1 // Created on: 1994-03-10
2 // Created by: Laurent BUCHARD
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
8 // This library is free software; you can redistribute it and/or modify it under
9 // the terms of the GNU Lesser General Public License version 2.1 as published
10 // by the Free Software Foundation, with special exception defined in the file
11 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
12 // distribution for complete text of the license and disclaimer of any warranty.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified: Porting NT 7-5-97 DPF (stdio.h)
18 // Apr 16 2002 eap, classification against infinite solid (occ299)
21 // Modified by skv - Thu Sep 4 12:29:30 2003 OCC578
23 //-- Process the case of a hole!!
28 #include <BRep_Tool.hxx>
29 #include <BRepAdaptor_Curve2d.hxx>
30 #include <BRepBndLib.hxx>
31 #include <BRepClass3d_SolidExplorer.hxx>
32 #include <BRepClass_FaceClassifier.hxx>
33 #include <BRepClass_FacePassiveClassifier.hxx>
34 #include <BRepTools.hxx>
35 #include <BRepTopAdaptor_FClass2d.hxx>
36 #include <Extrema_ExtPS.hxx>
41 #include <gp_Vec2d.hxx>
42 #include <IntCurvesFace_Intersector.hxx>
43 #include <Precision.hxx>
44 #include <TopAbs_Orientation.hxx>
45 #include <TopExp_Explorer.hxx>
47 #include <TopoDS_Face.hxx>
48 #include <TopoDS_Shape.hxx>
49 #include <TopoDS_Shell.hxx>
55 //=======================================================================
56 //function : FindAPointInTheFace
57 //purpose : Compute a point P in the face F. Param is a Real in
58 // ]0,1[ and is used to initialise the algorithm. For
59 // different values , different points are returned.
60 //=======================================================================
61 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
62 (const TopoDS_Face& _face,
64 Standard_Real& param_)
67 Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u,v,param_);
71 //=======================================================================
72 //function : FindAPointInTheFace
74 //=======================================================================
76 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
77 (const TopoDS_Face& _face,
79 Standard_Real& u_, Standard_Real& v_,
80 Standard_Real& param_)
82 gp_Vec aVecD1U, aVecD1V;
83 return FindAPointInTheFace (_face, APoint_, u_, v_, param_, aVecD1U, aVecD1V);
86 //=======================================================================
87 //function : FindAPointInTheFace
89 //=======================================================================
91 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
92 (const TopoDS_Face& _face,
94 Standard_Real& u_, Standard_Real& v_,
95 Standard_Real& param_,
99 TopoDS_Face face = _face;
100 face.Orientation (TopAbs_FORWARD);
102 TopExp_Explorer faceexplorer;
103 BRepAdaptor_Curve2d c;
107 for (faceexplorer.Init(face,TopAbs_EDGE);
111 TopoDS_Edge Edge = TopoDS::Edge (faceexplorer.Current());
112 c.Initialize (Edge, face);
113 c.D1((c.LastParameter() - c.FirstParameter()) * param_ + c.FirstParameter(),P,T);
115 Standard_Real x = T.X();
116 Standard_Real y = T.Y();
117 if (Edge.Orientation() == TopAbs_FORWARD)
125 Standard_Real ParamInit = Precision::Infinite();
126 Standard_Real TolInit = 0.00001;
127 Standard_Boolean APointExist = Standard_False;
129 BRepClass_FacePassiveClassifier FClassifier;
132 P.SetCoord (P.X() + TolInit * T.X(), P.Y() + TolInit * T.Y());
133 FClassifier.Reset (gp_Lin2d (P, T), ParamInit, RealEpsilon()); //-- Length and Tolerance #######
135 TopExp_Explorer otherfaceexplorer;
136 Standard_Integer aNbEdges = 0;
137 for (otherfaceexplorer.Init (face, TopAbs_EDGE);
138 otherfaceexplorer.More();
139 otherfaceexplorer.Next(), ++aNbEdges)
141 TopoDS_Edge OtherEdge = TopoDS::Edge (otherfaceexplorer.Current());
142 if (OtherEdge.Orientation() != TopAbs_EXTERNAL && OtherEdge != Edge)
144 BRepClass_Edge AEdge (OtherEdge, face);
145 FClassifier.Compare (AEdge, OtherEdge.Orientation());
146 if (FClassifier.ClosestIntersection())
148 if(ParamInit > FClassifier.Parameter())
150 ParamInit = FClassifier.Parameter();
151 APointExist = Standard_True;
159 BRepClass_Edge AEdge (Edge, face);
160 FClassifier.Compare (AEdge, Edge.Orientation());
161 if (FClassifier.ClosestIntersection())
163 if (ParamInit > FClassifier.Parameter())
165 ParamInit = FClassifier.Parameter();
166 APointExist = Standard_True;
173 ParamInit *= 0.41234;
174 u_ = P.X() + ParamInit* T.X();
175 v_ = P.Y() + ParamInit* T.Y();
178 BRepTopAdaptor_FClass2d Classifier(face, Precision::Confusion());
179 gp_Pnt2d aPnt2d(u_, v_);
180 TopAbs_State StateOfResultingPoint = Classifier.Perform(aPnt2d);
181 if (StateOfResultingPoint != TopAbs_IN)
182 return Standard_False;
184 BRepAdaptor_Surface s;
185 s.Initialize (face, Standard_False);
186 s.D1 (u_, v_, APoint_, theVecD1U, theVecD1V);
188 if(theVecD1U.CrossMagnitude(theVecD1V) > gp::Resolution())
189 return Standard_True;
191 if(ParamInit < Precision::PConfusion())
192 return Standard_False;
195 return Standard_False;
198 //=======================================================================
199 //function : PointInTheFace
201 //=======================================================================
203 Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
204 (const TopoDS_Face& Face,
206 Standard_Real& u_, Standard_Real& v_,
207 Standard_Real& param_,
208 Standard_Integer& IndexPoint,
209 const Handle(BRepAdaptor_Surface)& surf,
210 const Standard_Real U1,
211 const Standard_Real V1,
212 const Standard_Real U2,
213 const Standard_Real V2) const
215 gp_Vec aVecD1U, aVecD1V;
216 return PointInTheFace (Face, APoint_, u_, v_, param_, IndexPoint, surf,
217 U1, V1, U2, V2, aVecD1U, aVecD1V);
220 //=======================================================================
221 //function : ClassifyUVPoint
223 //=======================================================================
225 TopAbs_State BRepClass3d_SolidExplorer::ClassifyUVPoint
226 (const IntCurvesFace_Intersector& theIntersector,
227 const Handle(BRepAdaptor_Surface)& theSurf,
228 const gp_Pnt2d& theP2d) const
230 // first find if the point is near an edge/vertex
231 gp_Pnt aP3d = theSurf->Value(theP2d.X(), theP2d.Y());
232 BRepClass3d_BndBoxTreeSelectorPoint aSelectorPoint(myMapEV);
233 aSelectorPoint.SetCurrentPoint(aP3d);
234 Standard_Integer aSelsVE = myTree.Select(aSelectorPoint);
237 // The point is inside the tolerance area of vertices/edges => return ON state.
240 return theIntersector.ClassifyUVPoint(theP2d);
243 //=======================================================================
244 //function : PointInTheFace
246 //=======================================================================
248 Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
249 (const TopoDS_Face& Face,
251 Standard_Real& u_, Standard_Real& v_,
252 Standard_Real& param_,
253 Standard_Integer& IndexPoint,
254 const Handle(BRepAdaptor_Surface)& surf,
255 const Standard_Real U1,
256 const Standard_Real V1,
257 const Standard_Real U2,
258 const Standard_Real V2,
260 gp_Vec& theVecD1V) const
262 Standard_Real u,du = (U2-U1)/6.0;
263 Standard_Real v,dv = (V2-V1)/6.0;
264 if(du<1e-12) du=1e-12;
265 if(dv<1e-12) dv=1e-12;
266 Standard_Boolean IsNotUper = !surf->IsUPeriodic(), IsNotVper = !surf->IsVPeriodic();
267 Standard_Integer NbPntCalc=0;
268 if(myMapOfInter.IsBound(Face)) {
269 void *ptr = (void*)(myMapOfInter.Find(Face));
270 Standard_Boolean IsInside = Standard_True;
273 IsInside = (u_ >= U1) && (u_ <= U2);
277 IsInside &= (v_ >= V1) && (v_ <= V2);
280 const IntCurvesFace_Intersector& TheIntersector = (*((IntCurvesFace_Intersector *)ptr));
281 // Check if the point is already in the face
282 if (IsInside && (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u_, v_)) == TopAbs_IN)) {
284 surf->D1(u_, v_, aPnt, theVecD1U, theVecD1V);
285 if (aPnt.SquareDistance(APoint_) < Precision::Confusion() * Precision::Confusion())
286 return Standard_True;
289 //-- Take 4 points in each Quarter of surface
290 //-- -> Index : 1 -> 16
293 //-- Then take a matrix of points on a tight grid
295 for(u=du+(U1+U2)*0.5; u<U2; u+=du) { //-- 0 X u increases
296 for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) { //-- 0 0 v increases
297 if(++NbPntCalc>=IndexPoint) {
298 if (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u, v)) == TopAbs_IN) {
300 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
301 IndexPoint = NbPntCalc;
302 return(Standard_True);
308 for(u=-du+(U1+U2)*0.5; u>U1; u-=du) { //-- 0 0 u decreases
309 for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) { //-- X 0 v decreases
310 if(++NbPntCalc>=IndexPoint) {
311 if (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u, v)) == TopAbs_IN) {
313 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
314 IndexPoint = NbPntCalc;
315 return(Standard_True);
320 for(u=-du+(U1+U2)*0.5; u>U1; u-=du) { //-- X 0 u decreases
321 for(v=dv+(V1+V2)*0.5; v<V2; v+=dv) { //-- 0 0 v increases
322 if(++NbPntCalc>=IndexPoint) {
323 if (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u, v)) == TopAbs_IN) {
325 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
326 IndexPoint = NbPntCalc;
327 return(Standard_True);
332 for(u=du+(U1+U2)*0.5; u<U2; u+=du) { //-- 0 0 u increases
333 for(v=-dv+(V1+V2)*0.5; v>V1; v-=dv) { //-- 0 X v decreases
334 if(++NbPntCalc>=IndexPoint) {
335 if (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u, v)) == TopAbs_IN) {
337 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
338 IndexPoint = NbPntCalc;
339 return(Standard_True);
347 if(du<1e-12) du=1e-12;
348 if(dv<1e-12) dv=1e-12;
350 for(u=du+U1; u<U2; u+=du) {
351 for(v=dv+V1; v<V2; v+=dv) {
352 if(++NbPntCalc>=IndexPoint) {
353 if (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u, v)) == TopAbs_IN) {
355 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
356 IndexPoint = NbPntCalc;
357 return(Standard_True);
364 if(++NbPntCalc>=IndexPoint) {
365 if (ClassifyUVPoint(TheIntersector, surf, gp_Pnt2d(u, v)) == TopAbs_IN) {
367 surf->D1 (u, v, APoint_, theVecD1U, theVecD1V);
368 IndexPoint = NbPntCalc;
369 return(Standard_True);
373 IndexPoint = NbPntCalc;
376 //printf("BRepClass3d_SolidExplorer Face not found ds the map \n");
379 return BRepClass3d_SolidExplorer
380 ::FindAPointInTheFace (Face,APoint_, u_, v_, param_, theVecD1U, theVecD1V);
383 //=======================================================================
384 //function : LimitInfiniteUV
385 //purpose : Limit infinite parameters
386 //=======================================================================
387 static void LimitInfiniteUV (Standard_Real& U1,
393 infU1 = Precision::IsNegativeInfinite(U1),
394 infV1 = Precision::IsNegativeInfinite(V1),
395 infU2 = Precision::IsPositiveInfinite(U2),
396 infV2 = Precision::IsPositiveInfinite(V2);
398 if (infU1) U1 = -1e10;
399 if (infV1) V1 = -1e10;
400 if (infU2) U2 = 1e10;
401 if (infV2) V2 = 1e10;
403 //=======================================================================
404 //function : IsInfiniteUV
406 //=======================================================================
407 static Standard_Integer IsInfiniteUV (Standard_Real& U1,
412 Standard_Integer aVal = 0;
414 if (Precision::IsInfinite(U1))
417 if (Precision::IsInfinite(V1))
420 if (Precision::IsInfinite(U2))
423 if (Precision::IsInfinite(V2))
429 // Modified by skv - Tue Sep 16 13:50:39 2003 OCC578 End
430 //=======================================================================
431 //function : OtherSegment
432 //purpose : Returns in <L>, <Par> a segment having at least
433 // one intersection with the shape boundary to
434 // compute intersections.
435 // The First Call to this method returns a line which
436 // point to a point of the first face of the shape.
437 // The Second Call provide a line to the second face
439 //=======================================================================
440 Standard_Integer BRepClass3d_SolidExplorer::OtherSegment(const gp_Pnt& P,
444 const Standard_Real TolU = Precision::PConfusion();
445 const Standard_Real TolV = TolU;
448 TopExp_Explorer faceexplorer;
450 gp_Vec aVecD1U, aVecD1V;
451 Standard_Real maxscal=0;
452 Standard_Boolean ptfound=Standard_False;
455 Standard_Integer IndexPoint=0;
456 Standard_Integer NbPointsOK=0;
457 Standard_Integer NbFacesInSolid=0;
458 Standard_Boolean aRestr = Standard_True;
459 Standard_Boolean aTestInvert = Standard_False;
463 faceexplorer.Init(myShape,TopAbs_FACE);
464 // look for point on face starting from myFirstFace
465 // Modified by skv - Thu Sep 4 14:31:12 2003 OCC578 Begin
466 // while (faceexplorer.More()) {
468 for (; faceexplorer.More(); faceexplorer.Next()) {
469 // Modified by skv - Thu Sep 4 14:31:12 2003 OCC578 End
471 if (myFirstFace > NbFacesInSolid) continue;
472 face = TopoDS::Face(faceexplorer.Current());
474 Handle(BRepAdaptor_Surface) surf = new BRepAdaptor_Surface();
477 BRepTopAdaptor_FClass2d aClass(face, Precision::Confusion());
478 if(aClass.PerformInfinitePoint() == TopAbs_IN)
480 aRestr = Standard_False;
481 if(myMapOfInter.IsBound(face))
483 myMapOfInter.UnBind(face);
484 void *ptr = (void *)(new IntCurvesFace_Intersector(face, Precision::Confusion(),
485 aRestr, Standard_False));
486 myMapOfInter.Bind(face,ptr);
491 aRestr = Standard_True;
494 surf->Initialize(face, aRestr);
495 Standard_Real U1,V1,U2,V2;
496 U1 = surf->FirstUParameter();
497 V1 = surf->FirstVParameter();
498 U2 = surf->LastUParameter();
499 V2 = surf->LastVParameter();
500 face.Orientation(TopAbs_FORWARD);
502 //avoid process faces from uncorrected shells
503 const Standard_Real eps = Precision::PConfusion();
504 Standard_Real epsU = Max(eps * Max(Abs(U2), Abs(U1)), eps);
505 Standard_Real epsV = Max(eps * Max(Abs(V2), Abs(V1)), eps);
506 if( Abs (U2 - U1) < epsU || Abs(V2 - V1) < epsV) {
510 Standard_Real svmyparam=myParamOnEdge;
512 // Check if the point is on the face or the face is infinite.
513 Standard_Integer anInfFlag = IsInfiniteUV(U1,V1,U2,V2);
515 _u = (U1 + U2) * 0.5;
516 _v = (V1 + V2) * 0.5;
518 GeomAdaptor_Surface GA(BRep_Tool::Surface(face));
519 Extrema_ExtPS Ext(P, GA, TolU, TolV);
521 if (Ext.IsDone() && Ext.NbExt() > 0) {
522 Standard_Integer i, iNear, iEnd;
523 Standard_Real aUx, aVx, Dist2, Dist2Min;
527 Dist2Min = Ext.SquareDistance(1);
529 for (i = 2; i <= iEnd; i++) {
531 aPx.Parameter(aUx, aVx);
532 if (aUx>=U1 && aUx<=U2 && aVx>=V1 && aVx<=V2) {
533 Dist2 = Ext.SquareDistance(i);
534 if (Dist2 < Dist2Min) {
541 Standard_Real aDist2Tresh=1.e-24;
543 if (Dist2Min<aDist2Tresh) {
548 BRepClass_FaceClassifier classifier2d;
552 (Ext.Point(iNear)).Parameter(aU, aV);
554 gp_Pnt2d aPuv(aU, aV);
556 classifier2d.Perform(face,aPuv,Precision::PConfusion());
558 TopAbs_State aState = classifier2d.State();
560 if (aState == TopAbs_IN || aState == TopAbs_ON) {
564 return 3; // skv - the point is on surface but outside face.
569 APoint = (Ext.Point(iNear)).Value();
571 _Par = V.Magnitude();
573 ptfound=Standard_True;
577 // set the parameters found by extrema
578 aPx = Ext.Point(iNear);
579 aPx.Parameter(_u, _v);
580 APoint = aPx.Value();
582 //The point is not ON the face or surface. The face is restricted.
583 // find point in a face not too far from a projection of P on face
585 if (PointInTheFace (face, APoint, _u, _v, myParamOnEdge, ++IndexPoint, surf,
590 gp_Vec V (P, APoint);
592 if (Par > gp::Resolution() &&
593 aVecD1U.Magnitude() > gp::Resolution() &&
594 aVecD1V.Magnitude() > gp::Resolution())
596 gp_Vec Norm = aVecD1U.Crossed (aVecD1V);
597 Standard_Real tt = Norm.Magnitude();
598 if (tt > gp::Resolution())
600 tt = Abs (Norm.Dot (V)) / (tt * Par);
606 ptfound = Standard_True;
609 myParamOnEdge=svmyparam;
617 while(IndexPoint<200 && NbPointsOK<16);
619 myParamOnEdge=svmyparam;
625 // Modified by skv - Thu Sep 4 14:32:14 2003 OCC578 Begin
626 // Next is done in the main for(..) loop.
627 // faceexplorer.Next();
628 // Modified by skv - Thu Sep 4 14:32:14 2003 OCC578 End
631 Standard_Boolean encoreuneface = faceexplorer.More();
632 if(ptfound==Standard_False && encoreuneface==Standard_False) {
633 if(myParamOnEdge < 0.0001) {
634 //-- This case takes place when the point is on the solid
635 //-- and this solid is reduced to a face
636 gp_Pnt PBidon(P.X()+1.0,P.Y(),P.Z());
644 } //-- Exploration of the faces
646 if(NbFacesInSolid==0) {
648 myReject=Standard_True;
650 std::cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx (Solid without face)"<<std::endl;
659 if(myParamOnEdge==0.512345) myParamOnEdge = 0.4;
660 else if(myParamOnEdge==0.4) myParamOnEdge = 0.6;
661 else if(myParamOnEdge==0.6) myParamOnEdge = 0.3;
662 else if(myParamOnEdge==0.3) myParamOnEdge = 0.7;
663 else if(myParamOnEdge==0.7) myParamOnEdge = 0.2;
664 else if(myParamOnEdge==0.2) myParamOnEdge = 0.8;
665 else if(myParamOnEdge==0.8) myParamOnEdge = 0.1;
666 else if(myParamOnEdge==0.1) myParamOnEdge = 0.9;
670 if(myParamOnEdge < 0.0001) {
671 gp_Pnt PBidon(P.X()+1.0,P.Y(),P.Z());
679 aTestInvert = Standard_True;
680 } //-- for(;;) { ... }
683 // Modified by skv - Thu Sep 4 12:30:14 2003 OCC578 Begin
684 //=======================================================================
685 //function : GetFaceSegmentIndex
686 //purpose : Returns the index of face for which last segment is calculated.
687 //=======================================================================
689 Standard_Integer BRepClass3d_SolidExplorer::GetFaceSegmentIndex() const
693 // Modified by skv - Thu Sep 4 12:30:14 2003 OCC578 End
695 //=======================================================================
696 //function : PointInTheFace
698 //=======================================================================
700 Standard_Boolean BRepClass3d_SolidExplorer::PointInTheFace
701 (const TopoDS_Face& _face,
703 Standard_Real& u_, Standard_Real& v_,
704 Standard_Real& param_,
705 Standard_Integer& IndexPoint) const
707 TopoDS_Face Face = _face;
708 Face.Orientation(TopAbs_FORWARD);
709 Handle(BRepAdaptor_Surface) surf = new BRepAdaptor_Surface();
710 surf->Initialize(Face);
711 Standard_Real U1,V1,U2,V2;//,u,v;
712 U1 = surf->FirstUParameter();
713 V1 = surf->FirstVParameter();
714 U2 = surf->LastUParameter();
715 V2 = surf->LastVParameter();
716 LimitInfiniteUV (U1,V1,U2,V2);
717 return(PointInTheFace(Face,APoint_,u_,v_,param_,IndexPoint,surf,U1,V1,U2,V2));
720 //=======================================================================
721 //function : FindAPointInTheFace
723 //=======================================================================
725 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
726 (const TopoDS_Face& _face,
728 Standard_Real& u_,Standard_Real& v_)
730 Standard_Real param = 0.1;
731 Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u_,v_,param);
735 //=======================================================================
736 //function : FindAPointInTheFace
738 //=======================================================================
740 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
741 (const TopoDS_Face& _face,
744 Standard_Boolean r = FindAPointInTheFace(_face,APoint_,u,v);
748 //=======================================================================
749 //function : FindAPointInTheFace
751 //=======================================================================
753 Standard_Boolean BRepClass3d_SolidExplorer::FindAPointInTheFace
754 (const TopoDS_Face& _face,
755 Standard_Real& u_,Standard_Real& v_)
757 Standard_Boolean r = FindAPointInTheFace(_face,APoint,u_,v_);
761 //=======================================================================
762 //function : BRepClass3d_SolidExplorer
764 //=======================================================================
766 BRepClass3d_SolidExplorer::BRepClass3d_SolidExplorer()
767 : myReject(Standard_True),
773 //=======================================================================
774 //function : BRepClass3d_SolidExplorer
776 //=======================================================================
778 BRepClass3d_SolidExplorer::BRepClass3d_SolidExplorer(const TopoDS_Shape& S)
783 //=======================================================================
784 //function : ~BRepClass3d_SolidExplorer
786 //=======================================================================
788 BRepClass3d_SolidExplorer::~BRepClass3d_SolidExplorer()
793 //=======================================================================
795 //purpose : C++: alias ~
796 //=======================================================================
798 void BRepClass3d_SolidExplorer::Destroy() {
799 BRepClass3d_DataMapIteratorOfMapOfInter iter(myMapOfInter);
800 for(;iter.More();iter.Next()) {
801 void *ptr=iter.Value();
803 delete (IntCurvesFace_Intersector *)ptr;
804 myMapOfInter.ChangeFind(iter.Key()) = NULL;
807 myMapOfInter.Clear();
810 //=======================================================================
811 //function : InitShape
813 //=======================================================================
815 void BRepClass3d_SolidExplorer::InitShape(const TopoDS_Shape& S)
822 myParamOnEdge = 0.512345;
823 //-- Exploring of the Map and removal of allocated objects
826 BRepClass3d_DataMapIteratorOfMapOfInter iter(myMapOfInter);
827 for(;iter.More();iter.Next()) {
828 void *ptr=iter.Value();
830 delete (IntCurvesFace_Intersector *)ptr;
831 myMapOfInter.ChangeFind(iter.Key()) = NULL;
835 myMapOfInter.Clear();
837 myReject = Standard_True; //-- case of infinite solid (without any face)
839 TopExp_Explorer Expl;
840 for(Expl.Init(S,TopAbs_FACE);
843 const TopoDS_Face Face = TopoDS::Face(Expl.Current());
844 void *ptr = (void *)(new IntCurvesFace_Intersector(Face,Precision::Confusion(),Standard_True, Standard_False));
845 myMapOfInter.Bind(Face,ptr);
846 myReject=Standard_False; //-- at least one face in the solid
851 std::cout<<"\nWARNING : BRepClass3d_SolidExplorer.cxx (Solid without face)"<<std::endl;
856 BRepBndLib::Add(myShape,myBox);
859 // since the internal/external parts should be avoided in tree filler,
860 // there is no need to add these parts in the EV map as well
861 TopExp_Explorer aExpF(myShape, TopAbs_FACE);
862 for (; aExpF.More(); aExpF.Next()) {
863 const TopoDS_Shape& aF = aExpF.Current();
865 TopAbs_Orientation anOrF = aF.Orientation();
866 if (anOrF == TopAbs_INTERNAL || anOrF == TopAbs_EXTERNAL) {
870 TopExp_Explorer aExpE(aF, TopAbs_EDGE);
871 for (; aExpE.More(); aExpE.Next()) {
872 const TopoDS_Shape& aE = aExpE.Current();
874 TopAbs_Orientation anOrE = aE.Orientation();
875 if (anOrE == TopAbs_INTERNAL || anOrE == TopAbs_EXTERNAL) {
879 if (BRep_Tool::Degenerated(TopoDS::Edge(aE))) {
883 TopExp::MapShapes(aE, myMapEV);
887 // Fill mapEV with vertices and edges from shape
888 NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller (myTree);
890 Standard_Integer i, aNbEV = myMapEV.Extent();
891 for (i = 1; i <= aNbEV; ++i) {
892 const TopoDS_Shape& aS = myMapEV(i);
895 BRepBndLib::Add(aS, aBox);
896 aTreeFiller.Add(i, aBox);
901 //=======================================================================
903 //purpose : Should return True if P outside of bounding vol. of the shape
904 //=======================================================================
906 //Standard_Boolean BRepClass3d_SolidExplorer::Reject(const gp_Pnt& P) const
907 Standard_Boolean BRepClass3d_SolidExplorer::Reject(const gp_Pnt& ) const
909 return(myReject); // case of solid without face
912 //=======================================================================
913 //function : InitShell
914 //purpose : Starts an exploration of the shells.
915 //=======================================================================
917 void BRepClass3d_SolidExplorer::InitShell()
919 myShellExplorer.Init(myShape,TopAbs_SHELL);
922 //=======================================================================
923 //function : MoreShell
924 //purpose : Returns True if there is a current shell.
925 //=======================================================================
927 Standard_Boolean BRepClass3d_SolidExplorer::MoreShell() const
929 return(myShellExplorer.More());
932 //=======================================================================
933 //function : NextShell
934 //purpose : Sets the explorer to the next shell.
935 //=======================================================================
937 void BRepClass3d_SolidExplorer::NextShell()
939 myShellExplorer.Next();
942 //=======================================================================
943 //function : CurrentShell
944 //purpose : Returns the current shell.
945 //=======================================================================
947 TopoDS_Shell BRepClass3d_SolidExplorer::CurrentShell() const
949 return(TopoDS::Shell(myShellExplorer.Current()));
952 //=======================================================================
953 //function : RejectShell
954 //purpose : Returns True if the Shell is rejected.
955 //=======================================================================
957 Standard_Boolean BRepClass3d_SolidExplorer::RejectShell(const gp_Lin& ) const
959 return(Standard_False);
962 //=======================================================================
963 //function : InitFace
964 //purpose : Starts an exploration of the faces of the current shell.
965 //=======================================================================
967 void BRepClass3d_SolidExplorer::InitFace()
969 myFaceExplorer.Init(TopoDS::Shell(myShellExplorer.Current()),TopAbs_FACE);
972 //=======================================================================
973 //function : MoreFace
974 //purpose : Returns True if current face in current shell.
975 //=======================================================================
977 Standard_Boolean BRepClass3d_SolidExplorer::MoreFace() const
979 return(myFaceExplorer.More());
982 //=======================================================================
983 //function : NextFace
984 //purpose : Sets the explorer to the next Face of the current shell.
985 //=======================================================================
987 void BRepClass3d_SolidExplorer::NextFace()
989 myFaceExplorer.Next();
992 //=======================================================================
993 //function : CurrentFace
994 //purpose : Returns the current face.
995 //=======================================================================
997 TopoDS_Face BRepClass3d_SolidExplorer::CurrentFace() const
999 return(TopoDS::Face(myFaceExplorer.Current()));
1002 //=======================================================================
1003 //function : RejectFace
1004 //purpose : returns True if the face is rejected.
1005 //=======================================================================
1007 Standard_Boolean BRepClass3d_SolidExplorer::RejectFace(const gp_Lin& ) const
1009 return(Standard_False);
1013 #include <TopAbs_State.hxx>
1016 //=======================================================================
1017 //function : Segment
1018 //purpose : Returns in <L>, <Par> a segment having at least
1019 // one intersection with the shape boundary to
1020 // compute intersections.
1021 //=======================================================================
1022 Standard_Integer BRepClass3d_SolidExplorer::Segment(const gp_Pnt& P,
1026 Standard_Integer bRetFlag;
1028 bRetFlag=OtherSegment(P,L,Par);
1032 //=======================================================================
1033 //function : Intersector
1035 //=======================================================================
1037 IntCurvesFace_Intersector& BRepClass3d_SolidExplorer::Intersector(const TopoDS_Face& F) const {
1038 void *ptr = (void*)(myMapOfInter.Find(F));
1039 IntCurvesFace_Intersector& curr = (*((IntCurvesFace_Intersector *)ptr));
1043 //=======================================================================
1046 //=======================================================================
1048 const Bnd_Box& BRepClass3d_SolidExplorer::Box() const {
1052 //=======================================================================
1053 //function : DumpSegment
1055 //=======================================================================
1057 void BRepClass3d_SolidExplorer::DumpSegment(const gp_Pnt&,
1059 const Standard_Real,
1060 const TopAbs_State) const
1067 const TopoDS_Shape& BRepClass3d_SolidExplorer::GetShape() const