1 // GEOM PARTITION : partition algorithm
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : Partition_Inter3d.cxx
25 // Author : Benedicte MARTIN
30 #include "Partition_Inter2d.hxx"
31 #include "Partition_Inter3d.ixx"
32 #include "utilities.h"
34 #include <BRepAlgo_AsDes.hxx>
35 #include <BRepAlgo_Image.hxx>
36 #include <BRepLib.hxx>
37 #include <BRepOffset_Tool.hxx>
38 #include <BRep_Builder.hxx>
39 #include <BRep_Tool.hxx>
42 #include <TopExp_Explorer.hxx>
44 #include <TopOpeBRepTool_BoxSort.hxx>
45 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
46 #include <TopTools_ListIteratorOfListOfShape.hxx>
47 #include <TopTools_ListOfShape.hxx>
49 #include <TopoDS_Compound.hxx>
50 #include <TopoDS_Edge.hxx>
51 #include <TopoDS_Face.hxx>
52 #include <TopoDS_Vertex.hxx>
58 #include <BRepLib_MakeVertex.hxx>
59 #include <BRepTools.hxx>
60 #include <Extrema_ExtPS.hxx>
61 #include <Extrema_POnSurf.hxx>
62 #include <Geom2dAPI_ProjectPointOnCurve.hxx>
63 #include <Geom2d_Curve.hxx>
64 #include <GeomAPI_ProjectPointOnCurve.hxx>
65 #include <GeomAdaptor_Surface.hxx>
66 #include <Geom_Curve.hxx>
67 #include <Geom_RectangularTrimmedSurface.hxx>
68 #include <Geom_SphericalSurface.hxx>
69 #include <Geom_Surface.hxx>
70 #include <Geom_ToroidalSurface.hxx>
71 #include <Geom_TrimmedCurve.hxx>
72 #include <Precision.hxx>
73 #include <TColStd_MapOfInteger.hxx>
74 #include <TopOpeBRepBuild_Builder.hxx>
75 #include <TopOpeBRepDS_BuildTool.hxx>
76 #include <TopOpeBRepDS_CurveExplorer.hxx>
77 #include <TopOpeBRepDS_HDataStructure.hxx>
78 #include <TopOpeBRepDS_Interference.hxx>
79 #include <TopOpeBRepDS_PointIterator.hxx>
80 #include <TopOpeBRepDS_Transition.hxx>
81 #include <TopOpeBRepTool_CurveTool.hxx>
82 #include <TopOpeBRepTool_GeomTool.hxx>
83 #include <TopOpeBRepTool_OutCurveType.hxx>
84 #include <TopOpeBRep_DSFiller.hxx>
85 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
88 //=======================================================================
89 //function : Partition_Inter3d
91 //=======================================================================
93 Partition_Inter3d::Partition_Inter3d()
96 //=======================================================================
97 //function : Partition_Inter3d
99 //=======================================================================
101 Partition_Inter3d::Partition_Inter3d(const Handle(BRepAlgo_AsDes)& AsDes)
104 mySectionEdgesAD = new BRepAlgo_AsDes;
107 //=======================================================================
108 //function : CompletPart3d
109 //purpose : FaceShapeMap is just to know the shape a face belongs to
110 //=======================================================================
112 void Partition_Inter3d::CompletPart3d(const TopTools_ListOfShape& SetOfFaces1,
113 const TopTools_DataMapOfShapeShape& FaceShapeMap)
115 if (myAsDes.IsNull())
116 myAsDes = new BRepAlgo_AsDes;
118 TopTools_ListIteratorOfListOfShape it;
120 //---------------------------------------------------------------
121 // Construction of bounding boxes.
122 //---------------------------------------------------------------
125 TopoDS_Compound CompOS;
126 B.MakeCompound(CompOS);
127 for (it.Initialize(SetOfFaces1); it.More(); it.Next())
128 B.Add(CompOS, it.Value());
130 TopOpeBRepTool_BoxSort BOS;
131 BOS.AddBoxesMakeCOB(CompOS,TopAbs_FACE);
133 for (it.Initialize(SetOfFaces1); it.More(); it.Next()) {
134 TopoDS_Face F1 = TopoDS::Face(it.Value());
136 // avoid intersecting faces of one shape
138 if (FaceShapeMap.IsBound(F1)) S1 = FaceShapeMap.Find(F1);
139 // avoid intersecting faces sharing vertices, suppose they belong to
140 // shapes sharing same faces
141 TopTools_IndexedMapOfShape VM;
142 TopExp::MapShapes( F1, TopAbs_VERTEX, VM);
144 TColStd_ListIteratorOfListOfInteger itLI = BOS.Compare(F1);
145 for (; itLI.More(); itLI.Next()) {
146 TopoDS_Face F2 = TopoDS::Face(BOS.TouchedShape(itLI));
147 if (F1.IsSame(F2) || IsDone(F1,F2))
151 if (FaceShapeMap.IsBound(F2)) S2 = FaceShapeMap.Find(F2);
152 if (!S1.IsNull() && S1.IsSame(S2))
153 continue; // descendants of one shape
155 TopExp_Explorer expV (F2, TopAbs_VERTEX);
156 for ( ; expV.More(); expV.Next())
157 if (VM.Contains( expV.Current() ))
160 continue; // faces have a common edge
162 F1.Orientation(TopAbs_FORWARD);
163 F2.Orientation(TopAbs_FORWARD);
164 FacesPartition(F1,F2);
167 // mark as modified a face which has at least one new edge
168 if (!myAsDes->HasDescendant( F1 ))
170 TopTools_ListIteratorOfListOfShape itE (myAsDes->Descendant( F1 ));
171 for ( ; itE.More(); itE.Next()) {
172 if (myNewEdges.Contains( itE.Value())) {
180 //=======================================================================
181 //function : PutInBounds
183 //=======================================================================
185 static void PutInBounds (const TopoDS_Face& F,
186 const TopoDS_Edge& E,
187 Handle(Geom2d_Curve)& C2d)
189 Standard_Real umin,umax,vmin,vmax;
191 BRep_Tool::Range(E,f,l);
193 TopLoc_Location L; // Recup S avec la location pour eviter la copie.
194 Handle (Geom_Surface) S = BRep_Tool::Surface(F,L);
196 if (S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
197 S = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
199 if (!S->IsUPeriodic() && !S->IsVPeriodic())
202 BRepTools::UVBounds(F,umin,umax,vmin,vmax);
204 gp_Pnt2d Pf = C2d->Value(f);
205 gp_Pnt2d Pl = C2d->Value(l);
206 const Standard_Real Um = 0.34*f + 0.66*l;
207 gp_Pnt2d Pm = C2d->Value( Um );
209 // sometimes on shpere, pcurve is out of domain by V though S is
210 // UPeriodic, sometimes it is in domain but nontheless it has
212 // Check pcurve position by 3D point
213 if (S->IsKind(STANDARD_TYPE( Geom_SphericalSurface )) ||
214 S->IsKind(STANDARD_TYPE( Geom_ToroidalSurface )))
216 // get point on the surface
217 gp_Pnt Ps = S->Value( Pm.X(), Pm.Y() );
218 // get point on the edge
219 Handle(Geom_Curve) C = BRep_Tool::Curve( E, f, l );
220 gp_Pnt Pc = C->Value( Um );
222 Standard_Real TolE = BRep_Tool::Tolerance( E );
223 if ( Pc.SquareDistance( Ps ) * 0.95 < TolE * TolE )
226 // find good UV for Pc: project Pc on S
227 GeomAdaptor_Surface SA (S);
228 Extrema_ExtPS anExtPS (Pc, SA,
229 SA.UResolution( TolE ), SA.VResolution( TolE ));
230 if (anExtPS.IsDone())
232 Standard_Integer i, nbExt = anExtPS.NbExt();
233 Extrema_POnSurf aPOnSurf;
234 for (i = 1; i <= nbExt; ++i )
235 if (anExtPS.Value( i ) <= TolE) {
236 aPOnSurf = anExtPS.Point( i );
242 aPOnSurf.Parameter( u, v );
243 gp_Pnt2d aGoodPm ( u, v );
244 C2d->Translate( Pm , aGoodPm );
252 if (S->IsUPeriodic()) {
253 Standard_Real period = S->UPeriod();
254 Standard_Real eps = period*1.e-6;
255 Standard_Real minC = Min(Pf.X(),Pl.X()); minC = Min(minC,Pm.X());
256 Standard_Real maxC = Max(Pf.X(),Pl.X()); maxC = Max(maxC,Pm.X());
257 Standard_Real du = 0.;
258 if (minC< umin - eps) {
259 du = (int((umin - minC)/period) + 1)*period;
261 if (minC > umax + eps) {
262 du = -(int((minC - umax)/period) + 1)*period;
267 minC += du; maxC += du;
269 // Ajuste au mieux la courbe dans le domaine.
270 if (maxC > umax +100*eps) {
271 Standard_Real d1 = maxC - umax;
272 Standard_Real d2 = umin - minC + period;
273 if (d2 < d1) du =-period;
283 if (S->IsVPeriodic()) {
284 Standard_Real period = S->VPeriod();
285 Standard_Real eps = period*1.e-6;
286 Standard_Real minC = Min(Pf.Y(),Pl.Y()); minC = Min(minC,Pm.Y());
287 Standard_Real maxC = Max(Pf.Y(),Pl.Y()); maxC = Max(maxC,Pm.Y());
288 Standard_Real dv = 0.;
289 if (minC< vmin - eps) {
290 dv = (int((vmin - minC)/period) + 1)*period;
292 if (minC > vmax + eps) {
293 dv = -(int((minC - vmax)/period) + 1)*period;
298 minC += dv; maxC += dv;
300 // Ajuste au mieux la courbe dans le domaine.
301 if (maxC > vmax +100*eps) {
302 Standard_Real d1 = maxC - vmax;
303 Standard_Real d2 = vmin - minC + period;
304 if (d2 < d1) dv =-period;
313 //=======================================================================
316 //=======================================================================
318 void Partition_Inter3d::Inter3D(const TopoDS_Face& F1,
319 const TopoDS_Face& F2,
320 TopTools_ListOfShape& L)
324 // fill the data Structure
325 Handle(TopOpeBRepDS_HDataStructure) DatStr = new TopOpeBRepDS_HDataStructure();
326 TopOpeBRep_DSFiller DSFiller;
327 DSFiller.Insert(F1,F2,DatStr);
329 // define the GeomTool used by the DSFiller :
330 // compute BSpline of degree 1 on intersection curves.
331 Standard_Real tol3dAPPROX = 1e-7;
332 Standard_Real tol2dAPPROX = 1e-7;
333 TopOpeBRepTool_GeomTool GT2 (TopOpeBRepTool_APPROX);
334 GT2.SetTolerances(tol3dAPPROX,tol2dAPPROX);
335 TopOpeBRepDS_BuildTool BT(GT2);
338 TopOpeBRepBuild_Builder TopB(BT);
339 TopB.Perform(DatStr);
346 TopOpeBRepDS_CurveExplorer cex(DatStr->DS());
347 for (; cex.More(); cex.Next()) {
348 const TopOpeBRepDS_Curve& CDS = cex.Curve();
349 Standard_Integer ic = cex.Index();
350 Handle(Geom2d_Curve) pc1 = CDS.Curve1();
351 Handle(Geom2d_Curve) pc2 = CDS.Curve2();
353 TopTools_ListIteratorOfListOfShape itLE = TopB.NewEdges(ic);
354 while (itLE.More()) {
355 TopoDS_Edge E = TopoDS::Edge(itLE.Value());
357 PutInBounds (F1,E,pc1);
358 PutInBounds (F2,E,pc2);
360 B.UpdateEdge (E,pc1,F1,0.);
361 B.UpdateEdge (E,pc2,F2,0.);
367 pc1 = Handle(Geom2d_Curve)::DownCast(pc1->Copy());
368 pc2 = Handle(Geom2d_Curve)::DownCast(pc2->Copy());
373 // ========================
374 // store same domain faces
375 // ========================
378 if ( DatStr->HasSameDomain( F1 ))
380 TopTools_ListOfShape emptyList;
381 if (!mySameDomainFM.IsBound(F1))
382 mySameDomainFM.Bind(F1,emptyList);
383 if (!mySameDomainFM.IsBound(F2))
384 mySameDomainFM.Bind(F2,emptyList);
385 mySameDomainFM(F1).Append(F2);
386 mySameDomainFM(F2).Append(F1);
389 // ====================
390 // Store section edges
391 // ====================
393 const TopOpeBRepDS_DataStructure& DS = DatStr->DS();
394 Standard_Integer j,i,nse = DS.NbSectionEdges();
395 if (nse == 0) return;
398 TopoDS_Vertex V, sdeV1, sdeV2;
399 TopTools_MapOfShape MV;
400 TopTools_ListOfShape LSE; // list of section edges
403 for (i = 1; i <= nse; i++)
405 const TopoDS_Edge & se = DS.SectionEdge(i);
406 if (! TopB.IsSplit(se,TopAbs_ON))
410 // add vertices where section edges interferes with other
411 // edges as its descendant in myAsDes
413 TopoDS_Edge sde, oe; // same domain, other edge
414 if (DatStr->HasSameDomain(se)) {
415 sde = TopoDS::Edge( DatStr->SameDomain(se).Value() );
416 TopExp::Vertices( sde, sdeV1, sdeV2);
418 TColStd_MapOfInteger MIV; // indices of added edges
419 TopOpeBRepDS_PointIterator itP (DS.ShapeInterferences( se ));
420 itP.SupportKind( TopOpeBRepDS_EDGE );
421 // loop on intersections of se
422 for (; itP.More(); itP.Next()) {
423 oe = TopoDS::Edge( DS.Shape( itP.Support()));
424 if (itP.IsVertex()) {
425 // there is a vertex at intersection
426 if ( !MIV.Add( itP.Current() ))
428 V = TopoDS::Vertex( DS.Shape( itP.Current()));
429 if ( !sde.IsNull() && (V.IsSame(sdeV1) || V.IsSame(sdeV2)) )
431 V = ReplaceSameDomainV( V , oe );
432 V.Orientation( TopAbs_INTERNAL);
433 B.UpdateVertex( V, itP.Parameter(), se, 0.); // AddVonE() sets real U
436 // create a new vertex at the intersection point
437 const TopOpeBRepDS_Point& DSP = DS.Point( itP.Current());
438 V = BRepLib_MakeVertex( DSP.Point() );
439 V.Orientation( TopAbs_INTERNAL);
440 B.UpdateVertex( V, itP.Parameter(), se, DSP.Tolerance());
441 // make V be on the other edge
442 TopOpeBRepDS_PointIterator itOP (DS.ShapeInterferences( oe ));
443 for (; itOP.More(); itOP.Next()) {
444 const TopOpeBRepDS_Point& ODSP = DS.Point( itOP.Current());
445 if ( DSP.IsEqual (ODSP)) {
446 B.UpdateVertex( V, itOP.Parameter(), TopoDS::Edge(oe), ODSP.Tolerance());
451 // add V on the both intersecting edges
452 TopoDS_Vertex addedV = Partition_Inter2d::AddVonE( V,se,oe,myAsDes,dummyF);
453 if (!addedV.IsSame( V ))
454 mySameDomainVM.Bind (V, addedV); // equal vertex is already there
456 MV.Add( addedV ); // to ease storage of vertices of ON splits
460 // add section edge to the face it intersects and find
461 // splits ON that do not have same domain pair
463 TopB.SplitSectionEdges(); // let TopB find ON splits
465 TopTools_MapOfShape SPM; // map of ON splits
466 TopTools_IndexedMapOfShape ME[2];
467 TopExp::MapShapes( F1, TopAbs_EDGE, ME[1]);
468 TopExp::MapShapes( F2, TopAbs_EDGE, ME[0]);
470 TopTools_ListIteratorOfListOfShape itSP, itLSE (LSE);
471 while ( itLSE.More() ) {
473 TopoDS_Edge se = TopoDS::Edge( itLSE.Value() );
475 Standard_Integer ancRank = DS.AncestorRank(se);
476 if (ME[ancRank-1].Contains( se ))
477 LSE.Remove( itLSE ); // se is an edge of face it intersects
481 const TopoDS_Face& F = (ancRank == 1) ? F2 : F1;
483 // add se to face but dont add twice
484 TopTools_ListIteratorOfListOfShape itE( myAsDes->Descendant( F ));
485 if (myAsDes->HasDescendant( F )) {
486 for ( ; itE.More(); itE.Next())
487 if (se.IsSame( itE.Value() ))
492 myAsDes->Add( F, se );
494 // check se pcurve on F
495 Standard_Real tol, f,l, umin=1e100, umax=-1e100;
496 Handle(Geom2d_Curve) pc = BRep_Tool::CurveOnSurface( se, F, f,l);
498 itSP.Initialize( TopB.Splits(se,TopAbs_ON) );
499 for ( ; itSP.More(); itSP.Next()) {
500 const TopoDS_Edge& E = TopoDS::Edge ( itSP.Value());
501 BRep_Tool::Range(E, f, l);
502 umin = Min( umin, f);
503 umax = Max( umax, l);
505 Handle(Geom_Curve) C3d = BRep_Tool::Curve( se, f, l);
506 if (umin < umax) // sometimes umin == umax for closed edge
507 C3d = new Geom_TrimmedCurve( C3d, umin, umax);
508 pc = TopOpeBRepTool_CurveTool::MakePCurveOnFace (F,C3d,tol);
510 MESSAGE (" CANT BUILD PCURVE ");
512 B.UpdateEdge( se, pc, F, tol);
516 // to detect splits that do not have same domain pair
517 // ie which split a face into parts and not pass by its boundary
518 itSP.Initialize( TopB.Splits(se,TopAbs_ON) );
519 for ( ; itSP.More(); itSP.Next()) {
520 const TopoDS_Shape& SP = itSP.Value();
526 // store vertices of ON splits and bind section edges to faces
528 for (itLSE.Initialize (LSE); itLSE.More(); itLSE.Next())
530 const TopoDS_Shape& se = itLSE.Value();
532 Standard_Integer ancRank = DS.AncestorRank(se);
533 TopoDS_Face F = (ancRank == 1) ? F2 : F1;
535 // add vertices of ON splits which have no same domain pair
536 Standard_Boolean added = Standard_False;
537 itSP.Initialize( TopB.Splits(se,TopAbs_ON) );
538 for ( ; itSP.More(); itSP.Next())
540 if (!SPM.Contains( itSP.Value() ))
543 const TopoDS_Edge& S = TopoDS::Edge ( itSP.Value());
545 added = Standard_True;
546 mySectionEdgesAD->Add( F, se );
549 TopExp::Vertices (S, VS[0], VS[1]);
552 if (mySameDomainVM.IsBound( VS[j] ))
553 VS[j] = TopoDS::Vertex( mySameDomainVM( VS[j] ));
554 if ( !MV.Contains( VS[j] )) {
555 // find equal vertex on se - point interference
556 gp_Pnt P1 = BRep_Tool::Pnt( VS[j] );
557 TopTools_ListIteratorOfListOfShape itV( myAsDes->Descendant(se) );
558 for (; itV.More(); itV.Next()) {
559 V = TopoDS::Vertex( itV.Value() );
560 if ( V.IsSame( VS[j] ))
562 gp_Pnt P2 = BRep_Tool::Pnt( V );
563 if (P1.IsEqual( P2, Precision::Confusion())) {
564 mySameDomainVM.Bind (VS[j], V);
569 if (!itV.More()) // no interferences with edges
570 myAsDes->Add( se, VS[j]);
573 // add ends of ON splits to F in order to detect later
574 // if a split is on face in IsSplitOn()
575 mySectionEdgesAD->Add( F, VS[j]);
577 // in the descendants of F, first go ends of an ON split and
578 // then a split itself
579 mySectionEdgesAD->Add( F, S );
582 mySectionEdgesAD->Add( F, se );
584 myNewEdges.Add( se );
588 //=======================================================================
589 //function : FacesPartition
591 //=======================================================================
593 void Partition_Inter3d::FacesPartition(const TopoDS_Face& F1,
594 const TopoDS_Face& F2)
595 //(const TopTools_DataMapOfShapeListOfShape& /*SetOfFaces2*/)
597 TopTools_ListOfShape LInt;
599 Inter3D (F1,F2,LInt);
601 StorePart3d (F1,F2,LInt);
604 //=======================================================================
607 //=======================================================================
609 void Partition_Inter3d::SetDone(const TopoDS_Face& F1,
610 const TopoDS_Face& F2)
612 if (!myDone.IsBound(F1)) {
613 TopTools_ListOfShape emptyList;
614 myDone.Bind(F1,emptyList);
616 myDone(F1).Append(F2);
617 if (!myDone.IsBound(F2)) {
618 TopTools_ListOfShape emptyList;
619 myDone.Bind(F2,emptyList);
621 myDone(F2).Append(F1);
624 //=======================================================================
627 //=======================================================================
629 Standard_Boolean Partition_Inter3d::IsDone(const TopoDS_Face& F1,
630 const TopoDS_Face& F2)
634 if (myDone.IsBound(F1)) {
635 TopTools_ListIteratorOfListOfShape it (myDone(F1));
636 for (; it.More(); it.Next()) {
637 if (it.Value().IsSame(F2)) return Standard_True;
640 return Standard_False;
643 //=======================================================================
644 //function : StorePart3d
646 //=======================================================================
648 void Partition_Inter3d::StorePart3d(const TopoDS_Face& F1,
649 const TopoDS_Face& F2,
650 const TopTools_ListOfShape& LInt)
652 if (!LInt.IsEmpty()) {
653 myAsDes->Add( F1,LInt);
654 myAsDes->Add( F2,LInt);
656 TopTools_ListIteratorOfListOfShape it(LInt);
657 for (; it.More(); it.Next()) {
659 TopoDS_Edge E = TopoDS::Edge(it.Value());
662 B.SameParameter(E,Standard_False);
663 BRepLib::SameParameter(E,1.0e-7);
671 //=======================================================================
672 //function : TouchedFaces
674 //=======================================================================
676 TopTools_MapOfShape& Partition_Inter3d::TouchedFaces()
681 //=======================================================================
684 //=======================================================================
686 Handle(BRepAlgo_AsDes) Partition_Inter3d::AsDes() const
691 //=======================================================================
692 //function : NewEdges
694 //=======================================================================
696 TopTools_MapOfShape& Partition_Inter3d::NewEdges()
701 //=======================================================================
704 //=======================================================================
706 void Partition_Inter3d::Affiche(const TopTools_ListOfShape& SetOfFaces) const
710 char *section=PSection;
711 Standard_Integer i = 0;
713 TopTools_ListOfShape aList;
714 TopTools_ListIteratorOfListOfShape it;
715 for (it.Initialize(SetOfFaces); it.More(); it.Next()) {
716 const TopoDS_Shape& OS = it.Value();
717 aList=myAsDes->Descendant(OS);
718 MESSAGE ( " the number of items stored in the list " << j << " : " << aList.Extent() )
720 TopTools_ListIteratorOfListOfShape itaList;
721 for (itaList.Initialize(aList); itaList.More(); itaList.Next()) {
722 const TopoDS_Shape& SS = itaList.Value();
724 sprintf(PSection,"section_%d",i);
725 DBRep::Set(section,SS);
731 //=======================================================================
732 //function : SameDomain
734 //=======================================================================
736 const TopTools_ListOfShape& Partition_Inter3d::SameDomain(const TopoDS_Face& F) const
738 if (mySameDomainFM.IsBound( F ))
739 return mySameDomainFM (F);
741 static TopTools_ListOfShape emptyList;
745 //=======================================================================
746 //function : HasSameDomainF
747 //purpose : Return true if F has same domain faces
748 //=======================================================================
750 Standard_Boolean Partition_Inter3d::HasSameDomainF(const TopoDS_Shape& F) const
752 return mySameDomainFM.IsBound( F );
755 //=======================================================================
756 //function : IsSameDomain
757 //purpose : Return true if F1 and F2 are same domain faces
758 //=======================================================================
760 Standard_Boolean Partition_Inter3d::IsSameDomainF(const TopoDS_Shape& F1,
761 const TopoDS_Shape& F2) const
763 if (mySameDomainFM.IsBound( F1 )) {
764 TopTools_ListIteratorOfListOfShape it (mySameDomainFM( F1 ));
765 for (; it.More(); it.Next())
766 if (F2.IsSame( it.Value()))
767 return Standard_True;
769 return F1.IsSame( F2 );
772 //=======================================================================
773 //function : ReplaceSameDomainV
774 //purpose : return same domain vertex of V if it was replaced
775 // and make this vertex to be on E too, else return V
776 //=======================================================================
778 TopoDS_Vertex Partition_Inter3d::ReplaceSameDomainV(const TopoDS_Vertex& V,
779 const TopoDS_Edge& E) const
781 TopoDS_Vertex SDV = V;
782 if (mySameDomainVM.IsBound( V )) {
785 TopExp::Vertices(E,V1,V2);
786 Standard_Boolean isClosed = V1.IsSame( V2 ) && V.IsSame(V1);
788 SDV = TopoDS::Vertex( mySameDomainVM(V) );
789 Standard_Real tol = BRep_Tool::Tolerance( V );
791 SDV.Orientation( V.Orientation());
795 BRep_Tool::Range (E, f, l);
796 Standard_Boolean isFirst = IsEqual( BRep_Tool::Parameter(V,E), f );
797 B.UpdateVertex(SDV, (isFirst ? f : l), E, tol);
799 B.UpdateVertex(SDV, (isFirst ? l : f), E, tol);
802 B.UpdateVertex (SDV, BRep_Tool::Parameter(V,E), E, tol);
808 //=======================================================================
809 //function : SectionEdgesAD
811 //=======================================================================
813 Handle(BRepAlgo_AsDes) Partition_Inter3d::SectionEdgesAD() const
815 return mySectionEdgesAD;
818 //=======================================================================
819 //function : IsSectionEdge
820 //purpose : return True if E is an edge of a face and it
821 // intersects an other face
822 //=======================================================================
825 Partition_Inter3d::IsSectionEdge(const TopoDS_Edge& E) const
827 return mySectionEdgesAD->HasAscendant(E);
830 //=======================================================================
831 //function : HasSectionEdge
832 //purpose : return True if an edge of F intersects an other
833 // face or F is intersected by edge of an other face
834 //=======================================================================
837 Partition_Inter3d::HasSectionEdge(const TopoDS_Face& F) const
839 return mySectionEdgesAD->HasDescendant(F);
842 //=======================================================================
843 //function : IsSplitOn
844 //purpose : return True if NewE is split of OldE on F
845 //=======================================================================
848 Partition_Inter3d::IsSplitOn(const TopoDS_Edge& NewE,
849 const TopoDS_Edge& OldE,
850 const TopoDS_Face& F) const
852 if (! mySectionEdgesAD->HasDescendant(F))
853 return Standard_False;
855 TopTools_ListIteratorOfListOfShape itE ( mySectionEdgesAD->Descendant(F) );
856 for ( ; itE.More(); itE.Next()) {
857 if ( itE.Value().ShapeType() != TopAbs_EDGE ||
858 ! OldE.IsSame ( itE.Value() ))
860 // an edge encountered, its vertices and a split come next
862 if (!itE.More()) break;
863 const TopoDS_Shape& V3 = itE.Value();
864 if (V3.ShapeType() != TopAbs_VERTEX) continue;
866 if (!itE.More()) break;
867 const TopoDS_Shape& V4 = itE.Value();
868 if (V4.ShapeType() != TopAbs_VERTEX) continue;
870 TopoDS_Vertex V1, V2;
871 TopExp::Vertices( OldE, V1, V2);
873 if ( V1.IsSame(V2) &&
874 (V1.IsSame(V3) || V1.IsSame(V4)) ) {
875 // closed old edge; use the split for the test
877 if (!itE.More()) break;
878 const TopoDS_Edge& split = TopoDS::Edge( itE.Value() );
879 // check distance at middle point of NewE
880 Standard_Real f1,l1, f2,l2;
881 Handle(Geom2d_Curve) PC1 = BRep_Tool::CurveOnSurface( split, F ,f1,l1);
883 Handle(Geom2d_Curve) PC2 = BRep_Tool::CurveOnSurface(NewE, F ,f2,l2);
884 gp_Pnt2d P = PC2->Value( 0.5*(f2+l2) );
885 Geom2dAPI_ProjectPointOnCurve proj (P, PC1, f1, l1);
886 if (proj.NbPoints() &&
887 proj.LowerDistance() <= Precision::Confusion())
888 return Standard_True;
891 Handle(Geom_Curve) C1 = BRep_Tool::Curve( split ,f1,l1);
892 Handle(Geom_Curve) C2 = BRep_Tool::Curve( NewE ,f2,l2);
893 gp_Pnt P = C2->Value( 0.5*(f2+l2) );
894 GeomAPI_ProjectPointOnCurve proj (P, C1, f1, l1);
895 if (proj.NbPoints() &&
896 proj.LowerDistance() <= Precision::Confusion())
897 return Standard_True;
901 Standard_Real u3 = BRep_Tool::Parameter( TopoDS::Vertex(V3), OldE);
902 Standard_Real u4 = BRep_Tool::Parameter( TopoDS::Vertex(V4), OldE);
904 Standard_Real f,l, u;
905 BRep_Tool::Range( NewE, f,l);
910 if (u <= l && u >= f)
911 return Standard_True;
914 return Standard_False;
917 //=======================================================================
918 //function : SectionEdgeFaces
919 //purpose : return faces cut by section edge
920 //=======================================================================
922 const TopTools_ListOfShape&
923 Partition_Inter3d::SectionEdgeFaces(const TopoDS_Edge& SecE) const
925 return mySectionEdgesAD->Ascendant( SecE );