1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-29 14:00:49 +03:00

0024623: Visualization - improve selection mechanism

Redesign of selection mechanism:
- implemented 3-level BVH tree for selection;
- selection now calculates in 3D space;
- intersection tests were moved to SelectMgr_BaseFrustum descendants;
- removed .cdl files in Select3D and .cdl related to selection in MeshVS;
- SelectMgr_ViewerSelectors are now shared between local and global contexts;
- transformations of sensitive entities are now stored in SelectMgr_SelectableObject only. Sensitive entities are independent from transformations, it is applied to SelectMgr_SelectingVolumeManager instance only;
- connected and multiple connected interactive objects are now represented by their child objects only for SelectMgr_SelectionManager;
- if interactive object has child objects, they will be stored as separate objects in SelectMgr_SelectionManager now.
- test cases bugs/vis/bug24623_1, bug24623_2, bug24623_3, bug24623_4 to test performance and memory issues.
This commit is contained in:
vpa
2015-04-06 12:31:00 +03:00
committed by bugmaster
parent 7a91ad6e81
commit f751596e46
269 changed files with 12626 additions and 11723 deletions

View File

@@ -23,6 +23,7 @@
#include <Graphic3d_Structure.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <StdPrs_Curve.hxx>

View File

@@ -25,6 +25,7 @@
#include <Prs3d_Drawer.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <TopoDS.hxx>

View File

@@ -25,6 +25,7 @@
#include <Prs3d_Drawer.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <TopoDS.hxx>

View File

@@ -22,6 +22,7 @@
#include <Graphic3d_Structure.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveCircle.hxx>
#include <StdPrs_DeflectionCurve.hxx>
#include <TopoDS.hxx>

View File

@@ -19,6 +19,7 @@
#include <AIS_ConcentricRelation.ixx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveCircle.hxx>
#include <Select3D_SensitiveSegment.hxx>

View File

