1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-05 18:16:23 +03:00

0022554: Application hangs on selection

This commit is contained in:
AAA 2012-02-22 13:01:33 +00:00 committed by bugmaster
parent 529afc1a20
commit ceae62f08e
15 changed files with 1293 additions and 756 deletions

View File

@ -1,4 +1,5 @@
Select3D_Pnt.hxx
Select3D_Pnt2d.hxx
Select3D_Box2d.hxx
Select3D_Macro.hxx
Select3D_Macro.hxx
Select3D_PointData.hxx

View File

@ -80,5 +80,6 @@ is
imported Pnt;
imported Pnt2d;
imported Box2d;
imported PointData;
end Select3D;

View File

@ -0,0 +1,105 @@
#ifndef _Select3D_PointData_HeaderFile
#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
class Select3D_PointData {
public:
// Constructs internal arrays of 2D and 3D points defined
// by number of points theNbPoints
Select3D_PointData (const Standard_Integer theNbPoints)
{
if (theNbPoints <= 0)
Standard_ConstructionError::Raise("Select3D_PointData");
mynbpoints = theNbPoints;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
}
// Destructor
~Select3D_PointData ()
{
delete [] mypolyg3d;
delete [] mypolyg2d;
}
// Sets Select3D_Pnt to internal array
// of 3D points if theIndex is valid
void SetPnt (const Standard_Integer theIndex,
const Select3D_Pnt& theValue)
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::SetPnt");
mypolyg3d[theIndex] = theValue;
}
// Sets gp_Pnt to internal array
// of 3D points if theIndex is valid
void SetPnt (const Standard_Integer theIndex,
const gp_Pnt& theValue)
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::SetPnt");
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
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::Pnt");
return mypolyg3d[theIndex];
}
// Returns 2D point from internal array
// if theIndex is valid
Select3D_Pnt2d Pnt2d (const Standard_Integer theIndex) const
{
if (theIndex < 0 || theIndex >= mynbpoints)
Standard_OutOfRange::Raise("Select3D_PointData::Pnt2d");
return mypolyg2d[theIndex];
}
// Returns size of internal arrays
const Standard_Integer Size () const
{
return mynbpoints;
}
private:
// Default constructor
Select3D_PointData () {};
Select3D_Pnt* mypolyg3d;
Select3D_Pnt2d* mypolyg2d;
Standard_Integer mynbpoints;
};
#endif

View File

