From 1f000e597469b177172c2321368a4db60eae8c9f Mon Sep 17 00:00:00 2001 From: AndreyLA Date: Tue, 8 Feb 2022 18:53:18 +0300 Subject: [PATCH] 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. --- src/IntCurvesFace/FILES | 1 - .../IntCurvesFace_Intersector.cxx | 147 ++++---- .../IntCurvesFace_Intersector.hxx | 24 +- .../IntCurvesFace_ShapeIntersector.cxx | 322 +++++++++--------- .../IntCurvesFace_ShapeIntersector.hxx | 114 ++++--- .../IntCurvesFace_ShapeIntersector.lxx | 71 ---- 6 files changed, 298 insertions(+), 381 deletions(-) delete mode 100644 src/IntCurvesFace/IntCurvesFace_ShapeIntersector.lxx diff --git a/src/IntCurvesFace/FILES b/src/IntCurvesFace/FILES index f5dd47dae8..218dca7d5b 100644 --- a/src/IntCurvesFace/FILES +++ b/src/IntCurvesFace/FILES @@ -3,4 +3,3 @@ IntCurvesFace_Intersector.hxx IntCurvesFace_Intersector.lxx IntCurvesFace_ShapeIntersector.cxx IntCurvesFace_ShapeIntersector.hxx -IntCurvesFace_ShapeIntersector.lxx diff --git a/src/IntCurvesFace/IntCurvesFace_Intersector.cxx b/src/IntCurvesFace/IntCurvesFace_Intersector.cxx index 5ae6228f2d..78f47c648d 100644 --- a/src/IntCurvesFace/IntCurvesFace_Intersector.cxx +++ b/src/IntCurvesFace/IntCurvesFace_Intersector.cxx @@ -43,6 +43,9 @@ #include #include #include + +IMPLEMENT_STANDARD_RTTIEXT(IntCurvesFace_Intersector, Standard_Transient) + // static void ComputeSamplePars(const Handle(Adaptor3d_Surface)& Hsurface, const Standard_Integer nbsu, @@ -134,8 +137,6 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face, done(Standard_False), myReady(Standard_False), nbpnt(0), - PtrOnPolyhedron(NULL), - PtrOnBndBounding(NULL), myUseBoundTol (UseBToler), myIsParallel(Standard_False) { @@ -201,14 +202,12 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face, { Handle(TColStd_HArray1OfReal) UPars, VPars; ComputeSamplePars(Hsurface, nbsu, nbsv, UPars, VPars); - PtrOnPolyhedron = (IntCurveSurface_ThePolyhedronOfHInter *) - new IntCurveSurface_ThePolyhedronOfHInter(Hsurface, UPars->ChangeArray1(), - VPars->ChangeArray1()); + myPolyhedron.reset(new IntCurveSurface_ThePolyhedronOfHInter(Hsurface, UPars->ChangeArray1(), + VPars->ChangeArray1())); } else { - PtrOnPolyhedron = (IntCurveSurface_ThePolyhedronOfHInter *) - new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1); + myPolyhedron.reset(new IntCurveSurface_ThePolyhedronOfHInter(Hsurface,nbsu,nbsv,U0,V0,U1,V1)); } } myReady = Standard_True; @@ -218,8 +217,8 @@ IntCurvesFace_Intersector::IntCurvesFace_Intersector(const TopoDS_Face& Face, //purpose : //======================================================================= void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS, - const Standard_Real parinf, - const Standard_Real parsup) + const Standard_Real parinf, + const Standard_Real parsup) { if(HICS.IsDone() && HICS.NbPoints() > 0) { //Calculate tolerance for 2d classifier @@ -282,7 +281,6 @@ void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS, Standard_Real W = HICSW; IntCurveSurface_TransitionOnCurve transition = HICSPointindex.Transition(); gp_Pnt pnt = HICSPointindex.Pnt(); - // state = currentstate; // Modified by skv - Wed Sep 3 16:14:10 2003 OCC578 Begin Standard_Integer anIntState = (currentstate == TopAbs_IN) ? 0 : 1; // Modified by skv - Wed Sep 3 16:14:11 2003 OCC578 End @@ -340,8 +338,8 @@ void IntCurvesFace_Intersector::InternalCall(const IntCurveSurface_HInter &HICS, //purpose : //======================================================================= void IntCurvesFace_Intersector::Perform(const gp_Lin& L, - const Standard_Real ParMin, - const Standard_Real ParMax) + const Standard_Real ParMin, + const Standard_Real ParMax) { done = Standard_False; if (!myReady) @@ -360,7 +358,7 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L, Standard_Real parinf=ParMin; Standard_Real parsup=ParMax; // - if(PtrOnPolyhedron == NULL) { + if(!myPolyhedron) { HICS.Perform(HLL,Hsurface); } else { @@ -368,7 +366,7 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L, Bnd_Box boxLine; bndTool.LinBox (L, - ((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding(), + myPolyhedron->Bounding(), boxLine); if(bndTool.NbSegments() == 0) return; @@ -381,8 +379,8 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L, if((psup - pinf)<1e-10) { pinf-=1e-10; psup+=1e-10; } if(nbseg==1) { parinf=pinf; parsup=psup; } else { - if(parinf>pinf) parinf = pinf; - if(parsuppinf) parinf = pinf; + if(parsupParMax) { return; } @@ -391,28 +389,26 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L, if(parsup>ParMax) parsup=ParMax; if(parinf>(parsup-1e-9)) return; IntCurveSurface_ThePolygonOfHInter polygon(HLL, - parinf, - parsup, - 2); + parinf, + parsup, + 2); #if OPTIMISATION - if(PtrOnBndBounding==NULL) { - PtrOnBndBounding = (Bnd_BoundSortBox *) new Bnd_BoundSortBox(); - IntCurveSurface_ThePolyhedronOfHInter *thePolyh= - (IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; - ((Bnd_BoundSortBox *)(PtrOnBndBounding))-> - Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh), - IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh)); + if(!myBndBounding) + { + myBndBounding.reset(new Bnd_BoundSortBox()); + myBndBounding->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*myPolyhedron), + IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*myPolyhedron)); } HICS.Perform(HLL, - polygon, - Hsurface, - *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron), - *((Bnd_BoundSortBox *)PtrOnBndBounding)); + polygon, + Hsurface, + *myPolyhedron, + *myBndBounding); #else HICS.Perform(HLL, - polygon, - Hsurface, - *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)); + polygon, + Hsurface, + *myPolyhedron); #endif } @@ -423,8 +419,8 @@ void IntCurvesFace_Intersector::Perform(const gp_Lin& L, //purpose : //======================================================================= void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_Curve)& HCu, - const Standard_Real ParMin, - const Standard_Real ParMax) + const Standard_Real ParMin, + const Standard_Real ParMax) { done = Standard_False; if (!myReady) @@ -443,10 +439,12 @@ void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_Curve)& HCu, Standard_Real parinf=ParMin; Standard_Real parsup=ParMax; - if(PtrOnPolyhedron == NULL) { + if(!myPolyhedron) + { HICS.Perform(HCu,Hsurface); } - else { + else + { parinf = IntCurveSurface_TheHCurveTool::FirstParameter(HCu); parsup = IntCurveSurface_TheHCurveTool::LastParameter(HCu); if(parinfInitialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*thePolyh), - IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*thePolyh)); + if(!myBndBounding) { + myBndBounding.reset(new Bnd_BoundSortBox()); + myBndBounding->Initialize(IntCurveSurface_ThePolyhedronToolOfHInter::Bounding(*myPolyhedron), + IntCurveSurface_ThePolyhedronToolOfHInter::ComponentsBounding(*myPolyhedron)); } HICS.Perform(HCu, - polygon, - Hsurface, - *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron), - *((Bnd_BoundSortBox *)PtrOnBndBounding)); + polygon, + Hsurface, + *myPolyhedron, + *myBndBounding); #else HICS.Perform(HCu, - polygon, - Hsurface, - *((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)); + polygon, + Hsurface, + *myPolyhedron); #endif } InternalCall(HICS,parinf,parsup); @@ -483,37 +480,33 @@ void IntCurvesFace_Intersector::Perform(const Handle(Adaptor3d_Curve)& HCu, //============================================================================ Bnd_Box IntCurvesFace_Intersector::Bounding() const { - if(PtrOnPolyhedron !=NULL) { - return(((IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron)->Bounding()); + if(myPolyhedron) + { + return myPolyhedron->Bounding(); } - else { + else + { 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); - return(state); -} -//============================================================================ -void IntCurvesFace_Intersector::Destroy() { - if(PtrOnPolyhedron !=NULL) { - delete (IntCurveSurface_ThePolyhedronOfHInter *)PtrOnPolyhedron; - PtrOnPolyhedron = NULL; - } - if(PtrOnBndBounding !=NULL) { - delete (Bnd_BoundSortBox *)PtrOnBndBounding; - PtrOnBndBounding=NULL; - } + return state; } - void IntCurvesFace_Intersector::SetUseBoundToler(Standard_Boolean UseBToler) - { - myUseBoundTol = UseBToler; - } +void IntCurvesFace_Intersector::SetUseBoundToler(Standard_Boolean UseBToler) +{ + myUseBoundTol = UseBToler; +} - Standard_Boolean IntCurvesFace_Intersector::GetUseBoundToler() const - { - return myUseBoundTol; - } +Standard_Boolean IntCurvesFace_Intersector::GetUseBoundToler() const +{ + return myUseBoundTol; +} +IntCurvesFace_Intersector::~IntCurvesFace_Intersector() +{ +} diff --git a/src/IntCurvesFace/IntCurvesFace_Intersector.hxx b/src/IntCurvesFace/IntCurvesFace_Intersector.hxx index c1af3ff4ea..b7ec31eeb3 100644 --- a/src/IntCurvesFace/IntCurvesFace_Intersector.hxx +++ b/src/IntCurvesFace/IntCurvesFace_Intersector.hxx @@ -18,14 +18,18 @@ #define _IntCurvesFace_Intersector_HeaderFile #include +#include #include #include +#include #include #include #include #include #include +#include + class BRepTopAdaptor_TopolTool; class gp_Lin; class gp_Pnt; @@ -33,8 +37,13 @@ class IntCurveSurface_HInter; class gp_Pnt2d; 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: DEFINE_STANDARD_ALLOC @@ -123,14 +132,7 @@ public: //! Returns the boundary tolerance flag Standard_EXPORT Standard_Boolean GetUseBoundToler() const; - Standard_EXPORT void Destroy(); -~IntCurvesFace_Intersector() -{ - Destroy(); -} - - - + Standard_EXPORT virtual ~IntCurvesFace_Intersector(); protected: @@ -153,8 +155,8 @@ private: Standard_Boolean myReady; Standard_Integer nbpnt; TopoDS_Face face; - Standard_Address PtrOnPolyhedron; - Standard_Address PtrOnBndBounding; + std::unique_ptr myPolyhedron; + std::unique_ptr myBndBounding; Standard_Boolean myUseBoundTol; Standard_Boolean myIsParallel; //Curve is "parallel" face surface //This case is recognized only for some pairs diff --git a/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.cxx b/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.cxx index d99f3fd3ce..ea40cebe30 100644 --- a/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.cxx +++ b/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.cxx @@ -30,202 +30,186 @@ #include #include -//-- ================================================================================ -IntCurvesFace_ShapeIntersector::IntCurvesFace_ShapeIntersector() { - nbfaces=0; - done=Standard_False; - PtrJetons=NULL; - PtrJetonsIndex=NULL; + +IntCurvesFace_ShapeIntersector::IntCurvesFace_ShapeIntersector() +: myIsDone(Standard_False), + myNbFaces(0) +{ } -//-- ================================================================================ -void IntCurvesFace_ShapeIntersector::Load(const TopoDS_Shape& shape, - const Standard_Real tol) { - PtrJetons=NULL; - PtrJetonsIndex=NULL; - if(nbfaces) { - Destroy(); - } + +void IntCurvesFace_ShapeIntersector::Load(const TopoDS_Shape& theShape, + const Standard_Real theTol) +{ TopExp_Explorer Ex; Standard_Integer i; - for(nbfaces=0,i=0,Ex.Init(shape,TopAbs_FACE); Ex.More(); i++,Ex.Next()) { - nbfaces++; - TopoDS_Face currentface = TopoDS::Face(Ex.Current()); - PtrIntersector.Append((void *)(new IntCurvesFace_Intersector(currentface,tol))); - } + for(myNbFaces = 0, i = 0, Ex.Init(theShape, TopAbs_FACE); Ex.More(); ++i, Ex.Next()) + { + ++myNbFaces; + TopoDS_Face aCurrentFace = TopoDS::Face(Ex.Current()); + myIntersector.Append(new IntCurvesFace_Intersector(aCurrentFace, theTol)); + } } -//-- ================================================================================ -void IntCurvesFace_ShapeIntersector::Destroy() { - if(PtrJetons) { - delete ((Standard_Integer *)PtrJetons); - PtrJetons=NULL; - } - if(PtrJetonsIndex) { - delete ((Standard_Integer *)PtrJetonsIndex); - PtrJetonsIndex=NULL; - } - 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); + +void IntCurvesFace_ShapeIntersector::Perform(const gp_Lin& theL, + const Standard_Real theParMin, + const Standard_Real theParMax) +{ + myIsDone = Standard_False; + for(Standard_Integer i = 1; i <= myNbFaces; ++i) + { + myIntersector.ChangeValue(i)->Perform(theL, theParMin, theParMax); } SortResult(); } -//-- ================================================================================ -void IntCurvesFace_ShapeIntersector::PerformNearest(const gp_Lin& L, - const Standard_Real ParMin, - const Standard_Real _ParMax) { - Standard_Integer i; - Standard_Integer* _PtrJetons=(Standard_Integer *)PtrJetons; - Standard_Integer* _PtrJetonsIndex=(Standard_Integer *)PtrJetonsIndex; - - - if(nbfaces>2) { - if(PtrJetons==NULL) { - PtrJetons = (void *) new Standard_Integer [nbfaces]; - PtrJetonsIndex = (void *) new Standard_Integer [nbfaces]; - Standard_Integer *Ptr =(Standard_Integer *)PtrJetons; - Standard_Integer *PtrI=(Standard_Integer *)PtrJetonsIndex; - for(i=0;iPerform(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 2) + { + if (myPtrNums.IsEmpty()) + { + myPtrNums = TColStd_HArray1OfInteger(0, myNbFaces - 1); + myPtrIndexNums = TColStd_HArray1OfInteger(0, myNbFaces - 1); + for(; i < myNbFaces; ++i) + { + myPtrNums.ChangeValue(i) = 0; + myPtrIndexNums.ChangeValue(i) = i + 1; } } } - if(PtrJetons && Indexface>=0) { - _PtrJetons[Indexface]++; - + + 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; + } + } + } + if (!myPtrNums.IsEmpty() && anIndexFace >= 0) + { + myPtrNums.ChangeValue(anIndexFace) += 1; Standard_Integer im1; - for(im1=Indexface-1,i=Indexface; i>=1 && _PtrJetons[i]>_PtrJetons[i-1]; i--,im1--) { - Standard_Integer t=_PtrJetonsIndex[i]; - _PtrJetonsIndex[i]=_PtrJetonsIndex[im1]; - _PtrJetonsIndex[im1]=t; - t=_PtrJetons[i]; - _PtrJetons[i]=_PtrJetons[im1]; - _PtrJetons[im1]=t; + for (im1 = anIndexFace - 1, i = anIndexFace; i >= 1 && myPtrNums.Value(i) > myPtrNums.Value(im1); --i, --im1) + { + std::swap(myPtrIndexNums.ChangeValue(i), myPtrIndexNums.ChangeValue(im1)); + std::swap(myPtrNums.ChangeValue(i), myPtrNums.ChangeValue(im1)); } - //--for(Standard_Integer dd=0; dd",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(); } //-- ================================================================================ -void IntCurvesFace_ShapeIntersector::Perform(const Handle(Adaptor3d_Curve)& HCu, - 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(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) +//-- myIntersector : Sequence of the addresses +//-- myIndexPt : 1 2 3 .... n Points before the sorting +//-- myNumberFace : Number of the face (of the intersector) of the point myIndexPt(i) +//-- myNumberIntPnt : Number of the point myIndexPt(i) of the intersection myNumberFace(myIndexPt(i)) +//-- myIndexPar : Parameter W of point myIndexPt(i) //-- -//-- En resume, pour chaque point indice par K = IndexPt(i) on a -//-- * la face a laquelle il appartient : IndexFace(K) -//-- * le numero du point dans l'intersecteur FaceCurve : IndexIntPnt(K) -//-- * le parametre W du point sur la courbe : IndexPar(K) +//-- To sum up, for each point index of K = myIndexPt(i) on a +//-- * the face to which it belongs : myNumberFace(K) +//-- * the number of the point in the intersection for FaceCurve : myNumberIntPnt(K) +//-- * the parameter W of the point on the curve : myIndexPar(K) //-- -//-- SortResult Trie les points par ordre croissant de W -//-- (remet a jour le tableau d index TabPt(.)) +//-- SortResult Sorts the points in ascending order of W +//-- (updating the index table TabPt(.)) //-- //-- ================================================================================ -void IntCurvesFace_ShapeIntersector::SortResult() { - done = Standard_True; - Standard_Integer nbpnt=0; - IndexPt.Clear(); IndexFace.Clear(); IndexIntPnt.Clear();IndexPar.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 - //-- - for(Standard_Integer f=1; f<=nbfaces; f++) { - IntCurvesFace_Intersector *Ptr = (IntCurvesFace_Intersector *)PtrIntersector.ChangeValue(f); - if(Ptr->IsDone()) { - Standard_Integer n=Ptr->NbPnt(); - for(Standard_Integer j=1;j<=n;j++) { - IndexPt.Append(++nbpnt); - IndexFace.Append(f); - IndexIntPnt.Append(j); - IndexPar.Append(Ptr->WParameter(j)); +void IntCurvesFace_ShapeIntersector::SortResult() +{ + myIsDone = Standard_True; + Standard_Integer aNbPnt=0; + myIndexPt.Clear(); + myIndexFace.Clear(); + myIndexIntPnt.Clear(); + myIndexPar.Clear(); + + //Retrieval of the results + for(Standard_Integer f = 1; f <= myNbFaces; ++f) + { + Handle(IntCurvesFace_Intersector) anIntersector = myIntersector.ChangeValue(f); + if(anIntersector->IsDone()) + { + 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 { - done = Standard_False; + else + { + myIsDone = Standard_False; return; } } - //-- ----------------------------------------------------- - //-- t r i s e l o n l e p a r a m e t r e w - //-- - Standard_Boolean triok; - do { - triok=Standard_True; - for(Standard_Integer ind0=1;ind0 IndexPar(indp1)) { - IndexPt(ind0) =indp1; - IndexPt(ind0+1)=ind; - triok=Standard_False; + + //Sort according to parameter w + Standard_Boolean isOK; + do + { + isOK = Standard_True; + for(Standard_Integer ind0 = 1; ind0 < aNbPnt; ind0++) + { + Standard_Integer ind = myIndexPt(ind0); + Standard_Integer indp1 = myIndexPt(ind0 + 1); + if(myIndexPar(ind) > myIndexPar(indp1)) + { + 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 -//-- diff --git a/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.hxx b/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.hxx index 5f5e11fe25..1009b94a00 100644 --- a/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.hxx +++ b/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.hxx @@ -23,12 +23,12 @@ #include #include -#include -#include +#include #include #include #include #include +#include #include class Adaptor3d_Curve; @@ -52,7 +52,7 @@ public: //! segment L and the loaded shape. //! //! 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 //! +/- RealLast. @@ -62,92 +62,102 @@ public: //! segment L and the loaded shape. //! //! 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 //! +/- RealLast. Standard_EXPORT void PerformNearest (const gp_Lin& L, const Standard_Real PInf, const Standard_Real PSup); //! 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); - //! True is returned when the intersection have been computed. - Standard_Boolean IsDone() const; - - Standard_Integer NbPnt() const; + //! True when the intersection has been computed. + Standard_Boolean IsDone() 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 //! 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 //! 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 //! 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 //! 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. - 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. //! The values can be either TopAbs_IN //! ( the point is in the face) //! or TopAbs_ON //! ( 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 //! 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 //! parameter. Standard_EXPORT void SortResult(); - Standard_EXPORT void Destroy(); -~IntCurvesFace_ShapeIntersector() -{ - Destroy(); -} - - - - -protected: - - - - + Standard_EXPORT virtual ~IntCurvesFace_ShapeIntersector(); private: - - - - Standard_Boolean done; - Standard_Integer nbfaces; - Standard_Address PtrJetons; - Standard_Address PtrJetonsIndex; - BRepTopAdaptor_SeqOfPtr PtrIntersector; - TColStd_SequenceOfInteger IndexPt; - TColStd_SequenceOfInteger IndexFace; - TColStd_SequenceOfInteger IndexIntPnt; - TColStd_SequenceOfReal IndexPar; - - + + Standard_Boolean myIsDone; + Standard_Integer myNbFaces; + TColStd_Array1OfInteger myPtrNums; + TColStd_Array1OfInteger myPtrIndexNums; + NCollection_Sequence myIntersector; + TColStd_SequenceOfInteger myIndexPt; + TColStd_SequenceOfInteger myIndexFace; + TColStd_SequenceOfInteger myIndexIntPnt; + TColStd_SequenceOfReal myIndexPar; }; - -#include - - - - - #endif // _IntCurvesFace_ShapeIntersector_HeaderFile diff --git a/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.lxx b/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.lxx deleted file mode 100644 index 66e5db930a..0000000000 --- a/src/IntCurvesFace/IntCurvesFace_ShapeIntersector.lxx +++ /dev/null @@ -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 - - -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); -} - -