@@ -18,6 +18,7 @@
#include <AIS_ConnectedInteractive.ixx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Geom_Transformation.hxx>
@@ -287,31 +288,30 @@ void AIS_ConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selectio
if (!myReference->HasSelection (theMode))
{
myReference->UpdateSelection (theMode);
myReference->RecomputePrimitives (theMode);
}
const Handle(SelectMgr_Selection)& TheRefSel = myReference->Selection (theMode);
Handle(SelectMgr_EntityOwner) anOwner = new SelectMgr_EntityOwner (this);
Handle(Select3D_SensitiveEntity) aSensitive, aNewSensitive;
TopLoc_Location aLocation (Transformation());
anOwner->SetLocation (aLocation);
if (TheRefSel->IsEmpty())
{
myReference->UpdateSelection (theMode);
myReference->RecomputePrimitives (theMode);
}
for (TheRefSel->Init(); TheRefSel->More(); TheRefSel->Next())
{
aSensitive = Handle(Select3D_SensitiveEntity)::DownCast (TheRefSel->Sensitive());
aSensitive = Handle(Select3D_SensitiveEntity)::DownCast (TheRefSel->Sensitive()->BaseSensitive());
if (!aSensitive.IsNull())
{
TopLoc_Location aLocation (Transformation());
// Get the copy of SE3D
aNewSensitive = aSensitive->GetConnected (aLocation);
aNewSensitive = aSensitive->GetConnected();
aNewSensitive->Set(anOwner);
// In case if SE3D caches some location-dependent data
// that must be updated after setting OWN
aNewSensitive->SetLocation (aLocation);
theSelection->Add (aNewSensitive);
}
@@ -330,13 +330,13 @@ void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_
Shapes2EntitiesMap;
if (!myReference->HasSelection (theMode))
myReference->UpdateSelection (theMode);
myReference->RecomputePrimitives (theMode);
const Handle(SelectMgr_Selection)& aRefSel = myReference->Selection (theMode);
if (aRefSel->IsEmpty() || aRefSel->UpdateStatus() == SelectMgr_TOU_Full)
{
myReference->UpdateSelection (theMode);
myReference->RecomputePrimitives (theMode);
}
Handle(StdSelect_BRepOwner) anOwner;
@@ -352,7 +352,7 @@ void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_
// sensitive entities associated with aMode
for (aRefSel->Init(); aRefSel->More(); aRefSel->Next())
{
aSE = Handle(Select3D_SensitiveEntity)::DownCast (aRefSel->Sensitive());
aSE = Handle(Select3D_SensitiveEntity)::DownCast (aRefSel->Sensitive()->BaseSensitive());
if(!aSE.IsNull())
{
anOwner = Handle(StdSelect_BRepOwner)::DownCast (aSE->OwnerId());
@@ -376,17 +376,14 @@ void AIS_ConnectedInteractive::computeSubShapeSelection (const Handle(SelectMgr_
this,
aSEList.First()->OwnerId()->Priority(),
Standard_True);
anOwner->SetLocation (Transformation());
for (SensitiveList::Iterator aListIt (aSEList); aListIt.More(); aListIt.Next())
{
{
aSE = aListIt.Value();
TopLoc_Location aLocation (Transformation());
aNewSE = aSE->GetConnected (aDummyLoc);
aNewSE = aSE->GetConnected();
aNewSE->Set (anOwner);
// In case if aSE caches some location-dependent data
// that must be updated after setting anOwner
aNewSE->SetLocation (aLocation);
theSelection->Add (aNewSE);
}

View File

@@ -50,8 +50,6 @@
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_SequenceOfOwner.hxx>
#include <Select3D_ListIteratorOfListOfSensitive.hxx>
#include <Select3D_ListOfSensitive.hxx>
#include <Select3D_SensitiveCircle.hxx>
#include <Select3D_SensitiveGroup.hxx>
#include <Select3D_SensitiveCurve.hxx>

View File

@@ -32,7 +32,6 @@
#include <Prs3d_LineAspect.hxx>
#include <Prs3d_Presentation.hxx>
#include <Prs3d_TextAspect.hxx>
#include <Select3D_ListOfSensitive.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <Standard.hxx>
#include <TCollection_ExtendedString.hxx>

View File

@@ -26,6 +26,7 @@
#include <Geom_Circle.hxx>
#include <ElCLib.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <Precision.hxx>

View File

@@ -23,6 +23,7 @@
#include <TopAbs_ShapeEnum.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <BRep_Tool.hxx>

View File

@@ -40,6 +40,7 @@
#include <Select3D_SensitiveCurve.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <TColStd_ListIteratorOfListOfTransient.hxx>

View File

@@ -427,43 +427,16 @@ is
---Purpose:
-- Removes selection mode from Interactive Objects.
-- aMode provides the selection mode index of the entity aniobj.
SetSensitivityMode(me : mutable;
aMode : SensitivityMode from StdSelect) is static;
---Level: Public
---Purpose: Sets the selection sensitivity mode. SM_WINDOW mode
-- uses the specified pixel tolerance to compute the sensitivity
-- value, SM_VIEW mode allows to define the sensitivity manually.
SensitivityMode(me) returns SensitivityMode from StdSelect;
---Level: Public
---Purpose: Returns the selection sensitivity mode.
SetSensitivity(me:mutable;
aPrecision: Real from Standard);
---Level: Public
---Purpose: Sets the sensitivity aPrecision
-- according to the view size for the current context or local
-- context if any is activated.
-- Sets the sensitivity aPrecision in pixels for the current context
-- or local context if any is activated. By default, this
-- sensitivity is equal to 4 pixels.
-- When a local context is open, the defined sensitivity applies to
-- this local context instead of the main context.
Sensitivity (me) returns Real from Standard;
---Level: Public
---Purpose: Returns the selection sensitivity value.
SetPixelTolerance(me:mutable;
aPrecision: Integer from Standard = 4);
aPrecision: Real from Standard = 4.0);
---Level: Public
---Purpose: Define the current selection pixel sensitivity
-- for this context or local context if any one is activated.
-- Warning: When a local context is open the sensitivity is apply on it
-- instead on the main context.
PixelTolerance(me) returns Integer from Standard;
PixelTolerance(me) returns Real from Standard;
---Level: Public
---Purpose: Returns the pixel tolerance.
@@ -1668,9 +1641,10 @@ is
ZDetection(me) returns Boolean;
---Purpose: Retrieves the Z detection state.
Activate(me : mutable;
anIobj : InteractiveObject from AIS;
aMode : Integer from Standard = 0);
Activate(me : mutable;
anIobj : InteractiveObject from AIS;
aMode : Integer from Standard = 0;
theIsForce : Boolean from Standard = Standard_False);
---Purpose: Activates the selection mode aMode whose index is
-- given, for the given interactive entity anIobj.
@@ -1947,10 +1921,10 @@ is
---C++: inline
---C++: return const &
MainSelector(me) returns any ViewerSelector3d from StdSelect;
MainSelector(me) returns ViewerSelector3d from StdSelect;
---C++: inline
---C++: return const &
LocalSelector(me) returns any ViewerSelector3d from StdSelect;
LocalSelector(me) returns ViewerSelector3d from StdSelect;
PurgeDisplay(me:mutable)
returns Integer from Standard;
@@ -1962,12 +1936,6 @@ is
HighestIndex(me) returns Integer from Standard;
DisplayActiveAreas(me:mutable;aView:View from V3d) ;
ClearActiveAreas (me :mutable;
aView: View from V3d) is static;
---Level: Internal
DisplayActiveSensitive(me:mutable;aView : View from V3d) is static;
@@ -1978,9 +1946,6 @@ is
DisplayActiveSensitive(me:mutable;
anObject: InteractiveObject from AIS;
aView : View from V3d) is static;
DisplayActiveAreas(me:mutable;
anObject: InteractiveObject from AIS;
aView : View from V3d) is static;
GetDefModes(me;
anIobj : InteractiveObject from AIS;
@@ -2010,6 +1975,8 @@ is
---Purpose: returns if possible,
-- the first local context where the object is seen
RebuildSelectionStructs (me : mutable);
---Purpose: Rebuilds 1st level of BVH selection forcibly
SetViewAffinity (me : mutable;
theIObj : InteractiveObject from AIS;
theView : View from V3d;
@@ -2017,6 +1984,12 @@ is
---Purpose: setup object visibility in specified view,
-- has no effect if object is not disaplyed in this context.
Disconnect (me : mutable;
theAssembly : InteractiveObject from AIS;
theObjToDisconnect : InteractiveObject from AIS = NULL)
is static;
---Purpose: Disconnects theObjToDisconnect from theAssembly and removes dependent selection structures
ObjectsForView (me;
theListOfIO : in out ListOfInteractive from AIS;
theView : View from V3d;

View File

@@ -43,6 +43,7 @@
#include <Prs3d_PlaneAspect.hxx>
#include <PrsMgr_PresentableObject.hxx>
#include <Standard_Atomic.hxx>
#include <StdSelect_ViewerSelector3d.hxx>
#include <UnitsAPI.hxx>
#include <AIS_Trihedron.hxx>
@@ -2364,6 +2365,9 @@ void AIS_InteractiveContext::ClearGlobal (const Handle(AIS_InteractiveObject)& t
if (theIObj.IsNull()
|| !myObjects.IsBound (theIObj))
{
// for cases when reference shape of connected interactives was not displayed
// but its selection primitives were calculated
mgrSelector->Remove (theIObj);
return;
}
@@ -2584,65 +2588,11 @@ void AIS_InteractiveContext::UnsetSelectionMode (const Handle(AIS_InteractiveObj
//
}
//=======================================================================
//function : SetSensitivityMode
//purpose :
//=======================================================================
void AIS_InteractiveContext::SetSensitivityMode (const StdSelect_SensitivityMode theMode)
{
if (HasOpenedContext())
{
myLocalContexts (myCurLocalIndex)->SetSensitivityMode (theMode);
}
else
{
myMainSel->SetSensitivityMode (theMode);
}
}
//=======================================================================
//function : SensitivityMode
//purpose :
//=======================================================================
StdSelect_SensitivityMode AIS_InteractiveContext::SensitivityMode() const
{
return HasOpenedContext()
? myLocalContexts (myCurLocalIndex)->SensitivityMode()
: myMainSel->SensitivityMode();
}
//=======================================================================
//function : SetSensitivity
//purpose :
//=======================================================================
void AIS_InteractiveContext::SetSensitivity (const Standard_Real thePrecision)
{
if (HasOpenedContext())
{
myLocalContexts(myCurLocalIndex)->SetSensitivity (thePrecision);
}
else
{
myMainSel->SetSensitivity (thePrecision);
}
}
//=======================================================================
//function : Sensitivity
//purpose :
//=======================================================================
Standard_Real AIS_InteractiveContext::Sensitivity() const
{
return HasOpenedContext()
? myLocalContexts(myCurLocalIndex)->Sensitivity()
: myMainSel->Sensitivity();
}
//=======================================================================
//function : SetPixelTolerance
//purpose :
//=======================================================================
void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecision)
void AIS_InteractiveContext::SetPixelTolerance (const Standard_Real thePrecision)
{
if (HasOpenedContext())
{
@@ -2658,7 +2608,7 @@ void AIS_InteractiveContext::SetPixelTolerance (const Standard_Integer thePrecis
//function : PixelTolerance
//purpose :
//=======================================================================
Standard_Integer AIS_InteractiveContext::PixelTolerance() const
Standard_Real AIS_InteractiveContext::PixelTolerance() const
{
return HasOpenedContext()
? myLocalContexts (myCurLocalIndex)->PixelTolerance()
@@ -2836,3 +2786,37 @@ Standard_Integer AIS_InteractiveContext::GetZLayer (const Handle(AIS_Interactive
? theIObj->ZLayer()
: Graphic3d_ZLayerId_UNKNOWN;
}
//=======================================================================
//function : RebuildSelectionStructs
//purpose : Rebuilds 1st level of BVH selection forcibly
//=======================================================================
void AIS_InteractiveContext::RebuildSelectionStructs()
{
myMainSel->RebuildObjectsTree (Standard_True);
}
//=======================================================================
//function : Disconnect
//purpose : Disconnects selectable object from an assembly and updates selection structures
//=======================================================================
void AIS_InteractiveContext::Disconnect (const Handle(AIS_InteractiveObject)& theAssembly,
const Handle(AIS_InteractiveObject)& theObjToDisconnect)
{
if (theAssembly->IsInstance ("AIS_MultipleConnectedInteractive"))
{
const Handle(AIS_MultipleConnectedInteractive)& theObj =
Handle(AIS_MultipleConnectedInteractive)::DownCast (theAssembly);
theObj->Disconnect (theObjToDisconnect);
mgrSelector->Remove (theObjToDisconnect);
}
else if (theAssembly->IsInstance ("AIS_ConnectedInteractive") && theObjToDisconnect == NULL)
{
const Handle(AIS_ConnectedInteractive)& theObj =
Handle(AIS_ConnectedInteractive)::DownCast (theAssembly);
theObj->Disconnect();
mgrSelector->Remove (theObj);
}
else
return;
}

View File

@@ -16,6 +16,7 @@
#include <AIS_InteractiveContext.jxx>
#include <SelectMgr_EntityOwner.hxx>
#include <StdSelect_ViewerSelector3d.hxx>
#include <AIS_Selection.hxx>
#include <AIS_StatusOfDetection.hxx>
#include <AIS_StatusOfPick.hxx>
@@ -1098,11 +1099,11 @@ void AIS_InteractiveContext::EntityOwners(SelectMgr_IndexedMapOfOwner& theOwners
if ( !theIObj->HasSelection( aMode ) )
continue;
Handle(SelectMgr_Selection) aSel = theIObj->Selection( aMode );
Handle(SelectMgr_Selection) aSel = theIObj->Selection(aMode);
for ( aSel->Init(); aSel->More(); aSel->Next() )
{
Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive();
Handle(SelectBasics_SensitiveEntity) aEntity = aSel->Sensitive()->BaseSensitive();
if ( aEntity.IsNull() )
continue;

View File

@@ -29,6 +29,8 @@
#include <Graphic3d_MapIteratorOfMapOfStructure.hxx>
#include <AIS_Selection.hxx>
#include <StdSelect_ViewerSelector3d.hxx>
//=======================================================================
//function : OpenLocalContext
//purpose :
@@ -59,10 +61,6 @@ OpenLocalContext(const Standard_Boolean UseDisplayedObjects,
myLastPicked.Nullify();
myWasLastMain = Standard_True;
Standard_Integer untilnow = myCurLocalIndex;
myCurLocalIndex = HighestIndex() + 1;
Handle(AIS_LocalContext) NewLocal= new AIS_LocalContext(this,myCurLocalIndex,
@@ -72,12 +70,6 @@ OpenLocalContext(const Standard_Boolean UseDisplayedObjects,
// the AIS_LocalContext bind itself to myLocalContexts
// because procedures performed in AIS_LocalContext constructor
// already may access myLocalContexts(myCurLocalIndex) (like methods AIS_LocalContext::IsSelected()).
//myLocalContexts.Bind (myCurLocalIndex, NewLocal);
NewLocal->MainSelector()->Set ((myLocalContexts.Extent() > 1)
? myLocalContexts (untilnow)->MainSelector()->Projector()
: myMainSel->Projector());
NewLocal->MainSelector()->UpdateConversion();
#ifdef OCCT_DEBUG
cout<<"\tOpen Local Context No "<<myCurLocalIndex<<endl;
@@ -123,17 +115,11 @@ void AIS_InteractiveContext::CloseLocalContext(const Standard_Integer Index,
// the only open local context is closed...
if(myLocalContexts.Extent()==1 && GoodIndex == myCurLocalIndex){
Standard_Boolean updateproj = !(myLocalContexts(myCurLocalIndex)->HasSameProjector(myMainSel->Projector()));
myLocalContexts(myCurLocalIndex)->Terminate( updateviewer );
myLocalContexts.UnBind(myCurLocalIndex);
myCurLocalIndex = 0;
ResetOriginalState(Standard_False);
if(updateproj)
myMainSel->UpdateConversion();
else{
myMainSel->UpdateSort();
}
if(debugmode)
cout<<"No More Opened Local Context "<<endl;
}
@@ -146,11 +132,6 @@ void AIS_InteractiveContext::CloseLocalContext(const Standard_Integer Index,
// the current is closed...
if(GoodIndex==myCurLocalIndex){
myCurLocalIndex = HighestIndex();
const Handle(AIS_LocalContext)& LocCtx = myLocalContexts(myCurLocalIndex);
if (!LocCtx->HasSameProjector (VS->Projector()))
{
LocCtx->MainSelector()->UpdateConversion();
}
}
else if(debugmode)
cout<<"a No Current Local Context WasClosed"<<endl;
@@ -177,7 +158,6 @@ void AIS_InteractiveContext::CloseAllContexts(const Standard_Boolean updateviewe
ResetOriginalState(Standard_False);
myMainSel->UpdateSort();
if(updateviewer) myMainVwr->Update();
}
@@ -226,12 +206,13 @@ Standard_Integer AIS_InteractiveContext::HighestIndex() const
void AIS_InteractiveContext::
Activate(const Handle(AIS_InteractiveObject)& anIObj,
const Standard_Integer aMode)
const Standard_Integer aMode,
const Standard_Boolean theIsForce)
{
if(!HasOpenedContext()){
if(!myObjects.IsBound(anIObj)) return;
const Handle(AIS_GlobalStatus)& STAT = myObjects(anIObj);
if(STAT->GraphicStatus()==AIS_DS_Displayed)
if(STAT->GraphicStatus()==AIS_DS_Displayed || theIsForce)
mgrSelector->Activate(anIObj,aMode,myMainSel);
STAT ->AddSelectionMode(aMode);
}
@@ -570,31 +551,6 @@ const SelectMgr_ListOfFilter& AIS_InteractiveContext::Filters() const
return myFilters->StoredFilters();
}
//=======================================================================
//function : DisplayActiveAreas
//purpose :
//=======================================================================
void AIS_InteractiveContext::DisplayActiveAreas(const Handle(V3d_View)& aviou)
{
if(HasOpenedContext())
myLocalContexts(myCurLocalIndex)->DisplayAreas(aviou);
else
myMainSel->DisplayAreas(aviou);
}
//=======================================================================
//function : ClearActiveAreas
//purpose :
//=======================================================================
void AIS_InteractiveContext::ClearActiveAreas(const Handle(V3d_View)& aviou)
{
if(HasOpenedContext())
myLocalContexts(myCurLocalIndex)->ClearAreas(aviou);
else
myMainSel->ClearAreas(aviou);
}
//=======================================================================
//function : DisplayActiveSensitive
//purpose :
@@ -631,41 +587,11 @@ void AIS_InteractiveContext::DisplayActiveSensitive(const Handle(AIS_Interactive
for(;It.More();It.Next()){
const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
VS->DisplaySensitive(Sel,aviou,Standard_False);
VS->DisplaySensitive(Sel,anIObj->Transformation(), aviou,Standard_False);
}
}
//=======================================================================
//function : DisplayActiveAreas
//purpose :
//=======================================================================
void AIS_InteractiveContext::DisplayActiveAreas(const Handle(AIS_InteractiveObject)& anIObj,
const Handle(V3d_View)& aviou)
{
TColStd_ListIteratorOfListOfInteger It;
Handle(StdSelect_ViewerSelector3d) VS;
if(HasOpenedContext()){
const Handle(AIS_LocalContext)& LC = myLocalContexts(myCurLocalIndex);
if(!LC->IsIn(anIObj)) return;
It.Initialize(LC->SelectionModes(anIObj));
VS = LC->MainSelector();
}
else{
if(!myObjects.IsBound(anIObj)) return;
It.Initialize(myObjects(anIObj)->SelectionModes());
VS = myMainSel;
}
for(;It.More();It.Next()){
const Handle(SelectMgr_Selection)& Sel = anIObj->Selection(It.Value());
VS->DisplayAreas(Sel,aviou,Standard_False);
}
}
//=======================================================================
//function : ClearActiveSensitive
//purpose :
@@ -848,6 +774,7 @@ void AIS_InteractiveContext::ResetOriginalState(const Standard_Boolean updatevie
{
Standard_Boolean upd_main(Standard_False);
TColStd_ListIteratorOfListOfInteger itl;
myMainSel->ResetSelectionActivationStatus();
for (AIS_DataMapIteratorOfDataMapOfIOStatus it(myObjects);it.More();it.Next()){
const Handle(AIS_InteractiveObject)& iobj = it.Key();

View File

@@ -581,6 +581,12 @@ is
---Purpose: Retrieves current polygon offsets settings from <myDrawer>.
---Category: Inquire methods
BoundingBox (me : mutable;
theBndBox : out Box from Bnd)
is redefined;
---Level: Public
---Purpose: Returns bounding box of object correspondingly to its current display mode.
fields
myCTXPtr : PToContext from AIS;

View File

@@ -33,6 +33,8 @@
#include <Graphic3d_AspectLine3d.hxx>
#include <Graphic3d_AspectMarker3d.hxx>
#include <Graphic3d_AspectText3d.hxx>
#include <Graphic3d_BndBox4f.hxx>
#include <Graphic3d_CStructure.hxx>
#include <Graphic3d_Group.hxx>
#include <Graphic3d_Structure.hxx>
@@ -586,3 +588,62 @@ void AIS_InteractiveObject::PolygonOffsets(Standard_Integer& aMode,
if( HasPolygonOffsets() )
myDrawer->ShadingAspect()->Aspect()->PolygonOffsets( aMode, aFactor, aUnits );
}
//=======================================================================
//function : BoundingBox
//purpose : Returns bounding box of object correspondingly to its
// current display mode
//=======================================================================
void AIS_InteractiveObject::BoundingBox (Bnd_Box& theBndBox)
{
if (myDisplayMode == -1)
{
if (!myPresentations.IsEmpty())
{
const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations.First().Presentation();
const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation();
const Graphic3d_BndBox4f& aBndBox = aStruct->CStructure()->BoundingBox();
theBndBox.Update (static_cast<Standard_Real> (aBndBox.CornerMin().x()),
static_cast<Standard_Real> (aBndBox.CornerMin().y()),
static_cast<Standard_Real> (aBndBox.CornerMin().z()),
static_cast<Standard_Real> (aBndBox.CornerMax().x()),
static_cast<Standard_Real> (aBndBox.CornerMax().y()),
static_cast<Standard_Real> (aBndBox.CornerMax().z()));
return;
}
else
{
for (PrsMgr_ListOfPresentableObjectsIter aPrsIter (Children()); aPrsIter.More(); aPrsIter.Next())
{
const Handle(AIS_InteractiveObject)& aChild = Handle(AIS_InteractiveObject)::DownCast (aPrsIter.Value());
if (aChild.IsNull())
{
continue;
}
Bnd_Box aBox;
aChild->BoundingBox (aBox);
theBndBox.Add (aBox);
}
return;
}
}
else
{
for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)
{
if (myPresentations (aPrsIter).Mode() == myDisplayMode)
{
const Handle(PrsMgr_Presentation)& aPrs3d = myPresentations (aPrsIter).Presentation();
const Handle(Graphic3d_Structure)& aStruct = aPrs3d->Presentation();
const Graphic3d_BndBox4f& aBndBox = aStruct->CStructure()->BoundingBox();
theBndBox.Update (static_cast<Standard_Real> (aBndBox.CornerMin().x()),
static_cast<Standard_Real> (aBndBox.CornerMin().y()),
static_cast<Standard_Real> (aBndBox.CornerMin().z()),
static_cast<Standard_Real> (aBndBox.CornerMax().x()),
static_cast<Standard_Real> (aBndBox.CornerMax().y()),
static_cast<Standard_Real> (aBndBox.CornerMax().z()));
return;
}
}
}
}

View File

@@ -23,6 +23,7 @@
#include <Graphic3d_Structure.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <StdPrs_Curve.hxx>
#include <Geom_Line.hxx>

View File

@@ -51,7 +51,6 @@ uses
Shape from TopoDS,
View from V3d,
PresentationManager3d from PrsMgr,
Projector from Select3D,
IndexedMapOfOwner from SelectMgr,
EntityOwner from SelectMgr,
OrFilter from SelectMgr,
@@ -105,14 +104,6 @@ is
Terminate(me: mutable; updateviewer : Boolean from Standard = Standard_True);
HasSameProjector(me;aPrj:Projector from Select3D)
returns Boolean from Standard;
---Purpose: compares the current projector of the localContext
-- with <aPrj>
-- returns True if the projectors are identical.
-- (no need to update projection of selection primitives
-- when closing the local context)....
Reactivate(me:mutable);
---Purpose: to be called when a upper local context was closed...
-- useful to put pack the right projector...
@@ -445,35 +436,14 @@ is
WithColor : out Boolean from Standard;
HiCol : out NameOfColor from Quantity)
returns Boolean from Standard;
SetSensitivityMode(me : mutable;
aMode : SensitivityMode from StdSelect) is static;
---Level: Public
---Purpose: Sets the selection sensitivity mode. SM_WINDOW mode
-- uses the specified pixel tolerance to compute the sensitivity
-- value, SM_VIEW mode allows to define the sensitivity manually.
SensitivityMode(me) returns SensitivityMode from StdSelect;
---Level: Public
---Purpose: Returns the selection sensitivity mode.
SetSensitivity(me:mutable;
aPrecision: Real from Standard);
---Level: Public
---Purpose: Define the current selection sensitivity for
-- this local context according to the view size.
Sensitivity (me) returns Real from Standard;
---Level: Public
---Purpose: Returns the selection sensitivity value.
SetPixelTolerance(me:mutable;
aPrecision: Integer from Standard = 2);
aPrecision: Real from Standard = 2);
---Level: Public
---Purpose: Define the current selection sensitivity for
-- this local context according to the view size.
PixelTolerance(me) returns Integer from Standard;
PixelTolerance(me) returns Real from Standard;
---Level: Public
---Purpose: Returns the pixel tolerance.
@@ -505,11 +475,6 @@ is
---Category: INTERNAL METHODS;
UpdateConversion(me:mutable);
UpdateSort(me:mutable);
Status(me) returns AsciiString from TCollection is private;
@@ -524,15 +489,12 @@ is
UnloadContextObjects(me:mutable);
Process(me : mutable;
anObject : SelectableObject from SelectMgr;
WithProj: Boolean from Standard = Standard_True) is static private;
anObject : SelectableObject from SelectMgr) is static private;
Process(me:mutable;
WithProj: Boolean from Standard = Standard_True) is static private;
Process(me:mutable) is static private;
ActivateStandardModes(me:mutable;anObject: SelectableObject from SelectMgr;
WithProj: Boolean from Standard = Standard_True) is static private;
ActivateStandardModes(me:mutable;anObject: SelectableObject from SelectMgr) is static private;
manageDetected (me : mutable;
thePickOwner : EntityOwner from SelectMgr;
@@ -566,13 +528,6 @@ is
ComesFromDecomposition(me; aPickedIndex : Integer from Standard)
returns Boolean from Standard is static private;
DisplayAreas(me:mutable;aviou:View from V3d);
ClearAreas (me:mutable;
aView: View from V3d) is static;
---Level: Internal
HasFilters(me;aType:ShapeEnum from TopAbs)
returns Boolean from Standard is private;
@@ -580,7 +535,7 @@ is
ClearSensitive(me:mutable;aView:View from V3d) is static;
MainSelector(me) returns any ViewerSelector3d from StdSelect;
MainSelector(me) returns ViewerSelector3d from StdSelect;
---C++: inline
---C++: return const&

View File

@@ -33,6 +33,7 @@
#include <Prs3d_Presentation.hxx>
#include <Aspect_TypeOfMarker.hxx>
#include <StdSelect_ShapeTypeFilter.hxx>
#include <StdSelect_ViewerSelector3d.hxx>
#include <AIS_Selection.hxx>
#include <V3d_Viewer.hxx>
#include <V3d_View.hxx>
@@ -70,7 +71,7 @@ myLoadDisplayed(LoadDisplayed),
myAcceptStdMode(AcceptStandardModes),
myAcceptErase(AcceptEraseOfTemp),
mySM(aCtx->SelectionManager()),
myMainVS(new StdSelect_ViewerSelector3d(aCtx->MainSelector()->Projector())),
myMainVS(aCtx->MainSelector()),
myFilters(new SelectMgr_OrFilter()),
myAutoHilight(Standard_True),
mylastindex(0),
@@ -84,13 +85,14 @@ myAISCurDetected(0)
// created and mapped.
aCtx->myLocalContexts.Bind (Index, this);
myMainVS->ResetSelectionActivationStatus();
myMainPM = aCtx->MainPrsMgr();
mySelName = AIS_Local_SelName(this, Index);
AIS_Selection::CreateSelection(mySelName.ToCString());
mySM->Add(myMainVS);
if(myLoadDisplayed) LoadContextObjects();
Process(Standard_False);
Process();
}
@@ -195,7 +197,24 @@ Load(const Handle(AIS_InteractiveObject)& anInteractive,
const Standard_Boolean AllowShapeDecomposition,
const Standard_Integer ActivationMode)
{
if(myActiveObjects.IsBound(anInteractive)) return Standard_False;
if (myActiveObjects.IsBound (anInteractive))
{
if (anInteractive->HasSelection (ActivationMode))
{
const Handle(SelectMgr_Selection)& aSel = anInteractive->Selection (ActivationMode);
if (aSel->GetSelectionState() != SelectMgr_SOS_Activated)
{
if (!myMainVS->Contains (anInteractive))
{
mySM->Load (anInteractive, myMainVS);
}
mySM->Activate (anInteractive, ActivationMode, myMainVS);
return Standard_True;
}
}
return Standard_False;
}
Handle(AIS_LocalStatus) Att = new AIS_LocalStatus();
if(anInteractive->AcceptShapeDecomposition() && AllowShapeDecomposition)
@@ -296,8 +315,6 @@ Erase(const Handle(AIS_InteractiveObject)& anInteractive)
}
}
UpdateSort();
ClearOutdatedSelection (anInteractive, Standard_True);
return status;
@@ -353,7 +370,6 @@ void AIS_LocalContext::Clear(const AIS_ClearMode aType)
case AIS_CM_TemporaryShapePrs:
ClearDetected();
}
UpdateSort();
}
//=======================================================================
//function : ActivateMode
@@ -370,7 +386,6 @@ void AIS_LocalContext::ActivateMode(const Handle(AIS_InteractiveObject)& aSelect
myActiveObjects(aSelectable)->AddSelectionMode(aMode);
mySM->Activate(aSelectable,aMode,myMainVS);
}
UpdateSort();
}
//=======================================================================
//function : ActivateMode
@@ -386,8 +401,6 @@ void AIS_LocalContext::DeactivateMode(const Handle(AIS_InteractiveObject)& aSele
myActiveObjects(aSelectable)->RemoveSelectionMode(aMode);
mySM->Deactivate(aSelectable,aMode,myMainVS);
UpdateSort();
}
//=======================================================================
//function : ActivateMode
@@ -398,9 +411,8 @@ void AIS_LocalContext::Deactivate(const Handle(AIS_InteractiveObject)& aSelectab
{
if(!myActiveObjects.IsBound(aSelectable)) return;
mySM->Deactivate(aSelectable,myMainVS);
mySM->Deactivate(aSelectable, -1, myMainVS);
myActiveObjects(aSelectable)->ClearSelectionModes();
UpdateSort();
}
//=======================================================================
@@ -465,7 +477,6 @@ Standard_Boolean AIS_LocalContext::Remove(const Handle(AIS_InteractiveObject)& a
{
mySM->Remove (aSelectable);
}
UpdateSort();
ClearOutdatedSelection (aSelectable, Standard_True);
// This should be done at the very end because most methods use
@@ -538,10 +549,8 @@ void AIS_LocalContext::DeactivateStandardMode(const TopAbs_ShapeEnum aType)
myListOfStandardMode.Remove(It);
if(myFilters->IsIn(myStdFilters[IMode]))
myFilters->Remove(myStdFilters[IMode]);
UpdateSort();
return;
}
UpdateSort();
}
//=======================================================================
@@ -588,31 +597,6 @@ void AIS_LocalContext::RemoveFilter(const Handle(SelectMgr_Filter)& aFilter)
}
}
Standard_Boolean AIS_LocalContext::HasSameProjector(const Handle(Select3D_Projector)& thePrj) const
{
const Handle(Select3D_Projector)& aCurPrj = myMainVS->Projector();
if (aCurPrj->Perspective() != thePrj->Perspective())
return Standard_False;
if (aCurPrj->Perspective() && aCurPrj->Focus() != thePrj->Focus())
return Standard_False;
const gp_GTrsf& aCurTrsf = aCurPrj->Transformation();
const gp_GTrsf& aPrjTrsf = thePrj->Transformation();
for (Standard_Integer i = 1; i <= 3; ++i)
{
for (Standard_Integer j = 1; j <= 3 ; ++j)
{
if (aCurTrsf.Value (i, j) != aPrjTrsf.Value (i, j))
return Standard_False;
}
}
return Standard_True;
}
//=======================================================================
//function : Terminate
//purpose :
@@ -627,7 +611,6 @@ void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
mylastindex=0;
// clear the selector...
myMainVS->Clear();
myCTX->SelectionManager()->Remove(myMainVS);
AIS_Selection::SetCurrentSelection(mySelName.ToCString());
@@ -650,7 +633,6 @@ void AIS_LocalContext::Terminate (const Standard_Boolean theToUpdate)
}
Handle(V3d_View) aDummyView;
myMainVS->ClearAreas (aDummyView);
myMainVS->ClearSensitive (aDummyView);
if (theToUpdate)
@@ -893,12 +875,17 @@ void AIS_LocalContext::LoadContextObjects()
myCTX->DisplayedObjects(LL,Standard_True);
Handle(AIS_LocalStatus) Att;
for (It.Initialize(LL);It.More();It.Next()){
const Handle(AIS_InteractiveObject)& anObj = It.Value();
Att= new AIS_LocalStatus();
Att->SetDecomposition((It.Value()->AcceptShapeDecomposition() && myAcceptStdMode));
Att->SetDecomposition((anObj->AcceptShapeDecomposition() && myAcceptStdMode));
Att->SetTemporary(Standard_False);
Att->SetHilightMode(It.Value()->HasHilightMode()? It.Value()->HilightMode(): 0);
myActiveObjects.Bind(It.Value(),Att);
Att->SetHilightMode(anObj->HasHilightMode()? anObj->HilightMode(): 0);
for (anObj->Init(); anObj->More(); anObj->Next())
{
const Handle(SelectMgr_Selection)& aSel = anObj->CurrentSelection();
aSel->SetSelectionState (SelectMgr_SOS_Deactivated);
}
myActiveObjects.Bind(anObj,Att);
}
}
}
@@ -922,17 +909,16 @@ void AIS_LocalContext::UnloadContextObjects()
//purpose :
//=======================================================================
void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject,
const Standard_Boolean WithProj)
void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObject)
{
if(!myActiveObjects.IsBound(anObject)) return;
if(myActiveObjects(anObject)->Decomposed())
ActivateStandardModes(anObject,WithProj);
ActivateStandardModes(anObject);
else
{
TColStd_ListIteratorOfListOfInteger It(myActiveObjects(anObject)->SelectionModes());
for(;It.More();It.Next())
myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS,WithProj);
myCTX->SelectionManager()->Activate(anObject,It.Value(),myMainVS);
}
}
@@ -941,7 +927,7 @@ void AIS_LocalContext::Process(const Handle(SelectMgr_SelectableObject)& anObjec
//purpose :
//=======================================================================
void AIS_LocalContext::Process(const Standard_Boolean WithProj)
void AIS_LocalContext::Process()
{
myMainVS->Clear();
@@ -951,11 +937,11 @@ void AIS_LocalContext::Process(const Standard_Boolean WithProj)
for(;It.More();It.Next()){
myCTX->SelectionManager()->Load(It.Key(),myMainVS);
if(It.Value()->Decomposed())
ActivateStandardModes(It.Key(),WithProj);
ActivateStandardModes(It.Key());
else if( myCTX->GetAutoActivateSelection() )
{
It.Value()->AddSelectionMode(0);
myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS,WithProj);
myCTX->SelectionManager()->Activate(It.Key(),0,myMainVS);
}
}
@@ -966,8 +952,7 @@ void AIS_LocalContext::Process(const Standard_Boolean WithProj)
//purpose :
//=======================================================================
void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject,
const Standard_Boolean WithProj)
void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableObject)& anObject)
{
if(!myActiveObjects.IsBound(anObject)) return;
@@ -976,7 +961,7 @@ void AIS_LocalContext::ActivateStandardModes(const Handle(SelectMgr_SelectableOb
const Handle(AIS_LocalStatus)& LS = myActiveObjects(anObject);
if(LS->Decomposed()){
for(;itl.More();itl.Next()){
myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS,WithProj);
myCTX->SelectionManager()->Activate(anObject,itl.Value(),myMainVS);
LS->AddSelectionMode(itl.Value());
}
}
@@ -1023,13 +1008,13 @@ void AIS_LocalContext::ClearObjects()
myMainPM->Erase(SO,CurAtt->DisplayMode());
}
TColStd_ListIteratorOfListOfInteger ITL(CurAtt->SelectionModes());
for(;ITL.More();ITL.Next())
mySM->Deactivate(SO,ITL.Value(),myMainVS);
if(CurAtt->IsTemporary())
mySM->Remove(SO,myMainVS);
TColStd_ListIteratorOfListOfInteger aSelModeIter (CurAtt->SelectionModes());
for ( ; aSelModeIter.More(); aSelModeIter.Next())
{
Standard_Integer aSelMode = aSelModeIter.Value();
mySM->Deactivate (SO, aSelMode, myMainVS);
}
}
ClearSelected( Standard_False );
myActiveObjects.Clear();
@@ -1082,16 +1067,6 @@ void AIS_LocalContext::ClearDetected()
}
}
void AIS_LocalContext::UpdateConversion()
{
myMainVS->UpdateConversion();
}
void AIS_LocalContext::UpdateSort()
{
myMainVS->UpdateSort();
}
//=======================================================================
//function : BeginImmediateDraw
//purpose :
@@ -1155,32 +1130,12 @@ Standard_Boolean AIS_LocalContext::IsImmediateModeOn() const
return myMainPM->IsImmediateModeOn();
}
void AIS_LocalContext::SetSensitivityMode(const StdSelect_SensitivityMode aMode) {
myMainVS->SetSensitivityMode(aMode);
}
StdSelect_SensitivityMode AIS_LocalContext::SensitivityMode() const {
return myMainVS->SensitivityMode();
}
void AIS_LocalContext::SetSensitivity(const Standard_Real aPrecision) {
myMainVS->SetSensitivity(aPrecision);
}
Standard_Real AIS_LocalContext::Sensitivity() const {
return myMainVS->Sensitivity();
}
void AIS_LocalContext::SetPixelTolerance(const Standard_Integer aPrecision) {
void AIS_LocalContext::SetPixelTolerance(const Standard_Real aPrecision) {
myMainVS->SetPixelTolerance(aPrecision);
}
Standard_Integer AIS_LocalContext::PixelTolerance() const {
Standard_Real AIS_LocalContext::PixelTolerance() const {
return myMainVS->PixelTolerance();
}

View File

@@ -31,12 +31,12 @@
#include <Graphic3d_ArrayOfTriangles.hxx>
#include <Graphic3d_Group.hxx>
#include <Select3D_SensitiveTriangulation.hxx>
#include <StdSelect_ViewerSelector3d.hxx>
#include <SelectBasics_SensitiveEntity.hxx>
#include <TCollection_AsciiString.hxx>
#include <NCollection_Map.hxx>
#include <Visual3d_View.hxx>
#include <SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_SequenceOfOwner.hxx>
#include <OSD_Environment.hxx>
@@ -855,7 +855,7 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec
continue;
}
if (toClearDeactivated && !mySM->IsActivated (theIO, myMainVS, aMode))
if (toClearDeactivated && !mySM->IsActivated(theIO, aMode, myMainVS))
{
continue;
}
@@ -863,7 +863,7 @@ void AIS_LocalContext::ClearOutdatedSelection (const Handle(AIS_InteractiveObjec
Handle(SelectMgr_Selection) aSelection = theIO->Selection(aMode);
for (aSelection->Init(); aSelection->More(); aSelection->Next())
{
Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive();
Handle(SelectBasics_SensitiveEntity) anEntity = aSelection->Sensitive()->BaseSensitive();
if (anEntity.IsNull())
{
continue;
@@ -1012,7 +1012,7 @@ void AIS_LocalContext::SetSelected(const Handle(AIS_InteractiveObject)& anIObj,
const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
SIOBJ->Init();
if(SIOBJ->More()){
Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId();
EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
}
}
@@ -1049,10 +1049,9 @@ void AIS_LocalContext::AddOrRemoveSelected(const Handle(AIS_InteractiveObject)&
{
const Handle(SelectMgr_Selection)& SIOBJ = anIObj->Selection(0);
SIOBJ->Init();
if(SIOBJ->More())
{
Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->OwnerId();
EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
if(SIOBJ->More()){
Handle(SelectBasics_EntityOwner) BO = SIOBJ->Sensitive()->BaseSensitive()->OwnerId();
EO = *((Handle(SelectMgr_EntityOwner)*)&BO);
}
}
if(EO.IsNull())
@@ -1272,27 +1271,6 @@ Standard_Boolean AIS_LocalContext::ComesFromDecomposition(const Standard_Integer
return Standard_False;
}
//=======================================================================
//function : DisplayAreas
//purpose :
//=======================================================================
void AIS_LocalContext::DisplayAreas(const Handle(V3d_View)& aviou)
{
myMainVS->DisplayAreas(aviou);
}
//=======================================================================
//function : ClearAreas
//purpose :
//=======================================================================
void AIS_LocalContext::ClearAreas(const Handle(V3d_View)& aviou)
{
myMainVS->ClearAreas(aviou);
}
//=======================================================================
//function : DisplaySensitive
//purpose :
@@ -1475,9 +1453,9 @@ Handle(SelectMgr_EntityOwner) AIS_LocalContext::FindSelectedOwnerFromShape(const
Standard_Boolean found(Standard_False);
if (!found) {
SelectMgr_DataMapIteratorOfDataMapOfIntegerSensitive aSensitiveIt (myMainVS->Primitives());
for (; aSensitiveIt.More(); aSensitiveIt.Next()) {
EO = Handle(SelectMgr_EntityOwner)::DownCast (aSensitiveIt.Value()->OwnerId());
NCollection_List<Handle(SelectBasics_EntityOwner)>::Iterator anOwnersIt (myMainVS->ActiveOwners());
for (; anOwnersIt.More(); anOwnersIt.Next()) {
EO = Handle(SelectMgr_EntityOwner)::DownCast (anOwnersIt.Value());
Handle(StdSelect_BRepOwner) BROwnr = Handle(StdSelect_BRepOwner)::DownCast(EO);
if (!BROwnr.IsNull() && BROwnr->HasShape() && BROwnr->Shape() == sh) {
found = Standard_True;

View File

@@ -30,6 +30,7 @@
#include <Select3D_SensitiveCurve.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <ElCLib.hxx>
#include <ElSLib.hxx>

View File

@@ -38,6 +38,7 @@
#include <Geom_TrimmedCurve.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitiveCurve.hxx>

View File

@@ -31,6 +31,7 @@
#include <Select3D_SensitiveCurve.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <ElCLib.hxx>
#include <ElSLib.hxx>

View File

@@ -159,6 +159,7 @@ AIS_MultipleConnectedInteractive::AIS_MultipleConnectedInteractive()
: AIS_InteractiveObject (PrsMgr_TOP_AllView)
{
myHasOwnPresentations = Standard_False;
myAssemblyOwner = NULL;
SetHilightMode (0);
}
@@ -189,12 +190,16 @@ Handle(AIS_InteractiveObject) AIS_MultipleConnectedInteractive::Connect (const H
const Graphic3d_TransModeFlags& theTrsfPersFlag,
const gp_Pnt& theTrsfPersPoint)
{
if (myAssemblyOwner.IsNull())
myAssemblyOwner = new SelectMgr_EntityOwner (this);
Handle(AIS_InteractiveObject) anObjectToAdd;
Handle(AIS_MultipleConnectedInteractive) aMultiConnected = Handle(AIS_MultipleConnectedInteractive)::DownCast (theAnotherObj);
if (!aMultiConnected.IsNull())
{
Handle(AIS_MultipleConnectedInteractive) aNewMultiConnected = new AIS_MultipleConnectedInteractive();
aNewMultiConnected->myAssemblyOwner = myAssemblyOwner;
aNewMultiConnected->SetLocalTransformation (aMultiConnected->LocalTransformation());
// Perform deep copy of instance tree
@@ -357,7 +362,7 @@ Standard_Boolean AIS_MultipleConnectedInteractive::AcceptShapeDecomposition() co
//function : ComputeSelection
//purpose :
//=======================================================================
void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& theSelection,
void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_Selection)& /*theSelection*/,
const Standard_Integer theMode)
{
if (theMode != 0)
@@ -370,67 +375,13 @@ void AIS_MultipleConnectedInteractive::ComputeSelection (const Handle(SelectMgr_
continue;
}
if (!aChild->HasSelection(theMode))
if (!aChild->HasSelection (theMode))
{
aChild->UpdateSelection(theMode);
aChild->RecomputePrimitives (theMode);
}
aChild->ComputeSelection (theSelection, theMode);
}
return;
}
for (PrsMgr_ListOfPresentableObjectsIter anIter (Children()); anIter.More(); anIter.Next())
{
Handle(AIS_InteractiveObject) aChild = Handle(AIS_InteractiveObject)::DownCast (anIter.Value());
if (aChild.IsNull())
{
continue;
}
if (!aChild->HasSelection (theMode))
{
aChild->UpdateSelection (theMode);
}
const Handle(SelectMgr_Selection)& TheRefSel = aChild->Selection (theMode);
// To redirect selection we must replace owners in sensitives, but we don't want new owner for each SE.
// Only for each existing owner.
NCollection_DataMap <Handle(SelectMgr_EntityOwner), Handle(SelectMgr_EntityOwner)> anOwnerMap;
Handle(Select3D_SensitiveEntity) aSensitive, aNewSensitive;
if (TheRefSel->IsEmpty())
{
aChild->UpdateSelection(theMode);
}
for (TheRefSel->Init(); TheRefSel->More(); TheRefSel->Next())
{
aSensitive = Handle(Select3D_SensitiveEntity)::DownCast(TheRefSel->Sensitive());
if (!aSensitive.IsNull())
{
TopLoc_Location aLocation (Transformation());
// Get the copy of aSensitive
aNewSensitive = aSensitive->GetConnected (aLocation);
Handle(SelectMgr_EntityOwner) anOwner = Handle(SelectMgr_EntityOwner)::DownCast (aNewSensitive->OwnerId());
if (!anOwnerMap.IsBound (anOwner))
{
Handle(SelectMgr_EntityOwner) aNewOwner = new SelectMgr_AssemblyEntityOwner (anOwner, this);
anOwnerMap.Bind (anOwner, aNewOwner);
}
aNewSensitive->Set (anOwnerMap.Find (anOwner));
// In case if aSensitive caches some location-dependent data
// that must be updated after setting OWN
aNewSensitive->SetLocation (aLocation);
theSelection->Add (aNewSensitive);
}
Handle(SelectMgr_Selection) aSelection = new SelectMgr_Selection (theMode);
aChild->ComputeSelection (aSelection, theMode);
}
}
}

View File

@@ -35,6 +35,7 @@
#include <Select3D_SensitiveBox.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <StdPrs_WFDeflectionShape.hxx>
#include <TColStd_Array2OfReal.hxx>
#include <TCollection_ExtendedString.hxx>

View File

@@ -33,6 +33,7 @@
#include <AIS.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitiveBox.hxx>

View File

@@ -41,6 +41,7 @@
#include <Select3D_SensitiveSegment.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <TopoDS.hxx>
#include <TopoDS_Edge.hxx>

View File

@@ -50,7 +50,7 @@ inline Select3D_TypeOfSensitivity AIS_Plane::TypeOfSensitivity() const
return myTypeOfSensitivity;
}
inline void AIS_Plane::SetTypeOfSensitivity (const Select3D_TypeOfSensitivity theTypeOfSensitivity)
inline void AIS_Plane::SetTypeOfSensitivity (const Select3D_TypeOfSensitivity& theTypeOfSensitivity)
{
myTypeOfSensitivity = theTypeOfSensitivity;
}

View File

@@ -26,6 +26,7 @@
#include <DsgPrs_DatumPrs.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitivePoint.hxx>
#include <Geom_Axis1Placement.hxx>

View File

@@ -21,6 +21,7 @@
#include <gce_MakeLin.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Select3D_SensitiveBox.hxx>
#include <Precision.hxx>

View File

@@ -21,6 +21,7 @@
#include <Select3D_SensitiveSegment.hxx>
#include <SelectMgr_EntityOwner.hxx>
#include <SelectMgr_Selection.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS.hxx>

View File

@@ -45,7 +45,8 @@ public:
//! Creates binned SAH BVH builder.
BVH_BinnedBuilder (const Standard_Integer theLeafNodeSize = 5,
const Standard_Integer theMaxTreeDepth = 32);
const Standard_Integer theMaxTreeDepth = 32,
const Standard_Boolean theToUseMainAxis = Standard_False);
//! Releases resources of binned SAH BVH builder.
virtual ~BVH_BinnedBuilder();
@@ -64,6 +65,10 @@ protected:
BVH_BinVector& theBins,
const Standard_Integer theAxis);
private:
Standard_Boolean myUseMainAxis; //!< Defines whether to search for the best split or use the widest axis
};
#include <BVH_BinnedBuilder.lxx>

View File

@@ -19,9 +19,11 @@
// =======================================================================
template<class T, int N, int Bins>
BVH_BinnedBuilder<T, N, Bins>::BVH_BinnedBuilder (const Standard_Integer theLeafNodeSize,
const Standard_Integer theMaxTreeDepth)
const Standard_Integer theMaxTreeDepth,
const Standard_Boolean theToUseMainAxis)
: BVH_QueueBuilder<T, N> (theLeafNodeSize,
theMaxTreeDepth)
theMaxTreeDepth),
myUseMainAxis (theToUseMainAxis)
{
//
}
@@ -129,6 +131,46 @@ namespace BVH
#include <limits>
namespace BVH
{
template<class T, int N>
struct BVH_AxisSelector
{
typedef typename BVH::VectorType<T, N>::Type BVH_VecNt;
// =======================================================================
// function : MainAxis
// purpose :
// =======================================================================
static Standard_Integer MainAxis (const BVH_VecNt& theSize)
{
if (theSize.y() > theSize.x())
{
return theSize.y() > theSize.z() ? 1 : 2;
}
else
{
return theSize.z() > theSize.x() ? 2 : 0;
}
}
};
template<class T>
struct BVH_AxisSelector<T, 2>
{
typedef typename BVH::VectorType<T, 2>::Type BVH_VecNt;
// =======================================================================
// function : MainAxis
// purpose :
// =======================================================================
static Standard_Integer MainAxis (const BVH_VecNt& theSize)
{
return theSize.x() > theSize.y() ? 0 : 1;
}
};
}
// =======================================================================
// function : BuildNode
// purpose :
@@ -162,8 +204,10 @@ void BVH_BinnedBuilder<T, N, Bins>::BuildNode (BVH_Set<T, N>* theSet,
Standard_Real aMinSplitCost = std::numeric_limits<Standard_Real>::max();
Standard_Integer aMainAxis = BVH::BVH_AxisSelector<T, N>::MainAxis (aSize);
// Find best split
for (Standard_Integer anAxis = 0; anAxis < (N < 4 ? N : 3); ++anAxis)
for (Standard_Integer anAxis = myUseMainAxis ? aMainAxis : 0; anAxis <= (myUseMainAxis ? aMainAxis : Min (N - 1, 2)); ++anAxis)
{
if (BVH::VecComp<T, N>::Get (aSize, anAxis) <= BVH::THE_NODE_MIN_SIZE)
continue;

View File

@@ -26,7 +26,8 @@ public:
//! Creates spatial median split builder.
BVH_SpatialMedianBuilder (const Standard_Integer theLeafNodeSize = 5,
const Standard_Integer theMaxTreeDepth = 32);
const Standard_Integer theMaxTreeDepth = 32,
const Standard_Boolean theToUseMainAxis = Standard_False);
//! Releases resources of spatial median split builder.
virtual ~BVH_SpatialMedianBuilder();

View File

@@ -21,9 +21,11 @@
// =======================================================================
template<class T, int N>
BVH_SpatialMedianBuilder<T, N>::BVH_SpatialMedianBuilder (const Standard_Integer theLeafNodeSize,
const Standard_Integer theMaxTreeDepth)
const Standard_Integer theMaxTreeDepth,
const Standard_Boolean theToUseMainAxis)
: BVH_BinnedBuilder<T, N, 2> (theLeafNodeSize,
theMaxTreeDepth)
theMaxTreeDepth,
theToUseMainAxis)
{
//
}

View File

@@ -33,7 +33,6 @@ public:
DEFINE_STANDARD_RTTI( IVtk_IShapePickerAlgo )
virtual void SetView (const IVtk_IView::Handle& theView) = 0;
virtual void Modified() = 0;
virtual int NbPicked() = 0;
//! Get activated selection modes for a shape.

View File

@@ -19,6 +19,8 @@
#include <IVtk_Interface.hxx>
#include <gp_XY.hxx>
#include <gp_XYZ.hxx>
#include <gp_Pnt.hxx>
#include <Graphic3d_Mat4d.hxx>
DEFINE_STANDARD_HANDLE( IVtk_IView, IVtk_Interface )
@@ -65,12 +67,26 @@ public:
//! @return Two doubles containing the display coordinates of the view window center
virtual void GetViewCenter (double& theX, double& theY) const = 0;
//! Gets window size in screen coordinates in pixels
virtual void GetWindowSize (int& theX, int& theY) const = 0;
//! Gets camera projection and orientation matrices
virtual void GetCamera (Graphic3d_Mat4d& theProj,
Graphic3d_Mat4d& theOrient,
Standard_Boolean& theIsOrtho) const = 0;
//! Converts 3D display coordinates into 3D world coordinates.
//! @param [in] theDisplayPnt 2d point of display coordinates
//! @param [out] theWorldPnt 3d point of world coordinates
//! @return true if conversion was successful, false otherwise
virtual bool DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldPnt) const = 0;
//! Gets viewport coordinates
virtual void GetViewport (Standard_Real& theX,
Standard_Real& theY,
Standard_Real& theWidth,
Standard_Real& theHeight) const = 0;
DEFINE_STANDARD_RTTI( IVtk_IView )
};

View File

@@ -170,3 +170,13 @@ const Bnd_Box& IVtkOCC_SelectableObject::BoundingBox()
return myBndBox;
}
//============================================================================
// Method: BoundingBox
// Purpose:
//============================================================================
void IVtkOCC_SelectableObject::BoundingBox (Bnd_Box& theBndBox)
{
BoundingBox();
theBndBox = myBndBox;
}

View File

@@ -43,6 +43,9 @@ public:
const IVtkOCC_Shape::Handle& GetShape() const { return myShape; };
//! Returns bounding box of object
Standard_EXPORT virtual void BoundingBox (Bnd_Box& theBndBox) Standard_OVERRIDE;
DEFINE_STANDARD_RTTI( IVtkOCC_SelectableObject )
private:

View File

@@ -47,16 +47,6 @@ IVtkOCC_ShapePickerAlgo::~IVtkOCC_ShapePickerAlgo()
void IVtkOCC_ShapePickerAlgo::SetView (const IVtk_IView::Handle& theView)
{
myView = theView;
Modified();
}
//================================================================
// Function : Modified
// Purpose :
//================================================================
void IVtkOCC_ShapePickerAlgo::Modified()
{
myViewerSelector->Update (myView);
}
//================================================================
@@ -132,6 +122,7 @@ void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_IShape::Handle& theSh
// then create a new selection in the given mode for this object (shape).
Handle(SelectMgr_Selection) aNewSelection = new SelectMgr_Selection (theMode);
aSelObj->AddSelection (aNewSelection, theMode);
myViewerSelector->AddSelectionToObject (aSelObj, aNewSelection);
}
// Update the selection for the given mode according to its status.
@@ -141,14 +132,16 @@ void IVtkOCC_ShapePickerAlgo::SetSelectionMode (const IVtk_IShape::Handle& theSh
{
case SelectMgr_TOU_Full:
// Recompute the sensitive primitives which correspond to the mode.
aSelObj->UpdateSelection (theMode);
myViewerSelector->RemoveSelectionOfObject (aSelObj, aSelObj->Selection (theMode));
aSelObj->RecomputePrimitives (theMode);
myViewerSelector->AddSelectionToObject (aSelObj, aSelObj->Selection (theMode));
myViewerSelector->RebuildObjectsTree();
myViewerSelector->RebuildSensitivesTree (aSelObj);
case SelectMgr_TOU_Partial:
{
if (aSelObj->HasTransformation())
{
// Updates locations in all sensitive entities from the Selection and
// corresponding entity owners (shapes).
aSelObj->UpdateTransformations (aSel);
myViewerSelector->RebuildObjectsTree();
}
break;
}

View File

@@ -39,12 +39,6 @@ public:
//! the 3D view projection.
Standard_EXPORT virtual void SetView (const IVtk_IView::Handle& theView);
//! Informs the picker that some parameters of the view
//! has been modified so it is necessary to recompute internal selection data.
//! It makes sense to call this method automatically as soon as
//! the underlying VTK object emits its ModifiedEvent.
Standard_EXPORT virtual void Modified();
//! Get number of picked entities.
Standard_EXPORT virtual int NbPicked();

View File

@@ -29,33 +29,7 @@ IMPLEMENT_STANDARD_RTTIEXT( IVtkOCC_ViewerSelector, SelectMgr_ViewerSelector )
IVtkOCC_ViewerSelector::IVtkOCC_ViewerSelector()
: SelectMgr_ViewerSelector(),
myPixTol(2),
myToUpdateTol(Standard_True)
{
for (Standard_Integer i=0;i<=13;i++) {myCoeff [i] = 0.;myPrevCoeff[i]=0.0;}
for (Standard_Integer j=0;j<2;j++) {myCenter [j] = 0.;myPrevCenter[j]=0.0;}
}
//============================================================================
// Method: Convert
// Purpose: Projects all sensitive entities from the given selection container
// to 2D space
//============================================================================
void IVtkOCC_ViewerSelector::Convert (const Handle(SelectMgr_Selection)& theSelection)
{
for (theSelection->Init(); theSelection->More(); theSelection->Next())
{
if(theSelection->Sensitive()->NeedsConversion())
{
Handle(Select3D_SensitiveEntity) aSensEntity =
*((Handle(Select3D_SensitiveEntity)*) &(theSelection->Sensitive()));
aSensEntity->Project (myPrj);
if (!tosort)
{
tosort = Standard_True;
}
}
}
}
myToUpdateTol(Standard_True) {}
//============================================================================
// Method: Pick
@@ -65,14 +39,38 @@ void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXPix,
const Standard_Integer theYPix,
const IVtk_IView::Handle& theView)
{
myclip.SetVoid();
Update (theView);
gp_XY aDispPnt (theXPix, theYPix);
gp_XYZ aWorldPnt;
gp_Pnt2d aP2d;
theView->DisplayToWorld (aDispPnt, aWorldPnt);
myPrj->Project (gp_Pnt (aWorldPnt), aP2d);
InitSelect (aP2d.X(), aP2d.Y());
if (myToUpdateTol)
{
// Compute and set a sensitivity tolerance according to the renderer (viewport).
// TODO: Think if this works well in perspective view...'cause result depends
// on position on the screen, but we always use the point close to the
// screen's origin...
mySelectingVolumeMgr.SetPixelTolerance (myPixTol);
myToUpdateTol = Standard_False;
}
Standard_Integer aWidth = 0, aHeight = 0;
Graphic3d_Mat4d aProj, anOrient;
Standard_Boolean isOrthographic = Standard_False;
Standard_Real aX = RealLast(), aY = RealLast();
Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Point);
theView->GetCamera (aProj, anOrient, isOrthographic);
mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
theView->GetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
gp_Pnt2d aMousePos (static_cast<Standard_Real> (theXPix),
static_cast<Standard_Real> (theYPix));
mySelectingVolumeMgr.BuildSelectingVolume (aMousePos);
TraverseSensitives();
}
//============================================================================
@@ -91,33 +89,36 @@ void IVtkOCC_ViewerSelector::Pick (const Standard_Integer theXMin,
// TODO: Think if this works well in perspective view...'cause result depends
// on position on the screen, but we always use the point close to the
// screen's origin...
gp_XYZ aWorldPnt1, aWorldPnt2;
gp_XY aDispPnt1 (0.0, 0.0);
gp_XY aDispPnt2 (myPixTol, 0.0);
theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
gp_Pnt aPnt1 (aWorldPnt1);
gp_Pnt aPnt2 (aWorldPnt2);
SetSensitivity (aPnt2.Distance (aPnt1));
mySelectingVolumeMgr.SetPixelTolerance (myPixTol);
myToUpdateTol = Standard_False;
}
Update (theView);
gp_XY aDispPnt1 (theXMin, theYMin);
gp_XY aDispPnt2 (theXMax, theYMax);
gp_XYZ aWorldPnt1, aWorldPnt2;
Standard_Integer aWidth = 0, aHeight = 0;
Graphic3d_Mat4d aProj, anOrient;
Standard_Boolean isOrthographic = Standard_False;
Standard_Real aX = RealLast(), aY = RealLast();
Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
gp_Pnt2d aP2d_1, aP2d_2;
theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Box);
theView->GetCamera (aProj, anOrient, isOrthographic);
mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
myPrj->Project (gp_Pnt (aWorldPnt1), aP2d_1);
myPrj->Project (gp_Pnt (aWorldPnt2), aP2d_2);
theView->GetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
InitSelect (Min (aP2d_1.X(), aP2d_2.X()),
Min (aP2d_1.Y(), aP2d_2.Y()),
Max (aP2d_1.X(), aP2d_2.X()),
Max (aP2d_1.Y(), aP2d_2.Y()));
theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
gp_Pnt2d aMinMousePos (static_cast<Standard_Real> (theXMin),
static_cast<Standard_Real> (theYMin));
gp_Pnt2d aMaxMousePos (static_cast<Standard_Real> (theXMax),
static_cast<Standard_Real> (theYMax));
mySelectingVolumeMgr.BuildSelectingVolume (aMinMousePos,
aMaxMousePos);
TraverseSensitives();
}
//============================================================================
@@ -136,19 +137,11 @@ void IVtkOCC_ViewerSelector::Pick (double** thePoly,
// TODO: Think if this works well in perspective view...'cause result depends
// on position on the screen, but we always use the point close to the
// screen's origin...
gp_XYZ aWorldPnt1, aWorldPnt2;
gp_XY aDispPnt1 (0.0, 0.0);
gp_XY aDispPnt2 (myPixTol, 0.0);
theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
gp_Pnt aPnt1 (aWorldPnt1);
gp_Pnt aPnt2 (aWorldPnt2);
SetSensitivity (aPnt2.Distance (aPnt1));
mySelectingVolumeMgr.SetPixelTolerance (myPixTol);
myToUpdateTol = Standard_False;
}
Update (theView);
// Build TColgp_Array1OfPnt2d from input array of doubles
gp_XYZ aWorldPnt;
@@ -156,149 +149,46 @@ void IVtkOCC_ViewerSelector::Pick (double** thePoly,
{
gp_XY aDispPnt = thePoly[anIt][2] != 0 ? gp_XY (thePoly[anIt][0] / thePoly[anIt][2], thePoly[anIt][1] / thePoly[anIt][2])
: gp_XY (thePoly[anIt][0], thePoly[anIt][1]);
gp_Pnt2d aP2d;
theView->DisplayToWorld (aDispPnt, aWorldPnt);
myPrj->Project (gp_Pnt (aWorldPnt), aP2d);
aPolyline.SetValue (anIt + 1, aP2d);
aPolyline.SetValue (anIt + 1, aDispPnt);
}
InitSelect (aPolyline);
}
Standard_Integer aWidth = 0, aHeight = 0;
Graphic3d_Mat4d aProj, anOrient;
Standard_Boolean isOrthographic = Standard_False;
Standard_Real aX = RealLast(), aY = RealLast();
Standard_Real aVpWidth = RealLast(), aVpHeight = RealLast();
//============================================================================
// Method: Update
// Purpose: Checks if some projection parameters have changed,
// and updates the 2D projections of all sensitive entities if necessary.
//============================================================================
Standard_Boolean IVtkOCC_ViewerSelector::Update (const IVtk_IView::Handle& theView)
{
static Standard_Real aZoom (0.0);
mySelectingVolumeMgr.SetActiveSelectionType (SelectMgr_SelectingVolumeManager::Polyline);
theView->GetCamera (aProj, anOrient, isOrthographic);
mySelectingVolumeMgr.SetCamera (aProj, anOrient, isOrthographic);
// No focal distance by default
myPrevCoeff[9] = 0.0;
// Parallel projection by default
myPrevCoeff[10] = 0.0;
theView->GetWindowSize (aWidth, aHeight);
mySelectingVolumeMgr.SetWindowSize (aWidth, aHeight);
// Flag related to perspective or parallel projection
Standard_Boolean isPerspective = theView->IsPerspective();
theView->GetViewport (aX, aY, aVpWidth, aVpHeight);
mySelectingVolumeMgr.SetViewport (aX, aY, aVpWidth, aVpHeight);
// For perspective projections only
if (isPerspective)
{
// Flag = 1 if perspective projection
myPrevCoeff[10] = 1.0;
// Focal distance
myPrevCoeff[9] = theView->GetDistance();
}
// View point
// Use (0,0,0) as a view reference point:
mySelectingVolumeMgr.BuildSelectingVolume (aPolyline);
theView->GetPosition (myPrevCoeff[0], myPrevCoeff[1], myPrevCoeff[2]);
// Orientation
theView->GetViewUp (myPrevCoeff[3], myPrevCoeff[4], myPrevCoeff[5]);
// Projection direction vector
theView->GetDirectionOfProjection (myPrevCoeff[6], myPrevCoeff[7], myPrevCoeff[8]);
// 3D Scale
theView->GetScale (myPrevCoeff[11], myPrevCoeff[12], myPrevCoeff[13]);
// Return the center of this viewport in display coordinates.
theView->GetViewCenter (myPrevCenter[0], myPrevCenter[1]);
Standard_Integer anIt;
for (anIt=0; anIt <= 13 && (myPrevCoeff[anIt] == myCoeff[anIt]); anIt++) { }
if (anIt <= 13 || (myPrevCenter[0] != myCenter[0]) || (myPrevCenter[1] != myCenter[1]))
{
toupdate = Standard_True;
myToUpdateTol = Standard_True;
for (Standard_Integer anI = anIt; anI <= 13; anI++)
{
myCoeff[anI] = myPrevCoeff[anI];
}
for (Standard_Integer aJ = 0; aJ < 2; aJ++)
{
myCenter[aJ] = myPrevCenter[aJ];
}
// For orthographic view use only direction of projection and up vector
// Panning, and zooming has no effect on 2D selection sensitives.
Handle (Graphic3d_Camera) aCamera = new Graphic3d_Camera();
aCamera->SetProjectionType (Graphic3d_Camera::Projection_Orthographic);
aCamera->SetCenter (gp::Origin());
aCamera->SetDirection (gp_Dir (-myCoeff[6], -myCoeff[7], -myCoeff[8]));
aCamera->SetUp (gp_Dir (myCoeff[3], myCoeff[4], myCoeff[5]));
aCamera->SetDistance (1.0);
aCamera->SetAxialScale (gp_XYZ (myCoeff[11], myCoeff[12], myCoeff[13]));
myPrj = new Select3D_Projector (aCamera->OrientationMatrix(), Graphic3d_Mat4d());
}
if (isPerspective)
{
if (Abs(theView->GetViewAngle() - aZoom) > 1.e-3)
{
myToUpdateTol = Standard_True;
aZoom = theView->GetViewAngle();
}
}
else
{
if (Abs (theView->GetParallelScale() - aZoom) > 1.e-3)
{
myToUpdateTol = Standard_True;
aZoom = theView->GetParallelScale();
}
}
if(myToUpdateTol)
{
// Compute and set a sensitivity tolerance according to the view
gp_XYZ aWorldPnt1, aWorldPnt2;
gp_XY aDispPnt1 (0.0, 0.0);
gp_XY aDispPnt2 (myPixTol, 0.0);
theView->DisplayToWorld (aDispPnt1, aWorldPnt1);
theView->DisplayToWorld (aDispPnt2, aWorldPnt2);
gp_Pnt aPnt1 (aWorldPnt1);
gp_Pnt aPnt2 (aWorldPnt2);
SetSensitivity (aPnt2.Distance (aPnt1));
myToUpdateTol = Standard_False;
}
if(toupdate) UpdateConversion();
if(tosort) UpdateSort();
return Standard_True;
TraverseSensitives();
}
//============================================================================
// Method: Activate
// Purpose: Activates the given selection
//============================================================================
void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Boolean theIsAutomaticProj)
void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSelection)
{
tosort = Standard_True;
for (theSelection->Init(); theSelection->More(); theSelection->Next())
{
theSelection->Sensitive()->SetActiveForSelection();
}
if (!myselections.IsBound (theSelection))
{
myselections.Bind (theSelection, 0);
}
else if (myselections (theSelection) != 0)
{
myselections (theSelection) = 0;
}
if (theIsAutomaticProj)
{
Convert (theSelection);
}
theSelection->SetSelectionState (SelectMgr_SOS_Activated);
myTolerances.Add (theSelection->Sensitivity());
mytolerance = myTolerances.Largest();
myToUpdateTolerance = Standard_True;
}
//============================================================================
@@ -307,18 +197,14 @@ void IVtkOCC_ViewerSelector::Activate (const Handle(SelectMgr_Selection)& theSel
//============================================================================
void IVtkOCC_ViewerSelector::Deactivate (const Handle(SelectMgr_Selection)& theSelection)
{
if (myselections.IsBound (theSelection))
for (theSelection->Init(); theSelection->More(); theSelection->Next())
{
myselections (theSelection) = 1;
tosort = Standard_True;
theSelection->Sensitive()->ResetSelectionActiveStatus();
}
}
//============================================================================
// Method: PickingLine
// Purpose: Deactivate the given selection
//============================================================================
gp_Lin IVtkOCC_ViewerSelector::PickingLine (const Standard_Real theX,const Standard_Real theY) const
{
return myPrj->Shoot (theX, theY);
theSelection->SetSelectionState (SelectMgr_SOS_Deactivated);
myTolerances.Decrement (theSelection->Sensitivity());
mytolerance = myTolerances.Largest();
myToUpdateTolerance = Standard_True;
}

View File

@@ -17,7 +17,6 @@
#define __IVTKOCC_VIEWERSELECTOR_H__
#include <IVtk_IView.hxx>
#include <Select3D_Projector.hxx>
#include <SelectMgr_Selection.hxx>
#include <SelectMgr_ViewerSelector.hxx>
@@ -32,10 +31,6 @@ class IVtkOCC_ViewerSelector : public SelectMgr_ViewerSelector
public:
IVtkOCC_ViewerSelector();
//! Projects all sensitive entities from the given selection container to 2D space
//! param [in] theSelection Container with sensitive entities to project
void Convert (const Handle(SelectMgr_Selection)& theSelection);
//! Implements point picking
//! @param [in] theXPix, theYPix Display coordinates of the point
//! @param [in] theView ICamera interface to update the projection parameters.
@@ -56,32 +51,15 @@ public:
void Pick (double** thePoly, const int theNbPoints, const IVtk_IView::Handle& theView);
//! Activates the given selection
void Activate (const Handle(SelectMgr_Selection)& theSelection,
const Standard_Boolean isAutomaticProj = Standard_True);
void Activate (const Handle(SelectMgr_Selection)& theSelection);
//! Deactivate the given selection
void Deactivate (const Handle(SelectMgr_Selection)& theSelection);
//! Checks if some projection parameters have changed,
//! and updates the 2D projections of all sensitive entities if necessary.
//! @param [in] theView Interface to VTK renderer to access projection parameters
Standard_Boolean Update (const IVtk_IView::Handle& theView);
//! Returns picking line.
//! @param theX direction X.
//! @param theX direction Y.
//! @return picking direction.
virtual gp_Lin PickingLine (const Standard_Real theX, const Standard_Real theY) const;
DEFINE_STANDARD_RTTI( IVtkOCC_ViewerSelector )
private:
Standard_Real myCoeff[14];
Standard_Real myPrevCoeff[14];
Standard_Real myCenter[2];
Standard_Real myPrevCenter[2];
Standard_Integer myPixTol;
Handle(Select3D_Projector) myPrj;
Standard_Boolean myToUpdateTol;
};

