1 // Created on: 1995-10-27
2 // Created by: Yves FRICAUD
3 // Copyright (c) 1995-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 by skv - Tue Mar 15 16:20:43 2005
18 // Add methods for supporting history.
19 // Modified by skv - Mon Jan 12 11:50:02 2004 OCC4455
21 #include <Adaptor3d_CurveOnSurface.hxx>
22 #include <BRep_Builder.hxx>
23 #include <BRep_ListIteratorOfListOfPointRepresentation.hxx>
24 #include <BRep_PointRepresentation.hxx>
25 #include <BRep_TEdge.hxx>
26 #include <BRep_Tool.hxx>
27 #include <BRep_TVertex.hxx>
28 #include <BRepAdaptor_Curve.hxx>
29 #include <BRepAdaptor_Curve2d.hxx>
30 #include <BRepAdaptor_Surface.hxx>
31 #include <BRepAlgo_AsDes.hxx>
32 #include <BRepAlgo_Image.hxx>
33 #include <BRepCheck_Analyzer.hxx>
34 #include <BRepCheck_Edge.hxx>
35 #include <BRepCheck_Vertex.hxx>
36 #include <BRepClass3d_SolidClassifier.hxx>
37 #include <BRepGProp.hxx>
38 #include <BRepLib.hxx>
39 #include <BRepLib_FindSurface.hxx>
40 #include <BRepLib_MakeEdge.hxx>
41 #include <BRepLib_MakeFace.hxx>
42 #include <BRepLib_MakeVertex.hxx>
43 #include <BRepOffset_Analyse.hxx>
44 #include <BRepOffset_DataMapIteratorOfDataMapOfShapeOffset.hxx>
45 #include <BRepOffset_DataMapOfShapeMapOfShape.hxx>
46 #include <BRepOffset_DataMapOfShapeOffset.hxx>
47 #include <BRepOffset_Inter2d.hxx>
48 #include <BRepOffset_Inter3d.hxx>
49 #include <BRepOffset_Interval.hxx>
50 #include <BRepOffset_ListOfInterval.hxx>
51 #include <BRepOffset_MakeLoops.hxx>
52 #include <BRepOffset_MakeOffset.hxx>
53 #include <BRepOffset_Offset.hxx>
54 #include <BRepOffset_Tool.hxx>
55 #include <BRepTools.hxx>
56 #include <BRepTools_Quilt.hxx>
57 #include <BRepTools_Substitution.hxx>
58 #include <BRepTools_WireExplorer.hxx>
61 #include <GC_MakeCylindricalSurface.hxx>
62 #include <GCE2d_MakeLine.hxx>
63 #include <gce_MakeCone.hxx>
64 #include <gce_MakeDir.hxx>
65 #include <Geom2d_Line.hxx>
66 #include <Geom2d_TrimmedCurve.hxx>
67 #include <Geom2dAdaptor_HCurve.hxx>
68 #include <Geom_Circle.hxx>
69 #include <Geom_ConicalSurface.hxx>
70 #include <Geom_CylindricalSurface.hxx>
71 #include <Geom_OffsetSurface.hxx>
72 #include <Geom_Plane.hxx>
73 #include <Geom_SphericalSurface.hxx>
74 #include <Geom_SurfaceOfLinearExtrusion.hxx>
75 #include <Geom_TrimmedCurve.hxx>
76 #include <GeomAdaptor_HSurface.hxx>
77 #include <GeomAPI_ProjectPointOnCurve.hxx>
78 #include <GeomFill_Generator.hxx>
79 #include <GeomLib.hxx>
80 #include <gp_Cone.hxx>
81 #include <gp_Lin2d.hxx>
83 #include <GProp_GProps.hxx>
84 #include <IntTools_FClass2d.hxx>
85 #include <NCollection_List.hxx>
86 #include <Precision.hxx>
87 #include <Standard_ConstructionError.hxx>
88 #include <Standard_NotImplemented.hxx>
89 #include <TColStd_ListIteratorOfListOfInteger.hxx>
91 #include <TopExp_Explorer.hxx>
93 #include <TopoDS_Compound.hxx>
94 #include <TopoDS_Edge.hxx>
95 #include <TopoDS_Face.hxx>
96 #include <TopoDS_Iterator.hxx>
97 #include <TopoDS_Shape.hxx>
98 #include <TopoDS_Shell.hxx>
99 #include <TopoDS_Solid.hxx>
100 #include <TopoDS_Vertex.hxx>
101 #include <TopoDS_Wire.hxx>
102 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
103 #include <TopTools_DataMapIteratorOfDataMapOfShapeReal.hxx>
104 #include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
105 #include <TopTools_DataMapOfShapeShape.hxx>
106 #include <TopTools_IndexedMapOfShape.hxx>
107 #include <TopTools_ListIteratorOfListOfShape.hxx>
108 #include <TopTools_ListOfShape.hxx>
109 #include <TopTools_MapIteratorOfMapOfShape.hxx>
110 #include <TopTools_MapOfShape.hxx>
111 #include <TopTools_SequenceOfShape.hxx>
112 #include <BRepBuilderAPI_Sewing.hxx>
113 #include <Geom_Line.hxx>
114 #include <NCollection_Vector.hxx>
116 #include <BOPAlgo_MakerVolume.hxx>
117 #include <BOPTools_AlgoTools.hxx>
118 #include <BOPCol_ListOfShape.hxx>
127 #include <OSD_Chronometer.hxx>
129 Standard_Boolean AffichInt2d = Standard_False;
130 Standard_Boolean AffichOffC = Standard_False;
131 Standard_Boolean ChronBuild = Standard_False;
132 Standard_Integer NbAE = 0;
133 Standard_Integer NbAF = 0;
134 Standard_Integer NVP = 0;
135 Standard_Integer NVM = 0;
136 Standard_Integer NVN = 0;
137 static OSD_Chronometer Clock;
143 //=======================================================================
144 //function : DEBVerticesControl
146 //=======================================================================
148 static void DEBVerticesControl (const TopTools_IndexedMapOfShape& NewEdges,
149 Handle(BRepAlgo_AsDes) AsDes)
151 TopTools_ListOfShape LVP;
152 TopTools_ListIteratorOfListOfShape it1LE ;
153 TopTools_ListIteratorOfListOfShape it2LE ;
156 for (i = 1; i <= NewEdges.Extent(); i++) {
157 const TopoDS_Edge& NE = TopoDS::Edge(NewEdges(i));
158 if (AsDes->HasDescendant(NE)) {
159 for (it1LE.Initialize(AsDes->Descendant(NE)); it1LE.More(); it1LE.Next()) {
160 if (AsDes->Ascendant(it1LE.Value()).Extent() < 3) {
161 LVP.Append(it1LE.Value());
162 cout <<"Vertex on at least 3 edges."<<endl;
165 sprintf (name,"VP_%d",NVP++);
166 DBRep::Set(name,it1LE.Value());
170 else if (AsDes->Ascendant(it1LE.Value()).Extent() > 3) {
171 cout <<"Vertex on more than 3 edges."<<endl;
174 sprintf (name,"VM_%d",NVM++);
175 DBRep::Set(name,it1LE.Value());
183 sprintf (name,"VN_%d",NVN++);
184 DBRep::Set(name,it1LE.Value());
191 //------------------------------------------------
192 // Try to mix spoiled vertices.
193 //------------------------------------------------
195 TopTools_ListIteratorOfListOfShape it1(LVP);
196 Standard_Real TolConf = 1.e-5;
197 Standard_Real Tol = Precision::Confusion();
198 //Standard_Integer i = 1;
201 for ( ; it1.More(); it1.Next()) {
202 TopoDS_Shape V1 = it1.Value();
203 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(V1));
204 Standard_Real distmin = Precision::Infinite();
205 TopTools_ListIteratorOfListOfShape it2(LVP);
206 Standard_Integer j = 1;
208 for ( ; it2.More(); it2.Next()) {
210 TopoDS_Shape V2 = it2.Value();
211 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(V2));
212 if (!V1.IsSame(V2)) {
213 Standard_Real dist = P1.Distance(P2);
214 if (dist < distmin) distmin = dist;
215 if (dist < TolConf) {
218 const TopTools_ListOfShape& EdgeWithV2 = AsDes->Ascendant(V2);
219 TopTools_ListIteratorOfListOfShape itAsDes;
220 for (itAsDes.Initialize(EdgeWithV2); itAsDes.More(); itAsDes.Next()) {
221 EWE2 = TopoDS::Edge(itAsDes.Value());
222 TopoDS_Shape aLocalShape = V2.Oriented(TopAbs_INTERNAL);
223 UV2 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalShape),EWE2);
224 aLocalShape = V1.Oriented(TopAbs_INTERNAL) ;
225 B.UpdateVertex(TopoDS::Vertex(aLocalShape),UV2,EWE2,Tol);
227 // BRep_Tool::Parameter(TopoDS::Vertex(),EWE2);
228 // B.UpdateVertex(TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)),
231 AsDes->Replace(V2,V1);
238 cout <<" distmin between VP : "<<distmin<<endl;
244 //=======================================================================
246 //=======================================================================
248 void GetEnlargedFaces(const TopoDS_Shape& theShape,
249 const BRepOffset_DataMapOfShapeOffset& theMapSF,
250 const TopTools_DataMapOfShapeShape& theMES,
251 TopTools_DataMapOfShapeShape& theFacesOrigins,
252 BRepAlgo_Image& theImage,
253 TopTools_ListOfShape& theLSF);
256 Standard_Boolean BuildShellsCompleteInter(const BOPCol_ListOfShape& theLF,
257 const BOPCol_IndexedDataMapOfShapeListOfShape& theOrigins,
258 BRepAlgo_Image& theImage,
259 TopoDS_Shape& theShells);
262 Standard_Boolean GetSubShapes(const TopoDS_Shape& theShape,
263 const TopAbs_ShapeEnum theSSType,
264 TopoDS_Shape& theResult);
267 void UpdateInitOffset(BRepAlgo_Image& myInitOffset,
268 BRepAlgo_Image& myImageOffset,
269 const TopoDS_Shape& myOffsetShape,
270 const TopAbs_ShapeEnum &theShapeType);
273 void RemoveShapes(TopoDS_Shape& theS,
274 const TopTools_ListOfShape& theLS);
277 Standard_Boolean IsSolid(const TopoDS_Shape& theS);
280 void UpdateHistory(const TopTools_ListOfShape& theLF,
281 BOPAlgo_Builder& theGF,
282 BRepAlgo_Image& theImage);
285 Standard_Boolean IsPlanar(const TopoDS_Shape& theS);
288 void TrimEdge(TopoDS_Edge& NE,
289 const Handle(BRepAlgo_AsDes)& AsDes2d,
290 Handle(BRepAlgo_AsDes)& AsDes,
291 TopTools_DataMapOfShapeShape& theETrimEInf);
294 void TrimEdges(const TopoDS_Shape& theShape,
295 const Standard_Real theOffset,
296 BRepOffset_DataMapOfShapeOffset& theMapSF,
297 TopTools_DataMapOfShapeShape& theMES,
298 TopTools_DataMapOfShapeShape& theBuild,
299 Handle(BRepAlgo_AsDes)& theAsDes,
300 Handle(BRepAlgo_AsDes)& theAsDes2d,
301 TopTools_IndexedMapOfShape& theNewEdges,
302 TopTools_DataMapOfShapeShape& theETrimEInf,
303 TopTools_DataMapOfShapeListOfShape& theEdgesOrigins);
306 void AppendToList(TopTools_ListOfShape& theL,
307 const TopoDS_Shape& theS);
309 static BRepOffset_Error checkSinglePoint(const Standard_Real theUParam,
310 const Standard_Real theVParam,
311 const Handle(Geom_Surface)& theSurf,
312 const NCollection_Vector<gp_Pnt>& theBadPoints);
314 //---------------------------------------------------------------------
315 static void UpdateTolerance ( TopoDS_Shape& myShape,
316 const TopTools_IndexedMapOfShape& myFaces);
317 static Standard_Real ComputeMaxDist(const gp_Pln& thePlane,
318 const Handle(Geom_Curve)& theCrv,
319 const Standard_Real theFirst,
320 const Standard_Real theLast);
322 static void CorrectSolid(TopoDS_Solid& theSol, TopTools_ListOfShape& theSolList);
323 //---------------------------------------------------------------------
325 static Standard_Boolean FindParameter(const TopoDS_Vertex& V,
326 const TopoDS_Edge& E,
329 // Search the vertex in the edge
331 Standard_Boolean rev = Standard_False;
333 TopAbs_Orientation orient = TopAbs_INTERNAL;
335 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
337 // if the edge has no vertices
338 // and is degenerated use the vertex orientation
341 if (!itv.More() && BRep_Tool::Degenerated(E)) {
342 orient = V.Orientation();
346 const TopoDS_Shape& Vcur = itv.Value();
347 if (V.IsSame(Vcur)) {
352 rev = E.Orientation() == TopAbs_REVERSED;
353 if (Vcur.Orientation() == V.Orientation()) {
361 if (!VF.IsNull()) orient = VF.Orientation();
365 if (orient == TopAbs_FORWARD) {
366 BRep_Tool::Range(E,f,l);
367 //return (rev) ? l : f;
369 return Standard_True;
372 else if (orient == TopAbs_REVERSED) {
373 BRep_Tool::Range(E,f,l);
374 //return (rev) ? f : l;
376 return Standard_True;
381 const Handle(Geom_Curve)& C = BRep_Tool::Curve(E,L,f,l);
382 L = L.Predivided(V.Location());
383 if (!C.IsNull() || BRep_Tool::Degenerated(E)) {
384 BRep_ListIteratorOfListOfPointRepresentation itpr
385 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
387 while (itpr.More()) {
388 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
389 if (pr->IsPointOnCurve(C,L)) {
390 Standard_Real p = pr->Parameter();
391 Standard_Real res = p;// SVV 4 nov 99 - to avoid warnings on Linux
393 // Closed curves RLE 16 june 94
394 if (Precision::IsNegativeInfinite(f))
396 //return pr->Parameter();//p;
398 return Standard_True;
400 if (Precision::IsPositiveInfinite(l))
402 //return pr->Parameter();//p;
404 return Standard_True;
406 gp_Pnt Pf = C->Value(f).Transformed(L.Transformation());
407 gp_Pnt Pl = C->Value(l).Transformed(L.Transformation());
408 Standard_Real tol = BRep_Tool::Tolerance(V);
409 if (Pf.Distance(Pl) < tol) {
410 if (Pf.Distance(BRep_Tool::Pnt(V)) < tol) {
411 if (V.Orientation() == TopAbs_FORWARD) res = f;//p = f;
412 else res = l;//p = l;
418 return Standard_True;
425 // let us try with the first pcurve
426 Handle(Geom2d_Curve) PC;
427 Handle(Geom_Surface) S;
428 BRep_Tool::CurveOnSurface(E,PC,S,L,f,l);
429 L = L.Predivided(V.Location());
430 BRep_ListIteratorOfListOfPointRepresentation itpr
431 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
433 while (itpr.More()) {
434 const Handle(BRep_PointRepresentation)& pr = itpr.Value();
435 if (pr->IsPointOnCurveOnSurface(PC,S,L)) {
436 Standard_Real p = pr->Parameter();
437 // Closed curves RLE 16 june 94
438 if (PC->IsClosed()) {
439 if ((p == PC->FirstParameter()) ||
440 (p == PC->LastParameter())) {
441 if (V.Orientation() == TopAbs_FORWARD) p = PC->FirstParameter();
442 else p = PC->LastParameter();
447 return Standard_True;
454 //throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
455 return Standard_False;
458 //=======================================================================
459 //function : GetEdgePoints
460 //purpose : gets the first, last and middle points of the edge
461 //=======================================================================
462 static void GetEdgePoints(const TopoDS_Edge& anEdge,
463 const TopoDS_Face& aFace,
464 gp_Pnt& fPnt, gp_Pnt& mPnt,
468 Handle(Geom2d_Curve) theCurve = BRep_Tool::CurveOnSurface( anEdge, aFace, f, l );
469 gp_Pnt2d fPnt2d = theCurve->Value(f);
470 gp_Pnt2d lPnt2d = theCurve->Value(l);
471 gp_Pnt2d mPnt2d = theCurve->Value(0.5*(f + l));
472 Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
473 fPnt = aSurf->Value(fPnt2d.X(),fPnt2d.Y());
474 lPnt = aSurf->Value(lPnt2d.X(),lPnt2d.Y());
475 mPnt = aSurf->Value(mPnt2d.X(), mPnt2d.Y());
478 //=======================================================================
479 //function : FillContours
480 //purpose : fills free boundary contours and faces connected (MapEF)
481 //=======================================================================
482 static void FillContours(const TopoDS_Shape& aShape,
483 const BRepOffset_Analyse& Analyser,
484 TopTools_DataMapOfShapeListOfShape& Contours,
485 TopTools_DataMapOfShapeShape& MapEF)
487 TopTools_ListOfShape Edges;
489 TopExp_Explorer Explo(aShape, TopAbs_FACE);
490 BRepTools_WireExplorer Wexp;
492 for (; Explo.More(); Explo.Next())
494 TopoDS_Face aFace = TopoDS::Face(Explo.Current());
495 TopoDS_Iterator itf(aFace);
496 for (; itf.More(); itf.Next())
498 TopoDS_Wire aWire = TopoDS::Wire(itf.Value());
499 for (Wexp.Init(aWire, aFace); Wexp.More(); Wexp.Next())
501 TopoDS_Edge anEdge = Wexp.Current();
502 if (BRep_Tool::Degenerated(anEdge))
504 const BRepOffset_ListOfInterval& Lint = Analyser.Type(anEdge);
505 if (!Lint.IsEmpty() && Lint.First().Type() == BRepOffset_FreeBoundary)
507 MapEF.Bind(anEdge, aFace);
508 Edges.Append(anEdge);
514 TopTools_ListIteratorOfListOfShape itl;
515 while (!Edges.IsEmpty())
517 TopoDS_Edge StartEdge = TopoDS::Edge(Edges.First());
519 TopoDS_Vertex StartVertex, CurVertex;
520 TopExp::Vertices(StartEdge, StartVertex, CurVertex, Standard_True);
521 TopTools_ListOfShape aContour;
522 aContour.Append(StartEdge);
523 while (!CurVertex.IsSame(StartVertex))
524 for (itl.Initialize(Edges); itl.More(); itl.Next())
526 TopoDS_Edge anEdge = TopoDS::Edge(itl.Value());
527 TopoDS_Vertex V1, V2;
528 TopExp::Vertices(anEdge, V1, V2);
529 if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex))
531 aContour.Append(anEdge);
532 CurVertex = (V1.IsSame(CurVertex))? V2 : V1;
537 Contours.Bind(StartVertex, aContour);
542 //-----------------------------------------------------------------------
544 //=======================================================================
545 //function : BRepOffset_MakeOffset
547 //=======================================================================
549 BRepOffset_MakeOffset::BRepOffset_MakeOffset()
551 myAsDes = new BRepAlgo_AsDes();
555 //=======================================================================
556 //function : BRepOffset_MakeOffset
558 //=======================================================================
560 BRepOffset_MakeOffset::BRepOffset_MakeOffset(const TopoDS_Shape& S,
561 const Standard_Real Offset,
562 const Standard_Real Tol,
563 const BRepOffset_Mode Mode,
564 const Standard_Boolean Inter,
565 const Standard_Boolean SelfInter,
566 const GeomAbs_JoinType Join,
567 const Standard_Boolean Thickening,
568 const Standard_Boolean RemoveIntEdges)
575 mySelfInter (SelfInter),
577 myThickening (Thickening),
578 myRemoveIntEdges(RemoveIntEdges),
579 myDone (Standard_False)
581 myAsDes = new BRepAlgo_AsDes();
586 //=======================================================================
587 //function : Initialize
589 //=======================================================================
591 void BRepOffset_MakeOffset::Initialize(const TopoDS_Shape& S,
592 const Standard_Real Offset,
593 const Standard_Real Tol,
594 const BRepOffset_Mode Mode,
595 const Standard_Boolean Inter,
596 const Standard_Boolean SelfInter,
597 const GeomAbs_JoinType Join,
598 const Standard_Boolean Thickening,
599 const Standard_Boolean RemoveIntEdges)
606 mySelfInter = SelfInter;
608 myThickening = Thickening;
609 myRemoveIntEdges = RemoveIntEdges;
610 myDone = Standard_False;
611 myIsPerformSewing = Standard_False;
612 myIsPlanar = Standard_False;
617 //=======================================================================
620 //=======================================================================
622 void BRepOffset_MakeOffset::Clear()
624 myOffsetShape.Nullify();
625 myInitOffsetFace .Clear();
626 myInitOffsetEdge .Clear();
627 myImageOffset .Clear();
629 myFaceOffset .Clear();
631 myDone = Standard_False;
634 //=======================================================================
637 //=======================================================================
639 void BRepOffset_MakeOffset::AddFace(const TopoDS_Face& F) {
644 myInitOffsetFace.SetRoot (F) ;
645 myInitOffsetFace.Bind (F,F);
646 myImageOffset.SetRoot (F) ;
649 //=======================================================================
650 //function : SetOffsetOnFace
652 //=======================================================================
654 void BRepOffset_MakeOffset::SetOffsetOnFace(const TopoDS_Face& F,
655 const Standard_Real Off)
657 if ( myFaceOffset.IsBound(F)) myFaceOffset.UnBind(F);
658 myFaceOffset.Bind(F,Off);
661 //=======================================================================
662 //function : RemoveCorks
664 //=======================================================================
666 static void RemoveCorks (TopoDS_Shape& S,
667 TopTools_IndexedMapOfShape& Faces)
672 //-----------------------------------------------------
673 // Construction of a shape without caps.
674 // and Orientation of caps as in shape S.
675 //-----------------------------------------------------
676 TopExp_Explorer exp(S,TopAbs_FACE);
677 for (; exp.More(); exp.Next()) {
678 const TopoDS_Shape& Cork = exp.Current();
679 if (!Faces.Contains(Cork)) {
683 //Faces.Remove (Cork);
684 //begin instead of Remove//
685 TopoDS_Shape LastShape = Faces(Faces.Extent());
687 if (Faces.FindIndex(Cork) != 0)
688 Faces.Substitute(Faces.FindIndex(Cork), LastShape);
689 //end instead of Remove //
690 Faces.Add(Cork); // to reset it with proper orientation.
696 DBRep::Set("myInit", SS);
701 //=======================================================================
702 //function : IsConnectedShell
704 //=======================================================================
705 static Standard_Boolean IsConnectedShell( const TopoDS_Shape& S )
707 BRepTools_Quilt Glue;
710 TopoDS_Shape SS = Glue.Shells();
711 TopExp_Explorer Explo( SS, TopAbs_SHELL );
714 return Standard_False;
716 return Standard_True;
720 //=======================================================================
721 //function : MakeList
723 //=======================================================================
725 static void MakeList (TopTools_ListOfShape& OffsetFaces,
726 const BRepAlgo_Image& myInitOffsetFace,
727 const TopTools_IndexedMapOfShape& myFaces)
729 TopTools_ListIteratorOfListOfShape itLOF(myInitOffsetFace.Roots());
730 for ( ; itLOF.More(); itLOF.Next()) {
731 const TopoDS_Shape& Root = itLOF.Value();
732 if (!myFaces.Contains(Root)) {
733 if (myInitOffsetFace.HasImage(Root)) {
734 OffsetFaces.Append(myInitOffsetFace.Image(Root).First());
740 //=======================================================================
743 //=======================================================================
745 static void EvalMax(const TopoDS_Shape& S, Standard_Real& Tol)
748 for (exp.Init(S,TopAbs_VERTEX); exp.More(); exp.Next()) {
749 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
750 Standard_Real TolV = BRep_Tool::Tolerance(V);
751 if (TolV > Tol) Tol = TolV;
756 //=======================================================================
757 //function : MakeOffsetShape
759 //=======================================================================
761 void BRepOffset_MakeOffset::MakeOffsetShape()
763 myDone = Standard_False;
765 // check if shape consists of only planar faces
766 myIsPlanar = IsPlanar(myShape);
767 //------------------------------------------
768 // Construction of myShape without caps.
769 //------------------------------------------
770 if(!myFaces.IsEmpty())
772 RemoveCorks (myShape,myFaces);
775 if (!CheckInputData())
777 // There is error in input data.
778 // Check Error() method.
782 TopAbs_State Side = TopAbs_IN;
783 if (myOffset < 0.) Side = TopAbs_OUT;
788 EvalMax(myShape,myTol);
789 // There are possible second variant: analytical continuation of arcsin.
790 Standard_Real TolAngleCoeff = Min(myTol / (Abs(myOffset * 0.5) + Precision::Confusion()), 1.0);
791 Standard_Real TolAngle = 4*ASin(TolAngleCoeff);
792 myAnalyse.Perform(myShape,TolAngle);
793 //---------------------------------------------------
794 // Construction of Offset from preanalysis.
795 //---------------------------------------------------
796 //----------------------------
797 // MaJ of SD Face - Offset
798 //----------------------------
801 if (myJoin == GeomAbs_Arc)
803 else if (myJoin == GeomAbs_Intersection)
804 BuildOffsetByInter();
808 // if (mySelfInter) SelfInter(Modif);
812 BRepOffset_Inter3d Inter(myAsDes,Side,myTol);
813 Intersection3D (Inter);
817 TopTools_IndexedMapOfShape& Modif = Inter.TouchedFaces();
818 TopTools_IndexedMapOfShape& NewEdges = Inter.NewEdges();
820 if (!Modif.IsEmpty()) Intersection2D (Modif,NewEdges);
821 //-------------------------------------------------------
822 // Unwinding 2D and reconstruction of modified faces
823 //----------------------------------------------------
825 //-----------------------------------------------------
826 // Reconstruction of non modified faces sharing
827 // reconstructed edges
828 //------------------------------------------------------
829 if (!Modif.IsEmpty()) MakeFaces (Modif);
834 //-------------------------
835 // Construction of shells.
836 //-------------------------
838 if (myOffsetShape.IsNull()) {
840 myDone = Standard_False;
847 //----------------------------------
848 // Remove INTERNAL edges if necessary
849 //----------------------------------
850 if (myRemoveIntEdges) {
851 RemoveInternalEdges();
853 //----------------------------------
854 // Coding of regularities.
855 //----------------------------------
857 //----------------------
858 // Creation of solids.
859 //----------------------
862 //-----------------------------
863 // MAJ Tolerance edge and Vertex
864 // ----------------------------
865 if (!myOffsetShape.IsNull()) {
866 UpdateTolerance (myOffsetShape,myFaces);
867 BRepLib::UpdateTolerances( myOffsetShape );
870 CorrectConicalFaces();
872 // Result solid should be computed in MakeOffset scope.
876 BRepBuilderAPI_Sewing aSew(myTol);
877 aSew.Add(myOffsetShape);
879 myOffsetShape = aSew.SewedShape();
882 // Offset shape expected to be really closed after sewing.
883 myOffsetShape.Closed(Standard_True);
887 myDone = Standard_True;
892 //=======================================================================
893 //function : MakeThickSolid
895 //=======================================================================
897 void BRepOffset_MakeOffset::MakeThickSolid()
899 //--------------------------------------------------------------
900 // Construction of shell parallel to shell (initial without cap).
901 //--------------------------------------------------------------
906 // Save return code and myDone state.
910 //--------------------------------------------------------------------
911 // Construction of a solid with the initial shell, parallel shell
913 //--------------------------------------------------------------------
914 if (!myFaces.IsEmpty())
919 Standard_Integer NbF = myFaces.Extent();
923 BRepTools_Quilt Glue;
924 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next())
927 Glue.Add (exp.Current());
929 Standard_Boolean YaResult = 0;
930 if (!myOffsetShape.IsNull())
932 for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next())
935 Glue.Add (exp.Current().Reversed());
940 cout << "OffsetShape does not contain a FACES." << endl;
947 cout << "OffsetShape is null!" << endl;
953 myDone = Standard_False;
954 myError = BRepOffset_UnknownError;
958 myOffsetShape = Glue.Shells();
959 for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next())
961 B.Add(Res,exp.Current());
963 Res.Closed(Standard_True);
966 // Test of Validity of the result of thick Solid
967 // more face than the initial solid.
968 Standard_Integer NbOF = 0;
969 for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next())
975 myDone = Standard_False;
976 myError = BRepOffset_UnknownError;
981 if (myOffset > 0 ) myOffsetShape.Reverse();
983 myDone = Standard_True;
986 //=======================================================================
989 //=======================================================================
991 Standard_Boolean BRepOffset_MakeOffset::IsDone() const
996 //=======================================================================
999 //=======================================================================
1001 BRepOffset_Error BRepOffset_MakeOffset::Error() const
1006 //=======================================================================
1009 //=======================================================================
1011 const TopoDS_Shape& BRepOffset_MakeOffset::Shape() const
1013 return myOffsetShape;
1016 //=======================================================================
1017 //function : MakeOffsetFaces
1019 //=======================================================================
1020 void BRepOffset_MakeOffset::MakeOffsetFaces(BRepOffset_DataMapOfShapeOffset& theMapSF)
1022 Standard_Real aCurOffset;
1023 TopTools_ListOfShape aLF;
1024 TopTools_DataMapOfShapeShape ShapeTgt;
1025 TopTools_ListIteratorOfListOfShape aItLF;
1027 Standard_Boolean OffsetOutside = (myOffset > 0.);
1029 BRepLib::SortFaces(myShape, aLF);
1031 aItLF.Initialize(aLF);
1032 for (; aItLF.More(); aItLF.Next()) {
1033 const TopoDS_Face& aF = TopoDS::Face(aItLF.Value());
1034 aCurOffset = myFaceOffset.IsBound(aF) ? myFaceOffset(aF) : myOffset;
1035 BRepOffset_Offset OF(aF, aCurOffset, ShapeTgt, OffsetOutside, myJoin);
1036 TopTools_ListOfShape Let;
1037 myAnalyse.Edges(aF,BRepOffset_Tangent,Let);
1038 TopTools_ListIteratorOfListOfShape itl(Let);
1039 for (; itl.More(); itl.Next()) {
1040 const TopoDS_Edge& Cur = TopoDS::Edge(itl.Value());
1041 if ( !ShapeTgt.IsBound(Cur)) {
1042 TopoDS_Shape aLocalShape = OF.Generated(Cur);
1043 const TopoDS_Edge& OTE = TopoDS::Edge(aLocalShape);
1044 ShapeTgt.Bind(Cur,OF.Generated(Cur));
1045 TopoDS_Vertex V1,V2,OV1,OV2;
1046 TopExp::Vertices (Cur,V1,V2);
1047 TopExp::Vertices (OTE,OV1,OV2);
1048 TopTools_ListOfShape LE;
1049 if (!ShapeTgt.IsBound(V1)) {
1050 myAnalyse.Edges(V1,BRepOffset_Tangent,LE);
1051 const TopTools_ListOfShape& LA =myAnalyse.Ancestors(V1);
1052 if (LE.Extent() == LA.Extent())
1053 ShapeTgt.Bind(V1,OV1);
1055 if (!ShapeTgt.IsBound(V2)) {
1057 myAnalyse.Edges(V2,BRepOffset_Tangent,LE);
1058 const TopTools_ListOfShape& LA =myAnalyse.Ancestors(V2);
1059 if (LE.Extent() == LA.Extent())
1060 ShapeTgt.Bind(V2,OV2);
1064 theMapSF.Bind(aF,OF);
1068 //=======================================================================
1069 //function : BuildOffsetByInter
1071 //=======================================================================
1072 void BRepOffset_MakeOffset::BuildOffsetByInter()
1076 cout << " CONSTRUCTION OF OFFSETS :" << endl;
1082 TopExp_Explorer Exp, Exp2, ExpC;
1083 TopTools_ListIteratorOfListOfShape itLF;
1085 //--------------------------------------------------------
1086 // Construction of faces parallel to initial faces
1087 //--------------------------------------------------------
1088 BRepOffset_DataMapOfShapeOffset MapSF;
1089 MakeOffsetFaces(MapSF);
1090 //--------------------------------------------------------------------
1091 // MES : Map of OffsetShape -> Extended Shapes.
1092 // Build : Map of Initial SS -> OffsetShape build by Inter.
1093 // can be an edge or a compound of edges
1094 //---------------------------------------------------------------------
1095 TopTools_DataMapOfShapeShape MES;
1096 TopTools_DataMapOfShapeShape Build;
1097 TopTools_ListOfShape Failed;
1098 TopAbs_State Side = TopAbs_IN;
1099 Handle(BRepAlgo_AsDes) AsDes = new BRepAlgo_AsDes();
1101 //-------------------------------------------------------------------
1102 // Extension of faces and calculation of new edges of intersection.
1103 //-------------------------------------------------------------------
1104 Standard_Boolean ExtentContext = 0;
1105 if (myOffset > 0) ExtentContext = 1;
1107 BRepOffset_Inter3d Inter3 (AsDes,Side,myTol);
1108 // Intersection between parallel faces
1109 Inter3.ConnexIntByInt(myShape,MapSF,myAnalyse,MES,Build,Failed,myIsPlanar);
1110 // Intersection with caps.
1111 Inter3.ContextIntByInt(myFaces,ExtentContext,MapSF,myAnalyse,MES,Build,Failed,myIsPlanar);
1114 //---------------------------------------------------------------------------------
1115 // Extension of neighbor edges of new edges and intersection between neighbors.
1116 //--------------------------------------------------------------------------------
1117 Handle(BRepAlgo_AsDes) AsDes2d = new BRepAlgo_AsDes();
1118 IntersectEdges(myShape, MapSF, MES, Build, AsDes, AsDes2d);
1119 //-----------------------------------------------------------
1120 // Great restriction of new edges and update of AsDes.
1121 //------------------------------------------ ----------------
1122 TopTools_DataMapOfShapeListOfShape anEdgesOrigins; // offset edge - initial edges
1123 TopTools_IndexedMapOfShape NewEdges;
1124 TopTools_DataMapOfShapeShape aETrimEInf; // trimmed - not trimmed edges
1126 //Map of edges obtained after FACE-FACE (offsetted) intersection.
1127 //Key1 is edge trimmed by intersection points with other edges;
1128 //Item is not-trimmed edge.
1129 TrimEdges(myShape, myOffset, MapSF, MES, Build, AsDes, AsDes2d, NewEdges, aETrimEInf, anEdgesOrigins);
1131 //---------------------------------
1132 // Intersection 2D on //
1133 //---------------------------------
1134 TopTools_IndexedDataMapOfShapeListOfShape aDMVV;
1135 TopTools_DataMapOfShapeShape aFacesOrigins; // offset face - initial face
1136 TopTools_ListOfShape LFE;
1137 BRepAlgo_Image IMOE;
1138 GetEnlargedFaces(myShape, MapSF, MES, aFacesOrigins, IMOE, LFE);
1140 TopTools_ListIteratorOfListOfShape itLFE(LFE);
1141 for (; itLFE.More(); itLFE.Next())
1143 const TopoDS_Face& NEF = TopoDS::Face(itLFE.Value());
1144 Standard_Real aCurrFaceTol = BRep_Tool::Tolerance(NEF);
1145 BRepOffset_Inter2d::Compute(AsDes, NEF, NewEdges, aCurrFaceTol, aDMVV);
1147 //----------------------------------------------
1148 // Intersections 2d on caps.
1149 //----------------------------------------------
1151 for (i = 1; i <= myFaces.Extent(); i++)
1153 const TopoDS_Face& Cork = TopoDS::Face(myFaces(i));
1154 Standard_Real aCurrFaceTol = BRep_Tool::Tolerance(Cork);
1155 BRepOffset_Inter2d::Compute(AsDes, Cork, NewEdges, aCurrFaceTol, aDMVV);
1158 BRepOffset_Inter2d::FuseVertices(aDMVV, AsDes);
1159 //-------------------------------
1160 // Unwinding of extended Faces.
1161 //-------------------------------
1163 TopTools_MapOfShape aMFDone;
1165 if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) {
1166 BuildSplitsOfExtendedFaces(LFE, AsDes, anEdgesOrigins, aFacesOrigins, aETrimEInf, IMOE);
1168 TopTools_ListIteratorOfListOfShape aItLF(LFE);
1169 for (; aItLF.More(); aItLF.Next()) {
1170 const TopoDS_Shape& aS = aItLF.Value();
1175 myMakeLoops.Build(LFE, AsDes, IMOE);
1179 TopTools_IndexedMapOfShape COES;
1181 //---------------------------
1182 // MAJ SD. for faces //
1183 //---------------------------
1184 for (Exp.Init(myShape,TopAbs_FACE) ; Exp.More(); Exp.Next()) {
1185 const TopoDS_Shape& FI = Exp.Current();
1186 myInitOffsetFace.SetRoot(FI);
1187 TopoDS_Face OF = MapSF(FI).Face();
1188 if (MES.IsBound(OF)) {
1189 OF = TopoDS::Face(MES(OF));
1190 if (IMOE.HasImage(OF)) {
1191 const TopTools_ListOfShape& LOFE = IMOE.Image(OF);
1192 myInitOffsetFace.Bind(FI,LOFE);
1193 for (itLF.Initialize(LOFE); itLF.More(); itLF.Next()) {
1194 const TopoDS_Shape& OFE = itLF.Value();
1195 myImageOffset.SetRoot(OFE);
1198 sprintf(name,"AF_%d",NbAF++);
1199 DBRep::Set(name,OFE);
1202 TopTools_MapOfShape View;
1203 for (Exp2.Init(OFE.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1204 Exp2.More(); Exp2.Next()) {
1205 const TopoDS_Edge& COE = TopoDS::Edge(Exp2.Current());
1207 myAsDes->Add (OFE,COE);
1210 sprintf(name,"AE_%d",NbAE++);
1211 DBRep::Set(name,COE);
1216 if (!myAsDes->HasDescendant(COE)) {
1217 TopoDS_Vertex CV1,CV2;
1218 TopExp::Vertices(COE,CV1,CV2);
1219 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1220 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1227 if (aMFDone.Contains(OF)) {
1231 myInitOffsetFace.Bind(FI,OF);
1232 myImageOffset.SetRoot(OF);
1235 sprintf(name,"AF_%d",NbAF++);
1236 DBRep::Set(name,OF);
1239 const TopTools_ListOfShape& LE = AsDes->Descendant(OF);
1240 for (itLF.Initialize(LE) ; itLF.More(); itLF.Next()) {
1241 const TopoDS_Edge& OE = TopoDS::Edge(itLF.Value());
1242 if (IMOE.HasImage(OE)) {
1243 const TopTools_ListOfShape& LOE = IMOE.Image(OE);
1244 TopTools_ListIteratorOfListOfShape itLOE(LOE);
1245 for (; itLOE.More(); itLOE.Next()) {
1246 TopoDS_Shape aLocalShape = itLOE.Value().Oriented(OE.Orientation());
1247 const TopoDS_Edge& COE = TopoDS::Edge(aLocalShape);
1248 // const TopoDS_Edge& COE = TopoDS::Edge(itLOE.Value().Oriented(OE.Orientation()));
1249 myAsDes->Add(OF,COE);
1252 sprintf(name,"AE_%d",NbAE++);
1253 DBRep::Set(name,COE);
1258 if (!myAsDes->HasDescendant(COE)) {
1259 TopoDS_Vertex CV1,CV2;
1260 TopExp::Vertices(COE,CV1,CV2);
1261 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1262 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1267 myAsDes->Add(OF,OE);
1270 sprintf(name,"AE_%d",NbAE++);
1271 DBRep::Set(name,OE);
1276 const TopTools_ListOfShape& LV = AsDes->Descendant(OE);
1277 myAsDes->Add(OE,LV);
1283 myInitOffsetFace.Bind(FI,OF);
1284 myImageOffset.SetRoot(OF);
1285 TopTools_MapOfShape View;
1286 for (Exp2.Init(OF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1287 Exp2.More(); Exp2.Next()) {
1289 const TopoDS_Edge& COE = TopoDS::Edge(Exp2.Current());
1290 myAsDes->Add (OF,COE);
1293 sprintf(name,"AE_%d",NbAE++);
1294 DBRep::Set(name,COE);
1299 if (View.Add(Exp2.Current())) {
1300 if (!myAsDes->HasDescendant(COE)) {
1301 TopoDS_Vertex CV1,CV2;
1302 TopExp::Vertices(COE,CV1,CV2);
1303 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1304 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1310 // Modified by skv - Tue Mar 15 16:20:43 2005
1311 // Add methods for supporting history.
1312 TopTools_MapOfShape aMapEdges;
1314 for (Exp.Init(myShape,TopAbs_FACE) ; Exp.More(); Exp.Next()) {
1315 const TopoDS_Shape& aFaceRef = Exp.Current();
1317 Exp2.Init(aFaceRef.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1319 for (; Exp2.More(); Exp2.Next()) {
1320 const TopoDS_Shape& anEdgeRef = Exp2.Current();
1322 if (aMapEdges.Add(anEdgeRef)) {
1323 myInitOffsetEdge.SetRoot(anEdgeRef);
1324 if (Build.IsBound(anEdgeRef)) {
1325 TopoDS_Shape aNewShape = Build(anEdgeRef);
1327 if (aNewShape.ShapeType() == TopAbs_EDGE) {
1328 if (IMOE.HasImage(aNewShape)) {
1329 const TopTools_ListOfShape& aListNewE = IMOE.Image(aNewShape);
1331 myInitOffsetEdge.Bind (anEdgeRef, aListNewE);
1333 myInitOffsetEdge.Bind (anEdgeRef, aNewShape);
1334 } else { // aNewShape != TopAbs_EDGE
1335 TopTools_ListOfShape aListNewEdge;
1337 for (ExpC.Init(aNewShape, TopAbs_EDGE); ExpC.More(); ExpC.Next()) {
1338 const TopoDS_Shape &aResEdge = ExpC.Current();
1340 if (IMOE.HasImage(aResEdge)) {
1341 const TopTools_ListOfShape& aListNewE = IMOE.Image(aResEdge);
1342 TopTools_ListIteratorOfListOfShape aNewEIter(aListNewE);
1344 for (; aNewEIter.More(); aNewEIter.Next())
1345 aListNewEdge.Append(aNewEIter.Value());
1347 aListNewEdge.Append(aResEdge);
1350 myInitOffsetEdge.Bind (anEdgeRef, aListNewEdge);
1353 else { // Free boundary.
1354 TopoDS_Shape aNewEdge = MapSF(aFaceRef).Generated(anEdgeRef);
1356 if (MES.IsBound(aNewEdge))
1357 aNewEdge = MES(aNewEdge);
1359 if (IMOE.HasImage(aNewEdge)) {
1360 const TopTools_ListOfShape& aListNewE = IMOE.Image(aNewEdge);
1362 myInitOffsetEdge.Bind (anEdgeRef, aListNewE);
1364 myInitOffsetEdge.Bind (anEdgeRef, aNewEdge);
1369 // Modified by skv - Tue Mar 15 16:20:43 2005
1371 //---------------------------
1373 //---------------------------
1374 //TopTools_MapOfShape View;
1375 for (i = 1; i <= myFaces.Extent(); i++) {
1376 const TopoDS_Shape& Cork = myFaces(i);
1377 const TopTools_ListOfShape& LE = AsDes->Descendant(Cork);
1378 for (itLF.Initialize(LE) ; itLF.More(); itLF.Next()) {
1379 const TopoDS_Edge& OE = TopoDS::Edge(itLF.Value());
1380 if (IMOE.HasImage(OE)) {
1381 const TopTools_ListOfShape& LOE = IMOE.Image(OE);
1382 TopTools_ListIteratorOfListOfShape itLOE(LOE);
1383 for (; itLOE.More(); itLOE.Next()) {
1384 const TopoDS_Edge& COE = TopoDS::Edge(itLOE.Value());
1385 myAsDes->Add(Cork,COE.Oriented(OE.Orientation())) ;
1388 sprintf(name,"AE_%d",NbAE++);
1389 DBRep::Set(name,COE);
1394 if (!myAsDes->HasDescendant(COE)) {
1395 TopoDS_Vertex CV1,CV2;
1396 TopExp::Vertices(COE,CV1,CV2);
1397 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1398 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1403 myAsDes->Add(Cork,OE);
1404 if (AsDes->HasDescendant(OE)) {
1405 myAsDes->Add(OE,AsDes->Descendant(OE));
1409 sprintf(name,"AE_%d",NbAE++);
1410 DBRep::Set(name,OE);
1419 DEBVerticesControl (COES,myAsDes);
1420 if ( ChronBuild) Clock.Show();
1424 //=======================================================================
1425 //function : BuildOffsetByArc
1427 //=======================================================================
1428 void BRepOffset_MakeOffset::BuildOffsetByArc()
1432 cout << " CONSTRUCTION OF OFFSETS :" << endl;
1438 TopExp_Explorer Exp;
1439 TopTools_ListIteratorOfListOfShape itLF;
1440 TopTools_MapOfShape Done;
1442 //--------------------------------------------------------
1443 // Construction of faces parallel to initial faces
1444 //--------------------------------------------------------
1445 BRepOffset_DataMapOfShapeOffset MapSF;
1446 MakeOffsetFaces(MapSF);
1447 //--------------------------------------------------------
1448 // Construction of tubes on edge.
1449 //--------------------------------------------------------
1450 BRepOffset_Type OT = BRepOffset_Convex;
1451 if (myOffset < 0.) OT = BRepOffset_Concave;
1453 for (Exp.Init(myShape,TopAbs_EDGE); Exp.More(); Exp.Next()) {
1454 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1456 const TopTools_ListOfShape& Anc = myAnalyse.Ancestors(E);
1457 if (Anc.Extent() == 2) {
1458 const BRepOffset_ListOfInterval& L = myAnalyse.Type(E);
1459 if (!L.IsEmpty() && L.First().Type() == OT) {
1460 Standard_Real CurOffset = myOffset;
1461 if ( myFaceOffset.IsBound(Anc.First()))
1462 CurOffset = myFaceOffset(Anc.First());
1463 TopoDS_Shape aLocalShapeGen = MapSF(Anc.First()).Generated(E);
1464 TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShapeGen);
1465 aLocalShapeGen = MapSF(Anc.Last()).Generated(E);
1466 TopoDS_Edge EOn2 = TopoDS::Edge(aLocalShapeGen);
1467 // TopoDS_Edge EOn1 = TopoDS::Edge(MapSF(Anc.First()).Generated(E));
1468 // TopoDS_Edge EOn2 = TopoDS::Edge(MapSF(Anc.Last()) .Generated(E));
1469 // find if exits tangent edges in the original shape
1470 TopoDS_Edge E1f, E1l;
1471 TopoDS_Vertex V1f, V1l;
1472 TopExp::Vertices(E,V1f,V1l);
1473 TopTools_ListOfShape TangE;
1474 myAnalyse.TangentEdges(E,V1f,TangE);
1475 // find if the pipe on the tangent edges are soon created.
1476 TopTools_ListIteratorOfListOfShape itl(TangE);
1477 Standard_Boolean Find = Standard_False;
1478 for ( ; itl.More() && !Find; itl.Next()) {
1479 if ( MapSF.IsBound(itl.Value())) {
1480 TopoDS_Shape aLocalShape = MapSF(itl.Value()).Generated(V1f);
1481 E1f = TopoDS::Edge(aLocalShape);
1482 // E1f = TopoDS::Edge(MapSF(itl.Value()).Generated(V1f));
1483 Find = Standard_True;
1487 myAnalyse.TangentEdges(E,V1l,TangE);
1488 // find if the pipe on the tangent edges are soon created.
1489 itl.Initialize(TangE);
1490 Find = Standard_False;
1491 for ( ; itl.More() && !Find; itl.Next()) {
1492 if ( MapSF.IsBound(itl.Value())) {
1493 TopoDS_Shape aLocalShape = MapSF(itl.Value()).Generated(V1l);
1494 E1l = TopoDS::Edge(aLocalShape);
1495 // E1l = TopoDS::Edge(MapSF(itl.Value()).Generated(V1l));
1496 Find = Standard_True;
1499 BRepOffset_Offset OF (E,EOn1,EOn2,CurOffset,E1f, E1l);
1504 // ----------------------
1506 // ----------------------
1507 TopoDS_Shape aLocalShape = MapSF(Anc.First()).Generated(E);
1508 TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShape);
1509 /// TopoDS_Edge EOn1 = TopoDS::Edge(MapSF(Anc.First()).Generated(E));
1510 myInitOffsetEdge.SetRoot(E); // skv: supporting history.
1511 myInitOffsetEdge.Bind (E,EOn1);
1516 //--------------------------------------------------------
1517 // Construction of spheres on vertex.
1518 //--------------------------------------------------------
1520 TopTools_ListIteratorOfListOfShape it;
1522 for (Exp.Init(myShape,TopAbs_VERTEX); Exp.More(); Exp.Next()) {
1523 const TopoDS_Vertex& V = TopoDS::Vertex (Exp.Current());
1525 const TopTools_ListOfShape& LA = myAnalyse.Ancestors(V);
1526 TopTools_ListOfShape LE;
1527 myAnalyse.Edges(V,OT,LE);
1529 if (LE.Extent() >= 3 && LE.Extent() == LA.Extent()) {
1530 TopTools_ListOfShape LOE;
1531 //--------------------------------------------------------
1532 // Return connected edges on tubes.
1533 //--------------------------------------------------------
1534 for (it.Initialize(LE) ; it.More(); it.Next()) {
1535 LOE.Append(MapSF(it.Value()).Generated(V).Reversed());
1537 //----------------------
1538 // construction sphere.
1539 //-----------------------
1540 const TopTools_ListOfShape& LLA = myAnalyse.Ancestors(LA.First());
1541 const TopoDS_Shape& FF = LLA.First();
1542 Standard_Real CurOffset = myOffset;
1543 if ( myFaceOffset.IsBound(FF))
1544 CurOffset = myFaceOffset(FF);
1546 BRepOffset_Offset OF(V,LOE,CurOffset);
1549 //--------------------------------------------------------------
1550 // Particular processing if V is at least a free border.
1551 //-------------------------------------------------------------
1552 TopTools_ListOfShape LBF;
1553 myAnalyse.Edges(V,BRepOffset_FreeBoundary,LBF);
1554 if (!LBF.IsEmpty()) {
1555 Standard_Boolean First = Standard_True;
1556 for (it.Initialize(LE) ; it.More(); it.Next()) {
1558 myInitOffsetEdge.SetRoot(V); // skv: supporting history.
1559 myInitOffsetEdge.Bind(V,MapSF(it.Value()).Generated(V));
1560 First = Standard_False;
1563 myInitOffsetEdge.Add(V,MapSF(it.Value()).Generated(V));
1570 //------------------------------------------------------------
1571 // Extension of parallel faces to the context.
1572 // Extended faces are ordered in DS and removed from MapSF.
1573 //------------------------------------------------------------
1574 if (!myFaces.IsEmpty()) ToContext (MapSF);
1576 //------------------------------------------------------
1578 //------------------------------------------------------
1579 BRepOffset_Type RT = BRepOffset_Concave;
1580 if (myOffset < 0.) RT = BRepOffset_Convex;
1581 BRepOffset_DataMapIteratorOfDataMapOfShapeOffset It(MapSF);
1582 for ( ; It.More(); It.Next()) {
1583 const TopoDS_Shape& SI = It.Key();
1584 const BRepOffset_Offset& SF = It.Value();
1585 if (SF.Status() == BRepOffset_Reversed ||
1586 SF.Status() == BRepOffset_Degenerated ) {
1587 //------------------------------------------------
1588 // Degenerated or returned faces are not stored.
1589 //------------------------------------------------
1593 const TopoDS_Face& OF = It.Value().Face();
1594 myInitOffsetFace.Bind (SI,OF);
1595 myInitOffsetFace.SetRoot (SI); // Initial<-> Offset
1596 myImageOffset.SetRoot (OF); // FaceOffset root of images
1598 if (SI.ShapeType() == TopAbs_FACE) {
1599 for (Exp.Init(SI.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1600 Exp.More(); Exp.Next()) {
1601 //--------------------------------------------------------------------
1602 // To each face are associatedthe edges that restrict that
1603 // The edges that do not generate tubes or are not tangent
1604 // to two faces are removed.
1605 //--------------------------------------------------------------------
1606 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1607 const BRepOffset_ListOfInterval& L = myAnalyse.Type(E);
1608 if (!L.IsEmpty() && L.First().Type() != RT) {
1609 TopAbs_Orientation OO = E.Orientation();
1610 TopoDS_Shape aLocalShape = It.Value().Generated(E);
1611 TopoDS_Edge OE = TopoDS::Edge(aLocalShape);
1612 // TopoDS_Edge OE = TopoDS::Edge(It.Value().Generated(E));
1613 myAsDes->Add (OF,OE.Oriented(OO));
1618 for (Exp.Init(OF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1619 Exp.More(); Exp.Next()) {
1620 myAsDes->Add (OF,Exp.Current());
1626 if ( ChronBuild) Clock.Show();
1632 //=======================================================================
1633 //function : SelfInter
1635 //=======================================================================
1637 void BRepOffset_MakeOffset::SelfInter(TopTools_MapOfShape& /*Modif*/)
1641 cout << " AUTODEBOUCLAGE:" << endl;
1647 throw Standard_NotImplemented();
1651 //=======================================================================
1652 //function : ToContext
1654 //=======================================================================
1656 void BRepOffset_MakeOffset::ToContext (BRepOffset_DataMapOfShapeOffset& MapSF)
1658 TopTools_DataMapOfShapeShape Created;
1659 TopTools_DataMapOfShapeShape MEF;
1660 TopTools_IndexedMapOfShape FacesToBuild;
1661 TopTools_ListIteratorOfListOfShape itl;
1662 TopExp_Explorer exp;
1664 // TopAbs_State Side = TopAbs_IN;
1665 // if (myOffset < 0.) Side = TopAbs_OUT;
1667 TopAbs_State Side = TopAbs_OUT;
1671 for (i = 1; i <= myFaces.Extent(); i++) {
1672 const TopoDS_Face& CF = TopoDS::Face(myFaces(i));
1673 for (exp.Init(CF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1674 exp.More(); exp.Next()) {
1675 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1676 if (!myAnalyse.HasAncestor(E)) {
1677 //----------------------------------------------------------------
1678 // The edges of context faces that are not in the initial shape
1679 // can appear in the result.
1680 //----------------------------------------------------------------
1681 //myAsDes->Add(CF,E);
1687 //--------------------------------------------------------
1688 // Determine the edges and faces reconstructed by
1690 //---------------------------------------------------------
1692 for (j = 1; j <= myFaces.Extent(); j++) {
1693 const TopoDS_Face& CF = TopoDS::Face(myFaces(j));
1694 for (exp.Init(CF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1695 exp.More(); exp.Next()) {
1696 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1697 if (myAnalyse.HasAncestor(E)) {
1698 const TopTools_ListOfShape& LEA = myAnalyse.Ancestors(E);
1699 for (itl.Initialize(LEA); itl.More(); itl.Next()) {
1700 const BRepOffset_Offset& OF = MapSF(itl.Value());
1701 FacesToBuild.Add(itl.Value());
1702 MEF.Bind(OF.Generated(E),CF);
1705 TopExp::Vertices(E,V[0],V[1]);
1706 for (Standard_Integer i = 0; i < 2; i++) {
1707 const TopTools_ListOfShape& LVA = myAnalyse.Ancestors(V[i]);
1708 for ( itl.Initialize(LVA); itl.More(); itl.Next()) {
1709 const TopoDS_Edge& EV = TopoDS::Edge(itl.Value());
1710 if (MapSF.IsBound(EV)) {
1711 const BRepOffset_Offset& OF = MapSF(EV);
1712 FacesToBuild.Add(EV);
1713 MEF.Bind(OF.Generated(V[i]),CF);
1720 //---------------------------
1721 // Reconstruction of faces.
1722 //---------------------------
1724 BRepOffset_Type RT = BRepOffset_Concave;
1725 if (myOffset < 0.) RT = BRepOffset_Convex;
1727 TopAbs_Orientation Or;
1729 for (j = 1; j <= FacesToBuild.Extent(); j++) {
1730 const TopoDS_Shape& S = FacesToBuild(j);
1731 BRepOffset_Offset BOF;
1733 F = TopoDS::Face(BOF.Face());
1734 BRepOffset_Tool::ExtentFace(F,Created,MEF,Side,myTol,NF);
1739 myInitOffsetFace.Bind (S,NF);
1740 myInitOffsetFace.SetRoot (S); // Initial<-> Offset
1741 myImageOffset.SetRoot (NF);
1743 if (S.ShapeType() == TopAbs_FACE) {
1744 for (exp.Init(S.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1745 exp.More(); exp.Next()) {
1747 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1748 const BRepOffset_ListOfInterval& L = myAnalyse.Type(E);
1749 OE = BOF.Generated(E);
1750 Or = E.Orientation();
1752 if (!L.IsEmpty() && L.First().Type() != RT) {
1753 if (Created.IsBound(OE)) {
1755 if (NE.Orientation() == TopAbs_REVERSED)
1756 NE.Orientation(TopAbs::Reverse(Or));
1759 myAsDes->Add(NF,NE);
1762 myAsDes->Add(NF,OE);
1768 //------------------
1770 //---------------------
1771 for (exp.Init(NF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1772 exp.More(); exp.Next()) {
1773 myAsDes->Add (NF,exp.Current());
1779 //------------------
1781 //------------------
1782 TopTools_DataMapIteratorOfDataMapOfShapeShape itc;
1783 for (itc.Initialize(Created); itc.More(); itc.Next()) {
1786 if (myInitOffsetEdge.IsImage(OE)) {
1787 TopoDS_Shape E = myInitOffsetEdge.ImageFrom (OE);
1788 Or = myInitOffsetEdge.Image(E).First().Orientation();
1789 if (NE.Orientation() == TopAbs_REVERSED)
1790 NE.Orientation(TopAbs::Reverse(Or));
1793 myInitOffsetEdge.Remove(OE);
1794 myInitOffsetEdge.Bind(E,NE);
1800 //=======================================================================
1801 //function : UpdateFaceOffset
1803 //=======================================================================
1805 void BRepOffset_MakeOffset::UpdateFaceOffset()
1807 TopTools_MapOfShape M;
1808 TopTools_DataMapOfShapeReal CopiedMap;
1809 CopiedMap.Assign(myFaceOffset);
1810 TopTools_DataMapIteratorOfDataMapOfShapeReal it(CopiedMap);
1812 BRepOffset_Type RT = BRepOffset_Convex;
1813 if (myOffset < 0.) RT = BRepOffset_Concave;
1815 for ( ; it.More(); it.Next()) {
1816 const TopoDS_Face& F = TopoDS::Face(it.Key());
1817 Standard_Real CurOffset = CopiedMap(F);
1818 if ( !M.Add(F)) continue;
1821 Build.MakeCompound(Co);
1822 TopTools_MapOfShape Dummy;
1824 if (myJoin == GeomAbs_Arc)
1825 myAnalyse.AddFaces(F,Co,Dummy,BRepOffset_Tangent,RT);
1827 myAnalyse.AddFaces(F,Co,Dummy,BRepOffset_Tangent);
1829 TopExp_Explorer exp(Co,TopAbs_FACE);
1830 for (; exp.More(); exp.Next()) {
1831 const TopoDS_Face& FF = TopoDS::Face(exp.Current());
1832 if ( !M.Add(FF)) continue;
1833 if ( myFaceOffset.IsBound(FF))
1834 myFaceOffset.UnBind(FF);
1835 myFaceOffset.Bind(FF,CurOffset);
1840 //=======================================================================
1841 //function : CorrectConicalFaces
1843 //=======================================================================
1845 void BRepOffset_MakeOffset::CorrectConicalFaces()
1847 if(myOffsetShape.IsNull())
1852 TopTools_SequenceOfShape Cones;
1853 TopTools_SequenceOfShape Circs;
1854 TopTools_SequenceOfShape Seams;
1855 Standard_Real TolApex = 1.e-5;
1859 TopTools_DataMapOfShapeListOfShape FacesOfCone;
1860 //TopTools_DataMapOfShapeShape DegEdges;
1861 TopExp_Explorer Explo( myOffsetShape, TopAbs_FACE );
1862 if (myJoin == GeomAbs_Arc)
1864 for (; Explo.More(); Explo.Next())
1866 TopoDS_Face aFace = TopoDS::Face( Explo.Current() );
1867 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( aFace );
1868 //if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
1869 //aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface(); //???
1871 TopTools_IndexedMapOfShape Emap;
1872 TopExp::MapShapes( aFace, TopAbs_EDGE, Emap );
1873 for (i = 1; i <= Emap.Extent(); i++)
1875 TopoDS_Edge anEdge = TopoDS::Edge( Emap(i) );
1876 //Standard_Real f, l;
1877 //Handle(Geom_Curve) theCurve = BRep_Tool::Curve( anEdge, f, l );
1878 //Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
1879 if (BRep_Tool::Degenerated(anEdge))
1881 //Check if anEdge is a really degenerated edge or not
1882 BRepAdaptor_Curve BACurve(anEdge, aFace);
1883 gp_Pnt Pfirst, Plast, Pmid;
1884 Pfirst = BACurve.Value(BACurve.FirstParameter());
1885 Plast = BACurve.Value(BACurve.LastParameter());
1886 Pmid = BACurve.Value((BACurve.FirstParameter()+BACurve.LastParameter())/2.);
1887 if (Pfirst.Distance(Plast) <= TolApex &&
1888 Pfirst.Distance(Pmid) <= TolApex)
1890 //Cones.Append( aFace );
1891 //Circs.Append( anEdge );
1892 //TopoDS_Vertex Vdeg = TopExp::FirstVertex( anEdge );
1893 TopoDS_Edge OrEdge =
1894 TopoDS::Edge( myInitOffsetEdge.Root( anEdge) );
1895 TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
1896 if ( FacesOfCone.IsBound(VF) )
1898 //add a face to the existing list
1899 TopTools_ListOfShape& aFaces = FacesOfCone.ChangeFind(VF);
1900 aFaces.Append (aFace);
1901 //DegEdges.Bind(aFace, anEdge);
1905 //the vertex is not in the map => create a new key and items
1906 TopTools_ListOfShape aFaces;
1907 aFaces.Append (aFace);
1908 FacesOfCone.Bind(VF, aFaces);
1909 //DegEdges.Bind(aFace, anEdge);
1912 } //for (i = 1; i <= Emap.Extent(); i++)
1913 } //for (; fexp.More(); fexp.Next())
1914 } //if (myJoin == GeomAbs_Arc)
1916 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape Cone(FacesOfCone);
1919 Standard_Boolean IsModified = Standard_False;
1920 for (; Cone.More(); Cone.Next() ) {
1921 gp_Sphere theSphere;
1922 Handle(Geom_SphericalSurface) aSphSurf;
1923 TopoDS_Wire SphereWire;
1924 BB.MakeWire(SphereWire);
1925 TopoDS_Vertex anApex = TopoDS::Vertex(Cone.Key());
1926 const TopTools_ListOfShape& Faces = Cone.Value(); //FacesOfCone(anApex);
1927 TopTools_ListIteratorOfListOfShape itFaces(Faces);
1928 Standard_Boolean isFirstFace = Standard_True;
1930 TopoDS_Vertex theFirstVertex, CurFirstVertex;
1931 for (; itFaces.More(); itFaces.Next())
1933 TopoDS_Face aFace = TopoDS::Face(itFaces.Value()); //TopoDS::Face(Faces.First());
1934 TopoDS_Edge DegEdge; // = TopoDS::Edge(DegEdges(aFace));
1935 for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next())
1937 DegEdge = TopoDS::Edge(Explo.Current());
1938 if (BRep_Tool::Degenerated(DegEdge))
1940 TopoDS_Edge OrEdge = TopoDS::Edge( myInitOffsetEdge.Root( DegEdge) );
1941 TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
1942 if (VF.IsSame(anApex))
1946 TopoDS_Shape aLocalDegShape = DegEdge.Oriented(TopAbs_FORWARD);
1947 TopoDS_Edge CurEdge = TopoDS::Edge(aLocalDegShape);
1948 BB.Degenerated(CurEdge, Standard_False);
1949 BB.SameRange(CurEdge, Standard_False);
1950 BB.SameParameter(CurEdge, Standard_False);
1951 gp_Pnt fPnt, lPnt, mPnt;
1952 GetEdgePoints(CurEdge, aFace, fPnt, mPnt, lPnt);
1954 BRep_Tool::Range(CurEdge, f, l);
1957 gp_Vec aVec1(fPnt, mPnt);
1958 gp_Vec aVec2(fPnt, lPnt);
1959 gp_Vec aNorm = aVec1.Crossed(aVec2);
1960 gp_Pnt theApex = BRep_Tool::Pnt(anApex);
1961 gp_Vec ApexToFpnt(theApex, fPnt);
1962 gp_Vec Ydir = aNorm ^ ApexToFpnt;
1963 gp_Vec Xdir = Ydir ^ aNorm;
1964 //Xdir.Rotate(gp_Ax1(theApex, aNorm), -f);
1965 gp_Ax2 anAx2(theApex, gp_Dir(aNorm), gp_Dir(Xdir));
1966 theSphere.SetRadius(myOffset);
1967 theSphere.SetPosition(gp_Ax3(anAx2) /*gp_Ax3(theApex, gp_Dir(aNorm))*/);
1968 aSphSurf = new Geom_SphericalSurface(theSphere);
1970 theFirstVertex = BRepLib_MakeVertex(fPnt);
1971 CurFirstVertex = theFirstVertex;
1974 TopoDS_Vertex v1, v2, FirstVert, EndVert;
1975 TopExp::Vertices(CurEdge, v1, v2);
1976 FirstVert = CurFirstVertex;
1977 if (lPnt.Distance(FirstPoint) <= Precision::Confusion())
1978 EndVert = theFirstVertex;
1980 EndVert = BRepLib_MakeVertex(lPnt);
1981 CurEdge.Free( Standard_True );
1982 BB.Remove(CurEdge, v1);
1983 BB.Remove(CurEdge, v2);
1984 BB.Add(CurEdge, FirstVert.Oriented(TopAbs_FORWARD));
1985 BB.Add(CurEdge, EndVert.Oriented(TopAbs_REVERSED));
1986 //take the curve from sphere an put it to the edge
1987 Standard_Real Uf, Vf, Ul, Vl;
1988 ElSLib::Parameters( theSphere, fPnt, Uf, Vf );
1989 ElSLib::Parameters( theSphere, lPnt, Ul, Vl );
1990 if (Abs(Ul) <= Precision::Confusion())
1992 Handle(Geom_Curve) aCurv = aSphSurf->VIso(Vf);
1996 gp_Circ aCircle = (Handle(Geom_Circle)::DownCast(aCurv))->Circ();
1997 if (Abs(Uf - f) > Precision::Confusion())
1999 aCircle.Rotate(aCircle.Axis(), f - Uf);
2000 aCurv = new Geom_Circle(aCircle);
2004 Handle(Geom_TrimmedCurve) aTrimCurv = new Geom_TrimmedCurve(aCurv, Uf, Ul);
2005 BB.UpdateEdge(CurEdge, aTrimCurv, Precision::Confusion());
2006 BB.Range(CurEdge, Uf, Ul, Standard_True);
2007 Handle(Geom2d_Line) theLin2d = new Geom2d_Line( gp_Pnt2d( 0., Vf ), gp::DX2d() );
2008 Handle(Geom2d_TrimmedCurve) theTrimLin2d = new Geom2d_TrimmedCurve(theLin2d, Uf, Ul);
2009 BB.UpdateEdge(CurEdge, theTrimLin2d, aSphSurf, L, Precision::Confusion());
2010 BB.Range(CurEdge, aSphSurf, L, Uf, Ul);
2011 BRepLib::SameParameter(CurEdge);
2012 BB.Add(SphereWire, CurEdge);
2013 //Modifying correspondent edges in aFace: substitute vertices common with CurEdge
2014 BRepAdaptor_Curve2d BAc2d(CurEdge, aFace);
2015 gp_Pnt2d fPnt2d, lPnt2d;
2016 fPnt2d = BAc2d.Value(BAc2d.FirstParameter());
2017 lPnt2d = BAc2d.Value(BAc2d.LastParameter());
2018 TopTools_IndexedMapOfShape Emap;
2019 TopExp::MapShapes(aFace, TopAbs_EDGE, Emap);
2021 Standard_Integer j = 0, k;
2022 for (k = 1; k <= Emap.Extent(); k++)
2024 const TopoDS_Edge& anEdge = TopoDS::Edge(Emap(k));
2025 if (!BRep_Tool::Degenerated(anEdge))
2027 TopoDS_Vertex V1, V2;
2028 TopExp::Vertices(anEdge, V1, V2);
2029 if (V1.IsSame(v1) || V2.IsSame(v1))
2033 for (k = 0; k < j; k++)
2035 TopoDS_Shape aLocalShape = EE[k].Oriented(TopAbs_FORWARD);
2036 TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape);
2037 Eforward.Free(Standard_True);
2038 TopoDS_Vertex V1, V2;
2039 TopExp::Vertices( Eforward, V1, V2 );
2040 BRepAdaptor_Curve2d EEc( Eforward, aFace );
2041 gp_Pnt2d p2d1, p2d2;
2042 p2d1 = EEc.Value(EEc.FirstParameter());
2043 p2d2 = EEc.Value(EEc.LastParameter());
2046 TopoDS_Vertex NewV = (p2d1.Distance(fPnt2d) <= Precision::Confusion())?
2047 FirstVert : EndVert;
2048 BB.Remove( Eforward, V1 );
2049 BB.Add( Eforward, NewV.Oriented(TopAbs_FORWARD) );
2053 TopoDS_Vertex NewV = (p2d2.Distance(fPnt2d) <= Precision::Confusion())?
2054 FirstVert : EndVert;
2055 BB.Remove( Eforward, V2 );
2056 BB.Add( Eforward, NewV.Oriented(TopAbs_REVERSED) );
2060 isFirstFace = Standard_False;
2061 CurFirstVertex = EndVert;
2063 //Building new spherical face
2064 Standard_Real Ufirst = RealLast(), Ulast = RealFirst();
2065 gp_Pnt2d p2d1, p2d2;
2066 TopTools_ListOfShape EdgesOfWire;
2067 TopoDS_Iterator itw(SphereWire);
2068 for (; itw.More(); itw.Next())
2070 const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value());
2071 EdgesOfWire.Append(anEdge);
2073 Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, aSphSurf, L, f, l);
2074 p2d1 = aC2d->Value(f);
2075 p2d2 = aC2d->Value(l);
2076 if (p2d1.X() < Ufirst)
2078 if (p2d1.X() > Ulast)
2080 if (p2d2.X() < Ufirst)
2082 if (p2d2.X() > Ulast)
2085 TopTools_ListOfShape NewEdges;
2086 TopoDS_Edge FirstEdge;
2087 TopTools_ListIteratorOfListOfShape itl(EdgesOfWire);
2088 for (; itl.More(); itl.Next())
2090 FirstEdge = TopoDS::Edge(itl.Value());
2092 Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(FirstEdge, aSphSurf, L, f, l);
2093 p2d1 = aC2d->Value(f);
2094 p2d2 = aC2d->Value(l);
2095 if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion())
2097 EdgesOfWire.Remove(itl);
2101 NewEdges.Append(FirstEdge.Oriented(TopAbs_FORWARD));
2102 TopoDS_Vertex Vf1, CurVertex;
2103 TopExp::Vertices(FirstEdge, Vf1, CurVertex);
2104 itl.Initialize(EdgesOfWire);
2107 const TopoDS_Edge& anEdge = TopoDS::Edge(itl.Value());
2108 TopoDS_Vertex V1, V2;
2109 TopExp::Vertices(anEdge, V1, V2);
2110 if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex))
2112 NewEdges.Append(anEdge.Oriented(TopAbs_FORWARD));
2113 CurVertex = (V1.IsSame(CurVertex))? V2 : V1;
2114 EdgesOfWire.Remove(itl);
2120 Standard_Real Vfirst, Vlast;
2123 Vfirst = p2d1.Y(); Vlast = M_PI/2.;
2127 Vfirst = -M_PI/2.; Vlast = p2d1.Y();
2129 TopoDS_Face NewSphericalFace = BRepLib_MakeFace(aSphSurf, Ufirst, Ulast, Vfirst, Vlast, Precision::Confusion());
2130 TopoDS_Edge OldEdge, DegEdge;
2131 for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next())
2133 DegEdge = TopoDS::Edge(Explo.Current());
2134 if (BRep_Tool::Degenerated(DegEdge))
2137 TopoDS_Vertex DegVertex = TopExp::FirstVertex(DegEdge);
2138 for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next())
2140 OldEdge = TopoDS::Edge(Explo.Current());
2141 TopoDS_Vertex V1, V2;
2142 TopExp::Vertices(OldEdge, V1, V2);
2143 if (!V1.IsSame(DegVertex) && !V2.IsSame(DegVertex))
2146 TopoDS_Vertex V1, V2;
2147 TopExp::Vertices(OldEdge, V1, V2);
2148 TopTools_ListOfShape LV1, LV2;
2149 LV1.Append(Vf1.Oriented(TopAbs_FORWARD));
2150 LV2.Append(CurVertex.Oriented(TopAbs_FORWARD));
2151 BRepTools_Substitution theSubstitutor;
2152 theSubstitutor.Substitute(V1.Oriented(TopAbs_FORWARD), LV1);
2154 theSubstitutor.Substitute(V2.Oriented(TopAbs_FORWARD), LV2);
2155 theSubstitutor.Substitute(OldEdge.Oriented(TopAbs_FORWARD), NewEdges);
2156 theSubstitutor.Build(NewSphericalFace);
2157 if (theSubstitutor.IsCopied(NewSphericalFace))
2159 const TopTools_ListOfShape& listSh = theSubstitutor.Copy(NewSphericalFace);
2160 NewSphericalFace = TopoDS::Face(listSh.First());
2163 //Adding NewSphericalFace to the shell
2164 Explo.Init( myOffsetShape, TopAbs_SHELL );
2165 TopoDS_Shape theShell = Explo.Current();
2166 theShell.Free( Standard_True );
2167 BB.Add( theShell, NewSphericalFace );
2168 IsModified = Standard_True;
2169 if(!theShell.Closed())
2171 if(BRep_Tool::IsClosed(theShell))
2173 theShell.Closed(Standard_True);
2183 if (myShape.ShapeType() == TopAbs_SOLID || myThickening)
2185 //Explo.Init( myOffsetShape, TopAbs_SHELL );
2187 //if (Explo.More()) {
2188 // TopoDS_Shape theShell = Explo.Current();
2189 // theShell.Closed( Standard_True );
2192 Standard_Integer NbShell = 0;
2195 BB.MakeCompound (NC);
2199 Sol.Closed(Standard_True);
2200 for (Explo.Init(myOffsetShape,TopAbs_SHELL); Explo.More(); Explo.Next()) {
2201 TopoDS_Shell Sh = TopoDS::Shell(Explo.Current());
2202 //if (myThickening && myOffset > 0.)
2216 TopoDS_Iterator anIt(Sol);
2217 Standard_Boolean SolIsNull = !anIt.More();
2221 Standard_Integer nbs = 0;
2222 while(anIt.More()) {anIt.Next(); ++nbs;}
2225 BRepCheck_Analyzer aCheck(Sol, Standard_False);
2226 if(!aCheck.IsValid())
2228 TopTools_ListOfShape aSolList;
2229 CorrectSolid(Sol, aSolList);
2230 if(!aSolList.IsEmpty())
2233 TopTools_ListIteratorOfListOfShape aSLIt(aSolList);
2234 for(; aSLIt.More(); aSLIt.Next())
2236 BB.Add(NC, aSLIt.Value());
2238 SolIsNull = Standard_True;
2244 anIt.Initialize(NC);
2245 Standard_Boolean NCIsNull = !anIt.More();
2246 if((!SolIsNull) && (!NCIsNull))
2251 else if(SolIsNull && (!NCIsNull))
2262 else if((!SolIsNull) && NCIsNull)
2264 myOffsetShape = Sol;
2274 //=======================================================================
2275 //function : Intersection3D
2277 //=======================================================================
2279 void BRepOffset_MakeOffset::Intersection3D(BRepOffset_Inter3d& Inter)
2283 cout << " INTERSECTION 3D:" << endl;
2288 TopTools_ListOfShape OffsetFaces; // list of faces // created.
2289 MakeList (OffsetFaces,myInitOffsetFace,myFaces);
2291 if (!myFaces.IsEmpty()) {
2292 Standard_Boolean InSide = (myOffset < 0.); // Temporary
2293 // it is necessary to calculate Inside taking account of the concavity or convexity of edges
2294 // between the cap and the part.
2296 if (myJoin == GeomAbs_Arc)
2297 Inter.ContextIntByArc (myFaces,InSide,myAnalyse,myInitOffsetFace,myInitOffsetEdge);
2303 Inter.CompletInt (OffsetFaces,myInitOffsetFace);
2304 TopTools_IndexedMapOfShape& NewEdges = Inter.NewEdges();
2305 if (myJoin == GeomAbs_Intersection) {
2306 BRepOffset_Tool::CorrectOrientation (myShape,NewEdges,myAsDes,myInitOffsetFace,myOffset);
2310 //--------------------------------
2311 // Only between neighbor faces.
2312 //--------------------------------
2313 Inter.ConnexIntByArc(OffsetFaces,myShape,myAnalyse,myInitOffsetFace);
2316 if ( ChronBuild) Clock.Show();
2320 //=======================================================================
2321 //function : Intersection2D
2323 //=======================================================================
2325 void BRepOffset_MakeOffset::Intersection2D(const TopTools_IndexedMapOfShape& Modif,
2326 const TopTools_IndexedMapOfShape& NewEdges)
2330 cout << " INTERSECTION 2D:" << endl;
2335 //--------------------------------------------------------
2336 // calculate intersections2d on faces concerned by
2338 //---------------------------------------------------------
2339 //TopTools_MapIteratorOfMapOfShape it(Modif);
2340 //-----------------------------------------------
2341 // Intersection of edges 2 by 2.
2342 //-----------------------------------------------
2343 TopTools_IndexedDataMapOfShapeListOfShape aDMVV;
2345 for (i = 1; i <= Modif.Extent(); i++) {
2346 const TopoDS_Face& F = TopoDS::Face(Modif(i));
2347 BRepOffset_Inter2d::Compute(myAsDes,F,NewEdges,myTol, aDMVV);
2350 BRepOffset_Inter2d::FuseVertices(aDMVV, myAsDes);
2354 DEBVerticesControl (NewEdges,myAsDes);
2356 if ( ChronBuild) Clock.Show();
2361 //=======================================================================
2362 //function : MakeLoops
2364 //=======================================================================
2366 void BRepOffset_MakeOffset::MakeLoops(TopTools_IndexedMapOfShape& Modif)
2370 cout << " DEBOUCLAGE 2D:" << endl;
2375 //TopTools_MapIteratorOfMapOfShape it(Modif);
2376 TopTools_ListOfShape LF,LC;
2377 //-----------------------------------------
2378 // unwinding of faces // modified.
2379 //-----------------------------------------
2381 for (i = 1; i <= Modif.Extent(); i++) {
2382 if (!myFaces.Contains(Modif(i)))
2383 LF.Append(Modif(i));
2386 if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) {
2387 BuildSplitsOfTrimmedFaces(LF, myAsDes, myImageOffset);
2390 myMakeLoops.Build(LF,myAsDes,myImageOffset);
2393 //-----------------------------------------
2394 // unwinding of caps.
2395 //-----------------------------------------
2396 for (i = 1; i <= myFaces.Extent(); i++)
2397 LC.Append(myFaces(i));
2399 Standard_Boolean InSide = 1;
2400 if (myOffset > 0 ) InSide = 0;
2401 myMakeLoops.BuildOnContext(LC,myAnalyse,myAsDes,myImageOffset,InSide);
2404 if ( ChronBuild) Clock.Show();
2408 //=======================================================================
2409 //function : MakeFaces
2410 //purpose : Reconstruction of topologically unchanged faces that
2411 // share edges that were reconstructed.
2412 //=======================================================================
2414 void BRepOffset_MakeOffset::MakeFaces(TopTools_IndexedMapOfShape& /*Modif*/)
2418 cout << " RECONSTRUCTION OF FACES:" << endl;
2423 TopTools_ListIteratorOfListOfShape itr;
2424 const TopTools_ListOfShape& Roots = myInitOffsetFace.Roots();
2425 TopTools_ListOfShape LOF;
2426 //----------------------------------
2427 // Loop on all faces //.
2428 //----------------------------------
2429 for (itr.Initialize(Roots); itr.More(); itr.Next()) {
2430 TopoDS_Face F = TopoDS::Face(myInitOffsetFace.Image(itr.Value()).First());
2431 if (!myImageOffset.HasImage(F)) {
2436 if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) {
2437 BuildSplitsOfTrimmedFaces(LOF, myAsDes, myImageOffset);
2440 myMakeLoops.BuildFaces(LOF,myAsDes,myImageOffset);
2444 if ( ChronBuild) Clock.Show();
2448 //=======================================================================
2449 //function : UpdateInitOffset
2450 //purpose : Update and cleaning of myInitOffset
2451 //=======================================================================
2452 static void UpdateInitOffset (BRepAlgo_Image& myInitOffset,
2453 BRepAlgo_Image& myImageOffset,
2454 const TopoDS_Shape& myOffsetShape,
2455 const TopAbs_ShapeEnum &theShapeType) // skv
2457 BRepAlgo_Image NIOF;
2458 const TopTools_ListOfShape& Roots = myInitOffset.Roots();
2459 TopTools_ListIteratorOfListOfShape it(Roots);
2460 for (; it.More(); it.Next()) {
2461 NIOF.SetRoot (it.Value());
2463 for (it.Initialize(Roots); it.More(); it.Next()) {
2464 const TopoDS_Shape& SI = it.Value();
2465 TopTools_ListOfShape LI;
2466 TopTools_ListOfShape L1;
2467 myInitOffset.LastImage(SI,L1);
2468 TopTools_ListIteratorOfListOfShape itL1(L1);
2469 for (; itL1.More(); itL1.Next()) {
2470 const TopoDS_Shape& O1 = itL1.Value();
2471 TopTools_ListOfShape L2;
2472 myImageOffset.LastImage(O1,L2);
2477 // Modified by skv - Mon Apr 4 18:17:27 2005 Begin
2478 // Supporting history.
2479 // NIOF.Filter(myOffsetShape,TopAbs_FACE);
2480 NIOF.Filter(myOffsetShape, theShapeType);
2481 // Modified by skv - Mon Apr 4 18:17:27 2005 End
2482 myInitOffset = NIOF;
2485 //=======================================================================
2486 //function : MakeMissingWalls
2488 //=======================================================================
2489 void BRepOffset_MakeOffset::MakeMissingWalls ()
2491 TopTools_DataMapOfShapeListOfShape Contours; //Start vertex + list of connected edges (free boundary)
2492 TopTools_DataMapOfShapeShape MapEF; //Edges of contours: edge + face
2493 Standard_Real OffsetVal = Abs(myOffset);
2495 FillContours(myShape, myAnalyse, Contours, MapEF);
2497 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape iter(Contours);
2498 for (; iter.More(); iter.Next())
2500 TopoDS_Vertex StartVertex = TopoDS::Vertex(iter.Key());
2501 TopoDS_Edge StartEdge;
2502 const TopTools_ListOfShape& aContour = iter.Value();
2503 TopTools_ListIteratorOfListOfShape itl(aContour);
2504 Standard_Boolean FirstStep = Standard_True;
2505 TopoDS_Edge PrevEdge;
2506 TopoDS_Vertex PrevVertex = StartVertex;
2507 Standard_Boolean isBuildFromScratch = Standard_False; // Problems with edges.
2508 for (; itl.More(); itl.Next())
2510 TopoDS_Edge anEdge = TopoDS::Edge(itl.Value());
2512 // Check for offset existence.
2513 if (!myInitOffsetEdge.HasImage(anEdge))
2516 // Check for existence of two different vertices.
2517 TopTools_ListOfShape LOE, LOE2;
2518 myInitOffsetEdge.LastImage( anEdge, LOE );
2519 myImageOffset.LastImage( LOE.Last(), LOE2 );
2520 TopoDS_Edge OE = TopoDS::Edge( LOE2.Last() );
2521 TopoDS_Vertex V1, V2, V3, V4;
2522 TopExp::Vertices(OE, V4, V3);
2523 TopExp::Vertices(anEdge, V1, V2);
2524 Standard_Real aF, aL;
2525 const Handle(Geom_Curve) aC = BRep_Tool::Curve(anEdge, aF, aL);
2527 (!aC->IsClosed() && !aC->IsPeriodic()))
2529 gp_Pnt aPntF = BRep_Tool::Pnt(V1);
2530 gp_Pnt aPntL = BRep_Tool::Pnt(V2);
2531 Standard_Real aDistE = aPntF.SquareDistance(aPntL);
2532 if ( aDistE < Precision::SquareConfusion())
2534 // Bad case: non closed, but vertexes mapped to same 3d point.
2538 Standard_Real anEdgeTol = BRep_Tool::Tolerance(anEdge);
2539 if (aDistE < anEdgeTol)
2541 // Potential problems not detected via checkshape.
2542 gp_Pnt aPntOF = BRep_Tool::Pnt(V4);
2543 gp_Pnt aPntOL = BRep_Tool::Pnt(V3);
2544 if (aPntOF.SquareDistance(aPntOL) > gp::Resolution())
2546 // To avoid computation of complex analytical continuation of Sin / ArcSin.
2547 Standard_Real aSinValue = Min(2 * anEdgeTol / aPntOF.Distance(aPntOL), 1.0);
2548 Standard_Real aMaxAngle = Min(Abs(ASin(aSinValue)), M_PI_4); // Maximal angle.
2549 Standard_Real aCurrentAngle = gp_Vec(aPntF, aPntL).Angle(gp_Vec(aPntOF, aPntOL));
2550 if (aC->IsKind(STANDARD_TYPE(Geom_Line)) &&
2551 Abs (aCurrentAngle) > aMaxAngle)
2553 // anEdge not collinear to offset edge.
2554 isBuildFromScratch = Standard_True;
2555 myIsPerformSewing = Standard_True;
2562 Standard_Boolean ToReverse = Standard_False;
2563 if (!V1.IsSame(PrevVertex))
2565 TopoDS_Vertex aVtx = V1; V1 = V2; V2 = aVtx;
2566 aVtx = V3; V3 = V4; V4 = aVtx;
2567 ToReverse = Standard_True;
2570 OE.Orientation(TopAbs::Reverse(anEdge.Orientation()));
2572 Standard_Boolean ArcOnV2 = ((myJoin == GeomAbs_Arc) && (myInitOffsetEdge.HasImage(V2)));
2573 if (FirstStep || isBuildFromScratch)
2575 E4 = BRepLib_MakeEdge( V1, V4 );
2581 if (V2.IsSame(StartVertex) && !ArcOnV2)
2584 E3 = BRepLib_MakeEdge( V2, V3 );
2587 if (isBuildFromScratch)
2593 TopoDS_Shape localAnEdge = anEdge.Oriented(TopAbs_FORWARD);
2594 const TopoDS_Edge& anEdgeFWD = TopoDS::Edge(localAnEdge);
2595 Standard_Real ParV1 = BRep_Tool::Parameter(V1, anEdgeFWD);
2596 Standard_Real ParV2 = BRep_Tool::Parameter(V2, anEdgeFWD);
2598 TopoDS_Wire theWire;
2599 BB.MakeWire(theWire);
2602 BB.Add(theWire, anEdge.Reversed());
2603 BB.Add(theWire, E3.Reversed());
2604 BB.Add(theWire, OE.Reversed());
2605 BB.Add(theWire, E4.Reversed());
2609 BB.Add(theWire, anEdge);
2610 BB.Add(theWire, E3);
2611 BB.Add(theWire, OE);
2612 BB.Add(theWire, E4);
2615 BRepLib::BuildCurves3d( theWire, myTol );
2616 theWire.Closed(Standard_True);
2617 TopoDS_Face NewFace;
2618 Handle(Geom_Surface) theSurf;
2619 BRepAdaptor_Curve BAcurve(anEdge);
2620 BRepAdaptor_Curve BAcurveOE(OE);
2621 Standard_Real fpar = BAcurve.FirstParameter();
2622 Standard_Real lpar = BAcurve.LastParameter();
2623 gp_Pnt PonE = BAcurve.Value(fpar);
2624 gp_Pnt PonOE = BAcurveOE.Value(fpar);
2625 gp_Dir OffsetDir = gce_MakeDir( PonE, PonOE );
2626 Handle(Geom2d_Line) EdgeLine2d, OELine2d, aLine2d, aLine2d2;
2627 Standard_Boolean IsPlanar = Standard_False;
2628 if (BAcurve.GetType() == GeomAbs_Circle &&
2629 BAcurveOE.GetType() == GeomAbs_Circle)
2631 gp_Circ aCirc = BAcurve.Circle();
2632 gp_Circ aCircOE = BAcurveOE.Circle();
2633 gp_Lin anAxisLine(aCirc.Axis());
2634 gp_Dir CircAxisDir = aCirc.Axis().Direction();
2635 if (aCirc.Axis().IsParallel(aCircOE.Axis(), Precision::Confusion()) &&
2636 anAxisLine.Contains(aCircOE.Location(), Precision::Confusion()))
2637 { //cylinder, plane or cone
2638 if (Abs(aCirc.Radius() - aCircOE.Radius()) <= Precision::Confusion()) //case of cylinder
2639 theSurf = GC_MakeCylindricalSurface(aCirc).Value();
2640 else if (aCirc.Location().Distance(aCircOE.Location()) <= Precision::Confusion()) {//case of plane
2641 IsPlanar = Standard_True;
2643 gp_Pnt PonEL = BAcurve.Value(lpar);
2644 if (PonEL.Distance(PonE) <= Precision::PConfusion()) {
2645 Standard_Boolean bIsHole;
2646 TopoDS_Edge aE1, aE2;
2647 TopoDS_Wire aW1, aW2;
2648 Handle(Geom_Plane) aPL;
2649 IntTools_FClass2d aClsf;
2651 if (aCirc.Radius()>aCircOE.Radius()) {
2664 aPL = new Geom_Plane(aCirc.Location(), CircAxisDir);
2665 for (Standard_Integer i = 0; i < 2; ++i) {
2666 TopoDS_Wire& aW = (i==0) ? aW1 : aW2;
2667 TopoDS_Edge& aE = (i==0) ? aE1 : aE2;
2670 BB.MakeFace(aFace, aPL, Precision::Confusion());
2672 aClsf.Init(aFace, Precision::Confusion());
2673 bIsHole=aClsf.IsHole();
2674 if ((bIsHole && !i) || (!bIsHole && i)) {
2677 BB.Add(aW, aE.Reversed());
2681 BB.MakeFace(NewFace, aPL, Precision::Confusion());
2682 BB.Add(NewFace, aW1);
2683 BB.Add(NewFace, aW2);
2688 gp_Cone theCone = gce_MakeCone(aCirc.Location(), aCircOE.Location(),
2689 aCirc.Radius(), aCircOE.Radius());
2690 gp_Ax3 theAx3(aCirc.Position());
2691 if (CircAxisDir * theCone.Axis().Direction() < 0.)
2694 CircAxisDir.Reverse();
2696 theCone.SetPosition(theAx3);
2697 theSurf = new Geom_ConicalSurface(theCone);
2700 TopLoc_Location Loc;
2701 EdgeLine2d = new Geom2d_Line(gp_Pnt2d(0., 0.), gp_Dir2d(1., 0.));
2702 BB.UpdateEdge(anEdge, EdgeLine2d, theSurf, Loc, Precision::Confusion());
2703 Standard_Real Coeff = (OffsetDir * CircAxisDir > 0.)? 1. : -1.;
2704 OELine2d = new Geom2d_Line(gp_Pnt2d(0., OffsetVal*Coeff), gp_Dir2d(1., 0.));
2705 BB.UpdateEdge(OE, OELine2d, theSurf, Loc, Precision::Confusion());
2706 aLine2d = new Geom2d_Line(gp_Pnt2d(ParV2, 0.), gp_Dir2d(0., Coeff));
2707 aLine2d2 = new Geom2d_Line(gp_Pnt2d(ParV1, 0.), gp_Dir2d(0., Coeff));
2711 BB.UpdateEdge(E3, aLine2d, aLine2d2, theSurf, Loc, Precision::Confusion());
2714 BB.UpdateEdge(E3, aLine2d2, aLine2d, theSurf, Loc, Precision::Confusion());
2716 BB.MakeWire(theWire);
2717 BB.Add(theWire, anEdge.Oriented(TopAbs_REVERSED));
2718 BB.Add(theWire, E4);
2719 BB.Add(theWire, OE.Oriented(TopAbs_FORWARD));
2720 BB.Add(theWire, E3);
2721 theWire.Closed(Standard_True);
2726 BB.SameParameter(E3, Standard_False);
2727 BB.SameRange(E3, Standard_False);
2728 BB.SameParameter(E4, Standard_False);
2729 BB.SameRange(E4, Standard_False);
2730 BB.UpdateEdge(E3, aLine2d, theSurf, Loc, Precision::Confusion());
2731 BB.Range(E3, theSurf, Loc, 0., OffsetVal);
2732 BB.UpdateEdge(E4, aLine2d2, theSurf, Loc, Precision::Confusion());
2733 BB.Range(E4, theSurf, Loc, 0., OffsetVal);
2735 NewFace = BRepLib_MakeFace(theSurf, theWire);
2737 } //cylinder or cone
2738 } //if both edges are arcs of circles
2739 if (NewFace.IsNull())
2741 BRepLib_MakeFace MF(theWire, Standard_True); //Only plane
2742 if (MF.Error() == BRepLib_FaceDone)
2744 NewFace = MF.Face();
2745 IsPlanar = Standard_True;
2747 else //Extrusion (by thrusections)
2749 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
2750 Handle(Geom_TrimmedCurve) TrEdgeCurve =
2751 new Geom_TrimmedCurve( EdgeCurve, fpar, lpar );
2752 Standard_Real fparOE, lparOE;
2753 Handle(Geom_Curve) OffsetCurve = BRep_Tool::Curve(OE, fparOE, lparOE);
2754 Handle(Geom_TrimmedCurve) TrOffsetCurve =
2755 new Geom_TrimmedCurve( OffsetCurve, fparOE, lparOE );
2756 GeomFill_Generator ThrusecGenerator;
2757 ThrusecGenerator.AddCurve( TrEdgeCurve );
2758 ThrusecGenerator.AddCurve( TrOffsetCurve );
2759 ThrusecGenerator.Perform( Precision::PConfusion() );
2760 theSurf = ThrusecGenerator.Surface();
2761 //theSurf = new Geom_SurfaceOfLinearExtrusion( TrOffsetCurve, OffsetDir );
2762 Standard_Real Uf, Ul, Vf, Vl;
2763 theSurf->Bounds(Uf, Ul, Vf, Vl);
2764 TopLoc_Location Loc;
2765 EdgeLine2d = new Geom2d_Line(gp_Pnt2d(0., Vf), gp_Dir2d(1., 0.));
2766 BB.UpdateEdge(anEdge, EdgeLine2d, theSurf, Loc, Precision::Confusion());
2767 OELine2d = new Geom2d_Line(gp_Pnt2d(0., Vl), gp_Dir2d(1., 0.));
2768 BB.UpdateEdge(OE, OELine2d, theSurf, Loc, Precision::Confusion());
2769 Standard_Real UonV1 = (ToReverse)? Ul : Uf;
2770 Standard_Real UonV2 = (ToReverse)? Uf : Ul;
2771 aLine2d = new Geom2d_Line(gp_Pnt2d(UonV2, 0.), gp_Dir2d(0., 1.));
2772 aLine2d2 = new Geom2d_Line(gp_Pnt2d(UonV1, 0.), gp_Dir2d(0., 1.));
2775 BB.UpdateEdge(E3, aLine2d, aLine2d2, theSurf, Loc, Precision::Confusion());
2776 Handle(Geom_Curve) BSplC34 = theSurf->UIso( Uf );
2777 BB.UpdateEdge(E3, BSplC34, Precision::Confusion());
2778 BB.Range(E3, Vf, Vl);
2782 BB.SameParameter(E3, Standard_False);
2783 BB.SameRange(E3, Standard_False);
2784 BB.SameParameter(E4, Standard_False);
2785 BB.SameRange(E4, Standard_False);
2786 BB.UpdateEdge(E3, aLine2d, theSurf, Loc, Precision::Confusion());
2787 BB.Range(E3, theSurf, Loc, Vf, Vl);
2788 BB.UpdateEdge(E4, aLine2d2, theSurf, Loc, Precision::Confusion());
2789 BB.Range(E4, theSurf, Loc, Vf, Vl);
2790 Handle(Geom_Curve) BSplC3 = theSurf->UIso( UonV2 );
2791 BB.UpdateEdge(E3, BSplC3, Precision::Confusion());
2792 BB.Range(E3, Vf, Vl, Standard_True); //only for 3d curve
2793 Handle(Geom_Curve) BSplC4 = theSurf->UIso( UonV1 );
2794 BB.UpdateEdge(E4, BSplC4, Precision::Confusion());
2795 BB.Range(E4, Vf, Vl, Standard_True); //only for 3d curve
2797 NewFace = BRepLib_MakeFace(theSurf, theWire);
2802 Standard_Real fparOE = BAcurveOE.FirstParameter();
2803 Standard_Real lparOE = BAcurveOE.LastParameter();
2804 TopLoc_Location Loc;
2805 if (Abs(fpar - fparOE) > Precision::Confusion())
2807 const TopoDS_Edge& anE4 = (ToReverse)? E3 : E4;
2808 gp_Pnt2d fp2d = EdgeLine2d->Value(fpar);
2809 gp_Pnt2d fp2dOE = OELine2d->Value(fparOE);
2810 aLine2d2 = GCE2d_MakeLine( fp2d, fp2dOE ).Value();
2811 Handle(Geom_Curve) aCurve;
2812 Standard_Real FirstPar = 0., LastPar = fp2d.Distance(fp2dOE);
2813 Geom2dAdaptor_Curve AC2d( aLine2d2, FirstPar, LastPar );
2814 GeomAdaptor_Surface GAsurf( theSurf );
2815 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( AC2d );
2816 Handle(GeomAdaptor_HSurface) HSurf = new GeomAdaptor_HSurface( GAsurf );
2817 Adaptor3d_CurveOnSurface ConS( HC2d, HSurf );
2818 Standard_Real max_deviation = 0., average_deviation;
2819 GeomLib::BuildCurve3d(Precision::Confusion(),
2820 ConS, FirstPar, LastPar,
2821 aCurve, max_deviation, average_deviation);
2822 BB.UpdateEdge( anE4, aCurve, max_deviation );
2823 BB.UpdateEdge( anE4, aLine2d2, theSurf, Loc, max_deviation );
2824 BB.Range( anE4, FirstPar, LastPar );
2826 if (Abs(lpar - lparOE) > Precision::Confusion())
2828 const TopoDS_Edge& anE3 = (ToReverse)? E4 : E3;
2829 gp_Pnt2d lp2d = EdgeLine2d->Value(lpar);
2830 gp_Pnt2d lp2dOE = OELine2d->Value(lparOE);
2831 aLine2d = GCE2d_MakeLine( lp2d, lp2dOE ).Value();
2832 Handle(Geom_Curve) aCurve;
2833 Standard_Real FirstPar = 0., LastPar = lp2d.Distance(lp2dOE);
2834 Geom2dAdaptor_Curve AC2d( aLine2d, FirstPar, LastPar );
2835 GeomAdaptor_Surface GAsurf( theSurf );
2836 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( AC2d );
2837 Handle(GeomAdaptor_HSurface) HSurf = new GeomAdaptor_HSurface( GAsurf );
2838 Adaptor3d_CurveOnSurface ConS( HC2d, HSurf );
2839 Standard_Real max_deviation = 0., average_deviation;
2840 GeomLib::BuildCurve3d(Precision::Confusion(),
2841 ConS, FirstPar, LastPar,
2842 aCurve, max_deviation, average_deviation);
2843 BB.UpdateEdge( anE3, aCurve, max_deviation );
2844 BB.UpdateEdge( anE3, aLine2d, theSurf, Loc, max_deviation );
2845 BB.Range( anE3, FirstPar, LastPar );
2848 BRepLib::SameParameter(NewFace);
2849 BRepTools::Update(NewFace);
2850 myWalls.Append(NewFace);
2853 TopoDS_Edge anArc = TopoDS::Edge(myInitOffsetEdge.Image(V2).First());
2854 TopoDS_Vertex arcV1, arcV2;
2855 TopExp::Vertices(anArc, arcV1, arcV2);
2856 Standard_Boolean ArcReverse = Standard_False;
2857 if (!arcV1.IsSame(V3))
2859 TopoDS_Vertex aVtx = arcV1; arcV1 = arcV2; arcV2 = aVtx;
2860 ArcReverse = Standard_True;
2862 TopoDS_Edge EA1, EA2;
2863 //EA1 = (ToReverse)? E3 : TopoDS::Edge(E3.Reversed());
2868 //////////////////////////////////////////////////////
2869 if (V2.IsSame(StartVertex))
2872 EA2 = BRepLib_MakeEdge( V2, arcV2 );
2873 anArc.Orientation( ((ArcReverse)? TopAbs_REVERSED : TopAbs_FORWARD) );
2874 if (EA1.Orientation() == TopAbs_REVERSED)
2876 EA2.Orientation(TopAbs::Reverse(EA1.Orientation()));
2877 TopoDS_Wire arcWire;
2878 BB.MakeWire(arcWire);
2879 BB.Add(arcWire, EA1);
2880 BB.Add(arcWire, anArc);
2881 BB.Add(arcWire, EA2);
2882 BRepLib::BuildCurves3d( arcWire, myTol );
2883 arcWire.Closed(Standard_True);
2884 TopoDS_Face arcFace = BRepLib_MakeFace(arcWire, Standard_True);
2885 BRepTools::Update(arcFace);
2886 myWalls.Append(arcFace);
2887 TopoDS_Shape localEA2 = EA2.Oriented(TopAbs_FORWARD);
2888 const TopoDS_Edge& CEA2 = TopoDS::Edge(localEA2);
2894 if (isBuildFromScratch)
2896 PrevEdge = TopoDS::Edge(E4);
2898 isBuildFromScratch = Standard_False;
2906 FirstStep = Standard_False;
2911 //=======================================================================
2912 //function : MakeShells
2914 //=======================================================================
2916 void BRepOffset_MakeOffset::MakeShells ()
2920 cout << " RECONSTRUCTION OF SHELLS:" << endl;
2926 TopTools_IndexedDataMapOfShapeListOfShape anOrigins;
2928 BOPCol_ListOfShape aLSF;
2929 const TopTools_ListOfShape& R = myImageOffset.Roots();
2930 TopTools_ListIteratorOfListOfShape it(R);
2932 for (; it.More(); it.Next()) {
2933 const TopoDS_Shape& aF = it.Value();
2935 TopTools_ListOfShape Image;
2936 myImageOffset.LastImage(aF,Image);
2937 TopTools_ListIteratorOfListOfShape it2(Image);
2938 for (; it2.More(); it2.Next()) {
2939 const TopoDS_Shape& aFIm = it2.Value();
2942 TopTools_ListOfShape *pLOr = anOrigins.ChangeSeek(aFIm);
2944 pLOr = &anOrigins(anOrigins.Add(aFIm, TopTools_ListOfShape()));
2951 TopExp_Explorer Explo(myShape, TopAbs_FACE);
2952 for (; Explo.More(); Explo.Next()) {
2953 const TopoDS_Shape& aF = Explo.Current();
2957 it.Initialize(myWalls);
2958 for (; it.More(); it.Next()) {
2959 const TopoDS_Shape& aF = it.Value();
2964 if (aLSF.IsEmpty()) {
2968 Standard_Boolean bDone = Standard_False;
2969 if ((myJoin == GeomAbs_Intersection) && myInter &&
2970 !myThickening && myFaces.IsEmpty() &&
2971 IsSolid(myShape) && myIsPlanar) {
2973 TopoDS_Shape aShells;
2974 bDone = BuildShellsCompleteInter(aLSF, anOrigins, myImageOffset, aShells);
2976 myOffsetShape = aShells;
2981 BRepTools_Quilt Glue;
2982 BOPCol_ListIteratorOfListOfShape aItLS(aLSF);
2983 for (; aItLS.More(); aItLS.Next()) {
2984 Glue.Add(aItLS.Value());
2986 myOffsetShape = Glue.Shells();
2989 //Set correct value for closed flag
2990 TopExp_Explorer Explo(myOffsetShape, TopAbs_SHELL);
2991 for(; Explo.More(); Explo.Next())
2993 TopoDS_Shape aS = Explo.Current();
2996 if(BRep_Tool::IsClosed(aS))
2998 aS.Closed(Standard_True);
3004 //=======================================================================
3005 //function : MakeSolid
3007 //=======================================================================
3009 void BRepOffset_MakeOffset::MakeSolid ()
3011 if (myOffsetShape.IsNull()) return;
3013 // Modified by skv - Mon Apr 4 18:17:27 2005 Begin
3014 // Supporting history.
3015 UpdateInitOffset (myInitOffsetFace,myImageOffset,myOffsetShape, TopAbs_FACE);
3016 UpdateInitOffset (myInitOffsetEdge,myImageOffset,myOffsetShape, TopAbs_EDGE);
3017 // Modified by skv - Mon Apr 4 18:17:27 2005 End
3018 TopExp_Explorer exp;
3020 Standard_Integer NbShell = 0;
3023 B.MakeCompound (NC);
3027 Sol.Closed(Standard_True);
3028 Standard_Boolean aMakeSolid = (myShape.ShapeType() == TopAbs_SOLID) || myThickening;
3029 for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next()) {
3030 TopoDS_Shell Sh = TopoDS::Shell(exp.Current());
3031 if (myThickening && myOffset > 0.)
3034 if (Sh.Closed() && aMakeSolid) {
3045 TopoDS_Iterator anIt(Sol);
3046 Standard_Boolean SolIsNull = !anIt.More();
3050 Standard_Integer nbs = 0;
3051 while(anIt.More()) {anIt.Next(); ++nbs;}
3054 BRepCheck_Analyzer aCheck(Sol, Standard_False);
3055 if(!aCheck.IsValid())
3057 TopTools_ListOfShape aSolList;
3058 CorrectSolid(Sol, aSolList);
3059 if(!aSolList.IsEmpty())
3062 TopTools_ListIteratorOfListOfShape aSLIt(aSolList);
3063 for(; aSLIt.More(); aSLIt.Next())
3065 B.Add(NC, aSLIt.Value());
3067 SolIsNull = Standard_True;
3072 anIt.Initialize(NC);
3073 Standard_Boolean NCIsNull = !anIt.More();
3074 if((!SolIsNull) && (!NCIsNull))
3079 else if(SolIsNull && (!NCIsNull))
3090 else if((!SolIsNull) && NCIsNull)
3092 myOffsetShape = Sol;
3100 //=======================================================================
3101 //function : SelectShells
3103 //=======================================================================
3105 void BRepOffset_MakeOffset::SelectShells ()
3107 TopTools_MapOfShape FreeEdges;
3108 TopExp_Explorer exp(myShape,TopAbs_EDGE);
3109 //-------------------------------------------------------------
3110 // FreeEdges all edges that can have free border in the
3112 // 1 - free borders of myShape .
3113 //-------------------------------------------------------------
3114 for ( ; exp.More(); exp.Next()) {
3115 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
3116 const TopTools_ListOfShape& LA = myAnalyse.Ancestors(E);
3117 if (LA.Extent() < 2) {
3118 if (myAnalyse.Type(E).First().Type() == BRepOffset_FreeBoundary) {
3123 // myShape has free borders and there are no caps
3125 if (!FreeEdges.IsEmpty() && myFaces.IsEmpty()) return;
3127 myOffsetShape = BRepOffset_Tool::Deboucle3D(myOffsetShape,FreeEdges);
3130 //=======================================================================
3131 //function : OffsetFacesFromShapes
3133 //=======================================================================
3135 const BRepAlgo_Image& BRepOffset_MakeOffset::OffsetFacesFromShapes() const
3137 return myInitOffsetFace;
3140 // Modified by skv - Tue Mar 15 16:20:43 2005 Begin
3142 //=======================================================================
3143 //function : GetJoinType
3144 //purpose : Query offset join type.
3145 //=======================================================================
3147 GeomAbs_JoinType BRepOffset_MakeOffset::GetJoinType() const
3152 //=======================================================================
3153 //function : OffsetEdgesFromShapes
3155 //=======================================================================
3157 const BRepAlgo_Image& BRepOffset_MakeOffset::OffsetEdgesFromShapes() const
3159 return myInitOffsetEdge;
3162 // Modified by skv - Tue Mar 15 16:20:43 2005 End
3164 //=======================================================================
3165 //function : ClosingFaces
3167 //=======================================================================
3169 const TopTools_IndexedMapOfShape& BRepOffset_MakeOffset::ClosingFaces () const
3176 //=======================================================================
3177 //function : EncodeRegularity
3179 //=======================================================================
3181 void BRepOffset_MakeOffset::EncodeRegularity ()
3185 cout << " CODING OF REGULARITIES:" << endl;
3191 if (myOffsetShape.IsNull()) return;
3192 // find edges G1 in the result
3193 TopExp_Explorer exp(myOffsetShape,TopAbs_EDGE);
3196 TopTools_MapOfShape MS;
3198 for ( ; exp.More(); exp.Next()) {
3199 TopoDS_Edge OE = TopoDS::Edge(exp.Current());
3200 BRepLib::BuildCurve3d(OE,myTol);
3201 TopoDS_Edge ROE = OE;
3203 if ( !MS.Add(OE)) continue;
3205 if ( myImageOffset.IsImage(OE))
3206 ROE = TopoDS::Edge(myImageOffset.Root(OE));
3208 const TopTools_ListOfShape& LofOF = myAsDes->Ascendant(ROE);
3210 if (LofOF.Extent() != 2) {
3211 #ifdef OCCT_DEBUG_VERB
3212 cout << " Edge shared by " << LofOF.Extent() << " Faces" << endl;
3217 const TopoDS_Face& F1 = TopoDS::Face(LofOF.First());
3218 const TopoDS_Face& F2 = TopoDS::Face(LofOF.Last() );
3220 if ( F1.IsNull() || F2.IsNull())
3223 const TopoDS_Shape& Root1 = myInitOffsetFace.Root(F1);
3224 const TopoDS_Shape& Root2 = myInitOffsetFace.Root(F2);
3226 TopAbs_ShapeEnum Type1 = Root1.ShapeType();
3227 TopAbs_ShapeEnum Type2 = Root2.ShapeType();
3229 if (F1.IsSame(F2)) {
3230 if (BRep_Tool::IsClosed(OE,F1)) {
3231 // Temporary Debug for the Bench.
3233 // In mode intersection, the edges are not coded in myInitOffsetEdge
3234 // so, manage case by case
3235 // Note DUB; for Hidden parts, it is NECESSARY to code CN
3236 // Analytic Surfaces.
3237 if (myJoin == GeomAbs_Intersection) {
3238 BRepAdaptor_Surface BS(F1,Standard_False);
3239 GeomAbs_SurfaceType SType = BS.GetType();
3240 if (SType == GeomAbs_Cylinder ||
3241 SType == GeomAbs_Cone ||
3242 SType == GeomAbs_Sphere ||
3243 SType == GeomAbs_Torus ) {
3244 B.Continuity(OE,F1,F1,GeomAbs_CN);
3247 // See YFR : MaJ of myInitOffsetFace
3250 else if (myInitOffsetEdge.IsImage(ROE)) {
3251 if ( Type1 == TopAbs_FACE && Type2 == TopAbs_FACE) {
3252 const TopoDS_Face& FRoot = TopoDS::Face(Root1);
3253 const TopoDS_Edge& EI = TopoDS::Edge(myInitOffsetEdge.ImageFrom(ROE));
3254 GeomAbs_Shape Conti = BRep_Tool::Continuity(EI,FRoot,FRoot);
3255 if (Conti == GeomAbs_CN) {
3256 B.Continuity(OE,F1,F1,GeomAbs_CN);
3258 else if ( Conti > GeomAbs_C0) {
3259 B.Continuity(OE,F1,F1,GeomAbs_G1);
3268 // code regularities G1 between :
3269 // - sphere and tube : one root is a vertex, the other is an edge
3270 // and the vertex is included in the edge
3271 // - face and tube : one root is a face, the other an edge
3272 // and the edge is included in the face
3273 // - face and face : if two root faces are tangent in
3274 // the initial shape, they will be tangent in the offset shape
3275 // - tube and tube : if 2 edges generating tubes are
3276 // tangents, the 2 will be tangent either.
3277 if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_VERTEX) {
3278 TopoDS_Vertex V1,V2;
3279 TopExp::Vertices(TopoDS::Edge(Root1), V1, V2);
3280 if ( V1.IsSame(Root2) || V2.IsSame(Root2)) {
3281 B.Continuity(OE,F1,F2,GeomAbs_G1);
3284 else if ( Type1 == TopAbs_VERTEX && Type2 == TopAbs_EDGE) {
3285 TopoDS_Vertex V1,V2;
3286 TopExp::Vertices(TopoDS::Edge(Root2), V1, V2);
3287 if ( V1.IsSame(Root1) || V2.IsSame(Root1)) {
3288 B.Continuity(OE,F1,F2,GeomAbs_G1);
3291 else if ( Type1 == TopAbs_FACE && Type2 == TopAbs_EDGE) {
3292 TopExp_Explorer exp2(Root1,TopAbs_EDGE);
3293 for ( ; exp2.More(); exp2.Next()) {
3294 if ( exp2.Current().IsSame(Root2)) {
3295 B.Continuity(OE,F1,F2,GeomAbs_G1);
3300 else if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_FACE) {
3301 TopExp_Explorer exp2(Root2,TopAbs_EDGE);
3302 for ( ; exp2.More(); exp2.Next()) {
3303 if ( exp2.Current().IsSame(Root1)) {
3304 B.Continuity(OE,F1,F2,GeomAbs_G1);
3309 else if ( Type1 == TopAbs_FACE && Type2 == TopAbs_FACE) {
3310 // if two root faces are tangent in
3311 // the initial shape, they will be tangent in the offset shape
3312 TopTools_ListOfShape LE;
3313 BRepOffset_Tool::FindCommonShapes(Root1, Root2, TopAbs_EDGE, LE);
3314 if ( LE.Extent() == 1) {
3315 const TopoDS_Edge& Ed = TopoDS::Edge(LE.First());
3316 if ( myAnalyse.HasAncestor(Ed)) {
3317 const BRepOffset_ListOfInterval& LI = myAnalyse.Type(Ed);
3318 if (LI.Extent() == 1 &&
3319 LI.First().Type() == BRepOffset_Tangent) {
3320 B.Continuity(OE,F1,F2,GeomAbs_G1);
3325 else if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_EDGE) {
3326 TopTools_ListOfShape LV;
3327 BRepOffset_Tool::FindCommonShapes(Root1, Root2, TopAbs_VERTEX, LV);
3328 if ( LV.Extent() == 1) {
3329 TopTools_ListOfShape LEdTg;
3330 myAnalyse.TangentEdges(TopoDS::Edge(Root1),
3331 TopoDS::Vertex(LV.First()),
3333 TopTools_ListIteratorOfListOfShape it(LEdTg);
3334 for (; it.More(); it.Next()) {
3335 if ( it.Value().IsSame(Root2)) {
3336 B.Continuity(OE,F1,F2,GeomAbs_G1);
3345 if ( ChronBuild) Clock.Show();
3349 //=======================================================================
3350 //function : ComputeMaxDist
3352 //=======================================================================
3353 Standard_Real ComputeMaxDist(const gp_Pln& thePlane,
3354 const Handle(Geom_Curve)& theCrv,
3355 const Standard_Real theFirst,
3356 const Standard_Real theLast)
3358 Standard_Real aMaxDist = 0.;
3359 Standard_Integer i, NCONTROL = 23;
3360 Standard_Real aPrm, aDist2;
3362 for (i = 0; i< NCONTROL; i++) {
3363 aPrm = ((NCONTROL - 1 - i)*theFirst + i*theLast) / (NCONTROL - 1);
3364 aP = theCrv->Value(aPrm);
3365 if (Precision::IsInfinite(aP.X()) || Precision::IsInfinite(aP.Y())
3366 || Precision::IsInfinite(aP.Z()))
3368 return Precision::Infinite();
3370 aDist2 = thePlane.SquareDistance(aP);
3371 if (aDist2 > aMaxDist) aMaxDist = aDist2;
3373 return sqrt(aMaxDist)*1.05;
3375 //=======================================================================
3376 //function : UpDateTolerance
3378 //=======================================================================
3380 void UpdateTolerance (TopoDS_Shape& S,
3381 const TopTools_IndexedMapOfShape& Faces)
3384 TopTools_MapOfShape View;
3387 // The edges of caps are not modified.
3389 for (j = 1; j <= Faces.Extent(); j++) {
3390 const TopoDS_Shape& F = Faces(j);
3391 TopExp_Explorer Exp;
3392 for (Exp.Init(F,TopAbs_EDGE); Exp.More(); Exp.Next()) {
3393 View.Add(Exp.Current());
3398 TopExp_Explorer ExpF;
3399 for (ExpF.Init(S, TopAbs_FACE); ExpF.More(); ExpF.Next())
3401 const TopoDS_Shape& F = ExpF.Current();
3402 if (Faces.Contains(F))
3406 BRepAdaptor_Surface aBAS(TopoDS::Face(F), Standard_False);
3407 TopExp_Explorer Exp;
3408 for (Exp.Init(F, TopAbs_EDGE); Exp.More(); Exp.Next()) {
3409 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
3410 Standard_Boolean isUpdated = Standard_False;
3411 if (aBAS.GetType() == GeomAbs_Plane)
3413 //Edge does not seem to have pcurve on plane,
3414 //so EdgeCorrector does not include it in tolerance calculation
3415 Standard_Real aFirst, aLast;
3416 Handle(Geom_Curve) aCrv = BRep_Tool::Curve(E, aFirst, aLast);
3417 Standard_Real aMaxDist = ComputeMaxDist(aBAS.Plane(), aCrv, aFirst, aLast);
3418 B.UpdateEdge(E, aMaxDist);
3419 isUpdated = Standard_True;
3424 BRepCheck_Edge EdgeCorrector(E);
3425 Tol = EdgeCorrector.Tolerance();
3426 B.UpdateEdge(E, Tol);
3427 isUpdated = Standard_True;
3431 Tol = BRep_Tool::Tolerance(E);
3432 // Update the vertices.
3433 TopExp::Vertices(E, V[0], V[1]);
3435 for (Standard_Integer i = 0; i <= 1; i++) {
3436 if (View.Add(V[i])) {
3437 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V[i].TShape());
3439 BRepCheck_Vertex VertexCorrector(V[i]);
3440 B.UpdateVertex(V[i], VertexCorrector.Tolerance());
3441 // use the occasion to clean the vertices.
3442 (TV->ChangePoints()).Clear();
3444 B.UpdateVertex(V[i], Tol);
3451 //=======================================================================
3452 //function : CorrectSolid
3454 //=======================================================================
3455 void CorrectSolid(TopoDS_Solid& theSol, TopTools_ListOfShape& theSolList)
3458 TopoDS_Shape anOuterShell;
3459 NCollection_List<Standard_Real> aVols;
3460 Standard_Real aVolMax = 0., anOuterVol = 0.;
3462 TopoDS_Iterator anIt(theSol);
3463 for(; anIt.More(); anIt.Next())
3465 const TopoDS_Shape& aSh = anIt.Value();
3466 GProp_GProps aVProps;
3467 BRepGProp::VolumeProperties(aSh, aVProps, Standard_True);
3468 if(Abs(aVProps.Mass()) > aVolMax)
3470 anOuterVol = aVProps.Mass();
3471 aVolMax = Abs(anOuterVol);
3474 aVols.Append(aVProps.Mass());
3477 if (Abs(anOuterVol) < Precision::Confusion()) {
3482 anOuterShell.Reverse();
3484 TopoDS_Solid aNewSol;
3485 aBB.MakeSolid(aNewSol);
3486 aNewSol.Closed(Standard_True);
3487 aBB.Add(aNewSol, anOuterShell);
3488 BRepClass3d_SolidClassifier aSolClass(aNewSol);
3490 anIt.Initialize(theSol);
3491 NCollection_List<Standard_Real>::Iterator aVIt(aVols);
3492 for(; anIt.More(); anIt.Next(), aVIt.Next())
3494 TopoDS_Shell aSh = TopoDS::Shell(anIt.Value());
3495 if(aSh.IsSame(anOuterShell))
3501 TopExp_Explorer aVExp(aSh, TopAbs_VERTEX);
3502 const TopoDS_Vertex& aV = TopoDS::Vertex(aVExp.Current());
3503 gp_Pnt aP = BRep_Tool::Pnt(aV);
3504 aSolClass.Perform(aP, BRep_Tool::Tolerance(aV));
3505 if(aSolClass.State() == TopAbs_IN)
3507 if(aVIt.Value() > 0.)
3511 aBB.Add(aNewSol, aSh);
3515 if(aVIt.Value() < 0.)
3520 aBB.MakeSolid(aSol);
3521 aSol.Closed(Standard_True);
3523 theSolList.Append(aSol);
3530 //=======================================================================
3531 //function : CheckInputData
3532 //purpose : Check input data for possiblity of offset perform.
3533 //=======================================================================
3534 Standard_Boolean BRepOffset_MakeOffset::CheckInputData()
3536 // Set initial error state.
3537 myError = BRepOffset_NoError;
3538 TopoDS_Shape aTmpShape;
3539 myBadShape = aTmpShape;
3542 if (Abs(myOffset) <= myTol)
3544 Standard_Boolean isFound = Standard_False;
3545 TopTools_DataMapIteratorOfDataMapOfShapeReal anIter(myFaceOffset);
3546 for( ; anIter.More(); anIter.Next())
3548 if (Abs(anIter.Value()) > myTol)
3550 isFound = Standard_True;
3557 // No face with non-null offset found.
3558 myError = BRepOffset_NullOffset;
3559 return Standard_False;
3563 // Connectivity of input shape.
3564 if (!IsConnectedShell(myShape))
3566 myError = BRepOffset_NotConnectedShell;
3567 return Standard_False;
3570 // Normals check and continuity check.
3571 const Standard_Integer aPntPerDim = 20; // 21 points on each dimension.
3572 Standard_Real aUmin, aUmax, aVmin, aVmax;
3573 TopExp_Explorer anExpSF(myShape, TopAbs_FACE);
3574 NCollection_Map<Handle(TopoDS_TShape)> aPresenceMap;
3577 for( ; anExpSF.More(); anExpSF.Next())
3579 const TopoDS_Face& aF = TopoDS::Face(anExpSF.Current());
3581 if (aPresenceMap.Contains(aF.TShape()))
3583 // Not perform computations with partner shapes,
3584 // since they are contain same geometry.
3587 aPresenceMap.Add(aF.TShape());
3589 const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aF, L);
3590 BRepTools::UVBounds(aF, aUmin, aUmax, aVmin, aVmax);
3592 // Continuity check.
3593 if (aSurf->Continuity() == GeomAbs_C0)
3595 myError = BRepOffset_C0Geometry;
3596 return Standard_False;
3599 // Get degenerated points, to avoid check them.
3600 NCollection_Vector<gp_Pnt> aBad3dPnts;
3601 TopExp_Explorer anExpFE(aF, TopAbs_EDGE);
3602 for( ; anExpFE.More(); anExpFE.Next())
3604 const TopoDS_Edge &aE = TopoDS::Edge(anExpFE.Current());
3605 if (BRep_Tool::Degenerated(aE))
3607 aBad3dPnts.Append(BRep_Tool::Pnt((TopExp::FirstVertex(aE))));
3611 // Geometry grid check.
3612 for(Standard_Integer i = 0; i <= aPntPerDim; i++)
3614 Standard_Real aUParam = aUmin + (aUmax - aUmin) * i / aPntPerDim;
3615 for(Standard_Integer j = 0; j <= aPntPerDim; j++)
3617 Standard_Real aVParam = aVmin + (aVmax - aVmin) * j / aPntPerDim;
3619 myError = checkSinglePoint(aUParam, aVParam, aSurf, aBad3dPnts);
3620 if (myError != BRepOffset_NoError)
3621 return Standard_False;
3625 // Vertex list check.
3626 TopExp_Explorer anExpFV(aF, TopAbs_VERTEX);
3627 for( ; anExpFV.More(); anExpFV.Next())
3629 const TopoDS_Vertex &aV = TopoDS::Vertex(anExpFV.Current());
3630 aPnt2d = BRep_Tool::Parameters(aV, aF);
3632 myError = checkSinglePoint(aPnt2d.X(), aPnt2d.Y(), aSurf, aBad3dPnts);
3633 if (myError != BRepOffset_NoError)
3634 return Standard_False;
3638 return Standard_True;
3642 //=======================================================================
3643 //function : GetBadShape
3644 //purpose : Get shape where problems detected.
3645 //=======================================================================
3646 const TopoDS_Shape& BRepOffset_MakeOffset::GetBadShape() const
3651 //=======================================================================
3652 //function : RemoveInternalEdges
3654 //=======================================================================
3655 void BRepOffset_MakeOffset::RemoveInternalEdges()
3657 Standard_Boolean bRemoveWire, bRemoveEdge;
3658 TopExp_Explorer aExpF, aExpW, aExpE;
3659 TopTools_IndexedDataMapOfShapeListOfShape aDMELF;
3661 TopExp::MapShapesAndAncestors(myOffsetShape, TopAbs_EDGE, TopAbs_FACE, aDMELF);
3663 aExpF.Init(myOffsetShape, TopAbs_FACE);
3664 for (; aExpF.More(); aExpF.Next()) {
3665 TopoDS_Face& aF = *(TopoDS_Face*)&aExpF.Current();
3667 TopTools_ListOfShape aLIW;
3669 aExpW.Init(aF, TopAbs_WIRE);
3670 for (; aExpW.More(); aExpW.Next()) {
3671 TopoDS_Wire& aW = *(TopoDS_Wire*)&aExpW.Current();
3673 bRemoveWire = Standard_True;
3674 TopTools_ListOfShape aLIE;
3676 aExpE.Init(aW, TopAbs_EDGE);
3677 for (; aExpE.More(); aExpE.Next()) {
3678 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExpE.Current();
3679 if (aE.Orientation() != TopAbs_INTERNAL) {
3680 bRemoveWire = Standard_False;
3684 const TopTools_ListOfShape& aLF = aDMELF.FindFromKey(aE);
3685 bRemoveEdge = (aLF.Extent() == 1);
3690 bRemoveWire = Standard_False;
3697 else if (aLIE.Extent()) {
3698 RemoveShapes(aW, aLIE);
3702 if (aLIW.Extent()) {
3703 RemoveShapes(aF, aLIW);
3708 //=======================================================================
3709 // static methods implementation
3710 //=======================================================================
3712 //=======================================================================
3713 //function : checkSinglePoint
3714 //purpose : Check single point on surface for bad normals
3715 //=======================================================================
3716 BRepOffset_Error checkSinglePoint(const Standard_Real theUParam,
3717 const Standard_Real theVParam,
3718 const Handle(Geom_Surface)& theSurf,
3719 const NCollection_Vector<gp_Pnt>& theBadPoints)
3723 theSurf->D1(theUParam, theVParam, aPnt, aD1U, aD1V);
3725 if (aD1U.SquareMagnitude() < Precision::SquareConfusion() ||
3726 aD1V.SquareMagnitude() < Precision::SquareConfusion() )
3728 Standard_Boolean isKnownBadPnt = Standard_False;
3729 for(Standard_Integer anIdx = theBadPoints.Lower();
3730 anIdx <= theBadPoints.Upper();
3733 if (aPnt.SquareDistance(theBadPoints(anIdx)) < Precision::SquareConfusion())
3735 isKnownBadPnt = Standard_True;
3738 } // for(Standard_Integer anIdx = theBadPoints.Lower();
3742 return BRepOffset_BadNormalsOnGeometry;
3746 return BRepOffset_NoError;
3748 } // if (aD1U.SquareMagnitude() < Precision::SquareConfusion() ||
3750 if (aD1U.IsParallel(aD1V, Precision::Confusion()))
3752 // Isolines are collinear.
3753 return BRepOffset_BadNormalsOnGeometry;
3756 return BRepOffset_NoError;
3759 //=======================================================================
3760 //function : RemoveShapes
3761 //purpose : Removes the shapes <theLS> from the shape <theS>
3762 //=======================================================================
3763 void RemoveShapes(TopoDS_Shape& theS,
3764 const TopTools_ListOfShape& theLS)
3768 Standard_Boolean bFree = theS.Free();
3769 theS.Free(Standard_True);
3771 TopTools_ListIteratorOfListOfShape aIt(theLS);
3772 for (; aIt.More(); aIt.Next()) {
3773 const TopoDS_Shape& aSI = aIt.Value();
3774 aBB.Remove(theS, aSI);
3780 //=======================================================================
3781 //function : UpdateHistory
3782 //purpose : Updates the history information
3783 //=======================================================================
3784 void UpdateHistory(const TopTools_ListOfShape& theLF,
3785 BOPAlgo_Builder& theGF,
3786 BRepAlgo_Image& theImage)
3788 TopTools_ListIteratorOfListOfShape aIt(theLF);
3789 for (; aIt.More(); aIt.Next()) {
3790 const TopoDS_Shape& aF = aIt.Value();
3791 const TopTools_ListOfShape& aLFIm = theGF.Modified(aF);
3792 if (aLFIm.Extent()) {
3793 if (theImage.HasImage(aF)) {
3794 theImage.Add(aF, aLFIm);
3797 theImage.Bind(aF, aLFIm);
3803 //=======================================================================
3804 //function : IntersectEdges
3806 //=======================================================================
3807 void BRepOffset_MakeOffset::IntersectEdges(const TopoDS_Shape& theShape,
3808 BRepOffset_DataMapOfShapeOffset& theMapSF,
3809 TopTools_DataMapOfShapeShape& theMES,
3810 TopTools_DataMapOfShapeShape& theBuild,
3811 Handle(BRepAlgo_AsDes)& theAsDes,
3812 Handle(BRepAlgo_AsDes)& theAsDes2d)
3814 Standard_Real aTolF;
3815 TopTools_IndexedDataMapOfShapeListOfShape aDMVV;
3816 TopExp_Explorer aExp(theShape, TopAbs_FACE);
3817 // intersect edges created from edges
3818 TopTools_IndexedMapOfShape aMFV;
3819 for (; aExp.More(); aExp.Next()) {
3820 const TopoDS_Face& aF = TopoDS::Face(aExp.Current());
3821 aTolF = BRep_Tool::Tolerance(aF);
3822 BRepOffset_Inter2d::ConnexIntByInt
3823 (aF, theMapSF(aF), theMES, theBuild, theAsDes2d, myOffset, aTolF, aMFV, aDMVV);
3825 // intersect edges created from vertices
3826 Standard_Integer i, aNbF = aMFV.Extent();
3827 for (i = 1; i <= aNbF; ++i) {
3828 const TopoDS_Face& aF = TopoDS::Face(aMFV(i));
3829 aTolF = BRep_Tool::Tolerance(aF);
3830 BRepOffset_Inter2d::ConnexIntByIntInVert
3831 (aF, theMapSF(aF), theMES, theBuild, theAsDes, theAsDes2d, aTolF, aDMVV);
3834 // fuse vertices on edges
3835 BRepOffset_Inter2d::FuseVertices(aDMVV, theAsDes2d);
3838 //=======================================================================
3839 //function : TrimEdges
3841 //=======================================================================
3842 void TrimEdges(const TopoDS_Shape& theShape,
3843 const Standard_Real theOffset,
3844 BRepOffset_DataMapOfShapeOffset& theMapSF,
3845 TopTools_DataMapOfShapeShape& theMES,
3846 TopTools_DataMapOfShapeShape& theBuild,
3847 Handle(BRepAlgo_AsDes)& theAsDes,
3848 Handle(BRepAlgo_AsDes)& theAsDes2d,
3849 TopTools_IndexedMapOfShape& theNewEdges,
3850 TopTools_DataMapOfShapeShape& theETrimEInf,
3851 TopTools_DataMapOfShapeListOfShape& theEdgesOrigins)
3853 TopExp_Explorer Exp,Exp2,ExpC;
3858 for (Exp.Init(theShape,TopAbs_FACE) ; Exp.More(); Exp.Next()) {
3859 const TopoDS_Face& FI = TopoDS::Face(Exp.Current());
3860 NF = theMapSF(FI).Face();
3861 if (theMES.IsBound(NF)) {
3862 NF = TopoDS::Face(theMES(NF));
3865 TopTools_MapOfShape View;
3866 TopTools_IndexedMapOfShape VEmap;
3867 Standard_Integer i, aNb;
3869 TopExp::MapShapes(FI.Oriented(TopAbs_FORWARD), TopAbs_EDGE , VEmap);
3870 TopExp::MapShapes(FI.Oriented(TopAbs_FORWARD), TopAbs_VERTEX, VEmap);
3872 aNb = VEmap.Extent();
3873 for (i = 1; i <= aNb; ++i) {
3874 const TopoDS_Shape& aS = VEmap(i);
3875 if (!View.Add(aS)) {
3879 if (theBuild.IsBound(aS)) {
3881 // keep connection to original edges
3882 ExpC.Init(NE, TopAbs_EDGE);
3883 for (; ExpC.More(); ExpC.Next()) {
3884 const TopoDS_Edge& NEC = TopoDS::Edge(ExpC.Current());
3885 TopTools_ListOfShape* pLEOr = theEdgesOrigins.ChangeSeek(NEC);
3887 pLEOr = theEdgesOrigins.Bound(NEC, TopTools_ListOfShape());
3889 AppendToList(*pLEOr, aS);
3892 if (NE.ShapeType() == TopAbs_EDGE) {
3893 if (theNewEdges.Add(NE)) {
3894 TrimEdge (TopoDS::Edge(NE),theAsDes2d,theAsDes, theETrimEInf);
3898 //------------------------------------------------------------
3899 // The Intersections are on several edges.
3900 // The pieces without intersections with neighbors
3901 // are removed from AsDes.
3902 //------------------------------------------------------------
3903 for (ExpC.Init(NE,TopAbs_EDGE); ExpC.More(); ExpC.Next()) {
3904 TopoDS_Edge NEC = TopoDS::Edge(ExpC.Current());
3905 if (theNewEdges.Add(NEC)) {
3906 if (!theAsDes2d->Descendant(NEC).IsEmpty()) {
3907 TrimEdge (NEC,theAsDes2d, theAsDes, theETrimEInf);
3910 if (theAsDes->HasAscendant(NEC)) {
3911 theAsDes->Remove(NEC);
3919 if (aS.ShapeType() != TopAbs_EDGE) {
3923 NE = theMapSF(FI).Generated(aS);
3924 //// modified by jgv, 19.12.03 for OCC4455 ////
3925 NE.Orientation(aS.Orientation());
3927 TopTools_ListOfShape* pLEOr = theEdgesOrigins.ChangeSeek(NE);
3929 pLEOr = theEdgesOrigins.Bound(NE, TopTools_ListOfShape());
3931 AppendToList(*pLEOr, aS);
3933 if (theMES.IsBound(NE)) {
3935 NE.Orientation(aS.Orientation());
3936 if (theNewEdges.Add(NE)) {
3937 TrimEdge (TopoDS::Edge(NE), theAsDes2d, theAsDes, theETrimEInf);
3941 TopoDS_Edge& anEdge = TopoDS::Edge(NE);
3942 BRepAdaptor_Curve aBAC(anEdge);
3943 if (aBAC.GetType() == GeomAbs_Line) {
3944 TopoDS_Edge aNewEdge;
3945 BRepOffset_Inter2d::ExtentEdge(anEdge, aNewEdge, theOffset);
3946 theETrimEInf.Bind(anEdge, aNewEdge);
3949 theAsDes->Add(NF,NE);
3955 //=======================================================================
3956 //function : TrimEdge
3957 //purpose : Trim the edge of the largest of descendants in AsDes2d.
3958 // Order in AsDes two vertices that have trimmed the edge.
3959 //=======================================================================
3960 void TrimEdge(TopoDS_Edge& NE,
3961 const Handle(BRepAlgo_AsDes)& AsDes2d,
3962 Handle(BRepAlgo_AsDes)& AsDes,
3963 TopTools_DataMapOfShapeShape& theETrimEInf)
3965 TopoDS_Edge aSourceEdge;
3966 TopoDS_Vertex V1,V2;
3967 Standard_Real aT1, aT2;
3969 TopExp::Vertices(NE, V1, V2);
3970 BRep_Tool::Range(NE, aT1, aT2);
3972 BOPTools_AlgoTools::MakeSplitEdge(NE, V1, aT1, V2, aT2, aSourceEdge);
3975 Standard_Real aSameParTol = Precision::Confusion();
3977 Standard_Real U = 0.;
3978 Standard_Real UMin = Precision::Infinite();
3979 Standard_Real UMax = -UMin;
3981 const TopTools_ListOfShape& LE = AsDes2d->Descendant(NE);
3983 Standard_Boolean bTrim = Standard_False;
3985 if (LE.Extent() > 1) {
3986 TopTools_ListIteratorOfListOfShape it (LE);
3987 for (; it.More(); it.Next()) {
3988 TopoDS_Vertex V = TopoDS::Vertex(it.Value());
3989 if (NE.Orientation() == TopAbs_REVERSED)
3991 //V.Orientation(TopAbs_INTERNAL);
3992 if (!FindParameter(V, NE, U)) {
3994 Handle(Geom_Curve) theCurve = BRep_Tool::Curve(NE, f, l);
3995 gp_Pnt thePoint = BRep_Tool::Pnt(V);
3996 GeomAPI_ProjectPointOnCurve Projector(thePoint, theCurve);
3997 if (Projector.NbPoints() == 0)
3998 throw Standard_ConstructionError("BRepOffset_MakeOffset::TrimEdge no projection");
3999 U = Projector.LowerDistanceParameter();
4009 if (V1.IsNull() || V2.IsNull()) {
4010 throw Standard_ConstructionError("BRepOffset_MakeOffset::TrimEdge");
4012 if (!V1.IsSame(V2)) {
4013 NE.Free( Standard_True );
4015 TopAbs_Orientation Or = NE.Orientation();
4016 NE.Orientation(TopAbs_FORWARD);
4017 TopoDS_Vertex VF,VL;
4018 TopExp::Vertices (NE,VF,VL);
4021 B.Add (NE,V1.Oriented(TopAbs_FORWARD));
4022 B.Add (NE,V2.Oriented(TopAbs_REVERSED));
4023 B.Range(NE,UMin,UMax);
4025 AsDes->Add(NE,V1.Oriented(TopAbs_FORWARD));
4026 AsDes->Add(NE,V2.Oriented(TopAbs_REVERSED));
4027 BRepLib::SameParameter(NE, aSameParTol, Standard_True);
4029 bTrim = Standard_True;
4034 BRepAdaptor_Curve aBAC(NE);
4035 if (aBAC.GetType() == GeomAbs_Line) {
4036 if (AsDes->HasAscendant(NE)) {
4043 if (!theETrimEInf.IsBound(NE)) {
4044 theETrimEInf.Bind(NE, aSourceEdge);
4049 //=======================================================================
4050 //function : GetEnlargedFaces
4052 //=======================================================================
4053 void GetEnlargedFaces(const TopoDS_Shape& theShape,
4054 const BRepOffset_DataMapOfShapeOffset& theMapSF,
4055 const TopTools_DataMapOfShapeShape& theMES,
4056 TopTools_DataMapOfShapeShape& theFacesOrigins,
4057 BRepAlgo_Image& theImage,
4058 TopTools_ListOfShape& theLSF)
4060 TopExp_Explorer aExp(theShape, TopAbs_FACE);
4061 for (; aExp.More(); aExp.Next()) {
4062 const TopoDS_Shape& FI = aExp.Current();
4063 const TopoDS_Shape& OFI = theMapSF(FI).Face();
4064 if (theMES.IsBound(OFI)) {
4065 const TopoDS_Face& aLocalFace = TopoDS::Face(theMES(OFI));
4066 theLSF.Append(aLocalFace);
4067 theImage.SetRoot(aLocalFace);
4069 theFacesOrigins.Bind(aLocalFace, FI);
4074 //=======================================================================
4075 //function : BuildShellsCompleteInter
4076 //purpose : Make the shells from list of faces using MakerVolume algorithm.
4077 // In case there will be more than just one solid, it will be
4078 // rebuilt using only outer faces.
4079 //=======================================================================
4080 Standard_Boolean BuildShellsCompleteInter(const BOPCol_ListOfShape& theLF,
4081 const BOPCol_IndexedDataMapOfShapeListOfShape& theOrigins,
4082 BRepAlgo_Image& theImage,
4083 TopoDS_Shape& theShells)
4086 BOPAlgo_MakerVolume aMV1;
4087 aMV1.SetArguments(theLF);
4088 // we need to intersect the faces to process the tangential faces
4089 aMV1.SetIntersect(Standard_True);
4090 aMV1.SetAvoidInternalShapes(Standard_True);
4093 Standard_Boolean bDone = (aMV1.ErrorStatus() == 0);
4098 UpdateHistory(theLF, aMV1, theImage);
4100 const TopoDS_Shape& aResult1 = aMV1.Shape();
4101 if (aResult1.ShapeType() == TopAbs_SOLID) {
4102 // result is the alone solid, nothing to do
4103 return GetSubShapes(aResult1, TopAbs_SHELL, theShells);
4106 // it is necessary to rebuild the solids, avoiding internal faces
4108 // map faces to solids
4109 TopTools_IndexedDataMapOfShapeListOfShape aDMFS;
4110 TopExp::MapShapesAndAncestors(aResult1, TopAbs_FACE, TopAbs_SOLID, aDMFS);
4112 Standard_Integer i, aNb = aDMFS.Extent();
4115 // unable to build any solid
4119 // get faces attached to only one solid
4120 BOPCol_ListOfShape aLF2;
4121 for (i = 1; i <= aNb; ++i) {
4122 const TopTools_ListOfShape& aLS = aDMFS(i);
4123 if (aLS.Extent() == 1) {
4124 const TopoDS_Shape& aF = aDMFS.FindKey(i);
4129 // make solids from the new list
4130 BOPAlgo_MakerVolume aMV2;
4131 aMV2.SetArguments(aLF2);
4132 // no need to intersect this time
4133 aMV2.SetIntersect(Standard_False);
4134 aMV2.SetAvoidInternalShapes(Standard_True);
4136 bDone = (aMV2.ErrorStatus() == 0);
4141 const TopoDS_Shape& aResult2 = aMV2.Shape();
4142 if (aResult2.ShapeType() == TopAbs_SOLID) {
4143 return GetSubShapes(aResult2, TopAbs_SHELL, theShells);
4146 TopExp_Explorer aExp(aResult2, TopAbs_FACE);
4147 bDone = aExp.More();
4152 // the result is non-manifold - resolve it comparing normals
4153 // directions of the offset faces and original faces
4154 BOPCol_ListOfShape aLF3;
4155 for (; aExp.More(); aExp.Next()) {
4156 const TopoDS_Face& aF = TopoDS::Face(aExp.Current());
4158 // check orientation
4159 if (!theOrigins.Contains(aF)) {
4164 const TopTools_ListOfShape& aLFOr = theOrigins.FindFromKey(aF);
4165 TopTools_ListIteratorOfListOfShape aItLF(aLFOr);
4166 for (; aItLF.More(); aItLF.Next()) {
4167 const TopoDS_Face& aFOr = TopoDS::Face(aItLF.Value());
4168 if (BRepOffset_Tool::CheckPlanesNormals(aF, aFOr)) {
4175 // make solid from most outer faces with correct normal direction
4176 BOPAlgo_MakerVolume aMV3;
4177 aMV3.SetArguments(aLF3);
4178 aMV3.SetIntersect(Standard_False);
4179 aMV3.SetAvoidInternalShapes(Standard_True);
4181 bDone = (aMV3.ErrorStatus() == 0);
4186 const TopoDS_Shape& aResult3 = aMV3.Shape();
4187 return GetSubShapes(aResult3, TopAbs_SHELL, theShells);
4190 //=======================================================================
4191 //function : GetSubShapes
4193 //=======================================================================
4194 Standard_Boolean GetSubShapes(const TopoDS_Shape& theShape,
4195 const TopAbs_ShapeEnum theSSType,
4196 TopoDS_Shape& theResult)
4198 TopExp_Explorer aExp(theShape, theSSType);
4200 return Standard_False;
4203 TopoDS_Compound aResult;
4204 BRep_Builder().MakeCompound(aResult);
4206 for (; aExp.More(); aExp.Next()) {
4207 const TopoDS_Shape& aSS = aExp.Current();
4208 BRep_Builder().Add(aResult, aSS);
4210 theResult = aResult;
4211 return Standard_True;
4214 //=======================================================================
4215 //function : IsPlanar
4216 //purpose : Checks if all the faces of the shape are planes
4217 //=======================================================================
4218 Standard_Boolean IsPlanar(const TopoDS_Shape& theS)
4220 TopExp_Explorer aExp(theS, TopAbs_FACE);
4221 for (; aExp.More(); aExp.Next()) {
4222 const TopoDS_Face& aF = *(TopoDS_Face*)&aExp.Current();
4223 BRepAdaptor_Surface aBAS(aF, Standard_False);
4224 if (aBAS.GetType() != GeomAbs_Plane) {
4228 return !aExp.More();
4231 //=======================================================================
4232 //function : IsSolid
4233 //purpose : Checks if the shape is solid
4234 //=======================================================================
4235 Standard_Boolean IsSolid(const TopoDS_Shape& theS)
4237 TopExp_Explorer aExp(theS, TopAbs_SOLID);
4241 //=======================================================================
4242 //function : AppendToList
4243 //purpose : Add to a list only unique elements
4244 //=======================================================================
4245 void AppendToList(TopTools_ListOfShape& theList,
4246 const TopoDS_Shape& theShape)
4248 TopTools_ListIteratorOfListOfShape aIt(theList);
4249 for (; aIt.More(); aIt.Next()) {
4250 const TopoDS_Shape& aS = aIt.Value();
4251 if (aS.IsSame(theShape)) {
4255 theList.Append(theShape);