Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1996-12-16 |
2 | // Created by: Bruno DUMORTIER | |
3 | // Copyright (c) 1996-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 | |
7fd59977 | 17 | |
42cf5bc1 | 18 | #include <AppCont_Function.hxx> |
19 | #include <AppParCurves_MultiCurve.hxx> | |
20 | #include <Approx_FitAndDivide.hxx> | |
21 | #include <BiTgte_Blend.hxx> | |
7fd59977 | 22 | #include <BiTgte_CurveOnEdge.hxx> |
7fd59977 | 23 | #include <Bnd_Box.hxx> |
42cf5bc1 | 24 | #include <BRep_Builder.hxx> |
25 | #include <BRep_Tool.hxx> | |
26 | #include <BRepAlgo_AsDes.hxx> | |
27 | #include <BRepAlgo_Loop.hxx> | |
7fd59977 | 28 | #include <BRepBndLib.hxx> |
7fd59977 | 29 | #include <BRepBuilderAPI_Sewing.hxx> |
42cf5bc1 | 30 | #include <BRepLib.hxx> |
7fd59977 | 31 | #include <BRepLib_MakeEdge.hxx> |
7fd59977 | 32 | #include <BRepOffset_DataMapIteratorOfDataMapOfShapeOffset.hxx> |
42cf5bc1 | 33 | #include <BRepOffset_DataMapOfShapeOffset.hxx> |
7fd59977 | 34 | #include <BRepOffset_Inter2d.hxx> |
42cf5bc1 | 35 | #include <BRepOffset_Inter3d.hxx> |
7fd59977 | 36 | #include <BRepOffset_Interval.hxx> |
37 | #include <BRepOffset_ListOfInterval.hxx> | |
42cf5bc1 | 38 | #include <BRepOffset_MakeLoops.hxx> |
39 | #include <BRepOffset_Offset.hxx> | |
7fd59977 | 40 | #include <BRepOffset_Tool.hxx> |
42cf5bc1 | 41 | #include <BRepTools.hxx> |
42 | #include <BRepTools_Quilt.hxx> | |
43 | #include <BSplCLib.hxx> | |
7fd59977 | 44 | #include <ChFi3d.hxx> |
42cf5bc1 | 45 | #include <Convert_CompBezierCurvesToBSplineCurve.hxx> |
46 | #include <ElSLib.hxx> | |
47 | #include <Geom2d_Curve.hxx> | |
48 | #include <Geom2dAdaptor_Curve.hxx> | |
49 | #include <Geom2dAPI_ProjectPointOnCurve.hxx> | |
7fd59977 | 50 | #include <Geom_BSplineCurve.hxx> |
7fd59977 | 51 | #include <Geom_Circle.hxx> |
42cf5bc1 | 52 | #include <Geom_Curve.hxx> |
7fd59977 | 53 | #include <Geom_Line.hxx> |
42cf5bc1 | 54 | #include <Geom_Surface.hxx> |
55 | #include <Geom_TrimmedCurve.hxx> | |
56 | #include <GeomAbs_SurfaceType.hxx> | |
7fd59977 | 57 | #include <GeomAdaptor_Surface.hxx> |
42cf5bc1 | 58 | #include <GeomAPI.hxx> |
59 | #include <GeomAPI_ProjectPointOnCurve.hxx> | |
7fd59977 | 60 | #include <gp.hxx> |
7fd59977 | 61 | #include <gp_Ax1.hxx> |
62 | #include <gp_Ax3.hxx> | |
63 | #include <gp_Circ.hxx> | |
42cf5bc1 | 64 | #include <gp_Dir.hxx> |
65 | #include <gp_Dir2d.hxx> | |
66 | #include <gp_Lin.hxx> | |
67 | #include <gp_Lin2d.hxx> | |
68 | #include <gp_Pnt.hxx> | |
69 | #include <gp_Pnt2d.hxx> | |
7fd59977 | 70 | #include <gp_Sphere.hxx> |
7fd59977 | 71 | #include <Precision.hxx> |
42cf5bc1 | 72 | #include <Standard_NotImplemented.hxx> |
73 | #include <Standard_OutOfRange.hxx> | |
74 | #include <StdFail_NotDone.hxx> | |
7fd59977 | 75 | #include <TColgp_Array1OfPnt.hxx> |
7fd59977 | 76 | #include <TColStd_Array1OfInteger.hxx> |
42cf5bc1 | 77 | #include <TColStd_Array1OfReal.hxx> |
7fd59977 | 78 | #include <TopExp.hxx> |
42cf5bc1 | 79 | #include <TopExp_Explorer.hxx> |
80 | #include <TopoDS.hxx> | |
81 | #include <TopoDS_Compound.hxx> | |
82 | #include <TopoDS_Edge.hxx> | |
83 | #include <TopoDS_Face.hxx> | |
84 | #include <TopoDS_Shape.hxx> | |
85 | #include <TopoDS_Vertex.hxx> | |
86 | #include <TopoDS_Wire.hxx> | |
87 | #include <TopTools_DataMapOfShapeShape.hxx> | |
88 | #include <TopTools_ListIteratorOfListOfShape.hxx> | |
89 | #include <TopTools_ListOfShape.hxx> | |
90 | #include <TopTools_MapIteratorOfMapOfShape.hxx> | |
91 | #include <TopTools_SequenceOfShape.hxx> | |
7fd59977 | 92 | |
742cc8b0 | 93 | #ifdef OCCT_DEBUG |
94 | #include <OSD_Chronometer.hxx> | |
95 | #endif | |
96 | ||
42cf5bc1 | 97 | #include <stdio.h> |
98 | // include - all hxx, | |
99 | // - all small static functions. | |
100 | //======================== START STATIC FUNCTIONS ============ | |
0d969553 | 101 | // variables for performance |
7fd59977 | 102 | Standard_Real t_mkcurve; |
742cc8b0 | 103 | #ifdef OCCT_DEBUG |
1d0a9d4d | 104 | extern void ChFi3d_InitChron(OSD_Chronometer& ch); |
105 | extern void ChFi3d_ResultChron(OSD_Chronometer & ch, Standard_Real& time); | |
742cc8b0 | 106 | #endif |
7fd59977 | 107 | #ifdef DRAW |
108 | static Standard_Boolean Affich = Standard_False; | |
109 | static char name[100]; | |
110 | #include <DBRep.hxx> | |
111 | #endif | |
112 | ||
113 | //======================================================================= | |
114 | //function : IsOnRestriction | |
115 | //purpose : | |
116 | //======================================================================= | |
117 | ||
118 | static Standard_Boolean IsOnRestriction(const TopoDS_Vertex& V, | |
119 | const TopoDS_Edge& CurE, | |
120 | const TopoDS_Face& F, | |
121 | TopoDS_Edge& E) | |
122 | { | |
0d969553 Y |
123 | // find if Vertex V of CurE is on a restriction of F. |
124 | // if yes, store this restriction in E. | |
7fd59977 | 125 | |
126 | // dub - 03 01 97 | |
0d969553 Y |
127 | // Method somewhat brutal : possible to really optimize by a |
128 | // direct call the SD of intersections -> See LBR | |
7fd59977 | 129 | |
130 | Standard_Real f,l; | |
131 | Handle(Geom2d_Curve) CurC = BRep_Tool::CurveOnSurface(CurE,F,f,l); | |
132 | Standard_Real U = BRep_Tool::Parameter(V,CurE,F); | |
133 | gp_Pnt2d P = CurC->Value(U); | |
134 | ||
135 | Geom2dAPI_ProjectPointOnCurve Proj; | |
136 | ||
0d969553 Y |
137 | // The tolerance is exaggerated : it is better to construct too many |
138 | // tubes than to miss intersections. | |
7fd59977 | 139 | // Standard_Real Tol = 100 * BRep_Tool::Tolerance(V); |
140 | Standard_Real Tol = BRep_Tool::Tolerance(V); | |
141 | TopExp_Explorer exp(F,TopAbs_EDGE); | |
142 | for ( ; exp.More(); exp.Next()) { | |
143 | E = TopoDS::Edge(exp.Current()); | |
144 | Handle(Geom2d_Curve) PC = BRep_Tool::CurveOnSurface(E,F,f,l); | |
145 | Proj.Init(P,PC,f,l); | |
146 | if ( Proj.NbPoints() > 0) { | |
147 | if (Proj.LowerDistance() < Tol) { | |
148 | return Standard_True; | |
149 | } | |
150 | } | |
151 | } | |
152 | return Standard_False; | |
153 | } | |
154 | ||
155 | //======================================================================= | |
156 | //function : Add | |
157 | //purpose : | |
158 | //======================================================================= | |
159 | ||
160 | static void Add(const TopoDS_Edge& E, | |
975ec82a | 161 | TopTools_IndexedMapOfShape& Map, |
7fd59977 | 162 | const TopoDS_Shape& S, |
163 | const BRepOffset_Offset& OF, | |
164 | const BRepOffset_Analyse& Analyse, | |
165 | const Standard_Boolean WarningSurBordLibre) | |
0d969553 | 166 | // If WarningSurBordLibre = TRUE, no propagation if the edge is open. |
7fd59977 | 167 | { |
168 | TopAbs_ShapeEnum Type = S.ShapeType(); | |
169 | ||
170 | if ( Type == TopAbs_FACE) { | |
171 | TopExp_Explorer exp(S,TopAbs_EDGE); | |
172 | for ( ; exp.More(); exp.Next()) { | |
173 | const TopoDS_Edge& OriE = TopoDS::Edge(exp.Current()); | |
174 | TopoDS_Shape aLocalShape = OF.Generated(OriE); | |
175 | const TopoDS_Edge& IE = TopoDS::Edge(aLocalShape); | |
176 | // const TopoDS_Edge& IE = TopoDS::Edge(OF.Generated(OriE)); | |
177 | if ( E.IsEqual(IE)) { | |
178 | if (WarningSurBordLibre) { | |
0d969553 | 179 | // It is checked that the border is not free. |
7fd59977 | 180 | const TopTools_ListOfShape& L = Analyse.Ancestors(OriE); |
0d969553 | 181 | if (L.Extent() == 1) break; // Nothing is done. |
7fd59977 | 182 | } |
183 | Map.Add(exp.Current()); | |
184 | break; | |
185 | } | |
186 | } | |
187 | } | |
188 | else if ( Type == TopAbs_EDGE) { | |
189 | TopExp_Explorer exp(S,TopAbs_VERTEX); | |
190 | for ( ; exp.More(); exp.Next()) { | |
191 | TopoDS_Shape aLocalShape = OF.Generated(exp.Current()); | |
192 | const TopoDS_Edge& IE = TopoDS::Edge(aLocalShape); | |
193 | // const TopoDS_Edge& IE = TopoDS::Edge(OF.Generated(exp.Current())); | |
194 | if ( E.IsEqual(IE)) { | |
195 | const TopTools_ListOfShape& L = Analyse.Ancestors(exp.Current()); | |
196 | TopTools_ListIteratorOfListOfShape it(L); | |
197 | for ( ; it.More(); it.Next()) { | |
198 | Map.Add(it.Value()); | |
199 | } | |
200 | break; | |
201 | } | |
202 | } | |
203 | } | |
204 | } | |
205 | ||
206 | ||
207 | //======================================================================= | |
208 | //function : IsInFace | |
209 | //purpose : | |
210 | //======================================================================= | |
211 | ||
212 | static Standard_Boolean IsInFace(const TopoDS_Edge& E, | |
213 | const TopoDS_Face& F) | |
214 | { | |
215 | TopExp_Explorer exp(F,TopAbs_EDGE); | |
216 | for ( ;exp.More(); exp.Next()) | |
217 | if ( E.IsSame(exp.Current())) return Standard_True; | |
218 | return Standard_False; | |
219 | } | |
220 | ||
221 | ||
222 | //======================================================================= | |
223 | //function : KPartCurve3d | |
224 | //purpose : | |
225 | //======================================================================= | |
226 | ||
227 | static void KPartCurve3d(TopoDS_Edge Edge, | |
228 | Handle(Geom2d_Curve) Curve, | |
229 | Handle(Geom_Surface) Surf) | |
230 | { | |
231 | // try to find the particular case | |
232 | // if not found call BRepLib::BuildCurve3d | |
233 | ||
234 | TopLoc_Location Loc; | |
235 | Standard_Real Tol = Precision::Confusion(); | |
236 | ||
0d969553 | 237 | // Seach only isos on analytical surfaces. |
7fd59977 | 238 | Geom2dAdaptor_Curve C(Curve); |
239 | GeomAdaptor_Surface S(Surf); | |
240 | GeomAbs_CurveType CTy = C.GetType(); | |
241 | GeomAbs_SurfaceType STy = S.GetType(); | |
242 | BRep_Builder TheBuilder; | |
243 | ||
0d969553 | 244 | if ( STy != GeomAbs_Plane) { // if plane buildcurve3d manage KPart |
7fd59977 | 245 | if ( CTy == GeomAbs_Line) { |
246 | gp_Dir2d D = C.Line().Direction(); | |
247 | if ( D.IsParallel(gp::DX2d(),Precision::Angular())) { // Iso V. | |
248 | if ( STy == GeomAbs_Sphere) { | |
249 | gp_Pnt2d P = C.Line().Location(); | |
c6541a0c | 250 | if ( Abs( Abs(P.Y()) -M_PI/2. ) < Precision::PConfusion()) { |
7fd59977 | 251 | TheBuilder.Degenerated(Edge, Standard_True); |
252 | } | |
253 | else { | |
254 | gp_Sphere Sph = S.Sphere(); | |
255 | gp_Ax3 Axis = Sph.Position(); | |
256 | gp_Circ Ci = ElSLib::SphereVIso(Axis, | |
257 | Sph.Radius(), | |
258 | P.Y()); | |
259 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
260 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
261 | Ci.Rotate(AxeRev, P.X()); | |
262 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
263 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
264 | Circle->Reverse(); | |
265 | TheBuilder.UpdateEdge(Edge, Circle, Loc, Tol); | |
266 | } | |
7fd59977 | 267 | } |
268 | else if ( STy == GeomAbs_Cylinder) { | |
269 | gp_Cylinder Cyl = S.Cylinder(); | |
270 | gp_Pnt2d P = C.Line().Location(); | |
271 | gp_Ax3 Axis = Cyl.Position(); | |
272 | gp_Circ Ci = ElSLib::CylinderVIso(Axis, | |
273 | Cyl.Radius(), | |
274 | P.Y()); | |
275 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
276 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
277 | Ci.Rotate(AxeRev, P.X()); | |
278 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
279 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
280 | Circle->Reverse(); | |
281 | TheBuilder.UpdateEdge(Edge, Circle, Loc, Tol); | |
7fd59977 | 282 | } |
283 | else if ( STy == GeomAbs_Cone) { | |
284 | gp_Cone Cone = S.Cone(); | |
285 | gp_Pnt2d P = C.Line().Location(); | |
286 | gp_Ax3 Axis = Cone.Position(); | |
287 | gp_Circ Ci = ElSLib::ConeVIso(Axis, | |
288 | Cone.RefRadius(), | |
289 | Cone.SemiAngle(), | |
290 | P.Y()); | |
291 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
292 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
293 | Ci.Rotate(AxeRev, P.X()); | |
294 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
295 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
296 | Circle->Reverse(); | |
297 | TheBuilder.UpdateEdge(Edge, Circle, Loc, Tol); | |
7fd59977 | 298 | } |
299 | else if ( STy == GeomAbs_Torus) { | |
300 | gp_Torus Tore = S.Torus(); | |
301 | gp_Pnt2d P = C.Line().Location(); | |
302 | gp_Ax3 Axis = Tore.Position(); | |
303 | gp_Circ Ci = ElSLib::TorusVIso(Axis, | |
304 | Tore.MajorRadius(), | |
305 | Tore.MinorRadius(), | |
306 | P.Y()); | |
307 | gp_Dir DRev = Axis.XDirection().Crossed(Axis.YDirection()); | |
308 | gp_Ax1 AxeRev(Axis.Location(), DRev); | |
309 | Ci.Rotate(AxeRev, P.X()); | |
310 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
311 | if ( D.IsOpposite(gp::DX2d(),Precision::Angular())) | |
312 | Circle->Reverse(); | |
313 | TheBuilder.UpdateEdge(Edge, Circle, Loc, Tol); | |
7fd59977 | 314 | } |
315 | } | |
316 | else if ( D.IsParallel(gp::DY2d(),Precision::Angular())) { // Iso U. | |
317 | if ( STy == GeomAbs_Sphere) { | |
318 | gp_Sphere Sph = S.Sphere(); | |
319 | gp_Pnt2d P = C.Line().Location(); | |
320 | gp_Ax3 Axis = Sph.Position(); | |
0d969553 | 321 | // calculate iso 0. |
7fd59977 | 322 | gp_Circ Ci = ElSLib::SphereUIso(Axis, Sph.Radius(),0.); |
323 | ||
0d969553 | 324 | // set to sameparameter (rotation of the circle - offset from Y) |
7fd59977 | 325 | gp_Dir DRev = Axis.XDirection().Crossed(Axis. Direction()); |
326 | gp_Ax1 AxeRev(Axis.Location(),DRev); | |
327 | Ci.Rotate(AxeRev, P.Y()); | |
328 | ||
0d969553 | 329 | // transformation by iso U ( = P.X()) |
7fd59977 | 330 | DRev = Axis.XDirection().Crossed(Axis.YDirection()); |
331 | AxeRev = gp_Ax1(Axis.Location(), DRev); | |
332 | Ci.Rotate(AxeRev, P.X()); | |
333 | Handle(Geom_Circle) Circle = new Geom_Circle(Ci); | |
334 | ||
335 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
336 | Circle->Reverse(); | |
337 | TheBuilder.UpdateEdge(Edge, Circle, Loc, Tol); | |
7fd59977 | 338 | } |
339 | else if ( STy == GeomAbs_Cylinder) { | |
340 | gp_Cylinder Cyl = S.Cylinder(); | |
341 | gp_Pnt2d P = C.Line().Location(); | |
342 | gp_Lin L = ElSLib::CylinderUIso(Cyl.Position(), | |
343 | Cyl.Radius(), | |
344 | P.X()); | |
345 | gp_Vec Tr(L.Direction()); | |
346 | Tr.Multiply(P.Y()); | |
347 | L.Translate(Tr); | |
348 | Handle(Geom_Line) Line = new Geom_Line(L); | |
349 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
350 | Line->Reverse(); | |
351 | TheBuilder.UpdateEdge(Edge, Line, Loc, Tol); | |
7fd59977 | 352 | } |
353 | else if ( STy == GeomAbs_Cone) { | |
354 | gp_Cone Cone = S.Cone(); | |
355 | gp_Pnt2d P = C.Line().Location(); | |
356 | gp_Lin L = ElSLib::ConeUIso(Cone.Position(), | |
357 | Cone.RefRadius(), | |
358 | Cone.SemiAngle(), | |
359 | P.X()); | |
360 | gp_Vec Tr(L.Direction()); | |
361 | Tr.Multiply(P.Y()); | |
362 | L.Translate(Tr); Handle(Geom_Line) Line = new Geom_Line(L); | |
363 | if ( D.IsOpposite(gp::DY2d(),Precision::Angular())) | |
364 | Line->Reverse(); | |
365 | TheBuilder.UpdateEdge(Edge, Line, Loc, Tol); | |
7fd59977 | 366 | } |
367 | else if ( STy == GeomAbs_Torus) { | |
368 | } | |
369 | } | |
370 | } | |
371 | } | |
0d969553 | 372 | else { // Case Plane |
7fd59977 | 373 | Handle(Geom_Curve) C3d = GeomAPI::To3d(Curve,S.Plane()); |
374 | TheBuilder.UpdateEdge(Edge, C3d, Loc, Tol); | |
7fd59977 | 375 | } |
376 | } | |
377 | ||
378 | ||
379 | //======================================================================= | |
380 | //function : MakeCurve | |
381 | //purpose : | |
382 | //======================================================================= | |
383 | ||
384 | class MakeCurve_Function : public AppCont_Function | |
385 | { | |
386 | BiTgte_CurveOnEdge myCurve; | |
368cdde6 | 387 | |
7fd59977 | 388 | public : |
368cdde6 | 389 | |
390 | MakeCurve_Function(const BiTgte_CurveOnEdge& C) | |
391 | : myCurve(C) | |
392 | { | |
393 | myNbPnt = 1; | |
394 | myNbPnt2d = 0; | |
395 | } | |
7fd59977 | 396 | |
397 | Standard_Real FirstParameter() const | |
368cdde6 | 398 | { |
399 | return myCurve.FirstParameter(); | |
400 | } | |
401 | ||
7fd59977 | 402 | Standard_Real LastParameter() const |
368cdde6 | 403 | { |
404 | return myCurve.LastParameter(); | |
405 | } | |
406 | ||
407 | Standard_Boolean Value(const Standard_Real theT, | |
408 | NCollection_Array1<gp_Pnt2d>& /*thePnt2d*/, | |
409 | NCollection_Array1<gp_Pnt>& thePnt) const | |
410 | { | |
411 | thePnt(1) = myCurve.Value(theT); | |
412 | return Standard_True; | |
413 | } | |
7fd59977 | 414 | |
368cdde6 | 415 | Standard_Boolean D1(const Standard_Real /*theT*/, |
416 | NCollection_Array1<gp_Vec2d>& /*theVec2d*/, | |
417 | NCollection_Array1<gp_Vec>& /*theVec*/) const | |
418 | { | |
419 | return Standard_False; | |
420 | } | |
7fd59977 | 421 | |
422 | }; | |
423 | ||
424 | Handle(Geom_Curve) MakeCurve (const BiTgte_CurveOnEdge& HC) | |
425 | { | |
426 | Handle(Geom_Curve) C; | |
427 | ||
0797d9d3 | 428 | #ifdef OCCT_DEBUG |
7fd59977 | 429 | OSD_Chronometer ch; |
430 | ChFi3d_InitChron(ch); | |
431 | #endif | |
432 | ||
433 | if ( HC.GetType() == GeomAbs_Circle) { | |
434 | C = new Geom_Circle(HC.Circle()); | |
435 | C = new Geom_TrimmedCurve(C,HC.FirstParameter(),HC.LastParameter()); | |
436 | } | |
0d969553 | 437 | else { // the approximation is done |
7fd59977 | 438 | MakeCurve_Function F(HC); |
439 | Standard_Integer Deg1, Deg2; | |
440 | Deg1 = Deg2 = 8; | |
441 | Standard_Real Tol = Precision::Approximation(); | |
442 | Approx_FitAndDivide Fit(F,Deg1,Deg2,Tol,Tol,Standard_True); | |
443 | Standard_Integer i; | |
444 | Standard_Integer NbCurves = Fit.NbMultiCurves(); | |
0d969553 | 445 | // it is attempted to make the curve at least C1 |
7fd59977 | 446 | Convert_CompBezierCurvesToBSplineCurve Conv; |
447 | ||
448 | for (i = 1; i <= NbCurves; i++) { | |
0d969553 Y |
449 | AppParCurves_MultiCurve MC = Fit.Value( i); //Load the Ith Curve |
450 | TColgp_Array1OfPnt Poles( 1, MC.Degree() + 1); //Return poles | |
7fd59977 | 451 | MC.Curve(1, Poles); |
452 | ||
453 | Conv.AddCurve(Poles); | |
454 | } | |
455 | ||
456 | Conv.Perform(); | |
457 | ||
458 | Standard_Integer NbPoles = Conv.NbPoles(); | |
459 | Standard_Integer NbKnots = Conv.NbKnots(); | |
460 | TColgp_Array1OfPnt NewPoles(1,NbPoles); | |
461 | TColStd_Array1OfReal NewKnots(1,NbKnots); | |
462 | TColStd_Array1OfInteger NewMults(1,NbKnots); | |
463 | ||
464 | Conv.KnotsAndMults(NewKnots,NewMults); | |
465 | Conv.Poles(NewPoles); | |
466 | ||
467 | BSplCLib::Reparametrize(HC.FirstParameter(), | |
468 | HC.LastParameter(), | |
469 | NewKnots); | |
470 | ||
471 | C = new Geom_BSplineCurve (NewPoles, | |
472 | NewKnots, | |
473 | NewMults, | |
474 | Conv.Degree()); | |
475 | } | |
476 | ||
0797d9d3 | 477 | #ifdef OCCT_DEBUG |
7fd59977 | 478 | ChFi3d_ResultChron(ch, t_mkcurve); |
479 | #endif | |
480 | ||
481 | return C; | |
482 | } | |
483 | ||
484 | ||
485 | //======================================================================= | |
486 | //function : Touched | |
0d969553 | 487 | //purpose : Only the faces connected with caps are given |
7fd59977 | 488 | //======================================================================= |
489 | ||
35e08fe8 | 490 | static void Touched(const BRepOffset_Analyse&, |
491 | const TopTools_MapOfShape&, | |
492 | const TopoDS_Shape&, | |
493 | TopTools_MapOfShape&) | |
7fd59977 | 494 | { |
0d969553 | 495 | // currently nothing is done !! |
302f96fb | 496 | /*if ( Standard_True) { |
7fd59977 | 497 | return; |
498 | } | |
499 | else { | |
500 | TopExp_Explorer exp(Shape, TopAbs_EDGE); | |
501 | for ( ; exp.More(); exp.Next()) { | |
502 | const TopTools_ListOfShape& L = Analyse.Ancestors(exp.Current()); | |
503 | if (StopFaces.Contains(L.First())) | |
35e08fe8 | 504 | TouchedByCork.Add(L.Last()); |
7fd59977 | 505 | else if (StopFaces.Contains(L.Last())) |
35e08fe8 | 506 | TouchedByCork.Add(L.First()); |
7fd59977 | 507 | } |
302f96fb | 508 | }*/ |
509 | return; | |
7fd59977 | 510 | } |
511 | ||
512 | //======================================================================= | |
513 | //function : FindVertex | |
514 | //purpose : | |
515 | //======================================================================= | |
516 | ||
517 | static TopoDS_Vertex FindVertex(const gp_Pnt& P, | |
518 | const TopTools_MapOfShape& Map, | |
519 | const Standard_Real Tol) | |
520 | { | |
521 | BRep_Builder B; | |
522 | // Find in <Map> a vertex which represent the point <P>. | |
523 | Standard_Real Tol2,Dist; | |
524 | TopoDS_Vertex V,VV[2]; | |
525 | Standard_Real TolCarre = Tol*Tol; | |
526 | TopTools_MapIteratorOfMapOfShape it(Map); | |
527 | for ( ; it.More(); it.Next()) { | |
528 | const TopoDS_Edge& E = TopoDS::Edge(it.Key()); | |
529 | if ( !E.IsNull()) { | |
530 | TopExp::Vertices(E,VV[0],VV[1]); | |
531 | ||
532 | for (Standard_Integer i = 0; i < 2 ; i++) { | |
0d969553 | 533 | // if OK la Tolerance du Vertex |
7fd59977 | 534 | Tol2 = BRep_Tool::Tolerance(VV[i]); |
535 | Tol2 *= Tol2; | |
536 | gp_Pnt P1 = BRep_Tool::Pnt(VV[i]); | |
537 | Dist = P.SquareDistance(P1); | |
538 | if ( Dist <= Tol2) return VV[i]; | |
0d969553 | 539 | // otherwise with the required tolerance. |
7fd59977 | 540 | if (TolCarre > Tol2) { |
541 | if ( Dist <= TolCarre) { | |
0d969553 | 542 | // so it is necessary to update the tolerance of Vertex. |
7fd59977 | 543 | B.UpdateVertex(VV[i],Tol); |
544 | return VV[i]; | |
545 | } | |
546 | } | |
547 | } | |
548 | } | |
549 | } | |
550 | ||
551 | return V; | |
552 | } | |
553 | ||
554 | ||
555 | //======================================================================= | |
556 | //function : MakeDegeneratedEdge | |
557 | //purpose : | |
558 | //======================================================================= | |
559 | ||
560 | static TopoDS_Edge MakeDegeneratedEdge(const Handle(Geom_Curve)& CC, | |
561 | const TopoDS_Vertex& VfOnE) | |
562 | { | |
563 | BRep_Builder B; | |
564 | Standard_Real Tol = Precision::Confusion(); | |
565 | // kill trimmed curves | |
566 | Handle(Geom_Curve) C = CC; | |
567 | Handle(Geom_TrimmedCurve) CT = Handle(Geom_TrimmedCurve)::DownCast(C); | |
568 | while (!CT.IsNull()) { | |
569 | C = CT->BasisCurve(); | |
570 | CT = Handle(Geom_TrimmedCurve)::DownCast(C); | |
571 | } | |
572 | ||
573 | TopoDS_Vertex V1,V2; | |
574 | if ( VfOnE.IsNull()) { | |
575 | gp_Pnt P = C->Value(C->FirstParameter()); | |
576 | B.MakeVertex(V1,P,Tol); | |
577 | V2 = V1; | |
578 | } | |
579 | else { | |
580 | V1 = V2 = VfOnE; | |
581 | } | |
582 | V1.Orientation(TopAbs_FORWARD); | |
583 | V2.Orientation(TopAbs_REVERSED); | |
584 | ||
585 | TopoDS_Edge E; | |
586 | B.MakeEdge(E,C,Tol); | |
587 | B.Add(E,V1); B.Add(E,V2); | |
588 | // B.UpdateVertex(V1,C->FirstParameter(),E,Tol); | |
589 | // B.UpdateVertex(V2,C->LastParameter(),E,Tol); | |
590 | B.Range(E,CC->FirstParameter(),CC->LastParameter()); | |
591 | return E; | |
592 | } | |
593 | ||
594 | ||
595 | //======================================================================= | |
596 | //function : Orientation | |
597 | //purpose : | |
598 | //======================================================================= | |
599 | ||
600 | static TopAbs_Orientation Orientation(const TopoDS_Edge& E, | |
601 | const TopoDS_Face& F, | |
602 | const TopTools_ListOfShape& L) | |
603 | { | |
7fd59977 | 604 | TopAbs_Orientation Orien = TopAbs_FORWARD; |
7fd59977 | 605 | TopTools_ListIteratorOfListOfShape itld; |
606 | for ( itld.Initialize(L); itld.More(); itld.Next()) { | |
607 | if ( itld.Value().IsSame(E)) { | |
608 | Orien = itld.Value().Orientation(); | |
609 | break; | |
610 | } | |
611 | } | |
612 | if ( F.Orientation() == TopAbs_REVERSED) | |
613 | Orien = TopAbs::Reverse(Orien); | |
614 | ||
615 | return Orien; | |
616 | } | |
617 | ||
618 | //======================================================================= | |
619 | //function : FindCreatedEdge | |
620 | //purpose : | |
621 | //======================================================================= | |
622 | ||
623 | static TopoDS_Edge FindCreatedEdge | |
624 | (const TopoDS_Vertex& V1, | |
625 | const TopoDS_Edge& E, | |
626 | const BRepOffset_DataMapOfShapeOffset& MapSF, | |
627 | TopTools_MapOfShape& MapOnV, | |
628 | const BRepOffset_Analyse& CenterAnalyse, | |
629 | Standard_Real Radius, | |
630 | Standard_Real Tol) | |
631 | { | |
632 | TopoDS_Edge E1; | |
633 | if (!CenterAnalyse.HasAncestor(V1)) return E1; // return a Null Shape. | |
634 | ||
635 | TopTools_ListOfShape TangE; | |
636 | CenterAnalyse.TangentEdges(E,V1,TangE); | |
637 | ||
638 | TopTools_ListIteratorOfListOfShape itl(TangE); | |
639 | Standard_Boolean Find = Standard_False; | |
640 | for ( ; itl.More() && !Find; itl.Next()) { | |
641 | const TopoDS_Edge& ET = TopoDS::Edge(itl.Value()); | |
642 | if ( MapSF.IsBound(ET)) { | |
643 | TopoDS_Shape aLocalShape = MapSF(ET).Generated(V1); | |
644 | E1 = TopoDS::Edge(aLocalShape); | |
645 | // E1 = TopoDS::Edge(MapSF(ET).Generated(V1)); | |
646 | MapOnV.Add(E1); | |
647 | Find = Standard_True; | |
648 | } | |
649 | else { | |
0d969553 Y |
650 | // Find the sharing of vertices in case of tangent consecutive 3 edges |
651 | // the second of which is the edge that degenerates the tube. | |
7fd59977 | 652 | TopLoc_Location CLoc; |
653 | Standard_Real ff,ll; | |
654 | Handle(Geom_Curve) CET = | |
655 | BRep_Tool::Curve(ET,CLoc,ff,ll); | |
656 | if ( CET->DynamicType() == STANDARD_TYPE(Geom_TrimmedCurve)) { | |
657 | CET = Handle(Geom_TrimmedCurve)::DownCast(CET)->BasisCurve(); | |
658 | } | |
659 | Handle(Geom_Circle) Circ = Handle(Geom_Circle)::DownCast(CET); | |
660 | if ( Circ.IsNull()) continue; | |
661 | if ( Abs(Circ->Radius() - Abs(Radius)) > Tol) continue; | |
662 | ||
663 | TopoDS_Vertex U1,U2; | |
664 | TopExp::Vertices(ET,U1,U2); | |
665 | if ( U1.IsSame(V1)) U1 = U2; | |
666 | TopTools_ListOfShape Tang2; | |
667 | CenterAnalyse.TangentEdges(ET,U1,Tang2); | |
668 | TopTools_ListIteratorOfListOfShape it2(Tang2); | |
669 | for ( ; it2.More() ; it2.Next()) { | |
670 | const TopoDS_Edge& ET2 = TopoDS::Edge(it2.Value()); | |
671 | if ( MapSF.IsBound(ET2)) { | |
672 | TopoDS_Shape aLocalShape = MapSF(ET2).Generated(U1); | |
673 | MapOnV.Add(TopoDS::Edge(aLocalShape)); | |
674 | // MapOnV.Add(TopoDS::Edge(MapSF(ET2).Generated(U1))); | |
675 | } | |
676 | } | |
677 | } | |
678 | } | |
679 | if (!Find) { | |
680 | TangE.Clear(); | |
681 | // CenterAnalyse.Edges(V1f, OT, TangE); | |
682 | if (CenterAnalyse.HasAncestor(V1)) { | |
683 | TangE = CenterAnalyse.Ancestors(V1); | |
684 | itl.Initialize(TangE); | |
685 | for ( ; itl.More() && !Find; itl.Next()) { | |
686 | if ( MapSF.IsBound(itl.Value())) { | |
687 | MapOnV.Add(MapSF(itl.Value()).Generated(V1)); | |
688 | } | |
689 | } | |
690 | } | |
691 | } | |
692 | ||
693 | return E1; | |
694 | } | |
695 | ||
696 | //======================================================================= | |
697 | //function : Bubble | |
0d969553 | 698 | //purpose : Sets in increasing order the sequence of vertices. |
7fd59977 | 699 | //======================================================================= |
700 | ||
701 | static void Bubble(const TopoDS_Edge& E, | |
702 | TopTools_SequenceOfShape& Seq) | |
703 | { | |
704 | Standard_Boolean Invert = Standard_True; | |
705 | Standard_Integer NbPoints = Seq.Length(); | |
706 | Standard_Real U1,U2; | |
707 | TopoDS_Vertex V1,V2; | |
708 | ||
709 | while (Invert) { | |
710 | Invert = Standard_False; | |
711 | for ( Standard_Integer i = 1; i < NbPoints; i++) { | |
712 | TopoDS_Shape aLocalShape = Seq.Value(i) .Oriented(TopAbs_INTERNAL); | |
713 | V1 = TopoDS::Vertex(aLocalShape); | |
714 | aLocalShape = Seq.Value(i+1).Oriented(TopAbs_INTERNAL); | |
715 | V2 = TopoDS::Vertex(aLocalShape); | |
716 | // V1 = TopoDS::Vertex(Seq.Value(i) .Oriented(TopAbs_INTERNAL)); | |
717 | // V2 = TopoDS::Vertex(Seq.Value(i+1).Oriented(TopAbs_INTERNAL)); | |
718 | ||
719 | U1 = BRep_Tool::Parameter(V1,E); | |
720 | U2 = BRep_Tool::Parameter(V2,E); | |
721 | if (U2 < U1) { | |
722 | Seq.Exchange(i,i+1); | |
723 | Invert = Standard_True; | |
724 | } | |
725 | } | |
726 | } | |
727 | } | |
728 | ||
729 | //======================================================================= | |
730 | //function : CutEdge | |
731 | //purpose : | |
732 | //======================================================================= | |
733 | ||
734 | static void CutEdge (const TopoDS_Edge& E, | |
735 | const TopTools_ListOfShape& VOnE, | |
736 | TopTools_ListOfShape& NE ) | |
737 | { | |
51740958 | 738 | TopoDS_Shape aLocalShapeOrientedE = E.Oriented(TopAbs_FORWARD); |
739 | TopoDS_Edge WE = TopoDS::Edge(aLocalShapeOrientedE); | |
7fd59977 | 740 | // TopoDS_Edge WE = TopoDS::Edge(E.Oriented(TopAbs_FORWARD)); |
741 | ||
742 | Standard_Real U1,U2; | |
743 | TopoDS_Vertex V1,V2; | |
744 | TopTools_SequenceOfShape SV; | |
745 | TopTools_ListIteratorOfListOfShape it(VOnE); | |
746 | BRep_Builder B; | |
747 | ||
748 | for ( ; it.More(); it.Next()) { | |
749 | SV.Append(it.Value()); | |
750 | } | |
751 | //-------------------------------- | |
0d969553 | 752 | // Parse vertices on the edge. |
7fd59977 | 753 | //-------------------------------- |
754 | Bubble (WE,SV); | |
755 | ||
756 | Standard_Integer NbVer = SV.Length(); | |
757 | //---------------------------------------------------------------- | |
0d969553 Y |
758 | // Construction of new edges. |
759 | // The vertices at the extremities of edges are not | |
760 | // necessarily in the list of vertices | |
7fd59977 | 761 | //---------------------------------------------------------------- |
762 | if (SV.IsEmpty()) { | |
763 | NE.Append(E); | |
764 | return; | |
765 | } | |
766 | TopoDS_Vertex VF,VL; | |
767 | Standard_Real f,l; | |
768 | BRep_Tool::Range(WE,f,l); | |
769 | TopExp::Vertices(WE,VF,VL); | |
770 | ||
771 | if (NbVer == 2) { | |
772 | if (SV(1).IsEqual(VF) && SV(2).IsEqual(VL)) { | |
773 | NE.Append(E); | |
774 | return; | |
775 | } | |
776 | } | |
777 | //---------------------------------------------------- | |
0d969553 Y |
778 | // Processing of closed edges |
779 | // If a vertex of intersection is on the common vertex, | |
780 | // it should appear at the beginning and the end of SV. | |
7fd59977 | 781 | //---------------------------------------------------- |
782 | TopoDS_Vertex VCEI; | |
783 | ||
784 | if (!VF.IsNull() && !VF.IsSame(SV.First())) SV.Prepend(VF); | |
785 | if (!VL.IsNull() && !VL.IsSame(SV.Last ())) SV.Append (VL); | |
786 | ||
787 | V1 = TopoDS::Vertex(SV.First()); | |
788 | SV.Remove(1); | |
789 | ||
790 | while (!SV.IsEmpty()) { | |
791 | ||
792 | V2 = TopoDS::Vertex(SV.First()); | |
793 | SV.Remove(1); | |
794 | ||
795 | if ( V1.IsSame(V2)) { | |
796 | cout << "Vertex Confondus dans CutEdges" << endl; | |
797 | continue; | |
798 | } | |
799 | //------------------------------------------- | |
0d969553 | 800 | // Copy the edge and restriction by V1 V2. |
7fd59977 | 801 | //------------------------------------------- |
802 | TopoDS_Shape aLocalShape =WE.EmptyCopied(); | |
803 | TopoDS_Edge NewEdge = TopoDS::Edge(aLocalShape); | |
804 | // TopoDS_Edge NewEdge = TopoDS::Edge(WE.EmptyCopied()); | |
805 | B.Add (NewEdge,V1.Oriented(TopAbs_FORWARD)); | |
806 | B.Add (NewEdge,V2.Oriented(TopAbs_REVERSED)); | |
807 | if (V1.IsSame(VF)) | |
808 | U1 = f; | |
809 | else { | |
810 | aLocalShape = V1.Oriented(TopAbs_INTERNAL); | |
811 | U1 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalShape),WE); | |
812 | // U1 = BRep_Tool::Parameter | |
813 | // (TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)),WE); | |
814 | } | |
815 | if (V2.IsSame(VL)) | |
816 | U2 = l; | |
817 | else { | |
818 | aLocalShape = V2.Oriented(TopAbs_INTERNAL); | |
819 | U2 = BRep_Tool::Parameter(TopoDS::Vertex(aLocalShape),WE); | |
820 | // U2 = BRep_Tool::Parameter | |
821 | // (TopoDS::Vertex(V2.Oriented(TopAbs_INTERNAL)),WE); | |
822 | } | |
823 | B.Range (NewEdge,U1,U2); | |
824 | NE.Append(NewEdge.Oriented(E.Orientation())); | |
825 | ||
826 | V1 = V2; | |
827 | } | |
828 | } | |
0d969553 | 829 | //======================== END OF STATIC FUNCTIONS ============ |
7fd59977 | 830 | |
831 | ||
832 | ||
833 | ||
834 | //======================================================================= | |
835 | //function : BiTgte_Blend | |
836 | //purpose : | |
837 | //======================================================================= | |
838 | ||
839 | BiTgte_Blend::BiTgte_Blend() | |
840 | { | |
841 | myAsDes = new BRepAlgo_AsDes(); | |
842 | myNbBranches = -1; | |
843 | } | |
844 | ||
845 | ||
846 | //======================================================================= | |
847 | //function : BiTgte_Blend | |
848 | //purpose : | |
849 | //======================================================================= | |
850 | ||
851 | BiTgte_Blend::BiTgte_Blend(const TopoDS_Shape& S, | |
852 | const Standard_Real Radius, | |
853 | const Standard_Real Tol, | |
854 | const Standard_Boolean NUBS) | |
855 | { | |
856 | myAsDes = new BRepAlgo_AsDes(); | |
857 | Init(S,Radius,Tol,NUBS); | |
858 | } | |
859 | ||
860 | ||
861 | //======================================================================= | |
862 | //function : Init | |
863 | //purpose : | |
864 | //======================================================================= | |
865 | ||
866 | void BiTgte_Blend::Init(const TopoDS_Shape& S, | |
867 | const Standard_Real Radius, | |
868 | const Standard_Real Tol, | |
869 | const Standard_Boolean NUBS) | |
870 | { | |
871 | Clear(); | |
872 | myShape = S; | |
873 | myTol = Tol; | |
874 | myNubs = NUBS; | |
875 | myRadius = Radius; | |
876 | myNbBranches = -1; | |
877 | // TopExp::MapShapesAndAncestors(S,TopAbs_EDGE,TopAbs_FACE,myAncestors); | |
878 | } | |
879 | ||
880 | ||
881 | //======================================================================= | |
882 | //function : Clear | |
883 | //purpose : | |
884 | //======================================================================= | |
885 | ||
886 | void BiTgte_Blend::Clear() | |
887 | { | |
888 | myInitOffsetFace.Clear(); | |
889 | myImage .Clear(); | |
890 | myImageOffset .Clear(); | |
891 | myStopFaces .Clear(); | |
892 | myAnalyse .Clear(); | |
893 | myAsDes ->Clear(); | |
894 | myNbBranches = -1; | |
895 | myDone = Standard_False; | |
896 | } | |
897 | ||
898 | ||
899 | //======================================================================= | |
900 | //function : SetStoppingFace | |
901 | //purpose : | |
902 | //======================================================================= | |
903 | ||
904 | void BiTgte_Blend::SetStoppingFace(const TopoDS_Face& Face) | |
905 | { | |
906 | myStopFaces.Add(Face); | |
907 | //------------- | |
0d969553 | 908 | // MAJ SD. -> To end loop, set faces of edges |
7fd59977 | 909 | //------------- |
910 | // myInitOffsetFace.SetRoot(Face); | |
911 | // myInitOffsetFace.Bind (Face,Face); | |
912 | // myImageOffset.SetRoot (Face); | |
913 | } | |
914 | ||
915 | ||
916 | //======================================================================= | |
917 | //function : SetFaces | |
918 | //purpose : | |
919 | //======================================================================= | |
920 | ||
921 | void BiTgte_Blend::SetFaces(const TopoDS_Face& F1,const TopoDS_Face& F2) | |
922 | { | |
923 | myFaces.Add(F1); | |
924 | myFaces.Add(F2); | |
925 | } | |
926 | ||
927 | ||
928 | //======================================================================= | |
929 | //function : SetEdge | |
930 | //purpose : | |
931 | //======================================================================= | |
932 | ||
933 | void BiTgte_Blend::SetEdge(const TopoDS_Edge& Edge) | |
934 | { | |
935 | myEdges.Add(Edge); | |
936 | } | |
937 | ||
938 | ||
939 | //======================================================================= | |
940 | //function : Perform | |
941 | //purpose : | |
942 | //======================================================================= | |
943 | ||
944 | void BiTgte_Blend::Perform(const Standard_Boolean BuildShape) | |
945 | { | |
946 | myBuildShape = BuildShape; | |
947 | ||
0d969553 Y |
948 | // Try cutting to avoid tubes on free borders |
949 | // that are not actually free. | |
7fd59977 | 950 | Handle(BRepBuilderAPI_Sewing) Sew = new BRepBuilderAPI_Sewing(myTol); |
951 | BRepLib::BuildCurves3d(myShape); | |
952 | TopExp_Explorer expf(myShape,TopAbs_FACE); | |
953 | for ( ;expf.More(); expf.Next()) Sew->Add(expf.Current()); | |
954 | Sew->Perform(); | |
955 | TopoDS_Shape SewedShape = Sew->SewedShape(); | |
9775fa61 | 956 | if ( SewedShape.IsNull()) throw Standard_Failure("Sewing aux fraises"); |
7fd59977 | 957 | |
0d969553 | 958 | // Check if the sewing modified the orientation. |
7fd59977 | 959 | expf.Init(myShape,TopAbs_FACE); |
960 | TopoDS_Face FaceRef = TopoDS::Face(expf.Current()); | |
961 | TopAbs_Orientation OriRef = FaceRef.Orientation(); | |
962 | if (Sew->IsModified(FaceRef)) FaceRef = TopoDS::Face(Sew->Modified(FaceRef)); | |
963 | expf.Init(SewedShape, TopAbs_FACE); | |
964 | for (; expf.More(); expf.Next()) { | |
965 | const TopoDS_Face& FF = TopoDS::Face(expf.Current()); | |
966 | if (FaceRef.IsSame(FF) && (FF.Orientation() != OriRef)) { | |
967 | SewedShape.Reverse(); | |
968 | break; | |
969 | } | |
970 | } | |
971 | ||
0d969553 Y |
972 | // Make SameParameter if Sew does not do it (Detect that edges |
973 | // are not sameparameter but it does nothing.) | |
7fd59977 | 974 | expf.Init(SewedShape, TopAbs_EDGE); |
975 | for (; expf.More(); expf.Next()) { | |
976 | const TopoDS_Edge& sec = TopoDS::Edge(expf.Current()); | |
977 | BRepLib::SameParameter(sec, BRep_Tool::Tolerance(sec)); | |
978 | } | |
979 | ||
980 | TopExp::MapShapesAndAncestors | |
981 | (SewedShape,TopAbs_EDGE,TopAbs_FACE,myAncestors); | |
982 | ||
0d969553 | 983 | // Extend myFaces with the faces of the sewed shape. |
7fd59977 | 984 | expf.Init(myShape,TopAbs_FACE); |
985 | for ( ; expf.More(); expf.Next()) { | |
986 | const TopoDS_Shape& F = expf.Current(); | |
987 | if ( myFaces.Contains(F) && Sew->IsModified(F)) { | |
3f5aa017 | 988 | myFaces.RemoveKey(F); |
7fd59977 | 989 | myFaces.Add(Sew->Modified(F)); |
990 | } | |
991 | } | |
992 | ||
993 | myShape = SewedShape; | |
0d969553 | 994 | // end Sewing for false free borders. |
7fd59977 | 995 | |
0797d9d3 | 996 | #ifdef OCCT_DEBUG |
7fd59977 | 997 | OSD_Chronometer cl_total, ch; |
998 | Standard_Real t_total, t_center, t_surface, t_shape; | |
999 | ||
1000 | t_total=0; t_center=0; t_surface=0; t_mkcurve=0; t_shape=0; | |
1001 | ChFi3d_InitChron(cl_total); | |
1002 | #endif | |
1003 | ||
1004 | // ---------------------------------------------------------------- | |
0d969553 | 1005 | // place faces with the proper orientation in the initial shape |
7fd59977 | 1006 | // ---------------------------------------------------------------- |
1007 | TopExp_Explorer exp(myShape,TopAbs_FACE); | |
1008 | for ( ; exp.More(); exp.Next()) { | |
1009 | const TopoDS_Shape& F = exp.Current(); | |
1010 | if ( myFaces.Contains(F)) { | |
3f5aa017 | 1011 | myFaces.RemoveKey(F); |
7fd59977 | 1012 | myFaces.Add(F); |
1013 | } | |
1014 | else if ( myStopFaces.Contains(F)) { | |
1015 | myStopFaces.Remove(F); | |
1016 | myStopFaces.Add(F); | |
1017 | } | |
1018 | } | |
1019 | ||
1020 | // ---------------------------------------------- | |
0d969553 | 1021 | // Calculate lines of centers and of surfaces |
7fd59977 | 1022 | // ---------------------------------------------- |
0797d9d3 | 1023 | #ifdef OCCT_DEBUG |
7fd59977 | 1024 | ChFi3d_InitChron(ch); |
1025 | #endif | |
1026 | ||
1027 | ComputeCenters(); | |
1028 | ||
0797d9d3 | 1029 | #ifdef OCCT_DEBUG |
7fd59977 | 1030 | ChFi3d_ResultChron(ch, t_center); |
1031 | #endif | |
1032 | ||
1033 | // ----------------------------- | |
0d969553 | 1034 | // Calculate connection Surfaces |
7fd59977 | 1035 | // ----------------------------- |
0797d9d3 | 1036 | #ifdef OCCT_DEBUG |
7fd59977 | 1037 | ChFi3d_InitChron(ch); |
1038 | #endif | |
1039 | ||
1040 | ComputeSurfaces(); | |
1041 | ||
0797d9d3 | 1042 | #ifdef OCCT_DEBUG |
7fd59977 | 1043 | ChFi3d_ResultChron(ch, t_surface); |
1044 | #endif | |
1045 | ||
1046 | // ---------------------------------- | |
0d969553 | 1047 | // Calculate the generated shape if required |
7fd59977 | 1048 | // ---------------------------------- |
0797d9d3 | 1049 | #ifdef OCCT_DEBUG |
7fd59977 | 1050 | ChFi3d_InitChron(ch); |
1051 | #endif | |
1052 | ||
1053 | if ( myBuildShape) ComputeShape(); | |
1054 | ||
0797d9d3 | 1055 | #ifdef OCCT_DEBUG |
7fd59977 | 1056 | ChFi3d_ResultChron(ch, t_shape); |
1057 | #endif | |
1058 | ||
0d969553 Y |
1059 | // Finally construct curves 3d from edges to be transfered |
1060 | // since the partition is provided ( A Priori); | |
7fd59977 | 1061 | BRepLib::BuildCurves3d(myResult, Precision::Confusion()); |
1062 | ||
0797d9d3 | 1063 | #ifdef OCCT_DEBUG |
7fd59977 | 1064 | ChFi3d_ResultChron(cl_total, t_total); |
1065 | cout<<endl; | |
1066 | cout<<"Blend_PERFORM: temps total "<<t_total<<" s dont :"<<endl; | |
1067 | cout<<"- ComputeCenters "<<t_center<<" s"<<endl; | |
1068 | cout<<"- ComputeSurfaces "<<t_surface<<" s"<<endl; | |
1069 | cout<<"----> MakeCurve "<<t_mkcurve<<" s"<<endl; | |
1070 | if ( myBuildShape) cout<<"- ComputeShape "<<t_shape<<" s"<<endl; | |
1071 | #endif | |
1072 | ||
1073 | myDone = Standard_True; | |
1074 | } | |
1075 | ||
1076 | ||
1077 | //======================================================================= | |
1078 | //function : IsDone | |
1079 | //purpose : | |
1080 | //======================================================================= | |
1081 | ||
1082 | Standard_Boolean BiTgte_Blend::IsDone() const | |
1083 | { | |
1084 | return myDone; | |
1085 | } | |
1086 | ||
1087 | //======================================================================= | |
1088 | //function : Shape | |
1089 | //purpose : | |
1090 | //======================================================================= | |
1091 | ||
1092 | const TopoDS_Shape& BiTgte_Blend::Shape() const | |
1093 | { | |
1094 | return myResult; | |
1095 | } | |
1096 | ||
1097 | ||
1098 | //======================================================================= | |
1099 | //function : NbSurfaces | |
1100 | //purpose : | |
1101 | //======================================================================= | |
1102 | ||
1103 | Standard_Integer BiTgte_Blend::NbSurfaces() const | |
1104 | { | |
1105 | return myCenters.Extent(); | |
1106 | } | |
1107 | ||
1108 | ||
1109 | //======================================================================= | |
1110 | //function : Surface | |
1111 | //purpose : | |
1112 | //======================================================================= | |
1113 | ||
1114 | Handle(Geom_Surface) BiTgte_Blend::Surface(const Standard_Integer Index) const | |
1115 | { | |
1116 | return Surface(myCenters(Index)); | |
1117 | } | |
1118 | ||
1119 | //======================================================================= | |
1120 | //function : TopoDS_Face& | |
1121 | //purpose : | |
1122 | //======================================================================= | |
1123 | ||
1124 | const TopoDS_Face& BiTgte_Blend::Face(const Standard_Integer Index) const | |
1125 | { | |
1126 | return Face(myCenters(Index)); | |
1127 | } | |
1128 | ||
1129 | ||
1130 | ||
1131 | //======================================================================= | |
1132 | //function : CenterLines | |
1133 | //purpose : | |
1134 | //======================================================================= | |
1135 | ||
1136 | void BiTgte_Blend::CenterLines(TopTools_ListOfShape& LC) const | |
1137 | { | |
1138 | LC.Clear(); | |
1139 | Standard_Integer Nb = NbSurfaces(); | |
1140 | for ( Standard_Integer i = 1; i <= Nb; i++) | |
1141 | LC.Append(myCenters(i)); | |
1142 | } | |
1143 | ||
1144 | ||
1145 | //======================================================================= | |
1146 | //function : Surface | |
1147 | //purpose : | |
1148 | //======================================================================= | |
1149 | ||
1150 | Handle(Geom_Surface) BiTgte_Blend::Surface(const TopoDS_Shape& CenterLine) | |
1151 | const | |
1152 | { | |
1153 | const TopoDS_Face& F = myMapSF(CenterLine).Face(); | |
1154 | return BRep_Tool::Surface(F); | |
1155 | } | |
1156 | ||
1157 | //======================================================================= | |
1158 | //function : TopoDS_Face& | |
1159 | //purpose : | |
1160 | //======================================================================= | |
1161 | ||
1162 | const TopoDS_Face& BiTgte_Blend::Face(const TopoDS_Shape& CenterLine) const | |
1163 | { | |
1164 | if ( !myMapSF.IsBound(CenterLine)) { | |
9775fa61 | 1165 | throw Standard_DomainError("BiTgte_Blend::Face"); |
7fd59977 | 1166 | } |
1167 | ||
1168 | return myMapSF(CenterLine).Face(); | |
1169 | } | |
1170 | ||
1171 | //======================================================================= | |
1172 | //function : ContactType | |
1173 | //purpose : | |
1174 | //======================================================================= | |
1175 | ||
1176 | BiTgte_ContactType BiTgte_Blend::ContactType(const Standard_Integer Index) | |
1177 | const | |
1178 | { | |
1179 | const TopoDS_Shape& S1 = SupportShape1(Index); | |
1180 | const TopoDS_Shape& S2 = SupportShape2(Index); | |
1181 | ||
1182 | TopAbs_ShapeEnum Type1 = S1.ShapeType(); | |
1183 | TopAbs_ShapeEnum Type2 = S2.ShapeType(); | |
1184 | ||
1185 | if (Type2 < Type1) { | |
1186 | TopAbs_ShapeEnum Dummy = Type1; | |
1187 | Type1 = Type2; | |
1188 | Type2 = Dummy; | |
1189 | } | |
1190 | BiTgte_ContactType Type = BiTgte_VertexVertex; | |
1191 | ||
1192 | switch (Type1) { | |
1193 | ||
1194 | case TopAbs_VERTEX: | |
1195 | switch (Type2) { | |
1196 | case TopAbs_VERTEX: Type = BiTgte_VertexVertex; break; | |
1197 | case TopAbs_EDGE: Type = BiTgte_EdgeVertex; break; | |
1198 | case TopAbs_FACE: Type = BiTgte_FaceVertex; break; | |
1199 | default: | |
1200 | break; | |
1201 | } | |
1202 | ||
1203 | case TopAbs_EDGE: | |
1204 | switch (Type2) { | |
1205 | case TopAbs_EDGE: Type = BiTgte_EdgeEdge; break; | |
1206 | case TopAbs_FACE: Type = BiTgte_FaceEdge; break; | |
1207 | default: | |
1208 | break; | |
1209 | } | |
1210 | ||
1211 | case TopAbs_FACE: | |
1212 | switch (Type2) { | |
1213 | case TopAbs_FACE: Type = BiTgte_FaceEdge; break; | |
1214 | default: | |
1215 | break; | |
1216 | } | |
1217 | default: | |
1218 | break; | |
1219 | } | |
1220 | ||
1221 | return Type; | |
1222 | } | |
1223 | ||
1224 | ||
1225 | ||
1226 | //======================================================================= | |
1227 | //function : SupportShape1 | |
1228 | //purpose : | |
1229 | //======================================================================= | |
1230 | ||
1231 | const TopoDS_Shape& BiTgte_Blend::SupportShape1(const Standard_Integer Index) | |
1232 | const | |
1233 | { | |
1234 | const TopoDS_Edge& CurE = TopoDS::Edge(myCenters(Index)); | |
1235 | ||
1236 | const TopTools_ListOfShape& L = myAsDes->Ascendant(CurE); | |
1237 | ||
1238 | // -------------------------------------------------------------- | |
0d969553 | 1239 | // F1 and F2 = 2 parallel faces intersecting at CurE. |
7fd59977 | 1240 | // -------------------------------------------------------------- |
1241 | const TopoDS_Face& F1 = TopoDS::Face(L.First()); | |
1242 | const TopoDS_Shape& Or1 = myInitOffsetFace.ImageFrom(F1); | |
1243 | return Or1; | |
1244 | } | |
1245 | ||
1246 | ||
1247 | //======================================================================= | |
1248 | //function : SupportShape2 | |
1249 | //purpose : | |
1250 | //======================================================================= | |
1251 | ||
1252 | const TopoDS_Shape& BiTgte_Blend::SupportShape2(const Standard_Integer Index) | |
1253 | const | |
1254 | { | |
1255 | const TopoDS_Edge& CurE = TopoDS::Edge(myCenters(Index)); | |
1256 | ||
1257 | const TopTools_ListOfShape& L = myAsDes->Ascendant(CurE); | |
1258 | ||
1259 | // -------------------------------------------------------------- | |
0d969553 | 1260 | // F1 and F2 = 2 parallel faces intersecting at CurE. |
7fd59977 | 1261 | // -------------------------------------------------------------- |
1262 | const TopoDS_Face& F2 = TopoDS::Face(L.Last()); | |
1263 | const TopoDS_Shape& Or2 = myInitOffsetFace.ImageFrom(F2); | |
1264 | return Or2; | |
1265 | } | |
1266 | ||
1267 | ||
1268 | //======================================================================= | |
1269 | //function : CurveOnShape1 | |
1270 | //purpose : | |
1271 | //======================================================================= | |
1272 | ||
1273 | Handle(Geom_Curve) BiTgte_Blend::CurveOnShape1 | |
1274 | (const Standard_Integer Index) const | |
1275 | { | |
1276 | const TopoDS_Edge& CurE = TopoDS::Edge(myCenters(Index)); | |
1277 | const TopoDS_Shape& F = myMapSF(CurE).Face(); | |
1278 | ||
0d969553 Y |
1279 | // somewhat brutal method based ONLY on the construction of the fillet: |
1280 | // the first edge of the tube is exactly the edge on Shape1. | |
7fd59977 | 1281 | |
1282 | TopExp_Explorer exp(F,TopAbs_EDGE); | |
1283 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); | |
1284 | Handle(Geom_Curve) C; | |
1285 | if ( !BRep_Tool::Degenerated(E)) { | |
1286 | Standard_Real f,l; | |
1287 | C = BRep_Tool::Curve(E,f,l); | |
1288 | C = new Geom_TrimmedCurve(C,f,l); | |
1289 | } | |
1290 | return C; | |
1291 | } | |
1292 | ||
1293 | ||
1294 | //======================================================================= | |
1295 | //function : CurveOnShape2 | |
1296 | //purpose : | |
1297 | //======================================================================= | |
1298 | ||
1299 | Handle(Geom_Curve) BiTgte_Blend::CurveOnShape2 | |
1300 | (const Standard_Integer Index) const | |
1301 | { | |
1302 | const TopoDS_Edge& CurE = TopoDS::Edge(myCenters(Index)); | |
1303 | const TopoDS_Shape& F = myMapSF(CurE).Face(); | |
1304 | ||
0d969553 Y |
1305 | // somewhat brutal method based ONLY on the construction of the fillet: |
1306 | // the first edge of the tube is exactly the edge on Shape2. | |
7fd59977 | 1307 | |
1308 | TopExp_Explorer exp(F,TopAbs_EDGE); | |
1309 | exp.Next(); | |
1310 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); | |
1311 | Handle(Geom_Curve) C; | |
1312 | if ( !BRep_Tool::Degenerated(E)) { | |
1313 | Standard_Real f,l; | |
1314 | C = BRep_Tool::Curve(E,f,l); | |
1315 | C = new Geom_TrimmedCurve(C,f,l); | |
1316 | } | |
1317 | return C; | |
1318 | } | |
1319 | ||
1320 | ||
1321 | //======================================================================= | |
1322 | //function : PCurveOnFace1 | |
1323 | //purpose : | |
1324 | //======================================================================= | |
1325 | ||
1326 | Handle(Geom2d_Curve) BiTgte_Blend::PCurveOnFace1 | |
1327 | (const Standard_Integer /*Index*/) const | |
1328 | { | |
1329 | Handle(Geom2d_Curve) C; | |
1330 | return C; | |
1331 | } | |
1332 | ||
1333 | ||
1334 | //======================================================================= | |
1335 | //function : PCurve1OnFillet | |
1336 | //purpose : | |
1337 | //======================================================================= | |
1338 | ||
1339 | Handle(Geom2d_Curve) BiTgte_Blend::PCurve1OnFillet | |
1340 | (const Standard_Integer /*Index*/) const | |
1341 | { | |
1342 | Handle(Geom2d_Curve) C; | |
1343 | return C; | |
1344 | } | |
1345 | ||
1346 | ||
1347 | //======================================================================= | |
1348 | //function : PCurveOnFace2 | |
1349 | //purpose : | |
1350 | //======================================================================= | |
1351 | ||
1352 | Handle(Geom2d_Curve) BiTgte_Blend::PCurveOnFace2 | |
1353 | (const Standard_Integer /*Index*/) const | |
1354 | { | |
1355 | Handle(Geom2d_Curve) C; | |
1356 | return C; | |
1357 | } | |
1358 | ||
1359 | ||
1360 | //======================================================================= | |
1361 | //function : Curve2OnFillet | |
1362 | //purpose : | |
1363 | //======================================================================= | |
1364 | ||
1365 | Handle(Geom2d_Curve) BiTgte_Blend::PCurve2OnFillet | |
1366 | (const Standard_Integer /*Index*/) const | |
1367 | { | |
1368 | Handle(Geom2d_Curve) C; | |
1369 | return C; | |
1370 | } | |
1371 | ||
1372 | ||
1373 | ||
1374 | //======================================================================= | |
1375 | //function : NbBranches | |
1376 | //purpose : | |
1377 | //======================================================================= | |
1378 | ||
1379 | Standard_Integer BiTgte_Blend::NbBranches() | |
1380 | { | |
1381 | if (myNbBranches != -1) return myNbBranches; | |
1382 | ||
1383 | // else, compute the Branches. | |
1384 | BRepTools_Quilt Glue; | |
1385 | ||
1386 | Standard_Integer NbFaces = myCenters.Extent(); | |
1387 | ||
0d969553 | 1388 | |
7fd59977 | 1389 | if (NbFaces == 0) return 0; |
1390 | ||
0d969553 | 1391 | |
7fd59977 | 1392 | Standard_Integer i; |
1393 | for ( i = 1; i <= NbFaces; i++) { | |
1394 | const TopoDS_Shape& CenterLine = myCenters(i); | |
1395 | Glue.Add(myMapSF(CenterLine).Face()); | |
1396 | } | |
1397 | ||
1398 | const TopoDS_Shape Shells = Glue.Shells(); | |
1399 | ||
1400 | ||
0d969553 Y |
1401 | // Reorder Map myCenters. |
1402 | // The method is brutal and unpolished, | |
1403 | // it is possible to refine it. | |
7fd59977 | 1404 | myNbBranches = 0; |
1405 | TopTools_IndexedMapOfShape tmpMap; | |
1406 | ||
1407 | TopExp_Explorer exp(Shells,TopAbs_SHELL); | |
1408 | for (; exp.More(); exp.Next()) { | |
1409 | myNbBranches++; | |
1410 | } | |
1411 | ||
1412 | myIndices = new TColStd_HArray1OfInteger(1,myNbBranches+1); | |
1413 | ||
1414 | myIndices->SetValue(1,0); | |
1415 | Standard_Integer Count = 0; | |
1416 | Standard_Integer Index = 2; | |
1417 | ||
1418 | ||
1419 | exp.Init(Shells,TopAbs_SHELL); | |
1420 | for (; exp.More(); exp.Next()) { | |
0d969553 | 1421 | // CurS = the current Shell. |
7fd59977 | 1422 | const TopoDS_Shape CurS = exp.Current(); |
1423 | ||
1424 | TopExp_Explorer exp2(CurS, TopAbs_FACE); | |
1425 | for (; exp2.More(); exp2.Next()) { | |
0d969553 | 1426 | // CurF = the current face of the current Shell. |
7fd59977 | 1427 | const TopoDS_Shape CurF = exp2.Current(); |
1428 | ||
1429 | for ( i = 1; i <= NbFaces; i++) { | |
1430 | const TopoDS_Shape& Center = myCenters(i); | |
1431 | const TopoDS_Shape& Rakk = myMapSF(Center).Face(); | |
0d969553 | 1432 | // Rakk = the ith generated connection face |
7fd59977 | 1433 | if (CurF.IsEqual(Rakk)) { |
1434 | tmpMap.Add(Center); | |
1435 | Count++; | |
1436 | break; | |
1437 | } | |
1438 | } | |
1439 | } | |
1440 | myIndices->SetValue(Index, Count); | |
1441 | Index++; | |
1442 | } | |
1443 | ||
1444 | myCenters = tmpMap; | |
1445 | return myNbBranches; | |
1446 | } | |
1447 | ||
1448 | ||
1449 | //======================================================================= | |
1450 | //function : IndicesOfBranche | |
1451 | //purpose : | |
1452 | //======================================================================= | |
1453 | ||
1454 | void BiTgte_Blend::IndicesOfBranche | |
1455 | (const Standard_Integer Index, | |
1456 | Standard_Integer& From, | |
1457 | Standard_Integer& To ) const | |
1458 | { | |
0d969553 Y |
1459 | // Attention to the ranking in myIndices: |
1460 | // If the branches are 1-4 5-9 10-12, it is ranked in myIndices: | |
1461 | // 0 4 9 12 | |
7fd59977 | 1462 | From = myIndices->Value(Index) + 1; |
1463 | To = myIndices->Value(Index + 1); | |
1464 | } | |
1465 | ||
1466 | ||
1467 | //======================================================================= | |
1468 | //function : ComputeCenters | |
1469 | //purpose : | |
1470 | //======================================================================= | |
1471 | ||
1472 | void BiTgte_Blend::ComputeCenters() | |
1473 | { | |
1474 | // ------------ | |
0d969553 | 1475 | // Preanalyze. |
7fd59977 | 1476 | // ------------ |
1477 | Standard_Real TolAngle = 2*ASin(myTol/Abs(myRadius*0.5)); | |
1478 | myAnalyse.Perform(myShape,TolAngle); | |
1479 | ||
1480 | // ------------------------------------------ | |
0d969553 | 1481 | // calculate faces touched by caps |
7fd59977 | 1482 | // ------------------------------------------ |
1483 | TopTools_MapOfShape TouchedByCork; | |
1484 | Touched(myAnalyse, myStopFaces, myShape, TouchedByCork); | |
1485 | ||
1486 | // ----------------------- | |
0d969553 | 1487 | // init of the intersector |
7fd59977 | 1488 | // ----------------------- |
1489 | TopAbs_State Side = TopAbs_IN; | |
1490 | if (myRadius < 0.) Side = TopAbs_OUT; | |
1491 | BRepOffset_Inter3d Inter(myAsDes,Side,myTol); | |
1492 | ||
1155d05a | 1493 | TopTools_DataMapOfShapeBox MapSBox; |
7fd59977 | 1494 | TopTools_MapOfShape Done; |
975ec82a | 1495 | //TopTools_MapIteratorOfMapOfShape it; |
7fd59977 | 1496 | |
1497 | BRep_Builder B; | |
0d969553 | 1498 | TopoDS_Compound Co; // to only know on which edges the tubes are made |
7fd59977 | 1499 | B.MakeCompound(Co); |
1500 | ||
1501 | // ---------------------------------------- | |
0d969553 | 1502 | // Calculate Sections Face/Face + Propagation |
7fd59977 | 1503 | // ---------------------------------------- |
1504 | Standard_Boolean JenRajoute = Standard_True; | |
975ec82a J |
1505 | Standard_Integer i; |
1506 | ||
7fd59977 | 1507 | while ( JenRajoute) { |
1508 | JenRajoute = Standard_False; | |
1509 | ||
1510 | Standard_Boolean Fini = Standard_False; | |
1511 | ||
1512 | TopTools_DataMapOfShapeShape EdgeTgt; | |
1513 | ||
1514 | while ( !Fini) { | |
1515 | ||
1516 | // ------------------------------------------------- | |
0d969553 | 1517 | // locate in myFaces the Faces connected to myEdges. |
7fd59977 | 1518 | // ------------------------------------------------- |
1519 | Fini = Standard_True; | |
975ec82a J |
1520 | //for (it.Initialize(myEdges); it.More(); it.Next()) { |
1521 | for (i = 1; i <= myEdges.Extent(); i++) { | |
1522 | const TopoDS_Edge& E = TopoDS::Edge(myEdges(i)); | |
7fd59977 | 1523 | if (BRep_Tool::Degenerated(E)) continue; |
1524 | ||
1525 | const TopTools_ListOfShape& L = myAncestors.FindFromKey(E); | |
1526 | if ( L.Extent() == 1) { | |
0d969553 | 1527 | // So this is a free border onwhich the ball should roll. |
7fd59977 | 1528 | myFaces.Add(E); |
1529 | ||
0d969553 | 1530 | // set in myStopFaces to not propagate the tube on free border. |
7fd59977 | 1531 | myStopFaces.Add(E); |
1532 | } | |
1533 | else { | |
1534 | TopTools_ListIteratorOfListOfShape itl; | |
1535 | for (itl.Initialize(L); itl.More(); itl.Next()) { | |
1536 | const TopoDS_Shape& Sh = itl.Value(); | |
1537 | if ( !myStopFaces.Contains(Sh)) myFaces.Add(itl.Value()); | |
1538 | } | |
1539 | } | |
1540 | } | |
1541 | myEdges.Clear(); | |
1542 | ||
1543 | // -------------------------------------------- | |
0d969553 | 1544 | // Construction of Offsets of all faces. |
7fd59977 | 1545 | // -------------------------------------------- |
975ec82a J |
1546 | //for (it.Initialize(myFaces); it.More(); it.Next()) { |
1547 | for (i = 1; i <= myFaces.Extent(); i++) { | |
1548 | const TopoDS_Shape& AS = myFaces(i); | |
7fd59977 | 1549 | if ( myMapSF.IsBound(AS)) continue; |
1550 | ||
1551 | BRepOffset_Offset OF1; | |
1552 | TopoDS_Face BigF; | |
1553 | ||
1554 | if (AS.ShapeType() == TopAbs_FACE) { | |
975ec82a | 1555 | const TopoDS_Face& F = TopoDS::Face(myFaces(i)); |
7fd59977 | 1556 | if ( TouchedByCork.Contains(F)) { |
1557 | BRepOffset_Tool::EnLargeFace(F,BigF,Standard_True); | |
1558 | OF1.Init(BigF,myRadius,EdgeTgt); | |
1559 | } | |
1560 | else { | |
1561 | OF1.Init(F,myRadius,EdgeTgt); | |
1562 | } | |
1563 | } | |
0d969553 | 1564 | else { // So this is a Free Border edge on which the ball rolls. |
7fd59977 | 1565 | OF1.Init(TopoDS::Edge(AS),myRadius); |
1566 | } | |
1567 | ||
1568 | // ------------------------------------ | |
0d969553 | 1569 | // Increment the map of created tangents |
7fd59977 | 1570 | // ------------------------------------ |
1571 | TopTools_ListOfShape Let; | |
1572 | if ( AS.ShapeType() == TopAbs_FACE) { | |
1573 | myAnalyse.Edges(TopoDS::Face(AS),BRepOffset_Tangent,Let); | |
1574 | } | |
1575 | TopTools_ListIteratorOfListOfShape itlet(Let); | |
1576 | ||
1577 | for ( ; itlet.More(); itlet.Next()) { | |
1578 | const TopoDS_Edge& Cur = TopoDS::Edge(itlet.Value()); | |
1579 | if ( !EdgeTgt.IsBound(Cur)) { | |
1580 | TopoDS_Shape aLocalShape = OF1.Generated(Cur); | |
1581 | const TopoDS_Edge& OTE = TopoDS::Edge(aLocalShape); | |
1582 | // const TopoDS_Edge& OTE = TopoDS::Edge(OF1.Generated(Cur)); | |
1583 | EdgeTgt.Bind(Cur,OF1.Generated(Cur)); | |
1584 | TopoDS_Vertex V1,V2,OV1,OV2; | |
1585 | TopExp::Vertices (Cur,V1,V2); | |
1586 | TopExp::Vertices (OTE,OV1,OV2); | |
1587 | TopTools_ListOfShape LE; | |
1588 | if (!EdgeTgt.IsBound(V1)) { | |
1589 | myAnalyse.Edges(V1,BRepOffset_Tangent,LE); | |
1590 | const TopTools_ListOfShape& LA = myAnalyse.Ancestors(V1); | |
1591 | if (LE.Extent() == LA.Extent()) | |
1592 | EdgeTgt.Bind(V1,OV1); | |
1593 | } | |
1594 | if (!EdgeTgt.IsBound(V2)) { | |
1595 | LE.Clear(); | |
1596 | myAnalyse.Edges(V2,BRepOffset_Tangent,LE); | |
1597 | const TopTools_ListOfShape& LA = myAnalyse.Ancestors(V2); | |
1598 | if (LE.Extent() == LA.Extent()) | |
1599 | EdgeTgt.Bind(V2,OV2); | |
1600 | } | |
1601 | } | |
1602 | } | |
0d969553 | 1603 | // end of map created tangent |
7fd59977 | 1604 | |
1605 | if (OF1.Status() == BRepOffset_Reversed || | |
1606 | OF1.Status() == BRepOffset_Degenerated ) continue; | |
1607 | ||
1608 | const TopoDS_Face& F1 = OF1.Face(); | |
1609 | ||
0d969553 | 1610 | // increment S D |
7fd59977 | 1611 | myInitOffsetFace.SetRoot(AS); |
1612 | myInitOffsetFace.Bind(AS,F1); | |
1613 | ||
1614 | Bnd_Box Box1; | |
1615 | BRepBndLib::Add(F1,Box1); | |
1616 | MapSBox.Bind(F1,Box1); | |
1617 | ||
1618 | // --------------------------------------------- | |
0d969553 | 1619 | // intersection with all already created faces. |
7fd59977 | 1620 | // --------------------------------------------- |
1621 | Fini = !Intersect(AS,F1,MapSBox,OF1,Inter); | |
1622 | ||
1623 | if (AS.ShapeType() == TopAbs_FACE) B.Add(Co,AS); | |
1624 | ||
1625 | myMapSF.Bind(AS, OF1); | |
1626 | ||
1627 | } | |
1628 | } // end of : while ( !Fini) | |
1629 | ||
1630 | ||
1631 | //-------------------------------------------------------- | |
0d969553 Y |
1632 | // so the offsets were created and intersected. |
1633 | // now the tubes are constructed. | |
7fd59977 | 1634 | //-------------------------------------------------------- |
0d969553 | 1635 | // Construction of tubes on edge. |
7fd59977 | 1636 | //-------------------------------------------------------- |
1637 | BRepOffset_Type OT = BRepOffset_Convex; | |
1638 | if (myRadius < 0.) OT = BRepOffset_Concave; | |
1639 | ||
1640 | TopTools_IndexedDataMapOfShapeListOfShape Map; | |
1641 | TopExp::MapShapesAndAncestors(Co,TopAbs_EDGE,TopAbs_FACE,Map); | |
1642 | TopExp::MapShapesAndAncestors(Co,TopAbs_VERTEX,TopAbs_EDGE,Map); | |
1643 | ||
1644 | TopExp_Explorer exp(Co,TopAbs_EDGE); | |
1645 | for ( ; exp.More(); exp.Next()) { | |
1646 | const TopoDS_Edge& E = TopoDS::Edge(exp.Current()); | |
1647 | if ( myMapSF.IsBound(E)) continue; | |
1648 | ||
1649 | const TopTools_ListOfShape& Anc = Map.FindFromKey(E); | |
1650 | if (Anc.Extent() == 2) { | |
1651 | const BRepOffset_ListOfInterval& L = myAnalyse.Type(E); | |
1652 | if (!L.IsEmpty() && L.First().Type() == OT) { | |
51740958 | 1653 | TopoDS_Shape aLocalShapeGen = myMapSF(Anc.First()).Generated(E); |
1654 | TopoDS_Edge EOn1 = TopoDS::Edge(aLocalShapeGen); | |
1655 | aLocalShapeGen = myMapSF(Anc.Last()) .Generated(E); | |
1656 | TopoDS_Edge EOn2 = TopoDS::Edge(aLocalShapeGen); | |
7fd59977 | 1657 | // TopoDS_Edge EOn1 = TopoDS::Edge(myMapSF(Anc.First()).Generated(E)); |
1658 | // TopoDS_Edge EOn2 = TopoDS::Edge(myMapSF(Anc.Last()) .Generated(E)); | |
1659 | // find if exits tangent edges in the original shape | |
1660 | TopoDS_Edge E1f, E1l; | |
1661 | TopoDS_Vertex V1f, V1l; | |
1662 | TopExp::Vertices(E,V1f,V1l); | |
1663 | TopTools_ListOfShape TangE; | |
1664 | myAnalyse.TangentEdges(E,V1f,TangE); | |
1665 | // find if the pipe on the tangent edges are soon created. | |
1666 | TopTools_ListIteratorOfListOfShape itl(TangE); | |
1667 | Standard_Boolean Find = Standard_False; | |
1668 | for ( ; itl.More() && !Find; itl.Next()) { | |
1669 | if ( myMapSF.IsBound(itl.Value())) { | |
1670 | TopoDS_Shape aLocalShape = myMapSF(itl.Value()).Generated(V1f); | |
1671 | E1f = TopoDS::Edge(aLocalShape); | |
1672 | // E1f = TopoDS::Edge(myMapSF(itl.Value()).Generated(V1f)); | |
1673 | Find = Standard_True; | |
1674 | } | |
1675 | } | |
1676 | TangE.Clear(); | |
1677 | myAnalyse.TangentEdges(E,V1l,TangE); | |
1678 | // find if the pipe on the tangent edges are soon created. | |
1679 | itl.Initialize(TangE); | |
1680 | Find = Standard_False; | |
1681 | for ( ; itl.More() && !Find; itl.Next()) { | |
1682 | if ( myMapSF.IsBound(itl.Value())) { | |
1683 | TopoDS_Shape aLocalShape = myMapSF(itl.Value()).Generated(V1l); | |
1684 | E1l = TopoDS::Edge(aLocalShape); | |
1685 | // E1l = TopoDS::Edge(myMapSF(itl.Value()).Generated(V1l)); | |
1686 | Find = Standard_True; | |
1687 | } | |
1688 | } | |
1689 | BRepOffset_Offset OF1 (E,EOn1,EOn2,myRadius,E1f, E1l); | |
1690 | const TopoDS_Face& F1 = OF1.Face(); | |
1691 | ||
1692 | // maj S D | |
1693 | myInitOffsetFace.SetRoot(E); | |
1694 | myInitOffsetFace.Bind(E,F1); | |
1695 | ||
1696 | Bnd_Box Box1; | |
1697 | BRepBndLib::Add(F1,Box1); | |
1698 | MapSBox.Bind(F1,Box1); | |
1699 | ||
1700 | // --------------------------------------------- | |
0d969553 | 1701 | // intersection with all already created faces. |
7fd59977 | 1702 | // --------------------------------------------- |
1703 | Standard_Boolean IsOnRest = Intersect(E,F1,MapSBox,OF1,Inter); | |
1704 | JenRajoute = JenRajoute || IsOnRest; | |
1705 | ||
1706 | myMapSF.Bind(E,OF1); | |
1707 | } | |
1708 | } | |
1709 | } | |
1710 | ||
0d969553 | 1711 | } // end while JenRajoute |
7fd59977 | 1712 | |
1713 | ||
1714 | myEdges.Clear(); | |
1715 | myEdges = Inter.NewEdges(); | |
1716 | ||
1717 | // ------------------------------------------------------------------- | |
0d969553 Y |
1718 | // now it is necessary to limit edges on the neighbors (otherwise one |
1719 | // will go too far and will not be able to construct faces). | |
7fd59977 | 1720 | // ------------------------------------------------------------------- |
1721 | ||
0d969553 | 1722 | // Proceed with MakeLoops |
b0fbc579 | 1723 | TopTools_IndexedDataMapOfShapeListOfShape aDMVV; |
7fd59977 | 1724 | BRepOffset_Type OT = BRepOffset_Concave; |
1725 | if (myRadius < 0.) OT = BRepOffset_Convex; | |
1726 | ||
7fd59977 | 1727 | TopTools_ListOfShape LOF; |
975ec82a J |
1728 | //it.Initialize(myFaces); |
1729 | for (i = 1; i <= myFaces.Extent(); i++) { | |
1730 | const TopoDS_Shape& CurS = myFaces(i); | |
7fd59977 | 1731 | |
0d969553 | 1732 | // tube on free border, it is undesirable. |
7fd59977 | 1733 | if ( myStopFaces.Contains(CurS)) continue; |
1734 | ||
0d969553 | 1735 | if ( !myMapSF.IsBound(CurS)) continue; // inverted or degenerated |
7fd59977 | 1736 | |
1737 | const TopoDS_Face& CurOF = myMapSF(CurS).Face(); | |
1738 | LOF.Append(CurOF); | |
1739 | ||
1740 | if (CurS.ShapeType() == TopAbs_FACE) { | |
1741 | const TopoDS_Face& CurF = TopoDS::Face(CurS); | |
1742 | TopExp_Explorer expe(CurF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
1743 | for (; expe.More(); expe.Next()) { | |
1744 | // -------------------------------------------------------------- | |
0d969553 Y |
1745 | // set in myAsDes the edges generated by limitations of the |
1746 | // initial square if the type is correct (The edges that will | |
1747 | // disappear are not set) | |
7fd59977 | 1748 | // -------------------------------------------------------------- |
1749 | const TopoDS_Edge& CurE = TopoDS::Edge(expe.Current()); | |
1750 | const BRepOffset_ListOfInterval& L = myAnalyse.Type(CurE); | |
1751 | if (!L.IsEmpty() && L.First().Type() != OT) { | |
0d969553 | 1752 | // a priori doe s not disappear, so it is set |
7fd59977 | 1753 | TopoDS_Shape aLocalShape = myMapSF(CurF).Generated(CurE); |
1754 | const TopoDS_Edge& CurOE = TopoDS::Edge(aLocalShape); | |
1755 | // const TopoDS_Edge& CurOE = | |
1756 | // TopoDS::Edge(myMapSF(CurF).Generated(CurE)); | |
1757 | myAsDes->Add(CurOF,CurOE.Oriented(CurE.Orientation())); | |
1758 | } | |
1759 | else { | |
1760 | const TopTools_ListOfShape& Lanc = myAnalyse.Ancestors(CurE); | |
1761 | if ( !myFaces .Contains(Lanc.First()) | |
1762 | || !myFaces .Contains(Lanc.Last ()) | |
1763 | || myStopFaces.Contains(Lanc.First()) | |
1764 | || myStopFaces.Contains(Lanc.Last ())) { | |
1765 | TopoDS_Shape aLocalShape = myMapSF(CurF).Generated(CurE); | |
1766 | const TopoDS_Edge& CurOE = TopoDS::Edge(aLocalShape); | |
1767 | // const TopoDS_Edge& CurOE = | |
1768 | // TopoDS::Edge(myMapSF(CurF).Generated(CurE)); | |
1769 | myAsDes->Add(CurOF,CurOE.Oriented(CurE.Orientation())); | |
1770 | } | |
1771 | } | |
1772 | } | |
1773 | BRepOffset_Inter2d::Compute(myAsDes, | |
1774 | CurOF, | |
1775 | myEdges, | |
b0fbc579 | 1776 | myTol, |
1777 | aDMVV); | |
7fd59977 | 1778 | } |
1779 | } | |
1780 | ||
1781 | // ---------------------------------------------------------------- | |
0d969553 Y |
1782 | // It is also required to make 2D intersections with generated tubes |
1783 | // (Useful for unwinding) | |
7fd59977 | 1784 | // ---------------------------------------------------------------- |
1785 | BRepOffset_DataMapIteratorOfDataMapOfShapeOffset It(myMapSF); | |
1786 | for ( ; It.More(); It.Next()) { | |
1787 | const TopoDS_Shape& CurS = It.Key(); | |
1788 | if ( CurS.ShapeType() == TopAbs_FACE) continue; | |
1789 | ||
1790 | const TopoDS_Face& CurOF = It.Value().Face(); | |
1791 | ||
0d969553 | 1792 | // no unwinding by tubes on free border. |
7fd59977 | 1793 | if ( myStopFaces.Contains(CurS)) continue; |
1794 | ||
1795 | LOF.Append(CurOF); | |
1796 | ||
1797 | // -------------------------------------------------------------- | |
0d969553 | 1798 | // set in myAsDes the edge restrictions of the square |
7fd59977 | 1799 | // -------------------------------------------------------------- |
1800 | TopExp_Explorer expe(CurOF.Oriented(TopAbs_FORWARD),TopAbs_EDGE); | |
1801 | for (; expe.More(); expe.Next()) { | |
1802 | const TopoDS_Edge& CurOE = TopoDS::Edge(expe.Current()); | |
1803 | myAsDes->Add(CurOF,CurOE); | |
1804 | } | |
1805 | ||
1806 | BRepOffset_Inter2d::Compute(myAsDes, | |
1807 | CurOF, | |
1808 | myEdges, | |
b0fbc579 | 1809 | myTol, |
1810 | aDMVV); | |
7fd59977 | 1811 | } |
b0fbc579 | 1812 | // |
1813 | // fuse vertices on edges stored in AsDes | |
1814 | BRepOffset_Inter2d::FuseVertices(aDMVV, myAsDes); | |
7fd59977 | 1815 | // ------------ |
0d969553 | 1816 | // unwinding |
7fd59977 | 1817 | // ------------ |
1818 | BRepOffset_MakeLoops MakeLoops; | |
1819 | MakeLoops.Build( LOF, myAsDes, myImageOffset ); | |
1820 | ||
1821 | // ------------------------------------------------------------ | |
0d969553 Y |
1822 | // It is possible to unwind edges at least one ancestor which of |
1823 | // is a face of the initial shape, so: | |
1824 | // the edges generated by intersection tube-tube are missing | |
7fd59977 | 1825 | // ------------------------------------------------------------ |
1826 | ||
1827 | // -------------------------------------------------------------- | |
0d969553 | 1828 | // Currently set the unwinded surfaces in <myResult> |
7fd59977 | 1829 | // -------------------------------------------------------------- |
1830 | B.MakeCompound(TopoDS::Compound(myResult)); | |
1831 | TopTools_ListIteratorOfListOfShape itLOF(LOF); | |
1832 | for ( ; itLOF.More(); itLOF.Next()) { | |
1833 | const TopoDS_Shape& CurLOF = itLOF.Value(); | |
1834 | ||
1835 | if ( !myImageOffset.HasImage(CurLOF)) | |
1836 | continue; | |
1837 | ||
1838 | TopTools_ListOfShape Lim; | |
1839 | myImageOffset.LastImage(CurLOF,Lim); | |
1840 | TopTools_ListIteratorOfListOfShape itLim(Lim); | |
1841 | for ( ;itLim.More(); itLim.Next()) { | |
0d969553 | 1842 | // If a face is its own image, it is not set |
7fd59977 | 1843 | const TopoDS_Shape& CurLIM = itLim.Value(); |
1844 | if (CurLIM.IsSame(CurLOF)) break; | |
1845 | ||
1846 | B.Add(myResult,CurLIM); | |
1847 | } | |
1848 | } | |
1849 | ||
0797d9d3 | 1850 | #ifdef OCCT_DEBUG |
7fd59977 | 1851 | if ( myResult.IsNull()) { |
0d969553 | 1852 | cout << " No Lines of Generated Centers" << endl; |
7fd59977 | 1853 | } |
1854 | #ifdef DRAW | |
1855 | else { | |
0d969553 | 1856 | if (Affich) DBRep::Set("Unwind",myResult); |
7fd59977 | 1857 | } |
1858 | #endif | |
1859 | #endif | |
1860 | } | |
1861 | ||
1862 | ||
1863 | //======================================================================= | |
1864 | //function : ComputeSurfaces | |
1865 | //purpose : | |
1866 | //======================================================================= | |
1867 | ||
1868 | void BiTgte_Blend::ComputeSurfaces() | |
1869 | { | |
0d969553 | 1870 | // set in myFaces, the faces actually implied in the connection |
7fd59977 | 1871 | myFaces.Clear(); |
1872 | ||
0d969553 Y |
1873 | // construct |
1874 | // 1 - Tubes (True Fillets) | |
1875 | // 2 - Spheres. | |
7fd59977 | 1876 | |
1877 | #ifdef DRAW | |
1878 | Standard_Integer nbc = 1; | |
1879 | #endif | |
1880 | ||
1881 | TopTools_ListOfShape Empty; | |
1882 | TopTools_DataMapOfShapeListOfShape EmptyMap; | |
1883 | ||
1884 | Handle(Geom_Surface) GS1, GS2; | |
1885 | Handle(Geom_Curve) GC1, GC2; | |
1886 | ||
1887 | Standard_Real TolAngle = 2*ASin(myTol/Abs(myRadius*0.5)); | |
1888 | BRepOffset_Analyse CenterAnalyse(myResult,TolAngle); | |
1889 | ||
1890 | // ----------------------------------------------------- | |
0d969553 | 1891 | // Construction of tubes in myResult |
7fd59977 | 1892 | // ----------------------------------------------------- |
1893 | BRep_Builder B; | |
1894 | B.MakeCompound(TopoDS::Compound(myResult)); | |
1895 | ||
1896 | // -------------------------------------------------------------------- | |
0d969553 Y |
1897 | // Dummy: for construction of spheres: |
1898 | // Set in Co the center line, then it there are at least 3 | |
1899 | // center lines sharing the same vertex, Sphere on this vertex. | |
7fd59977 | 1900 | // -------------------------------------------------------------------- |
1901 | TopoDS_Compound Co; | |
1902 | B.MakeCompound(Co); | |
1903 | ||
1904 | // -------------------------------------------------------------------- | |
0d969553 Y |
1905 | // Iteration on the edges lines of center |
1906 | // and their valid valid part is taken after cut and tube construction. | |
7fd59977 | 1907 | // -------------------------------------------------------------------- |
7fd59977 | 1908 | |
975ec82a J |
1909 | //TopTools_MapIteratorOfMapOfShape ic(myEdges); |
1910 | Standard_Integer i; | |
1911 | for (i = 1; i <= myEdges.Extent(); i++) { | |
1912 | const TopoDS_Edge& CurE = TopoDS::Edge(myEdges(i)); | |
7fd59977 | 1913 | |
1914 | const TopTools_ListOfShape& L = myAsDes->Ascendant(CurE); | |
1915 | if ( L.Extent() != 2) continue; | |
1916 | ||
1917 | // -------------------------------------------------------------- | |
0d969553 | 1918 | // F1 and F2 = 2 parallel faces intersecting in CurE. |
7fd59977 | 1919 | // -------------------------------------------------------------- |
1920 | const TopoDS_Face& F1 = TopoDS::Face(L.First()); | |
1921 | const TopoDS_Face& F2 = TopoDS::Face(L.Last()); | |
1922 | ||
1923 | // ----------------------------------------------------- | |
0d969553 Y |
1924 | // find the orientation of edges of intersection |
1925 | // in the initial faces. | |
7fd59977 | 1926 | // ----------------------------------------------------- |
1927 | const TopTools_ListOfShape& LD1 = myAsDes->Descendant(F1); | |
1928 | const TopTools_ListOfShape& LD2 = myAsDes->Descendant(F2); | |
1929 | ||
1930 | TopAbs_Orientation Orien1 = Orientation(CurE, F1, LD1); | |
1931 | TopAbs_Orientation Orien2 = Orientation(CurE, F2, LD2); | |
1932 | ||
1933 | // --------------------------------------------------------- | |
0d969553 | 1934 | // Or1 and Or2 : the shapes generators of parallel faces |
7fd59977 | 1935 | // --------------------------------------------------------- |
1936 | const TopoDS_Shape& Or1 = myInitOffsetFace.ImageFrom(F1); | |
1937 | const TopoDS_Shape& Or2 = myInitOffsetFace.ImageFrom(F2); | |
1938 | ||
1939 | myFaces.Add(Or1); | |
1940 | myFaces.Add(Or2); | |
1941 | ||
1942 | TopoDS_Edge OE1, OE2; | |
1943 | TopoDS_Face OF1, OF2; | |
1944 | TopLoc_Location Loc; | |
1945 | Standard_Real f1,l1,f2,l2; | |
1946 | ||
1947 | Standard_Boolean OF1isEdge = Standard_False; | |
1948 | ||
1949 | if ( Or1.ShapeType() == TopAbs_EDGE) { | |
1950 | OF1isEdge = Standard_True; | |
1951 | OE1 = TopoDS::Edge(Or1); | |
1952 | GC1 = BRep_Tool::Curve(OE1,Loc,f1,l1); | |
1953 | GC1 = | |
1954 | Handle(Geom_Curve)::DownCast(GC1->Transformed(Loc.Transformation())); | |
1955 | } | |
1956 | else if ( Or1.ShapeType() == TopAbs_FACE) { | |
1957 | OF1 = TopoDS::Face(Or1); | |
1958 | GS1 = BRep_Tool::Surface(OF1); | |
1959 | } | |
1960 | ||
1961 | // ---------------------------------------------------------------- | |
0d969553 Y |
1962 | // If a vertex is used in contact, currently nothing is done |
1963 | // and the vertexes are not managed (Intersections with sphere); | |
7fd59977 | 1964 | // ---------------------------------------------------------------- |
1965 | if ( OF1.IsNull() && OE1.IsNull()) continue; | |
1966 | ||
1967 | Standard_Boolean OF2isEdge = Standard_False; | |
1968 | ||
1969 | if ( Or2.ShapeType() == TopAbs_EDGE) { | |
1970 | OF2isEdge = Standard_True; | |
1971 | OE2 = TopoDS::Edge(Or2); | |
1972 | GC2 = BRep_Tool::Curve(OE2,Loc,f2,l2); | |
1973 | GC2 = | |
1974 | Handle(Geom_Curve):: | |
1975 | DownCast(GC2->Transformed(Loc.Transformation())); | |
1976 | } | |
1977 | else if ( Or2.ShapeType() == TopAbs_FACE) { | |
1978 | OF2 = TopoDS::Face(Or2); | |
1979 | GS2 = BRep_Tool::Surface(OF2); | |
1980 | } | |
1981 | // ---------------------------------------------------------------- | |
0d969553 Y |
1982 | // If a vertex is used in contact, currently nothing is done |
1983 | // and the vertexes are not managed (Intersections with sphere); | |
7fd59977 | 1984 | // ---------------------------------------------------------------- |
1985 | if ( OF2.IsNull() && OE2.IsNull()) continue; | |
1986 | ||
1987 | ||
1988 | TopTools_ListOfShape CurL; | |
1989 | ||
0d969553 Y |
1990 | if ( !myImageOffset.HasImage(CurE)) {// the tubes are not unwinded |
1991 | if ( OF1isEdge && OF2isEdge) { // if I don't have the image, possibly | |
1992 | CurL.Append(CurE); // I'm on intersection tube-tube | |
1993 | } // See comment on the call to | |
7fd59977 | 1994 | else // MakeLoops |
1995 | continue; | |
1996 | } | |
1997 | else { | |
1998 | myImageOffset.LastImage(CurE,CurL); | |
1999 | } | |
2000 | ||
2001 | // --------------------------------------------------------------- | |
0d969553 | 2002 | // CurL = List of edges descending from CurE ( = Cuts of CurE) |
7fd59977 | 2003 | // --------------------------------------------------------------- |
2004 | TopTools_ListIteratorOfListOfShape itl(CurL); | |
2005 | for ( ; itl.More(); itl.Next()) { | |
2006 | const TopoDS_Edge& CurCutE = TopoDS::Edge(itl.Value()); | |
2007 | ||
2008 | Handle(Geom2d_Curve) PC1 = | |
2009 | BRep_Tool::CurveOnSurface(CurCutE,F1,f1,l1); | |
2010 | Handle(Geom2d_Curve) PC2 = | |
2011 | BRep_Tool::CurveOnSurface(CurCutE,F2,f2,l2); | |
2012 | if ( PC1.IsNull() || PC2.IsNull()) { | |
0797d9d3 | 2013 | #ifdef OCCT_DEBUG |
0d969553 | 2014 | cout << "No PCurves on Intersections : No tubes constructed"; |
7fd59977 | 2015 | cout << endl; |
2016 | #endif | |
2017 | continue; | |
2018 | } | |
2019 | ||
2020 | TopoDS_Edge E1f, E1l; | |
2021 | TopoDS_Vertex V1f, V1l; | |
2022 | TopoDS_Vertex VfOnE1,VlOnE1,VfOnE2,VlOnE2; | |
2023 | TopTools_ListOfShape TangE; | |
2024 | TopTools_MapOfShape MapOnV1f, MapOnV1l; | |
2025 | ||
2026 | TopExp::Vertices(CurCutE,V1f,V1l); | |
2027 | ||
2028 | // find if the pipe on the tangent edges are soon created. | |
0d969553 | 2029 | // edges generated by V1f and V1l + Maj MapOnV1f/l |
7fd59977 | 2030 | E1f = FindCreatedEdge(V1f,CurCutE,myMapSF,MapOnV1f, |
2031 | CenterAnalyse,myRadius,myTol); | |
2032 | ||
2033 | E1l = FindCreatedEdge(V1l,CurCutE,myMapSF,MapOnV1l, | |
2034 | CenterAnalyse,myRadius,myTol); | |
2035 | ||
2036 | TopoDS_Edge E1, E2; | |
2037 | if ( OF1isEdge) { | |
2038 | BiTgte_CurveOnEdge ConE(CurCutE, OE1); | |
2039 | Handle(Geom_Curve) C = MakeCurve(ConE); | |
2040 | gp_Pnt P1 = C->Value(C->FirstParameter()); | |
2041 | gp_Pnt P2 = C->Value(C->LastParameter()); | |
2042 | VfOnE1 = FindVertex(P1,MapOnV1f,myTol); | |
2043 | if ( VfOnE1.IsNull()) | |
2044 | VfOnE1 = FindVertex(P1,MapOnV1l,myTol); | |
2045 | VlOnE1 = FindVertex(P2,MapOnV1l,myTol); | |
2046 | if ( VlOnE1.IsNull()) | |
2047 | VlOnE1 = FindVertex(P2,MapOnV1f,myTol); | |
2048 | if ( P1.SquareDistance(P2) < myTol*myTol) { | |
0d969553 Y |
2049 | //BRepOffset_Offset manages degenerated KPart |
2050 | //It is REQUIRED that C should be a circle with ZERO radius | |
7fd59977 | 2051 | E1 = MakeDegeneratedEdge(C,VfOnE1); |
2052 | } | |
2053 | else { | |
2054 | E1 = BRepLib_MakeEdge(C,VfOnE1,VlOnE1); | |
2055 | } | |
2056 | } | |
2057 | else { | |
2058 | gp_Pnt2d P2d; | |
2059 | P2d = PC1->Value(f1); | |
2060 | gp_Pnt P1 = GS1->Value(P2d.X(),P2d.Y()); | |
2061 | P2d = PC1->Value(l1); | |
2062 | gp_Pnt P2 = GS1->Value(P2d.X(),P2d.Y()); | |
2063 | VfOnE1 = FindVertex(P1,MapOnV1f,myTol); | |
2064 | VlOnE1 = FindVertex(P2,MapOnV1l,myTol); | |
2065 | BRepLib_MakeEdge MKE(PC1,GS1,VfOnE1,VlOnE1,f1,l1); | |
2066 | if (MKE.IsDone()) | |
2067 | E1 = MKE.Edge(); | |
2068 | else { | |
2069 | cout << "Edge Not Done" << endl; | |
2070 | E1 = MKE.Edge(); | |
2071 | } | |
2072 | ||
2073 | KPartCurve3d(E1,PC1,GS1); | |
2074 | } | |
2075 | ||
2076 | if ( OF2isEdge) { | |
2077 | BiTgte_CurveOnEdge ConE(CurCutE, OE2); | |
2078 | Handle(Geom_Curve) C = MakeCurve(ConE); | |
2079 | gp_Pnt P1 = C->Value(C->FirstParameter()); | |
2080 | gp_Pnt P2 = C->Value(C->LastParameter()); | |
2081 | VfOnE2 = FindVertex(P1,MapOnV1f,myTol); | |
2082 | if ( VfOnE2.IsNull()) | |
2083 | VfOnE2 = FindVertex(P1,MapOnV1l,myTol); | |
2084 | VlOnE2 = FindVertex(P2,MapOnV1l,myTol); | |
2085 | if ( VlOnE2.IsNull()) | |
2086 | VlOnE2 = FindVertex(P2,MapOnV1f,myTol); | |
2087 | if ( P1.SquareDistance(P2) < myTol*myTol) { | |
0d969553 Y |
2088 | //BRepOffset_Offset manages degenerated KParts |
2089 | //It is REQUIRED that C should be a circle with ZERO radius | |
7fd59977 | 2090 | E2 = MakeDegeneratedEdge(C,VfOnE2); |
2091 | } | |
2092 | else { | |
2093 | E2 = BRepLib_MakeEdge(C,VfOnE2,VlOnE2); | |
2094 | } | |
2095 | } | |
2096 | else { | |
2097 | gp_Pnt2d P2d; | |
2098 | P2d = PC2->Value(f2); | |
2099 | gp_Pnt P1 = GS2->Value(P2d.X(),P2d.Y()); | |
2100 | P2d = PC2->Value(l2); | |
2101 | gp_Pnt P2 = GS2->Value(P2d.X(),P2d.Y()); | |
2102 | VfOnE2 = FindVertex(P1,MapOnV1f,myTol); | |
2103 | VlOnE2 = FindVertex(P2,MapOnV1l,myTol); | |
2104 | BRepLib_MakeEdge MKE(PC2,GS2,VfOnE2,VlOnE2,f2,l2); | |
2105 | if (MKE.IsDone()) | |
2106 | E2 = MKE.Edge(); | |
2107 | else { | |
2108 | cout << "edge not Done" << endl; | |
2109 | E2 = MKE.Edge(); | |
2110 | } | |
2111 | KPartCurve3d(E2,PC2,GS2); | |
2112 | } | |
0d969553 | 2113 | // Increment of the Map of Created if reconstruction of the Shape is required |
7fd59977 | 2114 | if ( myBuildShape) { |
2115 | myCreated.Bind(CurCutE,EmptyMap); | |
2116 | ||
2117 | myCreated(CurCutE).Bind(Or1,Empty); | |
2118 | myCreated(CurCutE)(Or1).Append(E1); | |
2119 | ||
2120 | myCreated(CurCutE).Bind(Or2,Empty); | |
2121 | myCreated(CurCutE)(Or2).Append(E2); | |
2122 | } | |
2123 | ||
2124 | // ---------------------------------------------------------- | |
2125 | // try to init E1f, E1l, if not found with Analysis. | |
0d969553 Y |
2126 | // Should happen only if the THEORETICALLY tangent edges |
2127 | // are not actually tangent ( Cf: Approximation of lines | |
2128 | // of intersection that add noise.) | |
7fd59977 | 2129 | // ---------------------------------------------------------- |
51740958 | 2130 | TopoDS_Vertex aVertex1, aVertex2; |
7fd59977 | 2131 | if ( E1f.IsNull() && !VfOnE1.IsNull() && !VfOnE2.IsNull()) { |
2132 | TopTools_MapIteratorOfMapOfShape it(MapOnV1f); | |
2133 | for ( ; it.More(); it.Next()) { | |
2134 | const TopoDS_Edge& E = TopoDS::Edge(it.Key()); | |
2135 | if ( !E.IsNull()) { | |
51740958 | 2136 | TopExp::Vertices(E, aVertex1, aVertex2); |
2137 | if ((aVertex1.IsSame(VfOnE1) && aVertex2.IsSame(VfOnE2)) || | |
2138 | (aVertex2.IsSame(VfOnE1) && aVertex1.IsSame(VfOnE2)) ) { | |
7fd59977 | 2139 | E1f = E; |
2140 | break; | |
2141 | } | |
2142 | } | |
2143 | } | |
2144 | } | |
2145 | if ( E1l.IsNull() && !VlOnE1.IsNull() && !VlOnE2.IsNull()) { | |
2146 | TopTools_MapIteratorOfMapOfShape it(MapOnV1l); | |
2147 | for ( ; it.More(); it.Next()) { | |
2148 | const TopoDS_Edge& E = TopoDS::Edge(it.Key()); | |
2149 | if ( !E.IsNull()) { | |
51740958 | 2150 | TopExp::Vertices(E, aVertex1, aVertex2); |
2151 | if ((aVertex1.IsSame(VlOnE1) && aVertex2.IsSame(VlOnE2)) || | |
2152 | (aVertex2.IsSame(VlOnE1) && aVertex1.IsSame(VlOnE2)) ) { | |
7fd59977 | 2153 | E1l = E; |
2154 | break; | |
2155 | } | |
2156 | } | |
2157 | } | |
2158 | } | |
2159 | ||
2160 | E1.Orientation(Orien1); | |
2161 | E2.Orientation(Orien2); | |
2162 | ||
2163 | BRepOffset_Offset AnOffset(CurCutE,E1,E2,-myRadius,E1f,E1l, | |
2164 | myNubs, myTol, GeomAbs_C2); | |
2165 | myMapSF.Bind(CurCutE,AnOffset); | |
2166 | myCenters.Add(CurCutE); | |
2167 | B.Add(Co, CurCutE); | |
2168 | ||
2169 | const TopoDS_Face& Tuyo = AnOffset.Face(); | |
2170 | B.Add(myResult,Tuyo); | |
2171 | ||
2172 | if ( myBuildShape) { | |
0d969553 Y |
2173 | // method based ONLY on the construction of fillet: |
2174 | // the first edge of the tube is exactly on Shape1. | |
7fd59977 | 2175 | GeomAPI_ProjectPointOnCurve Projector; |
2176 | TopExp_Explorer exp(Tuyo,TopAbs_EDGE); | |
2177 | TopoDS_Vertex V1,V2; | |
0d969553 | 2178 | if (OF1isEdge) { // Update CutEdges. |
7fd59977 | 2179 | const TopoDS_Edge& EOnF1 = TopoDS::Edge(exp.Current()); |
2180 | TopExp::Vertices(EOnF1,V1,V2); | |
2181 | ||
2182 | gp_Pnt P1 = BRep_Tool::Pnt(V1); | |
2183 | Projector.Init(P1,GC1); | |
2184 | Standard_Real U1 = Projector.LowerDistanceParameter(); | |
2185 | ||
2186 | gp_Pnt P2 = BRep_Tool::Pnt(V2); | |
2187 | Projector.Init(P2,GC1); | |
2188 | Standard_Real U2 = Projector.LowerDistanceParameter(); | |
2189 | ||
2190 | TopoDS_Shape aLocalShape = V1.Oriented(TopAbs_INTERNAL); | |
2191 | B.UpdateVertex(TopoDS::Vertex(aLocalShape),U1,TopoDS::Edge(Or1),myTol); | |
2192 | aLocalShape = V2.Oriented(TopAbs_INTERNAL); | |
2193 | B.UpdateVertex(TopoDS::Vertex(aLocalShape),U2,TopoDS::Edge(Or1),myTol); | |
2194 | // B.UpdateVertex(TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)),U1, | |
2195 | // TopoDS::Edge(Or1),myTol); | |
2196 | // B.UpdateVertex(TopoDS::Vertex(V2.Oriented(TopAbs_INTERNAL)),U2, | |
2197 | // TopoDS::Edge(Or1),myTol); | |
2198 | ||
2199 | if (!myCutEdges.IsBound(Or1)) { | |
2200 | TopTools_ListOfShape Dummy; | |
2201 | myCutEdges.Bind(Or1,Dummy); | |
2202 | } | |
2203 | TopTools_ListOfShape& L1 = myCutEdges(Or1); | |
2204 | L1.Append(V1); L1.Append(V2); | |
2205 | } | |
0d969553 | 2206 | if (OF2isEdge) { // Update CutEdges. |
7fd59977 | 2207 | exp.Next(); |
2208 | const TopoDS_Edge& EOnF2 = TopoDS::Edge(exp.Current()); | |
2209 | TopExp::Vertices(EOnF2,V1,V2);; | |
2210 | ||
2211 | gp_Pnt P1 = BRep_Tool::Pnt(V1); | |
2212 | Projector.Init(P1,GC2); | |
2213 | Standard_Real U1 = Projector.LowerDistanceParameter(); | |
2214 | ||
2215 | gp_Pnt P2 = BRep_Tool::Pnt(V2); | |
2216 | Projector.Init(P2,GC2); | |
2217 | Standard_Real U2 = Projector.LowerDistanceParameter(); | |
2218 | ||
2219 | TopoDS_Shape aLocalShape = V1.Oriented(TopAbs_INTERNAL); | |
2220 | B.UpdateVertex(TopoDS::Vertex(aLocalShape),U1,TopoDS::Edge(Or2),myTol); | |
2221 | aLocalShape = V2.Oriented(TopAbs_INTERNAL); | |
2222 | B.UpdateVertex(TopoDS::Vertex(aLocalShape),U2,TopoDS::Edge(Or2),myTol); | |
2223 | // B.UpdateVertex(TopoDS::Vertex(V1.Oriented(TopAbs_INTERNAL)),U1, | |
2224 | // TopoDS::Edge(Or2),myTol); | |
2225 | // B.UpdateVertex(TopoDS::Vertex(V2.Oriented(TopAbs_INTERNAL)),U2, | |
2226 | // TopoDS::Edge(Or2),myTol); | |
2227 | ||
2228 | if (!myCutEdges.IsBound(Or2)) { | |
2229 | TopTools_ListOfShape Dummy; | |
2230 | myCutEdges.Bind(Or2,Dummy); | |
2231 | } | |
2232 | TopTools_ListOfShape& L2 = myCutEdges(Or2); | |
2233 | L2.Append(V1); L2.Append(V2); | |
2234 | } | |
2235 | } | |
2236 | ||
2237 | #ifdef DRAW | |
2238 | if ( Affich) { | |
2239 | sprintf(name,"%s_%d","SURF",nbc); | |
2240 | DBRep::Set(name,AnOffset.Face()); | |
2241 | nbc++; | |
2242 | } | |
2243 | #endif | |
2244 | } | |
2245 | } | |
2246 | ||
2247 | // --------------------------------------------------- | |
0d969553 Y |
2248 | // Construction of spheres, |
2249 | // if enough tubes arrive at the vertex | |
7fd59977 | 2250 | // --------------------------------------------------- |
2251 | TopTools_IndexedDataMapOfShapeListOfShape Map; | |
2252 | TopExp::MapShapesAndAncestors(Co,TopAbs_VERTEX,TopAbs_EDGE,Map); | |
51740958 | 2253 | |
2254 | for ( Standard_Integer j = 1; j <= Map.Extent(); j++) { | |
2255 | const TopoDS_Vertex& V = TopoDS::Vertex(Map.FindKey(j)); | |
2256 | if ( Map(j).Extent() != 3) continue; | |
7fd59977 | 2257 | |
2258 | TopTools_ListOfShape LOE; | |
2259 | TopTools_ListIteratorOfListOfShape it; | |
2260 | ||
51740958 | 2261 | for (it.Initialize(Map(j)) ; it.More(); it.Next()) { |
7fd59977 | 2262 | Standard_Boolean Reverse = Standard_True; |
2263 | if ( Reverse) | |
2264 | LOE.Append(myMapSF(it.Value()).Generated(V).Reversed()); | |
2265 | else | |
2266 | LOE.Append(myMapSF(it.Value()).Generated(V)); | |
2267 | } | |
2268 | ||
2269 | BRepOffset_Offset OFT(V,LOE,-myRadius,myNubs, myTol, GeomAbs_C2); | |
2270 | myMapSF.Bind(V,OFT); | |
2271 | myCenters.Add(V); | |
2272 | ||
2273 | B.Add(myResult,OFT.Face()); | |
2274 | ||
2275 | #ifdef DRAW | |
2276 | if (Affich) { | |
2277 | sprintf(name,"%s_%d","SURF",nbc); | |
2278 | DBRep::Set(name,OFT.Face()); | |
2279 | nbc++; | |
2280 | } | |
2281 | #endif | |
2282 | } | |
2283 | } | |
2284 | ||
2285 | ||
2286 | //======================================================================= | |
2287 | //function : ComputeShape | |
2288 | //purpose : | |
2289 | //======================================================================= | |
2290 | #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx> | |
ec357c5c | 2291 | #include <Geom_Curve.hxx> |
7fd59977 | 2292 | |
2293 | void BiTgte_Blend::ComputeShape() | |
2294 | { | |
0d969553 Y |
2295 | // Find in the initial Shapel: |
2296 | // - untouched Faces | |
2297 | // - generated tubes | |
2298 | // - the faces neighbors of tubes that sould be reconstucted preserving sharing. | |
7fd59977 | 2299 | |
0d969553 | 2300 | // For Debug : Visualize edges of the initial shape that should be reconstructed. |
7fd59977 | 2301 | #ifdef DRAW |
2302 | if (Affich) { | |
2303 | TopTools_DataMapIteratorOfDataMapOfShapeListOfShape itm(myCutEdges); | |
2304 | Standard_Integer NbEdges = 0; | |
2305 | for ( ; itm.More(); itm.Next()) { | |
2306 | const TopoDS_Edge& E = TopoDS::Edge(itm.Key()); | |
2307 | const TopTools_ListOfShape& VonE = itm.Value(); | |
2308 | TopTools_ListOfShape NewE; | |
2309 | ||
2310 | CutEdge(E,VonE,NewE); | |
2311 | for (TopTools_ListIteratorOfListOfShape it(NewE); it.More(); it.Next()) { | |
2312 | sprintf(name,"%s_%d","CUTE",++NbEdges); | |
2313 | DBRep::Set(name,it.Value()); | |
2314 | } | |
2315 | } | |
2316 | } | |
2317 | #endif | |
0d969553 | 2318 | // end debug |
7fd59977 | 2319 | |
2320 | // | |
0d969553 | 2321 | // modify the tubes on edge for partition of edges. |
7fd59977 | 2322 | // |
2323 | Standard_Integer NbS = NbSurfaces(); | |
7fd59977 | 2324 | for (Standard_Integer i = 1; i <= NbS; i++) { |
2325 | const TopoDS_Shape& S1 = SupportShape1(i); | |
2326 | ||
2327 | if ( S1.ShapeType() == TopAbs_EDGE) { | |
2328 | const TopoDS_Edge& E1 = TopoDS::Edge(S1); | |
0d969553 Y |
2329 | // it is required to replace in F the cut edges of E1, that |
2330 | // represent CutE | |
7fd59977 | 2331 | const TopTools_ListOfShape& VonE = myCutEdges(E1); |
2332 | TopTools_ListOfShape NewE; | |
2333 | CutEdge(E1,VonE,NewE); | |
2334 | ||
2335 | } | |
2336 | } | |
2337 | ||
2338 | ||
2339 | TopTools_DataMapOfShapeShape Created; | |
2340 | ||
2341 | TopTools_ListOfShape Empty; | |
2342 | TopTools_DataMapOfShapeListOfShape EmptyMap; | |
2343 | ||
2344 | BRep_Builder B; | |
2345 | ||
7fd59977 | 2346 | |
0d969553 Y |
2347 | // Maj of the Map of created. |
2348 | // Update edges that do not change in the resulting shape | |
2349 | // i.e. invariant edges in the unwinding. | |
7fd59977 | 2350 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
2351 | // Standard_Integer nbe = 1; | |
2352 | for ( ;exp.More(); exp.Next()) { | |
2353 | ||
2354 | const TopoDS_Face& CurF = TopoDS::Face(exp.Current()); | |
2355 | ||
0d969553 | 2356 | if ( !myFaces.Contains(CurF)) continue; // so the face is not touched |
7fd59977 | 2357 | |
0d969553 Y |
2358 | // so the faces are unwinded |
2359 | if ( !myMapSF.IsBound(CurF)) continue; // inverted or degenerated | |
7fd59977 | 2360 | |
2361 | const BRepOffset_Offset& Offset = myMapSF(CurF); | |
2362 | const TopoDS_Face& CurOF = myMapSF(CurF).Face(); | |
2363 | ||
0d969553 | 2364 | if ( !myImageOffset.HasImage(CurOF)) // face disappears in unwinding |
7fd59977 | 2365 | continue; |
2366 | ||
2367 | TopExp_Explorer exp2(CurF,TopAbs_EDGE); | |
2368 | for ( ;exp2.More(); exp2.Next()) { | |
2369 | const TopoDS_Edge& CurE = TopoDS::Edge(exp2.Current()); | |
2370 | TopoDS_Shape aLocalShape = Offset.Generated(CurE); | |
2371 | const TopoDS_Edge& CurOE = TopoDS::Edge(aLocalShape); | |
2372 | // const TopoDS_Edge& CurOE = TopoDS::Edge(Offset.Generated(CurE)); | |
2373 | ||
2374 | if (!myImageOffset.HasImage(CurOE)) continue; | |
0d969553 | 2375 | // CurOE disappears |
7fd59977 | 2376 | |
2377 | const TopoDS_Edge& ImE = | |
2378 | TopoDS::Edge(myImageOffset.Image(CurOE).First()); | |
2379 | if (ImE.IsSame(CurOE)) { | |
2380 | myCreated.Bind(CurOE,EmptyMap); | |
2381 | myCreated(CurOE).Bind(CurF,Empty); | |
2382 | myCreated(CurOE)(CurF).Append(CurE); | |
2383 | } | |
2384 | } | |
2385 | } | |
2386 | ||
0d969553 Y |
2387 | // The connected faces are already in myResult. |
2388 | // So it is necessary to add faces: | |
2389 | // - non-touched (so not in myFaces) | |
2390 | // - issuing from the unwinding (non degenerated, non inverted, non disappeared) | |
7fd59977 | 2391 | exp.Init(myShape,TopAbs_FACE); |
2392 | for ( ;exp.More(); exp.Next()) { | |
2393 | ||
2394 | const TopoDS_Face& CurF = TopoDS::Face(exp.Current()); | |
2395 | ||
2396 | if ( !myFaces.Contains(CurF)) { | |
0d969553 | 2397 | // so the face is not touched |
7fd59977 | 2398 | B.Add(myResult,CurF); |
2399 | } | |
0d969553 | 2400 | else { // so the faces are unwindeds |
7fd59977 | 2401 | |
0d969553 | 2402 | if ( !myMapSF.IsBound(CurF)) continue; // inverted or degenerated |
7fd59977 | 2403 | |
2404 | const TopoDS_Face& CurOF = myMapSF(CurF).Face(); | |
2405 | ||
0d969553 | 2406 | if ( !myImageOffset.HasImage(CurOF)) // face disappears in unwinding |
7fd59977 | 2407 | continue; |
2408 | ||
0d969553 | 2409 | // List of faces generated by a face in the unwinding |
7fd59977 | 2410 | TopTools_ListOfShape Lim; |
2411 | myImageOffset.LastImage(CurOF,Lim); | |
2412 | TopTools_ListIteratorOfListOfShape itLim(Lim); | |
2413 | for ( ;itLim.More(); itLim.Next()) { | |
0d969553 | 2414 | // DeboucFace = offset Face unwinded in "Debouc". |
7fd59977 | 2415 | const TopoDS_Face& DeboucFace = TopoDS::Face(itLim.Value()); |
2416 | ||
2417 | TopLoc_Location L; | |
2418 | Handle(Geom_Surface) S = BRep_Tool::Surface(CurF,L); | |
2419 | ||
2420 | TopoDS_Face NewF; B.MakeFace(NewF); | |
2421 | B.UpdateFace(NewF,S,L,BRep_Tool::Tolerance(CurF)); | |
2422 | ||
2423 | TopTools_DataMapOfShapeShape MapSS; | |
2424 | ||
2425 | TopoDS_Shape aLocalShape = DeboucFace.Oriented(TopAbs_FORWARD); | |
2426 | const TopoDS_Face& Face = TopoDS::Face(aLocalShape); | |
2427 | // const TopoDS_Face& Face = | |
2428 | // TopoDS::Face(DeboucFace.Oriented(TopAbs_FORWARD)); | |
2429 | TopExp_Explorer exp2(Face, TopAbs_EDGE); | |
2430 | for ( ; exp2.More(); exp2.Next()) { | |
2431 | const TopoDS_Edge& E = TopoDS::Edge(exp2.Current()); | |
2432 | TopoDS_Vertex V1,V2,OV1,OV2; | |
2433 | TopExp::Vertices(E ,V1 ,V2 ); | |
2434 | if (myCreated.IsBound(E)) { | |
2435 | if (myCreated(E).IsBound(CurF)) { | |
2436 | const TopoDS_Edge& OE = TopoDS::Edge(myCreated(E)(CurF).First()); | |
2437 | TopExp::Vertices(OE,OV1,OV2); | |
2438 | if ( !myCreated.IsBound(V1)) myCreated.Bind(V1,EmptyMap); | |
2439 | if ( !myCreated.IsBound(V2)) myCreated.Bind(V2,EmptyMap); | |
2440 | if ( !myCreated(V1).IsBound(CurF)) { | |
2441 | myCreated(V1).Bind(CurF,Empty); | |
2442 | myCreated(V1)(CurF).Append(OV1); | |
2443 | } | |
2444 | if ( !myCreated(V2).IsBound(CurF)) { | |
2445 | myCreated(V2).Bind(CurF,Empty); | |
2446 | myCreated(V2)(CurF).Append(OV2); | |
2447 | } | |
2448 | } | |
2449 | } | |
2450 | } | |
2451 | ||
2452 | TopExp_Explorer expw(Face, TopAbs_WIRE); | |
2453 | for ( ; expw.More(); expw.Next()) { | |
2454 | const TopoDS_Wire& W = TopoDS::Wire(expw.Current()); | |
2455 | TopExp_Explorer expe(W.Oriented(TopAbs_FORWARD), | |
2456 | TopAbs_EDGE); | |
2457 | TopoDS_Wire OW; | |
2458 | B.MakeWire(OW); | |
2459 | ||
2460 | for ( ; expe.More(); expe.Next()) { | |
2461 | const TopoDS_Edge& E = TopoDS::Edge(expe.Current()); | |
2462 | Standard_Real f,l; | |
2463 | Handle(Geom2d_Curve) C2d = | |
2464 | BRep_Tool::CurveOnSurface(E,Face,f,l); | |
2465 | TopoDS_Edge OE; | |
0d969553 | 2466 | if ( MapSS.IsBound(E)) { // this is an edge of cutting |
7fd59977 | 2467 | OE = TopoDS::Edge(MapSS(E)); |
51740958 | 2468 | TopoDS_Shape aLocalShapeReversedE = E.Reversed(); |
7fd59977 | 2469 | Handle(Geom2d_Curve) C2d_1 = |
51740958 | 2470 | BRep_Tool::CurveOnSurface(TopoDS::Edge(aLocalShapeReversedE),Face,f,l); |
7fd59977 | 2471 | // Handle(Geom2d_Curve) C2d_1 = |
2472 | // BRep_Tool::CurveOnSurface(TopoDS::Edge(E.Reversed()), | |
2473 | // Face,f,l); | |
2474 | if ( E.Orientation() == TopAbs_FORWARD) | |
2475 | B.UpdateEdge(OE,C2d,C2d_1,NewF,BRep_Tool::Tolerance(E)); | |
2476 | else | |
2477 | B.UpdateEdge(OE,C2d_1,C2d,NewF,BRep_Tool::Tolerance(E)); | |
2478 | B.Range(OE,f,l); | |
2479 | } | |
2480 | else { | |
0d969553 | 2481 | // Is there an image in the Map of Created ? |
7fd59977 | 2482 | if ( myCreated.IsBound(E)) { |
2483 | if ( myCreated(E).IsBound(CurF)) { | |
2484 | OE = TopoDS::Edge(myCreated(E)(CurF).First()); | |
2485 | } | |
2486 | } | |
2487 | else { | |
2488 | B.MakeEdge(OE); | |
2489 | TopoDS_Vertex V1,V2,OV1,OV2; | |
2490 | TopExp::Vertices(E,V1,V2); | |
2491 | if ( myCreated.IsBound(V1) && myCreated(V1).IsBound(CurF)) { | |
2492 | OV1 = TopoDS::Vertex(myCreated(V1)(CurF).First()); | |
2493 | } | |
2494 | else { | |
2495 | B.MakeVertex(OV1); | |
2496 | gp_Pnt2d P2d = | |
2497 | C2d->Value(BRep_Tool::Parameter(V1,E,Face)); | |
2498 | gp_Pnt P; | |
2499 | S->D0(P2d.X(),P2d.Y(),P); | |
2500 | P.Transform(L.Transformation()); | |
2501 | B.UpdateVertex(OV1,P,BRep_Tool::Tolerance(V1)); | |
2502 | myCreated.Bind(V1,EmptyMap); | |
2503 | myCreated(V1).Bind(CurF,Empty); | |
2504 | myCreated(V1)(CurF).Append(OV1); | |
2505 | } | |
2506 | if ( myCreated.IsBound(V2) && myCreated(V2).IsBound(CurF)) { | |
2507 | OV2 = TopoDS::Vertex(myCreated(V2)(CurF).First()); | |
2508 | } | |
2509 | else { | |
2510 | B.MakeVertex(OV2); | |
2511 | gp_Pnt2d P2d = | |
2512 | C2d->Value(BRep_Tool::Parameter(V2,E,Face)); | |
2513 | gp_Pnt P; | |
2514 | S->D0(P2d.X(),P2d.Y(),P); | |
2515 | P.Transform(L.Transformation()); | |
2516 | B.UpdateVertex(OV2,P,BRep_Tool::Tolerance(V2)); | |
2517 | myCreated.Bind(V2,EmptyMap); | |
2518 | myCreated(V2).Bind(CurF,Empty); | |
2519 | myCreated(V2)(CurF).Append(OV2); | |
2520 | } | |
2521 | B.Add(OE,OV1.Oriented(V1.Orientation())); | |
2522 | B.Add(OE,OV2.Oriented(V2.Orientation())); | |
2523 | } | |
2524 | B.UpdateEdge(OE,C2d,NewF,BRep_Tool::Tolerance(E)); | |
2525 | B.Range(OE,f,l); | |
2526 | // ComputeCurve3d(OE,C2d,TheSurf,L,BRep_Tool::Tolerance(E)); | |
2527 | MapSS.Bind(E,OE); | |
2528 | } | |
2529 | B.Add(OW, OE.Oriented(E.Orientation())); | |
2530 | } | |
2531 | B.Add(NewF, OW.Oriented(W.Orientation())); | |
2532 | } | |
2533 | ||
2534 | NewF.Orientation(DeboucFace.Orientation()); | |
2535 | ||
2536 | BRepTools::Update(NewF); | |
2537 | B.Add(myResult,NewF); | |
2538 | } | |
2539 | } | |
2540 | } | |
2541 | ||
0d969553 | 2542 | // non-regarding the cause, there always remain greeb borders on this Shape, so it is sewn. |
7fd59977 | 2543 | Handle(BRepBuilderAPI_Sewing) Sew = new BRepBuilderAPI_Sewing(myTol); |
2544 | ||
2545 | BRepLib::BuildCurves3d(myResult); | |
2546 | ||
2547 | exp.Init(myResult,TopAbs_FACE); | |
2548 | for ( ;exp.More(); exp.Next()) | |
2549 | Sew->Add(exp.Current()); | |
2550 | ||
2551 | Sew->Perform(); | |
2552 | ||
0d969553 Y |
2553 | // SameParameter is done in case Sew does not do it (Detect that the edges |
2554 | // are not sameparameter but does nothing.) | |
7fd59977 | 2555 | |
2556 | const TopoDS_Shape& SewedShape = Sew->SewedShape(); | |
2557 | if ( !SewedShape.IsNull()) { | |
2558 | exp.Init(Sew->SewedShape(), TopAbs_EDGE); | |
2559 | for (; exp.More(); exp.Next()) { | |
2560 | const TopoDS_Edge& sec = TopoDS::Edge(exp.Current()); | |
2561 | BRepLib::SameParameter(sec, BRep_Tool::Tolerance(sec)); | |
2562 | } | |
2563 | myResult = SewedShape; | |
2564 | } | |
2565 | } | |
2566 | ||
2567 | ||
2568 | //======================================================================= | |
2569 | //function : Intersect | |
2570 | //purpose : | |
2571 | //======================================================================= | |
2572 | ||
2573 | Standard_Boolean BiTgte_Blend::Intersect | |
2574 | (const TopoDS_Shape& Init, | |
2575 | const TopoDS_Face& Face, | |
1155d05a | 2576 | const TopTools_DataMapOfShapeBox& MapSBox, |
7fd59977 | 2577 | const BRepOffset_Offset& OF1, |
2578 | BRepOffset_Inter3d& Inter) | |
2579 | { | |
2580 | Standard_Boolean JenRajoute = Standard_False; | |
2581 | ||
2582 | const Bnd_Box& Box1 = MapSBox(Face); | |
2583 | ||
2584 | // ----------------------------------------------- | |
0d969553 | 2585 | // intersection with all already created faces. |
7fd59977 | 2586 | // ----------------------------------------------- |
2587 | const TopoDS_Shape& InitShape1 = OF1.InitialShape(); | |
2588 | Standard_Boolean F1surBordLibre = | |
2589 | InitShape1.ShapeType() == TopAbs_EDGE && | |
2590 | myStopFaces.Contains(InitShape1); | |
2591 | ||
2592 | TopTools_MapOfShape Done; | |
2593 | BRepOffset_DataMapIteratorOfDataMapOfShapeOffset It(myMapSF); | |
2594 | for ( ; It.More(); It.Next()) { | |
2595 | const BRepOffset_Offset& OF2 = It.Value(); | |
2596 | const TopoDS_Face& F2 = OF2.Face(); | |
2597 | ||
2598 | if (Box1.IsOut(MapSBox(F2))) continue; | |
2599 | ||
2600 | if ( Inter.IsDone(Face,F2)) continue; | |
2601 | ||
0d969553 | 2602 | // 2 tubes created on free border are not intersected. |
7fd59977 | 2603 | const TopoDS_Shape& InitShape2 = OF2.InitialShape(); |
2604 | Standard_Boolean F2surBordLibre = | |
2605 | InitShape2.ShapeType() == TopAbs_EDGE && | |
2606 | myStopFaces.Contains(InitShape2); | |
2607 | ||
0797d9d3 | 2608 | #ifdef OCCT_DEBUG |
7fd59977 | 2609 | if ( F1surBordLibre && F2surBordLibre) { |
0d969553 | 2610 | cout << "Rejection : 2 tubes on free border are not intersected"; |
7fd59977 | 2611 | cout << endl; |
2612 | } | |
2613 | #endif | |
2614 | ||
2615 | if ( F1surBordLibre && F2surBordLibre) continue; | |
2616 | ||
2617 | // ------------------------------------------------------- | |
0d969553 | 2618 | // Tubes are not intersected with neighbor faces. |
7fd59977 | 2619 | // ------------------------------------------------------- |
2620 | const TopoDS_Shape& ItKey = It.Key(); | |
2621 | ||
2622 | if ( Init.ShapeType() == TopAbs_EDGE) { | |
2623 | if (ItKey.ShapeType() == TopAbs_FACE && | |
2624 | IsInFace(TopoDS::Edge(Init), TopoDS::Face(ItKey))) continue; | |
2625 | } | |
2626 | ||
2627 | Inter.FaceInter(Face,F2,myInitOffsetFace); | |
2628 | ||
2629 | // ------------------------------------------ | |
0d969553 Y |
2630 | // an edge of F1 or F2 has been touched ? |
2631 | // if yes, add faces in myFaces | |
7fd59977 | 2632 | // ==> JenRajoute = True |
2633 | // ------------------------------------------ | |
2634 | TopTools_ListOfShape LInt; | |
2635 | Done.Clear(); | |
2636 | if (myAsDes->HasCommonDescendant(Face,F2,LInt)) { | |
2637 | TopTools_ListIteratorOfListOfShape itl2; | |
2638 | for (itl2.Initialize(LInt); itl2.More(); itl2.Next()) { | |
2639 | const TopoDS_Edge& CurE = TopoDS::Edge(itl2.Value()); | |
2640 | TopoDS_Vertex V1,V2; | |
2641 | TopoDS_Edge E1,E2; | |
2642 | TopExp::Vertices(CurE,V1,V2); | |
2643 | ||
2644 | if ( Done.Add(V1)) { | |
2645 | Standard_Boolean IsOnR1 = IsOnRestriction(V1,CurE,Face,E1); | |
2646 | Standard_Boolean IsOnR2 = IsOnRestriction(V1,CurE,F2,E2); | |
0797d9d3 | 2647 | #ifdef OCCT_DEBUG |
7fd59977 | 2648 | if (IsOnR1 && IsOnR2) { |
0d969553 Y |
2649 | cout << "Leave in the same tps on 2 faces, "; |
2650 | cout << "propagation only on free border"; | |
7fd59977 | 2651 | cout << endl; |
2652 | } | |
2653 | #endif | |
2654 | if ( IsOnR1 ) { | |
2655 | if ( !myStopFaces.Contains(Init)) { | |
2656 | Add(E1,myEdges,Init,OF1,myAnalyse,IsOnR1 && IsOnR2); | |
2657 | JenRajoute = Standard_True; | |
2658 | } | |
2659 | } | |
2660 | if ( IsOnR2) { | |
2661 | if ( !myStopFaces.Contains(ItKey)) { | |
2662 | Add(E2,myEdges, ItKey,OF2,myAnalyse,IsOnR1 && IsOnR2); | |
2663 | JenRajoute = Standard_True; | |
2664 | } | |
2665 | } | |
2666 | } | |
2667 | ||
2668 | if ( Done.Add(V2)) { | |
2669 | Standard_Boolean IsOnR1 = IsOnRestriction(V2,CurE,Face,E1); | |
2670 | Standard_Boolean IsOnR2 = IsOnRestriction(V2,CurE,F2,E2); | |
2671 | ||
0d969553 Y |
2672 | // If IsOnR1 && IsOnR2, |
2673 | // Leave in the same tps on 2 faces, propagate only on | |
2674 | // free borders. | |
2675 | // A priori, only facet is closed. | |
0797d9d3 | 2676 | #ifdef OCCT_DEBUG |
7fd59977 | 2677 | if (IsOnR1 && IsOnR2) { |
0d969553 Y |
2678 | cout << "Leave with the same tps on 2 faces, "; |
2679 | cout << "propagate only if the border is free"; | |
7fd59977 | 2680 | cout << endl; |
2681 | } | |
2682 | #endif | |
2683 | if ( IsOnR1) { | |
2684 | if ( !myStopFaces.Contains(Init)) { | |
2685 | Add(E1,myEdges,Init,OF1,myAnalyse,IsOnR1 && IsOnR2); | |
2686 | JenRajoute = Standard_True; | |
2687 | } | |
2688 | } | |
2689 | if ( IsOnR2) { | |
2690 | if ( !myStopFaces.Contains(ItKey)) { | |
2691 | Add(E2,myEdges,ItKey,OF2,myAnalyse,IsOnR1 && IsOnR2); | |
2692 | JenRajoute = Standard_True; | |
2693 | } | |
2694 | } | |
2695 | } | |
2696 | } | |
2697 | } | |
2698 | } | |
2699 | ||
2700 | return JenRajoute; | |
2701 | } | |
2702 | ||
2703 |