View File

@@ -18,6 +18,7 @@
#include <vtkAutoInit.h>
#include <vtkCamera.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkTransform.h>
// Initialization of VTK object factories.
@@ -159,3 +160,56 @@ bool IVtkVTK_View::DisplayToWorld (const gp_XY& theDisplayPnt, gp_XYZ& theWorldP
return true;
}
//================================================================
// Function : GetWindowSize
// Purpose :
//================================================================
void IVtkVTK_View::GetWindowSize (int& theX, int& theY) const
{
int* aSize = myRenderer->GetRenderWindow()->GetSize();
theX = aSize[0];
theY = aSize[1];
}
//================================================================
// Function : GetCamera
// Purpose :
//================================================================
void IVtkVTK_View::GetCamera (Graphic3d_Mat4d& theProj,
Graphic3d_Mat4d& theOrient,
Standard_Boolean& theIsOrtho) const
{
theIsOrtho = !IsPerspective();
vtkMatrix4x4* aCompositeProj =
myRenderer->GetActiveCamera()->GetCompositeProjectionTransformMatrix (myRenderer->GetTiledAspectRatio(),
0,
1);
for (Standard_Integer aRow = 0; aRow < 4; ++aRow)
{
for (Standard_Integer aCol = 0; aCol < 4; ++aCol)
{
theProj.SetValue (aRow, aCol, aCompositeProj->GetElement (aRow, aCol));
}
}
theOrient.InitIdentity();
}
//================================================================
// Function : GetViewport
// Purpose :
//================================================================
void IVtkVTK_View::GetViewport (Standard_Real& theX,
Standard_Real& theY,
Standard_Real& theWidth,
Standard_Real& theHeight) const
{
Standard_Real aViewport[4];
myRenderer->GetViewport (aViewport);
theX = aViewport[0];
theY = aViewport[1];
theWidth = aViewport[2];
theHeight = aViewport[3];
}

View File

@@ -68,6 +68,20 @@ public:
//! @return Two doubles containing the display coordinates of the view window center
Standard_EXPORT virtual void GetViewCenter (double& theX, double& theY) const;
//! Gets window size in screen coordinates in pixels
Standard_EXPORT virtual void GetWindowSize (int& theX, int& theY) const Standard_OVERRIDE;
//! Gets camera projection and orientation matrices
Standard_EXPORT virtual void GetCamera (Graphic3d_Mat4d& theProj,
Graphic3d_Mat4d& theOrient,
Standard_Boolean& theIsOrtho) const Standard_OVERRIDE;
//! Gets viewport coordinates
Standard_EXPORT virtual void GetViewport (Standard_Real& theX,
Standard_Real& theY,
Standard_Real& theWidth,
Standard_Real& theHeight) const Standard_OVERRIDE;
//! Converts 3D display coordinates into 3D world coordinates.
//! @param [in] theDisplayPnt 2d point of display coordinates
//! @param [out] theWorldPnt 3d point of world coordinates

View File

@@ -1,10 +1,20 @@
MeshVS_Buffer.hxx
MeshVS_EntityType.hxx
MeshVS_DisplayModeFlags.hxx
MeshVS_DummySensitiveEntity.hxx
MeshVS_DummySensitiveEntity.cxx
MeshVS_BuilderPriority.hxx
MeshVS_MeshPrsBuilder.lxx
MeshVS_TwoColors.hxx
MeshVS_TwoColors.cxx
MeshVS_TwoNodes.hxx
MeshVS_SelectionModeFlags.hxx
MeshVS_SensitiveFace.hxx
MeshVS_SensitiveFace.cxx
MeshVS_SensitiveMesh.hxx
MeshVS_SensitiveMesh.cxx
MeshVS_SensitiveSegment.hxx
MeshVS_SensitiveSegment.cxx
MeshVS_SensitivePolyhedron.hxx
MeshVS_SensitivePolyhedron.cxx
MeshVS_SymmetricPairHasher.hxx

View File

@@ -141,12 +141,6 @@ is
class MeshOwner;
class MeshEntityOwner;
class DummySensitiveEntity;
class SensitiveMesh;
class SensitiveFace;
class SensitiveSegment;
class SensitivePolyhedron;
---Category: miscellaneous types: data maps, enumerations and other
imported EntityType;
@@ -156,6 +150,11 @@ is
imported BuilderPriority;
imported TwoNodes;
imported Buffer;
imported SensitiveFace;
imported SensitiveMesh;
imported SensitiveSegment;
imported SensitivePolyhedron;
imported DummySensitiveEntity;
class Tool;

View File

@@ -1,55 +0,0 @@
-- Created on: 2003-09-29
-- Created by: Alexander SOLOVYOV and Sergey LITONIN
-- Copyright (c) 2003-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class DummySensitiveEntity from MeshVS inherits SensitiveEntity from SelectBasics
---Purpose: This class allows to create owners to all elements or nodes,
-- both hidden and shown, but these owners user cannot select "by hands"
-- in viewer. They means for internal application tasks, for example, receiving
-- all owners, both for hidden and shown entities.
uses
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
PickArgs from SelectBasics,
Array1OfPnt2d from TColgp,
Box2d from Bnd
is
Create ( OwnerId : EntityOwner from SelectBasics ) returns DummySensitiveEntity from MeshVS;
Areas ( me: mutable;
aresult: in out ListOfBox2d from SelectBasics ) is redefined;
Matches (me : mutable;
thePickArgs : PickArgs from SelectBasics;
theMatchDMin, theMatchDepth : out Real from Standard)
returns Boolean is redefined;
Matches ( me: mutable;
XMin, YMin, XMax, YMax, aTol: Real ) returns Boolean is redefined;
Matches ( me: mutable;
Polyline : Array1OfPnt2d from TColgp;
aBox : Box2d from Bnd;
aTol : Real ) returns Boolean is redefined;
Is3D ( me ) returns Boolean is redefined;
NeedsConversion ( me ) returns Boolean is redefined;
MaxBoxes ( me ) returns Integer is redefined;
end DummySensitiveEntity;

View File

@@ -13,84 +13,61 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <MeshVS_DummySensitiveEntity.ixx>
#include <MeshVS_DummySensitiveEntity.hxx>
#include <Bnd_Box2d.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
IMPLEMENT_STANDARD_HANDLE (MeshVS_DummySensitiveEntity, SelectBasics_SensitiveEntity)
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_DummySensitiveEntity, SelectBasics_SensitiveEntity)
//================================================================
// Function : Constructor MeshVS_DummySensitiveEntity
// Purpose :
//================================================================
MeshVS_DummySensitiveEntity::MeshVS_DummySensitiveEntity
( const Handle(SelectBasics_EntityOwner)& OwnerId )
: SelectBasics_SensitiveEntity( OwnerId )
{
}
MeshVS_DummySensitiveEntity::MeshVS_DummySensitiveEntity (const Handle(SelectBasics_EntityOwner)& theOwnerId)
: SelectBasics_SensitiveEntity (theOwnerId)
{}
//================================================================
// Function : Areas
// Function : NbSubElements
// Purpose :
//================================================================
void MeshVS_DummySensitiveEntity::Areas( SelectBasics_ListOfBox2d& )
Standard_Integer MeshVS_DummySensitiveEntity::NbSubElements()
{
return -1;
}
//================================================================
// Function : Matches
// Purpose :
//================================================================
Standard_Boolean MeshVS_DummySensitiveEntity::Matches( const SelectBasics_PickArgs&,
Standard_Real&,
Standard_Real& )
Standard_Boolean MeshVS_DummySensitiveEntity::Matches (SelectBasics_SelectingVolumeManager& /*theMgr*/,
SelectBasics_PickResult& /*thePickResult*/)
{
return Standard_False;
}
//================================================================
// Function : Matches
// Function : BoundingBox
// Purpose :
//================================================================
Standard_Boolean MeshVS_DummySensitiveEntity::Matches( const Standard_Real,
const Standard_Real,
const Standard_Real,
const Standard_Real,
const Standard_Real )
Select3D_BndBox3d MeshVS_DummySensitiveEntity::BoundingBox()
{
return Standard_False;
return Select3D_BndBox3d();
}
//================================================================
// Function : Matches
// Function : ElementsNb
// Purpose :
//================================================================
Standard_Boolean MeshVS_DummySensitiveEntity::Matches( const TColgp_Array1OfPnt2d&,
const Bnd_Box2d&,
const Standard_Real )
{
return Standard_False;
}
void MeshVS_DummySensitiveEntity::BVH()
{}
//================================================================
// Function : NeedsConversion
// Function : Clear
// Purpose :
//================================================================
Standard_Boolean MeshVS_DummySensitiveEntity::NeedsConversion() const
{
return Standard_False;
}
//================================================================
// Function : Is3D
// Purpose :
//================================================================
Standard_Boolean MeshVS_DummySensitiveEntity::Is3D() const
{
return Standard_True;
}
//================================================================
// Function : MaxBoxes
// Purpose :
//================================================================
Standard_Integer MeshVS_DummySensitiveEntity::MaxBoxes() const
{
return 0;
}
void MeshVS_DummySensitiveEntity::Clear()
{}

View File

@@ -0,0 +1,56 @@
// Created on: 2003-09-29
// Created by: Alexander SOLOVYOV and Sergey LITONIN
// Copyright (c) 2003-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _MeshVS_DummySensitiveEntity_HeaderFile
#define _MeshVS_DummySensitiveEntity_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Select3D_BndBox3d.hxx>
#include <SelectBasics_SensitiveEntity.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <SelectBasics_SelectingVolumeManager.hxx>
class SelectBasics_EntityOwner;
//! This class allows to create owners to all elements or nodes,
//! both hidden and shown, but these owners user cannot select "by hands"
//! in viewer. They means for internal application tasks, for example, receiving
//! all owners, both for hidden and shown entities.
class MeshVS_DummySensitiveEntity : public SelectBasics_SensitiveEntity
{
public:
Standard_EXPORT MeshVS_DummySensitiveEntity (const Handle(SelectBasics_EntityOwner)& theOwnerId);
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
Standard_EXPORT virtual void Clear() Standard_OVERRIDE;
DEFINE_STANDARD_RTTI(MeshVS_DummySensitiveEntity)
};
DEFINE_STANDARD_HANDLE(MeshVS_DummySensitiveEntity, SelectBasics_SensitiveEntity)
#endif // _MeshVS_DummySensitiveEntity_HeaderFile

View File

@@ -29,9 +29,9 @@ uses
NameOfColor from Quantity,
Selection from SelectMgr,
EntityOwner from SelectMgr,
SequenceOfOwner from SelectMgr,
Selection from SelectMgr,
EntityOwner from SelectMgr,
SequenceOfOwner from SelectMgr,
Boolean from Standard,
CString from Standard,

View File

@@ -1,54 +0,0 @@
-- Created on: 2003-09-29
-- Created by: Alexander SOLOVYOV and Sergey LITONIN
-- Copyright (c) 2003-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class SensitiveFace from MeshVS inherits SensitiveFace from Select3D
---Purpose: This class provides custom sensitive face, which will be selected if it center is in rectangle.
uses
EntityOwner from SelectBasics,
Array1OfPnt from TColgp,
TypeOfSensitivity from Select3D,
Projector from Select3D,
Pnt from gp,
Pnt2d from gp,
Array1OfPnt2d from TColgp,
Box2d from Bnd
is
Create ( theOwner : EntityOwner from SelectBasics;
thePoints : Array1OfPnt from TColgp;
theSensType : TypeOfSensitivity from Select3D = Select3D_TOS_INTERIOR )
returns SensitiveFace from MeshVS;
Project( me: mutable; aProjector : Projector from Select3D ) is redefined;
Matches ( me: mutable; XMin, YMin, XMax, YMax: Real;
aTol: Real ) returns Boolean is redefined;
Matches ( me: mutable; Polyline: Array1OfPnt2d from TColgp;
aBox:Box2d; aTol: Real ) returns Boolean is redefined;
fields
myCentre : Pnt from gp is protected;
myProjCentre : Pnt2d from gp is protected;
end SensitiveFace;

View File

@@ -13,70 +13,26 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <MeshVS_SensitiveFace.ixx>
#include <MeshVS_SensitiveFace.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <Select3D_Projector.hxx>
#include <CSLib_Class2d.hxx>
#include <TopLoc_Location.hxx>
IMPLEMENT_STANDARD_HANDLE (MeshVS_SensitiveFace, Select3D_SensitiveEntity)
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveFace, Select3D_SensitiveEntity)
//=======================================================================
// name : MeshVS_SensitiveFace::MeshVS_SensitiveFace
// Purpose :
//=======================================================================
MeshVS_SensitiveFace::MeshVS_SensitiveFace (
const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePnts,
const Select3D_TypeOfSensitivity theSensitivity )
: Select3D_SensitiveFace( theOwnerId, thePnts, theSensitivity )
MeshVS_SensitiveFace::MeshVS_SensitiveFace (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePnts,
const Select3D_TypeOfSensitivity theSensitivity)
: Select3D_SensitiveFace (theOwnerId, thePnts, theSensitivity)
{
gp_XYZ c( 0, 0, 0 );
Standard_Integer nbPnts = thePnts.Upper() - thePnts.Lower() + 1;
for ( Standard_Integer i = thePnts.Lower(); i <= thePnts.Upper(); i++ )
c += thePnts( i ).XYZ();
myCentre.SetXYZ( c / nbPnts );
}
gp_XYZ aCenter (0.0, 0.0, 0.0);
Standard_Integer aNbPnts = thePnts.Upper() - thePnts.Lower() + 1;
for (Standard_Integer aPntIdx = thePnts.Lower(); aPntIdx <= thePnts.Upper(); aPntIdx++)
aCenter += thePnts (aPntIdx).XYZ();
//=======================================================================
// name : MeshVS_SensitiveFace::Project
// Purpose :
//=======================================================================
void MeshVS_SensitiveFace::Project( const Handle(Select3D_Projector)& aProj )
{
Select3D_SensitiveFace::Project( aProj );
if ( HasLocation() )
aProj->Project( myCentre.Transformed( Location().Transformation() ), myProjCentre );
else
aProj->Project( myCentre, myProjCentre );
}
//=======================================================================
// name : MeshVS_SensitiveFace::Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveFace::Matches( const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol )
{
Bnd_Box2d aBox;
aBox.Update( XMin-aTol, YMin-aTol, XMax+aTol, YMax+aTol );
return !aBox.IsOut( myProjCentre );
}
//=======================================================================
// name : MeshVS_SensitiveFace::Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveFace::Matches( const TColgp_Array1OfPnt2d& Polyline,
const Bnd_Box2d& aBox,
const Standard_Real aTol )
{
Standard_Real Umin, Vmin, Umax, Vmax;
aBox.Get ( Umin,Vmin,Umax,Vmax );
CSLib_Class2d aClassifier2d( Polyline, aTol, aTol, Umin, Vmin, Umax, Vmax );
Standard_Integer aRes = aClassifier2d.SiDans( myProjCentre );
return ( aRes == 1) ;
myCenter.SetXYZ (aCenter / aNbPnts);
}

View File

@@ -0,0 +1,49 @@
// Created on: 2003-09-29
// Created by: Alexander SOLOVYOV and Sergey LITONIN
// Copyright (c) 2003-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _MeshVS_SensitiveFace_HeaderFile
#define _MeshVS_SensitiveFace_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <gp_Pnt.hxx>
#include <Select3D_SensitiveFace.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Select3D_TypeOfSensitivity.hxx>
class SelectBasics_EntityOwner;
class TColgp_Array1OfPnt;
//! This class provides custom sensitive face, which will be selected if it center is in rectangle.
class MeshVS_SensitiveFace : public Select3D_SensitiveFace
{
public:
Standard_EXPORT MeshVS_SensitiveFace (const Handle(SelectBasics_EntityOwner)& theOwner,
const TColgp_Array1OfPnt& thePoints,
const Select3D_TypeOfSensitivity theSensType = Select3D_TOS_INTERIOR);
DEFINE_STANDARD_RTTI(MeshVS_SensitiveFace)
protected:
gp_Pnt myCenter;
};
DEFINE_STANDARD_HANDLE(MeshVS_SensitiveFace, Select3D_SensitiveFace)
#endif // _MeshVS_SensitiveFace_HeaderFile

View File

@@ -1,69 +0,0 @@
-- Created on: 2007-01-25
-- Created by: Sergey KOCHETKOV
-- Copyright (c) 2007-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class SensitiveMesh from MeshVS inherits SensitiveEntity from Select3D
---Purpose: This class provides custom mesh sensitive entity used in advanced mesh selection.
---It provides detection of mesh entities accordingly to activated selection mode
uses
EntityOwner from SelectBasics,
Array1OfPnt2d from TColgp,
Box from Bnd,
Box2d from Bnd,
Location from TopLoc,
Lin from gp,
ListOfBox2d from SelectBasics,
PickArgs from SelectBasics,
Projector from Select3D
is
Create ( theOwner : EntityOwner from SelectBasics;
theMode : Integer = 0 )
returns SensitiveMesh from MeshVS;
GetMode( me ) returns Integer from Standard;
GetConnected( me: mutable; aLocation : Location from TopLoc )
returns SensitiveEntity from Select3D is redefined;
Matches (me : mutable;
thePickArgs : PickArgs from SelectBasics;
theMatchDMin, theMatchDepth : out Real from Standard)
returns Boolean is redefined;
Matches ( me: mutable; XMin, YMin, XMax, YMax : Real;
aTol : Real ) returns Boolean
is redefined;
Matches ( me: mutable; Polyline : Array1OfPnt2d from TColgp;
aBox : Box2d;
aTol : Real ) returns Boolean
is redefined;
Project ( me:mutable; aProjector : Projector from Select3D ) is redefined static;
Areas ( me: mutable ; boxes : in out ListOfBox2d from SelectBasics ) is redefined static;
ProjectOneCorner( me: mutable; aProjector : Projector from Select3D;
X,Y,Z : Real from Standard ) is private;
fields
myMode : Integer from Standard;
mybox : Box from Bnd;
mybox2d : Box2d from Bnd;
end SensitiveMesh;

View File

@@ -13,15 +13,20 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <MeshVS_SensitiveMesh.ixx>
#include <MeshVS_SensitiveMesh.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColStd_Array1OfReal.hxx>
#include <TColStd_HPackedMapOfInteger.hxx>
#include <Select3D_Projector.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <TopLoc_Location.hxx>
#include <MeshVS_DataSource.hxx>
#include <MeshVS_MeshOwner.hxx>
#include <NCollection_Vec4.hxx>
IMPLEMENT_STANDARD_HANDLE (MeshVS_SensitiveMesh, Select3D_SensitiveEntity)
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveMesh, Select3D_SensitiveEntity)
//=======================================================================
// name : MeshVS_SensitiveMesh::MeshVS_SensitiveMesh
@@ -29,16 +34,24 @@
//=======================================================================
MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Standard_Integer theMode)
: Select3D_SensitiveEntity( theOwnerId )
: Select3D_SensitiveEntity (theOwnerId)
{
myMode = theMode;
mybox.SetVoid();
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId());
if( !anOwner.IsNull() )
{
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( !aDS.IsNull() )
mybox = aDS->GetBoundingBox();
if (!aDS.IsNull())
{
Bnd_Box aBox = aDS->GetBoundingBox();
Standard_Real aXMin, aYMin, aZMin;
Standard_Real aXMax, aYMax, aZMax;
aBox.Get (aXMin, aYMin, aZMin,
aXMax, aYMax, aZMax);
Select3D_Vec3 aMinPnt (aXMin, aYMin, aZMin);
Select3D_Vec3 aMaxPnt (aXMax, aYMax, aZMax);
myBndBox = Select3D_BndBox3d (aMinPnt, aMaxPnt);
}
}
}
@@ -46,159 +59,54 @@ MeshVS_SensitiveMesh::MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwne
// Function : GetMode
// Purpose :
//================================================================
Standard_Integer MeshVS_SensitiveMesh::GetMode () const
Standard_Integer MeshVS_SensitiveMesh::GetMode() const
{
return myMode;
}
//=======================================================================
// name : Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveMesh::Matches (const SelectBasics_PickArgs& thePickArgs,
Standard_Real& theMatchDMin,
Standard_Real& theMatchDepth)
{
theMatchDMin = 0.0;
theMatchDepth = Precision::Infinite();
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return Standard_False;
Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
if( aMeshPrs.IsNull() ) return Standard_False;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return Standard_False;
Handle(TColStd_HPackedMapOfInteger) NodesMap;
Handle(TColStd_HPackedMapOfInteger) ElemsMap;
// Mesh data source should provide the algorithm for computation
// of detected entities from 2D point
Standard_Boolean isDetected =
aDS->GetDetectedEntities (aMeshPrs, thePickArgs.X(), thePickArgs.Y(),
thePickArgs.Tolerance(), NodesMap,
ElemsMap, theMatchDMin);
// The detected entites will be available from mesh owner
anOwner->SetDetectedEntities( NodesMap, ElemsMap );
return isDetected;
}
//=======================================================================
// name : Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveMesh::Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return Standard_False;
Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
if( aMeshPrs.IsNull() ) return Standard_False;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return Standard_False;
Handle(TColStd_HPackedMapOfInteger) NodesMap;
Handle(TColStd_HPackedMapOfInteger) ElemsMap;
// Mesh data source should provide the algorithm for computation
// of detected entities from 2D box area
Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, XMin, YMin, XMax, YMax, aTol, NodesMap, ElemsMap );
// The detected entites will be available from mesh owner
anOwner->SetDetectedEntities( NodesMap, ElemsMap );
return isDetected;
}
//=======================================================================
// name : Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveMesh::Matches(const TColgp_Array1OfPnt2d& Polyline,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return Standard_False;
Handle(MeshVS_Mesh) aMeshPrs = Handle(MeshVS_Mesh)::DownCast( anOwner->Selectable() );
if( aMeshPrs.IsNull() ) return Standard_False;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return Standard_False;
Handle(TColStd_HPackedMapOfInteger) NodesMap;
Handle(TColStd_HPackedMapOfInteger) ElemsMap;
// Mesh data source should provide the algorithm for computation
// of detected entities from 2D polyline
Standard_Boolean isDetected = aDS->GetDetectedEntities( aMeshPrs, Polyline, aBox, aTol, NodesMap, ElemsMap );
// The detected entites will be available from mesh owner
anOwner->SetDetectedEntities( NodesMap, ElemsMap );
return isDetected;
}
//=======================================================================
// name : GetConnected
// Purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected( const TopLoc_Location& aLoc )
Handle(Select3D_SensitiveEntity) MeshVS_SensitiveMesh::GetConnected()
{
Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh( myOwnerId );
if(HasLocation()) aMeshEnt->SetLocation( Location() );
aMeshEnt->UpdateLocation( aLoc );
Handle(MeshVS_SensitiveMesh) aMeshEnt = new MeshVS_SensitiveMesh (myOwnerId);
return aMeshEnt;
}
//==================================================
// Function: ProjectOneCorner
// Purpose :
//==================================================
void MeshVS_SensitiveMesh::ProjectOneCorner(const Handle(Select3D_Projector)& theProj,
const Standard_Real theX,
const Standard_Real theY,
const Standard_Real theZ)
//=======================================================================
// function : NbSubElements
// purpose : Returns the amount of mesh nodes
//=======================================================================
Standard_Integer MeshVS_SensitiveMesh::NbSubElements()
{
gp_Pnt aPnt( theX, theY, theZ );
gp_Pnt2d aProjPnt;
if( HasLocation() )
theProj->Project( aPnt.Transformed(Location().Transformation()), aProjPnt );
else
theProj->Project( aPnt, aProjPnt );
mybox2d.Add( aProjPnt );
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast (OwnerId());
if (anOwner.IsNull())
return -1;
Handle(MeshVS_DataSource) aDataSource = anOwner->GetDataSource();
if (aDataSource.IsNull())
return -1;
return aDataSource->GetAllNodes().Extent();
}
//==================================================
// Function: Project
// Purpose :
//==================================================
void MeshVS_SensitiveMesh::Project(const Handle(Select3D_Projector)& aProj)
//=======================================================================
// function : BoundingBox
// purpose : Returns bounding box of mesh
//=======================================================================
Select3D_BndBox3d MeshVS_SensitiveMesh::BoundingBox()
{
mybox2d.SetVoid();
if (mybox.IsVoid())
return;
// Compute the 2D bounding box - projection of mesh bounding box
Handle(MeshVS_MeshOwner) anOwner = Handle(MeshVS_MeshOwner)::DownCast( OwnerId() );
if( anOwner.IsNull() ) return;
Handle(MeshVS_DataSource) aDS = anOwner->GetDataSource();
if( aDS.IsNull() ) return;
Standard_Real XMin, YMin, ZMin, XMax, YMax, ZMax;
mybox.Get( XMin, YMin, ZMin, XMax, YMax, ZMax );
ProjectOneCorner (aProj, XMin, YMin, ZMin);
ProjectOneCorner (aProj, XMin, YMin, ZMax);
ProjectOneCorner (aProj, XMin, YMax, ZMin);
ProjectOneCorner (aProj, XMin, YMax, ZMax);
ProjectOneCorner (aProj, XMax, YMin, ZMin);
ProjectOneCorner (aProj, XMax, YMin, ZMax);
ProjectOneCorner (aProj, XMax, YMax, ZMin);
ProjectOneCorner (aProj, XMax, YMax, ZMax);
return myBndBox;
}
//==================================================
// Function: Areas
// Purpose :
//==================================================
void MeshVS_SensitiveMesh::Areas( SelectBasics_ListOfBox2d& aSeq )
//=======================================================================
// function : CenterOfGeometry
// purpose : Returns center of mesh
//=======================================================================
gp_Pnt MeshVS_SensitiveMesh::CenterOfGeometry() const
{
aSeq.Append(mybox2d);
if (!myBndBox.IsValid())
return gp_Pnt (0.0, 0.0, 0.0);
SelectMgr_Vec3 aCenter = (myBndBox.CornerMax() + myBndBox.CornerMin()) * 0.5;
return gp_Pnt (aCenter.x(), aCenter.y(), aCenter.z());
}