@ -10,6 +10,8 @@ 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,
@ -29,6 +31,10 @@ uses
SensitiveEntity from Select3D,
Circle from Geom
raises
ConstructionError from Standard,
OutOfRange from Standard
is
Create (OwnerId : EntityOwner from SelectBasics;
TheCircle : Circle from Geom;
@ -114,7 +120,7 @@ is
Project(me: mutable;aProjector: Projector from Select3D) is redefined virtual;
ComputeCenter3D(me: mutable);
ComputeCenter3D(me: mutable) is private;
---Level: Internal
---Purpose: Computes myCenter3D as the barycenter of points from mypolyg3d

View File

@ -18,17 +18,29 @@
static Standard_Integer S3D_GetCircleNBPoints(const Handle(Geom_Circle)& C,
const Standard_Integer anInputNumber)
{
if(C->Radius()>Precision::Confusion())
{
// Check if number of points is invalid.
// In this case mypolyg raises Standard_ConstructionError
// exception (look constructor bellow).
if (anInputNumber <= 0)
return 0;
if (C->Radius()>Precision::Confusion())
return 2*anInputNumber+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)
{
if(C->Radius()>Precision::Confusion())
{
// 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;
// The radius is too small and circle degenerates into point
return 1;
}
@ -44,12 +56,12 @@ Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetCircleNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
myDetectedIndex(-1),
myCircle(TheCircle),
mystart(0),
myDetectedIndex(-1),
myCircle(TheCircle),
mystart(0),
myend(0)
{
if(mynbpoints!=1)
if (mypolyg.Size() != 1)
{
gp_Pnt p1,p2;
gp_Vec v1;
@ -58,30 +70,32 @@ myend(0)
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu =ustart;
for(Standard_Integer i=1;i<=NbPoints;i++)
for(Standard_Integer anIndex=1;anIndex<=NbPoints;anIndex++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
((Select3D_Pnt*)mypolyg3d)[rank-1] = p1;
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);
((Select3D_Pnt*)mypolyg3d)[rank-1] = p2;
mypolyg.SetPnt(rank-1, p2);
rank++;
curu+=du;
}
((Select3D_Pnt*)mypolyg3d)[NbPoints*2] = ((Select3D_Pnt*)mypolyg3d)[0];
// Get myCenter3D
// Copy the first point to the last point of mypolyg
mypolyg.SetPnt(NbPoints*2, mypolyg.Pnt(0));
// Get myCenter3D
myCenter3D = TheCircle->Location();
}
// Radius = 0.0
else
{
((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location();
mypolyg.SetPnt(0, TheCircle->Location());
// Get myCenter3D
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
myCenter3D = mypolyg.Pnt(0);
}
}
@ -99,50 +113,50 @@ Select3D_SensitiveCircle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer NbPoints):
Select3D_SensitivePoly(OwnerId, S3D_GetArcNBPoints(TheCircle,NbPoints)),
myFillStatus(FilledCircle),
myDetectedIndex(-1),
myCircle(TheCircle),
mystart(u1),
myDetectedIndex(-1),
myCircle(TheCircle),
mystart(u1),
myend(u2)
{
if(mynbpoints > 1)
if (mypolyg.Size() != 1)
{
gp_Pnt p1,p2;
gp_Vec v1;
if (u1 > u2)
if (u1 > u2)
{
mystart = u2;
mystart = u2;
myend = u1;
}
Standard_Real du = (myend-mystart)/(NbPoints-1);
Standard_Real R = TheCircle->Radius();
Standard_Integer rank = 1;
Standard_Real curu = mystart;
Standard_Real curu = mystart;
for(Standard_Integer i=1;i<=NbPoints-1;i++)
for(Standard_Integer anIndex=1;anIndex<=NbPoints-1;anIndex++)
{
TheCircle->D1(curu,p1,v1);
v1.Normalize();
((Select3D_Pnt*)mypolyg3d)[rank-1] = p1;
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);
((Select3D_Pnt*)mypolyg3d)[rank-1] = p2;
mypolyg.SetPnt(rank-1, p2);
rank++;
curu+=du;
}
TheCircle->D0(myend,p1);
((Select3D_Pnt*)mypolyg3d)[NbPoints*2-2] = p1;
mypolyg.SetPnt(NbPoints*2-2, p1);
// Get myCenter3D
myCenter3D = TheCircle->Location();
}
else
{
((Select3D_Pnt*)mypolyg3d)[0] = TheCircle->Location();
mypolyg.SetPnt(0, TheCircle->Location());
// Get myCenter3D
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
myCenter3D = mypolyg.Pnt(0);
}
}
@ -156,14 +170,14 @@ Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_Ent
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
myDetectedIndex(-1),
mystart(0),
myDetectedIndex(-1),
mystart(0),
myend(0)
{
if (mynbpoints > 1)
if (mypolyg.Size() != 1)
ComputeCenter3D();
else
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
else
myCenter3D = mypolyg.Pnt(0);
}
//=======================================================================
@ -176,14 +190,14 @@ Select3D_SensitiveCircle::Select3D_SensitiveCircle(const Handle(SelectBasics_Ent
const Standard_Boolean FilledCircle):
Select3D_SensitivePoly(OwnerId, Thepolyg3d),
myFillStatus(FilledCircle),
myDetectedIndex(-1),
mystart(0),
myDetectedIndex(-1),
mystart(0),
myend(0)
{
if (mynbpoints > 1)
{
if (mypolyg.Size() != 1)
ComputeCenter3D();
else
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
else
myCenter3D = mypolyg.Pnt(0);
}
//=======================================================================
@ -192,41 +206,42 @@ myend(0)
//=======================================================================
Standard_Boolean Select3D_SensitiveCircle::
Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Matches(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin)
{
if(mynbpoints>1)
Standard_Integer aSize = mypolyg.Size();
if (aSize != 1)
{
Standard_Boolean Found = Standard_False;
Standard_Integer i = 0;
Standard_Integer anIndex = 0;
if(!myFillStatus)
{
while(i < mynbpoints-2 && !Found)
{
Standard_Integer TheStat =
Select3D_SensitiveTriangle::Status(((Select3D_Pnt2d*)mypolyg2d)[i],
((Select3D_Pnt2d*)mypolyg2d)[i+1],
((Select3D_Pnt2d*)mypolyg2d)[i+2],
gp_XY(X,Y),aTol,DMin);
Found = (TheStat != 2);
if(Found) myDetectedIndex = i;
i += 2;
while(anIndex < aSize-2 && !Found)
{
Standard_Integer TheStat =
Select3D_SensitiveTriangle::Status(mypolyg.Pnt2d(anIndex),
mypolyg.Pnt2d(anIndex+1),
mypolyg.Pnt2d(anIndex+2),
gp_XY(X,Y),aTol,DMin);
Found = (TheStat != 2);
if(Found) myDetectedIndex = anIndex;
anIndex += 2;
}
}
else
else
{
myDetectedIndex =-1;
Standard_Real Xmin,Ymin,Xmax,Ymax;
// Get coordinates of the bounding box
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
TColgp_Array1OfPnt2d anArrayOf2dPnt(1, mynbpoints);
Bnd_Box2d(mybox2d).Get(Xmin,Ymin,Xmax,Ymax);
TColgp_Array1OfPnt2d anArrayOf2dPnt(1, aSize);
// Fill anArrayOf2dPnt with points from mypolig2d
Points2D(anArrayOf2dPnt);
Points2D(anArrayOf2dPnt);
CSLib_Class2d anInOutTool(anArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax);
@ -235,23 +250,27 @@ Matches(const Standard_Real X,
// 0 - the point is on the circle
// -1 - the point is outside the circle
Standard_Integer aStat = anInOutTool.SiDans(gp_Pnt2d(X,Y));
if(aStat != -1)
if(aStat != -1)
{
// Compute DMin (a distance between the center and the point)
DMin = gp_XY(myCenter2D.x - X, myCenter2D.y - Y).Modulus();
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_True;
}
return Standard_False;
return Standard_False;
}
if(!Found)
if(!Found)
myDetectedIndex=-1;
else
Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Found;
}
return Standard_True;
// Circle degenerates into point
DMin = gp_Pnt2d(X, Y).Distance(mypolyg.Pnt2d(0));
if (DMin <= aTol*SensitivityFactor())
return Select3D_SensitiveEntity::Matches(X,Y,aTol,DMin);
return Standard_False;
}
//=======================================================================
@ -270,9 +289,12 @@ Matches(const Standard_Real XMin,
Bnd_Box2d abox;
abox.Update(Min(XMin,XMax),Min(YMin,YMax),Max(XMin,XMax),Max(YMin,YMax));
abox.Enlarge(aTol);
for(Standard_Integer i=0;i<mynbpoints;i++)
if(abox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i])) return Standard_False;
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();anIndex++)
{
if(abox.IsOut(mypolyg.Pnt2d(anIndex)))
return Standard_False;
}
return Standard_True;
}
@ -285,18 +307,20 @@ Standard_Boolean Select3D_SensitiveCircle::
Matches (const TColgp_Array1OfPnt2d& aPoly,
const Bnd_Box2d& aBox,
const Standard_Real aTol)
{
{
myDetectedIndex = -1;
Standard_Real Umin,Vmin,Umax,Vmax;
aBox.Get(Umin,Vmin,Umax,Vmax);
Standard_Real Tolu,Tolv;
Tolu = 1e-7;
Tolv = 1e-7;
Tolu = Precision::Confusion();
Tolv = Precision::Confusion();
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=mynbpoints;j++)
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
if(RES!=1) return Standard_False;
Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
if(RES!=1)
return Standard_False;
}
return Standard_True;
}
@ -310,8 +334,8 @@ void Select3D_SensitiveCircle::
ArrayBounds(Standard_Integer & Low,
Standard_Integer & Up) const
{
Low = 0;
Up = mynbpoints-1;
Low = 0;
Up = mypolyg.Size()-1;
}
//=======================================================================
@ -322,9 +346,9 @@ ArrayBounds(Standard_Integer & Low,
gp_Pnt Select3D_SensitiveCircle::
GetPoint3d(const Standard_Integer Rank) const
{
if(Rank>=0&& Rank<mynbpoints)
return ((Select3D_Pnt*)mypolyg3d)[Rank];
return ((Select3D_Pnt*)mypolyg3d)[0];
if(Rank>=0 && Rank<mypolyg.Size())
return mypolyg.Pnt(Rank);
return gp_Pnt();
}
@ -335,12 +359,11 @@ GetPoint3d(const Standard_Integer Rank) const
void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
// Standard_Integer rank(1);
gp_XYZ CDG(0.,0.,0.);
Standard_Integer aSize = mypolyg.Size();
S<<"\tSensitiveCircle 3D :";
Standard_Boolean isclosed = 1== mynbpoints;
Standard_Boolean isclosed = 1== aSize;
if(isclosed)
S<<"(Closed Circle)"<<endl;
else
@ -352,20 +375,11 @@ void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean F
if(FullDump)
{
Standard_Integer EndIndex = isclosed? mynbpoints-2 : mynbpoints-1, nbpt(0);
for(Standard_Integer i=0;i<EndIndex;i+=2)
{
CDG +=((Select3D_Pnt*)mypolyg3d)[i];
nbpt++;
}
CDG/=nbpt;
Standard_Real R = (CDG-((Select3D_Pnt*)mypolyg3d)[0]).Modulus();
S<<"\t\t Center : ("<<CDG.X()<<" , "<<CDG.Y()<<" , "<<CDG.Z()<<" )"<<endl;
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;
}
}
@ -376,34 +390,25 @@ void Select3D_SensitiveCircle::Dump(Standard_OStream& S,const Standard_Boolean F
Standard_Real Select3D_SensitiveCircle::ComputeDepth(const gp_Lin& EyeLine) const
{
gp_Pnt CDG;
gp_XYZ aCDG;
if(myDetectedIndex==-1)
{
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[0]);
Standard_Boolean isclosed = 1==mynbpoints;
Standard_Integer EndIndex = isclosed ? mynbpoints-2 : mynbpoints-1, nbpt(0);
for(Standard_Integer i=1;i<EndIndex;i+=2)
{
CurCoord +=((Select3D_Pnt*)mypolyg3d)[i];
nbpt++;
}
CDG.SetXYZ(CurCoord);
aCDG = myCenter3D;
}
else
{
gp_XYZ CurCoord(((Select3D_Pnt*)mypolyg3d)[myDetectedIndex]);
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+1];
CurCoord+=((Select3D_Pnt*)mypolyg3d)[myDetectedIndex+2];
CDG.SetXYZ(CurCoord);
aCDG += mypolyg.Pnt(myDetectedIndex);
aCDG += mypolyg.Pnt(myDetectedIndex+1);
aCDG += mypolyg.Pnt(myDetectedIndex+2);
aCDG /= 3.;
}
return ElCLib::Parameter(EyeLine,CDG);
return ElCLib::Parameter(EyeLine,gp_Pnt(aCDG));
}
//=======================================================================
//function : GetConnected
//purpose :
//=======================================================================
//=======================================================================
Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected(const TopLoc_Location& theLocation)
{
@ -426,10 +431,11 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected(const To
// this was constructed using TColgp_Array1OfPnt
else
{
TColgp_Array1OfPnt aPolyg(1, mynbpoints);
for(Standard_Integer i = 1; i <= mynbpoints; ++i)
Standard_Integer aSize = mypolyg.Size();
TColgp_Array1OfPnt aPolyg(1, aSize);
for(Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
{
aPolyg.SetValue(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
aPolyg.SetValue(anIndex, mypolyg.Pnt(anIndex-1));
}
aNewEntity = new Select3D_SensitiveCircle(myOwnerId, aPolyg, myFillStatus);
}
@ -447,10 +453,9 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveCircle::GetConnected(const To
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProjector)
void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProjector)
{
Select3D_SensitivePoly::Project(aProjector);
// Project the center of the circle
gp_Pnt2d aCenter;
aProjector->Project(myCenter3D, aCenter);
myCenter2D = aCenter;
@ -461,30 +466,23 @@ void Select3D_SensitiveCircle::Project(const Handle_Select3D_Projector &aProject
//purpose :
//=======================================================================
void Select3D_SensitiveCircle::ComputeCenter3D()
void Select3D_SensitiveCircle::ComputeCenter3D()
{
gp_XYZ aCenter(0., 0., 0.);
if(mynbpoints > 1)
gp_XYZ aCenter;
Standard_Integer nbpoints = mypolyg.Size();
if (nbpoints != 1)
{
// The mass of points system
Standard_Integer aMass = mynbpoints - 1;
Standard_Integer aMass = nbpoints - 1;
// Find the circle barycenter
for(Standard_Integer i = 0; i < mynbpoints-1; ++i)
for (Standard_Integer anIndex = 0; anIndex < nbpoints-1; ++anIndex)
{
aCenter += ((Select3D_Pnt*)mypolyg3d)[i];
aCenter += mypolyg.Pnt(anIndex);
}
myCenter3D = aCenter / aMass;
}
else if (mynbpoints == 1)
{
myCenter3D = ((Select3D_Pnt*)mypolyg3d)[0];
}
// bad case! there are no points in mypolyg3d
// It can lead to incorrect computation of
// parameter DMin in method Matches.
// In spite of this myCenter3D isn't left uninitialized
else
{
myCenter3D = aCenter;
myCenter3D = mypolyg.Pnt(0);
}
}

View File

@ -11,6 +11,8 @@ 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,
@ -26,6 +28,10 @@ uses
Box2d from Bnd,
Location from TopLoc,
SensitiveEntity from Select3D
raises
ConstructionError from Standard,
OutOfRange from Standard
is

View File

@ -68,7 +68,7 @@ Standard_Boolean Select3D_SensitiveCurve
Standard_Real& DMin)
{
Standard_Integer Rank;
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mypolyg.Size());
Points2D(aArrayOf2dPnt);
if (SelectBasics_BasicTool::MatchPolyg2d (aArrayOf2dPnt,
X, Y,
@ -99,9 +99,10 @@ Matches (const Standard_Real XMin,
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=0; j<mynbpoints; j++)
for(Standard_Integer anIndex=0; anIndex<mypolyg.Size(); ++anIndex)
{
if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j])) return Standard_False;
if(BoundBox.IsOut(mypolyg.Pnt2d(anIndex)))
return Standard_False;
}
return Standard_True;
}
@ -123,10 +124,11 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=0;j<mynbpoints;j++)
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j]);
if(RES!=1) return Standard_False;
Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
if(RES!=1)
return Standard_False;
}
return Standard_True;
}
@ -144,11 +146,11 @@ void Select3D_SensitiveCurve
Standard_Real Step = (aCurve->LastParameter()- aCurve->FirstParameter())/(NbP-1);
Standard_Real Curparam = aCurve->FirstParameter();
for(Standard_Integer i=0;i<mynbpoints;i++)
{
((Select3D_Pnt*)mypolyg3d)[i] = aCurve->Value(Curparam);
Curparam+=Step;
}
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
mypolyg.SetPnt(anIndex, aCurve->Value(Curparam));
Curparam+=Step;
}
}
//=======================================================================
@ -159,14 +161,13 @@ void Select3D_SensitiveCurve
void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
S<<"\tSensitiveCurve 3D :"<<endl;
if(HasLocation())
if (HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
S<<"\t\tNumber Of Points :"<<mypolyg.Size()<<endl;
if(FullDump)
{
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
@ -178,11 +179,27 @@ void Select3D_SensitiveCurve::Dump(Standard_OStream& S,const Standard_Boolean Fu
Standard_Real Select3D_SensitiveCurve::ComputeDepth(const gp_Lin& EyeLine) const
{
if(mylastseg==0) return Precision::Infinite(); // non implemente actuellement...
gp_XYZ TheCDG(((Select3D_Pnt*)mypolyg3d)[mylastseg]);
TheCDG+=((Select3D_Pnt*)mypolyg3d)[mylastseg+1];
TheCDG/=2.;
return ElCLib::Parameter(EyeLine,gp_Pnt(TheCDG));
Standard_Real aDepth = Precision::Infinite();
// Not implemented
if(mylastseg==0)
return aDepth;
gp_XYZ aCDG;
// In case if mylastseg and mylastseg+1 are not valid
// the depth will be infinite
if (mylastseg < mypolyg.Size())
{
aCDG = mypolyg.Pnt(mylastseg);
if (mylastseg+1 < mypolyg.Size())
{
aCDG += mypolyg.Pnt(mylastseg+1);
aCDG /= 2.;
}
aDepth = ElCLib::Parameter(EyeLine,gp_Pnt(aCDG));
}
return aDepth;
}
//=======================================================================
@ -202,13 +219,14 @@ Handle(Select3D_SensitiveEntity) Select3D_SensitiveCurve::GetConnected(const Top
// this was constructed using TColgp_HArray1OfPnt
else
{
Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, mynbpoints);
Standard_Integer aSize = mypolyg.Size();
Handle(TColgp_HArray1OfPnt) aPoints = new TColgp_HArray1OfPnt(1, aSize);
// Fill the array with points from mypolyg3d
for (Standard_Integer i = 1; i <= mynbpoints; ++i)
for (Standard_Integer anIndex = 1; anIndex <= aSize; ++anIndex)
{
aPoints->SetValue(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
aPoints->SetValue(anIndex, mypolyg.Pnt(anIndex-1));
}
aNewEntity = new Select3D_SensitiveCurve(myOwnerId, aPoints);
aNewEntity = new Select3D_SensitiveCurve(myOwnerId, aPoints);
}
if (HasLocation())

View File

@ -9,6 +9,8 @@ class SensitiveFace from Select3D
inherits SensitivePoly from Select3D
---Purpose: Sensitive Entity to make a face selectable.
-- In some cases this class can raise Standard_ConstructionError and
-- Standard_OutOfRange exceptions. For more details see Select3D_SensitivePoly.
uses
EntityOwner from SelectBasics,
@ -23,6 +25,10 @@ uses
Location from TopLoc,
SensitiveEntity from Select3D
raises
ConstructionError from Standard,
OutOfRange from Standard
is
Create (OwnerId : EntityOwner from SelectBasics;

View File

@ -88,28 +88,27 @@ Matches(const Standard_Real X,
// then min. distance of the polyhedron or cdg...
Standard_Real aTol2 = aTol*aTol;
gp_XY CDG(0.,0.);
// for(Standard_Integer I=1;I<=Nbp-1;I++){
Standard_Integer I;
for(I=1;I<mynbpoints-1;I++)
Standard_Integer aSize = mypolyg.Size(), anIndex;
gp_XY CDG;
for(anIndex=0;anIndex<aSize;++anIndex)
{
CDG+=((Select3D_Pnt2d*)mypolyg2d)[I-1];
CDG+=mypolyg.Pnt2d(anIndex);
}
if(mynbpoints>1)
if(aSize>1)
{
CDG/= (mynbpoints-1);
CDG/=(aSize-1);
}
DMin2=Min(DMin2,gp_XY(CDG.X()-X,CDG.Y()-Y).SquareModulus());
DMin = Sqrt(DMin2);
Standard_Boolean isplane2d(Standard_True);
for( I=1;I<mynbpoints-1;I++)
for(anIndex=1;anIndex<aSize;++anIndex)
{
gp_XY V1(((Select3D_Pnt2d*)mypolyg2d)[I]),V(X,Y);
V1-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
V-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
gp_XY V1(mypolyg.Pnt2d(anIndex)),V(X,Y);
V1-=mypolyg.Pnt2d(anIndex-1);
V-=mypolyg.Pnt2d(anIndex-1);
Standard_Real Vector = V1^V;
Standard_Real V1V1 = V1.SquareModulus();
DMin2 =
@ -117,7 +116,8 @@ Matches(const Standard_Real X,
Min(DMin2,V.SquareModulus()): // if the segment is too small...
Min(DMin2,Vector*Vector/V1V1);
//cdg ...
gp_XY PlaneTest(CDG);PlaneTest-=((Select3D_Pnt2d*)mypolyg2d)[I-1];
gp_XY PlaneTest(CDG);
PlaneTest-=mypolyg.Pnt2d(anIndex-1);
Standard_Real valtst = PlaneTest^V1;
if(isplane2d && Abs(valtst)>aTol) isplane2d=Standard_False;
}
@ -127,11 +127,11 @@ Matches(const Standard_Real X,
}
//otherwise it is checked if the point is in the face...
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, mynbpoints);
TColgp_Array1OfPnt2d aArrayOf2dPnt(1, aSize);
Points2D(aArrayOf2dPnt);
CSLib_Class2d TheInOutTool(aArrayOf2dPnt,aTol,aTol,Xmin,Ymin,Xmax,Ymax);
Standard_Integer TheStat = TheInOutTool.SiDans(gp_Pnt2d(X,Y));
Standard_Boolean res(Standard_False);
switch(TheStat)
{
@ -139,7 +139,7 @@ Matches(const Standard_Real X,
res = Standard_True;
case 1:
{
if(mytype!=Select3D_TOS_BOUNDARY)
if(mytype!=Select3D_TOS_BOUNDARY)
res = Standard_True;
}
}
@ -164,10 +164,11 @@ Matches (const Standard_Real XMin,
{
Bnd_Box2d BoundBox;
BoundBox.Update(XMin-aTol,YMin-aTol,XMax+aTol,YMax+aTol);
for(Standard_Integer j=1;j<=mynbpoints-1;j++)
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
if(BoundBox.IsOut(((Select3D_Pnt2d*)mypolyg2d)[j-1])) return Standard_False;
if(BoundBox.IsOut(mypolyg.Pnt2d(anIndex)))
return Standard_False;
}
return Standard_True;
}
@ -189,10 +190,12 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer j=1;j<=mynbpoints;j++)
gp_Pnt2d aPnt2d;
for(Standard_Integer anIndex=0;anIndex<mypolyg.Size();++anIndex)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[j-1]);
if(RES!=1) return Standard_False;
Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
if(RES!=1)
return Standard_False;
}
return Standard_True;
}
@ -213,9 +216,7 @@ void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean Ful
if(FullDump)
{
S<<"\t\tNumber Of Points :"<<mynbpoints<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
S<<"\t\tNumber Of Points :"<<mypolyg.Size()<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
@ -228,12 +229,14 @@ void Select3D_SensitiveFace::Dump(Standard_OStream& S,const Standard_Boolean Ful
Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
{
Standard_Real aDepth = Precision::Infinite();
Standard_Real aDepthMin = !mylastprj.IsNull() ? mylastprj->DepthMin() : -Precision::Infinite();
Standard_Real aDepthMax = !mylastprj.IsNull() ? mylastprj->DepthMax() : Precision::Infinite();
Standard_Real aDepthTest;
for (Standard_Integer i = 0; i < mynbpoints - 1; i++)
for (Standard_Integer anIndex = 0; anIndex < mypolyg.Size()-1; ++anIndex)
{
aDepthTest = ElCLib::Parameter (EyeLine, ((Select3D_Pnt* )mypolyg3d)[i]);
aDepthTest = ElCLib::Parameter (EyeLine, mypolyg.Pnt(anIndex));
if (aDepthTest < aDepth && (aDepthTest > aDepthMin) && (aDepthTest < aDepthMax))
{
aDepth = aDepthTest;
@ -249,18 +252,19 @@ Standard_Real Select3D_SensitiveFace::ComputeDepth(const gp_Lin& EyeLine) const
Handle(Select3D_SensitiveEntity) Select3D_SensitiveFace::GetConnected(const TopLoc_Location &theLocation)
{
// Create a copy of this
TColgp_Array1OfPnt aPoints(1, mynbpoints);
for (Standard_Integer i = 1; i <= mynbpoints; ++i)
// 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(i, ((Select3D_Pnt*)mypolyg3d)[i-1]);
aPoints.SetValue(anIndex, mypolyg.Pnt(anIndex-1));
}
Handle(Select3D_SensitiveEntity) aNewEntity =
new Select3D_SensitiveFace(myOwnerId, aPoints, mytype);
Handle(Select3D_SensitiveEntity) aNewEntity =
new Select3D_SensitiveFace(myOwnerId, aPoints, mytype);
if (HasLocation())
aNewEntity->SetLocation(Location());
if (HasLocation())
aNewEntity->SetLocation(Location());
aNewEntity->UpdateLocation(theLocation);

View File

@ -2,6 +2,9 @@ deferred class SensitivePoly from Select3D
inherits SensitiveEntity from Select3D
---Purpose: Sensitive Entity to make a face selectable.
-- In some cases this class can raise Standard_ConstructionError and
-- Standard_OutOfRange exceptions from its member Select3D_PointData
-- mypolyg.
uses
EntityOwner from SelectBasics,
@ -9,8 +12,13 @@ uses
ListOfBox2d from SelectBasics,
Array1OfPnt from TColgp,
HArray1OfPnt from TColgp,
Array1OfPnt2d from TColgp,
Box2d from Select3D
Array1OfPnt2d from TColgp,
Box2d from Select3D,
PointData from Select3D
raises
ConstructionError from Standard,
OutOfRange from Standard
is
@ -58,15 +66,8 @@ is
---Purpose: Returns the 2D points of the array used at construction time.
---C++: inline
Destroy(me: mutable);
---C++: alias ~
fields
mypolyg3d : Address from Standard is protected;
mypolyg2d : Address from Standard is protected;
mybox2d : Box2d from Select3D is protected;
mynbpoints : Integer from Standard is protected;
mypolyg : PointData from Select3D is protected;
end SensitivePoly;

View File

@ -15,13 +15,11 @@
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const TColgp_Array1OfPnt& ThePoints):
Select3D_SensitiveEntity(OwnerId)
Select3D_SensitiveEntity(OwnerId),
mypolyg(ThePoints.Upper()-ThePoints.Lower()+1)
{
mynbpoints = ThePoints.Upper()-ThePoints.Lower()+1;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
for(Standard_Integer i=0;i<mynbpoints;i++)
((Select3D_Pnt*)mypolyg3d)[i] = ThePoints.Value(ThePoints.Lower()+i);
for (Standard_Integer theIndex = 0 ; theIndex < mypolyg.Size(); ++theIndex)
mypolyg.SetPnt(theIndex, ThePoints.Value(ThePoints.Lower()+theIndex));
}
//==================================================
@ -32,13 +30,11 @@ Select3D_SensitiveEntity(OwnerId)
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Handle(TColgp_HArray1OfPnt)& ThePoints):
Select3D_SensitiveEntity(OwnerId)
Select3D_SensitiveEntity(OwnerId),
mypolyg(ThePoints->Upper()-ThePoints->Lower()+1)
{
mynbpoints = ThePoints->Upper()-ThePoints->Lower()+1;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
for(Standard_Integer i=0;i<mynbpoints;i++)
((Select3D_Pnt*)mypolyg3d)[i] = ThePoints->Value(ThePoints->Lower()+i);
for (Standard_Integer theIndex = 0; theIndex < mypolyg.Size(); theIndex++)
mypolyg.SetPnt(theIndex, ThePoints->Value(ThePoints->Lower()+theIndex));
}
//==================================================
@ -49,11 +45,9 @@ Select3D_SensitiveEntity(OwnerId)
Select3D_SensitivePoly::
Select3D_SensitivePoly(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Standard_Integer NbPoints):
Select3D_SensitiveEntity(OwnerId)
Select3D_SensitiveEntity(OwnerId),
mypolyg(NbPoints)
{
mynbpoints = NbPoints;
mypolyg3d = new Select3D_Pnt[mynbpoints];
mypolyg2d = new Select3D_Pnt2d[mynbpoints];
}
//==================================================
@ -63,25 +57,26 @@ Select3D_SensitiveEntity(OwnerId)
void Select3D_SensitivePoly::Project(const Handle(Select3D_Projector)& aProj)
{
Select3D_SensitiveEntity::Project(aProj); // to set the field last proj...
Select3D_SensitiveEntity:: Project (aProj); // to set the field last proj...
mybox2d.SetVoid();
Standard_Boolean hasloc = HasLocation();
gp_Pnt2d aPnt2d;
for(Standard_Integer i=0;i<mynbpoints;i++)
gp_Pnt aPnt;
for (Standard_Integer theIndex = 0; theIndex < mypolyg.Size(); ++theIndex)
{
aPnt = mypolyg.Pnt(theIndex);
if (hasloc)
{
gp_Pnt aPnt(((Select3D_Pnt*)mypolyg3d)[i].x, ((Select3D_Pnt*)mypolyg3d)[i].y, ((Select3D_Pnt*)mypolyg3d)[i].z);
if (hasloc)
{
aProj->Project(aPnt.Transformed(Location().Transformation()),aPnt2d);
}
else
{
aProj->Project(aPnt,aPnt2d);
}
mybox2d.Update(aPnt2d);
((Select3D_Pnt2d*)mypolyg2d)[i] = aPnt2d;
aProj->Project(aPnt.Transformed(Location().Transformation()), aPnt2d);
}
else
{
aProj->Project(aPnt, aPnt2d);
}
mybox2d.Update(aPnt2d);
mypolyg.SetPnt2d(theIndex, aPnt2d);
}
}
//==================================================
@ -94,13 +89,3 @@ void Select3D_SensitivePoly
aSeq.Append(mybox2d);
}
//==================================================
// Function: Destroy
// Purpose :
//==================================================
void Select3D_SensitivePoly::Destroy()
{
delete[] (Select3D_Pnt*)mypolyg3d;
delete[] (Select3D_Pnt2d*)mypolyg2d;
}

View File

@ -6,21 +6,20 @@
inline void Select3D_SensitivePoly
::Points3D( Handle(TColgp_HArray1OfPnt)& theHArrayOfPnt )
{
theHArrayOfPnt = new TColgp_HArray1OfPnt(1,mynbpoints);
for(Standard_Integer i = 1; i <= mynbpoints; i++)
Standard_Integer aSize = mypolyg.Size();
theHArrayOfPnt = new TColgp_HArray1OfPnt(1,aSize);
for(Standard_Integer anIndex = 1; anIndex <= aSize; anIndex++)
{
gp_Pnt aPnt(((Select3D_Pnt*)mypolyg3d)[i-1].x, ((Select3D_Pnt*)mypolyg3d)[i-1].y, ((Select3D_Pnt*)mypolyg3d)[i-1].z);
theHArrayOfPnt->SetValue(i, aPnt);
theHArrayOfPnt->SetValue(anIndex, mypolyg.Pnt(anIndex-1));
}
}
inline void Select3D_SensitivePoly
::Points2D( TColgp_Array1OfPnt2d& aArrayOf2dPnt)
{
for(Standard_Integer i = 1; i <= mynbpoints; i++)
for(Standard_Integer anIndex = 1; anIndex <= mypolyg.Size(); anIndex++)
{
gp_Pnt2d aPnt2d(((Select3D_Pnt2d*)mypolyg2d)[i-1].x, ((Select3D_Pnt2d*)mypolyg2d)[i-1].y);
aArrayOf2dPnt.SetValue(i,aPnt2d);
aArrayOf2dPnt.SetValue(anIndex, mypolyg.Pnt2d(anIndex-1));
}
}

View File

@ -9,7 +9,9 @@ class SensitiveTriangle from Select3D
inherits SensitivePoly from Select3D
---Purpose: A framework to define selection of triangles in a view.
-- This comes into play in the detection of meshing and triangulation in surfaces.
-- This comes into play in the detection of meshing and triangulation in surfaces.
-- In some cases this class can raise Standard_ConstructionError and
-- Standard_OutOfRange exceptions. For more details see Select3D_SensitivePoly.
uses
EntityOwner from SelectBasics,
@ -24,6 +26,10 @@ uses
Location from TopLoc,
SensitiveEntity from Select3D
raises
ConstructionError from Standard,
OutOfRange from Standard
is
Create (OwnerId : EntityOwner from SelectBasics;
P1,P2,P3 : Pnt from gp;

View File

@ -18,9 +18,6 @@
#include <CSLib_Class2d.hxx>
#define COORD(a,b) ((Select3D_Pnt*)mypolyg3d)[(a)].b
#define COORD2d(a,b) ((Select3D_Pnt2d*)mypolyg2d)[(a)].b
static Standard_Boolean S3D_Str_NearSegment (const gp_XY& p0, const gp_XY& p1, const gp_XY& TheP,
const Standard_Real aTol, Standard_Real& aDMin)
{
@ -55,10 +52,10 @@ Select3D_SensitiveTriangle(const Handle(SelectBasics_EntityOwner)& OwnerId,
const Select3D_TypeOfSensitivity aType):
Select3D_SensitivePoly(OwnerId,3),
mytype (aType)
{
((Select3D_Pnt*)mypolyg3d)[0] = P0;
((Select3D_Pnt*)mypolyg3d)[1] = P1;
((Select3D_Pnt*)mypolyg3d)[2] = P2;
{
mypolyg.SetPnt(0, P0);
mypolyg.SetPnt(1, P1);
mypolyg.SetPnt(2, P2);
}
//==================================================
@ -76,7 +73,7 @@ Matches(const Standard_Real X,
if(Bnd_Box2d(mybox2d).IsOut(gp_Pnt2d(X,Y))) return Standard_False;
Standard_Integer Res;
switch (mytype)
switch (mytype)
{
case Select3D_TOS_BOUNDARY:
Res = Status(X,Y,aTol,DMin);
@ -88,7 +85,7 @@ Matches(const Standard_Real X,
#ifndef DEB
default:
break;
#endif
#endif
}
return Standard_True;
}
@ -110,9 +107,9 @@ Matches (const Standard_Real XMin,
Min(YMin,YMax)-aTol,
Max(XMin,XMax)+aTol,
Max(YMin,YMax)+aTol);
for(Standard_Integer i=0;i<=2;i++)
for(Standard_Integer anIndex=0;anIndex<=2;++anIndex)
{
if(B.IsOut(((Select3D_Pnt2d*)mypolyg2d)[i]))
if(B.IsOut(mypolyg.Pnt2d(anIndex)))
return Standard_False;
}
return Standard_True;
@ -127,7 +124,7 @@ Standard_Boolean Select3D_SensitiveTriangle::
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);
Standard_Real Tolu,Tolv;
@ -135,10 +132,11 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
Tolv = 1e-7;
CSLib_Class2d aClassifier2d(aPoly,aTol,aTol,Umin,Vmin,Umax,Vmax);
for(Standard_Integer i=0;i<=2;i++)
for(Standard_Integer anIndex=0;anIndex<=2;++anIndex)
{
Standard_Integer RES = aClassifier2d.SiDans(((Select3D_Pnt2d*)mypolyg2d)[i]);
if(RES!=1) return Standard_False;
Standard_Integer RES = aClassifier2d.SiDans(mypolyg.Pnt2d(anIndex));
if(RES!=1)
return Standard_False;
}
return Standard_True;
}
@ -148,11 +146,11 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
// Purpose :
//==================================================
void Select3D_SensitiveTriangle::Points3D(gp_Pnt& P0,gp_Pnt& P1,gp_Pnt& P2) const
void Select3D_SensitiveTriangle::Points3D(gp_Pnt& P0,gp_Pnt& P1,gp_Pnt& P2) const
{
P0 = ((Select3D_Pnt*)mypolyg3d)[0];
P1 = ((Select3D_Pnt*)mypolyg3d)[1];
P2 = ((Select3D_Pnt*)mypolyg3d)[2];
P0 = mypolyg.Pnt(0);
P1 = mypolyg.Pnt(1);
P2 = mypolyg.Pnt(2);
}
//==================================================
@ -162,11 +160,11 @@ Matches (const TColgp_Array1OfPnt2d& aPoly,
gp_Pnt Select3D_SensitiveTriangle::Center3D() const
{
gp_XYZ CDG(((Select3D_Pnt*)mypolyg3d)[0]);
CDG += ((Select3D_Pnt*)mypolyg3d)[1];
CDG += ((Select3D_Pnt*)mypolyg3d)[2];
CDG /=3.;
return gp_Pnt(CDG);;
gp_XYZ aPnt1, aPnt2, aPnt3;
aPnt1 = mypolyg.Pnt(0);
aPnt2 = mypolyg.Pnt(1);
aPnt3 = mypolyg.Pnt(2);
return gp_Pnt((aPnt1+aPnt2+aPnt3)/3.);
}
//==================================================
@ -176,8 +174,11 @@ gp_Pnt Select3D_SensitiveTriangle::Center3D() const
gp_XY Select3D_SensitiveTriangle::Center2D() const
{
return (gp_XY(((Select3D_Pnt2d*)mypolyg2d)[0])+gp_XY(((Select3D_Pnt2d*)mypolyg2d)[1])
+gp_XY(((Select3D_Pnt2d*)mypolyg2d)[2]))/3.;
gp_XY aPnt1, aPnt2, aPnt3;
aPnt1 = mypolyg.Pnt2d(0);
aPnt2 = mypolyg.Pnt2d(1);
aPnt3 = mypolyg.Pnt2d(2);
return (aPnt1+aPnt2+aPnt3)/3.;
}
//=======================================================================
@ -188,10 +189,10 @@ gp_XY Select3D_SensitiveTriangle::Center2D() const
Standard_Integer Select3D_SensitiveTriangle::Status(const Standard_Real X,
const Standard_Real Y,
const Standard_Real aTol,
Standard_Real& DMin) const
{
return Status(((Select3D_Pnt2d*)mypolyg2d)[0],((Select3D_Pnt2d*)mypolyg2d)[1],
((Select3D_Pnt2d*)mypolyg2d)[2],gp_XY(X,Y),aTol,DMin);
Standard_Real& DMin) const
{
return Status(mypolyg.Pnt2d(0), mypolyg.Pnt2d(1), mypolyg.Pnt2d(2),
gp_XY(X,Y), aTol, DMin);
}
//=======================================================================
@ -209,7 +210,7 @@ Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
Bnd_Box2d B;
B.Update(p0.X(),p0.Y());B.Update(p1.X(),p1.Y());B.Update(p2.X(),p2.Y());
B.Enlarge(aTol);
if(B.IsOut(TheP)) return 2;
if(B.IsOut(TheP)) return 2;
// the point is classified corresponding to demi-spaces limited
// by each side of the triangle (with tolerance)
@ -220,7 +221,7 @@ Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
Standard_Real TolTol = aTol*aTol;
// check these particular cases...
// if one of vectors is almost null (2 points are mixed),
// if one of vectors is almost null (2 points are mixed),
// leave at once (it is already in the bounding box, which is good...)
DMin = aTol;
@ -305,23 +306,30 @@ Standard_Integer Select3D_SensitiveTriangle::Status(const gp_XY& p0,
void Select3D_SensitiveTriangle::Dump(Standard_OStream& S,const Standard_Boolean FullDump) const
{
// general information....
S<<"\tSensitiveTriangle 3D :\n";
if(HasLocation())
S<<"\t\tExisting Location"<<endl;
S<<"\t\t P0 [ "<<COORD(0,x)<<" , "<<COORD(0,y) <<" , "<<COORD(0,z)<<" ]"<<endl;
S<<"\t\t P1 [ "<<COORD(1,x)<<" , "<<COORD(1,y) <<" , "<<COORD(1,z)<<" ]"<<endl;
S<<"\t\t P2 [ "<<COORD(2,x)<<" , "<<COORD(2,y) <<" , "<<COORD(2,z)<<" ]"<<endl;
gp_Pnt aPnt1, aPnt2, aPnt3;
aPnt1 = mypolyg.Pnt(0);
aPnt2 = mypolyg.Pnt(1);
aPnt3 = mypolyg.Pnt(2);
S<<"\t\t P0 [ "<<aPnt1.X()<<" , "<<aPnt1.Y()<<" , "<<aPnt1.Z()<<" ]"<<endl;
S<<"\t\t P1 [ "<<aPnt2.X()<<" , "<<aPnt2.Y()<<" , "<<aPnt2.Z()<<" ]"<<endl;
S<<"\t\t P2 [ "<<aPnt3.X()<<" , "<<aPnt3.Y()<<" , "<<aPnt3.Z()<<" ]"<<endl;
if(FullDump)
{
S<<"\t\tProjected Points"<<endl;
S<<"\t\t 0.[ "<<COORD2d(0,x)<<" , "<<COORD2d(0,y)<<" ]"<<endl;
S<<"\t\t 1.[ "<<COORD2d(1,x)<<" , "<<COORD2d(1,y)<<" ]"<<endl;
S<<"\t\t 2.[ "<<COORD2d(2,x)<<" , "<<COORD2d(2,y)<<" ]"<<endl;
// S<<"\t\t\tOwner:"<<myOwnerId<<endl;
gp_Pnt2d aPnt1, aPnt2, aPnt3;
aPnt1 = mypolyg.Pnt2d(0);
aPnt2 = mypolyg.Pnt2d(1);
aPnt3 = mypolyg.Pnt2d(2);
S<<"\t\t 0.[ "<<aPnt1.X()<<" , "<<aPnt1.Y()<<" ]"<<endl;
S<<"\t\t 1.[ "<<aPnt2.X()<<" , "<<aPnt2.Y()<<" ]"<<endl;
S<<"\t\t 2.[ "<<aPnt3.X()<<" , "<<aPnt3.Y()<<" ]"<<endl;
Select3D_SensitiveEntity::DumpBox(S,mybox2d);
}
}
@ -333,9 +341,12 @@ void Select3D_SensitiveTriangle::Dump(Standard_OStream& S,const Standard_Boolean
Standard_Real Select3D_SensitiveTriangle::ComputeDepth(const gp_Lin& EyeLine) const
{
gp_Pnt P1 = ((Select3D_Pnt*)mypolyg3d)[0];
gp_Pnt P2 = ((Select3D_Pnt*)mypolyg3d)[1];
gp_Pnt P3 = ((Select3D_Pnt*)mypolyg3d)[2];
Standard_Real prof(Precision::Infinite());
gp_Pnt P1, P2, P3;
P1 = mypolyg.Pnt(0);
P2 = mypolyg.Pnt(1);
P3 = mypolyg.Pnt(2);
gp_Trsf TheTrsf ;
if(HasLocation())
@ -348,7 +359,6 @@ Standard_Real Select3D_SensitiveTriangle::ComputeDepth(const gp_Lin& EyeLine) co
P3.Transform(TheTrsf);
}
Standard_Real prof(Precision::Infinite());
// formula calculation of the point parameters on intersection
// t = (P1P2 ^P1P3)* OP1 / ((P1P2^P1P3)*Dir)
@ -385,11 +395,7 @@ GetConnected(const TopLoc_Location &theLocation)
{
// Create a copy of this
Handle(Select3D_SensitiveEntity) aNewEntity =
new Select3D_SensitiveTriangle(myOwnerId,
((Select3D_Pnt*)mypolyg3d)[0],
((Select3D_Pnt*)mypolyg3d)[1],
((Select3D_Pnt*)mypolyg3d)[2],
mytype);
new Select3D_SensitiveTriangle(myOwnerId, mypolyg.Pnt(0), mypolyg.Pnt(1), mypolyg.Pnt(2), mytype);
if (HasLocation())
aNewEntity->SetLocation(Location());

File diff suppressed because it is too large Load Diff