0029321: Improve performance of the 3D offset algorithm for the planar cases
[occt.git] / src / BRepOffset / BRepOffset_MakeOffset.cxx
CommitLineData
b311480e 1// Created on: 1995-10-27
2// Created by: Yves FRICAUD
3// Copyright (c) 1995-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
17// Modified by skv - Tue Mar 15 16:20:43 2005
18// Add methods for supporting history.
7fd59977 19// Modified by skv - Mon Jan 12 11:50:02 2004 OCC4455
20
42cf5bc1 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>
7fd59977 43#include <BRepOffset_Analyse.hxx>
7fd59977 44#include <BRepOffset_DataMapIteratorOfDataMapOfShapeOffset.hxx>
42cf5bc1 45#include <BRepOffset_DataMapOfShapeMapOfShape.hxx>
46#include <BRepOffset_DataMapOfShapeOffset.hxx>
47#include <BRepOffset_Inter2d.hxx>
48#include <BRepOffset_Inter3d.hxx>
7fd59977 49#include <BRepOffset_Interval.hxx>
50#include <BRepOffset_ListOfInterval.hxx>
42cf5bc1 51#include <BRepOffset_MakeLoops.hxx>
52#include <BRepOffset_MakeOffset.hxx>
7fd59977 53#include <BRepOffset_Offset.hxx>
54#include <BRepOffset_Tool.hxx>
7fd59977 55#include <BRepTools.hxx>
42cf5bc1 56#include <BRepTools_Quilt.hxx>
57#include <BRepTools_Substitution.hxx>
58#include <BRepTools_WireExplorer.hxx>
7fd59977 59#include <ElCLib.hxx>
42cf5bc1 60#include <ElSLib.hxx>
61#include <GC_MakeCylindricalSurface.hxx>
7fd59977 62#include <GCE2d_MakeLine.hxx>
42cf5bc1 63#include <gce_MakeCone.hxx>
64#include <gce_MakeDir.hxx>
7fd59977 65#include <Geom2d_Line.hxx>
42cf5bc1 66#include <Geom2d_TrimmedCurve.hxx>
67#include <Geom2dAdaptor_HCurve.hxx>
7fd59977 68#include <Geom_Circle.hxx>
42cf5bc1 69#include <Geom_ConicalSurface.hxx>
c04c30b3 70#include <Geom_CylindricalSurface.hxx>
42cf5bc1 71#include <Geom_OffsetSurface.hxx>
72#include <Geom_Plane.hxx>
73#include <Geom_SphericalSurface.hxx>
7fd59977 74#include <Geom_SurfaceOfLinearExtrusion.hxx>
42cf5bc1 75#include <Geom_TrimmedCurve.hxx>
7fd59977 76#include <GeomAdaptor_HSurface.hxx>
42cf5bc1 77#include <GeomAPI_ProjectPointOnCurve.hxx>
7fd59977 78#include <GeomFill_Generator.hxx>
42cf5bc1 79#include <GeomLib.hxx>
80#include <gp_Cone.hxx>
81#include <gp_Lin2d.hxx>
82#include <gp_Pnt.hxx>
83#include <GProp_GProps.hxx>
bb310307 84#include <IntTools_FClass2d.hxx>
db2f1498 85#include <NCollection_List.hxx>
42cf5bc1 86#include <Precision.hxx>
87#include <Standard_ConstructionError.hxx>
88#include <Standard_NotImplemented.hxx>
89#include <TColStd_ListIteratorOfListOfInteger.hxx>
90#include <TopExp.hxx>
91#include <TopExp_Explorer.hxx>
92#include <TopoDS.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>
a8704c36 112#include <BRepBuilderAPI_Sewing.hxx>
113#include <Geom_Line.hxx>
e1ed38e0 114#include <NCollection_Vector.hxx>
e7384fd4 115#include <NCollection_IncAllocator.hxx>
9b7f3f83 116//
9b7f3f83 117#include <BOPAlgo_MakerVolume.hxx>
9b7f3f83 118#include <BOPTools_AlgoTools.hxx>
ecf4f17c 119#include <BOPCol_ListOfShape.hxx>
7fd59977 120
42cf5bc1 121#include <stdio.h>
122// POP for NT
7fd59977 123#ifdef DRAW
124
125#include <DBRep.hxx>
126#endif
0797d9d3 127#ifdef OCCT_DEBUG
7fd59977 128#include <OSD_Chronometer.hxx>
498ce76b 129//#define DEB_VERB
7fd59977 130 Standard_Boolean AffichInt2d = Standard_False;
131 Standard_Boolean AffichOffC = Standard_False;
132 Standard_Boolean ChronBuild = Standard_False;
133 Standard_Integer NbAE = 0;
134 Standard_Integer NbAF = 0;
b0091bc9 135 Standard_Integer NVP = 0;
136 Standard_Integer NVM = 0;
137 Standard_Integer NVN = 0;
7fd59977 138 static OSD_Chronometer Clock;
139 char name[100];
140
141
142
143
144//=======================================================================
145//function : DEBVerticesControl
146//purpose :
147//=======================================================================
148
975ec82a 149static void DEBVerticesControl (const TopTools_IndexedMapOfShape& NewEdges,
9b7f3f83 150 Handle(BRepAlgo_AsDes) AsDes)
7fd59977 151{
7fd59977 152 TopTools_ListOfShape LVP;
7fd59977 153 TopTools_ListIteratorOfListOfShape it1LE ;
154 TopTools_ListIteratorOfListOfShape it2LE ;
155
975ec82a
J
156 Standard_Integer i;
157 for (i = 1; i <= NewEdges.Extent(); i++) {
158 const TopoDS_Edge& NE = TopoDS::Edge(NewEdges(i));
7fd59977 159 if (AsDes->HasDescendant(NE)) {
160 for (it1LE.Initialize(AsDes->Descendant(NE)); it1LE.More(); it1LE.Next()) {
9b7f3f83 161 if (AsDes->Ascendant(it1LE.Value()).Extent() < 3) {
162 LVP.Append(it1LE.Value());
163 cout <<"Vertex on at least 3 edges."<<endl;
7fd59977 164#ifdef DRAW
9b7f3f83 165 if (AffichInt2d) {
166 sprintf (name,"VP_%d",NVP++);
167 DBRep::Set(name,it1LE.Value());
168 }
7fd59977 169#endif
9b7f3f83 170 }
171 else if (AsDes->Ascendant(it1LE.Value()).Extent() > 3) {
172 cout <<"Vertex on more than 3 edges."<<endl;
7fd59977 173#ifdef DRAW
9b7f3f83 174 if (AffichInt2d) {
175 sprintf (name,"VM_%d",NVM++);
176 DBRep::Set(name,it1LE.Value());
177 }
7fd59977 178#endif
9b7f3f83 179
180 }
181 else {
7fd59977 182#ifdef DRAW
9b7f3f83 183 if (AffichInt2d) {
184 sprintf (name,"VN_%d",NVN++);
185 DBRep::Set(name,it1LE.Value());
186 }
7fd59977 187#endif
9b7f3f83 188 }
7fd59977 189 }
190 }
191 }
192 //------------------------------------------------
0d969553 193 // Try to mix spoiled vertices.
7fd59977 194 //------------------------------------------------
195 BRep_Builder B;
196 TopTools_ListIteratorOfListOfShape it1(LVP);
197 Standard_Real TolConf = 1.e-5;
198 Standard_Real Tol = Precision::Confusion();
975ec82a
J
199 //Standard_Integer i = 1;
200
201 i = 1;
7fd59977 202 for ( ; it1.More(); it1.Next()) {
203 TopoDS_Shape V1 = it1.Value();
204 gp_Pnt P1 = BRep_Tool::Pnt(TopoDS::Vertex(V1));
205 Standard_Real distmin = Precision::Infinite();
206 TopTools_ListIteratorOfListOfShape it2(LVP);
207 Standard_Integer j = 1;
208
209 for ( ; it2.More(); it2.Next()) {
210 if (j > i) {
9b7f3f83 211 TopoDS_Shape V2 = it2.Value();
212 gp_Pnt P2 = BRep_Tool::Pnt(TopoDS::Vertex(V2));
213 if (!V1.IsSame(V2)) {
214 Standard_Real dist = P1.Distance(P2);
215 if (dist < distmin) distmin = dist;
216 if (dist < TolConf) {
217 Standard_Real UV2;
218 TopoDS_Edge EWE2;
219 const TopTools_ListOfShape& EdgeWithV2 = AsDes->Ascendant(V2);
220 TopTools_ListIteratorOfListOfShape itAsDes;
221 for (itAsDes.Initialize(EdgeWithV2); itAsDes.More(); itAsDes.Next()) {
222 EWE2 = TopoDS::Edge(itAsDes.Value());
223 TopoDS_Shape aLocalShape = V2.Oriented(TopAbs_INTERNAL);
224 UV2 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalShape),EWE2);
225 aLocalShape = V1.Oriented(TopAbs_INTERNAL) ;
226 B.UpdateVertex(TopoDS::Vertex(aLocalShape),UV2,EWE2,Tol);
227// UV2 =
228// BRep_Tool::Parameter(TopoDS::Vertex(),EWE2);
229// B.UpdateVertex(TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)),
230// UV2,EWE2,Tol);
231 }
232 AsDes->Replace(V2,V1);
233 }
234 }
7fd59977 235 }
236 j++;
237 }
238 i++;
0d969553 239 cout <<" distmin between VP : "<<distmin<<endl;
7fd59977 240 }
241}
242#endif
243
9b7f3f83 244
245//=======================================================================
246// static methods
247//=======================================================================
ecf4f17c 248static
249 void GetEnlargedFaces(const TopoDS_Shape& theShape,
250 const BRepOffset_DataMapOfShapeOffset& theMapSF,
251 const TopTools_DataMapOfShapeShape& theMES,
252 TopTools_DataMapOfShapeShape& theFacesOrigins,
253 BRepAlgo_Image& theImage,
254 TopTools_ListOfShape& theLSF);
9b7f3f83 255
ecf4f17c 256static
257 Standard_Boolean BuildShellsCompleteInter(const BOPCol_ListOfShape& theLF,
ecf4f17c 258 BRepAlgo_Image& theImage,
259 TopoDS_Shape& theShells);
9b7f3f83 260
ecf4f17c 261static
262 Standard_Boolean GetSubShapes(const TopoDS_Shape& theShape,
263 const TopAbs_ShapeEnum theSSType,
264 TopoDS_Shape& theResult);
9b7f3f83 265
9b7f3f83 266static
267 void UpdateInitOffset(BRepAlgo_Image& myInitOffset,
268 BRepAlgo_Image& myImageOffset,
269 const TopoDS_Shape& myOffsetShape,
270 const TopAbs_ShapeEnum &theShapeType);
271
272static
273 void RemoveShapes(TopoDS_Shape& theS,
274 const TopTools_ListOfShape& theLS);
275
276static
277 Standard_Boolean IsSolid(const TopoDS_Shape& theS);
278
279static
280 void UpdateHistory(const TopTools_ListOfShape& theLF,
281 BOPAlgo_Builder& theGF,
282 BRepAlgo_Image& theImage);
283
284static
285 Standard_Boolean IsPlanar(const TopoDS_Shape& theS);
286
ecf4f17c 287static
288 void TrimEdge(TopoDS_Edge& NE,
289 const Handle(BRepAlgo_AsDes)& AsDes2d,
290 Handle(BRepAlgo_AsDes)& AsDes,
291 TopTools_DataMapOfShapeShape& theETrimEInf);
292
293static
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);
304
305static
306 void AppendToList(TopTools_ListOfShape& theL,
307 const TopoDS_Shape& theS);
308
e1ed38e0 309static 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);
313
db2f1498 314//---------------------------------------------------------------------
975ec82a 315static void UpdateTolerance ( TopoDS_Shape& myShape,
9b7f3f83 316 const TopTools_IndexedMapOfShape& myFaces);
4560c054 317static Standard_Real ComputeMaxDist(const gp_Pln& thePlane,
318 const Handle(Geom_Curve)& theCrv,
319 const Standard_Real theFirst,
320 const Standard_Real theLast);
7fd59977 321
db2f1498 322static void CorrectSolid(TopoDS_Solid& theSol, TopTools_ListOfShape& theSolList);
323//---------------------------------------------------------------------
324//
7fd59977 325static Standard_Boolean FindParameter(const TopoDS_Vertex& V,
9b7f3f83 326 const TopoDS_Edge& E,
327 Standard_Real& U)
7fd59977 328{
329 // Search the vertex in the edge
330
331 Standard_Boolean rev = Standard_False;
332 TopoDS_Shape VF;
333 TopAbs_Orientation orient = TopAbs_INTERNAL;
334
335 TopoDS_Iterator itv(E.Oriented(TopAbs_FORWARD));
336
337 // if the edge has no vertices
338 // and is degenerated use the vertex orientation
339 // RLE, june 94
340
341 if (!itv.More() && BRep_Tool::Degenerated(E)) {
342 orient = V.Orientation();
343 }
344
345 while (itv.More()) {
346 const TopoDS_Shape& Vcur = itv.Value();
347 if (V.IsSame(Vcur)) {
348 if (VF.IsNull()) {
9b7f3f83 349 VF = Vcur;
7fd59977 350 }
351 else {
9b7f3f83 352 rev = E.Orientation() == TopAbs_REVERSED;
353 if (Vcur.Orientation() == V.Orientation()) {
354 VF = Vcur;
355 }
7fd59977 356 }
357 }
358 itv.Next();
359 }
360
361 if (!VF.IsNull()) orient = VF.Orientation();
362
363 Standard_Real f,l;
364
365 if (orient == TopAbs_FORWARD) {
366 BRep_Tool::Range(E,f,l);
367 //return (rev) ? l : f;
368 U = (rev) ? l : f;
369 return Standard_True;
370 }
371
372 else if (orient == TopAbs_REVERSED) {
373 BRep_Tool::Range(E,f,l);
374 //return (rev) ? f : l;
375 U = (rev) ? f : l;
376 return Standard_True;
377 }
378
379 else {
380 TopLoc_Location L;
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
9b7f3f83 385 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
7fd59977 386
387 while (itpr.More()) {
9b7f3f83 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
392 if (!C.IsNull()) {
393 // Closed curves RLE 16 june 94
394 if (Precision::IsNegativeInfinite(f))
395 {
396 //return pr->Parameter();//p;
397 U = pr->Parameter();
398 return Standard_True;
399 }
400 if (Precision::IsPositiveInfinite(l))
401 {
402 //return pr->Parameter();//p;
403 U = pr->Parameter();
404 return Standard_True;
405 }
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;
413 }
414 }
415 }
416 //return res;//p;
417 U = res;
418 return Standard_True;
419 }
420 itpr.Next();
7fd59977 421 }
422 }
423 else {
424 // no 3d curve !!
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
9b7f3f83 431 ((*((Handle(BRep_TVertex)*) &V.TShape()))->Points());
7fd59977 432
433 while (itpr.More()) {
9b7f3f83 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();
443 }
444 }
445 //return p;
446 U = p;
447 return Standard_True;
448 }
449 itpr.Next();
7fd59977 450 }
451 }
452 }
453
9775fa61 454 //throw Standard_NoSuchObject("BRep_Tool:: no parameter on edge");
7fd59977 455 return Standard_False;
456}
457
458//=======================================================================
459//function : GetEdgePoints
460//purpose : gets the first, last and middle points of the edge
461//=======================================================================
462static void GetEdgePoints(const TopoDS_Edge& anEdge,
463 const TopoDS_Face& aFace,
464 gp_Pnt& fPnt, gp_Pnt& mPnt,
465 gp_Pnt& lPnt)
466{
467 Standard_Real f, l;
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());
476}
477
478//=======================================================================
479//function : FillContours
480//purpose : fills free boundary contours and faces connected (MapEF)
481//=======================================================================
482static void FillContours(const TopoDS_Shape& aShape,
9b7f3f83 483 const BRepOffset_Analyse& Analyser,
484 TopTools_DataMapOfShapeListOfShape& Contours,
485 TopTools_DataMapOfShapeShape& MapEF)
7fd59977 486{
487 TopTools_ListOfShape Edges;
488
489 TopExp_Explorer Explo(aShape, TopAbs_FACE);
490 BRepTools_WireExplorer Wexp;
491
492 for (; Explo.More(); Explo.Next())
493 {
494 TopoDS_Face aFace = TopoDS::Face(Explo.Current());
495 TopoDS_Iterator itf(aFace);
496 for (; itf.More(); itf.Next())
9b7f3f83 497 {
498 TopoDS_Wire aWire = TopoDS::Wire(itf.Value());
499 for (Wexp.Init(aWire, aFace); Wexp.More(); Wexp.Next())
500 {
501 TopoDS_Edge anEdge = Wexp.Current();
502 if (BRep_Tool::Degenerated(anEdge))
503 continue;
504 const BRepOffset_ListOfInterval& Lint = Analyser.Type(anEdge);
505 if (!Lint.IsEmpty() && Lint.First().Type() == BRepOffset_FreeBoundary)
506 {
507 MapEF.Bind(anEdge, aFace);
508 Edges.Append(anEdge);
509 }
510 }
511 }
7fd59977 512 }
513
514 TopTools_ListIteratorOfListOfShape itl;
515 while (!Edges.IsEmpty())
516 {
517 TopoDS_Edge StartEdge = TopoDS::Edge(Edges.First());
518 Edges.RemoveFirst();
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))
9b7f3f83 524 for (itl.Initialize(Edges); itl.More(); itl.Next())
525 {
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))
530 {
531 aContour.Append(anEdge);
532 CurVertex = (V1.IsSame(CurVertex))? V2 : V1;
533 Edges.Remove(itl);
534 break;
535 }
536 }
7fd59977 537 Contours.Bind(StartVertex, aContour);
538 }
539}
540
db2f1498 541//
542//-----------------------------------------------------------------------
543//
7fd59977 544//=======================================================================
545//function : BRepOffset_MakeOffset
546//purpose :
547//=======================================================================
548
549BRepOffset_MakeOffset::BRepOffset_MakeOffset()
550{
551 myAsDes = new BRepAlgo_AsDes();
552}
553
554
555//=======================================================================
556//function : BRepOffset_MakeOffset
557//purpose :
558//=======================================================================
559
560BRepOffset_MakeOffset::BRepOffset_MakeOffset(const TopoDS_Shape& S,
9b7f3f83 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,
ecf4f17c 568 const Standard_Boolean RemoveIntEdges)
7fd59977 569:
570myOffset (Offset),
571myTol (Tol),
572myShape (S),
573myMode (Mode),
574myInter (Inter),
575mySelfInter (SelfInter),
576myJoin (Join),
9b7f3f83 577myThickening (Thickening),
578myRemoveIntEdges(RemoveIntEdges),
7fd59977 579myDone (Standard_False)
7fd59977 580{
581 myAsDes = new BRepAlgo_AsDes();
582 MakeOffsetShape();
583}
584
585
586//=======================================================================
587//function : Initialize
588//purpose :
589//=======================================================================
590
591void BRepOffset_MakeOffset::Initialize(const TopoDS_Shape& S,
9b7f3f83 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,
ecf4f17c 599 const Standard_Boolean RemoveIntEdges)
7fd59977 600{
601 myOffset = Offset;
602 myShape = S;
603 myTol = Tol;
604 myMode = Mode;
605 myInter = Inter;
606 mySelfInter = SelfInter;
607 myJoin = Join;
9b7f3f83 608 myThickening = Thickening;
609 myRemoveIntEdges = RemoveIntEdges;
7fd59977 610 myDone = Standard_False;
a8704c36 611 myIsPerformSewing = Standard_False;
9b7f3f83 612 myIsPlanar = Standard_False;
7fd59977 613 Clear();
614}
615
616
617//=======================================================================
618//function : Clear
619//purpose :
620//=======================================================================
621
622void BRepOffset_MakeOffset::Clear()
623{
624 myOffsetShape.Nullify();
625 myInitOffsetFace .Clear();
626 myInitOffsetEdge .Clear();
627 myImageOffset .Clear();
628 myFaces .Clear();
629 myFaceOffset .Clear();
630 myAsDes ->Clear();
631 myDone = Standard_False;
632}
633
634//=======================================================================
635//function : AddFace
636//purpose :
637//=======================================================================
638
639void BRepOffset_MakeOffset::AddFace(const TopoDS_Face& F) {
640 myFaces.Add(F);
641 //-------------
642 // MAJ SD.
643 //-------------
644 myInitOffsetFace.SetRoot (F) ;
645 myInitOffsetFace.Bind (F,F);
646 myImageOffset.SetRoot (F) ;
647}
648
649//=======================================================================
650//function : SetOffsetOnFace
651//purpose :
652//=======================================================================
653
654void BRepOffset_MakeOffset::SetOffsetOnFace(const TopoDS_Face& F,
9b7f3f83 655 const Standard_Real Off)
7fd59977 656{
657 if ( myFaceOffset.IsBound(F)) myFaceOffset.UnBind(F);
658 myFaceOffset.Bind(F,Off);
659}
660
661//=======================================================================
662//function : RemoveCorks
663//purpose :
664//=======================================================================
665
975ec82a 666static void RemoveCorks (TopoDS_Shape& S,
9b7f3f83 667 TopTools_IndexedMapOfShape& Faces)
7fd59977 668{
669 TopoDS_Compound SS;
670 BRep_Builder B;
671 B.MakeCompound (SS);
672 //-----------------------------------------------------
0d969553
Y
673 // Construction of a shape without caps.
674 // and Orientation of caps as in shape S.
7fd59977 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)) {
680 B.Add(SS,Cork);
681 }
682 else {
3f5aa017 683 Faces.RemoveKey(Cork);
975ec82a 684 Faces.Add(Cork); // to reset it with proper orientation.
7fd59977 685 }
686 }
687 S = SS;
688#ifdef DRAW
689 if ( AffichOffC)
690 DBRep::Set("myInit", SS);
691#endif
692
693}
694
9b7f3f83 695//=======================================================================
696//function : IsConnectedShell
697//purpose :
698//=======================================================================
7fd59977 699static Standard_Boolean IsConnectedShell( const TopoDS_Shape& S )
700{
701 BRepTools_Quilt Glue;
702 Glue.Add( S );
703
704 TopoDS_Shape SS = Glue.Shells();
705 TopExp_Explorer Explo( SS, TopAbs_SHELL );
706 Explo.Next();
707 if (Explo.More())
708 return Standard_False;
709
710 return Standard_True;
711}
712
713
714//=======================================================================
715//function : MakeList
716//purpose :
717//=======================================================================
718
975ec82a 719static void MakeList (TopTools_ListOfShape& OffsetFaces,
9b7f3f83 720 const BRepAlgo_Image& myInitOffsetFace,
721 const TopTools_IndexedMapOfShape& myFaces)
7fd59977 722{
723 TopTools_ListIteratorOfListOfShape itLOF(myInitOffsetFace.Roots());
724 for ( ; itLOF.More(); itLOF.Next()) {
725 const TopoDS_Shape& Root = itLOF.Value();
9b7f3f83 726 if (!myFaces.Contains(Root)) {
727 if (myInitOffsetFace.HasImage(Root)) {
edfa30de 728 TopTools_ListIteratorOfListOfShape aItLS(myInitOffsetFace.Image(Root));
729 for (; aItLS.More(); aItLS.Next()) {
730 OffsetFaces.Append(aItLS.Value());
731 }
9b7f3f83 732 }
733 }
7fd59977 734 }
735}
736
737//=======================================================================
738//function : EvalMax
739//purpose :
740//=======================================================================
741
742static void EvalMax(const TopoDS_Shape& S, Standard_Real& Tol)
743{
744 TopExp_Explorer exp;
745 for (exp.Init(S,TopAbs_VERTEX); exp.More(); exp.Next()) {
746 const TopoDS_Vertex& V = TopoDS::Vertex(exp.Current());
747 Standard_Real TolV = BRep_Tool::Tolerance(V);
748 if (TolV > Tol) Tol = TolV;
749 }
7fd59977 750}
751
a8704c36 752
7fd59977 753//=======================================================================
754//function : MakeOffsetShape
755//purpose :
756//=======================================================================
757
758void BRepOffset_MakeOffset::MakeOffsetShape()
759{
03383c97 760 myDone = Standard_False;
9b7f3f83 761 //
762 // check if shape consists of only planar faces
763 myIsPlanar = IsPlanar(myShape);
7fd59977 764 //------------------------------------------
0d969553 765 // Construction of myShape without caps.
7fd59977 766 //------------------------------------------
db2f1498 767 if(!myFaces.IsEmpty())
768 {
769 RemoveCorks (myShape,myFaces);
770 }
03383c97 771
e1ed38e0 772 if (!CheckInputData())
03383c97 773 {
e1ed38e0 774 // There is error in input data.
775 // Check Error() method.
776 return;
03383c97 777 }
7fd59977 778
779 TopAbs_State Side = TopAbs_IN;
780 if (myOffset < 0.) Side = TopAbs_OUT;
03383c97 781
7fd59977 782 // ------------
783 // Preanalyse.
784 // ------------
785 EvalMax(myShape,myTol);
a07a0416 786 // There are possible second variant: analytical continuation of arcsin.
03383c97 787 Standard_Real TolAngleCoeff = Min(myTol / (Abs(myOffset * 0.5) + Precision::Confusion()), 1.0);
a07a0416 788 Standard_Real TolAngle = 4*ASin(TolAngleCoeff);
7fd59977 789 myAnalyse.Perform(myShape,TolAngle);
790 //---------------------------------------------------
0d969553 791 // Construction of Offset from preanalysis.
7fd59977 792 //---------------------------------------------------
793 //----------------------------
0d969553 794 // MaJ of SD Face - Offset
7fd59977 795 //----------------------------
796 UpdateFaceOffset();
797
798 if (myJoin == GeomAbs_Arc)
799 BuildOffsetByArc();
800 else if (myJoin == GeomAbs_Intersection)
801 BuildOffsetByInter();
802 //-----------------
0d969553 803 // Auto unwinding.
7fd59977 804 //-----------------
805 // if (mySelfInter) SelfInter(Modif);
806 //-----------------
807 // Intersection 3d .
808 //-----------------
809 BRepOffset_Inter3d Inter(myAsDes,Side,myTol);
810 Intersection3D (Inter);
811 //-----------------
812 // Intersection2D
813 //-----------------
975ec82a
J
814 TopTools_IndexedMapOfShape& Modif = Inter.TouchedFaces();
815 TopTools_IndexedMapOfShape& NewEdges = Inter.NewEdges();
7fd59977 816
817 if (!Modif.IsEmpty()) Intersection2D (Modif,NewEdges);
818 //-------------------------------------------------------
0d969553 819 // Unwinding 2D and reconstruction of modified faces
7fd59977 820 //----------------------------------------------------
821 MakeLoops (Modif);
822 //-----------------------------------------------------
0d969553
Y
823 // Reconstruction of non modified faces sharing
824 // reconstructed edges
7fd59977 825 //------------------------------------------------------
826 if (!Modif.IsEmpty()) MakeFaces (Modif);
827
828 if (myThickening)
829 MakeMissingWalls();
830
831 //-------------------------
0d969553 832 // Construction of shells.
7fd59977 833 //-------------------------
834 MakeShells ();
ecf4f17c 835 if (myOffsetShape.IsNull()) {
836 // not done
837 myDone = Standard_False;
838 return;
839 }
7fd59977 840 //--------------
0d969553 841 // Unwinding 3D.
7fd59977 842 //--------------
843 SelectShells ();
844 //----------------------------------
9b7f3f83 845 // Remove INTERNAL edges if necessary
846 //----------------------------------
847 if (myRemoveIntEdges) {
848 RemoveInternalEdges();
849 }
850 //----------------------------------
0d969553 851 // Coding of regularities.
7fd59977 852 //----------------------------------
853 EncodeRegularity();
854 //----------------------
0d969553 855 // Creation of solids.
7fd59977 856 //----------------------
857 MakeSolid ();
858
859 //-----------------------------
0d969553 860 // MAJ Tolerance edge and Vertex
7fd59977 861 // ----------------------------
862 if (!myOffsetShape.IsNull()) {
863 UpdateTolerance (myOffsetShape,myFaces);
864 BRepLib::UpdateTolerances( myOffsetShape );
865 }
866
867 CorrectConicalFaces();
868
a8704c36 869 // Result solid should be computed in MakeOffset scope.
870 if (myThickening &&
871 myIsPerformSewing)
872 {
873 BRepBuilderAPI_Sewing aSew(myTol);
874 aSew.Add(myOffsetShape);
875 aSew.Perform();
876 myOffsetShape = aSew.SewedShape();
877
878 // Rebuild solid.
879 // Offset shape expected to be really closed after sewing.
880 myOffsetShape.Closed(Standard_True);
881 MakeSolid();
882 }
883
7fd59977 884 myDone = Standard_True;
885}
886
887
888
889//=======================================================================
890//function : MakeThickSolid
891//purpose :
892//=======================================================================
893
894void BRepOffset_MakeOffset::MakeThickSolid()
895{
896 //--------------------------------------------------------------
0d969553 897 // Construction of shell parallel to shell (initial without cap).
7fd59977 898 //--------------------------------------------------------------
899 MakeOffsetShape ();
900
e1ed38e0 901 if (!myDone)
902 {
903 // Save return code and myDone state.
904 return;
905 }
906
7fd59977 907 //--------------------------------------------------------------------
0d969553
Y
908 // Construction of a solid with the initial shell, parallel shell
909 // limited by caps.
7fd59977 910 //--------------------------------------------------------------------
e1ed38e0 911 if (!myFaces.IsEmpty())
912 {
7fd59977 913 TopoDS_Solid Res;
914 TopExp_Explorer exp;
915 BRep_Builder B;
916 Standard_Integer NbF = myFaces.Extent();
917
918 B.MakeSolid(Res);
919
920 BRepTools_Quilt Glue;
e1ed38e0 921 for (exp.Init(myShape,TopAbs_FACE); exp.More(); exp.Next())
922 {
7fd59977 923 NbF++;
924 Glue.Add (exp.Current());
925 }
926 Standard_Boolean YaResult = 0;
ab87e6fc 927 if (!myOffsetShape.IsNull())
928 {
929 for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next())
930 {
931 YaResult = 1;
932 Glue.Add (exp.Current().Reversed());
933 }
0797d9d3 934#ifdef OCCT_DEBUG
ab87e6fc 935 if(YaResult == 0)
936 {
937 cout << "OffsetShape does not contain a FACES." << endl;
938 }
939#endif
7fd59977 940 }
0797d9d3 941#ifdef OCCT_DEBUG
ab87e6fc 942 else
943 {
944 cout << "OffsetShape is null!" << endl;
945 }
946#endif
947
948 if (YaResult == 0)
949 {
7fd59977 950 myDone = Standard_False;
e1ed38e0 951 myError = BRepOffset_UnknownError;
7fd59977 952 return;
ab87e6fc 953 }
954
7fd59977 955 myOffsetShape = Glue.Shells();
e1ed38e0 956 for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next())
957 {
7fd59977 958 B.Add(Res,exp.Current());
959 }
960 Res.Closed(Standard_True);
961 myOffsetShape = Res;
962
0d969553
Y
963 // Test of Validity of the result of thick Solid
964 // more face than the initial solid.
7fd59977 965 Standard_Integer NbOF = 0;
e1ed38e0 966 for (exp.Init(myOffsetShape,TopAbs_FACE);exp.More(); exp.Next())
967 {
7fd59977 968 NbOF++;
969 }
e1ed38e0 970 if (NbOF <= NbF)
971 {
7fd59977 972 myDone = Standard_False;
e1ed38e0 973 myError = BRepOffset_UnknownError;
7fd59977 974 return;
975 }
976 }
977
e1ed38e0 978 if (myOffset > 0 ) myOffsetShape.Reverse();
7fd59977 979
980 myDone = Standard_True;
981}
982
983//=======================================================================
984//function : IsDone
985//purpose :
986//=======================================================================
987
988Standard_Boolean BRepOffset_MakeOffset::IsDone() const
989{
990 return myDone;
991}
992
993//=======================================================================
994//function : Error
995//purpose :
996//=======================================================================
997
998BRepOffset_Error BRepOffset_MakeOffset::Error() const
999{
1000 return myError;
1001}
1002
1003//=======================================================================
1004//function : Shape
1005//purpose :
1006//=======================================================================
1007
1008const TopoDS_Shape& BRepOffset_MakeOffset::Shape() const
1009{
1010 return myOffsetShape;
1011}
1012
1013//=======================================================================
ecf4f17c 1014//function : MakeOffsetFaces
1015//purpose :
7fd59977 1016//=======================================================================
ecf4f17c 1017void BRepOffset_MakeOffset::MakeOffsetFaces(BRepOffset_DataMapOfShapeOffset& theMapSF)
7fd59977 1018{
ecf4f17c 1019 Standard_Real aCurOffset;
1020 TopTools_ListOfShape aLF;
1021 TopTools_DataMapOfShapeShape ShapeTgt;
1022 TopTools_ListIteratorOfListOfShape aItLF;
9b7f3f83 1023 //
ecf4f17c 1024 Standard_Boolean OffsetOutside = (myOffset > 0.);
9b7f3f83 1025 //
ecf4f17c 1026 BRepLib::SortFaces(myShape, aLF);
9b7f3f83 1027 //
ecf4f17c 1028 aItLF.Initialize(aLF);
1029 for (; aItLF.More(); aItLF.Next()) {
1030 const TopoDS_Face& aF = TopoDS::Face(aItLF.Value());
1031 aCurOffset = myFaceOffset.IsBound(aF) ? myFaceOffset(aF) : myOffset;
1032 BRepOffset_Offset OF(aF, aCurOffset, ShapeTgt, OffsetOutside, myJoin);
7fd59977 1033 TopTools_ListOfShape Let;
ecf4f17c 1034 myAnalyse.Edges(aF,BRepOffset_Tangent,Let);
1035 TopTools_ListIteratorOfListOfShape itl(Let);
1036 for (; itl.More(); itl.Next()) {
7fd59977 1037 const TopoDS_Edge& Cur = TopoDS::Edge(itl.Value());
1038 if ( !ShapeTgt.IsBound(Cur)) {
9b7f3f83 1039 TopoDS_Shape aLocalShape = OF.Generated(Cur);
1040 const TopoDS_Edge& OTE = TopoDS::Edge(aLocalShape);
9b7f3f83 1041 ShapeTgt.Bind(Cur,OF.Generated(Cur));
1042 TopoDS_Vertex V1,V2,OV1,OV2;
1043 TopExp::Vertices (Cur,V1,V2);
1044 TopExp::Vertices (OTE,OV1,OV2);
1045 TopTools_ListOfShape LE;
1046 if (!ShapeTgt.IsBound(V1)) {
1047 myAnalyse.Edges(V1,BRepOffset_Tangent,LE);
1048 const TopTools_ListOfShape& LA =myAnalyse.Ancestors(V1);
1049 if (LE.Extent() == LA.Extent())
1050 ShapeTgt.Bind(V1,OV1);
1051 }
1052 if (!ShapeTgt.IsBound(V2)) {
1053 LE.Clear();
1054 myAnalyse.Edges(V2,BRepOffset_Tangent,LE);
1055 const TopTools_ListOfShape& LA =myAnalyse.Ancestors(V2);
1056 if (LE.Extent() == LA.Extent())
1057 ShapeTgt.Bind(V2,OV2);
1058 }
7fd59977 1059 }
1060 }
ecf4f17c 1061 theMapSF.Bind(aF,OF);
1062 }
1063}
1064
1065//=======================================================================
1066//function : BuildOffsetByInter
1067//purpose :
1068//=======================================================================
1069void BRepOffset_MakeOffset::BuildOffsetByInter()
1070{
1071#ifdef OCCT_DEBUG
1072 if ( ChronBuild) {
1073 cout << " CONSTRUCTION OF OFFSETS :" << endl;
1074 Clock.Reset();
1075 Clock.Start();
7fd59977 1076 }
ecf4f17c 1077#endif
1078
1079 TopExp_Explorer Exp, Exp2, ExpC;
1080 TopTools_ListIteratorOfListOfShape itLF;
1081
1082 //--------------------------------------------------------
1083 // Construction of faces parallel to initial faces
1084 //--------------------------------------------------------
1085 BRepOffset_DataMapOfShapeOffset MapSF;
1086 MakeOffsetFaces(MapSF);
7fd59977 1087 //--------------------------------------------------------------------
1088 // MES : Map of OffsetShape -> Extended Shapes.
1089 // Build : Map of Initial SS -> OffsetShape build by Inter.
1090 // can be an edge or a compound of edges
1091 //---------------------------------------------------------------------
1092 TopTools_DataMapOfShapeShape MES;
1093 TopTools_DataMapOfShapeShape Build;
1094 TopTools_ListOfShape Failed;
1095 TopAbs_State Side = TopAbs_IN;
1096 Handle(BRepAlgo_AsDes) AsDes = new BRepAlgo_AsDes();
1097
1098 //-------------------------------------------------------------------
0d969553 1099 // Extension of faces and calculation of new edges of intersection.
7fd59977 1100 //-------------------------------------------------------------------
1101 Standard_Boolean ExtentContext = 0;
1102 if (myOffset > 0) ExtentContext = 1;
1103
1104 BRepOffset_Inter3d Inter3 (AsDes,Side,myTol);
0d969553 1105 // Intersection between parallel faces
9b7f3f83 1106 Inter3.ConnexIntByInt(myShape,MapSF,myAnalyse,MES,Build,Failed,myIsPlanar);
0d969553 1107 // Intersection with caps.
9b7f3f83 1108 Inter3.ContextIntByInt(myFaces,ExtentContext,MapSF,myAnalyse,MES,Build,Failed,myIsPlanar);
7fd59977 1109
1110
1111 //---------------------------------------------------------------------------------
0d969553 1112 // Extension of neighbor edges of new edges and intersection between neighbors.
7fd59977 1113 //--------------------------------------------------------------------------------
1114 Handle(BRepAlgo_AsDes) AsDes2d = new BRepAlgo_AsDes();
ecf4f17c 1115 IntersectEdges(myShape, MapSF, MES, Build, AsDes, AsDes2d);
7fd59977 1116 //-----------------------------------------------------------
0d969553 1117 // Great restriction of new edges and update of AsDes.
7fd59977 1118 //------------------------------------------ ----------------
ecf4f17c 1119 TopTools_DataMapOfShapeListOfShape anEdgesOrigins; // offset edge - initial edges
975ec82a 1120 TopTools_IndexedMapOfShape NewEdges;
ecf4f17c 1121 TopTools_DataMapOfShapeShape aETrimEInf; // trimmed - not trimmed edges
1122 //
1123 //Map of edges obtained after FACE-FACE (offsetted) intersection.
1124 //Key1 is edge trimmed by intersection points with other edges;
1125 //Item is not-trimmed edge.
1126 TrimEdges(myShape, myOffset, MapSF, MES, Build, AsDes, AsDes2d, NewEdges, aETrimEInf, anEdgesOrigins);
1127 //
7fd59977 1128 //---------------------------------
0d969553 1129 // Intersection 2D on //
7fd59977 1130 //---------------------------------
ecf4f17c 1131 TopTools_IndexedDataMapOfShapeListOfShape aDMVV;
1132 TopTools_DataMapOfShapeShape aFacesOrigins; // offset face - initial face
7fd59977 1133 TopTools_ListOfShape LFE;
1134 BRepAlgo_Image IMOE;
ecf4f17c 1135 GetEnlargedFaces(myShape, MapSF, MES, aFacesOrigins, IMOE, LFE);
1136 //
7fd59977 1137 TopTools_ListIteratorOfListOfShape itLFE(LFE);
03383c97 1138 for (; itLFE.More(); itLFE.Next())
1139 {
7fd59977 1140 const TopoDS_Face& NEF = TopoDS::Face(itLFE.Value());
03383c97 1141 Standard_Real aCurrFaceTol = BRep_Tool::Tolerance(NEF);
b0fbc579 1142 BRepOffset_Inter2d::Compute(AsDes, NEF, NewEdges, aCurrFaceTol, aDMVV);
7fd59977 1143 }
1144 //----------------------------------------------
0d969553 1145 // Intersections 2d on caps.
7fd59977 1146 //----------------------------------------------
975ec82a 1147 Standard_Integer i;
03383c97 1148 for (i = 1; i <= myFaces.Extent(); i++)
1149 {
975ec82a 1150 const TopoDS_Face& Cork = TopoDS::Face(myFaces(i));
03383c97 1151 Standard_Real aCurrFaceTol = BRep_Tool::Tolerance(Cork);
b0fbc579 1152 BRepOffset_Inter2d::Compute(AsDes, Cork, NewEdges, aCurrFaceTol, aDMVV);
7fd59977 1153 }
b0fbc579 1154 //
1155 BRepOffset_Inter2d::FuseVertices(aDMVV, AsDes);
7fd59977 1156 //-------------------------------
0d969553 1157 // Unwinding of extended Faces.
7fd59977 1158 //-------------------------------
9b7f3f83 1159 //
1160 TopTools_MapOfShape aMFDone;
1161 //
ecf4f17c 1162 if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) {
1163 BuildSplitsOfExtendedFaces(LFE, AsDes, anEdgesOrigins, aFacesOrigins, aETrimEInf, IMOE);
9b7f3f83 1164 //
ecf4f17c 1165 TopTools_ListIteratorOfListOfShape aItLF(LFE);
1166 for (; aItLF.More(); aItLF.Next()) {
1167 const TopoDS_Shape& aS = aItLF.Value();
1168 aMFDone.Add(aS);
9b7f3f83 1169 }
1170 }
1171 else {
1172 myMakeLoops.Build(LFE, AsDes, IMOE);
1173 }
1174 //
0797d9d3 1175#ifdef OCCT_DEBUG
975ec82a 1176 TopTools_IndexedMapOfShape COES;
7fd59977 1177#endif
1178 //---------------------------
0d969553 1179 // MAJ SD. for faces //
7fd59977 1180 //---------------------------
1181 for (Exp.Init(myShape,TopAbs_FACE) ; Exp.More(); Exp.Next()) {
1182 const TopoDS_Shape& FI = Exp.Current();
1183 myInitOffsetFace.SetRoot(FI);
1184 TopoDS_Face OF = MapSF(FI).Face();
1185 if (MES.IsBound(OF)) {
1186 OF = TopoDS::Face(MES(OF));
1187 if (IMOE.HasImage(OF)) {
9b7f3f83 1188 const TopTools_ListOfShape& LOFE = IMOE.Image(OF);
1189 myInitOffsetFace.Bind(FI,LOFE);
1190 for (itLF.Initialize(LOFE); itLF.More(); itLF.Next()) {
1191 const TopoDS_Shape& OFE = itLF.Value();
1192 myImageOffset.SetRoot(OFE);
7fd59977 1193#ifdef DRAW
9b7f3f83 1194 if (AffichInt2d) {
1195 sprintf(name,"AF_%d",NbAF++);
1196 DBRep::Set(name,OFE);
1197 }
7fd59977 1198#endif
9b7f3f83 1199 TopTools_MapOfShape View;
1200 for (Exp2.Init(OFE.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
1201 Exp2.More(); Exp2.Next()) {
1202 const TopoDS_Edge& COE = TopoDS::Edge(Exp2.Current());
1203
1204 myAsDes->Add (OFE,COE);
7fd59977 1205#ifdef DRAW
9b7f3f83 1206 if (AffichInt2d) {
1207 sprintf(name,"AE_%d",NbAE++);
1208 DBRep::Set(name,COE);
1209 COES.Add(COE);
1210 }
7fd59977 1211#endif
9b7f3f83 1212 if (View.Add(COE)){
1213 if (!myAsDes->HasDescendant(COE)) {
1214 TopoDS_Vertex CV1,CV2;
1215 TopExp::Vertices(COE,CV1,CV2);
1216 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1217 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1218 }
1219 }
1220 }
1221 }
7fd59977 1222 }
1223 else {
9b7f3f83 1224 if (aMFDone.Contains(OF)) {
1225 continue;
1226 }
1227 //
1228 myInitOffsetFace.Bind(FI,OF);
1229 myImageOffset.SetRoot(OF);
7fd59977 1230#ifdef DRAW
9b7f3f83 1231 if (AffichInt2d) {
1232 sprintf(name,"AF_%d",NbAF++);
1233 DBRep::Set(name,OF);
1234 }
7fd59977 1235#endif
9b7f3f83 1236 const TopTools_ListOfShape& LE = AsDes->Descendant(OF);
1237 for (itLF.Initialize(LE) ; itLF.More(); itLF.Next()) {
1238 const TopoDS_Edge& OE = TopoDS::Edge(itLF.Value());
1239 if (IMOE.HasImage(OE)) {
1240 const TopTools_ListOfShape& LOE = IMOE.Image(OE);
1241 TopTools_ListIteratorOfListOfShape itLOE(LOE);
1242 for (; itLOE.More(); itLOE.Next()) {
1243 TopoDS_Shape aLocalShape = itLOE.Value().Oriented(OE.Orientation());
1244 const TopoDS_Edge& COE = TopoDS::Edge(aLocalShape);
1245// const TopoDS_Edge& COE = TopoDS::Edge(itLOE.Value().Oriented(OE.Orientation()));
1246 myAsDes->Add(OF,COE);
7fd59977 1247#ifdef DRAW
9b7f3f83 1248 if (AffichInt2d) {
1249 sprintf(name,"AE_%d",NbAE++);
1250 DBRep::Set(name,COE);
1251 COES.Add(COE);
1252 }
7fd59977 1253#endif
9b7f3f83 1254
1255 if (!myAsDes->HasDescendant(COE)) {
1256 TopoDS_Vertex CV1,CV2;
1257 TopExp::Vertices(COE,CV1,CV2);
1258 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1259 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1260 }
1261 }
1262 }
1263 else {
1264 myAsDes->Add(OF,OE);
7fd59977 1265#ifdef DRAW
9b7f3f83 1266 if (AffichInt2d) {
1267 sprintf(name,"AE_%d",NbAE++);
1268 DBRep::Set(name,OE);
1269 COES.Add(OE);
1270 }
7fd59977 1271#endif
1272
9b7f3f83 1273 const TopTools_ListOfShape& LV = AsDes->Descendant(OE);
1274 myAsDes->Add(OE,LV);
1275 }
1276 }
7fd59977 1277 }
1278 }
1279 else {
1280 myInitOffsetFace.Bind(FI,OF);
1281 myImageOffset.SetRoot(OF);
1282 TopTools_MapOfShape View;
1283 for (Exp2.Init(OF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1284 Exp2.More(); Exp2.Next()) {
7fd59977 1285
9b7f3f83 1286 const TopoDS_Edge& COE = TopoDS::Edge(Exp2.Current());
1287 myAsDes->Add (OF,COE);
7fd59977 1288#ifdef DRAW
9b7f3f83 1289 if (AffichInt2d) {
1290 sprintf(name,"AE_%d",NbAE++);
1291 DBRep::Set(name,COE);
1292 COES.Add(COE);
1293 }
7fd59977 1294#endif
9b7f3f83 1295
1296 if (View.Add(Exp2.Current())) {
1297 if (!myAsDes->HasDescendant(COE)) {
1298 TopoDS_Vertex CV1,CV2;
1299 TopExp::Vertices(COE,CV1,CV2);
1300 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1301 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1302 }
1303 }
7fd59977 1304 }
1305 }
1306 }
1307 // Modified by skv - Tue Mar 15 16:20:43 2005
1308 // Add methods for supporting history.
1309 TopTools_MapOfShape aMapEdges;
1310
1311 for (Exp.Init(myShape,TopAbs_FACE) ; Exp.More(); Exp.Next()) {
1312 const TopoDS_Shape& aFaceRef = Exp.Current();
1313
1314 Exp2.Init(aFaceRef.Oriented(TopAbs_FORWARD), TopAbs_EDGE);
1315
1316 for (; Exp2.More(); Exp2.Next()) {
1317 const TopoDS_Shape& anEdgeRef = Exp2.Current();
1318
1319 if (aMapEdges.Add(anEdgeRef)) {
9b7f3f83 1320 myInitOffsetEdge.SetRoot(anEdgeRef);
1321 if (Build.IsBound(anEdgeRef)) {
1322 TopoDS_Shape aNewShape = Build(anEdgeRef);
1323
1324 if (aNewShape.ShapeType() == TopAbs_EDGE) {
1325 if (IMOE.HasImage(aNewShape)) {
1326 const TopTools_ListOfShape& aListNewE = IMOE.Image(aNewShape);
1327
1328 myInitOffsetEdge.Bind (anEdgeRef, aListNewE);
1329 } else
1330 myInitOffsetEdge.Bind (anEdgeRef, aNewShape);
1331 } else { // aNewShape != TopAbs_EDGE
1332 TopTools_ListOfShape aListNewEdge;
1333
1334 for (ExpC.Init(aNewShape, TopAbs_EDGE); ExpC.More(); ExpC.Next()) {
1335 const TopoDS_Shape &aResEdge = ExpC.Current();
1336
1337 if (IMOE.HasImage(aResEdge)) {
1338 const TopTools_ListOfShape& aListNewE = IMOE.Image(aResEdge);
1339 TopTools_ListIteratorOfListOfShape aNewEIter(aListNewE);
1340
1341 for (; aNewEIter.More(); aNewEIter.Next())
1342 aListNewEdge.Append(aNewEIter.Value());
1343 } else
1344 aListNewEdge.Append(aResEdge);
1345 }
1346
1347 myInitOffsetEdge.Bind (anEdgeRef, aListNewEdge);
1348 }
1349 }
1350 else { // Free boundary.
1351 TopoDS_Shape aNewEdge = MapSF(aFaceRef).Generated(anEdgeRef);
1352
1353 if (MES.IsBound(aNewEdge))
1354 aNewEdge = MES(aNewEdge);
1355
1356 if (IMOE.HasImage(aNewEdge)) {
1357 const TopTools_ListOfShape& aListNewE = IMOE.Image(aNewEdge);
1358
1359 myInitOffsetEdge.Bind (anEdgeRef, aListNewE);
1360 } else
1361 myInitOffsetEdge.Bind (anEdgeRef, aNewEdge);
1362 }
7fd59977 1363 }
1364 }
1365 }
1366// Modified by skv - Tue Mar 15 16:20:43 2005
1367
1368 //---------------------------
ecf4f17c 1369 // MAJ SD. for caps
7fd59977 1370 //---------------------------
975ec82a
J
1371 //TopTools_MapOfShape View;
1372 for (i = 1; i <= myFaces.Extent(); i++) {
1373 const TopoDS_Shape& Cork = myFaces(i);
7fd59977 1374 const TopTools_ListOfShape& LE = AsDes->Descendant(Cork);
1375 for (itLF.Initialize(LE) ; itLF.More(); itLF.Next()) {
1376 const TopoDS_Edge& OE = TopoDS::Edge(itLF.Value());
1377 if (IMOE.HasImage(OE)) {
9b7f3f83 1378 const TopTools_ListOfShape& LOE = IMOE.Image(OE);
1379 TopTools_ListIteratorOfListOfShape itLOE(LOE);
1380 for (; itLOE.More(); itLOE.Next()) {
1381 const TopoDS_Edge& COE = TopoDS::Edge(itLOE.Value());
1382 myAsDes->Add(Cork,COE.Oriented(OE.Orientation())) ;
7fd59977 1383#ifdef DRAW
9b7f3f83 1384 if (AffichInt2d) {
1385 sprintf(name,"AE_%d",NbAE++);
1386 DBRep::Set(name,COE);
1387 COES.Add(COE);
1388 }
7fd59977 1389#endif
9b7f3f83 1390
1391 if (!myAsDes->HasDescendant(COE)) {
1392 TopoDS_Vertex CV1,CV2;
1393 TopExp::Vertices(COE,CV1,CV2);
1394 if (!CV1.IsNull()) myAsDes->Add(COE,CV1.Oriented(TopAbs_FORWARD));
1395 if (!CV2.IsNull()) myAsDes->Add(COE,CV2.Oriented(TopAbs_REVERSED));
1396 }
1397 }
7fd59977 1398 }
1399 else {
9b7f3f83 1400 myAsDes->Add(Cork,OE);
1401 if (AsDes->HasDescendant(OE)) {
1402 myAsDes->Add(OE,AsDes->Descendant(OE));
1403 }
7fd59977 1404#ifdef DRAW
9b7f3f83 1405 if (AffichInt2d) {
1406 sprintf(name,"AE_%d",NbAE++);
1407 DBRep::Set(name,OE);
1408 COES.Add(OE);
1409 }
7fd59977 1410#endif
1411 }
1412 }
1413 }
1414
0797d9d3 1415#ifdef OCCT_DEBUG
7fd59977 1416 DEBVerticesControl (COES,myAsDes);
1417 if ( ChronBuild) Clock.Show();
1418#endif
1419}
1420
9b7f3f83 1421//=======================================================================
ecf4f17c 1422//function : BuildOffsetByArc
9b7f3f83 1423//purpose :
1424//=======================================================================
ecf4f17c 1425void BRepOffset_MakeOffset::BuildOffsetByArc()
9b7f3f83 1426{
ecf4f17c 1427#ifdef OCCT_DEBUG
1428 if ( ChronBuild) {
1429 cout << " CONSTRUCTION OF OFFSETS :" << endl;
1430 Clock.Reset();
1431 Clock.Start();
7fd59977 1432 }
1433#endif
1434
ecf4f17c 1435 TopExp_Explorer Exp;
1436 TopTools_ListIteratorOfListOfShape itLF;
1437 TopTools_MapOfShape Done;
1438
7fd59977 1439 //--------------------------------------------------------
0d969553 1440 // Construction of faces parallel to initial faces
7fd59977 1441 //--------------------------------------------------------
ecf4f17c 1442 BRepOffset_DataMapOfShapeOffset MapSF;
1443 MakeOffsetFaces(MapSF);
7fd59977 1444 //--------------------------------------------------------
0d969553 1445 // Construction of tubes on edge.
7fd59977 1446 //--------------------------------------------------------
1447 BRepOffset_Type OT = BRepOffset_Convex;
1448 if (myOffset < 0.) OT = BRepOffset_Concave;
1449
1450 for (Exp.Init(myShape,TopAbs_EDGE); Exp.More(); Exp.Next()) {
1451 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1452 if (Done.Add(E)) {
1453 const TopTools_ListOfShape& Anc = myAnalyse.Ancestors(E);
1454 if (Anc.Extent() == 2) {
9b7f3f83 1455 const BRepOffset_ListOfInterval& L = myAnalyse.Type(E);
1456 if (!L.IsEmpty() && L.First().Type() == OT) {
1457 Standard_Real CurOffset = myOffset;
1458 if ( myFaceOffset.IsBound(Anc.First()))
1459 CurOffset = myFaceOffset(Anc.First());
1460 TopoDS_Shape aLocalShapeGen = MapSF(Anc.First()).Generated(E);
1461 TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShapeGen);
1462 aLocalShapeGen = MapSF(Anc.Last()).Generated(E);
1463 TopoDS_Edge EOn2 = TopoDS::Edge(aLocalShapeGen);
1464// TopoDS_Edge EOn1 = TopoDS::Edge(MapSF(Anc.First()).Generated(E));
1465// TopoDS_Edge EOn2 = TopoDS::Edge(MapSF(Anc.Last()) .Generated(E));
1466 // find if exits tangent edges in the original shape
1467 TopoDS_Edge E1f, E1l;
1468 TopoDS_Vertex V1f, V1l;
1469 TopExp::Vertices(E,V1f,V1l);
1470 TopTools_ListOfShape TangE;
1471 myAnalyse.TangentEdges(E,V1f,TangE);
1472 // find if the pipe on the tangent edges are soon created.
1473 TopTools_ListIteratorOfListOfShape itl(TangE);
1474 Standard_Boolean Find = Standard_False;
1475 for ( ; itl.More() && !Find; itl.Next()) {
1476 if ( MapSF.IsBound(itl.Value())) {
1477 TopoDS_Shape aLocalShape = MapSF(itl.Value()).Generated(V1f);
1478 E1f = TopoDS::Edge(aLocalShape);
1479// E1f = TopoDS::Edge(MapSF(itl.Value()).Generated(V1f));
1480 Find = Standard_True;
1481 }
1482 }
1483 TangE.Clear();
1484 myAnalyse.TangentEdges(E,V1l,TangE);
1485 // find if the pipe on the tangent edges are soon created.
1486 itl.Initialize(TangE);
1487 Find = Standard_False;
1488 for ( ; itl.More() && !Find; itl.Next()) {
1489 if ( MapSF.IsBound(itl.Value())) {
1490 TopoDS_Shape aLocalShape = MapSF(itl.Value()).Generated(V1l);
1491 E1l = TopoDS::Edge(aLocalShape);
1492// E1l = TopoDS::Edge(MapSF(itl.Value()).Generated(V1l));
1493 Find = Standard_True;
1494 }
1495 }
1496 BRepOffset_Offset OF (E,EOn1,EOn2,CurOffset,E1f, E1l);
1497 MapSF.Bind(E,OF);
1498 }
7fd59977 1499 }
1500 else {
9b7f3f83 1501 // ----------------------
1502 // free border.
1503 // ----------------------
1504 TopoDS_Shape aLocalShape = MapSF(Anc.First()).Generated(E);
1505 TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShape);
1506/// TopoDS_Edge EOn1 = TopoDS::Edge(MapSF(Anc.First()).Generated(E));
7fd59977 1507 myInitOffsetEdge.SetRoot(E); // skv: supporting history.
9b7f3f83 1508 myInitOffsetEdge.Bind (E,EOn1);
7fd59977 1509 }
1510 }
1511 }
1512
1513 //--------------------------------------------------------
0d969553 1514 // Construction of spheres on vertex.
7fd59977 1515 //--------------------------------------------------------
1516 Done.Clear();
1517 TopTools_ListIteratorOfListOfShape it;
1518
1519 for (Exp.Init(myShape,TopAbs_VERTEX); Exp.More(); Exp.Next()) {
1520 const TopoDS_Vertex& V = TopoDS::Vertex (Exp.Current());
1521 if (Done.Add(V)) {
1522 const TopTools_ListOfShape& LA = myAnalyse.Ancestors(V);
1523 TopTools_ListOfShape LE;
1524 myAnalyse.Edges(V,OT,LE);
1525
1526 if (LE.Extent() >= 3 && LE.Extent() == LA.Extent()) {
9b7f3f83 1527 TopTools_ListOfShape LOE;
1528 //--------------------------------------------------------
1529 // Return connected edges on tubes.
1530 //--------------------------------------------------------
1531 for (it.Initialize(LE) ; it.More(); it.Next()) {
1532 LOE.Append(MapSF(it.Value()).Generated(V).Reversed());
1533 }
1534 //----------------------
1535 // construction sphere.
1536 //-----------------------
1537 const TopTools_ListOfShape& LLA = myAnalyse.Ancestors(LA.First());
1538 const TopoDS_Shape& FF = LLA.First();
1539 Standard_Real CurOffset = myOffset;
1540 if ( myFaceOffset.IsBound(FF))
1541 CurOffset = myFaceOffset(FF);
1542
1543 BRepOffset_Offset OF(V,LOE,CurOffset);
1544 MapSF.Bind(V,OF);
7fd59977 1545 }
1546 //--------------------------------------------------------------
0d969553 1547 // Particular processing if V is at least a free border.
7fd59977 1548 //-------------------------------------------------------------
1549 TopTools_ListOfShape LBF;
1550 myAnalyse.Edges(V,BRepOffset_FreeBoundary,LBF);
9b7f3f83 1551 if (!LBF.IsEmpty()) {
1552 Standard_Boolean First = Standard_True;
1553 for (it.Initialize(LE) ; it.More(); it.Next()) {
1554 if (First) {
1555 myInitOffsetEdge.SetRoot(V); // skv: supporting history.
1556 myInitOffsetEdge.Bind(V,MapSF(it.Value()).Generated(V));
1557 First = Standard_False;
1558 }
1559 else {
1560 myInitOffsetEdge.Add(V,MapSF(it.Value()).Generated(V));
1561 }
1562 }
7fd59977 1563 }
1564 }
1565 }
1566
1567 //------------------------------------------------------------
0d969553
Y
1568 // Extension of parallel faces to the context.
1569 // Extended faces are ordered in DS and removed from MapSF.
7fd59977 1570 //------------------------------------------------------------
1571 if (!myFaces.IsEmpty()) ToContext (MapSF);
1572
1573 //------------------------------------------------------
1574 // MAJ SD.
1575 //------------------------------------------------------
1576 BRepOffset_Type RT = BRepOffset_Concave;
1577 if (myOffset < 0.) RT = BRepOffset_Convex;
1578 BRepOffset_DataMapIteratorOfDataMapOfShapeOffset It(MapSF);
7fd59977 1579 for ( ; It.More(); It.Next()) {
1580 const TopoDS_Shape& SI = It.Key();
1581 const BRepOffset_Offset& SF = It.Value();
1582 if (SF.Status() == BRepOffset_Reversed ||
9b7f3f83 1583 SF.Status() == BRepOffset_Degenerated ) {
7fd59977 1584 //------------------------------------------------
0d969553 1585 // Degenerated or returned faces are not stored.
7fd59977 1586 //------------------------------------------------
1587 continue;
9b7f3f83 1588 }
7fd59977 1589
1590 const TopoDS_Face& OF = It.Value().Face();
1591 myInitOffsetFace.Bind (SI,OF);
1592 myInitOffsetFace.SetRoot (SI); // Initial<-> Offset
0d969553 1593 myImageOffset.SetRoot (OF); // FaceOffset root of images
7fd59977 1594
1595 if (SI.ShapeType() == TopAbs_FACE) {
1596 for (Exp.Init(SI.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1597 Exp.More(); Exp.Next()) {
1598 //--------------------------------------------------------------------
1599 // To each face are associatedthe edges that restrict that
1600 // The edges that do not generate tubes or are not tangent
1601 // to two faces are removed.
1602 //--------------------------------------------------------------------
1603 const TopoDS_Edge& E = TopoDS::Edge(Exp.Current());
1604 const BRepOffset_ListOfInterval& L = myAnalyse.Type(E);
1605 if (!L.IsEmpty() && L.First().Type() != RT) {
1606 TopAbs_Orientation OO = E.Orientation();
1607 TopoDS_Shape aLocalShape = It.Value().Generated(E);
1608 TopoDS_Edge OE = TopoDS::Edge(aLocalShape);
1609// TopoDS_Edge OE = TopoDS::Edge(It.Value().Generated(E));
1610 myAsDes->Add (OF,OE.Oriented(OO));
1611 }
7fd59977 1612 }
1613 }
1614 else {
1615 for (Exp.Init(OF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1616 Exp.More(); Exp.Next()) {
1617 myAsDes->Add (OF,Exp.Current());
7fd59977 1618 }
1619 }
1620 }
1621
0797d9d3 1622#ifdef OCCT_DEBUG
7fd59977 1623 if ( ChronBuild) Clock.Show();
1624#endif
1625}
1626
1627
1628
1629//=======================================================================
1630//function : SelfInter
1631//purpose :
1632//=======================================================================
1633
35e08fe8 1634void BRepOffset_MakeOffset::SelfInter(TopTools_MapOfShape& /*Modif*/)
7fd59977 1635{
0797d9d3 1636#ifdef OCCT_DEBUG
7fd59977 1637 if ( ChronBuild) {
1638 cout << " AUTODEBOUCLAGE:" << endl;
1639 Clock.Reset();
1640 Clock.Start();
1641 }
1642#endif
1643
9775fa61 1644 throw Standard_NotImplemented();
7fd59977 1645}
1646
1647
1648//=======================================================================
1649//function : ToContext
1650//purpose :
1651//=======================================================================
1652
1653void BRepOffset_MakeOffset::ToContext (BRepOffset_DataMapOfShapeOffset& MapSF)
1654{
1655 TopTools_DataMapOfShapeShape Created;
1656 TopTools_DataMapOfShapeShape MEF;
975ec82a 1657 TopTools_IndexedMapOfShape FacesToBuild;
7fd59977 1658 TopTools_ListIteratorOfListOfShape itl;
1659 TopExp_Explorer exp;
1660
1661// TopAbs_State Side = TopAbs_IN;
1662// if (myOffset < 0.) Side = TopAbs_OUT;
1663
1664 TopAbs_State Side = TopAbs_OUT;
975ec82a
J
1665
1666 /*
1667 Standard_Integer i;
1668 for (i = 1; i <= myFaces.Extent(); i++) {
1669 const TopoDS_Face& CF = TopoDS::Face(myFaces(i));
7fd59977 1670 for (exp.Init(CF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1671 exp.More(); exp.Next()) {
7fd59977 1672 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1673 if (!myAnalyse.HasAncestor(E)) {
9b7f3f83 1674 //----------------------------------------------------------------
1675 // The edges of context faces that are not in the initial shape
1676 // can appear in the result.
1677 //----------------------------------------------------------------
1678 //myAsDes->Add(CF,E);
7fd59977 1679 }
1680 }
1681 }
975ec82a
J
1682 */
1683
1684 //--------------------------------------------------------
0d969553 1685 // Determine the edges and faces reconstructed by
7fd59977 1686 // intersection.
1687 //---------------------------------------------------------
975ec82a
J
1688 Standard_Integer j;
1689 for (j = 1; j <= myFaces.Extent(); j++) {
1690 const TopoDS_Face& CF = TopoDS::Face(myFaces(j));
7fd59977 1691 for (exp.Init(CF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1692 exp.More(); exp.Next()) {
7fd59977 1693 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1694 if (myAnalyse.HasAncestor(E)) {
9b7f3f83 1695 const TopTools_ListOfShape& LEA = myAnalyse.Ancestors(E);
1696 for (itl.Initialize(LEA); itl.More(); itl.Next()) {
1697 const BRepOffset_Offset& OF = MapSF(itl.Value());
1698 FacesToBuild.Add(itl.Value());
1699 MEF.Bind(OF.Generated(E),CF);
1700 }
1701 TopoDS_Vertex V[2];
1702 TopExp::Vertices(E,V[0],V[1]);
1703 for (Standard_Integer i = 0; i < 2; i++) {
1704 const TopTools_ListOfShape& LVA = myAnalyse.Ancestors(V[i]);
1705 for ( itl.Initialize(LVA); itl.More(); itl.Next()) {
1706 const TopoDS_Edge& EV = TopoDS::Edge(itl.Value());
1707 if (MapSF.IsBound(EV)) {
1708 const BRepOffset_Offset& OF = MapSF(EV);
1709 FacesToBuild.Add(EV);
1710 MEF.Bind(OF.Generated(V[i]),CF);
1711 }
1712 }
1713 }
7fd59977 1714 }
1715 }
1716 }
1717 //---------------------------
0d969553 1718 // Reconstruction of faces.
7fd59977 1719 //---------------------------
1720 TopoDS_Face F,NF;
1721 BRepOffset_Type RT = BRepOffset_Concave;
1722 if (myOffset < 0.) RT = BRepOffset_Convex;
1723 TopoDS_Shape OE,NE;
1724 TopAbs_Orientation Or;
1725
975ec82a
J
1726 for (j = 1; j <= FacesToBuild.Extent(); j++) {
1727 const TopoDS_Shape& S = FacesToBuild(j);
7fd59977 1728 BRepOffset_Offset BOF;
1729 BOF = MapSF(S);
1730 F = TopoDS::Face(BOF.Face());
1731 BRepOffset_Tool::ExtentFace(F,Created,MEF,Side,myTol,NF);
1732 MapSF.UnBind(S);
1733 //--------------
1734 // MAJ SD.
1735 //--------------
1736 myInitOffsetFace.Bind (S,NF);
1737 myInitOffsetFace.SetRoot (S); // Initial<-> Offset
1738 myImageOffset.SetRoot (NF);
1739
1740 if (S.ShapeType() == TopAbs_FACE) {
1741 for (exp.Init(S.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1742 exp.More(); exp.Next()) {
1743
1744 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
1745 const BRepOffset_ListOfInterval& L = myAnalyse.Type(E);
1746 OE = BOF.Generated(E);
1747 Or = E.Orientation();
1748 OE.Orientation(Or);
1749 if (!L.IsEmpty() && L.First().Type() != RT) {
1750 if (Created.IsBound(OE)) {
1751 NE = Created(OE);
1752 if (NE.Orientation() == TopAbs_REVERSED)
1753 NE.Orientation(TopAbs::Reverse(Or));
1754 else
1755 NE.Orientation(Or);
1756 myAsDes->Add(NF,NE);
1757 }
1758 else {
1759 myAsDes->Add(NF,OE);
1760 }
1761 }
7fd59977 1762 }
1763 }
1764 else {
1765 //------------------
0d969553 1766 // Tube
7fd59977 1767 //---------------------
1768 for (exp.Init(NF.Oriented(TopAbs_FORWARD),TopAbs_EDGE);
9b7f3f83 1769 exp.More(); exp.Next()) {
1770 myAsDes->Add (NF,exp.Current());
7fd59977 1771 }
1772 }
1773 MapSF.UnBind(S);
1774 }
1775
0d969553
Y
1776 //------------------
1777 // MAJ free borders
1778 //------------------
7fd59977 1779 TopTools_DataMapIteratorOfDataMapOfShapeShape itc;
1780 for (itc.Initialize(Created); itc.More(); itc.Next()) {
1781 OE = itc.Key();
1782 NE = itc.Value();
1783 if (myInitOffsetEdge.IsImage(OE)) {
1784 TopoDS_Shape E = myInitOffsetEdge.ImageFrom (OE);
1785 Or = myInitOffsetEdge.Image(E).First().Orientation();
1786 if (NE.Orientation() == TopAbs_REVERSED)
9b7f3f83 1787 NE.Orientation(TopAbs::Reverse(Or));
7fd59977 1788 else
9b7f3f83 1789 NE.Orientation(Or);
7fd59977 1790 myInitOffsetEdge.Remove(OE);
1791 myInitOffsetEdge.Bind(E,NE);
1792 }
1793 }
1794}
1795
1796
1797//=======================================================================
1798//function : UpdateFaceOffset
1799//purpose :
1800//=======================================================================
1801
1802void BRepOffset_MakeOffset::UpdateFaceOffset()
1803{
1804 TopTools_MapOfShape M;
1805 TopTools_DataMapOfShapeReal CopiedMap;
1806 CopiedMap.Assign(myFaceOffset);
1807 TopTools_DataMapIteratorOfDataMapOfShapeReal it(CopiedMap);
1808
1809 BRepOffset_Type RT = BRepOffset_Convex;
1810 if (myOffset < 0.) RT = BRepOffset_Concave;
1811
1812 for ( ; it.More(); it.Next()) {
1813 const TopoDS_Face& F = TopoDS::Face(it.Key());
1814 Standard_Real CurOffset = CopiedMap(F);
1815 if ( !M.Add(F)) continue;
1816 TopoDS_Compound Co;
1817 BRep_Builder Build;
1818 Build.MakeCompound(Co);
1819 TopTools_MapOfShape Dummy;
1820 Build.Add(Co,F);
1821 if (myJoin == GeomAbs_Arc)
1822 myAnalyse.AddFaces(F,Co,Dummy,BRepOffset_Tangent,RT);
1823 else
1824 myAnalyse.AddFaces(F,Co,Dummy,BRepOffset_Tangent);
1825
1826 TopExp_Explorer exp(Co,TopAbs_FACE);
1827 for (; exp.More(); exp.Next()) {
1828 const TopoDS_Face& FF = TopoDS::Face(exp.Current());
1829 if ( !M.Add(FF)) continue;
1830 if ( myFaceOffset.IsBound(FF))
9b7f3f83 1831 myFaceOffset.UnBind(FF);
7fd59977 1832 myFaceOffset.Bind(FF,CurOffset);
1833 }
1834 }
1835}
1836
1837//=======================================================================
1838//function : CorrectConicalFaces
1839//purpose :
1840//=======================================================================
1841
1842void BRepOffset_MakeOffset::CorrectConicalFaces()
1843{
db2f1498 1844 if(myOffsetShape.IsNull())
1845 {
1846 return;
1847 }
1848 //
7fd59977 1849 TopTools_SequenceOfShape Cones;
1850 TopTools_SequenceOfShape Circs;
1851 TopTools_SequenceOfShape Seams;
1852 Standard_Real TolApex = 1.e-5;
1853
1854 Standard_Integer i;
1855
1856 TopTools_DataMapOfShapeListOfShape FacesOfCone;
1857 //TopTools_DataMapOfShapeShape DegEdges;
1858 TopExp_Explorer Explo( myOffsetShape, TopAbs_FACE );
1859 if (myJoin == GeomAbs_Arc)
903f7584 1860 {
1861 for (; Explo.More(); Explo.Next())
7fd59977 1862 {
903f7584 1863 TopoDS_Face aFace = TopoDS::Face( Explo.Current() );
1864 Handle(Geom_Surface) aSurf = BRep_Tool::Surface( aFace );
1865 //if (aSurf->DynamicType() == STANDARD_TYPE(Geom_OffsetSurface))
1866 //aSurf = (Handle(Geom_OffsetSurface)::DownCast(aSurf))->BasisSurface(); //???
1867
1868 TopTools_IndexedMapOfShape Emap;
1869 TopExp::MapShapes( aFace, TopAbs_EDGE, Emap );
1870 for (i = 1; i <= Emap.Extent(); i++)
1871 {
1872 TopoDS_Edge anEdge = TopoDS::Edge( Emap(i) );
1873 //Standard_Real f, l;
1874 //Handle(Geom_Curve) theCurve = BRep_Tool::Curve( anEdge, f, l );
1875 //Handle(BRep_TEdge)& TE = *((Handle(BRep_TEdge)*) &anEdge.TShape());
1876 if (BRep_Tool::Degenerated(anEdge))
1877 {
1878 //Check if anEdge is a really degenerated edge or not
1879 BRepAdaptor_Curve BACurve(anEdge, aFace);
1880 gp_Pnt Pfirst, Plast, Pmid;
1881 Pfirst = BACurve.Value(BACurve.FirstParameter());
1882 Plast = BACurve.Value(BACurve.LastParameter());
1883 Pmid = BACurve.Value((BACurve.FirstParameter()+BACurve.LastParameter())/2.);
1884 if (Pfirst.Distance(Plast) <= TolApex &&
1885 Pfirst.Distance(Pmid) <= TolApex)
1886 continue;
1887 //Cones.Append( aFace );
1888 //Circs.Append( anEdge );
1889 //TopoDS_Vertex Vdeg = TopExp::FirstVertex( anEdge );
1890 TopoDS_Edge OrEdge =
1891 TopoDS::Edge( myInitOffsetEdge.Root( anEdge) );
1892 TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
1893 if ( FacesOfCone.IsBound(VF) )
1894 {
1895 //add a face to the existing list
1896 TopTools_ListOfShape& aFaces = FacesOfCone.ChangeFind(VF);
1897 aFaces.Append (aFace);
1898 //DegEdges.Bind(aFace, anEdge);
1899 }
1900 else
1901 {
1902 //the vertex is not in the map => create a new key and items
1903 TopTools_ListOfShape aFaces;
1904 aFaces.Append (aFace);
1905 FacesOfCone.Bind(VF, aFaces);
1906 //DegEdges.Bind(aFace, anEdge);
1907 }
1908 }
1909 } //for (i = 1; i <= Emap.Extent(); i++)
1910 } //for (; fexp.More(); fexp.Next())
1911 } //if (myJoin == GeomAbs_Arc)
7fd59977 1912
1913 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape Cone(FacesOfCone);
1914 BRep_Builder BB;
1915 TopLoc_Location L;
db2f1498 1916 Standard_Boolean IsModified = Standard_False;
7fd59977 1917 for (; Cone.More(); Cone.Next() ) {
1918 gp_Sphere theSphere;
1919 Handle(Geom_SphericalSurface) aSphSurf;
1920 TopoDS_Wire SphereWire;
1921 BB.MakeWire(SphereWire);
1922 TopoDS_Vertex anApex = TopoDS::Vertex(Cone.Key());
1923 const TopTools_ListOfShape& Faces = Cone.Value(); //FacesOfCone(anApex);
1924 TopTools_ListIteratorOfListOfShape itFaces(Faces);
1925 Standard_Boolean isFirstFace = Standard_True;
1926 gp_Pnt FirstPoint;
1927 TopoDS_Vertex theFirstVertex, CurFirstVertex;
1928 for (; itFaces.More(); itFaces.Next())
903f7584 1929 {
1930 TopoDS_Face aFace = TopoDS::Face(itFaces.Value()); //TopoDS::Face(Faces.First());
1931 TopoDS_Edge DegEdge; // = TopoDS::Edge(DegEdges(aFace));
1932 for (Explo.Init(aFace, TopAbs_EDGE); Explo.More(); Explo.Next())
7fd59977 1933 {
903f7584 1934 DegEdge = TopoDS::Edge(Explo.Current());
1935 if (BRep_Tool::Degenerated(DegEdge))
1936 {
1937 TopoDS_Edge OrEdge = TopoDS::Edge( myInitOffsetEdge.Root( DegEdge) );
1938 TopoDS_Vertex VF = TopExp::FirstVertex( OrEdge );
1939 if (VF.IsSame(anApex))
1940 break;
1941 }
1942 }
1943 TopoDS_Shape aLocalDegShape = DegEdge.Oriented(TopAbs_FORWARD);
1944 TopoDS_Edge CurEdge = TopoDS::Edge(aLocalDegShape);
1945 BB.Degenerated(CurEdge, Standard_False);
1946 BB.SameRange(CurEdge, Standard_False);
1947 BB.SameParameter(CurEdge, Standard_False);
1948 gp_Pnt fPnt, lPnt, mPnt;
1949 GetEdgePoints(CurEdge, aFace, fPnt, mPnt, lPnt);
1950 Standard_Real f, l;
1951 BRep_Tool::Range(CurEdge, f, l);
1952 if (isFirstFace)
1953 {
1954 gp_Vec aVec1(fPnt, mPnt);
1955 gp_Vec aVec2(fPnt, lPnt);
1956 gp_Vec aNorm = aVec1.Crossed(aVec2);
1957 gp_Pnt theApex = BRep_Tool::Pnt(anApex);
1958 gp_Vec ApexToFpnt(theApex, fPnt);
1959 gp_Vec Ydir = aNorm ^ ApexToFpnt;
1960 gp_Vec Xdir = Ydir ^ aNorm;
1961 //Xdir.Rotate(gp_Ax1(theApex, aNorm), -f);
1962 gp_Ax2 anAx2(theApex, gp_Dir(aNorm), gp_Dir(Xdir));
1963 theSphere.SetRadius(myOffset);
1964 theSphere.SetPosition(gp_Ax3(anAx2) /*gp_Ax3(theApex, gp_Dir(aNorm))*/);
1965 aSphSurf = new Geom_SphericalSurface(theSphere);
1966 FirstPoint = fPnt;
1967 theFirstVertex = BRepLib_MakeVertex(fPnt);
1968 CurFirstVertex = theFirstVertex;
1969 }
1970
1971 TopoDS_Vertex v1, v2, FirstVert, EndVert;
1972 TopExp::Vertices(CurEdge, v1, v2);
1973 FirstVert = CurFirstVertex;
1974 if (lPnt.Distance(FirstPoint) <= Precision::Confusion())
1975 EndVert = theFirstVertex;
1976 else
1977 EndVert = BRepLib_MakeVertex(lPnt);
1978 CurEdge.Free( Standard_True );
1979 BB.Remove(CurEdge, v1);
1980 BB.Remove(CurEdge, v2);
1981 BB.Add(CurEdge, FirstVert.Oriented(TopAbs_FORWARD));
1982 BB.Add(CurEdge, EndVert.Oriented(TopAbs_REVERSED));
1983 //take the curve from sphere an put it to the edge
1984 Standard_Real Uf, Vf, Ul, Vl;
1985 ElSLib::Parameters( theSphere, fPnt, Uf, Vf );
1986 ElSLib::Parameters( theSphere, lPnt, Ul, Vl );
1987 if (Abs(Ul) <= Precision::Confusion())
1988 Ul = 2.*M_PI;
1989 Handle(Geom_Curve) aCurv = aSphSurf->VIso(Vf);
1990 /*
9b7f3f83 1991 if (!isFirstFace)
903f7584 1992 {
1993 gp_Circ aCircle = (Handle(Geom_Circle)::DownCast(aCurv))->Circ();
1994 if (Abs(Uf - f) > Precision::Confusion())
1995 {
1996 aCircle.Rotate(aCircle.Axis(), f - Uf);
1997 aCurv = new Geom_Circle(aCircle);
1998 }
1999 }
2000 */
2001 Handle(Geom_TrimmedCurve) aTrimCurv = new Geom_TrimmedCurve(aCurv, Uf, Ul);
2002 BB.UpdateEdge(CurEdge, aTrimCurv, Precision::Confusion());
2003 BB.Range(CurEdge, Uf, Ul, Standard_True);
2004 Handle(Geom2d_Line) theLin2d = new Geom2d_Line( gp_Pnt2d( 0., Vf ), gp::DX2d() );
2005 Handle(Geom2d_TrimmedCurve) theTrimLin2d = new Geom2d_TrimmedCurve(theLin2d, Uf, Ul);
2006 BB.UpdateEdge(CurEdge, theTrimLin2d, aSphSurf, L, Precision::Confusion());
2007 BB.Range(CurEdge, aSphSurf, L, Uf, Ul);
2008 BRepLib::SameParameter(CurEdge);
2009 BB.Add(SphereWire, CurEdge);
2010 //Modifying correspondent edges in aFace: substitute vertices common with CurEdge
2011 BRepAdaptor_Curve2d BAc2d(CurEdge, aFace);
2012 gp_Pnt2d fPnt2d, lPnt2d;
2013 fPnt2d = BAc2d.Value(BAc2d.FirstParameter());
2014 lPnt2d = BAc2d.Value(BAc2d.LastParameter());
2015 TopTools_IndexedMapOfShape Emap;
2016 TopExp::MapShapes(aFace, TopAbs_EDGE, Emap);
2017 TopoDS_Edge EE [2];
2018 Standard_Integer j = 0, k;
2019 for (k = 1; k <= Emap.Extent(); k++)
2020 {
2021 const TopoDS_Edge& anEdge = TopoDS::Edge(Emap(k));
2022 if (!BRep_Tool::Degenerated(anEdge))
2023 {
2024 TopoDS_Vertex V1, V2;
2025 TopExp::Vertices(anEdge, V1, V2);
2026 if (V1.IsSame(v1) || V2.IsSame(v1))
2027 EE[j++] = anEdge;
2028 }
2029 }
2030 for (k = 0; k < j; k++)
2031 {
2032 TopoDS_Shape aLocalShape = EE[k].Oriented(TopAbs_FORWARD);
2033 TopoDS_Edge Eforward = TopoDS::Edge(aLocalShape);
2034 Eforward.Free(Standard_True);
2035 TopoDS_Vertex V1, V2;
2036 TopExp::Vertices( Eforward, V1, V2 );
2037 BRepAdaptor_Curve2d EEc( Eforward, aFace );
2038 gp_Pnt2d p2d1, p2d2;
2039 p2d1 = EEc.Value(EEc.FirstParameter());
2040 p2d2 = EEc.Value(EEc.LastParameter());
2041 if (V1.IsSame(v1))
2042 {
2043 TopoDS_Vertex NewV = (p2d1.Distance(fPnt2d) <= Precision::Confusion())?
2044 FirstVert : EndVert;
2045 BB.Remove( Eforward, V1 );
2046 BB.Add( Eforward, NewV.Oriented(TopAbs_FORWARD) );
2047 }
2048 else
2049 {
2050 TopoDS_Vertex NewV = (p2d2.Distance(fPnt2d) <= Precision::Confusion())?
2051 FirstVert : EndVert;
2052 BB.Remove( Eforward, V2 );
2053 BB.Add( Eforward, NewV.Oriented(TopAbs_REVERSED) );
2054 }
7fd59977 2055 }
903f7584 2056
2057 isFirstFace = Standard_False;
2058 CurFirstVertex = EndVert;
2059 }
7fd59977 2060 //Building new spherical face
2061 Standard_Real Ufirst = RealLast(), Ulast = RealFirst();
2062 gp_Pnt2d p2d1, p2d2;
2063 TopTools_ListOfShape EdgesOfWire;
2064 TopoDS_Iterator itw(SphereWire);
2065 for (; itw.More(); itw.Next())
903f7584 2066 {
2067 const TopoDS_Edge& anEdge = TopoDS::Edge(itw.Value());
2068 EdgesOfWire.Append(anEdge);
2069 Standard_Real f, l;
2070 Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(anEdge, aSphSurf, L, f, l);
2071 p2d1 = aC2d->Value(f);
2072 p2d2 = aC2d->Value(l);
2073 if (p2d1.X() < Ufirst)
2074 Ufirst = p2d1.X();
2075 if (p2d1.X() > Ulast)
2076 Ulast = p2d1.X();
2077 if (p2d2.X() < Ufirst)
2078 Ufirst = p2d2.X();
2079 if (p2d2.X() > Ulast)
2080 Ulast = p2d2.X();
2081 }
7fd59977 2082 TopTools_ListOfShape NewEdges;
2083 TopoDS_Edge FirstEdge;
2084 TopTools_ListIteratorOfListOfShape itl(EdgesOfWire);
2085 for (; itl.More(); itl.Next())
903f7584 2086 {
2087 FirstEdge = TopoDS::Edge(itl.Value());
2088 Standard_Real f, l;
2089 Handle(Geom2d_Curve) aC2d = BRep_Tool::CurveOnSurface(FirstEdge, aSphSurf, L, f, l);
2090 p2d1 = aC2d->Value(f);
2091 p2d2 = aC2d->Value(l);
2092 if (Abs(p2d1.X() - Ufirst) <= Precision::Confusion())
7fd59977 2093 {
903f7584 2094 EdgesOfWire.Remove(itl);
2095 break;
7fd59977 2096 }
903f7584 2097 }
cc9f4591 2098 NewEdges.Append(FirstEdge.Oriented(TopAbs_FORWARD));
7fd59977 2099 TopoDS_Vertex Vf1, CurVertex;
2100 TopExp::Vertices(FirstEdge, Vf1, CurVertex);
2101 itl.Initialize(EdgesOfWire);
2102 while (itl.More())
903f7584 2103 {
2104 const TopoDS_Edge& anEdge = TopoDS::Edge(itl.Value());
2105 TopoDS_Vertex V1, V2;
2106 TopExp::Vertices(anEdge, V1, V2);
2107 if (V1.IsSame(CurVertex) || V2.IsSame(CurVertex))
7fd59977 2108 {
cc9f4591 2109 NewEdges.Append(anEdge.Oriented(TopAbs_FORWARD));
903f7584 2110 CurVertex = (V1.IsSame(CurVertex))? V2 : V1;
2111 EdgesOfWire.Remove(itl);
7fd59977 2112 }
903f7584 2113 else
2114 itl.Next();
2115 }
2116
7fd59977 2117 Standard_Real Vfirst, Vlast;
2118 if (p2d1.Y() > 0.)
903f7584 2119 {
2120 Vfirst = p2d1.Y(); Vlast = M_PI/2.;
2121 }
7fd59977 2122 else
903f7584 2123 {
2124 Vfirst = -M_PI/2.; Vlast = p2d1.Y();
2125 }
1c72dff6 2126 TopoDS_Face NewSphericalFace = BRepLib_MakeFace(aSphSurf, Ufirst, Ulast, Vfirst, Vlast, Precision::Confusion());
cc9f4591 2127 TopoDS_Edge OldEdge, DegEdge;
2128 for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next())
2129 {
2130 DegEdge = TopoDS::Edge(Explo.Current());
2131 if (BRep_Tool::Degenerated(DegEdge))
2132 break;
2133 }
2134 TopoDS_Vertex DegVertex = TopExp::FirstVertex(DegEdge);
7fd59977 2135 for (Explo.Init(NewSphericalFace, TopAbs_EDGE); Explo.More(); Explo.Next())
903f7584 2136 {
2137 OldEdge = TopoDS::Edge(Explo.Current());
cc9f4591 2138 TopoDS_Vertex V1, V2;
2139 TopExp::Vertices(OldEdge, V1, V2);
2140 if (!V1.IsSame(DegVertex) && !V2.IsSame(DegVertex))
2141 break;
903f7584 2142 }
7fd59977 2143 TopoDS_Vertex V1, V2;
2144 TopExp::Vertices(OldEdge, V1, V2);
2145 TopTools_ListOfShape LV1, LV2;
cc9f4591 2146 LV1.Append(Vf1.Oriented(TopAbs_FORWARD));
2147 LV2.Append(CurVertex.Oriented(TopAbs_FORWARD));
7fd59977 2148 BRepTools_Substitution theSubstitutor;
cc9f4591 2149 theSubstitutor.Substitute(V1.Oriented(TopAbs_FORWARD), LV1);
7fd59977 2150 if (!V1.IsSame(V2))
cc9f4591 2151 theSubstitutor.Substitute(V2.Oriented(TopAbs_FORWARD), LV2);
2152 theSubstitutor.Substitute(OldEdge.Oriented(TopAbs_FORWARD), NewEdges);
7fd59977 2153 theSubstitutor.Build(NewSphericalFace);
2154 if (theSubstitutor.IsCopied(NewSphericalFace))
903f7584 2155 {
2156 const TopTools_ListOfShape& listSh = theSubstitutor.Copy(NewSphericalFace);
2157 NewSphericalFace = TopoDS::Face(listSh.First());
2158 }
2159
7fd59977 2160 //Adding NewSphericalFace to the shell
2161 Explo.Init( myOffsetShape, TopAbs_SHELL );
2162 TopoDS_Shape theShell = Explo.Current();
2163 theShell.Free( Standard_True );
2164 BB.Add( theShell, NewSphericalFace );
db2f1498 2165 IsModified = Standard_True;
2166 if(!theShell.Closed())
2167 {
2168 if(BRep_Tool::IsClosed(theShell))
2169 {
2170 theShell.Closed(Standard_True);
2171 }
2172 }
7fd59977 2173 }
db2f1498 2174 //
2175 if(!IsModified)
2176 {
2177 return;
2178 }
2179 //
903f7584 2180 if (myShape.ShapeType() == TopAbs_SOLID || myThickening)
2181 {
db2f1498 2182 //Explo.Init( myOffsetShape, TopAbs_SHELL );
2183
2184 //if (Explo.More()) {
2185 // TopoDS_Shape theShell = Explo.Current();
2186 // theShell.Closed( Standard_True );
2187 //}
2188
903f7584 2189 Standard_Integer NbShell = 0;
2190 TopoDS_Compound NC;
2191 TopoDS_Shape S1;
2192 BB.MakeCompound (NC);
db2f1498 2193
2194 TopoDS_Solid Sol;
2195 BB.MakeSolid(Sol);
2196 Sol.Closed(Standard_True);
903f7584 2197 for (Explo.Init(myOffsetShape,TopAbs_SHELL); Explo.More(); Explo.Next()) {
db2f1498 2198 TopoDS_Shell Sh = TopoDS::Shell(Explo.Current());
2199 //if (myThickening && myOffset > 0.)
2200 // Sh.Reverse();
903f7584 2201 NbShell++;
2202 if (Sh.Closed()) {
db2f1498 2203 BB.Add(Sol,Sh);
903f7584 2204 }
2205 else {
2206 BB.Add (NC,Sh);
db2f1498 2207 if(NbShell == 1)
2208 {
2209 S1 = Sh;
2210 }
903f7584 2211 }
7fd59977 2212 }
db2f1498 2213 TopoDS_Iterator anIt(Sol);
2214 Standard_Boolean SolIsNull = !anIt.More();
2215 //Checking solid
2216 if(!SolIsNull)
2217 {
2218 Standard_Integer nbs = 0;
2219 while(anIt.More()) {anIt.Next(); ++nbs;}
2220 if(nbs > 1)
2221 {
2222 BRepCheck_Analyzer aCheck(Sol, Standard_False);
2223 if(!aCheck.IsValid())
2224 {
2225 TopTools_ListOfShape aSolList;
2226 CorrectSolid(Sol, aSolList);
2227 if(!aSolList.IsEmpty())
2228 {
2229 BB.Add(NC, Sol);
2230 TopTools_ListIteratorOfListOfShape aSLIt(aSolList);
2231 for(; aSLIt.More(); aSLIt.Next())
2232 {
2233 BB.Add(NC, aSLIt.Value());
2234 }
2235 SolIsNull = Standard_True;
2236 }
2237 }
2238 }
2239 }
2240 //
2241 anIt.Initialize(NC);
2242 Standard_Boolean NCIsNull = !anIt.More();
2243 if((!SolIsNull) && (!NCIsNull))
2244 {
2245 BB.Add(NC, Sol);
2246 myOffsetShape = NC;
2247 }
2248 else if(SolIsNull && (!NCIsNull))
2249 {
2250 if (NbShell == 1)
2251 {
2252 myOffsetShape = S1;
2253 }
2254 else
2255 {
2256 myOffsetShape = NC;
2257 }
2258 }
2259 else if((!SolIsNull) && NCIsNull)
2260 {
2261 myOffsetShape = Sol;
2262 }
2263 else
2264 {
2265 myOffsetShape = NC;
2266 }
7fd59977 2267 }
7fd59977 2268}
2269
2270
2271//=======================================================================
2272//function : Intersection3D
2273//purpose :
2274//=======================================================================
2275
2276void BRepOffset_MakeOffset::Intersection3D(BRepOffset_Inter3d& Inter)
2277{
0797d9d3 2278#ifdef OCCT_DEBUG
7fd59977 2279 if (ChronBuild) {
2280 cout << " INTERSECTION 3D:" << endl;
2281 Clock.Reset();
2282 Clock.Start();
2283 }
2284#endif
e7384fd4 2285
2286 // In the Complete Intersection mode, implemented currently for planar
2287 // solids only, there is no need to intersect the faces here.
2288 // This intersection will be performed in the method BuildShellsCompleteInter
2289 // where the special treatment is applied to produced faces.
2290 //
2291 // Make sure to match the parameters in which the method
2292 // BuildShellsCompleteInter is called.
2293 if (myInter && (myJoin == GeomAbs_Intersection) && myIsPlanar &&
2294 !myThickening && myFaces.IsEmpty() && IsSolid(myShape))
2295 return;
2296
2297
0d969553 2298 TopTools_ListOfShape OffsetFaces; // list of faces // created.
7fd59977 2299 MakeList (OffsetFaces,myInitOffsetFace,myFaces);
2300
2301 if (!myFaces.IsEmpty()) {
0d969553
Y
2302 Standard_Boolean InSide = (myOffset < 0.); // Temporary
2303 // it is necessary to calculate Inside taking account of the concavity or convexity of edges
2304 // between the cap and the part.
7fd59977 2305
2306 if (myJoin == GeomAbs_Arc)
2307 Inter.ContextIntByArc (myFaces,InSide,myAnalyse,myInitOffsetFace,myInitOffsetEdge);
2308 }
2309 if (myInter) {
2310 //-------------
0d969553 2311 //Complete.
7fd59977 2312 //-------------
2313 Inter.CompletInt (OffsetFaces,myInitOffsetFace);
975ec82a 2314 TopTools_IndexedMapOfShape& NewEdges = Inter.NewEdges();
7fd59977 2315 if (myJoin == GeomAbs_Intersection) {
2316 BRepOffset_Tool::CorrectOrientation (myShape,NewEdges,myAsDes,myInitOffsetFace,myOffset);
2317 }
2318 }
2319 else {
2320 //--------------------------------
0d969553 2321 // Only between neighbor faces.
7fd59977 2322 //--------------------------------
2323 Inter.ConnexIntByArc(OffsetFaces,myShape,myAnalyse,myInitOffsetFace);
2324 }
0797d9d3 2325#ifdef OCCT_DEBUG
7fd59977 2326 if ( ChronBuild) Clock.Show();
2327#endif
2328}
2329
2330//=======================================================================
2331//function : Intersection2D
2332//purpose :
2333//=======================================================================
2334
975ec82a 2335void BRepOffset_MakeOffset::Intersection2D(const TopTools_IndexedMapOfShape& Modif,
9b7f3f83 2336 const TopTools_IndexedMapOfShape& NewEdges)
7fd59977 2337{
0797d9d3 2338#ifdef OCCT_DEBUG
7fd59977 2339 if (ChronBuild) {
2340 cout << " INTERSECTION 2D:" << endl;
2341 Clock.Reset();
2342 Clock.Start();
2343 }
2344#endif
0d969553
Y
2345 //--------------------------------------------------------
2346 // calculate intersections2d on faces concerned by
7fd59977 2347 // intersection3d
975ec82a
J
2348 //---------------------------------------------------------
2349 //TopTools_MapIteratorOfMapOfShape it(Modif);
7fd59977 2350 //-----------------------------------------------
0d969553 2351 // Intersection of edges 2 by 2.
7fd59977 2352 //-----------------------------------------------
b0fbc579 2353 TopTools_IndexedDataMapOfShapeListOfShape aDMVV;
975ec82a
J
2354 Standard_Integer i;
2355 for (i = 1; i <= Modif.Extent(); i++) {
2356 const TopoDS_Face& F = TopoDS::Face(Modif(i));
b0fbc579 2357 BRepOffset_Inter2d::Compute(myAsDes,F,NewEdges,myTol, aDMVV);
7fd59977 2358 }
b0fbc579 2359 //
2360 BRepOffset_Inter2d::FuseVertices(aDMVV, myAsDes);
2361 //
0797d9d3 2362#ifdef OCCT_DEBUG
7fd59977 2363 if (AffichInt2d) {
2364 DEBVerticesControl (NewEdges,myAsDes);
2365 }
2366 if ( ChronBuild) Clock.Show();
2367#endif
2368}
2369
2370
2371//=======================================================================
2372//function : MakeLoops
2373//purpose :
2374//=======================================================================
2375
975ec82a 2376void BRepOffset_MakeOffset::MakeLoops(TopTools_IndexedMapOfShape& Modif)
7fd59977 2377{
0797d9d3 2378#ifdef OCCT_DEBUG
7fd59977 2379 if (ChronBuild) {
2380 cout << " DEBOUCLAGE 2D:" << endl;
2381 Clock.Reset();
2382 Clock.Start();
2383 }
2384#endif
975ec82a 2385 //TopTools_MapIteratorOfMapOfShape it(Modif);
7fd59977 2386 TopTools_ListOfShape LF,LC;
2387 //-----------------------------------------
0d969553 2388 // unwinding of faces // modified.
7fd59977 2389 //-----------------------------------------
975ec82a
J
2390 Standard_Integer i;
2391 for (i = 1; i <= Modif.Extent(); i++) {
2392 if (!myFaces.Contains(Modif(i)))
2393 LF.Append(Modif(i));
7fd59977 2394 }
9b7f3f83 2395 //
ecf4f17c 2396 if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) {
2397 BuildSplitsOfTrimmedFaces(LF, myAsDes, myImageOffset);
9b7f3f83 2398 }
2399 else {
2400 myMakeLoops.Build(LF,myAsDes,myImageOffset);
2401 }
7fd59977 2402
2403 //-----------------------------------------
0d969553 2404 // unwinding of caps.
7fd59977 2405 //-----------------------------------------
975ec82a
J
2406 for (i = 1; i <= myFaces.Extent(); i++)
2407 LC.Append(myFaces(i));
2408
7fd59977 2409 Standard_Boolean InSide = 1;
2410 if (myOffset > 0 ) InSide = 0;
2411 myMakeLoops.BuildOnContext(LC,myAnalyse,myAsDes,myImageOffset,InSide);
2412
0797d9d3 2413#ifdef OCCT_DEBUG
7fd59977 2414 if ( ChronBuild) Clock.Show();
2415#endif
2416}
2417
2418//=======================================================================
2419//function : MakeFaces
0d969553
Y
2420//purpose : Reconstruction of topologically unchanged faces that
2421// share edges that were reconstructed.
7fd59977 2422//=======================================================================
2423
35e08fe8 2424void BRepOffset_MakeOffset::MakeFaces(TopTools_IndexedMapOfShape& /*Modif*/)
7fd59977 2425{
0797d9d3 2426#ifdef OCCT_DEBUG
7fd59977 2427 if (ChronBuild) {
0d969553 2428 cout << " RECONSTRUCTION OF FACES:" << endl;
7fd59977 2429 Clock.Reset();
2430 Clock.Start();
2431 }
2432#endif
2433 TopTools_ListIteratorOfListOfShape itr;
2434 const TopTools_ListOfShape& Roots = myInitOffsetFace.Roots();
2435 TopTools_ListOfShape LOF;
2436 //----------------------------------
0d969553 2437 // Loop on all faces //.
7fd59977 2438 //----------------------------------
2439 for (itr.Initialize(Roots); itr.More(); itr.Next()) {
2440 TopoDS_Face F = TopoDS::Face(myInitOffsetFace.Image(itr.Value()).First());
9b7f3f83 2441 if (!myImageOffset.HasImage(F)) {
2442 LOF.Append(F);
2443 }
2444 }
2445 //
ecf4f17c 2446 if ((myJoin == GeomAbs_Intersection) && myInter && myIsPlanar) {
2447 BuildSplitsOfTrimmedFaces(LOF, myAsDes, myImageOffset);
9b7f3f83 2448 }
2449 else {
2450 myMakeLoops.BuildFaces(LOF,myAsDes,myImageOffset);
7fd59977 2451 }
7fd59977 2452
0797d9d3 2453#ifdef OCCT_DEBUG
7fd59977 2454 if ( ChronBuild) Clock.Show();
2455#endif
2456}
2457
2458//=======================================================================
2459//function : UpdateInitOffset
0d969553 2460//purpose : Update and cleaning of myInitOffset
7fd59977 2461//=======================================================================
7fd59977 2462static void UpdateInitOffset (BRepAlgo_Image& myInitOffset,
9b7f3f83 2463 BRepAlgo_Image& myImageOffset,
2464 const TopoDS_Shape& myOffsetShape,
2465 const TopAbs_ShapeEnum &theShapeType) // skv
7fd59977 2466{
2467 BRepAlgo_Image NIOF;
2468 const TopTools_ListOfShape& Roots = myInitOffset.Roots();
2469 TopTools_ListIteratorOfListOfShape it(Roots);
2470 for (; it.More(); it.Next()) {
2471 NIOF.SetRoot (it.Value());
2472 }
2473 for (it.Initialize(Roots); it.More(); it.Next()) {
2474 const TopoDS_Shape& SI = it.Value();
2475 TopTools_ListOfShape LI;
2476 TopTools_ListOfShape L1;
2477 myInitOffset.LastImage(SI,L1);
2478 TopTools_ListIteratorOfListOfShape itL1(L1);
2479 for (; itL1.More(); itL1.Next()) {
2480 const TopoDS_Shape& O1 = itL1.Value();
2481 TopTools_ListOfShape L2;
2482 myImageOffset.LastImage(O1,L2);
2483 LI.Append(L2);
2484 }
2485 NIOF.Bind(SI,LI);
2486 }
2487// Modified by skv - Mon Apr 4 18:17:27 2005 Begin
2488// Supporting history.
2489// NIOF.Filter(myOffsetShape,TopAbs_FACE);
2490 NIOF.Filter(myOffsetShape, theShapeType);
2491// Modified by skv - Mon Apr 4 18:17:27 2005 End
2492 myInitOffset = NIOF;
2493}
2494
2495//=======================================================================
2496//function : MakeMissingWalls
2497//purpose :
2498//=======================================================================
7fd59977 2499void BRepOffset_MakeOffset::MakeMissingWalls ()
2500{
2501 TopTools_DataMapOfShapeListOfShape Contours; //Start vertex + list of connected edges (free boundary)
2502 TopTools_DataMapOfShapeShape MapEF; //Edges of contours: edge + face
2503 Standard_Real OffsetVal = Abs(myOffset);
2504
2505 FillContours(myShape, myAnalyse, Contours, MapEF);
2506
2507 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape iter(Contours);
2508 for (; iter.More(); iter.Next())
a8704c36 2509 {
2510 TopoDS_Vertex StartVertex = TopoDS::Vertex(iter.Key());
2511 TopoDS_Edge StartEdge;
2512 const TopTools_ListOfShape& aContour = iter.Value();
2513 TopTools_ListIteratorOfListOfShape itl(aContour);
2514 Standard_Boolean FirstStep = Standard_True;
2515 TopoDS_Edge PrevEdge;
2516 TopoDS_Vertex PrevVertex = StartVertex;
2517 Standard_Boolean isBuildFromScratch = Standard_False; // Problems with edges.
2518 for (; itl.More(); itl.Next())
7fd59977 2519 {
a8704c36 2520 TopoDS_Edge anEdge = TopoDS::Edge(itl.Value());
2521
2522 // Check for offset existence.
2523 if (!myInitOffsetEdge.HasImage(anEdge))
2524 continue;
2525
2526 // Check for existence of two different vertices.
2527 TopTools_ListOfShape LOE, LOE2;
2528 myInitOffsetEdge.LastImage( anEdge, LOE );
2529 myImageOffset.LastImage( LOE.Last(), LOE2 );
2530 TopoDS_Edge OE = TopoDS::Edge( LOE2.Last() );
2531 TopoDS_Vertex V1, V2, V3, V4;
2532 TopExp::Vertices(OE, V4, V3);
2533 TopExp::Vertices(anEdge, V1, V2);
2534 Standard_Real aF, aL;
2535 const Handle(Geom_Curve) aC = BRep_Tool::Curve(anEdge, aF, aL);
2536 if (!aC.IsNull() &&
2537 (!aC->IsClosed() && !aC->IsPeriodic()))
2538 {
2539 gp_Pnt aPntF = BRep_Tool::Pnt(V1);
2540 gp_Pnt aPntL = BRep_Tool::Pnt(V2);
2541 Standard_Real aDistE = aPntF.SquareDistance(aPntL);
2542 if ( aDistE < Precision::SquareConfusion())
2543 {
2544 // Bad case: non closed, but vertexes mapped to same 3d point.
2545 continue;
2546 }
2547
2548 Standard_Real anEdgeTol = BRep_Tool::Tolerance(anEdge);
2549 if (aDistE < anEdgeTol)
2550 {
2551 // Potential problems not detected via checkshape.
2552 gp_Pnt aPntOF = BRep_Tool::Pnt(V4);
2553 gp_Pnt aPntOL = BRep_Tool::Pnt(V3);
2554 if (aPntOF.SquareDistance(aPntOL) > gp::Resolution())
de878dad 2555 {
a8704c36 2556 // To avoid computation of complex analytical continuation of Sin / ArcSin.
2557 Standard_Real aSinValue = Min(2 * anEdgeTol / aPntOF.Distance(aPntOL), 1.0);
2558 Standard_Real aMaxAngle = Min(Abs(ASin(aSinValue)), M_PI_4); // Maximal angle.
2559 Standard_Real aCurrentAngle = gp_Vec(aPntF, aPntL).Angle(gp_Vec(aPntOF, aPntOL));
2560 if (aC->IsKind(STANDARD_TYPE(Geom_Line)) &&
2561 Abs (aCurrentAngle) > aMaxAngle)
2562 {
2563 // anEdge not collinear to offset edge.
2564 isBuildFromScratch = Standard_True;
2565 myIsPerformSewing = Standard_True;
2566 continue;
2567 }
2568 }
2569 }
2570 }
2571
2572 Standard_Boolean ToReverse = Standard_False;
2573 if (!V1.IsSame(PrevVertex))
2574 {
2575 TopoDS_Vertex aVtx = V1; V1 = V2; V2 = aVtx;
2576 aVtx = V3; V3 = V4; V4 = aVtx;
2577 ToReverse = Standard_True;
2578 }
2579
2580 OE.Orientation(TopAbs::Reverse(anEdge.Orientation()));
2581 TopoDS_Edge E3, E4;
2582 Standard_Boolean ArcOnV2 = ((myJoin == GeomAbs_Arc) && (myInitOffsetEdge.HasImage(V2)));
2583 if (FirstStep || isBuildFromScratch)
2584 {
2585 E4 = BRepLib_MakeEdge( V1, V4 );
2586 if (FirstStep)
2587 StartEdge = E4;
2588 }
2589 else
2590 E4 = PrevEdge;
2591 if (V2.IsSame(StartVertex) && !ArcOnV2)
2592 E3 = StartEdge;
2593 else
2594 E3 = BRepLib_MakeEdge( V2, V3 );
2595 E4.Reverse();
2596
2597 if (isBuildFromScratch)
2598 {
2599 E3.Reverse();
2600 E4.Reverse();
2601 }
2602
2603 TopoDS_Shape localAnEdge = anEdge.Oriented(TopAbs_FORWARD);
2604 const TopoDS_Edge& anEdgeFWD = TopoDS::Edge(localAnEdge);
2605 Standard_Real ParV1 = BRep_Tool::Parameter(V1, anEdgeFWD);
2606 Standard_Real ParV2 = BRep_Tool::Parameter(V2, anEdgeFWD);
2607 BRep_Builder BB;
2608 TopoDS_Wire theWire;
2609 BB.MakeWire(theWire);
2610 if (ToReverse)
2611 {
2612 BB.Add(theWire, anEdge.Reversed());
2613 BB.Add(theWire, E3.Reversed());
2614 BB.Add(theWire, OE.Reversed());
2615 BB.Add(theWire, E4.Reversed());
2616 }
2617 else
2618 {
2619 BB.Add(theWire, anEdge);
2620 BB.Add(theWire, E3);
2621 BB.Add(theWire, OE);
2622 BB.Add(theWire, E4);
2623 }
2624
2625 BRepLib::BuildCurves3d( theWire, myTol );
2626 theWire.Closed(Standard_True);
2627 TopoDS_Face NewFace;
2628 Handle(Geom_Surface) theSurf;
2629 BRepAdaptor_Curve BAcurve(anEdge);
2630 BRepAdaptor_Curve BAcurveOE(OE);
2631 Standard_Real fpar = BAcurve.FirstParameter();
2632 Standard_Real lpar = BAcurve.LastParameter();
2633 gp_Pnt PonE = BAcurve.Value(fpar);
2634 gp_Pnt PonOE = BAcurveOE.Value(fpar);
2635 gp_Dir OffsetDir = gce_MakeDir( PonE, PonOE );
2636 Handle(Geom2d_Line) EdgeLine2d, OELine2d, aLine2d, aLine2d2;
2637 Standard_Boolean IsPlanar = Standard_False;
2638 if (BAcurve.GetType() == GeomAbs_Circle &&
2639 BAcurveOE.GetType() == GeomAbs_Circle)
2640 {
2641 gp_Circ aCirc = BAcurve.Circle();
2642 gp_Circ aCircOE = BAcurveOE.Circle();
2643 gp_Lin anAxisLine(aCirc.Axis());
2644 gp_Dir CircAxisDir = aCirc.Axis().Direction();
2645 if (aCirc.Axis().IsParallel(aCircOE.Axis(), Precision::Confusion()) &&
2646 anAxisLine.Contains(aCircOE.Location(), Precision::Confusion()))
2647 { //cylinder, plane or cone
2648 if (Abs(aCirc.Radius() - aCircOE.Radius()) <= Precision::Confusion()) //case of cylinder
2649 theSurf = GC_MakeCylindricalSurface(aCirc).Value();
2650 else if (aCirc.Location().Distance(aCircOE.Location()) <= Precision::Confusion()) {//case of plane
2651 IsPlanar = Standard_True;
2652 //
2653 gp_Pnt PonEL = BAcurve.Value(lpar);
2654 if (PonEL.Distance(PonE) <= Precision::PConfusion()) {
2655 Standard_Boolean bIsHole;
2656 TopoDS_Edge aE1, aE2;
2657 TopoDS_Wire aW1, aW2;
2658 Handle(Geom_Plane) aPL;
2659 IntTools_FClass2d aClsf;
2660 //
2661 if (aCirc.Radius()>aCircOE.Radius()) {
2662 aE1 = anEdge;
2663 aE2 = OE;
2664 } else {
2665 aE1 = OE;
2666 aE2 = anEdge;
2667 }
2668 //
2669 BB.MakeWire(aW1);
2670 BB.Add(aW1, aE1);
2671 BB.MakeWire(aW2);
2672 BB.Add(aW2, aE2);
2673 //
2674 aPL = new Geom_Plane(aCirc.Location(), CircAxisDir);
2675 for (Standard_Integer i = 0; i < 2; ++i) {
2676 TopoDS_Wire& aW = (i==0) ? aW1 : aW2;
2677 TopoDS_Edge& aE = (i==0) ? aE1 : aE2;
bb310307 2678 //
a8704c36 2679 TopoDS_Face aFace;
2680 BB.MakeFace(aFace, aPL, Precision::Confusion());
2681 BB.Add (aFace, aW);
2682 aClsf.Init(aFace, Precision::Confusion());
2683 bIsHole=aClsf.IsHole();
2684 if ((bIsHole && !i) || (!bIsHole && i)) {
2685 aW.Nullify();
2686 BB.MakeWire(aW);
2687 BB.Add(aW, aE.Reversed());
bb310307 2688 }
2689 }
a8704c36 2690 //
2691 BB.MakeFace(NewFace, aPL, Precision::Confusion());
2692 BB.Add(NewFace, aW1);
2693 BB.Add(NewFace, aW2);
2694 }
2695 }
2696 else //case of cone
2697 {
2698 gp_Cone theCone = gce_MakeCone(aCirc.Location(), aCircOE.Location(),
2699 aCirc.Radius(), aCircOE.Radius());
2700 gp_Ax3 theAx3(aCirc.Position());
2701 if (CircAxisDir * theCone.Axis().Direction() < 0.)
2702 {
2703 theAx3.ZReverse();
2704 CircAxisDir.Reverse();
2705 }
2706 theCone.SetPosition(theAx3);
2707 theSurf = new Geom_ConicalSurface(theCone);
2708 }
2709 if (!IsPlanar) {
2710 TopLoc_Location Loc;
2711 EdgeLine2d = new Geom2d_Line(gp_Pnt2d(0., 0.), gp_Dir2d(1., 0.));
2712 BB.UpdateEdge(anEdge, EdgeLine2d, theSurf, Loc, Precision::Confusion());
2713 Standard_Real Coeff = (OffsetDir * CircAxisDir > 0.)? 1. : -1.;
2714 OELine2d = new Geom2d_Line(gp_Pnt2d(0., OffsetVal*Coeff), gp_Dir2d(1., 0.));
2715 BB.UpdateEdge(OE, OELine2d, theSurf, Loc, Precision::Confusion());
2716 aLine2d = new Geom2d_Line(gp_Pnt2d(ParV2, 0.), gp_Dir2d(0., Coeff));
2717 aLine2d2 = new Geom2d_Line(gp_Pnt2d(ParV1, 0.), gp_Dir2d(0., Coeff));
2718 if (E3.IsSame(E4))
2719 {
2720 if (Coeff > 0.)
2721 BB.UpdateEdge(E3, aLine2d, aLine2d2, theSurf, Loc, Precision::Confusion());
2722 else
de878dad 2723 {
a8704c36 2724 BB.UpdateEdge(E3, aLine2d2, aLine2d, theSurf, Loc, Precision::Confusion());
2725 theWire.Nullify();
2726 BB.MakeWire(theWire);
2727 BB.Add(theWire, anEdge.Oriented(TopAbs_REVERSED));
2728 BB.Add(theWire, E4);
2729 BB.Add(theWire, OE.Oriented(TopAbs_FORWARD));
2730 BB.Add(theWire, E3);
2731 theWire.Closed(Standard_True);
de878dad 2732 }
a8704c36 2733 }
2734 else
2735 {
2736 BB.SameParameter(E3, Standard_False);
2737 BB.SameRange(E3, Standard_False);
2738 BB.SameParameter(E4, Standard_False);
2739 BB.SameRange(E4, Standard_False);
2740 BB.UpdateEdge(E3, aLine2d, theSurf, Loc, Precision::Confusion());
2741 BB.Range(E3, theSurf, Loc, 0., OffsetVal);
2742 BB.UpdateEdge(E4, aLine2d2, theSurf, Loc, Precision::Confusion());
2743 BB.Range(E4, theSurf, Loc, 0., OffsetVal);
2744 }
2745 NewFace = BRepLib_MakeFace(theSurf, theWire);
2746 }
2747 } //cylinder or cone
2748 } //if both edges are arcs of circles
2749 if (NewFace.IsNull())
2750 {
2751 BRepLib_MakeFace MF(theWire, Standard_True); //Only plane
2752 if (MF.Error() == BRepLib_FaceDone)
2753 {
2754 NewFace = MF.Face();
2755 IsPlanar = Standard_True;
2756 }
2757 else //Extrusion (by thrusections)
2758 {
2759 Handle(Geom_Curve) EdgeCurve = BRep_Tool::Curve(anEdge, fpar, lpar);
2760 Handle(Geom_TrimmedCurve) TrEdgeCurve =
2761 new Geom_TrimmedCurve( EdgeCurve, fpar, lpar );
2762 Standard_Real fparOE, lparOE;
2763 Handle(Geom_Curve) OffsetCurve = BRep_Tool::Curve(OE, fparOE, lparOE);
2764 Handle(Geom_TrimmedCurve) TrOffsetCurve =
2765 new Geom_TrimmedCurve( OffsetCurve, fparOE, lparOE );
2766 GeomFill_Generator ThrusecGenerator;
2767 ThrusecGenerator.AddCurve( TrEdgeCurve );
2768 ThrusecGenerator.AddCurve( TrOffsetCurve );
2769 ThrusecGenerator.Perform( Precision::PConfusion() );
2770 theSurf = ThrusecGenerator.Surface();
2771 //theSurf = new Geom_SurfaceOfLinearExtrusion( TrOffsetCurve, OffsetDir );
2772 Standard_Real Uf, Ul, Vf, Vl;
2773 theSurf->Bounds(Uf, Ul, Vf, Vl);
2774 TopLoc_Location Loc;
2775 EdgeLine2d = new Geom2d_Line(gp_Pnt2d(0., Vf), gp_Dir2d(1., 0.));
2776 BB.UpdateEdge(anEdge, EdgeLine2d, theSurf, Loc, Precision::Confusion());
2777 OELine2d = new Geom2d_Line(gp_Pnt2d(0., Vl), gp_Dir2d(1., 0.));
2778 BB.UpdateEdge(OE, OELine2d, theSurf, Loc, Precision::Confusion());
2779 Standard_Real UonV1 = (ToReverse)? Ul : Uf;
2780 Standard_Real UonV2 = (ToReverse)? Uf : Ul;
2781 aLine2d = new Geom2d_Line(gp_Pnt2d(UonV2, 0.), gp_Dir2d(0., 1.));
2782 aLine2d2 = new Geom2d_Line(gp_Pnt2d(UonV1, 0.), gp_Dir2d(0., 1.));
2783 if (E3.IsSame(E4))
2784 {
2785 BB.UpdateEdge(E3, aLine2d, aLine2d2, theSurf, Loc, Precision::Confusion());
2786 Handle(Geom_Curve) BSplC34 = theSurf->UIso( Uf );
2787 BB.UpdateEdge(E3, BSplC34, Precision::Confusion());
2788 BB.Range(E3, Vf, Vl);
2789 }
2790 else
2791 {
2792 BB.SameParameter(E3, Standard_False);
2793 BB.SameRange(E3, Standard_False);
2794 BB.SameParameter(E4, Standard_False);
2795 BB.SameRange(E4, Standard_False);
2796 BB.UpdateEdge(E3, aLine2d, theSurf, Loc, Precision::Confusion());
2797 BB.Range(E3, theSurf, Loc, Vf, Vl);
2798 BB.UpdateEdge(E4, aLine2d2, theSurf, Loc, Precision::Confusion());
2799 BB.Range(E4, theSurf, Loc, Vf, Vl);
2800 Handle(Geom_Curve) BSplC3 = theSurf->UIso( UonV2 );
2801 BB.UpdateEdge(E3, BSplC3, Precision::Confusion());
2802 BB.Range(E3, Vf, Vl, Standard_True); //only for 3d curve
2803 Handle(Geom_Curve) BSplC4 = theSurf->UIso( UonV1 );
2804 BB.UpdateEdge(E4, BSplC4, Precision::Confusion());
2805 BB.Range(E4, Vf, Vl, Standard_True); //only for 3d curve
2806 }
2807 NewFace = BRepLib_MakeFace(theSurf, theWire);
2808 }
2809 }
2810 if (!IsPlanar)
2811 {
2812 Standard_Real fparOE = BAcurveOE.FirstParameter();
2813 Standard_Real lparOE = BAcurveOE.LastParameter();
2814 TopLoc_Location Loc;
2815 if (Abs(fpar - fparOE) > Precision::Confusion())
2816 {
2817 const TopoDS_Edge& anE4 = (ToReverse)? E3 : E4;
2818 gp_Pnt2d fp2d = EdgeLine2d->Value(fpar);
2819 gp_Pnt2d fp2dOE = OELine2d->Value(fparOE);
2820 aLine2d2 = GCE2d_MakeLine( fp2d, fp2dOE ).Value();
2821 Handle(Geom_Curve) aCurve;
2822 Standard_Real FirstPar = 0., LastPar = fp2d.Distance(fp2dOE);
2823 Geom2dAdaptor_Curve AC2d( aLine2d2, FirstPar, LastPar );
2824 GeomAdaptor_Surface GAsurf( theSurf );
2825 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( AC2d );
2826 Handle(GeomAdaptor_HSurface) HSurf = new GeomAdaptor_HSurface( GAsurf );
2827 Adaptor3d_CurveOnSurface ConS( HC2d, HSurf );
2828 Standard_Real max_deviation = 0., average_deviation;
2829 GeomLib::BuildCurve3d(Precision::Confusion(),
2830 ConS, FirstPar, LastPar,
2831 aCurve, max_deviation, average_deviation);
2832 BB.UpdateEdge( anE4, aCurve, max_deviation );
2833 BB.UpdateEdge( anE4, aLine2d2, theSurf, Loc, max_deviation );
2834 BB.Range( anE4, FirstPar, LastPar );
2835 }
2836 if (Abs(lpar - lparOE) > Precision::Confusion())
2837 {
2838 const TopoDS_Edge& anE3 = (ToReverse)? E4 : E3;
2839 gp_Pnt2d lp2d = EdgeLine2d->Value(lpar);
2840 gp_Pnt2d lp2dOE = OELine2d->Value(lparOE);
2841 aLine2d = GCE2d_MakeLine( lp2d, lp2dOE ).Value();
2842 Handle(Geom_Curve) aCurve;
2843 Standard_Real FirstPar = 0., LastPar = lp2d.Distance(lp2dOE);
2844 Geom2dAdaptor_Curve AC2d( aLine2d, FirstPar, LastPar );
2845 GeomAdaptor_Surface GAsurf( theSurf );
2846 Handle(Geom2dAdaptor_HCurve) HC2d = new Geom2dAdaptor_HCurve( AC2d );
2847 Handle(GeomAdaptor_HSurface) HSurf = new GeomAdaptor_HSurface( GAsurf );
2848 Adaptor3d_CurveOnSurface ConS( HC2d, HSurf );
2849 Standard_Real max_deviation = 0., average_deviation;
2850 GeomLib::BuildCurve3d(Precision::Confusion(),
2851 ConS, FirstPar, LastPar,
2852 aCurve, max_deviation, average_deviation);
2853 BB.UpdateEdge( anE3, aCurve, max_deviation );
2854 BB.UpdateEdge( anE3, aLine2d, theSurf, Loc, max_deviation );
2855 BB.Range( anE3, FirstPar, LastPar );
2856 }
2857 }
2858 BRepLib::SameParameter(NewFace);
2859 BRepTools::Update(NewFace);
2860 myWalls.Append(NewFace);
2861 if (ArcOnV2)
2862 {
2863 TopoDS_Edge anArc = TopoDS::Edge(myInitOffsetEdge.Image(V2).First());
2864 TopoDS_Vertex arcV1, arcV2;
2865 TopExp::Vertices(anArc, arcV1, arcV2);
2866 Standard_Boolean ArcReverse = Standard_False;
2867 if (!arcV1.IsSame(V3))
2868 {
2869 TopoDS_Vertex aVtx = arcV1; arcV1 = arcV2; arcV2 = aVtx;
2870 ArcReverse = Standard_True;
2871 }
2872 TopoDS_Edge EA1, EA2;
2873 //EA1 = (ToReverse)? E3 : TopoDS::Edge(E3.Reversed());
2874 EA1 = E3;
2875 EA1.Reverse();
2876 if (ToReverse)
2877 EA1.Reverse();
2878 //////////////////////////////////////////////////////
2879 if (V2.IsSame(StartVertex))
2880 EA2 = StartEdge;
2881 else
2882 EA2 = BRepLib_MakeEdge( V2, arcV2 );
2883 anArc.Orientation( ((ArcReverse)? TopAbs_REVERSED : TopAbs_FORWARD) );
2884 if (EA1.Orientation() == TopAbs_REVERSED)
2885 anArc.Reverse();
2886 EA2.Orientation(TopAbs::Reverse(EA1.Orientation()));
2887 TopoDS_Wire arcWire;
2888 BB.MakeWire(arcWire);
2889 BB.Add(arcWire, EA1);
2890 BB.Add(arcWire, anArc);
2891 BB.Add(arcWire, EA2);
2892 BRepLib::BuildCurves3d( arcWire, myTol );
2893 arcWire.Closed(Standard_True);
2894 TopoDS_Face arcFace = BRepLib_MakeFace(arcWire, Standard_True);
2895 BRepTools::Update(arcFace);
2896 myWalls.Append(arcFace);
2897 TopoDS_Shape localEA2 = EA2.Oriented(TopAbs_FORWARD);
2898 const TopoDS_Edge& CEA2 = TopoDS::Edge(localEA2);
2899 PrevEdge = CEA2;
2900 PrevVertex = V2;
2901 }
2902 else
2903 {
2904 if (isBuildFromScratch)
2905 {
2906 PrevEdge = TopoDS::Edge(E4);
2907 PrevVertex = V1;
2908 isBuildFromScratch = Standard_False;
2909 }
2910 else
2911 {
2912 PrevEdge = E3;
2913 PrevVertex = V2;
2914 }
2915 }
2916 FirstStep = Standard_False;
7fd59977 2917 }
a8704c36 2918 }
7fd59977 2919}
2920
2921//=======================================================================
2922//function : MakeShells
2923//purpose :
2924//=======================================================================
2925
2926void BRepOffset_MakeOffset::MakeShells ()
2927{
0797d9d3 2928#ifdef OCCT_DEBUG
7fd59977 2929 if (ChronBuild) {
0d969553 2930 cout << " RECONSTRUCTION OF SHELLS:" << endl;
7fd59977 2931 Clock.Reset();
2932 Clock.Start();
2933 }
2934#endif
9b7f3f83 2935 //
e7384fd4 2936 // Prepare list of splits of the offset faces to make the shells
9b7f3f83 2937 BOPCol_ListOfShape aLSF;
7fd59977 2938 const TopTools_ListOfShape& R = myImageOffset.Roots();
2939 TopTools_ListIteratorOfListOfShape it(R);
9b7f3f83 2940 //
2941 for (; it.More(); it.Next()) {
ecf4f17c 2942 const TopoDS_Shape& aF = it.Value();
2943 //
7fd59977 2944 TopTools_ListOfShape Image;
ecf4f17c 2945 myImageOffset.LastImage(aF,Image);
7fd59977 2946 TopTools_ListIteratorOfListOfShape it2(Image);
9b7f3f83 2947 for (; it2.More(); it2.Next()) {
ecf4f17c 2948 const TopoDS_Shape& aFIm = it2.Value();
2949 aLSF.Append(aFIm);
7fd59977 2950 }
2951 }
9b7f3f83 2952 //
2953 if (myThickening) {
db2f1498 2954 TopExp_Explorer Explo(myShape, TopAbs_FACE);
9b7f3f83 2955 for (; Explo.More(); Explo.Next()) {
2956 const TopoDS_Shape& aF = Explo.Current();
2957 aLSF.Append(aF);
2958 }
2959 //
2960 it.Initialize(myWalls);
2961 for (; it.More(); it.Next()) {
2962 const TopoDS_Shape& aF = it.Value();
2963 aLSF.Append(aF);
2964 }
2965 }
2966 //
ecf4f17c 2967 if (aLSF.IsEmpty()) {
2968 return;
2969 }
2970 //
9b7f3f83 2971 Standard_Boolean bDone = Standard_False;
2972 if ((myJoin == GeomAbs_Intersection) && myInter &&
2973 !myThickening && myFaces.IsEmpty() &&
2974 IsSolid(myShape) && myIsPlanar) {
2975 //
ecf4f17c 2976 TopoDS_Shape aShells;
e7384fd4 2977 bDone = BuildShellsCompleteInter(aLSF, myImageOffset, aShells);
9b7f3f83 2978 if (bDone) {
ecf4f17c 2979 myOffsetShape = aShells;
9b7f3f83 2980 }
2981 }
2982 //
2983 if (!bDone) {
2984 BRepTools_Quilt Glue;
ecf4f17c 2985 BOPCol_ListIteratorOfListOfShape aItLS(aLSF);
9b7f3f83 2986 for (; aItLS.More(); aItLS.Next()) {
ecf4f17c 2987 Glue.Add(aItLS.Value());
9b7f3f83 2988 }
2989 myOffsetShape = Glue.Shells();
db2f1498 2990 }
db2f1498 2991 //
2992 //Set correct value for closed flag
2993 TopExp_Explorer Explo(myOffsetShape, TopAbs_SHELL);
2994 for(; Explo.More(); Explo.Next())
2995 {
2996 TopoDS_Shape aS = Explo.Current();
2997 if(!aS.Closed())
2998 {
2999 if(BRep_Tool::IsClosed(aS))
3000 {
3001 aS.Closed(Standard_True);
3002 }
3003 }
ecf4f17c 3004 }
7fd59977 3005}
3006
3007//=======================================================================
3008//function : MakeSolid
3009//purpose :
3010//=======================================================================
3011
3012void BRepOffset_MakeOffset::MakeSolid ()
3013{
3014 if (myOffsetShape.IsNull()) return;
3015
3016// Modified by skv - Mon Apr 4 18:17:27 2005 Begin
3017// Supporting history.
3018 UpdateInitOffset (myInitOffsetFace,myImageOffset,myOffsetShape, TopAbs_FACE);
3019 UpdateInitOffset (myInitOffsetEdge,myImageOffset,myOffsetShape, TopAbs_EDGE);
3020// Modified by skv - Mon Apr 4 18:17:27 2005 End
3021 TopExp_Explorer exp;
3022 BRep_Builder B;
3023 Standard_Integer NbShell = 0;
3024 TopoDS_Compound NC;
3025 TopoDS_Shape S1;
3026 B.MakeCompound (NC);
3027
db2f1498 3028 TopoDS_Solid Sol;
3029 B.MakeSolid(Sol);
3030 Sol.Closed(Standard_True);
3031 Standard_Boolean aMakeSolid = (myShape.ShapeType() == TopAbs_SOLID) || myThickening;
7fd59977 3032 for (exp.Init(myOffsetShape,TopAbs_SHELL); exp.More(); exp.Next()) {
3033 TopoDS_Shell Sh = TopoDS::Shell(exp.Current());
3034 if (myThickening && myOffset > 0.)
3035 Sh.Reverse();
3036 NbShell++;
db2f1498 3037 if (Sh.Closed() && aMakeSolid) {
3038 B.Add(Sol,Sh);
7fd59977 3039 }
3040 else {
3041 B.Add (NC,Sh);
db2f1498 3042 if(NbShell == 1)
3043 {
3044 S1 = Sh;
3045 }
3046 }
3047 }
3048 TopoDS_Iterator anIt(Sol);
3049 Standard_Boolean SolIsNull = !anIt.More();
3050 //Checking solid
3051 if(!SolIsNull)
3052 {
3053 Standard_Integer nbs = 0;
3054 while(anIt.More()) {anIt.Next(); ++nbs;}
3055 if(nbs > 1)
3056 {
3057 BRepCheck_Analyzer aCheck(Sol, Standard_False);
3058 if(!aCheck.IsValid())
3059 {
3060 TopTools_ListOfShape aSolList;
3061 CorrectSolid(Sol, aSolList);
3062 if(!aSolList.IsEmpty())
3063 {
3064 B.Add(NC, Sol);
3065 TopTools_ListIteratorOfListOfShape aSLIt(aSolList);
3066 for(; aSLIt.More(); aSLIt.Next())
3067 {
3068 B.Add(NC, aSLIt.Value());
3069 }
3070 SolIsNull = Standard_True;
3071 }
3072 }
7fd59977 3073 }
3074 }
db2f1498 3075 anIt.Initialize(NC);
3076 Standard_Boolean NCIsNull = !anIt.More();
3077 if((!SolIsNull) && (!NCIsNull))
3078 {
3079 B.Add(NC, Sol);
3080 myOffsetShape = NC;
3081 }
3082 else if(SolIsNull && (!NCIsNull))
3083 {
3084 if (NbShell == 1)
3085 {
3086 myOffsetShape = S1;
3087 }
3088 else
3089 {
3090 myOffsetShape = NC;
3091 }
3092 }
3093 else if((!SolIsNull) && NCIsNull)
3094 {
3095 myOffsetShape = Sol;
3096 }
3097 else
3098 {
3099 myOffsetShape = NC;
3100 }
7fd59977 3101}
3102
3103//=======================================================================
3104//function : SelectShells
3105//purpose :
3106//=======================================================================
3107
3108void BRepOffset_MakeOffset::SelectShells ()
ecf4f17c 3109{
7fd59977 3110 TopTools_MapOfShape FreeEdges;
3111 TopExp_Explorer exp(myShape,TopAbs_EDGE);
3112 //-------------------------------------------------------------
0d969553
Y
3113 // FreeEdges all edges that can have free border in the
3114 // parallel shell
3115 // 1 - free borders of myShape .
7fd59977 3116 //-------------------------------------------------------------
3117 for ( ; exp.More(); exp.Next()) {
3118 const TopoDS_Edge& E = TopoDS::Edge(exp.Current());
3119 const TopTools_ListOfShape& LA = myAnalyse.Ancestors(E);
3120 if (LA.Extent() < 2) {
3121 if (myAnalyse.Type(E).First().Type() == BRepOffset_FreeBoundary) {
9b7f3f83 3122 FreeEdges.Add(E);
7fd59977 3123 }
3124 }
3125 }
0d969553
Y
3126 // myShape has free borders and there are no caps
3127 // no unwinding 3d.
7fd59977 3128 if (!FreeEdges.IsEmpty() && myFaces.IsEmpty()) return;
3129
3130 myOffsetShape = BRepOffset_Tool::Deboucle3D(myOffsetShape,FreeEdges);
3131}
3132
3133//=======================================================================
3134//function : OffsetFacesFromShapes
3135//purpose :
3136//=======================================================================
3137
3138const BRepAlgo_Image& BRepOffset_MakeOffset::OffsetFacesFromShapes() const
3139{
3140 return myInitOffsetFace;
3141}
3142
3143// Modified by skv - Tue Mar 15 16:20:43 2005 Begin
3144
3145//=======================================================================
3146//function : GetJoinType
3147//purpose : Query offset join type.
3148//=======================================================================
3149
3150GeomAbs_JoinType BRepOffset_MakeOffset::GetJoinType() const
3151{
3152 return myJoin;
3153}
3154
3155//=======================================================================
3156//function : OffsetEdgesFromShapes
3157//purpose :
3158//=======================================================================
3159
3160const BRepAlgo_Image& BRepOffset_MakeOffset::OffsetEdgesFromShapes() const
3161{
3162 return myInitOffsetEdge;
3163}
3164
3165// Modified by skv - Tue Mar 15 16:20:43 2005 End
3166
3167//=======================================================================
3168//function : ClosingFaces
3169//purpose :
3170//=======================================================================
3171
975ec82a 3172const TopTools_IndexedMapOfShape& BRepOffset_MakeOffset::ClosingFaces () const
7fd59977 3173{
3174 return myFaces;
3175}
3176
3177
3178
3179//=======================================================================
3180//function : EncodeRegularity
3181//purpose :
3182//=======================================================================
3183
3184void BRepOffset_MakeOffset::EncodeRegularity ()
3185{
0797d9d3 3186#ifdef OCCT_DEBUG
7fd59977 3187 if (ChronBuild) {
0d969553 3188 cout << " CODING OF REGULARITIES:" << endl;
7fd59977 3189 Clock.Reset();
3190 Clock.Start();
3191 }
3192#endif
3193
3194 if (myOffsetShape.IsNull()) return;
0d969553 3195 // find edges G1 in the result
7fd59977 3196 TopExp_Explorer exp(myOffsetShape,TopAbs_EDGE);
3197
3198 BRep_Builder B;
3199 TopTools_MapOfShape MS;
3200
3201 for ( ; exp.More(); exp.Next()) {
3202 TopoDS_Edge OE = TopoDS::Edge(exp.Current());
3203 BRepLib::BuildCurve3d(OE,myTol);
3204 TopoDS_Edge ROE = OE;
3205
3206 if ( !MS.Add(OE)) continue;
3207
3208 if ( myImageOffset.IsImage(OE))
3209 ROE = TopoDS::Edge(myImageOffset.Root(OE));
3210
3211 const TopTools_ListOfShape& LofOF = myAsDes->Ascendant(ROE);
3212
3213 if (LofOF.Extent() != 2) {
0797d9d3 3214#ifdef OCCT_DEBUG_VERB
498ce76b 3215 cout << " Edge shared by " << LofOF.Extent() << " Faces" << endl;
7fd59977 3216#endif
3217 continue;
3218 }
3219
3220 const TopoDS_Face& F1 = TopoDS::Face(LofOF.First());
3221 const TopoDS_Face& F2 = TopoDS::Face(LofOF.Last() );
3222
3223 if ( F1.IsNull() || F2.IsNull())
3224 continue;
3225
3226 const TopoDS_Shape& Root1 = myInitOffsetFace.Root(F1);
3227 const TopoDS_Shape& Root2 = myInitOffsetFace.Root(F2);
3228
3229 TopAbs_ShapeEnum Type1 = Root1.ShapeType();
3230 TopAbs_ShapeEnum Type2 = Root2.ShapeType();
3231
3232 if (F1.IsSame(F2)) {
3233 if (BRep_Tool::IsClosed(OE,F1)) {
9b7f3f83 3234 // Temporary Debug for the Bench.
3235 // Check with YFR.
3236 // In mode intersection, the edges are not coded in myInitOffsetEdge
3237 // so, manage case by case
3238 // Note DUB; for Hidden parts, it is NECESSARY to code CN
3239 // Analytic Surfaces.
3240 if (myJoin == GeomAbs_Intersection) {
3241 BRepAdaptor_Surface BS(F1,Standard_False);
3242 GeomAbs_SurfaceType SType = BS.GetType();
3243 if (SType == GeomAbs_Cylinder ||
3244 SType == GeomAbs_Cone ||
3245 SType == GeomAbs_Sphere ||
3246 SType == GeomAbs_Torus ) {
3247 B.Continuity(OE,F1,F1,GeomAbs_CN);
3248 }
3249 else {
3250 // See YFR : MaJ of myInitOffsetFace
3251 }
3252 }
3253 else if (myInitOffsetEdge.IsImage(ROE)) {
3254 if ( Type1 == TopAbs_FACE && Type2 == TopAbs_FACE) {
3255 const TopoDS_Face& FRoot = TopoDS::Face(Root1);
3256 const TopoDS_Edge& EI = TopoDS::Edge(myInitOffsetEdge.ImageFrom(ROE));
3257 GeomAbs_Shape Conti = BRep_Tool::Continuity(EI,FRoot,FRoot);
3258 if (Conti == GeomAbs_CN) {
3259 B.Continuity(OE,F1,F1,GeomAbs_CN);
3260 }
3261 else if ( Conti > GeomAbs_C0) {
3262 B.Continuity(OE,F1,F1,GeomAbs_G1);
3263 }
3264 }
3265 }
7fd59977 3266 }
3267 continue;
3268 }
3269
3270
0d969553
Y
3271 // code regularities G1 between :
3272 // - sphere and tube : one root is a vertex, the other is an edge
3273 // and the vertex is included in the edge
3274 // - face and tube : one root is a face, the other an edge
3275 // and the edge is included in the face
3276 // - face and face : if two root faces are tangent in
3277 // the initial shape, they will be tangent in the offset shape
3278 // - tube and tube : if 2 edges generating tubes are
3279 // tangents, the 2 will be tangent either.
7fd59977 3280 if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_VERTEX) {
3281 TopoDS_Vertex V1,V2;
3282 TopExp::Vertices(TopoDS::Edge(Root1), V1, V2);
3283 if ( V1.IsSame(Root2) || V2.IsSame(Root2)) {
9b7f3f83 3284 B.Continuity(OE,F1,F2,GeomAbs_G1);
7fd59977 3285 }
3286 }
3287 else if ( Type1 == TopAbs_VERTEX && Type2 == TopAbs_EDGE) {
3288 TopoDS_Vertex V1,V2;
3289 TopExp::Vertices(TopoDS::Edge(Root2), V1, V2);
3290 if ( V1.IsSame(Root1) || V2.IsSame(Root1)) {
9b7f3f83 3291 B.Continuity(OE,F1,F2,GeomAbs_G1);
7fd59977 3292 }
3293 }
3294 else if ( Type1 == TopAbs_FACE && Type2 == TopAbs_EDGE) {
3295 TopExp_Explorer exp2(Root1,TopAbs_EDGE);
3296 for ( ; exp2.More(); exp2.Next()) {
9b7f3f83 3297 if ( exp2.Current().IsSame(Root2)) {
3298 B.Continuity(OE,F1,F2,GeomAbs_G1);
3299 break;
3300 }
7fd59977 3301 }
3302 }
3303 else if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_FACE) {
3304 TopExp_Explorer exp2(Root2,TopAbs_EDGE);
3305 for ( ; exp2.More(); exp2.Next()) {
9b7f3f83 3306 if ( exp2.Current().IsSame(Root1)) {
3307 B.Continuity(OE,F1,F2,GeomAbs_G1);
3308 break;
3309 }
7fd59977 3310 }
3311 }
3312 else if ( Type1 == TopAbs_FACE && Type2 == TopAbs_FACE) {
0d969553
Y
3313 // if two root faces are tangent in
3314 // the initial shape, they will be tangent in the offset shape
fe1d4d6c 3315 TopTools_ListOfShape LE;
3316 BRepOffset_Tool::FindCommonShapes(Root1, Root2, TopAbs_EDGE, LE);
3317 if ( LE.Extent() == 1) {
9b7f3f83 3318 const TopoDS_Edge& Ed = TopoDS::Edge(LE.First());
3319 if ( myAnalyse.HasAncestor(Ed)) {
3320 const BRepOffset_ListOfInterval& LI = myAnalyse.Type(Ed);
3321 if (LI.Extent() == 1 &&
3322 LI.First().Type() == BRepOffset_Tangent) {
3323 B.Continuity(OE,F1,F2,GeomAbs_G1);
3324 }
3325 }
7fd59977 3326 }
3327 }
3328 else if ( Type1 == TopAbs_EDGE && Type2 == TopAbs_EDGE) {
3329 TopTools_ListOfShape LV;
fe1d4d6c 3330 BRepOffset_Tool::FindCommonShapes(Root1, Root2, TopAbs_VERTEX, LV);
7fd59977 3331 if ( LV.Extent() == 1) {
9b7f3f83 3332 TopTools_ListOfShape LEdTg;
3333 myAnalyse.TangentEdges(TopoDS::Edge(Root1),
3334 TopoDS::Vertex(LV.First()),
3335 LEdTg);
3336 TopTools_ListIteratorOfListOfShape it(LEdTg);
3337 for (; it.More(); it.Next()) {
3338 if ( it.Value().IsSame(Root2)) {
3339 B.Continuity(OE,F1,F2,GeomAbs_G1);
3340 break;
3341 }
3342 }
7fd59977 3343 }
3344 }
3345 }
3346
0797d9d3 3347#ifdef OCCT_DEBUG
7fd59977 3348 if ( ChronBuild) Clock.Show();
3349#endif
3350}
3351
4560c054 3352//=======================================================================
3353//function : ComputeMaxDist
3354//purpose :
3355//=======================================================================
3356Standard_Real ComputeMaxDist(const gp_Pln& thePlane,
3357 const Handle(Geom_Curve)& theCrv,
3358 const Standard_Real theFirst,
3359 const Standard_Real theLast)
3360{
3361 Standard_Real aMaxDist = 0.;
3362 Standard_Integer i, NCONTROL = 23;
3363 Standard_Real aPrm, aDist2;
3364 gp_Pnt aP;
3365 for (i = 0; i< NCONTROL; i++) {
3366 aPrm = ((NCONTROL - 1 - i)*theFirst + i*theLast) / (NCONTROL - 1);
3367 aP = theCrv->Value(aPrm);
3368 if (Precision::IsInfinite(aP.X()) || Precision::IsInfinite(aP.Y())
3369 || Precision::IsInfinite(aP.Z()))
3370 {
3371 return Precision::Infinite();
3372 }
3373 aDist2 = thePlane.SquareDistance(aP);
3374 if (aDist2 > aMaxDist) aMaxDist = aDist2;
3375 }
3376 return sqrt(aMaxDist)*1.05;
3377}
7fd59977 3378//=======================================================================
3379//function : UpDateTolerance
3380//purpose :
3381//=======================================================================
3382
db2f1498 3383void UpdateTolerance (TopoDS_Shape& S,
4560c054 3384 const TopTools_IndexedMapOfShape& Faces)
7fd59977 3385{
3386 BRep_Builder B;
3387 TopTools_MapOfShape View;
3388 TopoDS_Vertex V[2];
3389
0d969553 3390 // The edges of caps are not modified.
975ec82a
J
3391 Standard_Integer j;
3392 for (j = 1; j <= Faces.Extent(); j++) {
3393 const TopoDS_Shape& F = Faces(j);
7fd59977 3394 TopExp_Explorer Exp;
3395 for (Exp.Init(F,TopAbs_EDGE); Exp.More(); Exp.Next()) {
3396 View.Add(Exp.Current());
3397 }
3398 }
3399
4560c054 3400 Standard_Real Tol;
3401 TopExp_Explorer ExpF;
3402 for (ExpF.Init(S, TopAbs_FACE); ExpF.More(); ExpF.Next())
3403 {
3404 const TopoDS_Shape& F = ExpF.Current();
3405 if (Faces.Contains(F))
3406 {
3407 continue;
3408 }
3409 BRepAdaptor_Surface aBAS(TopoDS::Face(F), Standard_False);
3410 TopExp_Explorer Exp;
3411 for (Exp.Init(F, TopAbs_EDGE); Exp.More(); Exp.Next()) {
3412 TopoDS_Edge E = TopoDS::Edge(Exp.Current());
3413 Standard_Boolean isUpdated = Standard_False;
3414 if (aBAS.GetType() == GeomAbs_Plane)
3415 {
3416 //Edge does not seem to have pcurve on plane,
3417 //so EdgeCorrector does not include it in tolerance calculation
3418 Standard_Real aFirst, aLast;
3419 Handle(Geom_Curve) aCrv = BRep_Tool::Curve(E, aFirst, aLast);
3420 Standard_Real aMaxDist = ComputeMaxDist(aBAS.Plane(), aCrv, aFirst, aLast);
3421 B.UpdateEdge(E, aMaxDist);
3422 isUpdated = Standard_True;
3423 }
3424 if (View.Add(E))
3425 {
3426
3427 BRepCheck_Edge EdgeCorrector(E);
3428 Tol = EdgeCorrector.Tolerance();
3429 B.UpdateEdge(E, Tol);
3430 isUpdated = Standard_True;
3431 }
3432 if (isUpdated)
3433 {
3434 Tol = BRep_Tool::Tolerance(E);
3435 // Update the vertices.
3436 TopExp::Vertices(E, V[0], V[1]);
3437
3438 for (Standard_Integer i = 0; i <= 1; i++) {
3439 if (View.Add(V[i])) {
3440 Handle(BRep_TVertex) TV = Handle(BRep_TVertex)::DownCast(V[i].TShape());
3441 TV->Tolerance(0.);
3442 BRepCheck_Vertex VertexCorrector(V[i]);
3443 B.UpdateVertex(V[i], VertexCorrector.Tolerance());
3444 // use the occasion to clean the vertices.
3445 (TV->ChangePoints()).Clear();
3446 }
3447 B.UpdateVertex(V[i], Tol);
9b7f3f83 3448 }
7fd59977 3449 }
3450 }
3451 }
3452}
3453
db2f1498 3454//=======================================================================
3455//function : CorrectSolid
3456//purpose :
3457//=======================================================================
3458void CorrectSolid(TopoDS_Solid& theSol, TopTools_ListOfShape& theSolList)
3459{
3460 BRep_Builder aBB;
3461 TopoDS_Shape anOuterShell;
3462 NCollection_List<Standard_Real> aVols;
3463 Standard_Real aVolMax = 0., anOuterVol = 0.;
3464
3465 TopoDS_Iterator anIt(theSol);
3466 for(; anIt.More(); anIt.Next())
3467 {
3468 const TopoDS_Shape& aSh = anIt.Value();
3469 GProp_GProps aVProps;
3470 BRepGProp::VolumeProperties(aSh, aVProps, Standard_True);
3471 if(Abs(aVProps.Mass()) > aVolMax)
3472 {
3473 anOuterVol = aVProps.Mass();
3474 aVolMax = Abs(anOuterVol);
3475 anOuterShell = aSh;
3476 }
3477 aVols.Append(aVProps.Mass());
3478 }
3479 //
ecf4f17c 3480 if (Abs(anOuterVol) < Precision::Confusion()) {
3481 return;
3482 }
db2f1498 3483 if(anOuterVol < 0.)
3484 {
3485 anOuterShell.Reverse();
3486 }
3487 TopoDS_Solid aNewSol;
3488 aBB.MakeSolid(aNewSol);
3489 aNewSol.Closed(Standard_True);
3490 aBB.Add(aNewSol, anOuterShell);
3491 BRepClass3d_SolidClassifier aSolClass(aNewSol);
3492 //
3493 anIt.Initialize(theSol);
3494 NCollection_List<Standard_Real>::Iterator aVIt(aVols);
3495 for(; anIt.More(); anIt.Next(), aVIt.Next())
3496 {
3497 TopoDS_Shell aSh = TopoDS::Shell(anIt.Value());
3498 if(aSh.IsSame(anOuterShell))
3499 {
3500 continue;
3501 }
3502 else
3503 {
3504 TopExp_Explorer aVExp(aSh, TopAbs_VERTEX);
3505 const TopoDS_Vertex& aV = TopoDS::Vertex(aVExp.Current());
3506 gp_Pnt aP = BRep_Tool::Pnt(aV);
3507 aSolClass.Perform(aP, BRep_Tool::Tolerance(aV));
3508 if(aSolClass.State() == TopAbs_IN)
3509 {
3510 if(aVIt.Value() > 0.)
3511 {
3512 aSh.Reverse();
3513 }
3514 aBB.Add(aNewSol, aSh);
3515 }
3516 else
3517 {
3518 if(aVIt.Value() < 0.)
3519 {
3520 aSh.Reverse();
3521 }
3522 TopoDS_Solid aSol;
3523 aBB.MakeSolid(aSol);
3524 aSol.Closed(Standard_True);
3525 aBB.Add(aSol, aSh);
3526 theSolList.Append(aSol);
3527 }
3528 }
3529 }
3530 theSol = aNewSol;
3531}
e1ed38e0 3532
3533//=======================================================================
3534//function : CheckInputData
3535//purpose : Check input data for possiblity of offset perform.
3536//=======================================================================
3537Standard_Boolean BRepOffset_MakeOffset::CheckInputData()
3538{
3539 // Set initial error state.
3540 myError = BRepOffset_NoError;
3541 TopoDS_Shape aTmpShape;
3542 myBadShape = aTmpShape;
3543
3544 // Non-null offset.
3545 if (Abs(myOffset) <= myTol)
3546 {
3547 Standard_Boolean isFound = Standard_False;
3548 TopTools_DataMapIteratorOfDataMapOfShapeReal anIter(myFaceOffset);
3549 for( ; anIter.More(); anIter.Next())
3550 {
3551 if (Abs(anIter.Value()) > myTol)
3552 {
3553 isFound = Standard_True;
3554 break;
3555 }
3556 }
3557
3558 if (!isFound)
3559 {
3560 // No face with non-null offset found.
3561 myError = BRepOffset_NullOffset;
3562 return Standard_False;
3563 }
3564 }
3565
3566 // Connectivity of input shape.
3567 if (!IsConnectedShell(myShape))
3568 {
3569 myError = BRepOffset_NotConnectedShell;
3570 return Standard_False;
3571 }
3572
3573 // Normals check and continuity check.
3574 const Standard_Integer aPntPerDim = 20; // 21 points on each dimension.
3575 Standard_Real aUmin, aUmax, aVmin, aVmax;
3576 TopExp_Explorer anExpSF(myShape, TopAbs_FACE);
3577 NCollection_Map<Handle(TopoDS_TShape)> aPresenceMap;
3578 TopLoc_Location L;
3579 gp_Pnt2d aPnt2d;
3580 for( ; anExpSF.More(); anExpSF.Next())
3581 {
3582 const TopoDS_Face& aF = TopoDS::Face(anExpSF.Current());
3583
3584 if (aPresenceMap.Contains(aF.TShape()))
3585 {
3586 // Not perform computations with partner shapes,
3587 // since they are contain same geometry.
3588 continue;
3589 }
3590 aPresenceMap.Add(aF.TShape());
3591
3592 const Handle(Geom_Surface)& aSurf = BRep_Tool::Surface(aF, L);
3593 BRepTools::UVBounds(aF, aUmin, aUmax, aVmin, aVmax);
3594
3595 // Continuity check.
3596 if (aSurf->Continuity() == GeomAbs_C0)
3597 {
3598 myError = BRepOffset_C0Geometry;
3599 return Standard_False;
3600 }
3601
3602 // Get degenerated points, to avoid check them.
3603 NCollection_Vector<gp_Pnt> aBad3dPnts;
3604 TopExp_Explorer anExpFE(aF, TopAbs_EDGE);
3605 for( ; anExpFE.More(); anExpFE.Next())
3606 {
3607 const TopoDS_Edge &aE = TopoDS::Edge(anExpFE.Current());
3608 if (BRep_Tool::Degenerated(aE))
3609 {
3610 aBad3dPnts.Append(BRep_Tool::Pnt((TopExp::FirstVertex(aE))));
3611 }
3612 }
3613
3614 // Geometry grid check.
3615 for(Standard_Integer i = 0; i <= aPntPerDim; i++)
3616 {
3617 Standard_Real aUParam = aUmin + (aUmax - aUmin) * i / aPntPerDim;
3618 for(Standard_Integer j = 0; j <= aPntPerDim; j++)
3619 {
3620 Standard_Real aVParam = aVmin + (aVmax - aVmin) * j / aPntPerDim;
3621
3622 myError = checkSinglePoint(aUParam, aVParam, aSurf, aBad3dPnts);
3623 if (myError != BRepOffset_NoError)
3624 return Standard_False;
3625 }
3626 }
3627
3628 // Vertex list check.
3629 TopExp_Explorer anExpFV(aF, TopAbs_VERTEX);
3630 for( ; anExpFV.More(); anExpFV.Next())
3631 {
3632 const TopoDS_Vertex &aV = TopoDS::Vertex(anExpFV.Current());
3633 aPnt2d = BRep_Tool::Parameters(aV, aF);
3634
3635 myError = checkSinglePoint(aPnt2d.X(), aPnt2d.Y(), aSurf, aBad3dPnts);
3636 if (myError != BRepOffset_NoError)
3637 return Standard_False;
3638 }
3639 }
3640
3641 return Standard_True;
3642}
3643
3644
3645//=======================================================================
3646//function : GetBadShape
3647//purpose : Get shape where problems detected.
3648//=======================================================================
3649const TopoDS_Shape& BRepOffset_MakeOffset::GetBadShape() const
3650{
3651 return myBadShape;
3652}
3653
9b7f3f83 3654//=======================================================================
3655//function : RemoveInternalEdges
3656//purpose :
3657//=======================================================================
3658void BRepOffset_MakeOffset::RemoveInternalEdges()
3659{
3660 Standard_Boolean bRemoveWire, bRemoveEdge;
3661 TopExp_Explorer aExpF, aExpW, aExpE;
3662 TopTools_IndexedDataMapOfShapeListOfShape aDMELF;
3663 //
3664 TopExp::MapShapesAndAncestors(myOffsetShape, TopAbs_EDGE, TopAbs_FACE, aDMELF);
3665 //
3666 aExpF.Init(myOffsetShape, TopAbs_FACE);
3667 for (; aExpF.More(); aExpF.Next()) {
3668 TopoDS_Face& aF = *(TopoDS_Face*)&aExpF.Current();
3669 //
3670 TopTools_ListOfShape aLIW;
3671 //
3672 aExpW.Init(aF, TopAbs_WIRE);
3673 for (; aExpW.More(); aExpW.Next()) {
3674 TopoDS_Wire& aW = *(TopoDS_Wire*)&aExpW.Current();
3675 //
3676 bRemoveWire = Standard_True;
3677 TopTools_ListOfShape aLIE;
3678 //
3679 aExpE.Init(aW, TopAbs_EDGE);
3680 for (; aExpE.More(); aExpE.Next()) {
3681 const TopoDS_Edge& aE = *(TopoDS_Edge*)&aExpE.Current();
3682 if (aE.Orientation() != TopAbs_INTERNAL) {
3683 bRemoveWire = Standard_False;
3684 continue;
3685 }
3686 //
3687 const TopTools_ListOfShape& aLF = aDMELF.FindFromKey(aE);
3688 bRemoveEdge = (aLF.Extent() == 1);
3689 if (bRemoveEdge) {
3690 aLIE.Append(aE);
3691 }
3692 else {
3693 bRemoveWire = Standard_False;
3694 }
3695 }
3696 //
3697 if (bRemoveWire) {
3698 aLIW.Append(aW);
3699 }
3700 else if (aLIE.Extent()) {
3701 RemoveShapes(aW, aLIE);
3702 }
3703 }
3704 //
3705 if (aLIW.Extent()) {
3706 RemoveShapes(aF, aLIW);
3707 }
3708 }
3709}
3710
3711//=======================================================================
3712// static methods implementation
3713//=======================================================================
e1ed38e0 3714
3715//=======================================================================
3716//function : checkSinglePoint
3717//purpose : Check single point on surface for bad normals
3718//=======================================================================
3719BRepOffset_Error checkSinglePoint(const Standard_Real theUParam,
3720 const Standard_Real theVParam,
3721 const Handle(Geom_Surface)& theSurf,
3722 const NCollection_Vector<gp_Pnt>& theBadPoints)
3723{
3724 gp_Pnt aPnt;
3725 gp_Vec aD1U, aD1V;
3726 theSurf->D1(theUParam, theVParam, aPnt, aD1U, aD1V);
3727
3728 if (aD1U.SquareMagnitude() < Precision::SquareConfusion() ||
3729 aD1V.SquareMagnitude() < Precision::SquareConfusion() )
3730 {
3731 Standard_Boolean isKnownBadPnt = Standard_False;
3732 for(Standard_Integer anIdx = theBadPoints.Lower();
3733 anIdx <= theBadPoints.Upper();
3734 ++anIdx)
3735 {
3736 if (aPnt.SquareDistance(theBadPoints(anIdx)) < Precision::SquareConfusion())
3737 {
3738 isKnownBadPnt = Standard_True;
3739 break;
3740 }
3741 } // for(Standard_Integer anIdx = theBadPoints.Lower();
3742
3743 if (!isKnownBadPnt)
3744 {
3745 return BRepOffset_BadNormalsOnGeometry;
3746 }
3747 else
3748 {
3749 return BRepOffset_NoError;
3750 }
3751 } // if (aD1U.SquareMagnitude() < Precision::SquareConfusion() ||
3752
3753 if (aD1U.IsParallel(aD1V, Precision::Confusion()))
3754 {
3755 // Isolines are collinear.
3756 return BRepOffset_BadNormalsOnGeometry;
3757 }
3758
3759 return BRepOffset_NoError;
3760}
9b7f3f83 3761
3762//=======================================================================
3763//function : RemoveShapes
3764//purpose : Removes the shapes <theLS> from the shape <theS>
3765//=======================================================================
3766void RemoveShapes(TopoDS_Shape& theS,
3767 const TopTools_ListOfShape& theLS)
3768{
3769 BRep_Builder aBB;
3770 //
3771 Standard_Boolean bFree = theS.Free();
3772 theS.Free(Standard_True);
3773 //
3774 TopTools_ListIteratorOfListOfShape aIt(theLS);
3775 for (; aIt.More(); aIt.Next()) {
3776 const TopoDS_Shape& aSI = aIt.Value();
3777 aBB.Remove(theS, aSI);
3778 }
3779 //
3780 theS.Free(bFree);
3781}
3782
3783//=======================================================================
ecf4f17c 3784//function : UpdateHistory
3785//purpose : Updates the history information
9b7f3f83 3786//=======================================================================
ecf4f17c 3787void UpdateHistory(const TopTools_ListOfShape& theLF,
3788 BOPAlgo_Builder& theGF,
3789 BRepAlgo_Image& theImage)
9b7f3f83 3790{
ecf4f17c 3791 TopTools_ListIteratorOfListOfShape aIt(theLF);
3792 for (; aIt.More(); aIt.Next()) {
3793 const TopoDS_Shape& aF = aIt.Value();
3794 const TopTools_ListOfShape& aLFIm = theGF.Modified(aF);
3795 if (aLFIm.Extent()) {
3796 if (theImage.HasImage(aF)) {
3797 theImage.Add(aF, aLFIm);
9b7f3f83 3798 }
3799 else {
ecf4f17c 3800 theImage.Bind(aF, aLFIm);
9b7f3f83 3801 }
3802 }
9b7f3f83 3803 }
3804}
3805
3806//=======================================================================
ecf4f17c 3807//function : IntersectEdges
9b7f3f83 3808//purpose :
3809//=======================================================================
ecf4f17c 3810void BRepOffset_MakeOffset::IntersectEdges(const TopoDS_Shape& theShape,
3811 BRepOffset_DataMapOfShapeOffset& theMapSF,
3812 TopTools_DataMapOfShapeShape& theMES,
3813 TopTools_DataMapOfShapeShape& theBuild,
3814 Handle(BRepAlgo_AsDes)& theAsDes,
3815 Handle(BRepAlgo_AsDes)& theAsDes2d)
9b7f3f83 3816{
ecf4f17c 3817 Standard_Real aTolF;
3818 TopTools_IndexedDataMapOfShapeListOfShape aDMVV;
3819 TopExp_Explorer aExp(theShape, TopAbs_FACE);
3820 // intersect edges created from edges
3821 TopTools_IndexedMapOfShape aMFV;
9b7f3f83 3822 for (; aExp.More(); aExp.Next()) {
ecf4f17c 3823 const TopoDS_Face& aF = TopoDS::Face(aExp.Current());
3824 aTolF = BRep_Tool::Tolerance(aF);
3825 BRepOffset_Inter2d::ConnexIntByInt
3826 (aF, theMapSF(aF), theMES, theBuild, theAsDes2d, myOffset, aTolF, aMFV, aDMVV);
9b7f3f83 3827 }
ecf4f17c 3828 // intersect edges created from vertices
3829 Standard_Integer i, aNbF = aMFV.Extent();
3830 for (i = 1; i <= aNbF; ++i) {
3831 const TopoDS_Face& aF = TopoDS::Face(aMFV(i));
3832 aTolF = BRep_Tool::Tolerance(aF);
3833 BRepOffset_Inter2d::ConnexIntByIntInVert
3834 (aF, theMapSF(aF), theMES, theBuild, theAsDes, theAsDes2d, aTolF, aDMVV);
3835 }
3836 //
3837 // fuse vertices on edges
3838 BRepOffset_Inter2d::FuseVertices(aDMVV, theAsDes2d);
9b7f3f83 3839}
3840
3841//=======================================================================
ecf4f17c 3842//function : TrimEdges
9b7f3f83 3843//purpose :
3844//=======================================================================
ecf4f17c 3845void TrimEdges(const TopoDS_Shape& theShape,
3846 const Standard_Real theOffset,
3847 BRepOffset_DataMapOfShapeOffset& theMapSF,
3848 TopTools_DataMapOfShapeShape& theMES,
3849 TopTools_DataMapOfShapeShape& theBuild,
3850 Handle(BRepAlgo_AsDes)& theAsDes,
3851 Handle(BRepAlgo_AsDes)& theAsDes2d,
3852 TopTools_IndexedMapOfShape& theNewEdges,
3853 TopTools_DataMapOfShapeShape& theETrimEInf,
3854 TopTools_DataMapOfShapeListOfShape& theEdgesOrigins)
9b7f3f83 3855{
ecf4f17c 3856 TopExp_Explorer Exp,Exp2,ExpC;
3857 TopoDS_Shape NE;
3858 TopoDS_Edge TNE;
3859 TopoDS_Face NF;
9b7f3f83 3860 //
ecf4f17c 3861 for (Exp.Init(theShape,TopAbs_FACE) ; Exp.More(); Exp.Next()) {
3862 const TopoDS_Face& FI = TopoDS::Face(Exp.Current());
3863 NF = theMapSF(FI).Face();
3864 if (theMES.IsBound(NF)) {
3865 NF = TopoDS::Face(theMES(NF));
9b7f3f83 3866 }
3867 //
ecf4f17c 3868 TopTools_MapOfShape View;
3869 TopTools_IndexedMapOfShape VEmap;
3870 Standard_Integer i, aNb;
9b7f3f83 3871 //
ecf4f17c 3872 TopExp::MapShapes(FI.Oriented(TopAbs_FORWARD), TopAbs_EDGE , VEmap);
3873 TopExp::MapShapes(FI.Oriented(TopAbs_FORWARD), TopAbs_VERTEX, VEmap);
3874 //
3875 aNb = VEmap.Extent();
3876 for (i = 1; i <= aNb; ++i) {
3877 const TopoDS_Shape& aS = VEmap(i);
3878 if (!View.Add(aS)) {
9b7f3f83 3879 continue;
3880 }
3881 //
ecf4f17c 3882 if (theBuild.IsBound(aS)) {
3883 NE = theBuild(aS);
3884 // keep connection to original edges
3885 ExpC.Init(NE, TopAbs_EDGE);
3886 for (; ExpC.More(); ExpC.Next()) {
3887 const TopoDS_Edge& NEC = TopoDS::Edge(ExpC.Current());
3888 TopTools_ListOfShape* pLEOr = theEdgesOrigins.ChangeSeek(NEC);
3889 if (!pLEOr) {
3890 pLEOr = theEdgesOrigins.Bound(NEC, TopTools_ListOfShape());
3891 }
3892 AppendToList(*pLEOr, aS);
9b7f3f83 3893 }
ecf4f17c 3894 // trim edges
3895 if (NE.ShapeType() == TopAbs_EDGE) {
3896 if (theNewEdges.Add(NE)) {
3897 TrimEdge (TopoDS::Edge(NE),theAsDes2d,theAsDes, theETrimEInf);
3898 }
3899 }
3900 else {
3901 //------------------------------------------------------------
3902 // The Intersections are on several edges.
3903 // The pieces without intersections with neighbors
3904 // are removed from AsDes.
3905 //------------------------------------------------------------
3906 for (ExpC.Init(NE,TopAbs_EDGE); ExpC.More(); ExpC.Next()) {
3907 TopoDS_Edge NEC = TopoDS::Edge(ExpC.Current());
3908 if (theNewEdges.Add(NEC)) {
3909 if (!theAsDes2d->Descendant(NEC).IsEmpty()) {
3910 TrimEdge (NEC,theAsDes2d, theAsDes, theETrimEInf);
3911 }
3912 else {
3913 if (theAsDes->HasAscendant(NEC)) {
3914 theAsDes->Remove(NEC);
3915 }
3916 }
3917 }
3918 }
9b7f3f83 3919 }
3920 }
ecf4f17c 3921 else {
3922 if (aS.ShapeType() != TopAbs_EDGE) {
3923 continue;
3924 }
3925 //
3926 NE = theMapSF(FI).Generated(aS);
3927 //// modified by jgv, 19.12.03 for OCC4455 ////
3928 NE.Orientation(aS.Orientation());
3929 //
3930 TopTools_ListOfShape* pLEOr = theEdgesOrigins.ChangeSeek(NE);
3931 if (!pLEOr) {
3932 pLEOr = theEdgesOrigins.Bound(NE, TopTools_ListOfShape());
3933 }
3934 AppendToList(*pLEOr, aS);
3935 //
3936 if (theMES.IsBound(NE)) {
3937 NE = theMES(NE);
3938 NE.Orientation(aS.Orientation());
3939 if (theNewEdges.Add(NE)) {
3940 TrimEdge (TopoDS::Edge(NE), theAsDes2d, theAsDes, theETrimEInf);
3941 }
3942 }
3943 else {
3944 TopoDS_Edge& anEdge = TopoDS::Edge(NE);
3945 BRepAdaptor_Curve aBAC(anEdge);
3946 if (aBAC.GetType() == GeomAbs_Line) {
3947 TopoDS_Edge aNewEdge;
3948 BRepOffset_Inter2d::ExtentEdge(anEdge, aNewEdge, theOffset);
3949 theETrimEInf.Bind(anEdge, aNewEdge);
3950 }
3951 }
3952 theAsDes->Add(NF,NE);
3953 }
9b7f3f83 3954 }
3955 }
3956}
3957
3958//=======================================================================
ecf4f17c 3959//function : TrimEdge
3960//purpose : Trim the edge of the largest of descendants in AsDes2d.
3961// Order in AsDes two vertices that have trimmed the edge.
9b7f3f83 3962//=======================================================================
ecf4f17c 3963void TrimEdge(TopoDS_Edge& NE,
3964 const Handle(BRepAlgo_AsDes)& AsDes2d,
3965 Handle(BRepAlgo_AsDes)& AsDes,
3966 TopTools_DataMapOfShapeShape& theETrimEInf)
9b7f3f83 3967{
ecf4f17c 3968 TopoDS_Edge aSourceEdge;
3969 TopoDS_Vertex V1,V2;
3970 Standard_Real aT1, aT2;
9b7f3f83 3971 //
ecf4f17c 3972 TopExp::Vertices(NE, V1, V2);
3973 BRep_Tool::Range(NE, aT1, aT2);
3974 //
3975 BOPTools_AlgoTools::MakeSplitEdge(NE, V1, aT1, V2, aT2, aSourceEdge);
3976 //
3977 //
3978 Standard_Real aSameParTol = Precision::Confusion();
3979
3980 Standard_Real U = 0.;
3981 Standard_Real UMin = Precision::Infinite();
3982 Standard_Real UMax = -UMin;
3983
3984 const TopTools_ListOfShape& LE = AsDes2d->Descendant(NE);
3985 //
3986 Standard_Boolean bTrim = Standard_False;
3987 //
3988 if (LE.Extent() > 1) {
3989 TopTools_ListIteratorOfListOfShape it (LE);
3990 for (; it.More(); it.Next()) {
3991 TopoDS_Vertex V = TopoDS::Vertex(it.Value());
3992 if (NE.Orientation() == TopAbs_REVERSED)
3993 V.Reverse();
3994 //V.Orientation(TopAbs_INTERNAL);
3995 if (!FindParameter(V, NE, U)) {
3996 Standard_Real f, l;
3997 Handle(Geom_Curve) theCurve = BRep_Tool::Curve(NE, f, l);
3998 gp_Pnt thePoint = BRep_Tool::Pnt(V);
3999 GeomAPI_ProjectPointOnCurve Projector(thePoint, theCurve);
4000 if (Projector.NbPoints() == 0)
9775fa61 4001 throw Standard_ConstructionError("BRepOffset_MakeOffset::TrimEdge no projection");
ecf4f17c 4002 U = Projector.LowerDistanceParameter();
4003 }
4004 if (U < UMin) {
4005 UMin = U; V1 = V;
4006 }
4007 if (U > UMax) {
4008 UMax = U; V2 = V;
4009 }
4010 }
4011 //
4012 if (V1.IsNull() || V2.IsNull()) {
9775fa61 4013 throw Standard_ConstructionError("BRepOffset_MakeOffset::TrimEdge");
ecf4f17c 4014 }
4015 if (!V1.IsSame(V2)) {
4016 NE.Free( Standard_True );
4017 BRep_Builder B;
4018 TopAbs_Orientation Or = NE.Orientation();
4019 NE.Orientation(TopAbs_FORWARD);
4020 TopoDS_Vertex VF,VL;
4021 TopExp::Vertices (NE,VF,VL);
4022 B.Remove(NE,VF);
4023 B.Remove(NE,VL);
4024 B.Add (NE,V1.Oriented(TopAbs_FORWARD));
4025 B.Add (NE,V2.Oriented(TopAbs_REVERSED));
4026 B.Range(NE,UMin,UMax);
4027 NE.Orientation(Or);
4028 AsDes->Add(NE,V1.Oriented(TopAbs_FORWARD));
4029 AsDes->Add(NE,V2.Oriented(TopAbs_REVERSED));
4030 BRepLib::SameParameter(NE, aSameParTol, Standard_True);
9b7f3f83 4031 //
ecf4f17c 4032 bTrim = Standard_True;
9b7f3f83 4033 }
4034 }
4035 //
ecf4f17c 4036 if (!bTrim) {
4037 BRepAdaptor_Curve aBAC(NE);
4038 if (aBAC.GetType() == GeomAbs_Line) {
4039 if (AsDes->HasAscendant(NE)) {
4040 AsDes->Remove(NE);
4041 }
4042 }
4043 }
4044 else
4045 {
4046 if (!theETrimEInf.IsBound(NE)) {
4047 theETrimEInf.Bind(NE, aSourceEdge);
4048 }
4049 }
9b7f3f83 4050}
4051
4052//=======================================================================
ecf4f17c 4053//function : GetEnlargedFaces
9b7f3f83 4054//purpose :
4055//=======================================================================
ecf4f17c 4056void GetEnlargedFaces(const TopoDS_Shape& theShape,
4057 const BRepOffset_DataMapOfShapeOffset& theMapSF,
4058 const TopTools_DataMapOfShapeShape& theMES,
4059 TopTools_DataMapOfShapeShape& theFacesOrigins,
4060 BRepAlgo_Image& theImage,
4061 TopTools_ListOfShape& theLSF)
9b7f3f83 4062{
ecf4f17c 4063 TopExp_Explorer aExp(theShape, TopAbs_FACE);
4064 for (; aExp.More(); aExp.Next()) {
4065 const TopoDS_Shape& FI = aExp.Current();
4066 const TopoDS_Shape& OFI = theMapSF(FI).Face();
4067 if (theMES.IsBound(OFI)) {
4068 const TopoDS_Face& aLocalFace = TopoDS::Face(theMES(OFI));
4069 theLSF.Append(aLocalFace);
4070 theImage.SetRoot(aLocalFace);
4071 //
4072 theFacesOrigins.Bind(aLocalFace, FI);
4073 }
4074 }
4075}
4076
4077//=======================================================================
4078//function : BuildShellsCompleteInter
4079//purpose : Make the shells from list of faces using MakerVolume algorithm.
4080// In case there will be more than just one solid, it will be
4081// rebuilt using only outer faces.
4082//=======================================================================
4083Standard_Boolean BuildShellsCompleteInter(const BOPCol_ListOfShape& theLF,
ecf4f17c 4084 BRepAlgo_Image& theImage,
4085 TopoDS_Shape& theShells)
4086{
4087 // make solids
4088 BOPAlgo_MakerVolume aMV1;
4089 aMV1.SetArguments(theLF);
4090 // we need to intersect the faces to process the tangential faces
4091 aMV1.SetIntersect(Standard_True);
291fced1 4092 aMV1.SetAvoidInternalShapes(Standard_True);
ecf4f17c 4093 aMV1.Perform();
9b7f3f83 4094 //
33ba8565 4095 Standard_Boolean bDone = ! aMV1.HasErrors();
ecf4f17c 4096 if (!bDone) {
9b7f3f83 4097 return bDone;
4098 }
4099 //
ecf4f17c 4100 UpdateHistory(theLF, aMV1, theImage);
9b7f3f83 4101 //
ecf4f17c 4102 const TopoDS_Shape& aResult1 = aMV1.Shape();
4103 if (aResult1.ShapeType() == TopAbs_SOLID) {
4104 // result is the alone solid, nothing to do
4105 return GetSubShapes(aResult1, TopAbs_SHELL, theShells);
4106 }
e7384fd4 4107
4108 // Allocators for effective memory allocations
4109 // Global allocator for the long-living containers
4110 Handle(NCollection_IncAllocator) anAllocGlob = new NCollection_IncAllocator;
4111 // Local allocator for the local containers
4112 Handle(NCollection_IncAllocator) anAllocLoc = new NCollection_IncAllocator;
4113
4114 // Since the <theImage> object does not support multiple ancestors,
4115 // prepare local copy of the origins, which will be used to resolve
4116 // non-manifold solids produced by Maker Volume algorithm by comparison
4117 // of the normal directions of the split faces with their origins.
4118 TopTools_DataMapOfShapeListOfShape anOrigins(1, anAllocGlob);
4119 TopTools_ListIteratorOfListOfShape aItLR(theImage.Roots());
4120 for (; aItLR.More(); aItLR.Next())
4121 {
4122 const TopoDS_Shape& aFR = aItLR.Value();
4123
4124 // Reset the local allocator
4125 anAllocLoc->Reset();
4126 // Find the last splits of the root face, including the ones
4127 // created during MakeVolume operation
4128 TopTools_ListOfShape aLFIm(anAllocLoc);
4129 theImage.LastImage(aFR, aLFIm);
4130
4131 TopTools_ListIteratorOfListOfShape aItLFIm(aLFIm);
4132 for (; aItLFIm.More(); aItLFIm.Next())
4133 {
4134 const TopoDS_Shape& aFIm = aItLFIm.Value();
4135 TopTools_ListOfShape *pLFOr = anOrigins.ChangeSeek(aFIm);
4136 if (!pLFOr) {
4137 pLFOr = anOrigins.Bound(aFIm, TopTools_ListOfShape(anAllocGlob));
4138 }
4139 pLFOr->Append(aFR);
4140 }
4141 }
4142
4143 // Reset the local allocator
4144 anAllocLoc->Reset();
4145 // It is necessary to rebuild the solids, avoiding internal faces
4146 // Map faces to solids
4147 TopTools_IndexedDataMapOfShapeListOfShape aDMFS(1, anAllocLoc);
ecf4f17c 4148 TopExp::MapShapesAndAncestors(aResult1, TopAbs_FACE, TopAbs_SOLID, aDMFS);
9b7f3f83 4149 //
ecf4f17c 4150 Standard_Integer i, aNb = aDMFS.Extent();
4151 bDone = (aNb > 0);
4152 if (!bDone) {
4153 // unable to build any solid
4154 return bDone;
4155 }
9b7f3f83 4156 //
ecf4f17c 4157 // get faces attached to only one solid
e7384fd4 4158 BOPCol_ListOfShape aLF(anAllocLoc);
ecf4f17c 4159 for (i = 1; i <= aNb; ++i) {
4160 const TopTools_ListOfShape& aLS = aDMFS(i);
4161 if (aLS.Extent() == 1) {
4162 const TopoDS_Shape& aF = aDMFS.FindKey(i);
e7384fd4 4163 aLF.Append(aF);
9b7f3f83 4164 }
4165 }
4166 //
ecf4f17c 4167 // make solids from the new list
4168 BOPAlgo_MakerVolume aMV2;
e7384fd4 4169 aMV2.SetArguments(aLF);
ecf4f17c 4170 // no need to intersect this time
4171 aMV2.SetIntersect(Standard_False);
291fced1 4172 aMV2.SetAvoidInternalShapes(Standard_True);
ecf4f17c 4173 aMV2.Perform();
33ba8565 4174 bDone = ! aMV2.HasErrors();
ecf4f17c 4175 if (!bDone) {
4176 return bDone;
9b7f3f83 4177 }
4178 //
ecf4f17c 4179 const TopoDS_Shape& aResult2 = aMV2.Shape();
4180 if (aResult2.ShapeType() == TopAbs_SOLID) {
4181 return GetSubShapes(aResult2, TopAbs_SHELL, theShells);
9b7f3f83 4182 }
4183 //
ecf4f17c 4184 TopExp_Explorer aExp(aResult2, TopAbs_FACE);
4185 bDone = aExp.More();
4186 if (!bDone) {
4187 return bDone;
9b7f3f83 4188 }
4189 //
e7384fd4 4190 aLF.Clear();
4191 aDMFS.Clear();
4192 anAllocLoc->Reset();
4193
4194 // the result is non-manifold - resolve it comparing normal
ecf4f17c 4195 // directions of the offset faces and original faces
e7384fd4 4196 for (; aExp.More(); aExp.Next())
4197 {
ecf4f17c 4198 const TopoDS_Face& aF = TopoDS::Face(aExp.Current());
e7384fd4 4199 const TopTools_ListOfShape* pLFOr = anOrigins.Seek(aF);
4200 if (!pLFOr)
4201 {
4202 Standard_ASSERT_INVOKE("BRepOffset_MakeOffset::BuildShellsCompleteInterSplit(): "
4203 "Origins map does not contain the split face");
ecf4f17c 4204 continue;
4205 }
e7384fd4 4206 // Check orientation
4207 TopTools_ListIteratorOfListOfShape aItLOr(*pLFOr);
4208 for (; aItLOr.More(); aItLOr.Next())
4209 {
4210 const TopoDS_Face& aFOr = TopoDS::Face(aItLOr.Value());
4211 if (BRepOffset_Tool::CheckPlanesNormals(aF, aFOr))
4212 {
4213 aLF.Append(aF);
9b7f3f83 4214 break;
4215 }
4216 }
4217 }
4218 //
ecf4f17c 4219 // make solid from most outer faces with correct normal direction
4220 BOPAlgo_MakerVolume aMV3;
e7384fd4 4221 aMV3.SetArguments(aLF);
ecf4f17c 4222 aMV3.SetIntersect(Standard_False);
291fced1 4223 aMV3.SetAvoidInternalShapes(Standard_True);
ecf4f17c 4224 aMV3.Perform();
33ba8565 4225 bDone = ! aMV3.HasErrors();
ecf4f17c 4226 if (!bDone) {
4227 return bDone;
4228 }
4229 //
4230 const TopoDS_Shape& aResult3 = aMV3.Shape();
4231 return GetSubShapes(aResult3, TopAbs_SHELL, theShells);
9b7f3f83 4232}
4233
4234//=======================================================================
ecf4f17c 4235//function : GetSubShapes
9b7f3f83 4236//purpose :
4237//=======================================================================
ecf4f17c 4238Standard_Boolean GetSubShapes(const TopoDS_Shape& theShape,
4239 const TopAbs_ShapeEnum theSSType,
4240 TopoDS_Shape& theResult)
9b7f3f83 4241{
ecf4f17c 4242 TopExp_Explorer aExp(theShape, theSSType);
4243 if (!aExp.More()) {
4244 return Standard_False;
9b7f3f83 4245 }
4246 //
ecf4f17c 4247 TopoDS_Compound aResult;
4248 BRep_Builder().MakeCompound(aResult);
9b7f3f83 4249 //
ecf4f17c 4250 for (; aExp.More(); aExp.Next()) {
4251 const TopoDS_Shape& aSS = aExp.Current();
4252 BRep_Builder().Add(aResult, aSS);
9b7f3f83 4253 }
ecf4f17c 4254 theResult = aResult;
4255 return Standard_True;
9b7f3f83 4256}
4257
ecf4f17c 4258//=======================================================================
4259//function : IsPlanar
4260//purpose : Checks if all the faces of the shape are planes
4261//=======================================================================
4262Standard_Boolean IsPlanar(const TopoDS_Shape& theS)
4263{
4264 TopExp_Explorer aExp(theS, TopAbs_FACE);
4265 for (; aExp.More(); aExp.Next()) {
4266 const TopoDS_Face& aF = *(TopoDS_Face*)&aExp.Current();
4267 BRepAdaptor_Surface aBAS(aF, Standard_False);
4268 if (aBAS.GetType() != GeomAbs_Plane) {
4269 break;
4270 }
4271 }
4272 return !aExp.More();
4273}
4274
9b7f3f83 4275//=======================================================================
4276//function : IsSolid
ecf4f17c 4277//purpose : Checks if the shape is solid
9b7f3f83 4278//=======================================================================
4279Standard_Boolean IsSolid(const TopoDS_Shape& theS)
4280{
4281 TopExp_Explorer aExp(theS, TopAbs_SOLID);
4282 return aExp.More();
4283}
ecf4f17c 4284
9b7f3f83 4285//=======================================================================
ecf4f17c 4286//function : AppendToList
4287//purpose : Add to a list only unique elements
9b7f3f83 4288//=======================================================================
ecf4f17c 4289void AppendToList(TopTools_ListOfShape& theList,
4290 const TopoDS_Shape& theShape)
9b7f3f83 4291{
ecf4f17c 4292 TopTools_ListIteratorOfListOfShape aIt(theList);
9b7f3f83 4293 for (; aIt.More(); aIt.Next()) {
ecf4f17c 4294 const TopoDS_Shape& aS = aIt.Value();
4295 if (aS.IsSame(theShape)) {
4296 return;
9b7f3f83 4297 }
4298 }
ecf4f17c 4299 theList.Append(theShape);
9b7f3f83 4300}