View File

@@ -0,0 +1,63 @@
// Created on: 2007-01-29
// Created by: Sergey KOCHETKOV
// Copyright (c) 2007-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _MeshVS_SensitiveMesh_HeaderFile
#define _MeshVS_SensitiveMesh_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Bnd_Box.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Select3D_BndBox3d.hxx>
class SelectBasics_EntityOwner;
class Select3D_SensitiveEntity;
//! This class provides custom mesh sensitive entity used in advanced mesh selection.
class MeshVS_SensitiveMesh : public Select3D_SensitiveEntity
{
public:
Standard_EXPORT MeshVS_SensitiveMesh (const Handle(SelectBasics_EntityOwner)& theOwner,
const Standard_Integer theMode = 0);
Standard_EXPORT Standard_Integer GetMode() const;
Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
//! Returns the amount of mesh nodes
Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
//! Returns bounding box of mesh
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
//! Returns center of mesh
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
DEFINE_STANDARD_RTTI(MeshVS_SensitiveMesh)
private:
Standard_Integer myMode;
Select3D_BndBox3d myBndBox;
};
DEFINE_STANDARD_HANDLE(MeshVS_SensitiveMesh, Select3D_SensitiveEntity)
#endif // _MeshVS_SensitiveMesh_HeaderFile

View File

@@ -1,78 +0,0 @@
-- Created on: 2005-01-21
-- Created by: Alexander SOLOVYOV
-- Copyright (c) 2005-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class SensitivePolyhedron from MeshVS inherits SensitiveEntity from Select3D
uses
EntityOwner from SelectBasics,
Projector from Select3D,
Location from TopLoc,
Real from Standard,
Boolean from Standard,
Array1OfPnt2d from TColgp,
SequenceOfInteger from TColStd,
Box2d from Bnd,
Lin from gp,
ListOfBox2d from SelectBasics,
PickArgs from SelectBasics,
Array1OfPnt from TColgp,
HArray1OfPnt from TColgp,
HArray1OfPnt2d from TColgp,
HArray1OfSequenceOfInteger from MeshVS,
XY from gp
is
Create( Owner : EntityOwner from SelectBasics;
Nodes : Array1OfPnt from TColgp;
Topo : HArray1OfSequenceOfInteger from MeshVS ) returns SensitivePolyhedron from MeshVS;
Project( me:mutable; aProjector: Projector from Select3D ) is redefined;
GetConnected( me:mutable; aLocation: Location from TopLoc ) returns SensitiveEntity from Select3D
is redefined;
Matches (me : mutable;
thePickArgs : PickArgs from SelectBasics;
theMatchDMin, theMatchDepth : out Real from Standard)
returns Boolean is redefined;
Matches( me : mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol : Real from Standard ) returns Boolean from Standard is redefined;
Matches( me : mutable;
Polyline : Array1OfPnt2d from TColgp;
aBox : Box2d from Bnd;
aTol : Real from Standard ) returns Boolean from Standard is redefined;
GetBox2d( me; aBox : out Box2d from Bnd ) is protected;
FindIntersection( me; NodesIndices : SequenceOfInteger from TColStd;
EyeLine : Lin from gp ) returns Real is protected;
ComputeDepth( me; EyeLine: Lin from gp ) returns Real from Standard is virtual;
-- ComputeSize( me ) returns Real from Standard is redefined;
Areas( me: mutable; aResult : in out ListOfBox2d from SelectBasics ) is redefined;
fields
myNodes : HArray1OfPnt from TColgp;
myNodes2d : HArray1OfPnt2d from TColgp;
myTopo : HArray1OfSequenceOfInteger from MeshVS;
myCenter : XY from gp;
end SensitiveEntity;

View File

@@ -13,289 +13,118 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <MeshVS_SensitivePolyhedron.ixx>
#include <MeshVS_SensitivePolyhedron.hxx>
#include <gp_Lin.hxx>
#include <MeshVS_HArray1OfSequenceOfInteger.hxx>
#include <MeshVS_Tool.hxx>
#include <CSLib_Class2d.hxx>
#include <ElCLib.hxx>
#include <NCollection_Vec4.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <TColgp_Array1OfPnt2d.hxx>
#include <TColStd_SequenceOfInteger.hxx>
IMPLEMENT_STANDARD_HANDLE (MeshVS_SensitivePolyhedron, Select3D_SensitiveEntity)
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitivePolyhedron, Select3D_SensitiveEntity)
//================================================================
// Function : Constructor MeshVS_SensitivePolyhedron
// Purpose :
//================================================================
MeshVS_SensitivePolyhedron::
MeshVS_SensitivePolyhedron( const Handle( SelectBasics_EntityOwner )& Owner,
const TColgp_Array1OfPnt& Nodes,
const Handle( MeshVS_HArray1OfSequenceOfInteger )& Topo )
: Select3D_SensitiveEntity( Owner ),
myTopo( Topo )
MeshVS_SensitivePolyhedron::MeshVS_SensitivePolyhedron (const Handle(SelectBasics_EntityOwner)& theOwner,
const TColgp_Array1OfPnt& theNodes,
const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo)
: Select3D_SensitiveEntity (theOwner),
myTopo (theTopo)
{
Standard_Integer low = Nodes.Lower(), up = Nodes.Upper(), i;
Standard_Integer aPlaneLowIdx = theTopo->Lower();
Standard_Integer aPlaneUpIdx = theTopo->Upper();
Standard_Integer aNodesLowerIdx = theNodes.Lower();
myNodes = new TColgp_HArray1OfPnt (aNodesLowerIdx, theNodes.Upper());
myCenter = gp_XYZ (0.0, 0.0, 0.0);
myNodes = new TColgp_HArray1OfPnt ( low, up );
for( i=low; i<=up; i++ )
myNodes->SetValue( i, Nodes.Value( i ) );
myNodes2d = new TColgp_HArray1OfPnt2d( low, up );
}
//================================================================
// Function : Project
// Purpose :
//================================================================
void MeshVS_SensitivePolyhedron::Project( const Handle(Select3D_Projector)& aProjector )
{
if( myNodes.IsNull() || myNodes2d.IsNull() )
return;
Standard_Integer low = myNodes->Lower(),
up = myNodes->Upper();
gp_Pnt pnt;
gp_Pnt2d proj;
Standard_Boolean hasLoc = HasLocation();
myCenter = gp_XY( 0, 0 );
for( Standard_Integer i=low; i<=up; i++ )
for (Standard_Integer aPlaneIdx = aPlaneLowIdx; aPlaneIdx <= aPlaneUpIdx; ++aPlaneIdx)
{
pnt = myNodes->Value( i );
if( !hasLoc )
aProjector->Project( pnt, proj );
else
aProjector->Project( pnt.Transformed( Location().Transformation() ), proj );
Standard_Integer aVertNb = theTopo->Value (aPlaneIdx).Length();
Handle(TColgp_HArray1OfPnt) aVertArray = new TColgp_HArray1OfPnt (0, aVertNb - 1);
for (Standard_Integer aVertIdx = 1; aVertIdx <= aVertNb; ++aVertIdx)
{
Standard_Integer aNodeIdx = theTopo->Value (aPlaneIdx).Value (aVertIdx);
const gp_Pnt& aVert = theNodes.Value (aNodeIdx + aNodesLowerIdx);
aVertArray->SetValue (aVertIdx - 1, aVert);
myNodes->SetValue (aNodeIdx + aNodesLowerIdx, aVert);
myBndBox.Add (SelectMgr_Vec3 (aVert.X(), aVert.Y(), aVert.Z()));
myCenter += aVert.XYZ();
}
myNodes2d->SetValue( i, proj.XY() );
myCenter += proj.XY();
myTopology.Append (aVertArray);
}
myCenter /= ( up-low+1 );
myCenter.Divide (theNodes.Length());
}
//================================================================
// Function : GetConnected
// Purpose :
//================================================================
Handle( Select3D_SensitiveEntity ) MeshVS_SensitivePolyhedron::GetConnected
( const TopLoc_Location& aLocation )
Handle(Select3D_SensitiveEntity) MeshVS_SensitivePolyhedron::GetConnected()
{
Handle( MeshVS_SensitivePolyhedron ) NewEnt = new
MeshVS_SensitivePolyhedron( myOwnerId, myNodes->Array1(), myTopo );
Handle(MeshVS_SensitivePolyhedron) aNewEnt = new
MeshVS_SensitivePolyhedron (myOwnerId, myNodes->Array1(), myTopo);
if( HasLocation() )
NewEnt->SetLocation( Location() );
NewEnt->UpdateLocation( aLocation );
return NewEnt;
return aNewEnt;
}
//================================================================
// Function : sort
// Purpose :
//================================================================
void sort( Standard_Real& a, Standard_Real& b )
//=======================================================================
// function : Matches
// purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitivePolyhedron::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
if( a>b )
Standard_Real aDepthMin = RealLast();
Standard_Real aDistToCOG = RealLast();
for (MeshVS_PolyhedronVertsIter aIter (myTopology); aIter.More(); aIter.Next())
{
Standard_Real temp = a; a = b; b = temp;
}
}
//================================================================
// Function : Matches
// Purpose :
//================================================================
Standard_Boolean MeshVS_SensitivePolyhedron::Matches( const SelectBasics_PickArgs& thePickArgs,
Standard_Real& /*theMatchDMin*/,
Standard_Real& theMatchDepth )
{
if( myNodes2d.IsNull() || myTopo.IsNull() )
return Standard_False;
Standard_Integer R1 = myTopo->Lower(),
R2 = myTopo->Upper(),
low = myNodes2d->Lower();
Standard_Real rTol = thePickArgs.Tolerance() * SensitivityFactor();
Standard_Boolean inside = Standard_False;
// "odd-even" algorithm: with ray parallel axis of absciss and toward positive
for( Standard_Integer i=R1; i<=R2 && !inside; i++ )
{
Standard_Integer intersect = 0, cur, next, C1 = 1, C2 = myTopo->Value( i ).Length();
Standard_Real k, b, // y=kx+b -- equation of polygon's edge
x1, y1, x2, y2, xp; // auxiliary points
for( Standard_Integer j=C1; j<=C2; j++ )
Standard_Real aDepth = RealLast();
if (theMgr.Overlaps (aIter.Value(), Select3D_TOS_INTERIOR, aDepth))
{
cur = myTopo->Value( i ).Value( j );
next = myTopo->Value( i ).Value( j<C2 ? j+1 : C1 );
x1 = myNodes2d->Value( low+cur ).X(),
y1 = myNodes2d->Value( low+cur ).Y(),
x2 = myNodes2d->Value( low+next ).X(),
y2 = myNodes2d->Value( low+next ).Y();
if( Abs( x2-x1 )<Precision::Confusion() )
{
//vertical edge!!!
sort( y1, y2 );
if ( thePickArgs.Y() >= y1 - rTol && thePickArgs.Y() <= y2 + rTol && x1 > thePickArgs.X() - rTol )
intersect++;
}
else
{
//inclined edge!!!
k = ( y2-y1 ) / ( x2-x1 );
b = y1 - k*x1;
if( Abs( k )>Precision::Confusion() )
{
xp = ( thePickArgs.Y() - b ) / k; // absciss of point of intersection
sort( x1, x2 );
if( xp >= x1 && xp <= x2 && xp > thePickArgs.X() - rTol )
intersect++;
}
}
}
inside = ( intersect%2 ) == 1;
}
if( inside )
{
theMatchDepth = ComputeDepth (thePickArgs.PickLine());
return !thePickArgs.IsClipped(theMatchDepth);
}
return Standard_False;
}
//================================================================
// Function : Matches
// Purpose :
//================================================================
Standard_Boolean MeshVS_SensitivePolyhedron::Matches( const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol )
{
Standard_Real rTol = aTol*SensitivityFactor();
return myCenter.X()>=XMin-rTol && myCenter.X()<=XMax+rTol &&
myCenter.Y()>=YMin-rTol && myCenter.Y()<=YMax+rTol;
}
//================================================================
// Function : Matches
// Purpose :
//================================================================
Standard_Boolean MeshVS_SensitivePolyhedron::Matches
( const TColgp_Array1OfPnt2d& Polyline,
const Bnd_Box2d& aBox,
const Standard_Real aTol )
{
Standard_Real Umin, Vmin, Umax, Vmax;
aBox.Get( Umin, Vmin, Umax, Vmax );
CSLib_Class2d aClassifier2d( Polyline, aTol, aTol, Umin, Vmin, Umax, Vmax );
Standard_Integer res = aClassifier2d.SiDans( myCenter );
return( res==1 );
}
//================================================================
// Function : FindIntersection
// Purpose :
//================================================================
Standard_Real MeshVS_SensitivePolyhedron::FindIntersection
( const TColStd_SequenceOfInteger& NodesIndices,
const gp_Lin& EyeLine) const
{
Standard_Real val( Precision::Infinite() );
for( Standard_Integer i=1, n=NodesIndices.Length(); i<=n; i++ )
val = Min( val, ElCLib::Parameter(
EyeLine, myNodes->Value( myNodes->Lower()+NodesIndices.Value( i ) ) ) );
return val;
}
//================================================================
// Function : ComputeDepth
// Purpose :
//================================================================
Standard_Real MeshVS_SensitivePolyhedron::ComputeDepth( const gp_Lin& EyeLine ) const
{
Standard_Real val = Precision::Infinite();
if( !myTopo.IsNull() )
for( Standard_Integer i=myTopo->Lower(), up=myTopo->Upper(); i<=up; i++ )
val = Min( val, FindIntersection( myTopo->Value( i ), EyeLine ) );
return val;
}
//================================================================
// Function : ComputeSize
// Purpose :
//================================================================
/*Standard_Real MeshVS_SensitivePolyhedron::ComputeSize() const
{
Bnd_Box2d aBox;
GetBox2d( aBox );
Standard_Real aXmin, aYmin, aXmax, aYmax;
aBox.Get( aXmin, aYmin, aXmax, aYmax );
return Abs( ( aXmax-aXmin ) * ( aYmax-aYmin ) );
} */
//================================================================
// Function : Areas
// Purpose :
//================================================================
void MeshVS_SensitivePolyhedron::Areas( SelectBasics_ListOfBox2d& aResult )
{
Bnd_Box2d aBox;
GetBox2d( aBox );
aResult.Append( aBox );
}
//================================================================
// Function : GetBox2d
// Purpose :
//================================================================
void MeshVS_SensitivePolyhedron::GetBox2d( Bnd_Box2d& aBox ) const
{
aBox.SetVoid();
Standard_Real xmin = 0., ymin = 0., xmax = 0., ymax = 0., x, y;
Standard_Integer low = myNodes2d->Lower(),
up = myNodes2d->Upper();
if( !myNodes2d.IsNull() )
{
xmin = xmax = myNodes2d->Value( low ).X();
ymin = ymax = myNodes2d->Value( low ).Y();
for( Standard_Integer i=low+1; i<=up; i++ )
{
x = myNodes2d->Value( i ).X();
y = myNodes2d->Value( i ).Y();
if( x>xmax )
xmax = x;
else if( x<xmin )
xmin = x;
if( y>ymax )
ymax = y;
else if( y<ymin )
ymin = y;
aDepthMin = Min (aDepth, aDepthMin);
}
}
aBox.Update( xmin, ymin, xmax, ymax );
aDistToCOG = aDepthMin == RealLast() ? RealLast() : theMgr.DistToGeometryCenter (myCenter);
thePickResult = SelectBasics_PickResult (aDepthMin, aDistToCOG);
return aDepthMin != RealLast();
}
//=======================================================================
// function : NbSubElements
// purpose : Returns the amount of nodes of polyhedron
//=======================================================================
Standard_Integer MeshVS_SensitivePolyhedron::NbSubElements()
{
return myNodes->Length();
}
//=======================================================================
// function : BoundingBox
// purpose :
//=======================================================================
Select3D_BndBox3d MeshVS_SensitivePolyhedron::BoundingBox()
{
return myBndBox;
}
//=======================================================================
// function : CenterOfGeometry
// purpose :
//=======================================================================
gp_Pnt MeshVS_SensitivePolyhedron::CenterOfGeometry() const
{
return myCenter;
}

View File

@@ -0,0 +1,85 @@
// Created on: 2005-01-21
// Created by: Alexander SOLOVYOV
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _MeshVS_SensitivePolyhedron_HeaderFile
#define _MeshVS_SensitivePolyhedron_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Handle_TColgp_HArray1OfPnt.hxx>
#include <Handle_TColgp_HArray1OfPnt2d.hxx>
#include <Handle_MeshVS_HArray1OfSequenceOfInteger.hxx>
#include <gp_XY.hxx>
#include <NCollection_List.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Select3D_BndBox3d.hxx>
class TColgp_HArray1OfPnt;
class TColgp_HArray1OfPnt2d;
class MeshVS_HArray1OfSequenceOfInteger;
class SelectBasics_EntityOwner;
class TColgp_Array1OfPnt;
class Select3D_SensitiveEntity;
class TopLoc_Location;
class TColgp_Array1OfPnt2d;
class Bnd_Box2d;
class TColStd_SequenceOfInteger;
class gp_Lin;
class SelectBasics_ListOfBox2d;
typedef NCollection_List<Handle(TColgp_HArray1OfPnt)> MeshVS_PolyhedronVerts;
typedef NCollection_List<Handle(TColgp_HArray1OfPnt)>::Iterator MeshVS_PolyhedronVertsIter;
//! This class is used to detect selection of a polyhedron. The main
//! principle of detection algorithm is to search for overlap with
//! each polyhedron's face separately, treating them as planar convex
//! polygons.
class MeshVS_SensitivePolyhedron : public Select3D_SensitiveEntity
{
public:
Standard_EXPORT MeshVS_SensitivePolyhedron (const Handle(SelectBasics_EntityOwner)& theOwner,
const TColgp_Array1OfPnt& theNodes,
const Handle(MeshVS_HArray1OfSequenceOfInteger)& theTopo);
Standard_EXPORT virtual Handle_Select3D_SensitiveEntity GetConnected() Standard_OVERRIDE;
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
//! Returns the amount of nodes of polyhedron
Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
DEFINE_STANDARD_RTTI(MeshVS_SensitivePolyhedron)
private:
MeshVS_PolyhedronVerts myTopology;
gp_XYZ myCenter;
Select3D_BndBox3d myBndBox;
Handle(TColgp_HArray1OfPnt) myNodes;
Handle(MeshVS_HArray1OfSequenceOfInteger) myTopo;
};
DEFINE_STANDARD_HANDLE(MeshVS_SensitivePolyhedron, Select3D_SensitiveEntity)
#endif // _MeshVS_SensitivePolyhedron_HeaderFile

View File

@@ -1,53 +0,0 @@
-- Created on: 2003-09-29
-- Created by: Alexander SOLOVYOV and Sergey LITONIN
-- Copyright (c) 2003-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class SensitiveSegment from MeshVS inherits SensitiveSegment from Select3D
---Purpose: This class provides custom sensitive face, which will be selected if it center is in rectangle.
uses
EntityOwner from SelectBasics,
Array1OfPnt from TColgp,
TypeOfSensitivity from Select3D,
Projector from Select3D,
Pnt from gp,
Pnt2d from gp,
Array1OfPnt2d from TColgp,
Box2d from Bnd
is
Create ( theOwner : EntityOwner from SelectBasics;
theFirstP, theLastP : Pnt from gp;
theMaxRect : Integer = 1 ) returns SensitiveSegment from MeshVS;
Project( me: mutable; aProjector : Projector from Select3D ) is redefined;
Matches ( me: mutable; XMin, YMin, XMax, YMax: Real;
aTol: Real ) returns Boolean is redefined;
Matches ( me: mutable; Polyline: Array1OfPnt2d from TColgp;
aBox: Box2d; aTol: Real ) returns Boolean is redefined;
fields
myCentre : Pnt from gp is protected;
myProjCentre : Pnt2d from gp is protected;
end SensitiveSegment;

View File

@@ -13,66 +13,19 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <MeshVS_SensitiveSegment.ixx>
#include <Select3D_Projector.hxx>
#include <Bnd_Box2d.hxx>
#include <CSLib_Class2d.hxx>
#include <TopLoc_Location.hxx>
#include <MeshVS_SensitiveSegment.hxx>
#include <SelectBasics_EntityOwner.hxx>
IMPLEMENT_STANDARD_HANDLE (MeshVS_SensitiveSegment, Select3D_SensitiveSegment)
IMPLEMENT_STANDARD_RTTIEXT(MeshVS_SensitiveSegment, Select3D_SensitiveSegment)
//=======================================================================
// name : MeshVS_SensitiveSegment::MeshVS_SensitiveSegment
// Purpose :
//=======================================================================
MeshVS_SensitiveSegment::MeshVS_SensitiveSegment (
const Handle(SelectBasics_EntityOwner)& theOwnerId,
const gp_Pnt& theFirstP,
const gp_Pnt& theLastP,
const Standard_Integer theMaxRect )
: Select3D_SensitiveSegment( theOwnerId, theFirstP, theLastP, theMaxRect )
{
myCentre.SetXYZ( ( theFirstP.XYZ() + theLastP.XYZ() ) / 2 );
}
//=======================================================================
// name : MeshVS_SensitiveSegment::Project
// Purpose :
//=======================================================================
void MeshVS_SensitiveSegment::Project( const Handle(Select3D_Projector)& aProj )
{
Select3D_SensitiveSegment::Project( aProj );
if ( HasLocation() )
aProj->Project( myCentre.Transformed( Location().Transformation() ), myProjCentre );
else
aProj->Project( myCentre, myProjCentre );
}
//=======================================================================
// name : MeshVS_SensitiveSegment::Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveSegment::Matches( const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol )
{
Bnd_Box2d aBox;
aBox.Update( XMin-aTol, YMin-aTol, XMax+aTol, YMax+aTol );
return !aBox.IsOut( myProjCentre );
}
//=======================================================================
// name : MeshVS_SensitiveSegment::Matches
// Purpose :
//=======================================================================
Standard_Boolean MeshVS_SensitiveSegment::Matches( const TColgp_Array1OfPnt2d& Polyline,
const Bnd_Box2d& aBox,
const Standard_Real aTol )
{
Standard_Real Umin, Vmin, Umax, Vmax;
aBox.Get ( Umin,Vmin,Umax,Vmax );
CSLib_Class2d aClassifier2d( Polyline, aTol, aTol, Umin, Vmin, Umax, Vmax );
Standard_Integer aRes = aClassifier2d.SiDans( myProjCentre );
return ( aRes == 1) ;
}
MeshVS_SensitiveSegment::MeshVS_SensitiveSegment (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const gp_Pnt& theFirstPnt,
const gp_Pnt& theLastPnt)
: Select3D_SensitiveSegment (theOwnerId, theFirstPnt, theLastPnt)
{}

View File

@@ -0,0 +1,44 @@
// Created on: 2003-09-29
// Created by: Alexander SOLOVYOV and Sergey LITONIN
// Copyright (c) 2003-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _MeshVS_SensitiveSegment_HeaderFile
#define _MeshVS_SensitiveSegment_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <gp_Pnt.hxx>
#include <Select3D_SensitiveSegment.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
class SelectBasics_EntityOwner;
class gp_Pnt;
//! This class provides custom sensitive face, which will be selected if it center is in rectangle.
class MeshVS_SensitiveSegment : public Select3D_SensitiveSegment
{
public:
Standard_EXPORT MeshVS_SensitiveSegment (const Handle(SelectBasics_EntityOwner)& theOwner,
const gp_Pnt& theFirstPnt,
const gp_Pnt& theLastPnt);
DEFINE_STANDARD_RTTI(MeshVS_SensitiveSegment)
};
DEFINE_STANDARD_HANDLE(MeshVS_SensitiveSegment, Select3D_SensitiveSegment)
#endif // _MeshVS_SensitiveSegment_HeaderFile

View File

@@ -234,6 +234,10 @@ is
Transformation(me) returns any Trsf from gp;
---C++: inline
---C++: return const&
InversedTransformation(me) returns any Trsf from gp;
---C++: inline
---C++: return const&
ResetTransformation(me:mutable) is virtual;
---Purpose: resets local transformation to identity.
@@ -330,6 +334,7 @@ fields
myLocalTransformation : Trsf from gp; -- Own transformation of presentable object.
myTransformation : Trsf from gp; -- Combined transformation of presentable object.
myInvTransformation : Trsf from gp; -- Inverted combined transformation of presentable object.
myCombinedParentTransform : Trsf from gp; -- Combined transformation of presentable object excepting local transformation.
myChildren : ListOfPresentableObjects from PrsMgr; -- Child objects in scene hierarchy.

View File

