mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-09-13 14:27:08 +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:
@@ -18,261 +18,124 @@
|
||||
// pour teste si on est dedans ou dehors...
|
||||
//Modif on jul-21-97 : changement en harray1 pour eventuelles connexions ...
|
||||
|
||||
#include <Select3D_SensitiveFace.ixx>
|
||||
#include <Select3D_Projector.hxx>
|
||||
#include <SelectBasics_BasicTool.hxx>
|
||||
#include <gp_Pnt2d.hxx>
|
||||
#include <Select3D_SensitiveFace.hxx>
|
||||
#include <gp_Pnt.hxx>
|
||||
#include <Precision.hxx>
|
||||
#include <ElCLib.hxx>
|
||||
|
||||
#include <CSLib_Class2d.hxx>
|
||||
IMPLEMENT_STANDARD_HANDLE (Select3D_SensitiveFace, Select3D_SensitiveEntity)
|
||||
IMPLEMENT_STANDARD_RTTIEXT(Select3D_SensitiveFace, Select3D_SensitiveEntity)
|
||||
|
||||
//==================================================
|
||||
// Function: Hide this constructor to the next version...
|
||||
// Purpose : simply avoid interfering with the version update
|
||||
//==================================================
|
||||
|
||||
Select3D_SensitiveFace::
|
||||
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
|
||||
const TColgp_Array1OfPnt& ThePoints,
|
||||
const Select3D_TypeOfSensitivity aType):
|
||||
Select3D_SensitivePoly(OwnerId, ThePoints),
|
||||
mytype (aType)
|
||||
Select3D_SensitiveFace::Select3D_SensitiveFace (const Handle(SelectBasics_EntityOwner)& theOwnerId,
|
||||
const TColgp_Array1OfPnt& thePoints,
|
||||
const Select3D_TypeOfSensitivity theType)
|
||||
: Select3D_SensitiveEntity (theOwnerId),
|
||||
mySensType (theType)
|
||||
{
|
||||
if (mySensType == Select3D_TOS_INTERIOR)
|
||||
{
|
||||
myFacePoints = new Select3D_InteriorSensitivePointSet (theOwnerId, thePoints);
|
||||
}
|
||||
else
|
||||
{
|
||||
myFacePoints = new Select3D_BoundarySensitivePointSet (theOwnerId, thePoints);
|
||||
}
|
||||
}
|
||||
|
||||
//==================================================
|
||||
// Function: Creation
|
||||
// Purpose :
|
||||
//==================================================
|
||||
|
||||
Select3D_SensitiveFace::
|
||||
Select3D_SensitiveFace(const Handle(SelectBasics_EntityOwner)& OwnerId,
|
||||
const Handle(TColgp_HArray1OfPnt)& ThePoints,
|
||||
const Select3D_TypeOfSensitivity aType):
|
||||
Select3D_SensitivePoly(OwnerId, ThePoints),
|
||||
mytype (aType)
|
||||
Select3D_SensitiveFace::Select3D_SensitiveFace (const Handle(SelectBasics_EntityOwner)& theOwnerId,
|
||||
const Handle(TColgp_HArray1OfPnt)& thePoints,
|
||||
const Select3D_TypeOfSensitivity theType)
|
||||
: Select3D_SensitiveEntity (theOwnerId),
|
||||
mySensType (theType)
|
||||
{
|
||||
}
|
||||
|
||||
//==================================================
|
||||
// Function: Matches
|
||||
// Purpose :
|
||||
//==================================================
|
||||
|
||||
Standard_Boolean Select3D_SensitiveFace::Matches (const SelectBasics_PickArgs& thePickArgs,
|
||||
Standard_Real& theMatchDMin,
|
||||
Standard_Real& theMatchDepth)
|
||||
{
|
||||
Standard_Real DMin2 = 0.;
|
||||
Standard_Real Xmin = 0.,Ymin = 0.,Xmax = 0.,Ymax = 0.;
|
||||
if(!Bnd_Box2d(mybox2d).IsVoid())
|
||||
if (mySensType == Select3D_TOS_INTERIOR)
|
||||
{
|
||||
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
|
||||
DMin2 = gp_XY(Xmax-Xmin,Ymax-Ymin).SquareModulus();
|
||||
myFacePoints = new Select3D_InteriorSensitivePointSet (theOwnerId, thePoints);
|
||||
}
|
||||
// calculation of a criterion of minimum distance...
|
||||
// from start Dmin = size of the bounding box 2D,
|
||||
// then min. distance of the polyhedron or cdg...
|
||||
|
||||
Standard_Real aTol2 = thePickArgs.Tolerance() * thePickArgs.Tolerance();
|
||||
Standard_Integer aSize = mypolyg.Size(), anIndex;
|
||||
gp_XY CDG;
|
||||
for(anIndex=0;anIndex<aSize;++anIndex)
|
||||
else
|
||||
{
|
||||
CDG+=mypolyg.Pnt2d(anIndex);
|
||||
}
|
||||
|
||||
if(aSize>1)
|
||||
{
|
||||
CDG/=(aSize-1);
|
||||
}
|
||||
DMin2 = Min (DMin2, gp_XY (CDG.X() - thePickArgs.X(), CDG.Y() - thePickArgs.Y()).SquareModulus());
|
||||
theMatchDMin = Sqrt(DMin2);
|
||||
|
||||
Standard_Boolean isplane2d(Standard_True);
|
||||
|
||||
for(anIndex=1;anIndex<aSize;++anIndex)
|
||||
{
|
||||
gp_XY V1(mypolyg.Pnt2d(anIndex)),V(thePickArgs.X(), thePickArgs.Y());
|
||||
V1-=mypolyg.Pnt2d(anIndex-1);
|
||||
V-=mypolyg.Pnt2d(anIndex-1);
|
||||
Standard_Real Vector = V1^V;
|
||||
Standard_Real V1V1 = V1.SquareModulus();
|
||||
DMin2 =
|
||||
(V1V1 <=aTol2) ?
|
||||
Min(DMin2,V.SquareModulus()): // if the segment is too small...
|
||||
Min(DMin2,Vector*Vector/V1V1);
|
||||
//cdg ...
|
||||
gp_XY PlaneTest(CDG);
|
||||
PlaneTest-=mypolyg.Pnt2d(anIndex-1);
|
||||
Standard_Real valtst = PlaneTest^V1;
|
||||
if(isplane2d && Abs(valtst) > thePickArgs.Tolerance()) isplane2d=Standard_False;
|
||||
}
|
||||
if (isplane2d)
|
||||
{
|
||||
theMatchDepth = ComputeDepth (thePickArgs.PickLine(),
|
||||
thePickArgs.DepthMin(),
|
||||
thePickArgs.DepthMax());
|
||||
|
||||
return !thePickArgs.IsClipped (theMatchDepth);
|
||||
}
|
||||
|
||||
//otherwise it is checked if the point is in the face...
|
||||
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, aSize);
|
||||
Points2D(aArrayOf2dPnt);
|
||||
CSLib_Class2d TheInOutTool (aArrayOf2dPnt,
|
||||
thePickArgs.Tolerance(),
|
||||
thePickArgs.Tolerance(),
|
||||
Xmin, Ymin, Xmax, Ymax);
|
||||
Standard_Integer TheStat = TheInOutTool.SiDans (gp_Pnt2d (thePickArgs.X(), thePickArgs.Y()));
|
||||
|
||||
Standard_Boolean res(Standard_False);
|
||||
switch(TheStat)
|
||||
{
|
||||
case 0:
|
||||
res = Standard_True;
|
||||
case 1:
|
||||
{
|
||||
if(mytype!=Select3D_TOS_BOUNDARY)
|
||||
res = Standard_True;
|
||||
}
|
||||
}
|
||||
if (res)
|
||||
{
|
||||
theMatchDepth = ComputeDepth (thePickArgs.PickLine(),
|
||||
thePickArgs.DepthMin(),
|
||||
thePickArgs.DepthMax());
|
||||
|
||||
return !thePickArgs.IsClipped (theMatchDepth);
|
||||
}
|
||||
return Standard_False;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : Matches
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Standard_Boolean Select3D_SensitiveFace::
|
||||
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_SensitiveFace::
|
||||
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);
|
||||
|
||||
gp_Pnt2d aPnt2d;
|
||||
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 : Dump
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
|
||||
{
|
||||
S<<"\tSensitiveFace 3D :"<<endl;;
|
||||
if(HasLocation())
|
||||
S<<"\t\tExisting Location"<<endl;
|
||||
|
||||
if(mytype==Select3D_TOS_BOUNDARY)
|
||||
S<<"\t\tSelection Of Bounding Polyline Only"<<endl;
|
||||
|
||||
if(FullDump)
|
||||
{
|
||||
S<<"\t\tNumber Of Points :"<<mypolyg.Size()<<endl;
|
||||
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
|
||||
myFacePoints = new Select3D_BoundarySensitivePointSet (theOwnerId, thePoints);
|
||||
}
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ComputeDepth
|
||||
//purpose :
|
||||
// function : GetPoints
|
||||
// purpose : Initializes the given array theHArrayOfPnt by 3d
|
||||
// coordinates of vertices of the face
|
||||
//=======================================================================
|
||||
|
||||
Standard_Real Select3D_SensitiveFace::ComputeDepth (const gp_Lin& thePickLine,
|
||||
const Standard_Real theDepthMin,
|
||||
const Standard_Real theDepthMax) const
|
||||
void Select3D_SensitiveFace::GetPoints (Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt)
|
||||
{
|
||||
Standard_Real aDepth = Precision::Infinite();
|
||||
Standard_Real aPointDepth;
|
||||
|
||||
for (Standard_Integer anIndex = 0; anIndex < mypolyg.Size()-1; ++anIndex)
|
||||
{
|
||||
aPointDepth = ElCLib::Parameter (thePickLine, mypolyg.Pnt(anIndex));
|
||||
if (aPointDepth < aDepth && (aPointDepth > theDepthMin) && (aPointDepth < theDepthMax))
|
||||
{
|
||||
aDepth = aPointDepth;
|
||||
}
|
||||
}
|
||||
return aDepth;
|
||||
myFacePoints->GetPoints (theHArrayOfPnt);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : ComputeDepth
|
||||
//purpose :
|
||||
// function : BVH
|
||||
// purpose : Builds BVH tree for the face
|
||||
//=======================================================================
|
||||
|
||||
void Select3D_SensitiveFace::ComputeDepth(const gp_Lin& /*theEyeLine*/) const
|
||||
void Select3D_SensitiveFace::BVH()
|
||||
{
|
||||
// this method is obsolete.
|
||||
myFacePoints->BVH();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : Matches
|
||||
// purpose : Checks whether the face overlaps current selecting volume
|
||||
//=======================================================================
|
||||
Standard_Boolean Select3D_SensitiveFace::Matches (SelectBasics_SelectingVolumeManager& theMgr,
|
||||
SelectBasics_PickResult& thePickResult)
|
||||
{
|
||||
return myFacePoints->Matches (theMgr, thePickResult);
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
//function : GetConnected
|
||||
//purpose :
|
||||
//=======================================================================
|
||||
|
||||
Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected(const TopLoc_Location &theLocation)
|
||||
Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected()
|
||||
{
|
||||
// Create a copy of this
|
||||
Standard_Integer aSize = mypolyg.Size();
|
||||
TColgp_Array1OfPnt aPoints(1, aSize);
|
||||
for (Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
|
||||
{
|
||||
aPoints.SetValue(anIndex, mypolyg.Pnt(anIndex-1));
|
||||
}
|
||||
Handle(TColgp_HArray1OfPnt) aPoints;
|
||||
myFacePoints->GetPoints (aPoints);
|
||||
|
||||
Handle(Select3D_SensitiveEntity) aNewEntity =
|
||||
new Select3D_SensitiveFace(myOwnerId, aPoints, mytype);
|
||||
|
||||
if (HasLocation())
|
||||
aNewEntity->SetLocation(Location());
|
||||
|
||||
aNewEntity->UpdateLocation(theLocation);
|
||||
new Select3D_SensitiveFace (myOwnerId, aPoints, mySensType);
|
||||
|
||||
return aNewEntity;
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : BoundingBox
|
||||
// purpose : Returns bounding box of the face. If location transformation
|
||||
// is set, it will be applied
|
||||
//=======================================================================
|
||||
Select3D_BndBox3d Select3D_SensitiveFace::BoundingBox()
|
||||
{
|
||||
return myFacePoints->BoundingBox();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : CenterOfGeometry
|
||||
// purpose : Returns center of the face. If location transformation
|
||||
// is set, it will be applied
|
||||
//=======================================================================
|
||||
gp_Pnt Select3D_SensitiveFace::CenterOfGeometry() const
|
||||
{
|
||||
return myFacePoints->CenterOfGeometry();
|
||||
}
|
||||
|
||||
//=======================================================================
|
||||
// function : NbSubElements
|
||||
// purpose : Returns the amount of sub-entities (points or planar convex
|
||||
// polygons)
|
||||
//=======================================================================
|
||||
Standard_Integer Select3D_SensitiveFace::NbSubElements()
|
||||
{
|
||||
return myFacePoints->NbSubElements();
|
||||
}
|
||||
|
Reference in New Issue
Block a user