1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-21 10:13:43 +03:00

0031009: Modeling Algorithms - leak reported by Clang address sanitizer in IntCurvesFace_ShapeIntersector

Refactor IntCurvesFace_ShapeIntersector. Use handles and std::unique_ptr instead of raw pointers.
This commit is contained in:
AndreyLA 2022-02-08 18:53:18 +03:00 committed by smoskvin
parent 2491eec38b
commit 1f000e5974
6 changed files with 298 additions and 381 deletions

View File

@ -3,4 +3,3 @@ IntCurvesFace_Intersector.hxx
IntCurvesFace_Intersector.lxx IntCurvesFace_Intersector.lxx
IntCurvesFace_ShapeIntersector.cxx IntCurvesFace_ShapeIntersector.cxx
IntCurvesFace_ShapeIntersector.hxx IntCurvesFace_ShapeIntersector.hxx
IntCurvesFace_ShapeIntersector.lxx

View File

@ -43,6 +43,9 @@
#include <BRep_Tool.hxx> #include <BRep_Tool.hxx>
#include <TopoDS.hxx> #include <TopoDS.hxx>
#include <GeomAPI_ProjectPointOnCurve.hxx> #include <GeomAPI_ProjectPointOnCurve.hxx>
IMPLEMENT_STANDARD_RTTIEXT(IntCurvesFace_Intersector, Standard_Transient)
// //
static void ComputeSamplePars(const Handle(Adaptor3d_Surface)& Hsurface, static void ComputeSamplePars(const Handle(Adaptor3d_Surface)& Hsurface,
const Standard_Integer nbsu, const Standard_Integer nbsu,
@ -134,8 +137,6 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face,
done(Standard_False), done(Standard_False),
myReady(Standard_False), myReady(Standard_False),
nbpnt(0), nbpnt(0),
PtrOnPolyhedron(NULL),
PtrOnBndBounding(NULL),
myUseBoundTol (UseBToler), myUseBoundTol (UseBToler),
myIsParallel(Standard_False) myIsParallel(Standard_False)
{ {
@ -201,14 +202,12 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face,
{ {
Handle(TColStd_HArray1OfReal) UPars, VPars; Handle(TColStd_HArray1OfReal) UPars, VPars;
ComputeSamplePars(Hsurface, nbsu, nbsv, UPars, VPars); ComputeSamplePars(Hsurface, nbsu, nbsv, UPars, VPars);
PtrOnPolyhedron = (IntCurveSurface_ThePolyhedronOfHInter *) myPolyhedron.reset(new IntCurveSurface_ThePolyhedronOfHInter(Hsurface, UPars->ChangeArray1(),
new IntCurveSurface_ThePolyhedronOfHInter(Hsurface, UPars->ChangeArray1(), VPars->ChangeArray1()));
VPars->ChangeArray1());
} }
else else
{ {
PtrOnPolyhedron = (IntCurveSurface_ThePolyhedronOfHInter *) myPolyhedron.reset(new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1));
new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1);
} }
} }
myReady = Standard_True; myReady = Standard_True;
@ -282,7 +281,6 @@ void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS,
Standard_Real W = HICSW; Standard_Real W = HICSW;
IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition(); IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition();
gp_Pnt pnt = HICSPointindex.Pnt(); gp_Pnt pnt = HICSPointindex.Pnt();
// state = currentstate;
// Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin
Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1; Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1;
// Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End
@ -360,7 +358,7 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L,
Standard_Real parinf=ParMin; Standard_Real parinf=ParMin;
Standard_Real parsup=ParMax; Standard_Real parsup=ParMax;
// //
if(PtrOnPolyhedron == NULL) { if(!myPolyhedron) {
HICS.Perform(HLL,Hsurface); HICS.Perform(HLL,Hsurface);
} }
else { else {
@ -368,7 +366,7 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L,
Bnd_Box boxLine; Bnd_Box boxLine;
bndTool.LinBox bndTool.LinBox
(L, (L,
((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding(), myPolyhedron->Bounding(),
boxLine); boxLine);
if(bndTool.NbSegments() == 0) if(bndTool.NbSegments() == 0)
return; return;
@ -395,24 +393,22 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L,
parsup, parsup,
2); 2);
#if OPTIMISATION #if OPTIMISATION
if(PtrOnBndBounding==NULL) { if(!myBndBounding)
PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox(); {
IntCurveSurface_ThePolyhedronOfHInter *thePolyh= myBndBounding.reset(new Bnd_BoundSortBox());
(IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; myBndBounding->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*myPolyhedron),
((Bnd_BoundSortBox *)(PtrOnBndBounding))-> IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*myPolyhedron));
Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh),
IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh));
} }
HICS.Perform(HLL, HICS.Perform(HLL,
polygon, polygon,
Hsurface, Hsurface,
*((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron), *myPolyhedron,
*((Bnd_BoundSortBox *)PtrOnBndBounding)); *myBndBounding);
#else #else
HICS.Perform(HLL, HICS.Perform(HLL,
polygon, polygon,
Hsurface, Hsurface,
*((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)); *myPolyhedron);
#endif #endif
} }
@ -443,10 +439,12 @@ void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_Curve)& HCu,
Standard_Real parinf=ParMin; Standard_Real parinf=ParMin;
Standard_Real parsup=ParMax; Standard_Real parsup=ParMax;
if(PtrOnPolyhedron == NULL) { if(!myPolyhedron)
{
HICS.Perform(HCu,Hsurface); HICS.Perform(HCu,Hsurface);
} }
else { else
{
parinf = IntCurveSurface_TheHCurveTool::FirstParameter(HCu); parinf = IntCurveSurface_TheHCurveTool::FirstParameter(HCu);
parsup = IntCurveSurface_TheHCurveTool::LastParameter(HCu); parsup = IntCurveSurface_TheHCurveTool::LastParameter(HCu);
if(parinf<ParMin) parinf = ParMin; if(parinf<ParMin) parinf = ParMin;
@ -460,22 +458,21 @@ void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_Curve)& HCu,
parsup, parsup,
nbs); nbs);
#if OPTIMISATION #if OPTIMISATION
if(PtrOnBndBounding==NULL) { if(!myBndBounding) {
PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox(); myBndBounding.reset(new Bnd_BoundSortBox());
IntCurveSurface_ThePolyhedronOfHInter *thePolyh=(IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; myBndBounding->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*myPolyhedron),
((Bnd_BoundSortBox *)(PtrOnBndBounding))->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh), IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*myPolyhedron));
IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh));
} }
HICS.Perform(HCu, HICS.Perform(HCu,
polygon, polygon,
Hsurface, Hsurface,
*((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron), *myPolyhedron,
*((Bnd_BoundSortBox *)PtrOnBndBounding)); *myBndBounding);
#else #else
HICS.Perform(HCu, HICS.Perform(HCu,
polygon, polygon,
Hsurface, Hsurface,
*((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)); *myPolyhedron);
#endif #endif
} }
InternalCall(HICS,parinf,parsup); InternalCall(HICS,parinf,parsup);
@ -483,37 +480,33 @@ void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_Curve)& HCu,
//============================================================================ //============================================================================
Bnd_Box IntCurvesFace_Intersector::Bounding() const { Bnd_Box IntCurvesFace_Intersector::Bounding() const {
if(PtrOnPolyhedron !=NULL) { if(myPolyhedron)
return(((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding()); {
return myPolyhedron->Bounding();
} }
else { else
{
Bnd_Box B; Bnd_Box B;
return(B); return B;
} }
} }
TopAbs_State IntCurvesFace_Intersector::ClassifyUVPoint(const gp_Pnt2d& Puv) const {
TopAbs_State IntCurvesFace_Intersector::ClassifyUVPoint(const gp_Pnt2d& Puv) const
{
TopAbs_State state = myTopolTool->Classify(Puv,1e-7); TopAbs_State state = myTopolTool->Classify(Puv,1e-7);
return(state); return state;
}
//============================================================================
void IntCurvesFace_Intersector::Destroy() {
if(PtrOnPolyhedron !=NULL) {
delete (IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron;
PtrOnPolyhedron = NULL;
}
if(PtrOnBndBounding !=NULL) {
delete (Bnd_BoundSortBox *)PtrOnBndBounding;
PtrOnBndBounding=NULL;
}
} }
void IntCurvesFace_Intersector::SetUseBoundToler(Standard_Boolean UseBToler) void IntCurvesFace_Intersector::SetUseBoundToler(Standard_Boolean UseBToler)
{ {
myUseBoundTol = UseBToler; myUseBoundTol = UseBToler;
} }
Standard_Boolean IntCurvesFace_Intersector::GetUseBoundToler() const Standard_Boolean IntCurvesFace_Intersector::GetUseBoundToler() const
{ {
return myUseBoundTol; return myUseBoundTol;
} }
IntCurvesFace_Intersector::~IntCurvesFace_Intersector()
{
}

View File

@ -18,14 +18,18 @@
#define _IntCurvesFace_Intersector_HeaderFile #define _IntCurvesFace_Intersector_HeaderFile
#include <Adaptor3d_Curve.hxx> #include <Adaptor3d_Curve.hxx>
#include <Bnd_BoundSortBox.hxx>
#include <BRepAdaptor_Surface.hxx> #include <BRepAdaptor_Surface.hxx>
#include <IntCurveSurface_SequenceOfPnt.hxx> #include <IntCurveSurface_SequenceOfPnt.hxx>
#include <IntCurveSurface_ThePolyhedronOfHInter.hxx>
#include <TColStd_SequenceOfInteger.hxx> #include <TColStd_SequenceOfInteger.hxx>
#include <TopoDS_Face.hxx> #include <TopoDS_Face.hxx>
#include <GeomAbs_SurfaceType.hxx> #include <GeomAbs_SurfaceType.hxx>
#include <IntCurveSurface_TransitionOnCurve.hxx> #include <IntCurveSurface_TransitionOnCurve.hxx>
#include <TopAbs_State.hxx> #include <TopAbs_State.hxx>
#include <memory>
class BRepTopAdaptor_TopolTool; class BRepTopAdaptor_TopolTool;
class gp_Lin; class gp_Lin;
class gp_Pnt; class gp_Pnt;
@ -33,8 +37,13 @@ class IntCurveSurface_HInter;
class gp_Pnt2d; class gp_Pnt2d;
class Bnd_Box; class Bnd_Box;
class IntCurvesFace_Intersector DEFINE_STANDARD_HANDLE(IntCurvesFace_Intersector, Standard_Transient)
class IntCurvesFace_Intersector : public Standard_Transient
{ {
DEFINE_STANDARD_RTTIEXT(IntCurvesFace_Intersector, Standard_Transient)
public: public:
DEFINE_STANDARD_ALLOC DEFINE_STANDARD_ALLOC
@ -123,14 +132,7 @@ public:
//! Returns the boundary tolerance flag //! Returns the boundary tolerance flag
Standard_EXPORT Standard_Boolean GetUseBoundToler() const; Standard_EXPORT Standard_Boolean GetUseBoundToler() const;
Standard_EXPORT void Destroy(); Standard_EXPORT virtual ~IntCurvesFace_Intersector();
~IntCurvesFace_Intersector()
{
Destroy();
}
protected: protected:
@ -153,8 +155,8 @@ private:
Standard_Boolean myReady; Standard_Boolean myReady;
Standard_Integer nbpnt; Standard_Integer nbpnt;
TopoDS_Face face; TopoDS_Face face;
Standard_Address PtrOnPolyhedron; std::unique_ptr<IntCurveSurface_ThePolyhedronOfHInter> myPolyhedron;
Standard_Address PtrOnBndBounding; std::unique_ptr<Bnd_BoundSortBox> myBndBounding;
Standard_Boolean myUseBoundTol; Standard_Boolean myUseBoundTol;
Standard_Boolean myIsParallel; //Curve is "parallel" face surface Standard_Boolean myIsParallel; //Curve is "parallel" face surface
//This case is recognized only for some pairs //This case is recognized only for some pairs

View File

@ -30,202 +30,186 @@
#include <TopoDS_Face.hxx> #include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx> #include <TopoDS_Shape.hxx>
//-- ================================================================================
IntCurvesFace_ShapeIntersector::IntCurvesFace_ShapeIntersector() { IntCurvesFace_ShapeIntersector::IntCurvesFace_ShapeIntersector()
nbfaces=0; : myIsDone(Standard_False),
done=Standard_False; myNbFaces(0)
PtrJetons=NULL; {
PtrJetonsIndex=NULL;
} }
//-- ================================================================================
void IntCurvesFace_ShapeIntersector::Load(const TopoDS_Shape& shape, void IntCurvesFace_ShapeIntersector::Load(const TopoDS_Shape& theShape,
const Standard_Real tol) { const Standard_Real theTol)
PtrJetons=NULL; {
PtrJetonsIndex=NULL;
if(nbfaces) {
Destroy();
}
TopExp_Explorer Ex; TopExp_Explorer Ex;
Standard_Integer i; Standard_Integer i;
for(nbfaces=0,i=0,Ex.Init(shape,TopAbs_FACE); Ex.More(); i++,Ex.Next()) { for(myNbFaces = 0, i = 0, Ex.Init(theShape, TopAbs_FACE); Ex.More(); ++i, Ex.Next())
nbfaces++; {
TopoDS_Face currentface = TopoDS::Face(Ex.Current()); ++myNbFaces;
PtrIntersector.Append((void *)(new IntCurvesFace_Intersector(currentface,tol))); TopoDS_Face aCurrentFace = TopoDS::Face(Ex.Current());
myIntersector.Append(new IntCurvesFace_Intersector(aCurrentFace, theTol));
} }
} }
//-- ================================================================================
void IntCurvesFace_ShapeIntersector::Destroy() { void IntCurvesFace_ShapeIntersector::Perform(const gp_Lin& theL,
if(PtrJetons) { const Standard_Real theParMin,
delete ((Standard_Integer *)PtrJetons); const Standard_Real theParMax)
PtrJetons=NULL; {
} myIsDone = Standard_False;
if(PtrJetonsIndex) { for(Standard_Integer i = 1; i <= myNbFaces; ++i)
delete ((Standard_Integer *)PtrJetonsIndex); {
PtrJetonsIndex=NULL; myIntersector.ChangeValue(i)->Perform(theL, theParMin, theParMax);
}
for(Standard_Integer i=1; i<=nbfaces; i++) {
IntCurvesFace_Intersector *Ptr = (IntCurvesFace_Intersector *)PtrIntersector.ChangeValue(i);
delete Ptr;
}
done=Standard_False;
nbfaces=0;
PtrIntersector.Clear();
IndexPt.Clear(); IndexFace.Clear(); IndexIntPnt.Clear();IndexPar.Clear();
}
//-- ================================================================================
void IntCurvesFace_ShapeIntersector::Perform(const gp_Lin& L,
const Standard_Real ParMin,
const Standard_Real ParMax) {
done = Standard_False;
for(Standard_Integer i=1; i<=nbfaces; i++) {
IntCurvesFace_Intersector *Ptr = (IntCurvesFace_Intersector *)PtrIntersector.ChangeValue(i);
Ptr->Perform(L,ParMin,ParMax);
} }
SortResult(); SortResult();
} }
//-- ================================================================================
void IntCurvesFace_ShapeIntersector::PerformNearest(const gp_Lin& L,
const Standard_Real ParMin,
const Standard_Real _ParMax) {
Standard_Integer i; void IntCurvesFace_ShapeIntersector::PerformNearest(const gp_Lin& theL,
Standard_Integer* _PtrJetons=(Standard_Integer *)PtrJetons; const Standard_Real theParMin,
Standard_Integer* _PtrJetonsIndex=(Standard_Integer *)PtrJetonsIndex; const Standard_Real theParMax)
{
Standard_Integer i = 0;
if(nbfaces>2) { if(myNbFaces > 2)
if(PtrJetons==NULL) { {
PtrJetons = (void *) new Standard_Integer [nbfaces]; if (myPtrNums.IsEmpty())
PtrJetonsIndex = (void *) new Standard_Integer [nbfaces]; {
Standard_Integer *Ptr =(Standard_Integer *)PtrJetons; myPtrNums = TColStd_HArray1OfInteger(0, myNbFaces - 1);
Standard_Integer *PtrI=(Standard_Integer *)PtrJetonsIndex; myPtrIndexNums = TColStd_HArray1OfInteger(0, myNbFaces - 1);
for(i=0;i<nbfaces;i++) { for(; i < myNbFaces; ++i)
Ptr[i]=0; {
PtrI[i]=i+1; myPtrNums.ChangeValue(i) = 0;
} myPtrIndexNums.ChangeValue(i) = i + 1;
_PtrJetons=(Standard_Integer *)PtrJetons;
_PtrJetonsIndex=(Standard_Integer *)PtrJetonsIndex;
}
}
Standard_Integer Indexface=-1;
Standard_Real ParMax=_ParMax;
done = Standard_False;
for(Standard_Integer ii=1; ii<=nbfaces; ii++) {
if(_PtrJetons) {
i=_PtrJetonsIndex[ii-1];
}
else {
i=ii;
}
IntCurvesFace_Intersector *Ptr = (IntCurvesFace_Intersector *)PtrIntersector.ChangeValue(i);
if(ParMin<ParMax) {
Ptr->Perform(L,ParMin,ParMax);
if(Ptr->IsDone()) {
Standard_Integer n=Ptr->NbPnt();
for(Standard_Integer j=1;j<=n;j++) {
Standard_Real w=Ptr->WParameter(j);
if(w<ParMax) {
ParMax=w;
Indexface=ii-1;
} }
} }
} }
else {
done = Standard_False; Standard_Integer anIndexFace = -1;
Standard_Real aParMax=theParMax;
myIsDone = Standard_False;
for(Standard_Integer ii = 1; ii <= myNbFaces; ++ii)
{
if (!myPtrNums.IsEmpty())
{
i = myPtrIndexNums.Value(ii - 1);
}
else
{
i = ii;
}
Handle(IntCurvesFace_Intersector) anIntersector = myIntersector.ChangeValue(i);
if(theParMin < aParMax)
{
anIntersector->Perform(theL, theParMin,aParMax);
if(anIntersector->IsDone())
{
Standard_Integer n = anIntersector->NbPnt();
for(Standard_Integer j = 1; j <= n; ++j)
{
Standard_Real w = anIntersector->WParameter(j);
if(w < aParMax)
{
aParMax = w;
anIndexFace = ii - 1;
}
}
}
else
{
myIsDone = Standard_False;
return; return;
} }
} }
} }
if(PtrJetons && Indexface>=0) { if (!myPtrNums.IsEmpty() && anIndexFace >= 0)
_PtrJetons[Indexface]++; {
myPtrNums.ChangeValue(anIndexFace) += 1;
Standard_Integer im1; Standard_Integer im1;
for(im1=Indexface-1,i=Indexface; i>=1 && _PtrJetons[i]>_PtrJetons[i-1]; i--,im1--) { for (im1 = anIndexFace - 1, i = anIndexFace; i >= 1 && myPtrNums.Value(i) > myPtrNums.Value(im1); --i, --im1)
Standard_Integer t=_PtrJetonsIndex[i]; {
_PtrJetonsIndex[i]=_PtrJetonsIndex[im1]; std::swap(myPtrIndexNums.ChangeValue(i), myPtrIndexNums.ChangeValue(im1));
_PtrJetonsIndex[im1]=t; std::swap(myPtrNums.ChangeValue(i), myPtrNums.ChangeValue(im1));
t=_PtrJetons[i];
_PtrJetons[i]=_PtrJetons[im1];
_PtrJetons[im1]=t;
} }
//--for(Standard_Integer dd=0; dd<nbfaces;dd++) { if(_PtrJetons[dd]) { printf("\n<%3d %3d %3d>",dd,_PtrJetons[dd],_PtrJetonsIndex[dd]); } } }
//--printf("\n"); SortResult();
}
void IntCurvesFace_ShapeIntersector::Perform(const Handle(Adaptor3d_Curve)& theHCurve,
const Standard_Real theParMin,
const Standard_Real theParMax)
{
myIsDone = Standard_False;
for(Standard_Integer i = 1; i <= myNbFaces; ++i)
{
Handle(IntCurvesFace_Intersector) anIntersector = myIntersector.ChangeValue(i);
anIntersector->Perform(theHCurve, theParMin, theParMax);
} }
SortResult(); SortResult();
} }
//-- ================================================================================ //-- ================================================================================
void IntCurvesFace_ShapeIntersector::Perform(const Handle(Adaptor3d_Curve)& HCu, //-- myIntersector : Sequence of the addresses
const Standard_Real ParMin, //-- myIndexPt : 1 2 3 .... n Points before the sorting
const Standard_Real ParMax) { //-- myNumberFace : Number of the face (of the intersector) of the point myIndexPt(i)
done = Standard_False; //-- myNumberIntPnt : Number of the point myIndexPt(i) of the intersection myNumberFace(myIndexPt(i))
for(Standard_Integer i=1; i<=nbfaces; i++) { //-- myIndexPar : Parameter W of point myIndexPt(i)
IntCurvesFace_Intersector *Ptr = (IntCurvesFace_Intersector *)PtrIntersector.ChangeValue(i);
Ptr->Perform(HCu,ParMin,ParMax);
}
SortResult();
}
//-- ================================================================================
//-- PtrIntersector : Sequence d addresses
//-- IndexPt : 1 2 3 .... n points avant le tri
//-- IndexFace : Numero de la face (de l intersector) du point IndexPt(i)
//-- IndexIntPnt : Numero du point IndexPt(i) dans l'intersector IndexFace(IndexPt(i))
//-- IndexPar : W parameter du point IndexPt(i)
//-- //--
//-- En resume, pour chaque point indice par K = IndexPt(i) on a //-- To sum up, for each point index of K = myIndexPt(i) on a
//-- * la face a laquelle il appartient : IndexFace(K) //-- * the face to which it belongs : myNumberFace(K)
//-- * le numero du point dans l'intersecteur FaceCurve : IndexIntPnt(K) //-- * the number of the point in the intersection for FaceCurve : myNumberIntPnt(K)
//-- * le parametre W du point sur la courbe : IndexPar(K) //-- * the parameter W of the point on the curve : myIndexPar(K)
//-- //--
//-- SortResult Trie les points par ordre croissant de W //-- SortResult Sorts the points in ascending order of W
//-- (remet a jour le tableau d index TabPt(.)) //-- (updating the index table TabPt(.))
//-- //--
//-- ================================================================================ //-- ================================================================================
void IntCurvesFace_ShapeIntersector::SortResult() { void IntCurvesFace_ShapeIntersector::SortResult()
done = Standard_True; {
Standard_Integer nbpnt=0; myIsDone = Standard_True;
IndexPt.Clear(); IndexFace.Clear(); IndexIntPnt.Clear();IndexPar.Clear(); Standard_Integer aNbPnt=0;
//-- ----------------------------------------------------- myIndexPt.Clear();
//-- r e c u p e r a t i o n d e s r e s u l t a t s myIndexFace.Clear();
//-- myIndexIntPnt.Clear();
for(Standard_Integer f=1; f<=nbfaces; f++) { myIndexPar.Clear();
IntCurvesFace_Intersector *Ptr = (IntCurvesFace_Intersector *)PtrIntersector.ChangeValue(f);
if(Ptr->IsDone()) { //Retrieval of the results
Standard_Integer n=Ptr->NbPnt(); for(Standard_Integer f = 1; f <= myNbFaces; ++f)
for(Standard_Integer j=1;j<=n;j++) { {
IndexPt.Append(++nbpnt); Handle(IntCurvesFace_Intersector) anIntersector = myIntersector.ChangeValue(f);
IndexFace.Append(f); if(anIntersector->IsDone())
IndexIntPnt.Append(j); {
IndexPar.Append(Ptr->WParameter(j)); Standard_Integer n = anIntersector->NbPnt();
for(Standard_Integer j = 1; j <= n; ++j)
{
myIndexPt.Append(++aNbPnt);
myIndexFace.Append(f);
myIndexIntPnt.Append(j);
myIndexPar.Append(anIntersector->WParameter(j));
} }
} }
else { else
done = Standard_False; {
myIsDone = Standard_False;
return; return;
} }
} }
//-- -----------------------------------------------------
//-- t r i s e l o n l e p a r a m e t r e w //Sort according to parameter w
//-- Standard_Boolean isOK;
Standard_Boolean triok; do
do { {
triok=Standard_True; isOK = Standard_True;
for(Standard_Integer ind0=1;ind0<nbpnt;ind0++) { for(Standard_Integer ind0 = 1; ind0 < aNbPnt; ind0++)
Standard_Integer ind =IndexPt(ind0); {
Standard_Integer indp1=IndexPt(ind0+1); Standard_Integer ind = myIndexPt(ind0);
if(IndexPar(ind) > IndexPar(indp1)) { Standard_Integer indp1 = myIndexPt(ind0 + 1);
IndexPt(ind0) =indp1; if(myIndexPar(ind) > myIndexPar(indp1))
IndexPt(ind0+1)=ind; {
triok=Standard_False; myIndexPt(ind0) = indp1;
myIndexPt(ind0 + 1) = ind;
isOK = Standard_False;
} }
} }
} }
while(triok==Standard_False); while(!isOK);
}
IntCurvesFace_ShapeIntersector::~IntCurvesFace_ShapeIntersector()
{
} }
//-- ================================================================================
//-- Creation le 28 jan 98
//--

View File

@ -23,12 +23,12 @@
#include <Standard_Boolean.hxx> #include <Standard_Boolean.hxx>
#include <Standard_Integer.hxx> #include <Standard_Integer.hxx>
#include <Standard_Address.hxx> #include <TColStd_Array1OfInteger.hxx>
#include <BRepTopAdaptor_SeqOfPtr.hxx>
#include <TColStd_SequenceOfInteger.hxx> #include <TColStd_SequenceOfInteger.hxx>
#include <TColStd_SequenceOfReal.hxx> #include <TColStd_SequenceOfReal.hxx>
#include <Standard_Real.hxx> #include <Standard_Real.hxx>
#include <IntCurveSurface_TransitionOnCurve.hxx> #include <IntCurveSurface_TransitionOnCurve.hxx>
#include <IntCurvesFace_Intersector.hxx>
#include <TopAbs_State.hxx> #include <TopAbs_State.hxx>
class Adaptor3d_Curve; class Adaptor3d_Curve;
@ -52,7 +52,7 @@ public:
//! segment L and the loaded shape. //! segment L and the loaded shape.
//! //!
//! PInf is the smallest parameter on the line //! PInf is the smallest parameter on the line
//! PSup is the highest parammter on the line //! PSup is the highest parameter on the line
//! //!
//! For an infinite line PInf and PSup can be //! For an infinite line PInf and PSup can be
//! +/- RealLast. //! +/- RealLast.
@ -62,92 +62,102 @@ public:
//! segment L and the loaded shape. //! segment L and the loaded shape.
//! //!
//! PInf is the smallest parameter on the line //! PInf is the smallest parameter on the line
//! PSup is the highest parammter on the line //! PSup is the highest parameter on the line
//! //!
//! For an infinite line PInf and PSup can be //! For an infinite line PInf and PSup can be
//! +/- RealLast. //! +/- RealLast.
Standard_EXPORT void PerformNearest (const gp_Lin& L, const Standard_Real PInf, const Standard_Real PSup); Standard_EXPORT void PerformNearest (const gp_Lin& L, const Standard_Real PInf, const Standard_Real PSup);
//! same method for a HCurve from Adaptor3d. //! same method for a HCurve from Adaptor3d.
//! PInf an PSup can also be - and + INF. //! PInf an PSup can also be -INF and +INF.
Standard_EXPORT void Perform (const Handle(Adaptor3d_Curve)& HCu, const Standard_Real PInf, const Standard_Real PSup); Standard_EXPORT void Perform (const Handle(Adaptor3d_Curve)& HCu, const Standard_Real PInf, const Standard_Real PSup);
//! True is returned when the intersection have been computed. //! True when the intersection has been computed.
Standard_Boolean IsDone() const; Standard_Boolean IsDone() const
{
Standard_Integer NbPnt() const; return myIsDone;
}
//! Returns the number of the intersection points
Standard_Integer NbPnt() const
{
return myIndexPt.Length();
}
//! Returns the U parameter of the ith intersection point //! Returns the U parameter of the ith intersection point
//! on the surface. //! on the surface.
Standard_Real UParameter (const Standard_Integer I) const; Standard_Real UParameter (const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->UParameter(myIndexIntPnt(myIndexPt(I)));
}
//! Returns the V parameter of the ith intersection point //! Returns the V parameter of the ith intersection point
//! on the surface. //! on the surface.
Standard_Real VParameter (const Standard_Integer I) const; Standard_Real VParameter (const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->VParameter(myIndexIntPnt(myIndexPt(I)));
}
//! Returns the parameter of the ith intersection point //! Returns the parameter of the ith intersection point
//! on the line. //! on the line.
Standard_Real WParameter (const Standard_Integer I) const; Standard_Real WParameter (const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->WParameter(myIndexIntPnt(myIndexPt(I)));
}
//! Returns the geometric point of the ith intersection //! Returns the geometric point of the ith intersection
//! between the line and the surface. //! between the line and the surface.
const gp_Pnt& Pnt (const Standard_Integer I) const; const gp_Pnt& Pnt (const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->Pnt(myIndexIntPnt(myIndexPt(I)));
}
//! Returns the ith transition of the line on the surface. //! Returns the ith transition of the line on the surface.
IntCurveSurface_TransitionOnCurve Transition (const Standard_Integer I) const; IntCurveSurface_TransitionOnCurve Transition (const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->Transition(myIndexIntPnt(myIndexPt(I)));
}
//! Returns the ith state of the point on the face. //! Returns the ith state of the point on the face.
//! The values can be either TopAbs_IN //! The values can be either TopAbs_IN
//! ( the point is in the face) //! ( the point is in the face)
//! or TopAbs_ON //! or TopAbs_ON
//! ( the point is on a boundary of the face). //! ( the point is on a boundary of the face).
TopAbs_State State (const Standard_Integer I) const; TopAbs_State State(const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->State(myIndexIntPnt(myIndexPt(I)));
}
//! Returns the significant face used to determine //! Returns the significant face used to determine
//! the intersection. //! the intersection.
const TopoDS_Face& Face (const Standard_Integer I) const; const TopoDS_Face& Face(const Standard_Integer I) const
{
Handle(IntCurvesFace_Intersector) anIntAdaptor = myIntersector(myIndexFace(myIndexPt(I)));
return anIntAdaptor->Face();
}
//! Internal method. Sort the result on the Curve //! Internal method. Sort the result on the Curve
//! parameter. //! parameter.
Standard_EXPORT void SortResult(); Standard_EXPORT void SortResult();
Standard_EXPORT void Destroy(); Standard_EXPORT virtual ~IntCurvesFace_ShapeIntersector();
~IntCurvesFace_ShapeIntersector()
{
Destroy();
}
protected:
private: private:
Standard_Boolean myIsDone;
Standard_Integer myNbFaces;
Standard_Boolean done; TColStd_Array1OfInteger myPtrNums;
Standard_Integer nbfaces; TColStd_Array1OfInteger myPtrIndexNums;
Standard_Address PtrJetons; NCollection_Sequence<Handle(IntCurvesFace_Intersector)> myIntersector;
Standard_Address PtrJetonsIndex; TColStd_SequenceOfInteger myIndexPt;
BRepTopAdaptor_SeqOfPtr PtrIntersector; TColStd_SequenceOfInteger myIndexFace;
TColStd_SequenceOfInteger IndexPt; TColStd_SequenceOfInteger myIndexIntPnt;
TColStd_SequenceOfInteger IndexFace; TColStd_SequenceOfReal myIndexPar;
TColStd_SequenceOfInteger IndexIntPnt;
TColStd_SequenceOfReal IndexPar;
}; };
#include <IntCurvesFace_ShapeIntersector.lxx>
#endif // _IntCurvesFace_ShapeIntersector_HeaderFile #endif // _IntCurvesFace_ShapeIntersector_HeaderFile

View File

@ -1,71 +0,0 @@
// Created on: 1998-01-28
// Created by: Laurent BUCHARD
// Copyright (c) 1998-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 <IntCurvesFace_Intersector.hxx>
inline Standard_Integer IntCurvesFace_ShapeIntersector::NbPnt() const {
return(IndexPt.Length());
}
inline Standard_Real IntCurvesFace_ShapeIntersector::UParameter(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->UParameter(IndexIntPnt(IndexPt(i))));
}
inline Standard_Real IntCurvesFace_ShapeIntersector::VParameter(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->VParameter(IndexIntPnt(IndexPt(i))));
}
inline Standard_Real IntCurvesFace_ShapeIntersector::WParameter(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->WParameter(IndexIntPnt(IndexPt(i))));
}
inline const gp_Pnt& IntCurvesFace_ShapeIntersector::Pnt(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->Pnt(IndexIntPnt(IndexPt(i))));
}
inline IntCurveSurface_TransitionOnCurve IntCurvesFace_ShapeIntersector::Transition(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->Transition(IndexIntPnt(IndexPt(i))));
}
inline TopAbs_State IntCurvesFace_ShapeIntersector::State(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->State(IndexIntPnt(IndexPt(i))));
}
inline const TopoDS_Face& IntCurvesFace_ShapeIntersector::Face(const Standard_Integer i) const {
IntCurvesFace_Intersector *Ptr =
(IntCurvesFace_Intersector *)(PtrIntersector(IndexFace(IndexPt(i))));
return(Ptr->Face());
}
inline Standard_Boolean IntCurvesFace_ShapeIntersector::IsDone() const {
return(done);
}