@@ -269,6 +269,7 @@ void PrsMgr_PresentableObject::SetCombinedParentTransform (const gp_Trsf& theTra
void PrsMgr_PresentableObject::UpdateTransformation()
{
myTransformation = myCombinedParentTransform * myLocalTransformation;
myInvTransformation = myTransformation.Inverted();
Handle(Geom_Transformation) aTrsf = new Geom_Transformation (myTransformation);
for (Standard_Integer aPrsIter = 1; aPrsIter <= myPresentations.Length(); ++aPrsIter)

View File

@@ -28,6 +28,11 @@ inline const gp_Trsf& PrsMgr_PresentableObject::Transformation() const
return myTransformation;
}
inline const gp_Trsf& PrsMgr_PresentableObject::InversedTransformation() const
{
return myInvTransformation;
}
inline const PrsMgr_ListOfPresentableObjects& PrsMgr_PresentableObject::Children() const
{
return myChildren;

View File

@@ -5270,7 +5270,7 @@ Standard_Integer CR23234 (Draw_Interpretor& di, Standard_Integer argc, const cha
aisContext->OpenLocalContext();
//aisContext->ActivateStandardMode(TopAbs_ShapeEnum::TopAbs_EDGE);
aisContext->ActivateStandardMode(TopAbs_EDGE);
aisContext->SetSensitivity(8);
aisContext->SetPixelTolerance(8);
return 0; //TCL_OK
}

View File

@@ -117,7 +117,7 @@ static Standard_Integer OCC137 (Draw_Interpretor& di, Standard_Integer argc, con
const Handle(SelectMgr_Selection)& aSelection = AISObj->Selection(4);
if(!aSelection.IsNull()) {
for(aSelection->Init();aSelection->More();aSelection->Next()) {
Handle(StdSelect_BRepOwner) aO = Handle(StdSelect_BRepOwner)::DownCast(aSelection->Sensitive()->OwnerId());
Handle(StdSelect_BRepOwner) aO = Handle(StdSelect_BRepOwner)::DownCast(aSelection->Sensitive()->BaseSensitive()->OwnerId());
aO->SetHilightMode(Draw::Atoi(argv[1]));
}
}

View File

@@ -20,16 +20,12 @@ uses
PresentationManager3d from PrsMgr,
Presentation from Prs3d,
NameOfColor from Quantity,
Selection from SelectMgr
Selection from SelectMgr
is
Create(aText :ExtendedString from TCollection;aPosition : Pnt from gp)
returns MyText from QABugs;
Create(aText :ExtendedString from TCollection;aPosition : Pnt from gp;aFont : CString from Standard; aColor : NameOfColor from Quantity; aHeight :Real from Standard)
returns MyText from QABugs;
NbPossibleSelection(me)
returns Integer from Standard
is redefined virtual protected;
Compute(me:mutable;
aPresentationManager: PresentationManager3d from PrsMgr;

View File

@@ -77,10 +77,3 @@ void QABugs_MyText::ComputeSelection(const Handle(SelectMgr_Selection)& aSelecti
myPosition.Z() + 20);
aSelection->Add(box);
}
Standard_Integer QABugs_MyText::NbPossibleSelection() const
{
return 1;
}

View File

@@ -1,5 +1,43 @@
Select3D_Pnt.hxx
Select3D_Pnt2d.hxx
Select3D_Box2d.hxx
Select3D_Macro.hxx
Select3D_PointData.hxx
Select3D_PointData.hxx
Select3D_BoundarySensitivePointSet.hxx
Select3D_BoundarySensitivePointSet.cxx
Select3D_BndBox3d.hxx
Select3D_BVHPrimitiveContent.hxx
Select3D_BVHPrimitiveContent.cxx
Select3D_InteriorSensitivePointSet.hxx
Select3D_InteriorSensitivePointSet.cxx
Select3D_ISensitivePointSet.hxx
Select3D_EntitySequence.hxx
Select3D_SensitiveBox.hxx
Select3D_SensitiveBox.cxx
Select3D_SensitiveCircle.hxx
Select3D_SensitiveCircle.cxx
Select3D_SensitiveCurve.hxx
Select3D_SensitiveCurve.cxx
Select3D_SensitiveEntity.hxx
Select3D_SensitiveEntity.cxx
Select3D_SensitiveFace.hxx
Select3D_SensitiveFace.cxx
Select3D_SensitiveGroup.hxx
Select3D_SensitiveGroup.cxx
Select3D_SensitiveGroup.lxx
Select3D_SensitivePoint.hxx
Select3D_SensitivePoint.cxx
Select3D_SensitivePoly.hxx
Select3D_SensitivePoly.cxx
Select3D_SensitivePoly.lxx
Select3D_SensitiveSegment.hxx
Select3D_SensitiveSegment.cxx
Select3D_SensitiveSegment.lxx
Select3D_SensitiveSet.hxx
Select3D_SensitiveSet.cxx
Select3D_SensitiveTriangle.hxx
Select3D_SensitiveTriangle.cxx
Select3D_SensitiveTriangulation.hxx
Select3D_SensitiveTriangulation.cxx
Select3D_SensitiveTriangulation.lxx
Select3D_SensitiveWire.hxx
Select3D_SensitiveWire.cxx
Select3D_TypeOfSensitivity.hxx

View File

@@ -37,60 +37,34 @@ uses
TopLoc,
Geom,
SelectBasics,
SelectMgr,
V3d,
Graphic3d
is
---Category: sensitive entities
enumeration TypeOfSensitivity is TOS_INTERIOR,TOS_BOUNDARY
end TypeOfSensitivity;
---Purpose: Provides values for type of sensitivity in 3D.
-- These are used to specify whether it is the interior,
-- the boundary, or the exterior of a 3D sensitive entity which is sensitive.
deferred class SensitiveEntity;
deferred class SensitivePoly;
class SensitivePoint;
class SensitiveSegment;
class SensitiveCircle;
class SensitiveCurve;
class SensitiveTriangle;
class SensitiveTriangulation;
class SensitiveFace;
class SensitiveBox;
class SensitiveWire;
class SensitiveGroup;
class SensitiveEntitySequence instantiates Sequence from TCollection
(SensitiveEntity from Select3D);
---Category: selectors/projectors
class Projector;
class ListOfSensitiveTriangle instantiates List from TCollection
(SensitiveTriangle from Select3D);
class ListOfSensitive instantiates List from TCollection
(SensitiveEntity from Select3D);
imported BndBox3d;
imported BoundarySensitivePointSet;
imported BVHPrimitiveContent;
imported InteriorSensitivePointSet;
imported ISensitivePointSet;
imported EntitySequence;
imported Pnt;
imported Pnt2d;
imported Box2d;
imported PointData;
imported SelectingVolumeManager;
imported SensitiveBox;
imported SensitiveCircle;
imported SensitiveCurve;
imported transient class SensitiveEntity;
imported SensitiveFace;
imported SensitiveGroup;
imported SensitivePoint;
imported SensitivePoly;
imported SensitiveSegment;
imported SensitiveSet;
imported SensitiveTriangle;
imported SensitiveTriangulation;
imported SensitiveWire;
imported TypeOfSensitivity;
end Select3D;

View File

@@ -0,0 +1,80 @@
// Created on: 2014-05-30
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <BVH_LinearBuilder.hxx>
#include <Select3D_SensitiveSet.hxx>
#include <Select3D_BVHPrimitiveContent.hxx>
//=======================================================================
// function : Select3D_BVHPrimitiveContent
// purpose : Initializes new linear BVH builder for the set of sensitives
// theSensitiveSet given
//=======================================================================
Select3D_BVHPrimitiveContent::Select3D_BVHPrimitiveContent (const Handle(Select3D_SensitiveSet)& theSensitiveSet)
{
mySensitiveSet = theSensitiveSet;
myBuilder = new BVH_LinearBuilder<Standard_Real, 3> (8, 32);
MarkDirty();
}
//=======================================================================
// function : Size
// purpose : Returns the length of set of sensitives
//=======================================================================
Standard_Integer Select3D_BVHPrimitiveContent::Size() const
{
return mySensitiveSet->Size();
}
//=======================================================================
// function : Box
// purpose : Returns bounding box of sensitive with index theIdx
//=======================================================================
Select3D_BndBox3d Select3D_BVHPrimitiveContent::Box (const Standard_Integer theIdx) const
{
return mySensitiveSet->Box (theIdx);
}
//=======================================================================
// function : Center
// purpose : Returns center of sensitive with index theIdx in the set
// along the given axis theAxis
//=======================================================================
Standard_Real Select3D_BVHPrimitiveContent::Center (const Standard_Integer theIdx,
const Standard_Integer theAxis) const
{
return mySensitiveSet->Center (theIdx, theAxis);
}
//=======================================================================
// function : Swap
// purpose : Swaps items with indexes theIdx1 and theIdx2 in the set
//=======================================================================
void Select3D_BVHPrimitiveContent::Swap (const Standard_Integer theIdx1,
const Standard_Integer theIdx2)
{
mySensitiveSet->Swap (theIdx1, theIdx2);
}
//=======================================================================
// function : GetBVH
// purpose : Returns the tree built for set of sensitives
//=======================================================================
const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& Select3D_BVHPrimitiveContent::GetBVH()
{
return BVH();
}

View File

@@ -0,0 +1,57 @@
// Created on: 2014-05-30
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_BVHPrimitiveContent_Header
#define _Select3D_BVHPrimitiveContent_Header
#include <BVH_PrimitiveSet.hxx>
class Select3D_SensitiveSet;
//! The purpose of this class is to provide a link between BVH_PrimitiveSet
//! and Select3D_SensitiveSet instance to build BVH tree for set of sensitives
class Select3D_BVHPrimitiveContent : public BVH_PrimitiveSet<Standard_Real, 3>
{
public:
//! Initializes new linear BVH builder for the set of sensitives
//! theSensitiveSet given
Select3D_BVHPrimitiveContent (const Handle(Select3D_SensitiveSet)& theSensitiveSet);
~Select3D_BVHPrimitiveContent() {};
//! Returns the length of set of sensitives
Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
//! Returns bounding box of sensitive with index theIdx
Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
//! Returns center of sensitive with index theIdx in the set along the
//! given axis theAxis
Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
const Standard_Integer theAxis) const Standard_OVERRIDE;
//! Swaps items with indexes theIdx1 and theIdx2 in the set
Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
const Standard_Integer theIdx2) Standard_OVERRIDE;
//! Returns the tree built for set of sensitives
Standard_EXPORT const NCollection_Handle<BVH_Tree<Standard_Real, 3> >& GetBVH();
protected:
Handle(Select3D_SensitiveSet) mySensitiveSet; //!< Set of sensitive entities
};
#endif // _Select3D_BVHPrimitiveContent_Header

View File

@@ -1,4 +1,6 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
// Created on: 2014-29-05
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
@@ -11,5 +13,17 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
inline Standard_Integer Select3D_SensitiveCurve::GetLastDetected() const
{return mylastseg;}
#ifndef _Select3D_BndBox3d_Header
#define _Select3D_BndBox3d_Header
#include <BVH_Box.hxx>
#include <BVH_Types.hxx>
#include <gp_Trsf.hxx>
#include <NCollection_Vector.hxx>
typedef BVH_Box<Standard_Real, 3> Select3D_BndBox3d;
typedef NCollection_Vec3<Standard_Real> Select3D_Vec3;
#endif // _Select3D_BndBox3d_Header

View File

@@ -0,0 +1,95 @@
// Created on: 2014-11-10
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Select3D_BoundarySensitivePointSet.hxx>
//=======================================================================
// function : Select3D_BoundarySensitivePointSet
// purpose : Creates new instance of Select3D_SensitivePoly with BVH tree
// required and initializes it with the given array of points
//=======================================================================
Select3D_BoundarySensitivePointSet::Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints)
: Select3D_SensitivePoly (OwnerId, ThePoints, Standard_True)
{}
//=======================================================================
// function : Select3D_BoundarySensitivePointSet
// purpose : Creates new instance of Select3D_SensitivePoly with BVH tree
// required and initializes it with the given array of points
//=======================================================================
Select3D_BoundarySensitivePointSet::Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints)
: Select3D_SensitivePoly (OwnerId, ThePoints, Standard_True)
{}
//=======================================================================
// function : Matches
// purpose : Checks whether the point set overlaps current selecting
// volume
//=======================================================================
Standard_Boolean Select3D_BoundarySensitivePointSet::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
return Select3D_SensitivePoly::Matches (theMgr, thePickResult);
}
//=======================================================================
// function : GetPoints
// purpose : Initializes the given array theHArrayOfPnt by 3d
// coordinates of vertices of the point set
//=======================================================================
void Select3D_BoundarySensitivePointSet::GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt)
{
Points3D (theHArrayOfPnt);
}
//=======================================================================
// function : BoundingBox
// purpose : Returns bounding box of the point set. If location transformation
// is set, it will be applied
//=======================================================================
Select3D_BndBox3d Select3D_BoundarySensitivePointSet::BoundingBox()
{
return Select3D_SensitivePoly::BoundingBox();
}
//=======================================================================
// function : CenterOfGeometry
// purpose : Returns center of the point set. If location transformation
// is set, it will be applied
//=======================================================================
gp_Pnt Select3D_BoundarySensitivePointSet::CenterOfGeometry() const
{
return Select3D_SensitivePoly::CenterOfGeometry();
}
//=======================================================================
// function : BVH
// purpose : Builds BVH tree for the point set
//=======================================================================
void Select3D_BoundarySensitivePointSet::BVH()
{
Select3D_SensitivePoly::BVH();
}
//=======================================================================
// function : NbSubElements
// purpose : Returns the amount of points in set
//=======================================================================
Standard_Integer Select3D_BoundarySensitivePointSet::NbSubElements()
{
return Select3D_SensitivePoly::NbSubElements();
}

View File

@@ -0,0 +1,67 @@
// Created on: 2014-08-15
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_BoundarySensitivePointSet_HeaderFile
#define _Select3D_BoundarySensitivePointSet_HeaderFile
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Handle_TColgp_HArray1OfPnt.hxx>
#include <Select3D_ISensitivePointSet.hxx>
#include <Select3D_SensitivePoly.hxx>
class SelectBasics_EntityOwner;
class TColgp_Array1OfPnt;
class TColgp_HArray1OfPnt;
//! This class handles the selection of arbitrary point set with boundary type of sensitivity.
class Select3D_BoundarySensitivePointSet : public Select3D_ISensitivePointSet, public Select3D_SensitivePoly
{
public:
//! Creates new instance of Select3D_SensitivePoly with BVH tree
//! required and initializes it with the given array of points
Standard_EXPORT Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints);
//! Creates new instance of Select3D_SensitivePoly with BVH tree
//! required and initializes it with the given array of points
Standard_EXPORT Select3D_BoundarySensitivePointSet (const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints);
//! Checks whether the point set overlaps current selecting volume
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
//! Initializes the given array theHArrayOfPnt by 3d coordinates
//! of vertices of the point set
Standard_EXPORT virtual void GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt) Standard_OVERRIDE;
//! Returns bounding box of the point set. If there is a
//! location transformation set, it will be applied
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
//! Returns center of the point set. If there is a
//! location transformation set, it will be applied
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
//! Builds BVH tree for the point set
Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
//! Returns the amount of points in set
Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
};
#endif // _Select3D_BoundarySensitivePointSet_HeaderFile

View File

@@ -1,95 +0,0 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_Box2d_HeaderFile
#define _Select3D_Box2d_HeaderFile
#include<Bnd_Box2d.hxx>
#include<Standard_ShortReal.hxx>
#include<Select3D_Macro.hxx>
struct Select3D_Box2d
{
Standard_ShortReal xmin, ymin, xmax, ymax;
Select3D_Box2d()
: xmin( ShortRealLast() ),
ymin( ShortRealLast() ),
xmax( ShortRealFirst() ),
ymax( ShortRealFirst() )
{
}
Select3D_Box2d(const Bnd_Box2d& theBox)
{
SetField(theBox);
}
inline operator Bnd_Box2d() const
{
Bnd_Box2d aBox;
aBox.SetVoid();
if( !IsVoid() )
aBox.Update(xmin, ymin, xmax, ymax);
return aBox;
}
inline Select3D_Box2d operator = ( const Bnd_Box2d& theBox)
{
SetField(theBox);
return *this;
}
inline void Update(const gp_Pnt2d& thePnt)
{
Bnd_Box2d aBox;
aBox.Set(thePnt);
if( !IsVoid() )
aBox.Update(xmin, ymin, xmax, ymax);
SetField(aBox);
}
inline void SetVoid()
{
xmin = ymin = ShortRealLast();
xmax = ymax = ShortRealFirst();
}
inline Standard_Boolean IsVoid() const
{
return ( xmin == ShortRealLast() && ymin == ShortRealLast() && xmax == ShortRealFirst() && ymax == ShortRealFirst() );
}
private:
inline void SetField(const Bnd_Box2d& theBox)
{
if( theBox.IsVoid() )
SetVoid();
else {
Standard_Real x, y, x1, y1;
theBox.Get(x, y, x1, y1);
xmin = DToF(x);
ymin = DToF(y);
xmax = DToF(x1);
ymax = DToF(y1);
}
}
};
#endif

View File

@@ -0,0 +1,11 @@
#ifndef _Select3D_EntitySequence_Header
#define _Select3D_EntitySequence_Header
#include <NCollection_Sequence.hxx>
class Handle(Select3D_SensitiveEntity);
typedef NCollection_Sequence<Handle(Select3D_SensitiveEntity)> Select3D_EntitySequence;
typedef NCollection_Sequence<Handle(Select3D_SensitiveEntity)>::Iterator Select3D_EntitySequenceIter;
#endif // _Select3D_EntitySequence_Header

View File

@@ -0,0 +1,70 @@
// Created on: 2014-08-15
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_ISensitivePointSet_HeaderFile
#define _Select3D_ISensitivePointSet_HeaderFile
#include <Standard.hxx>
#include <Standard_Boolean.hxx>
#include <Standard_OStream.hxx>
#include <Standard_Real.hxx>
#include <Select3D_BndBox3d.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <SelectBasics_PickResult.hxx>
#include <SelectBasics_SelectingVolumeManager.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Handle_TColgp_HArray1OfPnt.hxx>
class gp_Pnt;
class Standard_ConstructionError;
class Standard_OutOfRange;
class TColgp_Array1OfPnt;
class TColgp_HArray1OfPnt;
class TColgp_Array1OfPnt2d;
class TopLoc_Location;
//! Interface class to unify the work with both internal and boundary
//! sensitive sets of points.
class Select3D_ISensitivePointSet
{
public:
//! Checks whether the point set overlaps current selecting volume
virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) = 0;
//! Initializes the given array theHArrayOfPnt by 3d coordinates
//! of vertices of the point set
virtual void GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt) = 0;
//! Returns bounding box of the point set. If location
//! transformation is set, it will be applied
virtual Select3D_BndBox3d BoundingBox() = 0;
//! Returns center of the point set. If location
//! transformation is set, it will be applied
virtual gp_Pnt CenterOfGeometry() const = 0;
//! Builds BVH tree for the point set
virtual void BVH() = 0;
//! Returns the amount of points in set
virtual Standard_Integer NbSubElements() = 0;
};
#endif // _Select3D_ISensitivePointSet_HeaderFile

View File

@@ -0,0 +1,418 @@
// Created on: 2014-08-15
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <gp_Pnt.hxx>
#include <gp_XYZ.hxx>
#include <TColgp_Array1OfPnt.hxx>
#include <TColgp_HArray1OfPnt.hxx>
#include <Select3D_InteriorSensitivePointSet.hxx>
// Internal class for creation of planar polygons
class Select3D_Plane
{
public:
Select3D_Plane()
: myPlane (0.0),
myIsInitialized (Standard_False)
{}
Standard_Boolean Contains (const gp_Pnt& thePnt) const
{
if (!myIsInitialized)
return Standard_False;
Standard_Real aRes = myPlane.x() * thePnt.X() +
myPlane.y() * thePnt.Y() +
myPlane.z() * thePnt.Z() +
myPlane.w();
if (aRes < Precision::Confusion())
return Standard_True;
return Standard_False;
}
void MakePlane (const gp_Pnt& thePnt1,
const gp_Pnt& thePnt2,
const gp_Pnt& thePnt3)
{
const gp_XYZ& aVec1 = thePnt2.XYZ() - thePnt1.XYZ();
const gp_XYZ& aVec2 = thePnt3.XYZ() - thePnt1.XYZ();
const gp_XYZ& aDir = aVec1.Crossed (aVec2);
Standard_Real aD = aDir.Dot (thePnt1.XYZ().Reversed());
myPlane = NCollection_Vec4<Standard_Real> (aDir.X(), aDir.Y(), aDir.Z(), aD);
myIsInitialized = Standard_True;
}
void Invalidate()
{
myIsInitialized = Standard_False;
}
Standard_Boolean IsValid() const
{
return myIsInitialized;
}
private:
NCollection_Vec4<Standard_Real> myPlane;
Standard_Boolean myIsInitialized;
};
// =======================================================================
// function : Select3D_InteriorSensitivePointSet
// purpose : Splits the given point set thePoints onto planar convex
// polygons
// =======================================================================
Select3D_InteriorSensitivePointSet::Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePoints)
: Select3D_SensitiveSet (theOwnerId)
{
Select3D_Plane aPlane;
Standard_Integer aStartIdx = 1, anEndIdx = 0;
Standard_Integer aLowerIdx = thePoints.Lower();
Standard_Integer anUpperIdx = thePoints.Upper();
Select3D_BndBox3d aBndBox;
gp_XYZ aPntSum (0.0, 0.0, 0.0);
if (thePoints.Length() > 3)
{
for (Standard_Integer aPntIter = aLowerIdx; aPntIter <= anUpperIdx; ++aPntIter)
{
gp_Pnt aPnt1, aPnt2;
const gp_Pnt& aPnt3 = thePoints.Value (aPntIter);
aBndBox.Add (SelectMgr_Vec3 (aPnt3.X(), aPnt3.Y(), aPnt3.Z()));
aPntSum += aPnt3.XYZ();
if (aPntIter - aLowerIdx >= 2)
{
aPnt1 = thePoints.Value (aPntIter - 2);
aPnt2 = thePoints.Value (aPntIter - 1);
}
if (aPntIter - aStartIdx == 2 && !aPlane.IsValid())
{
aPlane.MakePlane (aPnt1, aPnt2, aPnt3);
aStartIdx = aPntIter - 2;
anEndIdx = aPntIter;
}
else if (aPlane.IsValid())
{
const gp_XYZ& aVec1 = aPnt1.XYZ() - aPnt2.XYZ();
const gp_XYZ& aVec2 = aPnt3.XYZ() - aPnt2.XYZ();
Standard_Real anAngle = aVec1.Dot (aVec2);
if (!aPlane.Contains (thePoints.Value (aPntIter)) || anAngle > Precision::Confusion())
{
Standard_Integer anUpperBound = aPntIter - aStartIdx;
Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anUpperBound);
for (Standard_Integer aIdx = aStartIdx; aIdx <= aStartIdx + anUpperBound; ++aIdx)
{
aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value (aIdx));
}
Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
aPointsArray,
Standard_False);
myPlanarPolygons.Append (aPlanarPolyg);
aStartIdx = aPntIter;
anEndIdx = aPntIter;
aPlane.Invalidate();
}
else
{
if (anEndIdx == anUpperIdx)
{
Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anEndIdx - aStartIdx);
for (Standard_Integer aIdx = aStartIdx; aIdx <= anEndIdx; ++aIdx)
{
aPointsArray->SetValue (aIdx - aStartIdx, thePoints.Value (aIdx));
}
Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
aPointsArray,
Standard_False);
myPlanarPolygons.Append (aPlanarPolyg);
}
anEndIdx++;
}
}
}
}
else
{
Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, 2);
const gp_Pnt& aPnt1 = thePoints.Value (aLowerIdx);
const gp_Pnt& aPnt2 = thePoints.Value (aLowerIdx + 1);
const gp_Pnt& aPnt3 = thePoints.Value (aLowerIdx + 2);
aPointsArray->SetValue (0, aPnt1);
aPointsArray->SetValue (1, aPnt2);
aPointsArray->SetValue (2, aPnt3);
aBndBox.Add (SelectMgr_Vec3 (aPnt1.X(), aPnt1.Y(), aPnt1.Z()));
aBndBox.Add (SelectMgr_Vec3 (aPnt2.X(), aPnt2.Y(), aPnt2.Z()));
aBndBox.Add (SelectMgr_Vec3 (aPnt3.X(), aPnt3.Y(), aPnt3.Z()));
aPntSum += aPnt1.XYZ() + aPnt2.XYZ() + aPnt3.XYZ();
Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
aPointsArray,
Standard_False);
myPlanarPolygons.Append (aPlanarPolyg);
}
myPolygonsIdxs = new TColStd_HArray1OfInteger (0, myPlanarPolygons.Length() - 1);
for (Standard_Integer aIdx = 0; aIdx < myPlanarPolygons.Length(); ++aIdx)
{
myPolygonsIdxs->SetValue (aIdx, aIdx);
}
myCOG = aPntSum / thePoints.Length();
myBndBox = aBndBox;
}
// =======================================================================
// function : Select3D_InteriorSensitivePointSet
// purpose : Splits the given point set thePoints onto planar convex
// polygons
// =======================================================================
Select3D_InteriorSensitivePointSet::Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(TColgp_HArray1OfPnt)& thePoints)
: Select3D_SensitiveSet (theOwnerId)
{
Select3D_Plane aPlane;
Standard_Integer aLowerIdx = thePoints->Lower();
Standard_Integer anUpperIdx = thePoints->Upper();
Standard_Integer aStartIdx = aLowerIdx, anEndIdx = 0;
Select3D_BndBox3d aBndBox;
gp_XYZ aPntSum (0.0, 0.0, 0.0);
for (Standard_Integer aPntIter = aLowerIdx; aPntIter <= anUpperIdx; ++aPntIter)
{
gp_Pnt aPnt1, aPnt2;
const gp_Pnt& aPnt3 = thePoints->Value (aPntIter);
aPntSum += aPnt3.XYZ();
SelectMgr_Vec3 aCurrPnt (aPnt3.X(), aPnt3.Y(), aPnt3.Z());
aBndBox.Add (aCurrPnt);
if (aPntIter - aLowerIdx >= 2)
{
aPnt1 = thePoints->Value (aPntIter - 2);
aPnt2 = thePoints->Value (aPntIter - 1);
}
if (aPntIter - aStartIdx == 2 && !aPlane.IsValid())
{
aPlane.MakePlane (aPnt1, aPnt2, aPnt3);
aStartIdx = aPntIter - 2;
anEndIdx = aPntIter;
}
else if (aPlane.IsValid())
{
const gp_XYZ& aVec1 = aPnt1.XYZ() - aPnt2.XYZ();
const gp_XYZ& aVec2 = aPnt3.XYZ() - aPnt2.XYZ();
Standard_Real anAngle = aVec1.Dot (aVec2);
if (!aPlane.Contains (thePoints->Value (aPntIter)) || anAngle > Precision::Confusion())
{
Standard_Integer anUpperBound = aPntIter - aStartIdx;
Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anUpperBound);
for (Standard_Integer aIdx = aStartIdx; aIdx <= aStartIdx + anUpperBound; ++aIdx)
{
aPointsArray->SetValue (aIdx - aStartIdx, thePoints->Value (aIdx));
}
Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
aPointsArray,
Standard_False);
myPlanarPolygons.Append (aPlanarPolyg);
aStartIdx = aPntIter;
anEndIdx = aPntIter;
aPlane.Invalidate();
}
else
{
anEndIdx++;
if (anEndIdx == anUpperIdx)
{
Handle (TColgp_HArray1OfPnt) aPointsArray = new TColgp_HArray1OfPnt (0, anEndIdx - aStartIdx);
for (Standard_Integer aIdx = aStartIdx; aIdx <= anEndIdx; ++aIdx)
{
aPointsArray->SetValue (aIdx - aStartIdx, thePoints->Value (aIdx));
}
Handle(Select3D_SensitivePoly) aPlanarPolyg = new Select3D_SensitivePoly (theOwnerId,
aPointsArray,
Standard_False);
myPlanarPolygons.Append (aPlanarPolyg);
}
}
}
}
myPolygonsIdxs = new TColStd_HArray1OfInteger (0, myPlanarPolygons.Length() - 1);
for (Standard_Integer aIdx = 0; aIdx < myPlanarPolygons.Length(); ++aIdx)
{
myPolygonsIdxs->SetValue (aIdx, aIdx);
}
myCOG = aPntSum / thePoints->Length();
myBndBox = aBndBox;
}
// =======================================================================
// function : Matches
// purpose : Checks whether the point set overlaps current selecting
// volume
// =======================================================================
Standard_Boolean Select3D_InteriorSensitivePointSet::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
return Select3D_SensitiveSet::Matches (theMgr, thePickResult);
}
// =======================================================================
// function : GetPoints
// purpose : Initializes the given array theHArrayOfPnt by 3d
// coordinates of vertices of the whole point set
// =======================================================================
void Select3D_InteriorSensitivePointSet::GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt)
{
Standard_Integer aSize = 0;
for (Standard_Integer anIdx = 0; anIdx < myPlanarPolygons.Length(); ++anIdx)
{
const Handle(Select3D_SensitivePoly)& aPolygon = myPlanarPolygons.Value (anIdx);
aSize += aPolygon->NbSubElements();
}
aSize -= (myPlanarPolygons.Length() - 1) * 2;
theHArrayOfPnt = new TColgp_HArray1OfPnt (1, aSize);
Standard_Integer anOutputPntArrayIdx = 1;
for (Standard_Integer aPolygIdx = 0; aPolygIdx < myPlanarPolygons.Length(); ++aPolygIdx)
{
const Handle(Select3D_SensitivePoly)& aPolygon = myPlanarPolygons.Value (aPolygIdx);
Handle(TColgp_HArray1OfPnt) aPoints;
aPolygon->Points3D (aPoints);
Standard_Integer anUpper = aPolygIdx < myPlanarPolygons.Length() - 1 ? aPoints->Upper() : aPoints->Upper() + 1;
for (Standard_Integer aPntIter = 1; aPntIter < anUpper; ++aPntIter)
{
theHArrayOfPnt->SetValue (anOutputPntArrayIdx, aPoints->Value (aPntIter));
anOutputPntArrayIdx++;
}
aPoints.Nullify();
}
}
//=======================================================================
// function : Size
// purpose : Returns the length of vector of planar convex polygons
//=======================================================================
Standard_Integer Select3D_InteriorSensitivePointSet::Size() const
{
return myPlanarPolygons.Length();
}
//=======================================================================
// function : Box
// purpose : Returns bounding box of planar convex polygon with index
// theIdx
//=======================================================================
Select3D_BndBox3d Select3D_InteriorSensitivePointSet::Box (const Standard_Integer theIdx) const
{
Standard_Integer aPolygIdx = myPolygonsIdxs->Value (theIdx);
return myPlanarPolygons.Value (aPolygIdx)->BoundingBox();
}
//=======================================================================
// function : Center
// purpose : Returns geometry center of planar convex polygon with index
// theIdx in the vector along the given axis theAxis
//=======================================================================
Standard_Real Select3D_InteriorSensitivePointSet::Center (const Standard_Integer theIdx,
const Standard_Integer theAxis) const
{
Standard_Integer aPolygIdx = myPolygonsIdxs->Value (theIdx);
const gp_XYZ& aCOG = myPlanarPolygons.Value (aPolygIdx)->CenterOfGeometry().XYZ();
Standard_Real aCenter = theAxis == 0 ? aCOG.X() : (theAxis == 1 ? aCOG.Y() : aCOG.Z());
return aCenter;
}
//=======================================================================
// function : Swap
// purpose : Swaps items with indexes theIdx1 and theIdx2 in the vector
//=======================================================================
void Select3D_InteriorSensitivePointSet::Swap (const Standard_Integer theIdx1,
const Standard_Integer theIdx2)
{
Standard_Integer aPolygIdx1 = myPolygonsIdxs->Value (theIdx1);
Standard_Integer aPolygIdx2 = myPolygonsIdxs->Value (theIdx2);
myPolygonsIdxs->ChangeValue (theIdx1) = aPolygIdx2;
myPolygonsIdxs->ChangeValue (theIdx2) = aPolygIdx1;
}
// =======================================================================
// function : overlapsElement
// purpose : Checks whether the planar convex polygon with index theIdx
// in myPlanarPolygons overlaps the current selecting volume
// =======================================================================
Standard_Boolean Select3D_InteriorSensitivePointSet::overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
Standard_Integer theElemIdx,
Standard_Real& theMatchDepth)
{
Standard_Integer aPolygIdx = myPolygonsIdxs->Value (theElemIdx);
const Handle(Select3D_SensitivePoly)& aPolygon = myPlanarPolygons.Value (aPolygIdx);
Handle(TColgp_HArray1OfPnt) aPoints;
aPolygon->Points3D (aPoints);
return theMgr.Overlaps (aPoints, Select3D_TOS_INTERIOR, theMatchDepth);
}
// =======================================================================
// function : distanceToCOG
// purpose : Calculates distance from the 3d projection of used-picked
// screen point to center of the geometry
// =======================================================================
Standard_Real Select3D_InteriorSensitivePointSet::distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr)
{
return theMgr.DistToGeometryCenter (myCOG);
}
//=======================================================================
// function : BoundingBox
// purpose : Returns bounding box of the point set. If location
// transformation is set, it will be applied
//=======================================================================
Select3D_BndBox3d Select3D_InteriorSensitivePointSet::BoundingBox()
{
return myBndBox;
}
//=======================================================================
// function : CenterOfGeometry
// purpose : Returns center of the point set. If location transformation
// is set, it will be applied
//=======================================================================
gp_Pnt Select3D_InteriorSensitivePointSet::CenterOfGeometry() const
{
return myCOG;
}
//=======================================================================
// function : BVH
// purpose : Builds BVH tree for the point set
//=======================================================================
void Select3D_InteriorSensitivePointSet::BVH()
{
BVH();
}
//=======================================================================
// function : NbSubElements
// purpose : Returns the amount of points in set
//=======================================================================
Standard_Integer Select3D_InteriorSensitivePointSet::NbSubElements()
{
return myPlanarPolygons.Length();
}

View File

@@ -0,0 +1,109 @@
// Created on: 2014-08-15
// Created by: Varvara POSKONINA
// Copyright (c) 2005-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_InteriorSensitivePointSet_HeaderFile
#define _Select3D_InteriorSensitivePointSet_HeaderFile
#include <NCollection_Vector.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Handle_TColgp_HArray1OfPnt.hxx>
#include <Handle_TColStd_HArray1OfInteger.hxx>
#include <Select3D_ISensitivePointSet.hxx>
#include <Select3D_SensitivePoly.hxx>
#include <Select3D_SensitiveSet.hxx>
class gp_Pnt;
class SelectBasics_EntityOwner;
class TColgp_Array1OfPnt;
class TColgp_HArray1OfPnt;
class TColStd_HArray1OfInteger;
typedef NCollection_Vector<Handle(Select3D_SensitivePoly)> Select3D_VectorOfHPoly;
//! This class handles the selection of arbitrary point set with internal type of sensitivity.
//! The main principle is to split the point set given onto planar convex polygons and search
//! for the overlap with one or more of them through traverse of BVH tree.
class Select3D_InteriorSensitivePointSet : public Select3D_ISensitivePointSet, public Select3D_SensitiveSet
{
public:
//! Splits the given point set thePoints onto planar convex polygons
Standard_EXPORT Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePoints);
//! Splits the given point set thePoints onto planar convex polygons
Standard_EXPORT Select3D_InteriorSensitivePointSet (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(TColgp_HArray1OfPnt)& thePoints);
//! Checks whether the point set overlaps current selecting volume
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
//! Initializes the given array theHArrayOfPnt by 3d coordinates of vertices of the
//! whole point set
Standard_EXPORT virtual void GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt) Standard_OVERRIDE;
//! Returns the length of vector of planar convex polygons
Standard_EXPORT virtual Standard_Integer Size() const Standard_OVERRIDE;
//! Returns bounding box of planar convex polygon with index theIdx
Standard_EXPORT virtual Select3D_BndBox3d Box (const Standard_Integer theIdx) const Standard_OVERRIDE;
//! Returns geometry center of planar convex polygon with index
//! theIdx in the vector along the given axis theAxis
Standard_EXPORT virtual Standard_Real Center (const Standard_Integer theIdx,
const Standard_Integer theAxis) const Standard_OVERRIDE;
//! Swaps items with indexes theIdx1 and theIdx2 in the vector
Standard_EXPORT virtual void Swap (const Standard_Integer theIdx1,
const Standard_Integer theIdx2) Standard_OVERRIDE;
//! Returns bounding box of the point set. If location
//! transformation is set, it will be applied
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
//! Returns center of the point set. If location
//! transformation is set, it will be applied
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
//! Builds BVH tree for the point set
Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
//! Returns the amount of points in set
Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
protected:
//! Checks whether the planar convex polygon with index theIdx
//! in myPlanarPolygons overlaps the current selecting volume
Standard_EXPORT virtual Standard_Boolean overlapsElement (SelectBasics_SelectingVolumeManager& theMgr,
Standard_Integer theElemIdx,
Standard_Real& theMatchDepth) Standard_OVERRIDE;
//! Calculates distance from the 3d projection of used-picked
//! screen point to center of the geometry
Standard_EXPORT virtual Standard_Real distanceToCOG (SelectBasics_SelectingVolumeManager& theMgr) Standard_OVERRIDE;
protected:
Select3D_VectorOfHPoly myPlanarPolygons; //!< Vector of planar polygons
Handle_TColStd_HArray1OfInteger myPolygonsIdxs; //!< Indexes array for BVH calculation
gp_Pnt myCOG; //!< Center of the point set
Select3D_BndBox3d myBndBox; //!< Bounding box of the point set
};
#endif // _Select3D_InteriorSensitivePointSet_HeaderFile

View File

@@ -1,46 +0,0 @@
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_Pnt2d_HeaderFile
#define _Select3D_Pnt2d_HeaderFile
#include<gp_Pnt2d.hxx>
#include<Standard_ShortReal.hxx>
#include<Select3D_Macro.hxx>
struct Select3D_Pnt2d{
Standard_ShortReal x, y;
inline operator gp_Pnt2d() const
{
return gp_Pnt2d(x, y);
}
inline operator gp_XY() const
{
return gp_XY(x, y);
}
inline gp_Pnt2d operator = (const gp_Pnt2d& thePnt)
{
x = DToF(thePnt.X());
y = DToF(thePnt.Y());
return *this;
}
};
#endif

View File

@@ -15,14 +15,13 @@
#define _Select3D_PointData_HeaderFile
#include <Select3D_Pnt.hxx>
#include <Select3D_Pnt2d.hxx>
// A framework for safe management of Select3D_SensitivePoly polygons of 3D and 2D points
// A framework for safe management of Select3D_SensitivePoly polygons of 3D points
class Select3D_PointData {
public:
// Constructs internal arrays of 2D and 3D points defined
// Constructs internal array of 3D points defined
// by number of points theNbPoints
Select3D_PointData (const Standard_Integer theNbPoints)
: mynbpoints(theNbPoints)
@@ -31,14 +30,12 @@ public:
Standard_ConstructionError::Raise("Select3D_PointData");
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
}
// Destructor
~Select3D_PointData ()
{
delete [] mypolyg3d;
delete [] mypolyg2d;
}
// Sets Select3D_Pnt to internal array
@@ -61,26 +58,6 @@ public:
mypolyg3d[theIndex] = theValue;
}
// Sets Select3D_Pnt2d to internal array
// of 2D points if theIndex is valid
void SetPnt2d (const Standard_Integer theIndex,
const Select3D_Pnt2d& theValue)
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::SetPnt2d");
mypolyg2d[theIndex] = theValue;
}
// Sets gp_Pnt2d to internal array
// of 2D points if theIndex is valid
void SetPnt2d (const Standard_Integer theIndex,
const gp_Pnt2d& theValue)
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::SetPnt2d");
mypolyg2d[theIndex] = theValue;
}
// Returns 3D point from internal array
// if theIndex is valid
Select3D_Pnt Pnt (const Standard_Integer theIndex) const
@@ -90,13 +67,13 @@ public:
return mypolyg3d[theIndex];
}
// Returns 2D point from internal array
// Returns 3D point from internal array
// if theIndex is valid
Select3D_Pnt2d Pnt2d (const Standard_Integer theIndex) const
gp_Pnt Pnt3d (const Standard_Integer theIndex) const
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::Pnt2d");
return mypolyg2d[theIndex];
Standard_OutOfRange::Raise("Select3D_PointData::Pnt");
return mypolyg3d[theIndex];
}
// Returns size of internal arrays
@@ -112,7 +89,6 @@ private:
private:
Select3D_Pnt* mypolyg3d;
Select3D_Pnt2d* mypolyg2d;
Standard_Integer mynbpoints;
};

View File

@@ -1,257 +0,0 @@
-- Created on: 1992-03-12
-- Created by: Christophe MARION
-- Copyright (c) 1992-1999 Matra Datavision
-- Copyright (c) 1999-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
-- <cma@sdsun2> copie quasi exacte de HLRAlgo_Projector
class Projector from Select3D inherits Transient from Standard
---Purpose: A framework to define 3D projectors.
-- Projector provides services for projecting points from
-- world-coordinates to a viewing plane. Projection could be defined by
-- corresponding transformation, or coordinate system. The transformation
-- could be constructed for a view with transposed view transformation
-- matrix ( that represents view-orientation ), including, for perspective
-- view, focal distance ( distance from an eye to the view plane ) and
-- translational part that represents translation of focal point in
-- view-coordinate space. The Select3D_Projector class recognizes the
-- predefined set of popular projections: axonometric, top view, front
-- view and uses more efficient algorithm for projection computations.
-- User-defined transformation could be also defined in constructor.
-- Perspective projection consists of two separate parts, that are
-- composed together during computation: transformation component and
-- focale distance.
uses
Real from Standard,
Boolean from Standard,
Trsf from gp,
GTrsf from gp,
Lin from gp,
Pnt from gp,
Vec from gp,
Ax2 from gp,
Vec2d from gp,
Pnt2d from gp,
Box from Bnd,
View from V3d,
Mat4 from Graphic3d,
Mat4d from Graphic3d
raises
NoSuchObject from Standard
is
Create (theView : View from V3d) returns Projector from Select3D;
--- Purpose: Constructs the 3D projector object from the passed view.
-- The projector captures current model-view and projection transformation
-- of the passed view.
Create returns Projector from Select3D;
--- Purpose: Constructs identity projector.
Create (theCS : Ax2 from gp)
---Purpose: Builds the Projector from the model-view transformation specified
-- by the passed viewing coordinate system <theCS>. The Projector has
-- identity projection transformation, is orthogonal.
-- The viewing coordinate system could be constructed from x direction,
-- view plane normal direction, and view point location in
-- world-coordinate space.
returns Projector from Select3D;
Create (theCS : Ax2 from gp;
theFocus : Real from Standard)
---Purpose: Builds the Projector from the model-view transformation specified
-- by the passed view coordinate system <theCS> and simplified perspective
-- projection transformation defined by <theFocus> parameter.
-- The viewing coordinate system could be constructed from x direction,
-- view plane normal direction, and focal point location in world-coordinate
-- space. <theFocus> should represent distance of an eye from view plane
-- in world-coordinate space (focal distance).
returns Projector from Select3D;
Create (theViewTrsf : Trsf from gp;
theIsPersp : Boolean from Standard;
theFocus : Real from Standard)
---Purpose: Build the Projector from the model-view transformation passed
-- as <theViewTrsf> and simplified perspective projection transformation
-- parameters passed as <theIsPersp> and <theFocus>.
-- In case, when <theViewTrsf> transformation should represent custom view
-- projection, it could be constructed from two separate components:
-- transposed view orientation matrix and translation of focal point
-- in view-coordinate system.
-- <theViewTrsf> could be built up from x direction, up direction,
-- view plane normal direction vectors and translation with SetValues(...)
-- method, where first row arguments (a11, a12, a13, a14) are x, y, z
-- component of x direction vector, and x value of reversed translation
-- vector. Second row arguments, are x y z for up direction and y value of
-- reversed translation, and the third row defined in the same manner.
-- This also suits for simple perspective view, where <theFocus> is the focale
-- distance of an eye from view plane in world-space coordinates.
-- Note, that in that case amount of perspective distortion (perspective
-- angle) should be defined through focal distance.
returns Projector from Select3D;
Create (theViewTrsf : GTrsf from gp;
theIsPersp : Boolean from Standard;
theFocus : Real from Standard)
---Purpose: Builds the Projector from the model-view transformation passed
-- as <theViewTrsf> and projection transformation for <theIsPersp> and
-- <theFocus> parameters.
-- In case, when <theViewTrsf> transformation should represent custom view
-- projection, it could be constructed from two separate components:
-- transposed view orientation matrix and translation of a focal point
-- in view-coordinate system.
-- This also suits for perspective view, with <theFocus> that could be
-- equal to distance from an eye to a view plane in
-- world-coordinates (focal distance).
-- The 3x3 transformation matrix is built up from three vectors:
-- x direction, up direction and view plane normal vectors, where each
-- vector is a matrix row. Then <theViewTrsf> is constructed from matrix and
-- reversed translation with methods SetTranslationPart(..) and
-- SetVectorialPart(..).
-- Note, that in that case amount of perspective distortion (perspective
-- angle) should be defined through focal distance.
returns Projector from Select3D;
Create (theViewTrsf : Mat4d from Graphic3d;
theProjTrsf : Mat4d from Graphic3d;
theZNear : Real from Standard = 0.0;
theZFar : Real from Standard = 10.0)
---Purpose: Builds the Projector from the passed model-view <theViewTrsf>
-- and projection <theProjTrsf> transformation matrices. Parameters <theZNear>
-- and <theZFar> are passed to define view frustum depth for further projection
-- line computation using perspective projection.
returns Projector from Select3D;
Set (me : mutable;
theViewTrsf : Trsf from gp;
theIsPersp : Boolean from Standard;
theFocus : Real from Standard);
---Purpose: Sets new parameters for the Projector.
Set (me : mutable;
theViewTrsf : Mat4d from Graphic3d;
theProjTrsf : Mat4d from Graphic3d;
theZNear : Real from Standard;
theZFar : Real from Standard);
---Purpose: Sets new parameters for the Projector.
SetView (me : mutable;
theView : View from V3d);
---Purpose: Sets new parameters for the Projector
-- captured from the passed view.
Scaled (me : mutable; theToCheckOptimized : Boolean from Standard = Standard_False)
---Purpose: Pre-compute inverse transformation and ensure whether it is possible
-- to use optimized transformation for the common view-orientation type or not
-- if <theToCheckOptimized> is TRUE.
is virtual;
Perspective (me) returns Boolean
---Purpose: Returns True if there is simplified perspective
-- projection approach is used. Distortion defined by Focus.
---C++: inline
is virtual;
Focus (me) returns Real from Standard
---Purpose: Returns the focal length of simplified perspective
-- projection approach. Raises program error exception if the
-- the projection transformation is not specified as simplified
-- Perspective (for example, custom projection transformation is defined
-- or the orthogonal Projector is defined).
---C++: inline
is virtual;
Projection (me) returns Mat4d from Graphic3d;
---Purpose: Returns projection transformation. Please note that for
-- simplified perspective projection approach, defined by Focus, the
-- returned transformation is identity.
---C++: inline
---C++: return const &
Transformation (me) returns GTrsf from gp
---Purpose: Returns the view transformation.
---C++: inline
---C++: return const &
is virtual;
InvertedTransformation (me) returns GTrsf from gp
---Purpose: Returns the inverted view transformation.
---C++: inline
---C++: return const &
is virtual;
FullTransformation (me) returns Trsf from gp
---Purpose: Returns the uniform-scaled view transformation.
---C++: inline
---C++: return const &
is virtual;
Transform (me; theD : in out Vec from gp)
---Purpose: Transforms the vector into view-coordinate space.
---C++: inline
is virtual;
Transform (me; thePnt : in out Pnt from gp)
---Purpose: Transforms the point into view-coordinate space.
---C++: inline
is virtual;
Project (me; theP : Pnt from gp; thePout : out Pnt2d from gp)
---Purpose: Transforms the point into view-coordinate space
-- and applies projection transformation.
is virtual;
Project (me; theP : Pnt from gp; theX, theY, theZ : out Real from Standard)
---Purpose: Transforms the point into view-coordinate space
-- and applies projection transformation.
is static;
Project (me; theP : Pnt from gp;
theD1 : Vec from gp;
thePout : out Pnt2d from gp;
theD1out : out Vec2d from gp)
---Purpose: Transforms the point and vector passed from its location
-- into view-coordinate space and applies projection transformation.
is virtual;
Shoot (me; theX, theY : Real from Standard) returns Lin from gp
---Purpose: Return projection line going through the 2d point <theX, theY>
is virtual;
Transform(me; thePnt : in out Pnt from gp;
theTrsf : GTrsf from gp)
---C++: inline
is virtual;
Transform(me; theLin : in out Lin from gp;
theTrsf : GTrsf from gp)
---C++: inline
is virtual;
fields
myType : Integer from Standard;
myPersp : Boolean from Standard is protected;
myFocus : Real from Standard is protected;
myGTrsf : GTrsf from gp is protected;
myInvTrsf : GTrsf from gp is protected;
myScaledTrsf : Trsf from gp is protected;
myProjTrsf : Mat4d from Graphic3d is protected;
myZNear : Real from Standard is protected;
myZFar : Real from Standard is protected;
end Projector;

View File

@@ -1,492 +0,0 @@
// Created on: 1992-03-13
// Created by: Christophe MARION
// Copyright (c) 1992-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Select3D_Projector.ixx>
#include <Precision.hxx>
#include <gp_Ax3.hxx>
#include <gp_Vec.hxx>
#include <gp_Vec2d.hxx>
#include <gp_Mat.hxx>
#include <Graphic3d_Vec4.hxx>
namespace
{
//=======================================================================
//function : TrsfType
//purpose :
//=======================================================================
static Standard_Integer TrsfType(const gp_GTrsf& theTrsf)
{
const gp_Mat& aMat = theTrsf.VectorialPart();
if ((Abs (aMat.Value (1, 1) - 1.0) < 1e-15)
&& (Abs (aMat.Value (2, 2) - 1.0) < 1e-15)
&& (Abs (aMat.Value (3, 3) - 1.0) < 1e-15))
{
return 1; // top
}
else if ((Abs (aMat.Value (1, 1) - 0.7071067811865476) < 1e-15)
&& (Abs (aMat.Value (1, 2) + 0.5) < 1e-15)
&& (Abs (aMat.Value (1, 3) - 0.5) < 1e-15)
&& (Abs (aMat.Value (2, 1) - 0.7071067811865476) < 1e-15)
&& (Abs (aMat.Value (2, 2) - 0.5) < 1e-15)
&& (Abs (aMat.Value (2, 3) + 0.5) < 1e-15)
&& (Abs (aMat.Value (3, 1)) < 1e-15)
&& (Abs (aMat.Value (3, 2) - 0.7071067811865476) < 1e-15)
&& (Abs (aMat.Value (3, 3) - 0.7071067811865476) < 1e-15))
{
return 0; // inverse axo
}
else if ((Abs (aMat.Value (1, 1) - 1.0) < 1e-15)
&& (Abs (aMat.Value (2, 3) - 1.0) < 1e-15)
&& (Abs (aMat.Value (3, 2) + 1.0) < 1e-15))
{
return 2; // front
}
else if ((Abs (aMat.Value (1, 1) - 0.7071067811865476) < 1e-15)
&& (Abs (aMat.Value (1, 2) - 0.7071067811865476) < 1e-15)
&& (Abs (aMat.Value (1, 3)) < 1e-15)
&& (Abs (aMat.Value (2, 1) + 0.5) < 1e-15)
&& (Abs (aMat.Value (2, 2) - 0.5) < 1e-15)
&& (Abs (aMat.Value (2, 3) - 0.7071067811865476) < 1e-15)
&& (Abs (aMat.Value (3, 1) - 0.5) < 1e-15)
&& (Abs (aMat.Value (3, 2) + 0.5) < 1e-15)
&& (Abs (aMat.Value (3, 3) - 0.7071067811865476) < 1e-15))
{
return 3; // axo
}
return -1;
}
//====== TYPE 0 (inverse axonometric)
// (0.7071067811865476, -0.5 , 0.4999999999999999)
// (0.7071067811865475, 0.5000000000000001, -0.5 )
// (0.0, 0.7071067811865475, 0.7071067811865476)
// ====== TYPE 1 (top)
// (1.0, 0.0, 0.0)
// (0.0, 1.0, 0.0)
// (0.0, 0.0, 1.0)
// ======= TYPE 2 (front)
// (1.0, 0.0 , 0.0)
// (0.0, 1.110223024625157e-16 , 1.0)
// (0.0, -1.0 , 1.110223024625157e-16)
// ======= TYPE 3 (axonometric)
// ( 0.7071067811865476, 0.7071067811865475, 0.0)
// (-0.5 , 0.5000000000000001, 0.7071067811865475)
// ( 0.4999999999999999, -0.5 , 0.7071067811865476)
}
// formula for derivating a perspective, from Mathematica
// X'[t] X[t] Z'[t]
// D1 = -------- + -------------
// Z[t] Z[t] 2
// 1 - ---- f (1 - ----)
// f f
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector (const Handle(V3d_View)& theView)
: myPersp (Standard_False),
myFocus (0.0),
myZNear (0.0),
myZFar (10.0),
myType (-1)
{
SetView (theView);
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector()
: myPersp (Standard_False),
myFocus (0.0),
myZNear (0.0),
myZFar (10.0),
myType (-1)
{
Scaled();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS)
: myPersp (Standard_False),
myFocus (0.0),
myZNear (0.0),
myZFar (10.0),
myType (-1)
{
myScaledTrsf.SetTransformation (theCS);
myGTrsf.SetTrsf (myScaledTrsf);
Scaled();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector (const gp_Ax2& theCS, const Standard_Real theFocus)
: myPersp (Standard_True),
myFocus (theFocus),
myZNear (0.0),
myZFar (10.0),
myType (-1)
{
myScaledTrsf.SetTransformation (theCS);
myGTrsf.SetTrsf (myScaledTrsf);
Scaled();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector (const gp_Trsf& theViewTrsf,
const Standard_Boolean theIsPersp,
const Standard_Real theFocus)
: myPersp (theIsPersp),
myFocus (theFocus),
myGTrsf (theViewTrsf),
myScaledTrsf (theViewTrsf),
myZNear (0.0),
myZFar (10.0),
myType (-1)
{
Scaled();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector (const gp_GTrsf& theViewTrsf,
const Standard_Boolean theIsPersp,
const Standard_Real theFocus)
: myPersp (theIsPersp),
myFocus (theFocus),
myGTrsf (theViewTrsf),
myScaledTrsf (theViewTrsf.Trsf()),
myZNear (0.0),
myZFar (10.0),
myType (-1)
{
Scaled();
}
//=======================================================================
//function : Select3D_Projector
//purpose :
//=======================================================================
Select3D_Projector::Select3D_Projector (const Graphic3d_Mat4d& theViewTrsf,
const Graphic3d_Mat4d& theProjTrsf,
const Standard_Real theZNear,
const Standard_Real theZFar)
: myPersp (Standard_False),
myFocus (0.0),
myType (-1)
{
Set (theViewTrsf, theProjTrsf, theZNear, theZFar);
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void Select3D_Projector::Set (const gp_Trsf& theViewTrsf,
const Standard_Boolean theIsPersp,
const Standard_Real theFocus)
{
myPersp = theIsPersp;
myFocus = theFocus;
myScaledTrsf = theViewTrsf;
myProjTrsf.InitIdentity();
Scaled();
}
//=======================================================================
//function : Set
//purpose :
//=======================================================================
void Select3D_Projector::Set (const Graphic3d_Mat4d& theViewTrsf,
const Graphic3d_Mat4d& theProjTrsf,
const Standard_Real theZNear,
const Standard_Real theZFar)
{
// Copy elements corresponding to common view-transformation
for (Standard_Integer aRowIt = 0; aRowIt < 3; ++aRowIt)
{
for (Standard_Integer aColIt = 0; aColIt < 4; ++aColIt)
{
myGTrsf.SetValue (aRowIt + 1, aColIt + 1, theViewTrsf.GetValue (aRowIt, aColIt));
}
}
// Adapt scaled transformation for compatibilty
gp_Dir aViewY (theViewTrsf.GetValue (0, 1), theViewTrsf.GetValue (1, 1), theViewTrsf.GetValue (2, 1));
gp_Dir aViewZ (theViewTrsf.GetValue (0, 2), theViewTrsf.GetValue (1, 2), theViewTrsf.GetValue (2, 2));
gp_XYZ aViewT (theViewTrsf.GetValue (0, 3), theViewTrsf.GetValue (1, 3), theViewTrsf.GetValue (2, 3));
gp_Dir aViewX = aViewY ^ aViewZ;
gp_Ax3 aViewAx3 (gp_Pnt (aViewT), aViewZ, aViewX);
myScaledTrsf.SetTransformation (aViewAx3);
myPersp = Standard_False;
myFocus = 0.0;
myProjTrsf = theProjTrsf;
myZNear = theZNear;
myZFar = theZFar;
Scaled();
}
//=======================================================================
//function : SetView
//purpose :
//=======================================================================
void Select3D_Projector::SetView (const Handle(V3d_View)& theView)
{
const Graphic3d_Mat4d& aViewTrsf = theView->Camera()->OrientationMatrix();
const Graphic3d_Mat4d& aProjTrsf = theView->Camera()->ProjectionMatrix();
gp_XYZ aFrameScale = theView->Camera()->ViewDimensions();
Graphic3d_Mat4d aScale;
aScale.ChangeValue (0, 0) = aFrameScale.X();
aScale.ChangeValue (1, 1) = aFrameScale.Y();
aScale.ChangeValue (2, 2) = aFrameScale.Z();
Graphic3d_Mat4d aScaledProjTrsf = aScale * aProjTrsf;
Set (aViewTrsf,
aScaledProjTrsf,
theView->Camera()->ZNear(),
theView->Camera()->ZFar());
}
//=======================================================================
//function : Scaled
//purpose :
//=======================================================================
void Select3D_Projector::Scaled (const Standard_Boolean theToCheckOptimized)
{
myType = -1;
if (!theToCheckOptimized && !myPersp && myProjTrsf.IsIdentity())
{
myType = TrsfType (myGTrsf);
}
myInvTrsf = myGTrsf.Inverted();
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_Projector::Project (const gp_Pnt& theP, gp_Pnt2d& thePout) const
{
Standard_Real aXout = 0.0;
Standard_Real aYout = 0.0;
Standard_Real aZout = 0.0;
Project (theP, aXout, aYout, aZout);
thePout.SetCoord (aXout, aYout);
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_Projector::Project (const gp_Pnt& theP,
Standard_Real& theX,
Standard_Real& theY,
Standard_Real& theZ) const
{
Graphic3d_Vec4d aTransformed (0.0, 0.0, 0.0, 1.0);
// view transformation
switch (myType)
{
case 0 : // inverse axo
{
Standard_Real aX07 = theP.X() * 0.7071067811865475;
Standard_Real aY05 = theP.Y() * 0.5;
Standard_Real aZ05 = theP.Z() * 0.5;
aTransformed.x() = aX07 - aY05 + aZ05;
aTransformed.y() = aX07 + aY05 - aZ05;
aTransformed.z() = 0.7071067811865475 * (theP.Y() + theP.Z());
break;
}
case 1 : // top
{
aTransformed.x() = theP.X();
aTransformed.y() = theP.Y();
aTransformed.z() = theP.Z();
break;
}
case 2 : // front
{
aTransformed.x() = theP.X();
aTransformed.y() = theP.Z();
aTransformed.z() = -theP.Y();
break;
}
case 3 : // axo
{
Standard_Real aXmy05 = (theP.X() - theP.Y()) * 0.5;
Standard_Real aZ07 = theP.Z() * 0.7071067811865476;
aTransformed.x() = 0.7071067811865476 * (theP.X() + theP.Y());
aTransformed.y() = -aXmy05 + aZ07;
aTransformed.z() = aXmy05 + aZ07;
break;
}
default :
{
gp_Pnt aTransformPnt = theP;
Transform (aTransformPnt);
aTransformed.x() = aTransformPnt.X();
aTransformed.y() = aTransformPnt.Y();
aTransformed.z() = aTransformPnt.Z();
}
}
// projection transformation
if (myPersp)
{
// simplified perspective
Standard_Real aDistortion = 1.0 - aTransformed.z() / myFocus;
theX = aTransformed.x() / aDistortion;
theY = aTransformed.y() / aDistortion;
theZ = aTransformed.z();
return;
}
if (myProjTrsf.IsIdentity())
{
// no projection transformation
theX = aTransformed.x();
theY = aTransformed.y();
theZ = aTransformed.z();
return;
}
Graphic3d_Vec4d aProjected = myProjTrsf * aTransformed;
theX = aProjected.x() / aProjected.w();
theY = aProjected.y() / aProjected.w();
theZ = aProjected.z() / aProjected.w();
}
//=======================================================================
//function : Project
//purpose :
//=======================================================================
void Select3D_Projector::Project (const gp_Pnt& theP,
const gp_Vec& theD1,
gp_Pnt2d& thePout,
gp_Vec2d& theD1out) const
{
// view transformation
gp_Pnt aTP = theP;
Transform (aTP);
gp_Vec aTD1 = theD1;
Transform (aTD1);
// projection transformation
if (myPersp)
{
// simplified perspective
Standard_Real aDist = 1.0 - aTP.Z() / myFocus;
thePout.SetCoord (aTP.X() / aDist, aTP.Y() / aDist);
theD1out.SetCoord (aTD1.X() / aDist + aTP.X() * aTD1.Z() / (myFocus * aDist * aDist),
aTD1.Y() / aDist + aTP.Y() * aTD1.Z() / (myFocus * aDist * aDist));
return;
}
if (myProjTrsf.IsIdentity())
{
// no projection transformation
thePout.SetCoord (aTP.X(), aTP.Y());
theD1out.SetCoord (aTD1.X(), aTD1.Y());
}
Graphic3d_Vec4d aTransformedPnt1 (aTP.X(), aTP.Y(), aTP.Z(), 1.0);
Graphic3d_Vec4d aTransformedPnt2 (aTP.X() + aTD1.X(), aTP.Y() + aTD1.Y(), aTP.Z() + aTD1.Z(), 1.0);
Graphic3d_Vec4d aProjectedPnt1 = myProjTrsf * aTransformedPnt1;
Graphic3d_Vec4d aProjectedPnt2 = myProjTrsf * aTransformedPnt2;
aProjectedPnt1 /= aProjectedPnt1.w();
aProjectedPnt2 /= aProjectedPnt2.w();
Graphic3d_Vec4d aProjectedD1 = aProjectedPnt2 - aProjectedPnt1;
thePout.SetCoord (aProjectedPnt1.x(), aProjectedPnt1.y());
theD1out.SetCoord (aProjectedD1.x(), aProjectedD1.y());
}
//=======================================================================
//function : Shoot
//purpose :
//=======================================================================
gp_Lin Select3D_Projector::Shoot (const Standard_Real theX, const Standard_Real theY) const
{
gp_Lin aViewLin;
if (myPersp)
{
// simplified perspective
aViewLin = gp_Lin (gp_Pnt (0.0, 0.0, myFocus), gp_Dir (theX, theY, -myFocus));
}
else if (myProjTrsf.IsIdentity())
{
// no projection transformation
aViewLin = gp_Lin (gp_Pnt (theX, theY, 0.0), gp_Dir (0.0, 0.0, -1.0));
}
else
{
// get direction of projection over the point in view space
Graphic3d_Mat4d aProjInv;
if (!myProjTrsf.Inverted (aProjInv))
{
return gp_Lin();
}
Graphic3d_Vec4d aVPnt1 = aProjInv * Graphic3d_Vec4d (theX, theY, myZNear, 1.0);
Graphic3d_Vec4d aVPnt2 = aProjInv * Graphic3d_Vec4d (theX, theY, myZFar, 1.0);
aVPnt1 /= aVPnt1.w();
aVPnt2 /= aVPnt2.w();
gp_Vec aViewDir (aVPnt2.x() - aVPnt1.x(), aVPnt2.y() - aVPnt1.y(), aVPnt2.z() - aVPnt1.z());
aViewLin = gp_Lin (gp_Pnt (aVPnt1.x(), aVPnt1.y(), aVPnt1.z()), gp_Dir (aViewDir));
}
// view transformation
Transform (aViewLin, myInvTrsf);
return aViewLin;
}

View File

@@ -1,145 +0,0 @@
// Created on: 1992-07-09
// Created by: Christophe MARION
// Copyright (c) 1992-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Graphic3d_Mat4d.hxx>
#include <Standard_Assert.hxx>
#include <gp_Vec.hxx>
#include <gp_Pnt.hxx>
#include <gp_Lin.hxx>
//=======================================================================
//function : Perspective
//purpose :
//=======================================================================
inline Standard_Boolean Select3D_Projector::Perspective() const
{
return myPersp;
}
//=======================================================================
//function : ProjectionTransformation
//purpose :
//=======================================================================
inline const Graphic3d_Mat4d& Select3D_Projector::Projection() const
{
return myProjTrsf;
}
//=======================================================================
//function : Transformation
//purpose :
//=======================================================================
inline const gp_GTrsf& Select3D_Projector::Transformation() const
{
return myGTrsf;
}
//=======================================================================
//function : InvertedTransformation
//purpose :
//=======================================================================
inline const gp_GTrsf& Select3D_Projector::InvertedTransformation() const
{
return myInvTrsf;
}
//=======================================================================
//function : FullTransformation
//purpose :
//=======================================================================
inline const gp_Trsf& Select3D_Projector::FullTransformation() const
{
return myScaledTrsf;
}
//=======================================================================
//function : Focus
//purpose :
//=======================================================================
inline Standard_Real Select3D_Projector::Focus() const
{
Standard_ASSERT_RAISE (myPersp, "Not a simplified Perspective.");
return myFocus;
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
inline void Select3D_Projector::Transform (gp_Vec& theD) const
{
gp_XYZ aXYZ = theD.XYZ();
if (myGTrsf.Form() == gp_PntMirror)
{
aXYZ.Reverse();
}
else if (myGTrsf.Form() != gp_Identity && myGTrsf.Form() != gp_Translation)
{
aXYZ.Multiply (myGTrsf.VectorialPart());
}
theD.SetXYZ (aXYZ);
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
inline void Select3D_Projector::Transform (gp_Pnt& thePnt) const
{
Transform (thePnt, myGTrsf);
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
inline void Select3D_Projector::Transform (gp_Lin& theLin, const gp_GTrsf& theTrsf) const
{
gp_Ax1 anAx1 = theLin.Position();
gp_XYZ aXYZ = anAx1.Location().XYZ();
theTrsf.Transforms (aXYZ);
anAx1.SetLocation (gp_Pnt (aXYZ));
gp_Dir aDir = anAx1.Direction();
gp_XYZ aDirXYZ = aDir.XYZ();
if (theTrsf.Form() == gp_PntMirror)
{
aDirXYZ.Reverse();
}
else if (theTrsf.Form() != gp_Identity && theTrsf.Form() != gp_Translation)
{
aDirXYZ.Multiply (theTrsf.VectorialPart());
Standard_Real aModulus = aDirXYZ.Modulus();
aDirXYZ.Divide (aModulus);
}
aDir.SetXYZ (aDirXYZ);
anAx1.SetDirection (aDir);
theLin.SetPosition (anAx1);
}
//=======================================================================
//function : Transform
//purpose :
//=======================================================================
inline void Select3D_Projector::Transform (gp_Pnt& thePnt, const gp_GTrsf& theTrsf) const
{
gp_XYZ aXYZ = thePnt.XYZ();
theTrsf.Transforms (aXYZ);
thePnt = gp_Pnt (aXYZ);
}

View File

@@ -1,121 +0,0 @@
-- Created on: 1995-04-13
-- Created by: Robert COUBLANC
-- Copyright (c) 1995-1999 Matra Datavision
-- Copyright (c) 1999-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class SensitiveBox from Select3D
inherits SensitiveEntity from Select3D
---Purpose: A framework to define selection by a sensitive box.
uses
Pnt from gp,
Pnt2d from gp,
Box from Bnd,
Box2d from Bnd,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
PickArgs from SelectBasics,
Array1OfPnt2d from TColgp,
Location from TopLoc
is
Create (OwnerId : EntityOwner from SelectBasics;
BoundingBox : Box from Bnd)
returns SensitiveBox;
---Purpose: Constructs a sensitive box object defined by the
-- owner OwnerId, and the bounding box BoundingBox.
Create (OwnerId : EntityOwner from SelectBasics;
XMin,YMin,ZMin,
XMax,YMax,ZMax : Real)
returns SensitiveBox;
--- Purpose: Constructs a sensitive box object defined by the
-- owner OwnerId, and the coordinates Xmin, YMin, ZMin, XMax, YMax, ZMax.
-- Xmin, YMin and ZMin define the minimum point in
-- the front lower left hand corner of the box,
-- and XMax, YMax and ZMax define the maximum
-- point in the back upper right hand corner of the box.
Project (me:mutable;aProjector : Projector from Select3D)
is redefined static;
---Level: Public
---Purpose: projection of the sensitive primitive in order to
-- get 2D boxes for the Sort Algorithm
Areas (me:mutable ; boxes : in out ListOfBox2d from SelectBasics)
is redefined static;
---Level: Public
---Purpose: gives the 2D boxes which represent the Box in the
-- selection process...
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is redefined static;
Matches (me : mutable;
thePickArgs : PickArgs from SelectBasics;
theMatchDMin, theMatchDepth : out Real from Standard)
returns Boolean is redefined static;
---Level: Public
---Purpose: Checks whether the sensitive entity matches the picking
-- detection area (close to the picking line).
-- For details please refer to base class declaration.
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean is redefined static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth(me;EyeLine: Lin from gp)
returns Real from Standard;
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
Box(me) returns Box from Bnd;
---Purpose: Returns the sensitive 3D box used at the time of construction.
---C++: inline
---C++: return const &
ProjectBox(me:mutable;aPrj: Projector from Select3D;aBox:Box from Bnd)
is static private;
fields
mybox3d : Box from Bnd;
mybox2d : Box2d from Bnd;
end SensitiveBox;

View File

@@ -14,198 +14,126 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Select3D_SensitiveBox.ixx>
#include <Select3D_SensitiveBox.hxx>
#include <gp_Pnt2d.hxx>
#include <gp_Pnt.hxx>
#include <Bnd_Box.hxx>
#include <ElCLib.hxx>
IMPLEMENT_STANDARD_HANDLE (Select3D_SensitiveBox, Select3D_SensitiveEntity)
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveBox, Select3D_SensitiveEntity)
//==================================================
// Function: Constructor
// Function: Select3D_SensitiveBox
// Purpose :
//==================================================
Select3D_SensitiveBox::Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Bnd_Box& BBox):
Select3D_SensitiveEntity(OwnerId),
mybox3d(BBox){}
//==================================================
// Function: Constructor
// Purpose :
//==================================================
Select3D_SensitiveBox::
Select3D_SensitiveBox(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real ZMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real ZMax):
Select3D_SensitiveEntity(OwnerId)
Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Bnd_Box& theBox)
: Select3D_SensitiveEntity (theOwnerId)
{
mybox3d.Update(XMin,YMin,ZMin,XMax,YMax,ZMax);
Standard_Real aXMax, aYMax, aZMax;
Standard_Real aXMin, aYMin, aZMin;
theBox.Get (aXMin, aYMin, aZMin, aXMax, aYMax, aZMax);
myBox = Select3D_BndBox3d (SelectMgr_Vec3 (aXMin, aYMin, aZMin),
SelectMgr_Vec3 (aXMax, aYMax, aZMax));
myCenter3d = (gp_XYZ (aXMin, aYMin, aZMin) + gp_XYZ (aXMax, aYMax, aZMax))
* (1.0 / 2.0);
}
//==================================================
// Function: Project
// Function: Select3D_SensitiveBox
// Purpose :
//==================================================
void Select3D_SensitiveBox::
Project(const Handle(Select3D_Projector)& aProj)
Select3D_SensitiveBox::Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Standard_Real theXMin,
const Standard_Real theYMin,
const Standard_Real theZMin,
const Standard_Real theXMax,
const Standard_Real theYMax,
const Standard_Real theZMax)
: Select3D_SensitiveEntity (theOwnerId)
{
if(HasLocation())
{
Bnd_Box B = mybox3d.Transformed(Location().Transformation());
ProjectBox(aProj,B);
}
else
ProjectBox(aProj,mybox3d);
myBox = Select3D_BndBox3d (SelectMgr_Vec3 (theXMin, theYMin, theZMin),
SelectMgr_Vec3 (theXMax, theYMax, theZMax));
myCenter3d = (gp_XYZ (theXMin, theYMin, theZMin) + gp_XYZ (theXMax, theYMax, theZMax))
* (1.0 / 2.0);
}
//==================================================
// Function: Areas
// Purpose :
//==================================================
void Select3D_SensitiveBox::
Areas(SelectBasics_ListOfBox2d& aSeq)
{ aSeq.Append(mybox2d);}
//=======================================================================
// function : NbSubElements
// purpose : Returns the amount of sub-entities in sensitive
//=======================================================================
Standard_Integer Select3D_SensitiveBox::NbSubElements()
{
return 1;
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected(const TopLoc_Location& aLoc)
Handle(Select3D_SensitiveEntity) Select3D_SensitiveBox::GetConnected()
{
Handle(Select3D_SensitiveBox) NiouEnt = new Select3D_SensitiveBox(myOwnerId,mybox3d);
if(HasLocation()) NiouEnt->SetLocation(Location());
NiouEnt->UpdateLocation(aLoc);
return NiouEnt;
Bnd_Box aBox;
aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(),
myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z());
Handle(Select3D_SensitiveBox) aNewEntity = new Select3D_SensitiveBox (myOwnerId, aBox);
return aNewEntity;
}
//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveBox::Matches (const SelectBasics_PickArgs& thePickArgs,
Standard_Real& theMatchDMin,
Standard_Real& theMatchDepth)
//=======================================================================
// function : Matches
// purpose : Checks whether the box overlaps current selecting volume
//=======================================================================
Standard_Boolean Select3D_SensitiveBox::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
// check that sensitive box passes by depth
Standard_Real aDepth = ComputeDepth (thePickArgs.PickLine());
if (thePickArgs.IsClipped (aDepth))
Standard_Real aDepth = RealLast();
Standard_Real aDistToCOG = RealLast();
Standard_Boolean isMatched = theMgr.Overlaps (myBox, aDepth);
if (isMatched)
{
return Standard_False;
aDistToCOG = theMgr.DistToGeometryCenter (myCenter3d);
}
theMatchDMin = 0.0;
theMatchDepth = aDepth;
return Standard_True;
thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
return isMatched;
}
//==================================================
// Function: Matches
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveBox::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
//=======================================================================
// function : CenterOfGeometry
// purpose : Returns center of the box. If location transformation
// is set, it will be applied
//=======================================================================
gp_Pnt Select3D_SensitiveBox::CenterOfGeometry() const
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
return(!BoundBox.IsOut(mybox2d));
return myCenter3d;
}
//=======================================================================
//function : Matches
//purpose :
// function : BoundingBox
// purpose : Returns coordinates of the box. If location transformation
// is set, it will be applied
//=======================================================================
Standard_Boolean Select3D_SensitiveBox::
Matches (const TColgp_Array1OfPnt2d& /*aPoly*/,
const Bnd_Box2d& aBox,
const Standard_Real /*aTol*/)
Select3D_BndBox3d Select3D_SensitiveBox::BoundingBox()
{
return(!aBox.IsOut(mybox2d));
return myBox;
}
//=======================================================================
//function : Dump
//purpose :
// function : Box
// purpose :
//=======================================================================
void Select3D_SensitiveBox::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
Bnd_Box Select3D_SensitiveBox::Box() const
{
S<<"\tSensitiveBox 3D :\n";
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
S<<"\t\t PMin [ "<<XMin<<" , "<<YMin<<" , "<<ZMin<<" ]";
S<<"\t\t PMax [ "<<XMax<<" , "<<YMax<<" , "<<ZMax<<" ]"<<endl;
Bnd_Box aBox;
aBox.Update (myBox.CornerMin().x(), myBox.CornerMin().y(), myBox.CornerMin().z(),
myBox.CornerMax().x(), myBox.CornerMax().y(), myBox.CornerMax().z());
if(FullDump)
{
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
//=======================================================================
//function : ProjectBox
//purpose :
//=======================================================================
void Select3D_SensitiveBox::ProjectBox(const Handle(Select3D_Projector)& aPrj,
const Bnd_Box& aBox)
{
mybox2d.SetVoid();
gp_Pnt2d curp2d;
Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
aBox.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
aPrj->Project(gp_Pnt(XMin,YMin,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMax,YMin,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMax,YMax,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMin,YMax,ZMin),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMin,YMin,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMax,YMin,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMax,YMax,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
aPrj->Project(gp_Pnt(XMin,YMax,ZMax),curp2d);
mybox2d.Update(curp2d.X(),curp2d.Y());
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveBox::ComputeDepth(const gp_Lin& EyeLine) const
{
Standard_Real XMin,YMin,ZMin,XMax,YMax,ZMax;
mybox3d.Get(XMin,YMin,ZMin,XMax,YMax,ZMax);
gp_Pnt PMid((XMin+XMax)/2.,(YMin+YMax)/2.,(ZMin+ZMax)/2.);
return ElCLib::Parameter(EyeLine,PMid);
return aBox;
}

View File

@@ -0,0 +1,88 @@
// Created on: 1995-04-13
// Created by: Robert COUBLANC
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_SensitiveBox_HeaderFile
#define _Select3D_SensitiveBox_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Standard_Type.hxx>
#include <Bnd_Box.hxx>
#include <gp_Pnt.hxx>
#include <Select3D_SensitiveEntity.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <SelectMgr_SelectingVolumeManager.hxx>
#include <Standard_OStream.hxx>
class SelectBasics_EntityOwner;
class Bnd_Box;
class TopLoc_Location;
//! A framework to define selection by a sensitive box.
class Select3D_SensitiveBox : public Select3D_SensitiveEntity
{
public:
//! Constructs a sensitive box object defined by the
//! owner theOwnerId, and the box theBox.
Standard_EXPORT Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId, const Bnd_Box& theBox);
//! Constructs a sensitive box object defined by the
//! owner theOwnerId, and the coordinates theXmin, theYMin, theZMin, theXMax, theYMax, theZMax.
//! theXmin, theYMin and theZMin define the minimum point in
//! the front lower left hand corner of the box,
//! and theXMax, theYMax and theZMax define the maximum
//! point in the back upper right hand corner of the box.
Standard_EXPORT Select3D_SensitiveBox (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Standard_Real theXMin,
const Standard_Real theYMin,
const Standard_Real theZMin,
const Standard_Real theXMax,
const Standard_Real theYMax,
const Standard_Real theZMax);
//! Returns the amount of sub-entities in sensitive
Standard_EXPORT virtual Standard_Integer NbSubElements() Standard_OVERRIDE;
Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
//! Checks whether the box overlaps current selecting volume
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
Bnd_Box Box() const;
//! Returns center of the box. If location
//! transformation is set, it will be applied
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
//! Returns coordinates of the box. If location
//! transformation is set, it will be applied
Standard_EXPORT virtual Select3D_BndBox3d BoundingBox() Standard_OVERRIDE;
DEFINE_STANDARD_RTTI(Select3D_SensitiveBox)
private:
Select3D_BndBox3d myBox; //!< 3d coordinates of box corners
gp_Pnt myCenter3d; //!< 3d coordinate of box's center
};
DEFINE_STANDARD_HANDLE(Select3D_SensitiveBox, Select3D_SensitiveEntity)
#endif // _Select3D_SensitiveBox_HeaderFile

View File

@@ -1,18 +0,0 @@
// Created on: 1997-07-16
// Created by: Robert COUBLANC
// Copyright (c) 1997-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
inline const Bnd_Box& Select3D_SensitiveBox::Box() const
{return mybox3d;}

View File

@@ -1,155 +0,0 @@
-- Created on: 1996-02-06
-- Created by: Robert COUBLANC
-- Copyright (c) 1996-1999 Matra Datavision
-- Copyright (c) 1999-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
class SensitiveCircle from Select3D
inherits SensitivePoly from Select3D
---Purpose: A framework to define sensitive 3D arcs and circles.
-- In some cases this class can raise Standard_ConstructionError and
-- Standard_OutOfRange exceptions. For more details see Select3D_SensitivePoly.
uses
Pnt from gp,
Pnt2d from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
PickArgs from SelectBasics,
Circle from Geom,
Array1OfPnt from TColgp,
HArray1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
Box2d from Bnd,
Location from TopLoc,
Pnt from Select3D,
Pnt2d from Select3D,
Projector from Select3D,
SensitiveEntity from Select3D,
Circle from Geom
raises
ConstructionError from Standard,
OutOfRange from Standard
is
Create (OwnerId : EntityOwner from SelectBasics;
TheCircle : Circle from Geom;
FilledCircle : Boolean = Standard_False;
NbOfPoints : Integer = 6)
returns SensitiveCircle;
---Level: Public
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the circle Circle, the Boolean
-- FilledCircle and the number of points NbOfPoints.
Create (OwnerId : EntityOwner from SelectBasics;
TheCircle : Circle from Geom;
u1 : Real ;
u2 : Real;
FilledCircle : Boolean = Standard_False;
NbOfPoints : Integer = 6)
returns SensitiveCircle;
---Level: Public
---Purpose: Constructs the sensitive arc object defined by the
-- owner OwnerId, the circle Circle, the parameters u1
-- and u2, the Boolean FilledCircle and the number of points NbOfPoints.
-- u1 and u2 define the first and last points of the arc on Circle.
Create(OwnerId : EntityOwner from SelectBasics;
apolyg3d : HArray1OfPnt from TColgp;
FilledCircle : Boolean from Standard = Standard_False)
returns SensitiveCircle;
---Level: Internal
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the array of triangles apolyg3d, and the Boolean FilledCircle.
-- apolyg3d is an array of consecutive triangles on the
-- circle. The triangle i+1 lies on the intersection of the
-- tangents to the circle of i and i+2. Note, that the first point of apolyg3d
-- must be equal to the last point of apolyg3d.
Create(OwnerId : EntityOwner from SelectBasics;
apolyg3d : Array1OfPnt from TColgp;
FilledCircle : Boolean from Standard = Standard_False)
returns SensitiveCircle;
---Purpose: Constructs the sensitive circle object defined by the
-- owner OwnerId, the array of points apolyg3d, and the Boolean FilledCircle.
-- If the length of apolyg3d is more then 1, the first point of apolyg3d
-- must be equal to the last point of apolyg3d.
Matches (me : mutable;
thePickArgs : PickArgs from SelectBasics;
theMatchDMin, theMatchDepth : out Real from Standard)
returns Boolean is redefined static;
---Level: Public
---Purpose: Checks whether the sensitive entity matches the picking
-- detection area (close to the picking line).
-- For details please refer to base class declaration.
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is redefined static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth (me;
thePickLine : Lin from gp;
theDetectedIndex : Integer from Standard)
returns Real from Standard;
---Level: Public
---Purpose: Compute depth of sensitive circle for the detected sub-part.
-- @param thePickLine [in] the picking line.
-- @param theDetectedIndex [in] index of the detected sub-part.
-- @return depth on the picking line.
ArrayBounds(me;Low,Up:in out Integer);
GetPoint3d(me;rank:Integer) returns Pnt from gp;
---Level: Internal
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
GetConnected(me: mutable; theLocation : Location from TopLoc)
returns SensitiveEntity from Select3D
is redefined virtual;
---Level: Public
---Purpose: Returns the copy of this.
Project(me: mutable;aProjector: Projector from Select3D) is redefined virtual;
ComputeCenter3D(me: mutable) is private;
---Level: Internal
---Purpose: Computes myCenter3D as the barycenter of points from mypolyg3d
fields
myFillStatus : Boolean;
myCenter2D : Pnt2d from Select3D; -- used for Matches()
myCenter3D : Pnt from Select3D; -- used for Matches()
myCircle : Circle from Geom;
mystart : Real from Standard; -- used for GetConnected()
myend : Real from Standard; -- used for GetConnected()
end SensitiveCircle;

View File

@@ -14,43 +14,41 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// Modified Tue Apr 14 1998 by rob : fix Bug : Case of Null Radius Circle...
#include <Geom_Circle.hxx>
#include <Select3D_SensitiveCircle.ixx>
#include <Precision.hxx>
#include <gp_Lin2d.hxx>
#include <CSLib_Class2d.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <ElCLib.hxx>
#include <Select3D_Pnt.hxx>
#include <Select3D_Pnt2d.hxx>
#include <Select3D_Projector.hxx>
#include <Select3D_SensitiveTriangle.hxx>
#include <Precision.hxx>
#include <Select3D_SensitiveCircle.hxx>
static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
IMPLEMENT_STANDARD_HANDLE (Select3D_SensitiveCircle, Select3D_SensitivePoly)
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveCircle, Select3D_SensitivePoly)
static Standard_Integer GetCircleNbPoints (const Handle(Geom_Circle)& theCircle,
const Standard_Integer theNbPnts)
{
// Check if number of points is invalid.
// In this case mypolyg raises Standard_ConstructionError
// In this case myPolyg raises Standard_ConstructionError
// exception (look constructor bellow).
if (anInputNumber <= 0)
if (theNbPnts <= 0)
return 0;
if (C->Radius()>Precision::Confusion())
return 2*anInputNumber+1;
if (theCircle->Radius() > Precision::Confusion())
return 2 * theNbPnts + 1;
// The radius is too small and circle degenerates into point
return 1;
}
static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
static Standard_Integer GetArcNbPoints (const Handle(Geom_Circle)& theCircle,
const Standard_Integer theNbPnts)
{
// There is no need to check number of points here.
// In case of invalid number of points this method returns
// -1 or smaller value.
if (C->Radius()>Precision::Confusion())
return 2*anInputNumber-1;
if (theCircle->Radius() > Precision::Confusion())
return 2 * theNbPnts - 1;
// The radius is too small and circle degenerates into point
return 1;
@@ -60,53 +58,57 @@ static Standard_Integer S3D_GetArcNBPoints(const Handle(Geom_Circle)& C,
//function : Select3D_SensitiveCircle (constructor)
//purpose : Definition of a sensitive circle
//=======================================================================
Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Circle)& TheCircle,
const Standard_Boolean FilledCircle,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
myCircle(TheCircle),
mystart(0),
myend(0)
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(Geom_Circle)& theCircle,
const Standard_Boolean theIsFilled,
const Standard_Integer theNbPnts)
: Select3D_SensitivePoly (theOwnerId, !theIsFilled, GetCircleNbPoints (theCircle, theNbPnts)),
myCircle (theCircle),
myStart (0),
myEnd (0)
{
if (mypolyg.Size() != 1)
mySensType = theIsFilled ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
if (myPolyg.Size() != 1)
{
gp_Pnt p1,p2;
gp_Vec v1;
Standard_Real ustart = TheCircle->FirstParameter(),uend = TheCircle->LastParameter();
Standard_Real du = (uend-ustart)/NbPoints;
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu =ustart;
for(Standard_Integer anIndex=1;anIndex<=NbPoints;anIndex++)
gp_Pnt aP1, aP2;
gp_Vec aV1;
Standard_Real anUStart = theCircle->FirstParameter();
Standard_Real anUEnd = theCircle->LastParameter();
Standard_Real aStep = (anUEnd - anUStart) / theNbPnts;
Standard_Real aRadius = theCircle->Radius();
Standard_Integer aPntIdx = 1;
Standard_Real aCurU = anUStart;
for (Standard_Integer anIndex = 1; anIndex <= theNbPnts; anIndex++)
{
TheCircle->D1(curu,p1,v1);
theCircle->D1 (aCurU, aP1, aV1);
v1.Normalize();
mypolyg.SetPnt(rank-1, p1);
rank++;
p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R,
p1.Y()+v1.Y()*tan(du/2.)*R,
p1.Z()+v1.Z()*tan(du/2.)*R);
mypolyg.SetPnt(rank-1, p2);
rank++;
curu+=du;
aV1.Normalize();
myPolyg.SetPnt (aPntIdx - 1, aP1);
aPntIdx++;
aP2 = gp_Pnt (aP1.X() + aV1.X() * tan (aStep / 2.0) * aRadius,
aP1.Y() + aV1.Y() * tan (aStep / 2.0) * aRadius,
aP1.Z() + aV1.Z() * tan (aStep / 2.0) * aRadius);
myPolyg.SetPnt (aPntIdx - 1, aP2);
aPntIdx++;
aCurU += aStep;
}
// Copy the first point to the last point of mypolyg
mypolyg.SetPnt(NbPoints*2, mypolyg.Pnt(0));
// Copy the first point to the last point of myPolyg
myPolyg.SetPnt (theNbPnts * 2, myPolyg.Pnt (0));
// Get myCenter3D
myCenter3D = TheCircle->Location();
myCenter3D = theCircle->Location();
}
// Radius = 0.0
else
{
mypolyg.SetPnt(0, TheCircle->Location());
myPolyg.SetPnt (0, theCircle->Location());
// Get myCenter3D
myCenter3D = mypolyg.Pnt(0);
myCenter3D = myPolyg.Pnt (0);
}
if (mySensType == Select3D_TOS_BOUNDARY)
{
SetSensitivityFactor (6.0);
}
}
@@ -114,59 +116,81 @@ myend(0)
//function : Select3D_SensitiveCircle (constructor)
//purpose : Definition of a sensitive arc
//=======================================================================
Select3D_SensitiveCircle::
Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Circle)& TheCircle,
const Standard_Real u1,
const Standard_Real u2,
const Standard_Boolean FilledCircle,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
myCircle(TheCircle),
mystart(u1),
myend(u2)
Select3D_SensitiveCircle::Select3D_SensitiveCircle (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(Geom_Circle)& theCircle,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theIsFilled,
const Standard_Integer theNbPnts)
: Select3D_SensitivePoly (theOwnerId, !theIsFilled, GetArcNbPoints (theCircle, theNbPnts)),
myCircle (theCircle),
myStart (Min (theU1, theU2)),
myEnd (Max (theU1, theU2))
{
if (mypolyg.Size() != 1)
mySensType = theIsFilled ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
if (myPolyg.Size() != 1)
{
gp_Pnt p1,p2;
gp_Vec v1;
gp_Pnt aP1, aP2;
gp_Vec aV1;
if (u1 > u2)
Standard_Real aStep = (myEnd - myStart) / (theNbPnts - 1);
Standard_Real aRadius = theCircle->Radius();
Standard_Integer aPntIdx = 1;
Standard_Real aCurU = myStart;
for (Standard_Integer anIndex = 1; anIndex <= theNbPnts - 1; anIndex++)
{
mystart = u2;
myend = u1;
theCircle->D1 (aCurU, aP1, aV1);
aV1.Normalize();
myPolyg.SetPnt (aPntIdx - 1, aP1);
aPntIdx++;
aP2 = gp_Pnt (aP1.X() + aV1.X() * tan (aStep /2.0) * aRadius,
aP1.Y() + aV1.Y() * tan (aStep /2.0) * aRadius,
aP1.Z() + aV1.Z() * tan (aStep /2.0) * aRadius);
myPolyg.SetPnt (aPntIdx - 1, aP2);
aPntIdx++;
aCurU += aStep;
}
Standard_Real du = (myend-mystart)/(NbPoints-1);
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu = mystart;
for(Standard_Integer anIndex=1;anIndex<=NbPoints-1;anIndex++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
mypolyg.SetPnt(rank-1, p1);
rank++;
p2 = gp_Pnt(p1.X()+v1.X()*tan(du/2.)*R,
p1.Y()+v1.Y()*tan(du/2.)*R,
p1.Z()+v1.Z()*tan(du/2.)*R);
mypolyg.SetPnt(rank-1, p2);
rank++;
curu+=du;
}
TheCircle->D0(myend,p1);
mypolyg.SetPnt(NbPoints*2-2, p1);
theCircle->D0 (myEnd, aP1);
myPolyg.SetPnt (theNbPnts * 2 - 2, aP1);
// Get myCenter3D
myCenter3D = TheCircle->Location();
myCenter3D = theCircle->Location();
}
else
{
mypolyg.SetPnt(0, TheCircle->Location());
myPolyg.SetPnt (0, theCircle->Location());
// Get myCenter3D
myCenter3D = mypolyg.Pnt(0);
myCenter3D = myPolyg.Pnt (0);
}
if (mySensType == Select3D_TOS_BOUNDARY)
{
SetSensitivityFactor (6.0);
}
}
//=======================================================================
//function : Select3D_SensitiveCircle
//purpose :
//=======================================================================
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(TColgp_HArray1OfPnt)& thePnts3d,
const Standard_Boolean theIsFilled)
: Select3D_SensitivePoly (theOwnerId, thePnts3d, !theIsFilled),
myStart (0),
myEnd (0)
{
mySensType = theIsFilled ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
if (myPolyg.Size() != 1)
computeCenter3D();
else
myCenter3D = myPolyg.Pnt (0);
if (mySensType == Select3D_TOS_BOUNDARY)
{
SetSensitivityFactor (6.0);
}
}
@@ -175,338 +199,161 @@ myend(u2)
//purpose :
//=======================================================================
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& Thepolyg3d,
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
mystart(0),
myend(0)
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePnts3d,
const Standard_Boolean theIsFilled)
: Select3D_SensitivePoly (theOwnerId, thePnts3d, !theIsFilled),
myStart (0),
myEnd (0)
{
if (mypolyg.Size() != 1)
ComputeCenter3D();
mySensType = theIsFilled ? Select3D_TOS_INTERIOR : Select3D_TOS_BOUNDARY;
if (myPolyg.Size() != 1)
computeCenter3D();
else
myCenter3D = mypolyg.Pnt(0);
}
myCenter3D = myPolyg.Pnt (0);
//=======================================================================
//function : Select3D_SensitiveCircle
//purpose :
//=======================================================================
Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& Thepolyg3d,
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
mystart(0),
myend(0)
{
if (mypolyg.Size() != 1)
ComputeCenter3D();
else
myCenter3D = mypolyg.Pnt(0);
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::Matches (const SelectBasics_PickArgs& thePickArgs,
Standard_Real& theMatchDMin,
Standard_Real& theMatchDepth)
{
Standard_Integer aSize = mypolyg.Size();
Standard_Integer aDetectedIndex = -1;
gp_XY aPickXY (thePickArgs.X(), thePickArgs.Y());
if (aSize != 1)
if (mySensType == Select3D_TOS_BOUNDARY)
{
Standard_Boolean Found = Standard_False;
Standard_Integer anIndex = 0;
SetSensitivityFactor (6.0);
}
}
if(!myFillStatus)
{
while(anIndex < aSize-2 && !Found)
{
Standard_Integer TheStat =
Select3D_SensitiveTriangle::Status(mypolyg.Pnt2d(anIndex),
mypolyg.Pnt2d(anIndex+1),
mypolyg.Pnt2d(anIndex+2),
aPickXY, thePickArgs.Tolerance(),
theMatchDMin);
Found = (TheStat != 2);
if (Found)
{
aDetectedIndex = anIndex;
}
//=======================================================================
// function : BVH
// purpose : Builds BVH tree for a circle's edge segments if needed
//=======================================================================
void Select3D_SensitiveCircle::BVH()
{
if (mySensType == Select3D_TOS_BOUNDARY)
{
Select3D_SensitivePoly::BVH();
}
}
anIndex += 2;
}
}
else
{
Standard_Real Xmin,Ymin,Xmax,Ymax;
//=======================================================================
// function : Matches
// purpose : Checks whether the circle overlaps current selecting volume
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
Standard_Real aDepth = RealLast();
Standard_Real aDistToCOG = RealLast();
// Get coordinates of the bounding box
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
TColgp_Array1OfPnt2d anArrayOf2dPnt(1, aSize);
// Fill anArrayOf2dPnt with points from mypolig2d
Points2D(anArrayOf2dPnt);
CSLib_Class2d anInOutTool (anArrayOf2dPnt,
thePickArgs.Tolerance(),
thePickArgs.Tolerance(),
Xmin, Ymin, Xmax, Ymax);
// Method SiDans returns the status :
// 1 - the point is inside the circle
// 0 - the point is on the circle
// -1 - the point is outside the circle
Standard_Integer aStat = anInOutTool.SiDans (gp_Pnt2d (aPickXY));
if(aStat != -1)
{
// Compute DMin (a distance between the center and the point)
theMatchDMin = gp_XY (myCenter2D.x - aPickXY.X(), myCenter2D.y - aPickXY.Y()).Modulus();
theMatchDepth = ComputeDepth (thePickArgs.PickLine(), aDetectedIndex);
return !thePickArgs.IsClipped (theMatchDepth);
}
return Standard_False;
}
if (Found)
{
theMatchDepth = ComputeDepth (thePickArgs.PickLine(), aDetectedIndex);
return !thePickArgs.IsClipped (theMatchDepth);
}
return Standard_False;
Standard_Boolean isCollisionDetected = Standard_False;
if (mySensType == Select3D_TOS_BOUNDARY)
{
isCollisionDetected = Select3D_SensitivePoly::Matches (theMgr, thePickResult);
}
else if (mySensType == Select3D_TOS_INTERIOR)
{
Handle(TColgp_HArray1OfPnt) anArrayOfPnt;
Points3D (anArrayOfPnt);
isCollisionDetected = theMgr.Overlaps (anArrayOfPnt,
Select3D_TOS_INTERIOR,
aDepth);
}
// Circle degenerates into point
theMatchDMin = gp_Pnt2d(aPickXY).Distance(mypolyg.Pnt2d(0));
if (theMatchDMin <= thePickArgs.Tolerance() * SensitivityFactor())
if (isCollisionDetected)
{
theMatchDepth = ComputeDepth (thePickArgs.PickLine(), aDetectedIndex);
return !thePickArgs.IsClipped (theMatchDepth);
aDistToCOG = theMgr.DistToGeometryCenter (myCenter3D);
}
return Standard_False;
thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
return isCollisionDetected;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
void Select3D_SensitiveCircle::ArrayBounds (Standard_Integer & theLow,
Standard_Integer & theUp) const
{
Bnd_Box2d abox;
abox.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
abox.Enlarge(aTol);
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();anIndex++)
{
if(abox.IsOut(mypolyg.Pnt2d(anIndex)))
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
if(RES!=1)
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : ArrayBounds
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::
ArrayBounds(Standard_Integer & Low,
Standard_Integer & Up) const
{
Low = 0;
Up = mypolyg.Size()-1;
theLow = 0;
theUp = myPolyg.Size() - 1;
}
//=======================================================================
//function : GetPoint3d
//purpose :
//=======================================================================
gp_Pnt Select3D_SensitiveCircle::
GetPoint3d(const Standard_Integer Rank) const
gp_Pnt Select3D_SensitiveCircle::GetPoint3d (const Standard_Integer thePntIdx) const
{
if(Rank>=0 && Rank<mypolyg.Size())
return mypolyg.Pnt(Rank);
if (thePntIdx >= 0 && thePntIdx < myPolyg.Size())
return myPolyg.Pnt (thePntIdx);
return gp_Pnt();
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
Standard_Integer aSize = mypolyg.Size();
S<<"\tSensitiveCircle 3D :";
Standard_Boolean isclosed = 1== aSize;
if(isclosed)
S<<"(Closed Circle)"<<endl;
else
S<<"(Arc Of Circle)"<<endl;
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
if(FullDump)
{
gp_XYZ aCenter = myCenter3D;
Standard_Real R = (aCenter-mypolyg.Pnt(0)).Modulus();
S<<"\t\t Center : ("<<aCenter.X()<<" , "<<aCenter.Y()<<" , "<<aCenter.Z()<<" )"<<endl;
S<<"\t\t Radius :"<<R<<endl;
}
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveCircle::ComputeDepth (const gp_Lin& thePickLine,
const Standard_Integer theDetectedIndex) const
{
gp_XYZ aCDG;
if (theDetectedIndex == -1)
{
aCDG = myCenter3D;
}
else
{
aCDG += mypolyg.Pnt (theDetectedIndex);
aCDG += mypolyg.Pnt (theDetectedIndex + 1);
aCDG += mypolyg.Pnt (theDetectedIndex + 2);
aCDG /= 3.;
}
return ElCLib::Parameter (thePickLine, gp_Pnt (aCDG));
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected(const TopLoc_Location& theLocation)
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected()
{
Standard_Boolean isFilled = mySensType == Select3D_TOS_INTERIOR;
// Create a copy of this
Handle(Select3D_SensitiveEntity) aNewEntity;
// this was constructed using Handle(Geom_Circle)
if(!myCircle.IsNull())
{
if((myend-mystart) > Precision::Confusion())
if ((myEnd - myStart) > Precision::Confusion())
{
// Arc
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, myCircle, mystart, myend, myFillStatus);
aNewEntity = new Select3D_SensitiveCircle (myOwnerId, myCircle, myStart, myEnd, isFilled);
}
else
{
// Circle
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, myCircle, myFillStatus);
aNewEntity = new Select3D_SensitiveCircle (myOwnerId, myCircle, isFilled);
}
}
// this was constructed using TColgp_Array1OfPnt
else
{
Standard_Integer aSize = mypolyg.Size();
TColgp_Array1OfPnt aPolyg(1, aSize);
Standard_Integer aSize = myPolyg.Size();
TColgp_Array1OfPnt aPolyg (1, aSize);
for(Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
{
aPolyg.SetValue(anIndex, mypolyg.Pnt(anIndex-1));
aPolyg.SetValue(anIndex, myPolyg.Pnt (anIndex-1));
}
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, aPolyg, myFillStatus);
aNewEntity = new Select3D_SensitiveCircle (myOwnerId, aPolyg, isFilled);
}
if(HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);
return aNewEntity;
}
//=======================================================================
//function : Project
//function : computeCenter3D
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::Project(const Handle(Select3D_Projector) &aProjector)
{
Select3D_SensitivePoly::Project(aProjector);
gp_Pnt2d aCenter;
aProjector->Project(myCenter3D, aCenter);
myCenter2D = aCenter;
}
//=======================================================================
//function : ComputeCenter3D
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::ComputeCenter3D()
void Select3D_SensitiveCircle::computeCenter3D()
{
gp_XYZ aCenter;
Standard_Integer nbpoints = mypolyg.Size();
if (nbpoints != 1)
Standard_Integer aNbPnts = myPolyg.Size();
if (aNbPnts != 1)
{
// The mass of points system
Standard_Integer aMass = nbpoints - 1;
Standard_Integer aMass = aNbPnts - 1;
// Find the circle barycenter
for (Standard_Integer anIndex = 0; anIndex < nbpoints-1; ++anIndex)
for (Standard_Integer anIndex = 0; anIndex < aNbPnts - 1; ++anIndex)
{
aCenter += mypolyg.Pnt(anIndex);
aCenter += myPolyg.Pnt(anIndex);
}
myCenter3D = aCenter / aMass;
}
else
{
myCenter3D = mypolyg.Pnt(0);
myCenter3D = myPolyg.Pnt(0);
}
}
//=======================================================================
// function : CenterOfGeometry
// purpose : Returns center of the circle. If location transformation
// is set, it will be applied
//=======================================================================
gp_Pnt Select3D_SensitiveCircle::CenterOfGeometry() const
{
return myCenter3D;
}

View File

@@ -0,0 +1,124 @@
// Created on: 1996-02-06
// Created by: Robert COUBLANC
// Copyright (c) 1996-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
// Modified Tue Apr 14 1998 by rob : fix Bug : Case of Null Radius Circle...
#ifndef _Select3D_SensitiveCircle_HeaderFile
#define _Select3D_SensitiveCircle_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Standard_Type.hxx>
#include <Select3D_SensitivePoly.hxx>
#include <Select3D_Pnt.hxx>
#include <Handle_Geom_Circle.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Handle_TColgp_HArray1OfPnt.hxx>
#include <SelectMgr_SelectingVolumeManager.hxx>
#include <Select3D_TypeOfSensitivity.hxx>
class Geom_Circle;
class Standard_ConstructionError;
class Standard_OutOfRange;
class SelectBasics_EntityOwner;
class TColgp_HArray1OfPnt;
class TColgp_Array1OfPnt;
class gp_Pnt;
class TopLoc_Location;
//! A framework to define sensitive 3D arcs and circles.
//! In some cases this class can raise Standard_ConstructionError and
//! Standard_OutOfRange exceptions. For more details see Select3D_SensitivePoly.
class Select3D_SensitiveCircle : public Select3D_SensitivePoly
{
public:
//! Constructs the sensitive circle object defined by the
//! owner theOwnerId, the circle theCircle, the boolean
//! theIsFilled and the number of points theNbPnts.
Standard_EXPORT Select3D_SensitiveCircle (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(Geom_Circle)& theCircle,
const Standard_Boolean theIsFilled = Standard_False,
const Standard_Integer theNbPnts = 12);
//! Constructs the sensitive arc object defined by the
//! owner theOwnerId, the circle theCircle, the parameters theU1
//! and theU2, the boolean theIsFilled and the number of points theNbPnts.
//! theU1 and theU2 define the first and last points of the arc on theCircle.
Standard_EXPORT Select3D_SensitiveCircle (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(Geom_Circle)& theCircle,
const Standard_Real theU1,
const Standard_Real theU2,
const Standard_Boolean theIsFilled = Standard_False,
const Standard_Integer theNbPnts = 12);
//! Constructs the sensitive circle object defined by the
//! owner theOwnerId, the array of triangles thePnts3d, and the boolean theIsFilled.
//! thePnts3d is an array of consecutive triangles on the
//! circle. The triangle i+1 lies on the intersection of the
//! tangents to the circle of i and i+2. Note, that the first point of thePnts3d
//! must be equal to the last point of thePnts3d.
Standard_EXPORT Select3D_SensitiveCircle (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(TColgp_HArray1OfPnt)& thePnts3d,
const Standard_Boolean theIsFilled = Standard_False);
//! Constructs the sensitive circle object defined by the
//! owner theOwnerId, the array of points thePnts3d, and the boolean theIsFilled.
//! If the length of thePnts3d is more then 1, the first point of thePnts3d
//! must be equal to the last point of thePnts3d.
Standard_EXPORT Select3D_SensitiveCircle (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePnts3d,
const Standard_Boolean theIsFilled = Standard_False);
//! Checks whether the circle overlaps current selecting volume
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
Standard_EXPORT void ArrayBounds (Standard_Integer & theLow, Standard_Integer & theUp) const;
Standard_EXPORT gp_Pnt GetPoint3d (const Standard_Integer thePntIdx) const;
Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
//! Returns center of the circle. If location
//! transformation is set, it will be applied
Standard_EXPORT virtual gp_Pnt CenterOfGeometry() const Standard_OVERRIDE;
//! Builds BVH tree for a circle's edge segments if needed
Standard_EXPORT virtual void BVH() Standard_OVERRIDE;
DEFINE_STANDARD_RTTI(Select3D_SensitiveCircle)
private:
//! Computes myCenter3D as the barycenter of points from mypolyg3d
void computeCenter3D();
private:
Select3D_TypeOfSensitivity mySensType; //!< True if type of selection is interior, false otherwise
gp_Pnt myCenter3D; //!< Center of a circle
Handle_Geom_Circle myCircle; //!< Points of the circle
Standard_Real myStart; //!< Sensitive arc parameter
Standard_Real myEnd; //!< Sensitive arc parameter
};
DEFINE_STANDARD_HANDLE(Select3D_SensitiveCircle, Select3D_SensitivePoly)
#endif // _Select3D_SensitiveCircle_HeaderFile

View File

@@ -1,139 +0,0 @@
-- Created on: 1995-03-10
-- Created by: Mister rmi
-- Copyright (c) 1995-1999 Matra Datavision
-- Copyright (c) 1999-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
-- Modified on july 97 by ROB : Field HArray instead Of ArrayOfPnt3D
-- (connected entities)
class SensitiveCurve from Select3D
inherits SensitivePoly from Select3D
---Purpose: A framework to define a sensitive 3D curve.
-- In some cases this class can raise Standard_ConstructionError and
-- Standard_OutOfRange exceptions. For more details see Select3D_SensitivePoly.
uses
Pnt from gp,
Pnt2d from gp,
Projector from Select3D,
Lin from gp,
EntityOwner from SelectBasics,
ListOfBox2d from SelectBasics,
PickArgs from SelectBasics,
Curve from Geom,
Array1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
HArray1OfPnt from TColgp,
Box2d from Bnd,
Location from TopLoc,
SensitiveEntity from Select3D,
XYZ from gp
raises
ConstructionError from Standard,
OutOfRange from Standard
is
Create (OwnerId : EntityOwner from SelectBasics;
TheCurve : Curve from Geom;
MaxPoints : Integer = 17)
returns SensitiveCurve;
---Level: Public
---Purpose: Constructs a sensitive curve object defined by the
-- owner OwnerId, the curve TheCurve, and the
-- maximum number of points on the curve: MaxPoints.
Create (OwnerId : EntityOwner from SelectBasics;
ThePoints : HArray1OfPnt from TColgp)
returns SensitiveCurve;
---Level: Public
---Purpose: Constructs a sensitive curve object defined by the
-- owner OwnerId and the set of points ThePoints.
Create (OwnerId : EntityOwner from SelectBasics;
ThePoints : Array1OfPnt from TColgp)
returns SensitiveCurve;
---Level: Public
---Purpose: Creation of Sensitive Curve from Points.
-- Warning : This Method should disappear in the next version...
Matches (me : mutable;
thePickArgs : PickArgs from SelectBasics;
theMatchDMin, theMatchDepth : out Real from Standard)
returns Boolean is redefined static;
---Level: Public
---Purpose: Checks whether the sensitive entity matches the picking
-- detection area (close to the picking line).
-- For details please refer to base class declaration.
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean
is static;
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean
is redefined virtual;
---Level: Public
ComputeDepth (me;
thePickLine : Lin from gp;
theDetectedIndex : Integer from Standard)
returns Real from Standard;
---Level: Public
---Purpose: Compute depth of sensitive circle for the detected sub-part.
-- @param thePickLine [in] the picking line.
-- @param theDetectedIndex [in] index of the detected sub-part.
-- @return depth on the picking line.
GetLastDetected(me) returns Integer from Standard;
---Purpose: Gets index of last detected segment
---C++: inline
---Category: Internal Methods
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is redefined virtual;
LoadPoints(me:mutable;aCurve:Curve from Geom;NbPoints: Integer) is static private;
GetConnected(me: mutable; theLocation : Location from TopLoc)
returns SensitiveEntity from Select3D
is redefined virtual;
---Level: Public
---Purpose: Returns the copy of this
ComputeDepth(me;
thePickLine : Lin from gp;
theP1 : XYZ from gp;
theP2 : XYZ from gp;
theDepth : out Real from Standard)
---Purpose: Computes the depth by means of intersection of
-- a segment of the curve defined by <theP1, theP2> and
-- the eye-line <thePickLine>.
returns Boolean from Standard
is protected;
fields
mylastseg : Integer from Standard;
myCurve : Curve from Geom;
end SensitiveCurve;

View File

@@ -14,300 +14,126 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Select3D_SensitiveCurve.ixx>
#include <SelectBasics_BasicTool.hxx>
#include <gp_Lin2d.hxx>
#include <Select3D_SensitiveCurve.hxx>
#include <Precision.hxx>
#include <ElCLib.hxx>
#include <CSLib_Class2d.hxx>
#include <Extrema_ExtElC.hxx>
#include <TColgp_Array1OfPnt.hxx>
IMPLEMENT_STANDARD_HANDLE (Select3D_SensitiveCurve, Select3D_SensitivePoly)
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveCurve, Select3D_SensitivePoly)
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(Geom_Curve)& C,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, NbPoints),
mylastseg(0),
myCurve(C)
Select3D_SensitiveCurve::Select3D_SensitiveCurve (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(Geom_Curve)& theCurve,
const Standard_Integer theNbPnts)
: Select3D_SensitivePoly (theOwnerId, theNbPnts > 2, theNbPnts),
myCurve (theCurve)
{
LoadPoints(C,NbPoints);
loadPoints (theCurve, theNbPnts);
SetSensitivityFactor (3.0);
}
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve::Select3D_SensitiveCurve (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(TColgp_HArray1OfPnt)& thePoints)
: Select3D_SensitivePoly (theOwnerId, thePoints, thePoints->Length() > 2)
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0)
{
SetSensitivityFactor (3.0);
}
//==================================================
// Function: Creation
// Purpose :
//==================================================
Select3D_SensitiveCurve
::Select3D_SensitiveCurve(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitivePoly(OwnerId, ThePoints),
mylastseg(0)
Select3D_SensitiveCurve::Select3D_SensitiveCurve (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePoints)
: Select3D_SensitivePoly (theOwnerId, thePoints, thePoints.Length() > 2)
{
SetSensitivityFactor (3.0);
}
//==================================================
// Function: Matches
// Function: loadPoints
// Purpose :
//==================================================
Standard_Boolean Select3D_SensitiveCurve::Matches (const SelectBasics_PickArgs& thePickArgs,
Standard_Real& theMatchDMin,
Standard_Real& theMatchDepth)
void Select3D_SensitiveCurve::loadPoints (const Handle(Geom_Curve)& theCurve, const Standard_Integer theNbPnts)
{
Standard_Integer Rank;
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mypolyg.Size());
Points2D(aArrayOf2dPnt);
if (SelectBasics_BasicTool::MatchPolyg2d (aArrayOf2dPnt,
thePickArgs.X(), thePickArgs.Y(),
thePickArgs.Tolerance(),
theMatchDMin,
Rank))
Standard_Real aStep = (theCurve->LastParameter() - theCurve->FirstParameter()) / (theNbPnts - 1);
Standard_Real aParam = theCurve->FirstParameter();
for (Standard_Integer aPntIdx = 0; aPntIdx < myPolyg.Size(); ++aPntIdx)
{
// remember detected segment (for GetLastDetected)
mylastseg = Rank;
theMatchDepth = ComputeDepth (thePickArgs.PickLine(), Rank);
return !thePickArgs.IsClipped (theMatchDepth);
myPolyg.SetPnt (aPntIdx, theCurve->Value (aParam));
aParam += aStep;
}
return Standard_False;
}
//==================================================
// Function: Matches
// Purpose : know if a box touches the projected polygon
// of the Curve.
//==================================================
Standard_Boolean Select3D_SensitiveCurve::
Matches (const Standard_Real XMin,
const Standard_Real YMin,
const Standard_Real XMax,
const Standard_Real YMax,
const Standard_Real aTol)
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer anIndex=0; anIndex<mypolyg.Size(); ++anIndex)
{
if(BoundBox.IsOut(mypolyg.Pnt2d(anIndex)))
return Standard_False;
}
return Standard_True;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveCurve::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
if(RES!=1)
return Standard_False;
}
return Standard_True;
}
//==================================================
// Function: LoadPoints
// Purpose :
//==================================================
void Select3D_SensitiveCurve
::LoadPoints (const Handle(Geom_Curve)& aCurve,const Standard_Integer NbP)
{
/*this method is private and it used only inside of constructor.
That's why check !NbP==mypolyg3d->Length() was removed*/
Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1);
Standard_Real Curparam = aCurve->FirstParameter();
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
mypolyg.SetPnt(anIndex, aCurve->Value(Curparam));
Curparam+=Step;
}
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveCurve 3D :"<<endl;
if (HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\tNumber Of Points :"<<mypolyg.Size()<<endl;
if(FullDump)
{
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
//=======================================================================
//function : ComputeDepth
//purpose :
//=======================================================================
Standard_Real Select3D_SensitiveCurve::ComputeDepth (const gp_Lin& thePickLine,
const Standard_Integer theSegment) const
{
Standard_Real aDepth = Precision::Infinite();
if (theSegment == 0)
{
return aDepth;
}
// In case if theSegment and theSegment + 1 are not valid
// the depth will be infinite
if (theSegment >= mypolyg.Size())
{
return aDepth;
}
gp_XYZ aCDG = mypolyg.Pnt (theSegment);
// Check depth of a line forward within the curve.
if (theSegment + 1 < mypolyg.Size())
{
gp_XYZ aCDG1 = mypolyg.Pnt (theSegment + 1);
if (ComputeDepth(thePickLine, aCDG, aCDG1, aDepth))
{
return aDepth;
}
}
// Check depth of a line backward within the curve.
if (theSegment - 1 >= 0)
{
gp_XYZ aCDG1 = mypolyg.Pnt (theSegment - 1);
if (ComputeDepth(thePickLine, aCDG, aCDG1, aDepth))
{
return aDepth;
}
}
// Calculate the depth in the middle point of
// a next (forward) segment of the curve.
if (theSegment + 1 < mypolyg.Size())
{
aCDG += mypolyg.Pnt(theSegment + 1);
aCDG /= 2.;
}
return ElCLib::Parameter (thePickLine, gp_Pnt (aCDG));
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCurve::GetConnected(const TopLoc_Location &theLocation)
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCurve::GetConnected()
{
// Create a copy of this
Handle(Select3D_SensitiveEntity) aNewEntity;
// this was constructed using Handle(Geom_Curve)
if (!myCurve.IsNull())
{
aNewEntity = new Select3D_SensitiveCurve(myOwnerId, myCurve);
aNewEntity = new Select3D_SensitiveCurve (myOwnerId, myCurve);
}
// this was constructed using TColgp_HArray1OfPnt
else
{
Standard_Integer aSize = mypolyg.Size();
Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, aSize);
Standard_Integer aSize = myPolyg.Size();
Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt (1, aSize);
// Fill the array with points from mypolyg3d
for (Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
{
aPoints->SetValue(anIndex, mypolyg.Pnt(anIndex-1));
aPoints->SetValue (anIndex, myPolyg.Pnt (anIndex-1));
}
aNewEntity = new Select3D_SensitiveCurve(myOwnerId, aPoints);
aNewEntity = new Select3D_SensitiveCurve (myOwnerId, aPoints);
}
if (HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);
return aNewEntity;
}
//=======================================================================
//function : ComputeDepth()
//purpose : Computes the depth by means of intersection of
// a segment of the curve defined by <theP1, theP2> and
// the eye-line <thePickLine>.
// function : Matches
// purpose : Checks whether the curve overlaps current selecting volume
//=======================================================================
Standard_Boolean Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& thePickLine,
const gp_XYZ& theP1,
const gp_XYZ& theP2,
Standard_Real& theDepth) const
Standard_Boolean Select3D_SensitiveCurve::Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult)
{
// The segment may have null length.
gp_XYZ aVec = theP2 - theP1;
Standard_Real aLength = aVec.Modulus();
if (aLength <= gp::Resolution())
{
theDepth = ElCLib::Parameter(thePickLine, theP1);
return Standard_True;
}
if (myPolyg.Size() > 2)
return Select3D_SensitivePoly::Matches (theMgr, thePickResult);
// Compute an intersection point of the segment-line and the eye-line.
gp_Lin aLine (theP1, aVec);
Extrema_ExtElC anExtrema(aLine, thePickLine, Precision::Angular());
if (anExtrema.IsDone() && !anExtrema.IsParallel() )
const gp_Pnt aPnt1 = myPolyg.Pnt3d (0);
const gp_Pnt aPnt2 = myPolyg.Pnt3d (1);
Standard_Real aDepth = RealLast();
Standard_Boolean isMatched = theMgr.Overlaps (aPnt1, aPnt2, aDepth);
if (isMatched)
{
// Iterator on solutions (intersection points).
for (Standard_Integer i = 1; i <= anExtrema.NbExt(); i++)
Standard_Real aDistToCOG = RealLast();
if (myCOG.X() == RealLast() && myCOG.Y() == RealLast() && myCOG.Z() == RealLast())
{
// Get the intersection point.
Extrema_POnCurv aPointOnLine1, aPointOnLine2;
anExtrema.Points(i, aPointOnLine1, aPointOnLine2);
// Check bounds: the point of intersection should lie within the segment.
if (aPointOnLine1.Parameter() > 0.0 && aPointOnLine1.Parameter() < aLength)
gp_XYZ aCenter (0.0, 0.0, 0.0);
for (Standard_Integer aIdx = 0; aIdx < myPolyg.Size(); ++aIdx)
{
theDepth = ElCLib::Parameter(thePickLine, aPointOnLine1.Value());
return Standard_True;
aCenter += myPolyg.Pnt (aIdx);
}
myCOG = aCenter / myPolyg.Size();
}
aDistToCOG = theMgr.DistToGeometryCenter (myCOG);
thePickResult = SelectBasics_PickResult (aDepth, aDistToCOG);
return Standard_True;
}
return Standard_False;

View File

@@ -0,0 +1,91 @@
// Created on: 1995-03-13
// Created by: Robert COUBLANC
// Copyright (c) 1995-1999 Matra Datavision
// Copyright (c) 1999-2014 OPEN CASCADE SAS
//
// This file is part of Open CASCADE Technology software library.
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License version 2.1 as published
// by the Free Software Foundation, with special exception defined in the file
// OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
// distribution for complete text of the license and disclaimer of any warranty.
//
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#ifndef _Select3D_SensitiveCurve_HeaderFile
#define _Select3D_SensitiveCurve_HeaderFile
#include <Standard.hxx>
#include <Standard_DefineHandle.hxx>
#include <Standard_Type.hxx>
#include <Geom_Curve.hxx>
#include <Handle_Geom_Curve.hxx>
#include <Select3D_SensitivePoly.hxx>
#include <Handle_SelectBasics_EntityOwner.hxx>
#include <Handle_TColgp_HArray1OfPnt.hxx>
#include <Standard_Boolean.hxx>
#include <SelectMgr_SelectingVolumeManager.hxx>
#include <Standard_Real.hxx>
#include <Standard_OStream.hxx>
class Geom_Curve;
class Standard_ConstructionError;
class Standard_OutOfRange;
class SelectBasics_EntityOwner;
class TColgp_HArray1OfPnt;
class TColgp_Array1OfPnt;
class Select3D_SensitiveEntity;
class TopLoc_Location;
//! A framework to define a sensitive 3D curve.
//! In some cases this class can raise Standard_ConstructionError and
//! Standard_OutOfRange exceptions. For more details see Select3D_SensitivePoly.
class Select3D_SensitiveCurve : public Select3D_SensitivePoly
{
public:
//! Constructs a sensitive curve object defined by the
//! owner theOwnerId, the curve theCurve, and the
//! maximum number of points on the curve: theNbPnts.
Standard_EXPORT Select3D_SensitiveCurve (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(Geom_Curve)& theCurve,
const Standard_Integer theNbPnts = 17);
//! Constructs a sensitive curve object defined by the
//! owner theOwnerId and the set of points ThePoints.
Standard_EXPORT Select3D_SensitiveCurve (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const Handle(TColgp_HArray1OfPnt)& thePoints);
//! Creation of Sensitive Curve from Points.
//! Warning : This Method should disappear in the next version...
Standard_EXPORT Select3D_SensitiveCurve (const Handle(SelectBasics_EntityOwner)& theOwnerId,
const TColgp_Array1OfPnt& thePoints);
//! Checks whether the curve overlaps current selecting volume
Standard_EXPORT virtual Standard_Boolean Matches (SelectBasics_SelectingVolumeManager& theMgr,
SelectBasics_PickResult& thePickResult) Standard_OVERRIDE;
//! Returns the copy of this
Standard_EXPORT virtual Handle(Select3D_SensitiveEntity) GetConnected() Standard_OVERRIDE;
public:
DEFINE_STANDARD_RTTI(Select3D_SensitiveCurve)
private:
void loadPoints (const Handle(Geom_Curve)& aCurve,
const Standard_Integer NbPoints);
private:
Handle_Geom_Curve myCurve; //!< Curve points
};
DEFINE_STANDARD_HANDLE(Select3D_SensitiveCurve, Select3D_SensitivePoly)
#endif // _Select3D_SensitiveCurve_HeaderFile

View File

@@ -1,135 +0,0 @@
-- Created on: 1995-01-24
-- Created by: Rob
-- Copyright (c) 1995-1999 Matra Datavision
-- Copyright (c) 1999-2014 OPEN CASCADE SAS
--
-- This file is part of Open CASCADE Technology software library.
--
-- This library is free software; you can redistribute it and/or modify it under
-- the terms of the GNU Lesser General Public License version 2.1 as published
-- by the Free Software Foundation, with special exception defined in the file
-- OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
-- distribution for complete text of the license and disclaimer of any warranty.
--
-- Alternatively, this file may be used under the terms of Open CASCADE
-- commercial license or contractual agreement.
-- modified by rob jul/ 21/ 97 : inserting locations ...
-- modified by rob jan/ 29/ 98 : Sort by deph-> add a field to be able
-- to compute a depth
-- -> Virtual methods rather than
-- Deferred for Project
-- WARNING : Must be redefined for
-- each kind of sensitive entity
deferred class SensitiveEntity from Select3D inherits
SensitiveEntity from SelectBasics
---Purpose: Abstract framework to define 3D sensitive entities.
-- As the selection process uses the principle of a
-- projection of 3D shapes onto a 2D view where
-- nearness to a rectangle determines whether a shape
-- is picked or not, all 3D shapes need to be converted
-- into 2D ones in order to be selected.
uses
Projector from Select3D,
EntityOwner from SelectBasics,
Location from TopLoc,
Lin from gp,
Box2d from Bnd,
Array1OfPnt2d from TColgp
is
Initialize(OwnerId : EntityOwner from SelectBasics);
NeedsConversion(me) returns Boolean is redefined static;
---Level: Public
---Purpose: Returns true if this framework needs conversion.
---C++: inline
Is3D(me) returns Boolean from Standard is redefined static;
---Purpose: Returns true if this framework provides 3D information.
Project (me:mutable;aProjector : Projector from Select3D) is deferred;
---Level: Public
---Purpose: In classes inheriting this framework, you must
-- redefine this function in order to get a sensitive 2D
-- rectangle from a 3D entity. This rectangle is the
-- sensitive zone which makes the 3D entity selectable.
MaxBoxes(me) returns Integer is redefined virtual;
---Level: Public
---Purpose: Returns the max number of sensitive areas returned
-- by this class is 1 by default.
-- Else on must redefine this method.
GetConnected(me:mutable;aLocation: Location from TopLoc)
returns SensitiveEntity from Select3D is virtual;
---Purpose: Originally this method intended to return sensitive
-- entity with new location aLocation, but currently sensitive
-- entities do not hold a location, instead HasLocation() and
-- Location() methods call corresponding entity owner's methods.
-- Thus all entities returned by GetConnected() share the same
-- location propagated from corresponding selectable object.
-- You must redefine this function for any type of
-- sensitive entity which can accept another connected
-- sensitive entity.//can be connected to another sensitive entity.
Matches (me :mutable;
XMin,YMin,XMax,YMax : Real from Standard;
aTol: Real from Standard)
returns Boolean from Standard is redefined virtual;
---Purpose: Matches the box defined by the coordinates Xmin,
-- Ymin, Xmax, Ymax with the entity found at that point
-- within the tolerance aTol.
-- Xmin, YMin define the minimum point in the lower left
-- hand corner of the box, and XMax, YMax define the
-- maximum point in the upper right hand corner of the box.
-- You must redefine this function for every inheriting entity.
-- You will have to call this framework inside the redefined function.
Matches (me :mutable;
Polyline:Array1OfPnt2d from TColgp;
aBox:Box2d from Bnd;
aTol: Real from Standard)
returns Boolean from Standard is redefined virtual;
---Purpose: prevents from hiding virtual methods...
---Category: Location of sensitive entities...
-- Default implementations of HasLocation() and Location() rely on
-- location obtained from the entity owner, to minimize memory usage.
-- SetLocation() and ResetLocation() do nothing by default.
HasLocation(me) returns Boolean from Standard is virtual;
---Purpose: Returns true if this framework has a location defined.
Location(me) returns Location from TopLoc is virtual;
---C++: return const
ResetLocation(me:mutable) is virtual;
---Purpose: sets the location to Identity
SetLocation(me:mutable;aLoc :Location from TopLoc) is virtual;
Dump(me; S: in out OStream;FullDump : Boolean from Standard = Standard_True) is virtual;
---Purpose: 2 options :
-- <FullDump> = False -> general information
-- <FullDump> = True -> whole informtion 3D +2d ...
DumpBox(myclass; S: in out OStream;abox:Box2d from Bnd) ;
UpdateLocation(me:mutable;aLoc:Location from TopLoc);
end SensitiveEntity;

View File

@@ -14,153 +14,60 @@
// Alternatively, this file may be used under the terms of Open CASCADE
// commercial license or contractual agreement.
#include <Select3D_SensitiveEntity.ixx>
#include <Select3D_SensitiveEntity.hxx>
#include <Precision.hxx>
#include <SelectBasics_EntityOwner.hxx>
#include <Select3D_Macro.hxx>
#include <TopLoc_Location.hxx>
IMPLEMENT_STANDARD_HANDLE (Select3D_SensitiveEntity, SelectBasics_SensitiveEntity)
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveEntity, SelectBasics_SensitiveEntity)
//=======================================================================
//function : Select3D_SensitiveEntity
//purpose :
//=======================================================================
Select3D_SensitiveEntity::Select3D_SensitiveEntity(const Handle(SelectBasics_EntityOwner)& OwnerId):
SelectBasics_SensitiveEntity(OwnerId)
{}
Select3D_SensitiveEntity::Select3D_SensitiveEntity(const Handle(SelectBasics_EntityOwner)& theOwnerId)
: SelectBasics_SensitiveEntity (theOwnerId) {}
//=======================================================================
//function : Matches
//purpose :
// function : Matches
// purpose : Checks whether sensitive overlaps current selecting volume.
// Stores minimum depth, distance to center of geometry and
// closest point detected into thePickResult
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const Standard_Real,
const Standard_Real,
const Standard_Real,
const Standard_Real,
const Standard_Real)
Standard_Boolean Select3D_SensitiveEntity::Matches (SelectBasics_SelectingVolumeManager& /*theMgr*/,
SelectBasics_PickResult& /*thePickResult*/)
{
return Standard_False;
}
//=======================================================================
//function : Matches
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Matches(const TColgp_Array1OfPnt2d&,
const Bnd_Box2d&,
const Standard_Real)
{
return Standard_False;
}
//=======================================================================
//function : Dump
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::Dump(Standard_OStream& S, const Standard_Boolean) const
{
S<<"\tSensitive Entity 3D"<<endl;
}
//=======================================================================
//function : DumpBox
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::DumpBox(Standard_OStream& S,const Bnd_Box2d& b2d)
{
if(!b2d.IsVoid())
{
Standard_Real xmin,ymin,xmax,ymax;
b2d.Get(xmin,ymin,xmax,ymax);
S<<"\t\t\tBox2d: PMIN ["<<xmin<<" , "<<ymin<<"]"<<endl;
S<<"\t\t\t PMAX ["<<xmax<<" , "<<ymax<<"]"<<endl;
}
}
//=======================================================================
//function : ResetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::ResetLocation()
{
}
//=======================================================================
//function : SetLocation
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::SetLocation(const TopLoc_Location&)
{
}
//=======================================================================
//function : UpdateLocation
//purpose :
//=======================================================================
void Select3D_SensitiveEntity::UpdateLocation(const TopLoc_Location& aLoc)
{
if(aLoc.IsIdentity() || aLoc == Location()) return;
if(!HasLocation())
SetLocation(aLoc);
else
{
TopLoc_Location compLoc = aLoc * Location();
SetLocation(compLoc);
}
}
//=======================================================================
//function : Location
//purpose :
//=======================================================================
const TopLoc_Location Select3D_SensitiveEntity::Location() const
{
TopLoc_Location anIdentity;
Handle(SelectBasics_EntityOwner) anOwner = OwnerId();
return anOwner.IsNull() ? anIdentity : anOwner->Location();
}
//=======================================================================
//function : HasLocation
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::HasLocation() const
{
Handle(SelectBasics_EntityOwner) anOwner = OwnerId();
return (!anOwner.IsNull() && anOwner->HasLocation());
}
//=======================================================================
//function : Is3D
//purpose :
//=======================================================================
Standard_Boolean Select3D_SensitiveEntity::Is3D() const
{return Standard_True;}
//=======================================================================
//function : MaxBoxes
//purpose :
//=======================================================================
Standard_Integer Select3D_SensitiveEntity::MaxBoxes() const
{return 1;}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveEntity::GetConnected(const TopLoc_Location&)
Handle(Select3D_SensitiveEntity) Select3D_SensitiveEntity::GetConnected()
{
Handle(Select3D_SensitiveEntity) NiouEnt;
return NiouEnt;
Handle(Select3D_SensitiveEntity) aNewEntity;
return aNewEntity;
}
//=======================================================================
// function : BVH
// purpose : Builds BVH tree for a sensitive if needed
//=======================================================================
void Select3D_SensitiveEntity::BVH()
{
return;
}
//=======================================================================
// function : Clear
// purpose : Cleans up resources and memory
//=======================================================================
void Select3D_SensitiveEntity::Clear()
{
Set (NULL);
}

Some files were not shown because too many files have changed in this diff Show More