Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1999-04-27 |
2 | // Created by: Andrey BETENEV | |
3 | // Copyright (c) 1999-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. | |
b311480e | 16 | |
7fd59977 | 17 | // pdn 01.06.99 S4205: handling not-SameRange edges |
18 | // abv 22.07.99 implementing patch indices | |
19 | // svv 10.01.00 porting on DEC | |
20 | ||
42cf5bc1 | 21 | #include <Bnd_Box2d.hxx> |
22 | #include <BndLib_Add2dCurve.hxx> | |
23 | #include <BRep_Builder.hxx> | |
24 | #include <BRep_Tool.hxx> | |
25 | #include <BRepTools.hxx> | |
26 | #include <BRepTopAdaptor_FClass2d.hxx> | |
27 | #include <Extrema_ExtPC2d.hxx> | |
28 | #include <Geom2d_Curve.hxx> | |
29 | #include <Geom2d_Line.hxx> | |
30 | #include <Geom2dAdaptor_Curve.hxx> | |
31 | #include <Geom2dInt_GInter.hxx> | |
32 | #include <Geom_Curve.hxx> | |
33 | #include <Geom_Surface.hxx> | |
34 | #include <GeomAdaptor_Surface.hxx> | |
7fd59977 | 35 | #include <gp_Dir2d.hxx> |
42cf5bc1 | 36 | #include <gp_Lin2d.hxx> |
37 | #include <gp_Pnt.hxx> | |
38 | #include <gp_Pnt2d.hxx> | |
39 | #include <IntRes2d_Domain.hxx> | |
40 | #include <IntRes2d_IntersectionPoint.hxx> | |
41 | #include <IntRes2d_IntersectionSegment.hxx> | |
42 | #include <Precision.hxx> | |
43 | #include <ShapeAnalysis.hxx> | |
44 | #include <ShapeAnalysis_Curve.hxx> | |
45 | #include <ShapeAnalysis_Edge.hxx> | |
46 | #include <ShapeAnalysis_Surface.hxx> | |
47 | #include <ShapeAnalysis_TransferParameters.hxx> | |
48 | #include <ShapeAnalysis_TransferParametersProj.hxx> | |
49 | #include <ShapeAnalysis_WireOrder.hxx> | |
50 | #include <ShapeBuild_Edge.hxx> | |
51 | #include <ShapeBuild_ReShape.hxx> | |
52 | #include <ShapeBuild_Vertex.hxx> | |
53 | #include <ShapeExtend.hxx> | |
54 | #include <ShapeExtend_CompositeSurface.hxx> | |
55 | #include <ShapeExtend_WireData.hxx> | |
56 | #include <ShapeFix_ComposeShell.hxx> | |
57 | #include <ShapeFix_Edge.hxx> | |
58 | #include <ShapeFix_Face.hxx> | |
59 | #include <ShapeFix_Wire.hxx> | |
60 | #include <ShapeFix_WireSegment.hxx> | |
61 | #include <Standard_Type.hxx> | |
62 | #include <TColgp_SequenceOfPnt2d.hxx> | |
7fd59977 | 63 | #include <TColStd_Array1OfBoolean.hxx> |
42cf5bc1 | 64 | #include <TColStd_Array1OfInteger.hxx> |
7fd59977 | 65 | #include <TColStd_Array1OfReal.hxx> |
66 | #include <TColStd_HArray1OfReal.hxx> | |
7fd59977 | 67 | #include <TColStd_SequenceOfReal.hxx> |
42cf5bc1 | 68 | #include <TopLoc_Location.hxx> |
7fd59977 | 69 | #include <TopoDS.hxx> |
7fd59977 | 70 | #include <TopoDS_Edge.hxx> |
42cf5bc1 | 71 | #include <TopoDS_Face.hxx> |
7fd59977 | 72 | #include <TopoDS_Iterator.hxx> |
42cf5bc1 | 73 | #include <TopoDS_Shape.hxx> |
74 | #include <TopoDS_Shell.hxx> | |
75 | #include <TopoDS_Vertex.hxx> | |
76 | #include <TopoDS_Wire.hxx> | |
7fd59977 | 77 | #include <TopTools_DataMapOfShapeListOfShape.hxx> |
42cf5bc1 | 78 | #include <TopTools_MapOfShape.hxx> |
7fd59977 | 79 | |
80 | //======================================================================= | |
81 | //function : ShapeFix_ComposeShell | |
82 | //purpose : | |
83 | //======================================================================= | |
7fd59977 | 84 | ShapeFix_ComposeShell::ShapeFix_ComposeShell () : |
85 | myStatus(0), myClosedMode(Standard_False) | |
86 | { | |
87 | myTransferParamTool = new ShapeAnalysis_TransferParametersProj; | |
88 | } | |
89 | ||
90 | ||
91 | //======================================================================= | |
92 | //function : Init | |
93 | //purpose : | |
94 | //======================================================================= | |
95 | ||
96 | void ShapeFix_ComposeShell::Init (const Handle(ShapeExtend_CompositeSurface) &Grid, | |
97 | const TopLoc_Location& L, | |
98 | const TopoDS_Face &Face, | |
99 | const Standard_Real Prec) | |
100 | { | |
101 | myGrid = Grid; | |
102 | myUClosed = myGrid->IsUClosed(); | |
103 | myVClosed = myGrid->IsVClosed(); | |
104 | myUPeriod = myGrid->UJointValue(myGrid->NbUPatches()+1) - myGrid->UJointValue(1); | |
105 | myVPeriod = myGrid->VJointValue(myGrid->NbVPatches()+1) - myGrid->VJointValue(1); | |
106 | ||
107 | // DTK-CKY 100531 : protection against very thin face | |
108 | // Test "isclosed" should be filtered on the overall (non trimmed) surface, must be closed | |
109 | Handle(Geom_Surface) theSurface = BRep_Tool::Surface(Face,myLoc); | |
110 | Standard_Real U0,U1,V0,V1; | |
111 | theSurface->Bounds(U0,U1,V0,V1); | |
112 | if (myUClosed) { | |
113 | gp_Pnt P0 = theSurface->Value(U0,(V0+V1)/2.); | |
114 | gp_Pnt P1 = theSurface->Value(U1,(V0+V1)/2.); | |
115 | if (P0.Distance(P1) > Precision::Confusion()*10) | |
116 | myUClosed = Standard_False; | |
117 | } | |
118 | if (myVClosed) { | |
119 | gp_Pnt P0 = theSurface->Value((U0+U1)/2.,V0); | |
120 | gp_Pnt P1 = theSurface->Value((U0+U1)/2.,V1); | |
121 | if (P0.Distance(P1) > Precision::Confusion()*10) | |
122 | myVClosed = Standard_False; | |
123 | } | |
124 | // DTK-CKY 100531 end | |
125 | ||
126 | myLoc = L; | |
127 | //smh#8 | |
128 | TopoDS_Shape tmpF = Face.Oriented ( TopAbs_FORWARD ); | |
129 | myFace = TopoDS::Face ( tmpF ); // for correct dealing with seams | |
130 | myOrient = Face.Orientation(); | |
131 | SetPrecision(Prec); | |
132 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
133 | ||
134 | // Compute resolution (checking in 2d is necessary for splitting | |
135 | // degenerated edges and avoiding NotClosed) | |
136 | myUResolution = myVResolution = RealLast(); | |
137 | for ( Standard_Integer i=1; i <= myGrid->NbUPatches(); i++ ) { | |
138 | Standard_Real uRange = myGrid->UJointValue(i+1)-myGrid->UJointValue(i); | |
139 | for ( Standard_Integer j=1; j <= myGrid->NbVPatches(); j++ ) { | |
140 | Standard_Real vRange = myGrid->VJointValue(j+1)-myGrid->VJointValue(j); | |
141 | Standard_Real u1,u2,v1,v2; | |
142 | myGrid->Patch(i,j)->Bounds(u1,u2,v1,v2); | |
143 | GeomAdaptor_Surface GAS ( myGrid->Patch(i,j) ); | |
144 | Standard_Real ures = GAS.UResolution ( 1. )*uRange/(u2-u1); | |
145 | Standard_Real vres = GAS.VResolution ( 1. )*vRange/(v2-v1); | |
146 | if ( ures >0. && myUResolution > ures ) myUResolution = ures; | |
147 | if ( vres >0. && myVResolution > vres ) myVResolution = vres; | |
148 | } | |
149 | } | |
150 | if ( myUResolution == RealLast() ) myUResolution = ::Precision::Parametric ( 1. ); | |
151 | if ( myVResolution == RealLast() ) myVResolution = ::Precision::Parametric ( 1. ); | |
152 | } | |
153 | ||
154 | ||
155 | //======================================================================= | |
156 | //function : Perform | |
157 | //purpose : | |
158 | //======================================================================= | |
159 | ||
160 | Standard_Boolean ShapeFix_ComposeShell::Perform () | |
161 | { | |
162 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
163 | myInvertEdgeStatus = Standard_False; | |
164 | ||
165 | ShapeFix_SequenceOfWireSegment seqw; // working data: wire segments | |
166 | ||
167 | // Init seqw by initial set of wires (with corresponding orientation) | |
168 | LoadWires ( seqw ); | |
169 | if(seqw.Length() == 0) { | |
170 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_FAIL6 ); | |
171 | return Standard_False; | |
172 | } | |
173 | ||
174 | // Split edges in the wires by grid and add internal segments of grid (parts of cutting lines) | |
175 | SplitByGrid ( seqw ); | |
176 | ||
177 | // Split all the wires into segments by common vertices (intersections) | |
178 | BreakWires ( seqw ); | |
179 | ||
180 | // Then, collect resulting wires | |
181 | ShapeFix_SequenceOfWireSegment wires; // resulting wires | |
182 | CollectWires ( wires, seqw ); | |
183 | ||
184 | // And construct resulting faces | |
185 | TopTools_SequenceOfShape faces; | |
186 | DispatchWires ( faces, wires ); | |
187 | ||
188 | // Finally, construct resulting shell | |
189 | if ( faces.Length() !=1 ) { | |
190 | TopoDS_Shell S; | |
191 | BRep_Builder B; | |
192 | B.MakeShell ( S ); | |
193 | for ( Standard_Integer i=1; i <= faces.Length(); i++ ) | |
194 | B.Add ( S, faces(i) ); | |
195 | myResult = S; | |
196 | } | |
197 | else myResult = faces(1); | |
198 | myResult.Orientation ( myOrient ); | |
199 | ||
200 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 ); | |
201 | return Standard_True; | |
202 | } | |
203 | ||
204 | ||
205 | //======================================================================= | |
206 | //function : SplitEdges | |
207 | //purpose : | |
208 | //======================================================================= | |
209 | ||
210 | void ShapeFix_ComposeShell::SplitEdges () | |
211 | { | |
212 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); | |
213 | ||
214 | ShapeFix_SequenceOfWireSegment seqw; // working data: wire segments | |
215 | ||
216 | // Init seqw by initial set of wires (with corresponding orientation) | |
217 | LoadWires ( seqw ); | |
218 | ||
219 | // Split edges in the wires by grid and add internal segments of grid (parts of cutting lines) | |
220 | SplitByGrid ( seqw ); | |
221 | } | |
222 | ||
223 | ||
224 | //======================================================================= | |
225 | //function : Result | |
226 | //purpose : | |
227 | //======================================================================= | |
228 | ||
229 | const TopoDS_Shape& ShapeFix_ComposeShell::Result () const | |
230 | { | |
231 | return myResult; | |
232 | } | |
233 | ||
234 | ||
235 | //======================================================================= | |
236 | //function : Status | |
237 | //purpose : | |
238 | //======================================================================= | |
239 | ||
240 | Standard_Boolean ShapeFix_ComposeShell::Status (const ShapeExtend_Status status) const | |
241 | { | |
242 | return ShapeExtend::DecodeStatus ( myStatus, status ); | |
243 | } | |
244 | ||
245 | ||
246 | //======================================================================= | |
247 | // PRIVATE (working) METHODS | |
248 | //======================================================================= | |
249 | ||
250 | #define TOLINT 1.e-10 // precision for intersection | |
251 | ||
252 | // Local definitions: characteristics of intersection point | |
253 | ||
254 | #define IOR_UNDEF 0 // undefined side | |
255 | #define IOR_LEFT 1 // to left side of cutting line | |
256 | #define IOR_RIGHT 2 // to right side of cutting line | |
257 | #define IOR_BOTH 3 // crossing | |
258 | #define IOR_POS 4 // in case of cycle on full period, whether first point is right | |
259 | ||
260 | #define ITP_INTER 8 // crossing | |
261 | #define ITP_BEGSEG 16 // start of tangential segment | |
262 | #define ITP_ENDSEG 32 // stop of tangential segment | |
263 | #define ITP_TANG 64 // tangential point | |
264 | ||
265 | ||
266 | //======================================================================= | |
267 | //function : PointLineDeviation | |
268 | //purpose : auxilary | |
269 | //======================================================================= | |
270 | // Return (signed) deviation of point from line | |
271 | static Standard_Real PointLineDeviation (const gp_Pnt2d &p, const gp_Lin2d &line) | |
272 | { | |
273 | gp_Dir2d dir = line.Direction(); | |
274 | gp_Dir2d n ( -dir.Y(), dir.X() ); | |
275 | return n.XY() * ( p.XY() - line.Location().XY() ); | |
276 | } | |
277 | ||
278 | ||
279 | //======================================================================= | |
280 | //function : PointLinePosition | |
281 | //purpose : auxilary | |
282 | //======================================================================= | |
283 | // Define position of point relative to line | |
284 | static Standard_Integer PointLinePosition (const gp_Pnt2d &p, const gp_Lin2d &line, | |
285 | Standard_Real &dev) | |
286 | { | |
287 | dev = PointLineDeviation ( p, line ); | |
288 | return ( dev > TOLINT ? IOR_LEFT : ( dev < -TOLINT ? IOR_RIGHT : IOR_UNDEF ) ); | |
289 | } | |
290 | ||
291 | ||
292 | //======================================================================= | |
293 | //function : PointLinePosition | |
294 | //purpose : auxilary | |
295 | //======================================================================= | |
296 | // Define position of point relative to line | |
297 | static Standard_Integer PointLinePosition (const gp_Pnt2d &p, const gp_Lin2d &line) | |
298 | { | |
299 | Standard_Real dev; | |
300 | return PointLinePosition ( p, line, dev ); | |
301 | } | |
302 | ||
303 | ||
304 | //======================================================================= | |
305 | //function : ParamPointsOnLine | |
306 | //purpose : auxilary | |
307 | //======================================================================= | |
308 | // Compute parameter of point on line | |
309 | static inline Standard_Real ParamPointOnLine (const gp_Pnt2d &p, const gp_Lin2d &line) | |
310 | { | |
311 | return line.Direction().XY() * ( p.XY() - line.Location().XY() ); | |
312 | } | |
313 | ||
314 | ||
315 | //======================================================================= | |
316 | //function : ParamPointsOnLine | |
317 | //purpose : auxilary | |
318 | //======================================================================= | |
319 | // Compute parameter of two points on line (as intersection of segment) | |
320 | static Standard_Real ParamPointsOnLine (const gp_Pnt2d &p1, const gp_Pnt2d &p2, | |
321 | const gp_Lin2d &line) | |
322 | { | |
323 | Standard_Real dist1 = PointLineDeviation ( p1, line ); | |
324 | Standard_Real dist2 = PointLineDeviation ( p2, line ); | |
325 | // in most cases, one of points is on line | |
326 | if ( Abs ( dist1 ) < ::Precision::PConfusion() ) { | |
327 | if ( Abs ( dist2 ) < ::Precision::PConfusion() ) | |
328 | return 0.5 * ( ParamPointOnLine ( p1, line ) + ParamPointOnLine ( p2, line ) ); | |
329 | return ParamPointOnLine ( p1, line ); | |
330 | } | |
331 | if ( Abs ( dist2 ) < ::Precision::PConfusion() ) | |
332 | return ParamPointOnLine ( p2, line ); | |
333 | // just protection | |
334 | if ( dist2 * dist1 >0 ) | |
335 | return 0.5 * ( ParamPointOnLine ( p1, line ) + ParamPointOnLine ( p2, line ) ); | |
336 | // else compute intersection | |
337 | return ( ParamPointOnLine ( p1, line ) * dist2 - | |
338 | ParamPointOnLine ( p2, line ) * dist1 ) / ( dist2 - dist1 ); | |
339 | } | |
340 | ||
341 | ||
342 | //======================================================================= | |
343 | //function : ProjectPointOnLine | |
344 | //purpose : auxilary | |
345 | //======================================================================= | |
346 | // Compute projection of point on line | |
347 | static inline gp_Pnt2d ProjectPointOnLine (const gp_Pnt2d &p, const gp_Lin2d &line) | |
348 | { | |
349 | return line.Location().XY() + line.Direction().XY() * ParamPointOnLine ( p, line ); | |
350 | } | |
351 | ||
352 | ||
353 | //======================================================================= | |
354 | //function : ApplyContext | |
355 | //purpose : auxilary | |
356 | //======================================================================= | |
357 | // Apply context to one edge in the wire and put result into this wire | |
358 | static Standard_Integer ApplyContext (ShapeFix_WireSegment &wire, | |
359 | const Standard_Integer iedge, | |
360 | const Handle(ShapeBuild_ReShape) &context) | |
361 | { | |
362 | TopoDS_Edge edge = wire.Edge ( iedge ); | |
363 | TopoDS_Shape res = context->Apply ( edge ); | |
364 | ||
365 | if ( res.IsSame ( edge ) ) return 1; | |
366 | ||
367 | if ( res.ShapeType() == TopAbs_EDGE ) { | |
368 | wire.SetEdge ( iedge, TopoDS::Edge ( res ) ); | |
369 | return 1; | |
370 | } | |
371 | ||
372 | Standard_Integer index = iedge; | |
373 | ||
374 | Handle(ShapeExtend_WireData) segw = new ShapeExtend_WireData; | |
375 | segw->ManifoldMode() = Standard_False; | |
376 | for ( TopoDS_Iterator it(res); it.More(); it.Next() ) { | |
377 | TopoDS_Edge E = TopoDS::Edge ( it.Value() ); | |
378 | if ( ! E.IsNull() ) segw->Add ( E ); | |
0797d9d3 | 379 | #ifdef OCCT_DEBUG |
7fd59977 | 380 | else cout << "Error: ShapeFix_ComposeShell, ApplyContext: wrong mapping of edge" << endl; |
381 | #endif | |
382 | } | |
383 | ||
384 | // add edges into the wire in correct order | |
385 | if ( segw->NbEdges() >0 ) { | |
386 | Standard_Integer ind, iumin, iumax, ivmin, ivmax; | |
387 | wire.GetPatchIndex ( iedge, iumin, iumax, ivmin, ivmax ); | |
388 | Standard_Integer nbEdges = segw->NbEdges(); | |
389 | for ( Standard_Integer i=1; i <= nbEdges; i++, index++ ) { | |
390 | ind = ( edge.Orientation() == TopAbs_FORWARD || edge.Orientation() == TopAbs_INTERNAL ? i : segw->NbEdges()-i+1 ); | |
391 | TopoDS_Edge aE = segw->Edge ( ind ); | |
392 | if ( i==1 ) wire.SetEdge ( index, aE ); | |
393 | else wire.AddEdge ( index, aE, iumin, iumax, ivmin, ivmax ); | |
394 | } | |
395 | } | |
0797d9d3 | 396 | #ifdef OCCT_DEBUG |
7fd59977 | 397 | else cout << "Warning: ShapeFix_ComposeShell, ApplyContext: edge is to remove - not implemented" << endl; |
398 | #endif | |
399 | ||
400 | return index - iedge; | |
401 | } | |
402 | ||
403 | ||
404 | //======================================================================= | |
405 | //function : IsCoincided | |
406 | //purpose : auxilary | |
407 | //======================================================================= | |
408 | // check points coincidence | |
409 | static inline Standard_Integer IsCoincided (const gp_Pnt2d &p1, const gp_Pnt2d &p2, | |
410 | const Standard_Real UResolution, | |
411 | const Standard_Real VResolution, | |
412 | const Standard_Real tol) | |
413 | { | |
414 | //pdn Maximal accuracy is working precision of intersector. | |
415 | Standard_Real UTolerance = UResolution * tol; | |
416 | Standard_Real VTolerance = VResolution * tol; | |
417 | return Abs ( p1.X() - p2.X() ) <= Max(TOLINT,UTolerance) && | |
418 | Abs ( p1.Y() - p2.Y() ) <= Max(TOLINT,VTolerance); | |
419 | } | |
420 | ||
421 | ||
422 | //======================================================================= | |
423 | //function : GetPatchIndex | |
424 | //purpose : auxilary | |
425 | //======================================================================= | |
426 | // computes index for the patch by given parameter Param | |
427 | static Standard_Integer GetPatchIndex (const Standard_Real Param, | |
428 | const Handle(TColStd_HArray1OfReal) &Params, | |
429 | const Standard_Boolean isClosed) | |
430 | { | |
431 | Standard_Integer NP = Params->Upper(); | |
432 | Standard_Real period = Params->Value(NP) - Params->Value(1); | |
433 | Standard_Real shift = 0; | |
434 | if ( isClosed ) | |
435 | shift = ShapeAnalysis::AdjustToPeriod ( Param, Params->Value(1), Params->Value(NP) ); | |
436 | Standard_Real p = Param + shift; | |
437 | ||
438 | // locate patch: the same algo as in SE_CS::LocateParameter() | |
439 | Standard_Integer i; // svv #1 | |
440 | for ( i = 2; i < NP; i++ ) { | |
441 | // Standard_Real par = Params->Value(i); | |
442 | if ( p < Params->Value(i) ) break; | |
443 | } | |
444 | i--; | |
445 | ||
446 | Standard_Real ish = shift / period; | |
447 | Standard_Integer ishift = (Standard_Integer)( ish <0 ? ish - 0.5 : ish + 0.5 ); | |
448 | return i - ishift * ( NP - 1 ); | |
449 | } | |
450 | ||
451 | ||
452 | //======================================================================= | |
453 | //function : LoadWires | |
454 | //purpose : | |
455 | //======================================================================= | |
456 | ||
457 | void ShapeFix_ComposeShell::LoadWires (ShapeFix_SequenceOfWireSegment &seqw) const | |
458 | { | |
459 | seqw.Clear(); | |
460 | ||
461 | // Init seqw by initial set of wires (with corresponding orientation) | |
59495dbe | 462 | for ( TopoDS_Iterator iw(myFace,Standard_False); iw.More(); iw.Next() ) |
463 | { | |
7fd59977 | 464 | TopoDS_Shape tmpW = Context()->Apply ( iw.Value() ) ; |
59495dbe | 465 | if(tmpW.ShapeType() != TopAbs_WIRE) |
466 | { | |
467 | if(tmpW.ShapeType() == TopAbs_VERTEX) | |
468 | { | |
7fd59977 | 469 | ShapeFix_WireSegment seg; //(( isOuter ? TopAbs_REVERSED : TopAbs_FORWARD ) ); |
470 | seg.SetVertex(TopoDS::Vertex(tmpW)); | |
471 | seg.Orientation(tmpW.Orientation()); | |
472 | seqw.Append ( seg ); | |
473 | } | |
59495dbe | 474 | |
7fd59977 | 475 | continue; |
476 | } | |
59495dbe | 477 | |
7fd59977 | 478 | TopoDS_Wire wire = TopoDS::Wire ( tmpW ); |
479 | ||
480 | Standard_Boolean isNonManifold = ( wire.Orientation() != TopAbs_REVERSED && | |
481 | wire.Orientation() != TopAbs_FORWARD ); | |
482 | ||
7fd59977 | 483 | // protect against INTERNAL/EXTERNAL wires |
59495dbe | 484 | // if ( wire.Orientation() != TopAbs_REVERSED && |
485 | // wire.Orientation() != TopAbs_FORWARD ) continue; | |
7fd59977 | 486 | |
487 | // determine orientation of the wire | |
59495dbe | 488 | // TopoDS_Face face = TopoDS::Face ( myFace.EmptyCopied() ); |
489 | // B.Add ( face, wire ); | |
490 | // Standard_Boolean isOuter = ShapeAnalysis::IsOuterBound ( face ); | |
7fd59977 | 491 | |
59495dbe | 492 | if(isNonManifold) |
493 | { | |
7fd59977 | 494 | Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData ( wire ,Standard_True,Standard_False); |
495 | //pdn protection againts of wires w/o edges | |
496 | Standard_Integer nbEdges = sbwd->NbEdges(); | |
59495dbe | 497 | if(nbEdges) |
498 | { | |
7fd59977 | 499 | //wire segments for non-manifold topology should have INTERNAL orientation |
500 | ShapeFix_WireSegment seg ( sbwd, TopAbs_INTERNAL); | |
501 | seqw.Append ( seg ); | |
502 | } | |
503 | } | |
59495dbe | 504 | else |
505 | { | |
7fd59977 | 506 | //splitting wires containing manifold and non-manifold parts on a separate |
59495dbe | 507 | //wire segment |
7fd59977 | 508 | Handle(ShapeExtend_WireData) sbwdM = new ShapeExtend_WireData(); |
509 | Handle(ShapeExtend_WireData) sbwdNM = new ShapeExtend_WireData(); | |
510 | sbwdNM->ManifoldMode() = Standard_False; | |
511 | TopoDS_Iterator aIt(wire); | |
59495dbe | 512 | for( ; aIt.More(); aIt.Next()) |
513 | { | |
7fd59977 | 514 | TopoDS_Edge E = TopoDS::Edge ( aIt.Value() ); |
515 | if(E.Orientation() == TopAbs_FORWARD || E.Orientation() == TopAbs_REVERSED) | |
516 | sbwdM->Add(E); | |
517 | else | |
518 | sbwdNM->Add(E); | |
519 | } | |
59495dbe | 520 | |
7fd59977 | 521 | Standard_Integer nbMEdges = sbwdM->NbEdges(); |
522 | Standard_Integer nbNMEdges = sbwdNM->NbEdges(); | |
59495dbe | 523 | |
524 | if(nbNMEdges) | |
525 | { | |
7fd59977 | 526 | ShapeFix_WireSegment seg ( sbwdNM, TopAbs_INTERNAL); //(( isOuter ? TopAbs_REVERSED : TopAbs_FORWARD ) ); |
527 | seqw.Append ( seg ); | |
528 | } | |
59495dbe | 529 | |
7fd59977 | 530 | if(nbMEdges) { |
531 | // Orientation is set so as to allow the segment to be traversed in only one direction | |
532 | // skl 01.04.2002 | |
533 | Handle(ShapeFix_Wire) sfw = new ShapeFix_Wire; | |
534 | sfw->Load ( sbwdM ); | |
535 | Standard_Integer stat=0; | |
536 | Handle(Geom_Surface) gs = BRep_Tool::Surface(myFace); | |
59495dbe | 537 | if( gs->IsUPeriodic() && gs->IsVPeriodic() ) |
538 | { | |
7fd59977 | 539 | // For torus-like shapes, first reorder in 2d since reorder is indifferent in 3d |
540 | ShapeAnalysis_WireOrder sawo(Standard_False, 0); | |
541 | ShapeAnalysis_Edge sae; | |
542 | for(Standard_Integer i = 1; i <= nbMEdges; i++) { | |
543 | Standard_Real f,l; | |
544 | Handle(Geom2d_Curve) c2d; | |
545 | //smh#8 | |
546 | TopoDS_Shape tmpF = myFace.Oriented(TopAbs_FORWARD); | |
547 | if(!sae.PCurve(sbwdM->Edge(i),TopoDS::Face(tmpF),c2d,f,l)) | |
548 | continue; | |
549 | sawo.Add(c2d->Value(f).XY(),c2d->Value(l).XY()); | |
550 | } | |
59495dbe | 551 | |
7fd59977 | 552 | sawo.Perform(); |
553 | stat = (sawo.Status() < 0 ? -1 : 1); | |
554 | sfw->FixReorder(sawo); | |
555 | } | |
556 | ||
557 | sfw->FixReorder(); | |
558 | if (sfw->StatusReorder(ShapeExtend_DONE3)) | |
559 | stat=-1; | |
560 | ||
59495dbe | 561 | if(stat < 0) |
562 | { | |
7fd59977 | 563 | BRep_Builder B; |
564 | TopoDS_Shape dummy = myFace.EmptyCopied(); | |
565 | TopoDS_Face face = TopoDS::Face ( dummy ); | |
566 | B.Add ( face, wire ); | |
567 | Standard_Boolean isOuter = ShapeAnalysis::IsOuterBound ( face ); | |
568 | TopoDS_Wire w = sbwdM->Wire(); | |
569 | dummy = myFace.EmptyCopied(); | |
570 | face = TopoDS::Face ( dummy ); | |
571 | B.Add ( face, w ); | |
572 | Standard_Boolean isOuterAfter = ShapeAnalysis::IsOuterBound ( face ); | |
573 | if(isOuter!=isOuterAfter) | |
574 | sbwdM->Reverse(face); | |
575 | } | |
576 | ||
577 | ShapeFix_WireSegment seg ( sbwdM, TopAbs_REVERSED ); //(( isOuter ? TopAbs_REVERSED : TopAbs_FORWARD ) ); | |
578 | seqw.Append ( seg ); | |
579 | } | |
580 | } | |
7fd59977 | 581 | } |
582 | } | |
583 | ||
584 | ||
585 | //======================================================================= | |
586 | //function : ComputeCode | |
587 | //purpose : compute code for wire segment between two intersections (by deviation) | |
588 | //======================================================================= | |
589 | ||
590 | Standard_Integer ShapeFix_ComposeShell::ComputeCode (const Handle(ShapeExtend_WireData) &wire, | |
591 | const gp_Lin2d &line, | |
592 | const Standard_Integer begInd, | |
593 | const Standard_Integer endInd, | |
594 | const Standard_Real begPar, | |
595 | const Standard_Real endPar, | |
596 | const Standard_Boolean isInternal) | |
597 | { | |
598 | Standard_Integer code = IOR_UNDEF; | |
599 | ||
600 | ShapeAnalysis_Edge sae; | |
601 | const Standard_Integer NPOINTS = 5; // number of points for measuring deviation | |
602 | ||
603 | // track special closed case: segment starts at end of edge and ends at its beginning | |
604 | Standard_Integer special = ( begInd == endInd && | |
605 | ( wire->Edge(begInd).Orientation() == TopAbs_FORWARD || | |
606 | wire->Edge(begInd).Orientation() == TopAbs_INTERNAL) == | |
607 | ( begPar > endPar ) ? 1 : 0); | |
608 | if ( ! special && begInd == endInd && begPar == endPar && | |
609 | (myClosedMode || isInternal)) | |
610 | special = 1; | |
611 | ||
612 | // for tracking cases in closed mode | |
613 | Standard_Boolean begin=Standard_True; | |
614 | Standard_Real shift=0; | |
615 | gp_Pnt2d p2d0; | |
616 | ||
617 | // check if segment is tangency | |
618 | // Segment is considered as tangency if deviation of pcurve from line | |
619 | // (in 2d) measured by NPOINTS points is less than tolerance of edge | |
620 | // (recomputed to 2d using Resolution). | |
621 | ||
622 | Standard_Integer nb = wire->NbEdges(); | |
623 | ||
624 | Standard_Integer i; // svv #1 | |
625 | for ( i=begInd; ; i++ ) { | |
626 | if ( i > nb ) i = 1; | |
627 | TopoDS_Edge edge = wire->Edge ( i );; | |
628 | ||
629 | Handle(Geom2d_Curve) c2d; | |
630 | Standard_Real f, l; | |
631 | if ( ! sae.PCurve ( edge, myFace, c2d, f, l, Standard_False ) ) { | |
632 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 ); | |
633 | continue; | |
634 | } | |
635 | Standard_Real tol = LimitTolerance(BRep_Tool::Tolerance ( edge )); | |
636 | Standard_Boolean isreversed = ( edge.Orientation() == TopAbs_REVERSED ); | |
637 | ||
638 | Standard_Real par1 = ( i == begInd && special >=0 ? begPar : ( isreversed ? l : f ) ); | |
639 | Standard_Real par2 = ( i == endInd && special <=0 ? endPar : ( isreversed ? f : l ) ); | |
640 | Standard_Real dpar = ( par2 - par1 ) / ( NPOINTS - 1 ); | |
641 | Standard_Integer np = ( Abs ( dpar ) < ::Precision::PConfusion() ? 1 : NPOINTS ); | |
642 | Standard_Integer j; // svv #1 | |
643 | for ( j=0; j < np; j++ ) { | |
644 | Standard_Real par = par1 + dpar * j; | |
645 | gp_Pnt2d p2d = c2d->Value ( par ); | |
646 | if ( myClosedMode ) { | |
647 | if ( myUClosed && Abs ( line.Direction().X() ) < ::Precision::PConfusion() ) { | |
648 | if ( begin ) shift = ShapeAnalysis::AdjustByPeriod ( p2d.X(), line.Location().X(), myUPeriod ); | |
649 | else if ( ! j ) shift = ShapeAnalysis::AdjustByPeriod ( p2d.X()-p2d0.X(), 0., myUPeriod ); | |
650 | p2d.SetX ( p2d.X() + shift ); | |
651 | } | |
652 | if ( myVClosed && Abs ( line.Direction().Y() ) < ::Precision::PConfusion() ) { | |
653 | if ( begin ) shift = ShapeAnalysis::AdjustByPeriod ( p2d.Y(), line.Location().Y(), myVPeriod ); | |
654 | else if ( ! j ) shift = ShapeAnalysis::AdjustByPeriod ( p2d.Y()-p2d0.Y(), 0., myVPeriod ); | |
655 | p2d.SetY ( p2d.Y() + shift ); | |
656 | } | |
657 | begin = Standard_False; | |
658 | } | |
659 | p2d0 = p2d; | |
660 | Standard_Integer pos = PointLinePosition ( p2d, line ); | |
661 | if ( pos == IOR_UNDEF ) continue; | |
662 | ||
663 | // analyse the deviation | |
664 | gp_Pnt2d p2dl = ProjectPointOnLine ( p2d, line ); | |
665 | if(!IsCoincided ( p2d, p2dl, myUResolution, myVResolution, tol )) { | |
666 | if(!myClosedMode) { code = pos; break; } | |
667 | else { | |
668 | code |= pos; | |
669 | } | |
670 | } | |
671 | } | |
672 | if ( j < np ) { i = 0; break; } // not tangency | |
eafb234b | 673 | if ( i == endInd ) { |
7fd59977 | 674 | if ( special <=0 ) break; |
675 | else special = -1; | |
eafb234b | 676 | } |
7fd59977 | 677 | } |
678 | if ( myClosedMode ) { | |
679 | if ( code != IOR_UNDEF && ! begin ) { | |
680 | // in closed mode, if segment is of 2*pi length, it is BOTH | |
681 | Standard_Real dev = PointLineDeviation ( p2d0, line ); | |
682 | if ( myUClosed && Abs ( line.Direction().X() ) < ::Precision::PConfusion() ) { | |
683 | if ( Abs ( Abs ( dev ) - myUPeriod ) < 0.1 * myUPeriod ) { | |
684 | code = IOR_BOTH; | |
685 | if ( dev >0 ) code |= IOR_POS; | |
686 | } | |
687 | else if(code==IOR_BOTH) | |
688 | code=IOR_UNDEF; | |
689 | } | |
690 | if ( myVClosed && Abs ( line.Direction().Y() ) < ::Precision::PConfusion() ) { | |
691 | if ( Abs ( Abs ( dev ) - myVPeriod ) < 0.1 * myVPeriod ) { | |
692 | code = IOR_BOTH; | |
693 | if ( dev >0 ) code |= IOR_POS; | |
694 | } | |
695 | else if(code==IOR_BOTH) | |
696 | code=IOR_UNDEF; | |
697 | } | |
698 | } | |
699 | return code; | |
700 | } | |
701 | if ( i ) code = IOR_UNDEF; // tangency | |
702 | else if ( code == IOR_BOTH ) { // parity error in intersector | |
703 | code = IOR_LEFT; | |
704 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
0797d9d3 | 705 | #ifdef OCCT_DEBUG |
008aef40 | 706 | cout << "Warning: ShapeFix_ComposeShell::ComputeCode: lost intersection point" << endl; |
7fd59977 | 707 | #endif |
708 | } | |
709 | return code; | |
710 | } | |
711 | ||
712 | ||
713 | //======================================================================= | |
714 | //function : DistributeSplitPoints | |
715 | //purpose : auxilary | |
716 | //======================================================================= | |
717 | // After applying context to (seam) edge, distribute its indices on new edges, | |
718 | // according to their parameters on that edge | |
719 | static void DistributeSplitPoints (const Handle(ShapeExtend_WireData) &sbwd, | |
720 | const TopoDS_Face myFace, | |
721 | const Standard_Integer index, | |
722 | const Standard_Integer nsplit, | |
723 | TColStd_SequenceOfInteger& indexes, | |
724 | const TColStd_SequenceOfReal& values) | |
725 | { | |
726 | Standard_Boolean isreversed = ( nsplit >0 && sbwd->Edge(index).Orientation() == TopAbs_REVERSED ); | |
727 | ||
728 | TColStd_Array1OfReal params(0,nsplit); | |
729 | Standard_Integer i; // svv #1 | |
730 | for ( i=0; i < nsplit; i++ ) { | |
731 | Standard_Real f, l; | |
732 | BRep_Tool::Range ( sbwd->Edge(index+i), myFace, f, l ); | |
733 | params.SetValue ( i, ( isreversed ? l : f ) ); | |
734 | } | |
735 | ||
736 | for ( i=1; i <= indexes.Length() && indexes(i) < index; i++ ); | |
737 | for ( Standard_Integer shift = 1; i <= indexes.Length() && indexes(i) == index; i++ ) { | |
738 | while ( shift < nsplit && isreversed != (Standard_Boolean) ( values(i) > params(shift) ) ) shift++; | |
739 | indexes.SetValue ( i, index + shift - 1 ); | |
740 | } | |
741 | for ( ; i <= indexes.Length(); i++ ) | |
742 | indexes.SetValue ( i, indexes(i) + nsplit - 1 ); | |
743 | } | |
744 | ||
745 | ||
746 | //======================================================================= | |
747 | //function : CheckByCurve3d | |
748 | //purpose : auxilary | |
749 | //======================================================================= | |
750 | static Standard_Integer CheckByCurve3d (const gp_Pnt &pos, | |
751 | const Handle(Geom_Curve) &c3d, | |
752 | const Standard_Real param, | |
753 | const gp_Trsf &T, | |
754 | const Standard_Real tol) | |
755 | { | |
756 | if ( c3d.IsNull() ) return Standard_True; | |
757 | gp_Pnt p = c3d->Value(param); | |
758 | if ( T.Form() != gp_Identity ) p.Transform ( T ); | |
759 | return pos.SquareDistance ( p ) <= tol * tol; | |
760 | } | |
761 | ||
762 | ||
763 | //======================================================================= | |
764 | //function : DefinePatch | |
765 | //purpose : auxilary | |
766 | //======================================================================= | |
767 | static void DefinePatch (ShapeFix_WireSegment &wire, const Standard_Integer code, | |
768 | const Standard_Boolean isCutByU, const Standard_Integer cutIndex, | |
769 | const Standard_Integer number = -1) | |
770 | { | |
771 | Standard_Integer nb = (number > 0 ? number : wire.NbEdges()); | |
772 | if ( isCutByU ) { | |
773 | if ( ! ( code & IOR_LEFT ) ) wire.DefineIUMin ( nb, cutIndex ); | |
774 | if ( ! ( code & IOR_RIGHT ) ) wire.DefineIUMax ( nb, cutIndex ); | |
775 | } | |
776 | else { | |
777 | if ( ! ( code & IOR_RIGHT ) ) wire.DefineIVMin ( nb, cutIndex ); | |
778 | if ( ! ( code & IOR_LEFT ) ) wire.DefineIVMax ( nb, cutIndex ); | |
779 | } | |
780 | } | |
781 | ||
782 | ||
783 | //======================================================================= | |
784 | //function : DefinePatchForWire | |
785 | //purpose : auxilary | |
786 | //======================================================================= | |
787 | static void DefinePatchForWire(ShapeFix_WireSegment &wire, const Standard_Integer code, | |
788 | const Standard_Boolean isCutByU, const Standard_Integer cutIndex) | |
789 | { | |
790 | for(Standard_Integer i = 1; i <= wire.NbEdges(); i++) | |
791 | DefinePatch(wire,code,isCutByU,cutIndex,i); | |
792 | } | |
793 | ||
794 | ||
795 | //======================================================================= | |
796 | //function : GetGridResolution | |
797 | //purpose : auxilary | |
798 | //======================================================================= | |
799 | static Standard_Real GetGridResolution(const Handle(TColStd_HArray1OfReal) SplitValues, | |
800 | const Standard_Integer cutIndex) | |
801 | { | |
802 | Standard_Integer nb = SplitValues->Length(); | |
803 | Standard_Real leftLen = (cutIndex > 1 ? SplitValues->Value(cutIndex) - SplitValues->Value(cutIndex-1) : | |
804 | SplitValues->Value(nb) -SplitValues->Value(nb-1)); | |
805 | Standard_Real rigthLen =(cutIndex < nb ? SplitValues->Value(cutIndex+1)-SplitValues->Value(cutIndex) : | |
806 | SplitValues->Value(2) - SplitValues->Value(1)); | |
807 | return Min(leftLen,rigthLen)/3.; | |
808 | } | |
809 | ||
810 | ||
811 | //======================================================================= | |
812 | //function : SplitWire | |
813 | //purpose : | |
814 | //======================================================================= | |
815 | ||
816 | ShapeFix_WireSegment ShapeFix_ComposeShell::SplitWire (ShapeFix_WireSegment &wire, | |
817 | TColStd_SequenceOfInteger& indexes, | |
818 | const TColStd_SequenceOfReal& values, | |
819 | TopTools_SequenceOfShape& vertices, | |
820 | const TColStd_SequenceOfInteger &SegmentCodes, | |
821 | const Standard_Boolean isCutByU, | |
822 | const Standard_Integer cutIndex) | |
823 | { | |
824 | BRep_Builder B; | |
825 | ShapeFix_WireSegment result; | |
826 | Handle(ShapeAnalysis_Surface) aSurfTool = | |
827 | new ShapeAnalysis_Surface ( BRep_Tool::Surface (myFace) ); | |
828 | Standard_Integer nbSplits = indexes.Length(); | |
829 | ShapeAnalysis_Edge sae; | |
830 | Standard_Integer start = 1; | |
831 | TopAbs_Orientation anWireOrient = wire.Orientation(); | |
832 | gp_Trsf T; | |
833 | if ( ! myLoc.IsIdentity() ) T = myLoc.Inverted().Transformation(); | |
834 | ||
835 | // Processing edge by edge (assuming that split points are sorted along the wire) | |
836 | for ( Standard_Integer i = 1; i <= wire.NbEdges(); i++ ) { | |
837 | ||
838 | // for already splitted seam edge, redistribute its splitting points | |
839 | Standard_Integer nsplit = ApplyContext ( wire, i, Context() ); | |
840 | if ( nsplit !=1 ) { | |
841 | DistributeSplitPoints ( wire.WireData(), myFace, i, nsplit, indexes, values ); | |
842 | if ( nsplit <=0 ) { | |
0797d9d3 | 843 | #ifdef OCCT_DEBUG |
7fd59977 | 844 | cout << "Error: ShapeFix_ComposeShell::SplitWire: edge dismissed" << endl; |
845 | #endif | |
846 | i--; | |
847 | continue; | |
848 | } | |
849 | } | |
850 | TopoDS_Edge edge = wire.Edge(i); | |
851 | ||
852 | Standard_Integer iumin, iumax, ivmin, ivmax; | |
853 | wire.GetPatchIndex ( i, iumin, iumax, ivmin, ivmax ); | |
854 | ||
855 | // Position code for first segment of edge | |
856 | Standard_Integer code = SegmentCodes ( start >1 ? start-1 : SegmentCodes.Length() ); | |
857 | ||
858 | // Defining split parameters on edge | |
859 | Standard_Integer stop = start; | |
860 | while ( stop <= nbSplits && indexes(stop) == i ) stop++; | |
861 | if ( stop == start ) { | |
862 | result.AddEdge ( 0, edge, iumin, iumax, ivmin, ivmax ); | |
863 | if(code!=0 || wire.Orientation()!=TopAbs_EXTERNAL) // pdn 0 code handling for extertnal wires | |
864 | DefinePatch ( result, code, isCutByU, cutIndex ); | |
865 | continue; | |
866 | } | |
867 | //find non-manifold vertices on edge | |
868 | TopTools_SequenceOfShape aNMVertices; | |
869 | TopoDS_Iterator aIt(edge,Standard_False); | |
870 | for( ; aIt.More(); aIt.Next()) { | |
871 | if(aIt.Value().Orientation() != TopAbs_FORWARD && | |
872 | aIt.Value().Orientation() != TopAbs_REVERSED) | |
873 | aNMVertices.Append(aIt.Value()); | |
874 | } | |
875 | ||
876 | // Collect data on edge | |
877 | Standard_Real tolEdge = BRep_Tool::Tolerance(edge); | |
878 | Standard_Real tol = LimitTolerance( tolEdge ); | |
879 | TopoDS_Vertex prevV = sae.FirstVertex(edge); | |
880 | TopoDS_Vertex lastV = sae.LastVertex(edge); | |
881 | Standard_Real prevVTol = LimitTolerance( BRep_Tool::Tolerance(prevV) ); | |
882 | Standard_Real lastVTol = LimitTolerance( BRep_Tool::Tolerance(lastV) ); | |
883 | gp_Pnt prevVPnt = BRep_Tool::Pnt(prevV); | |
884 | gp_Pnt lastVPnt = BRep_Tool::Pnt(lastV); | |
885 | if ( T.Form() != gp_Identity ) { | |
886 | prevVPnt.Transform ( T ); | |
887 | lastVPnt.Transform ( T ); | |
888 | } | |
889 | ||
890 | Handle(Geom_Curve) c3d; | |
891 | Standard_Real f3d, l3d; | |
892 | if ( ! sae.Curve3d ( edge, c3d, f3d, l3d ) ) { // not a crime | |
893 | c3d.Nullify(); | |
894 | f3d = l3d = 0; | |
895 | } | |
896 | ||
897 | Standard_Real firstPar, lastPar; | |
898 | Handle(Geom2d_Curve) C2d; | |
899 | if ( ! sae.PCurve ( edge, myFace, C2d, firstPar, lastPar ) ) { | |
900 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
901 | } | |
902 | //finding sequence of non-manifold parameters | |
903 | Standard_Integer nbNMVert = aNMVertices.Length(); | |
904 | TColStd_SequenceOfReal aNMVertParams; | |
905 | if( nbNMVert) { | |
906 | Geom2dAdaptor_Curve adc(C2d); | |
907 | ||
908 | Standard_Integer n =1; | |
909 | for( ; n<= nbNMVert; n++) { | |
910 | gp_Pnt apV = BRep_Tool::Pnt(TopoDS::Vertex(aNMVertices.Value(n))); | |
911 | Standard_Real apar =firstPar; | |
912 | Standard_Real adist2 =RealLast(); | |
913 | gp_Pnt aPproj; | |
914 | if(!c3d.IsNull()) { | |
915 | ShapeAnalysis_Curve asae; | |
916 | adist2 = asae.Project(c3d,apV,Precision::Confusion(),aPproj,apar); | |
917 | adist2 *= adist2; | |
918 | } | |
919 | else { | |
920 | ||
921 | gp_Pnt2d aP2d = aSurfTool->ValueOfUV(apV,Precision::Confusion()); | |
922 | Extrema_ExtPC2d aExtr(aP2d,adc); | |
923 | if(aExtr.IsDone() && aExtr.NbExt()) { | |
924 | adist2 = aExtr.SquareDistance(1); | |
925 | Standard_Integer index =1; | |
926 | Standard_Integer k =2; | |
927 | for( ; k <= aExtr.NbExt();k++) { | |
928 | Standard_Real ad2 = aExtr.SquareDistance(k); | |
929 | if( ad2 <adist2) { | |
930 | adist2 = ad2; | |
931 | index =k; | |
932 | } | |
933 | } | |
934 | apar = aExtr.Point(index).Parameter(); | |
935 | ||
936 | } | |
937 | } | |
938 | aNMVertParams.Append(apar); | |
939 | } | |
940 | } | |
941 | ||
942 | //pdn Claculating parametric shift | |
943 | Standard_Boolean sp = (f3d == firstPar && l3d == lastPar); | |
944 | Standard_Real span2d = lastPar - firstPar; | |
945 | // Standard_Real ln2d = lastPar-prevPar; | |
946 | // Standard_Real ln3d = l3d - f3d; | |
947 | // Standard_Real fact = ln2d/ln3d; | |
948 | // Standard_Real shift = prevPar - f3d*fact; | |
949 | Standard_Real prevPar = firstPar; | |
950 | gp_Pnt2d prevPnt2d = C2d->Value(prevPar); | |
951 | gp_Pnt2d lastPnt2d = C2d->Value(lastPar); | |
952 | gp_Pnt prevPnt = myGrid->Value ( prevPnt2d ); | |
953 | gp_Pnt lastPnt = myGrid->Value ( lastPnt2d ); | |
954 | Standard_Boolean isPeriodic = C2d->IsPeriodic(); | |
955 | Standard_Real aPeriod = (isPeriodic ? C2d->Period() :0.); | |
956 | ||
957 | // Splitting edge | |
958 | Standard_Integer NbEdgesStart = result.NbEdges(); | |
959 | Standard_Boolean splitted = Standard_False; | |
960 | Standard_Real currPar=lastPar; //SK | |
961 | for ( Standard_Integer j = start; j <= stop; prevPar = currPar, j++ ) { | |
962 | if ( ! splitted && j >= stop ) { // no splitting at all | |
963 | // code = SegmentCodes ( j >1 ? j-1 : SegmentCodes.Length() ); // classification code | |
964 | break; | |
965 | } | |
966 | currPar = ( j < stop ? values.Value(j) : lastPar ); | |
967 | ||
968 | //fix for case when pcurve is periodic and first parameter of edge is more than 2P | |
969 | //method ShapeBuild_Edge::CopyRanges shift pcurve to range 0-2P and parameters of cutting | |
970 | //should be shifted too. gka SAMTECH 28.07.06 | |
971 | if(isPeriodic ) { | |
972 | if (currPar > (Max(lastPar,firstPar) +Precision::PConfusion()) || | |
973 | currPar < (Min(firstPar,lastPar)- Precision::PConfusion())) { | |
974 | Standard_Real aShift = ShapeAnalysis::AdjustByPeriod(currPar, (firstPar+lastPar)*0.5,aPeriod); | |
975 | currPar+=aShift; | |
976 | } | |
977 | } | |
978 | ||
979 | gp_Pnt2d currPnt2d; | |
980 | gp_Pnt currPnt; | |
981 | ||
982 | // Try to adjust current splitting point to previous or end of edge | |
983 | Standard_Boolean doCut = Standard_True; | |
984 | TopoDS_Vertex V; | |
985 | if ( Abs ( currPar - lastPar ) < ::Precision::PConfusion() ) { | |
986 | V = lastV; | |
987 | doCut = Standard_False; | |
988 | } | |
989 | else if ( Abs ( currPar - prevPar ) < ::Precision::PConfusion() ) { | |
990 | vertices.Append ( prevV ); | |
991 | code = SegmentCodes ( j ); // classification code - update for next segment | |
992 | continue; // no splitting at this point, go to next one | |
993 | } | |
994 | else { | |
995 | currPnt2d = C2d->Value(currPar); | |
996 | currPnt = myGrid->Value ( currPnt2d ); | |
997 | if ( currPnt.Distance ( lastVPnt ) <= lastVTol && | |
998 | lastPnt.Distance ( currPnt ) <= tol && | |
999 | CheckByCurve3d ( lastVPnt, c3d, f3d+(currPar-firstPar)*(l3d-f3d)/span2d, | |
1000 | T, lastVTol ) && | |
1001 | lastPnt.Distance ( myGrid->Value ( C2d->Value(0.5*(currPar+lastPar)) ) ) <= tol ) { | |
1002 | V = lastV; | |
1003 | Standard_Real uRes = myUResolution; | |
1004 | Standard_Real vRes = myVResolution; | |
1005 | if(isCutByU) { | |
1006 | Standard_Real gridRes = GetGridResolution(myGrid->UJointValues(),cutIndex)/tol; | |
1007 | uRes = Min(myUResolution,gridRes); | |
1008 | } | |
1009 | else { | |
1010 | Standard_Real gridRes = GetGridResolution(myGrid->VJointValues(),cutIndex)/tol; | |
1011 | vRes = Min(myVResolution,gridRes); | |
1012 | } | |
1013 | if ( IsCoincided ( lastPnt2d, currPnt2d, uRes, vRes, tol ) && | |
1014 | IsCoincided ( lastPnt2d, C2d->Value(0.5*(currPar+lastPar)), | |
1015 | uRes, vRes, tol ) ) doCut = Standard_False; | |
1016 | } | |
1017 | else if ( currPnt.Distance ( prevVPnt ) <= prevVTol && | |
1018 | prevPnt.Distance ( currPnt ) <= tol && | |
1019 | CheckByCurve3d ( prevVPnt, c3d, f3d+(currPar-firstPar)*(l3d-f3d)/span2d, | |
1020 | T, prevVTol ) && | |
1021 | prevPnt.Distance ( myGrid->Value ( C2d->Value(0.5*(currPar+prevPar)) ) ) <= tol ) { | |
1022 | V = prevV; | |
1023 | Standard_Real uRes = myUResolution; | |
1024 | Standard_Real vRes = myVResolution; | |
1025 | if(isCutByU) { | |
1026 | Standard_Real gridRes = GetGridResolution(myGrid->UJointValues(),cutIndex)/tol; | |
1027 | uRes = Min(myUResolution,gridRes); | |
1028 | } | |
1029 | else { | |
1030 | Standard_Real gridRes = GetGridResolution(myGrid->VJointValues(),cutIndex)/tol; | |
1031 | vRes = Min(myVResolution,gridRes); | |
1032 | } | |
1033 | if ( IsCoincided ( prevPnt2d, currPnt2d, uRes, vRes, tol ) && | |
1034 | IsCoincided ( prevPnt2d, C2d->Value(0.5*(currPar+prevPar)), | |
1035 | uRes, vRes, tol ) ) { | |
1036 | vertices.Append ( prevV ); | |
1037 | code = SegmentCodes ( j ); // classification code - update for next segment | |
1038 | continue; // no splitting at this point, go to next one | |
1039 | } | |
1040 | } | |
1041 | //:abv 28.05.02: OCC320 Sample_2: if maxtol = 1e-7, the vertex tolerance | |
1042 | // is actually ignored - protect against new vertex on degenerated edge | |
1043 | else if ( BRep_Tool::Degenerated(edge) && prevV.IsSame(lastV) ) { | |
1044 | V = prevV; | |
1045 | } | |
1046 | } | |
1047 | // classification code for current segment | |
1048 | if ( j > start ) code = SegmentCodes ( j >1 ? j-1 : SegmentCodes.Length() ); | |
1049 | ||
1050 | // if not adjusted, make new vertex | |
1051 | if ( V.IsNull() ) { | |
1052 | B.MakeVertex ( V, currPnt.Transformed(myLoc.Transformation()), tolEdge ); | |
1053 | vertices.Append ( V ); | |
1054 | } | |
1055 | // else adjusted to end, fill all resting vertices | |
1056 | else if ( ! doCut ) { | |
1057 | for ( ; j < stop; j++ ) vertices.Append ( lastV ); | |
1058 | if ( ! splitted ) break; // no splitting at all | |
1059 | currPar = lastPar; | |
1060 | } | |
1061 | else vertices.Append ( V ); | |
1062 | ||
1063 | // When edge is about to be splitted, copy end vertices to protect | |
1064 | // original shape from increasing tolerance after fixing SameParameter | |
1065 | if ( ! splitted ) { | |
1066 | //smh#8 | |
1067 | TopoDS_Shape emptyCopiedfV = prevV.EmptyCopied(); | |
1068 | TopoDS_Vertex fV = TopoDS::Vertex (emptyCopiedfV ); | |
1069 | Context()->Replace ( prevV, fV ); | |
1070 | TopoDS_Vertex lV; | |
1071 | if ( prevV.IsSame ( lastV ) ) { | |
1072 | //smh#8 | |
1073 | TopoDS_Shape tmpV = fV.Oriented ( lastV.Orientation() ) ; | |
1074 | lV = TopoDS::Vertex (tmpV); | |
1075 | } | |
1076 | else { | |
1077 | //smh#8 | |
1078 | TopoDS_Shape emptyCopied = lastV.EmptyCopied(); | |
1079 | lV = TopoDS::Vertex (emptyCopied); | |
1080 | Context()->Replace ( lastV, lV ); | |
1081 | } | |
1082 | if ( V.IsSame ( lastV ) ) V = lV; | |
1083 | else if ( V.IsSame ( prevV ) ) V = fV; | |
1084 | lastV = lV; | |
1085 | prevV = fV; | |
1086 | } | |
1087 | ||
1088 | // Splitting of the edge | |
1089 | splitted = Standard_True; | |
1090 | prevV.Orientation ( TopAbs_FORWARD ); | |
1091 | V.Orientation ( TopAbs_REVERSED ); | |
1092 | ShapeBuild_Edge sbe; | |
1093 | TopoDS_Edge anInitEdge = edge; | |
1094 | Standard_Boolean ismanifold = (edge.Orientation() == TopAbs_FORWARD || | |
1095 | edge.Orientation() == TopAbs_REVERSED); | |
1096 | if(!ismanifold) | |
1097 | anInitEdge.Orientation(TopAbs_FORWARD); | |
1098 | TopoDS_Edge newEdge = sbe.CopyReplaceVertices (anInitEdge, prevV, V ); | |
1099 | ||
1100 | ||
1101 | //addition internal vertices if they exists on edge | |
1102 | Standard_Integer n =1; | |
1103 | for( ; n <= aNMVertParams.Length(); n++) { | |
1104 | Standard_Real apar = aNMVertParams.Value(n); | |
1105 | TopoDS_Vertex aNMVert =TopoDS::Vertex(aNMVertices.Value(n)); | |
1106 | TopoDS_Vertex atmpV = TopoDS::Vertex(Context()->Apply(aNMVert)); | |
1107 | if(fabs(apar - prevPar) <= Precision::PConfusion()) { | |
1108 | Context()->Replace(atmpV,prevV); | |
1109 | aNMVertParams.Remove(n); | |
1110 | aNMVertices.Remove(n); | |
1111 | n--; | |
1112 | } | |
1113 | else if(fabs(apar - currPar) <= Precision::PConfusion()) { | |
1114 | Context()->Replace(atmpV,V); | |
1115 | aNMVertParams.Remove(n); | |
1116 | aNMVertices.Remove(n); | |
1117 | n--; | |
1118 | } | |
1119 | if(apar > prevPar && apar < currPar) { | |
1120 | B.Add(newEdge,atmpV); | |
1121 | aNMVertParams.Remove(n); | |
1122 | aNMVertices.Remove(n); | |
1123 | n--; | |
1124 | } | |
1125 | } | |
1126 | ||
1127 | ||
1128 | sbe.CopyPCurves ( newEdge, anInitEdge ); | |
1129 | ||
1130 | ||
1131 | Handle(ShapeAnalysis_TransferParameters) theTransferParamtool = GetTransferParamTool(); | |
1132 | theTransferParamtool->SetMaxTolerance(MaxTolerance()); | |
1133 | theTransferParamtool->Init(anInitEdge,myFace); | |
1134 | theTransferParamtool->TransferRange(newEdge,prevPar,currPar,Standard_True); | |
1135 | ||
1136 | ||
1137 | if(!ismanifold) { | |
1138 | if(code == IOR_UNDEF) //tangential segment | |
1139 | newEdge.Orientation(TopAbs_EXTERNAL); | |
1140 | else | |
1141 | newEdge.Orientation(edge.Orientation()); | |
1142 | } | |
1143 | ||
1144 | if(!sp && !BRep_Tool::Degenerated(newEdge)) | |
1145 | B.SameRange(newEdge, Standard_False); | |
1146 | //pdn take into account 0 codes (if ext) | |
1147 | if(code == 0 && wire.Orientation()==TopAbs_EXTERNAL){ | |
1148 | code = ( ( isCutByU == (Standard_Boolean)( j == 1 ) ) ? 1 : 2 ); | |
1149 | } | |
1150 | ||
1151 | result.AddEdge ( 0, newEdge, iumin, iumax, ivmin, ivmax ); | |
1152 | DefinePatch ( result, code, isCutByU, cutIndex ); | |
1153 | ||
1154 | // Changing prev parameters | |
1155 | prevV = V; | |
1156 | prevVTol = LimitTolerance( BRep_Tool::Tolerance ( V ) ); | |
1157 | prevVPnt = BRep_Tool::Pnt ( V ); | |
1158 | prevPnt = currPnt; | |
1159 | prevPnt2d = currPnt2d; | |
1160 | } | |
1161 | start = stop; | |
1162 | ||
1163 | if ( splitted ) { | |
1164 | // record replacement in context | |
1165 | // NOTE: order of edges in the replacing wire corresponds to FORWARD orientation of the edge | |
1166 | TopoDS_Wire resWire; | |
1167 | B.MakeWire ( resWire ); | |
1168 | for ( Standard_Integer k=NbEdgesStart; k < result.NbEdges(); k++ ) { | |
1169 | if ( edge.Orientation() == TopAbs_FORWARD || edge.Orientation() == TopAbs_INTERNAL) | |
1170 | B.Add ( resWire, result.Edge(k+1) ); | |
1171 | else B.Add ( resWire, result.Edge(result.NbEdges()-k+NbEdgesStart) ); | |
1172 | } | |
1173 | Context()->Replace ( edge, resWire ); | |
1174 | } | |
1175 | else { | |
1176 | if(anWireOrient == TopAbs_INTERNAL && code ==0) { | |
1177 | ShapeBuild_Edge sbe; | |
1178 | if(edge.Orientation() == TopAbs_INTERNAL) | |
1179 | edge.Orientation(TopAbs_FORWARD); | |
1180 | TopoDS_Edge e1 = sbe.Copy(edge,Standard_False); | |
1181 | Handle(Geom2d_Curve) C2d2 = Handle(Geom2d_Curve)::DownCast(C2d->Copy()); | |
1182 | B.UpdateEdge(e1,C2d,C2d2,myFace,0.); | |
1183 | e1.Orientation(TopAbs_EXTERNAL); | |
1184 | Context()->Replace ( edge,e1); | |
1185 | result.AddEdge ( 0,e1 , iumin, iumax, ivmin, ivmax ); | |
1186 | } | |
1187 | else | |
1188 | result.AddEdge ( 0, edge, iumin, iumax, ivmin, ivmax ); | |
1189 | if(code == 0 && wire.Orientation()==TopAbs_EXTERNAL){ | |
1190 | //pdn defining code for intersection of two isos | |
1191 | code = ( ( isCutByU == (Standard_Boolean)( Abs(firstPar-currPar) < Abs(lastPar-currPar) ) ) ? 2 : 1 ); | |
1192 | } | |
1193 | DefinePatch ( result, code, isCutByU, cutIndex ); | |
1194 | } | |
1195 | } | |
1196 | result.Orientation ( anWireOrient ); | |
1197 | return result; | |
1198 | } | |
1199 | ||
1200 | ||
1201 | //======================================================================= | |
1202 | //function : SplitByLine | |
1203 | //purpose : | |
1204 | //======================================================================= | |
1205 | ||
1206 | Standard_Boolean ShapeFix_ComposeShell::SplitByLine (ShapeFix_WireSegment &wire, | |
1207 | const gp_Lin2d &line, | |
1208 | const Standard_Boolean isCutByU, | |
1209 | const Standard_Integer cutIndex, | |
1210 | TColStd_SequenceOfReal &SplitLinePar, | |
1211 | TColStd_SequenceOfInteger &SplitLineCode, | |
1212 | TopTools_SequenceOfShape &SplitLineVertex) | |
1213 | { | |
1214 | ShapeAnalysis_Edge sae; | |
1215 | // prepare data on cutting line | |
1216 | Handle(Geom2d_Line) jC2d = new Geom2d_Line ( line ); | |
1217 | Geom2dAdaptor_Curve jGAC(jC2d); | |
1218 | ||
1219 | TColStd_SequenceOfInteger IntEdgeInd; // index of intersecting edge | |
1220 | TColStd_SequenceOfReal IntEdgePar; // parameter of intersection point on edge | |
1221 | TColStd_SequenceOfReal IntLinePar; // parameter of intersection point on line | |
1222 | ||
1223 | Standard_Boolean isnonmanifold = (wire.Orientation() == TopAbs_INTERNAL); | |
1224 | //gka correction for non-manifold vertices SAMTECH | |
1225 | if(wire.IsVertex()) { | |
1226 | Handle(ShapeAnalysis_Surface) aSurfTool = new ShapeAnalysis_Surface ( BRep_Tool::Surface (myFace) ); | |
1227 | TopoDS_Vertex aVert = wire.GetVertex(); | |
1228 | gp_Pnt aP3d = BRep_Tool::Pnt(aVert); | |
1229 | gp_Pnt2d aP2d = aSurfTool->ValueOfUV(aP3d,Precision::Confusion()); | |
1230 | Standard_Real dev =0.; | |
1231 | Standard_Integer code = PointLinePosition(aP2d,line,dev); | |
1232 | if(code != IOR_UNDEF) | |
1233 | return Standard_False; | |
1234 | Standard_Real par = ParamPointOnLine (aP2d,line); | |
1235 | SplitLinePar.Append ( par ); | |
1236 | //splitting codes for non-manifold topology should be tangential | |
1237 | SplitLineCode.Append (ITP_TANG); //ITP_INTER); | |
1238 | TopoDS_Vertex aVertNew; | |
1239 | BRep_Builder aB; | |
1240 | aB.MakeVertex(aVertNew,aP3d,BRep_Tool::Tolerance(aVert)); | |
1241 | aVertNew.Orientation(TopAbs_FORWARD); | |
1242 | Context()->Replace(aVert,aVertNew); | |
1243 | SplitLineVertex.Append (aVertNew); | |
1244 | wire.SetVertex(aVertNew); | |
1245 | return Standard_True; | |
1246 | } | |
1247 | const Handle(ShapeExtend_WireData) sewd = wire.WireData(); | |
1248 | ||
1249 | Standard_Integer nbe = sewd->NbEdges(); | |
1250 | ||
1251 | //:abv 31.10.01: for closed mode | |
1252 | Standard_Integer closedDir = 0; | |
1253 | if ( myClosedMode ) { | |
1254 | if ( myUClosed && Abs ( line.Direction().X() ) < ::Precision::PConfusion() ) | |
1255 | closedDir = -1; | |
1256 | else if ( myVClosed && Abs ( line.Direction().Y() ) < ::Precision::PConfusion() ) | |
1257 | closedDir = 1; | |
1258 | } | |
1259 | Standard_Real halfPeriod = 0.5 * ( closedDir ? closedDir <0 ? myUPeriod : myVPeriod : 0. ); | |
1260 | ||
1261 | //============================================ | |
1262 | // make intersections and collect all data on intersection points | |
1263 | Standard_Integer firstCode=0, prevCode=0; | |
1264 | gp_Pnt2d firstPos, prevPos; | |
1265 | Standard_Real firstDev=0., prevDev=0.; | |
1266 | for (Standard_Integer iedge = 1; iedge <= nbe; iedge++) { | |
1267 | ||
1268 | TopoDS_Edge E= sewd->Edge ( iedge ); | |
1269 | Standard_Boolean isreversed = ( E.Orientation() == TopAbs_REVERSED ); | |
1270 | ||
1271 | Standard_Real f, l; | |
1272 | Handle(Geom2d_Curve) c2d; | |
1273 | if ( ! sae.PCurve ( E, myFace, c2d, f, l, Standard_False ) ) continue; | |
1274 | ||
1275 | // get end points | |
1276 | gp_Pnt2d posf = c2d->Value(f), posl = c2d->Value(l); | |
1277 | gp_XY pppf = posf.XY(), pppl = posl.XY(); | |
1278 | ||
1279 | // In case of ClosedMode, adjust curve and end points to period on closed surface | |
1280 | //:abv 16.10.01: Ziegler_CADDY01.sat -18: if pcurve is longer than period, | |
1281 | // ensure processing of all intersections | |
1282 | Standard_Integer nbIter = 1; | |
1283 | gp_Vec2d shiftNext(0.,0.); | |
1284 | if ( myClosedMode ) { | |
1285 | ||
1286 | // get bounding box of pcurve | |
1287 | ShapeAnalysis_Curve sac; | |
1288 | Bnd_Box2d box; | |
696d81d0 | 1289 | const Standard_Integer aNbPoints = 41; |
1290 | sac.FillBndBox ( c2d, f, l, aNbPoints, Standard_True, box ); | |
7fd59977 | 1291 | Standard_Real umin, vmin, umax, vmax; |
1292 | box.Get ( umin, vmin, umax, vmax ); | |
1293 | ||
1294 | // compute shifts and adjust points adjust | |
1295 | if ( closedDir < 0 ) { | |
1296 | Standard_Real x = line.Location().X(); | |
1297 | Standard_Real shift = ShapeAnalysis::AdjustToPeriod ( umin, x-myUPeriod, x ); | |
1298 | if ( shift != 0. ) { | |
1299 | c2d = Handle(Geom2d_Curve)::DownCast ( c2d->Copy() ); | |
1300 | gp_Vec2d V ( shift, 0. ); | |
1301 | c2d->Translate ( V ); | |
1302 | pppf.SetX ( pppf.X() + shift ); | |
1303 | pppl.SetX ( pppl.X() + shift ); | |
1304 | } | |
1305 | shiftNext.SetX ( -myUPeriod ); | |
1306 | nbIter = (Standard_Integer)( 1 + Abs ( umax + shift - x ) / myUPeriod ); | |
1307 | shift = ShapeAnalysis::AdjustByPeriod ( posf.X(), x, myUPeriod ); | |
1308 | posf.SetX ( posf.X() + shift ); | |
1309 | shift = ShapeAnalysis::AdjustByPeriod ( posl.X(), x, myUPeriod ); | |
1310 | posl.SetX ( posl.X() + shift ); | |
1311 | } | |
1312 | else if ( closedDir > 0 ) { | |
1313 | Standard_Real y = line.Location().Y(); | |
1314 | Standard_Real shift = ShapeAnalysis::AdjustToPeriod ( vmin, y-myVPeriod, y ); | |
1315 | if ( shift != 0. ) { | |
1316 | c2d = Handle(Geom2d_Curve)::DownCast ( c2d->Copy() ); | |
1317 | gp_Vec2d V ( 0., shift ); | |
1318 | c2d->Translate ( V ); | |
1319 | pppf.SetY ( pppf.Y() + shift ); | |
1320 | pppl.SetY ( pppl.Y() + shift ); | |
1321 | } | |
1322 | shiftNext.SetY ( -myVPeriod ); | |
1323 | nbIter = (Standard_Integer)( 1 + Abs ( umax + shift - y ) / myVPeriod ); | |
1324 | shift = ShapeAnalysis::AdjustByPeriod ( posf.Y(), y, myVPeriod ); | |
1325 | posf.SetY ( posf.Y() + shift ); | |
1326 | shift = ShapeAnalysis::AdjustByPeriod ( posl.Y(), y, myVPeriod ); | |
1327 | posl.SetY ( posl.Y() + shift ); | |
1328 | } | |
1329 | } | |
1330 | ||
1331 | // detect intersections at junction of two edges | |
1332 | gp_Pnt2d pos = ( isreversed ? posl : posf ); | |
1333 | Standard_Real dev; | |
1334 | Standard_Integer code = PointLinePosition ( pos, line, dev ); | |
1335 | if ( iedge ==1 ) { firstCode = code; firstPos = pos; firstDev = dev; } | |
1336 | else if ( code == IOR_UNDEF || code != prevCode ) { | |
1337 | if ( ! closedDir || Abs ( dev - prevDev ) < halfPeriod ) { | |
1338 | IntLinePar.Append ( ParamPointsOnLine ( pos, prevPos, line ) ); // !! - maybe compute exactly ? | |
1339 | IntEdgePar.Append ( isreversed ? l : f ); | |
1340 | IntEdgeInd.Append ( iedge ); | |
1341 | } | |
1342 | } | |
1343 | ||
1344 | // fill data on end point (for next edge) | |
1345 | pos = ( isreversed ? posf : posl ); | |
1346 | prevCode = PointLinePosition ( pos, line, prevDev ); | |
1347 | prevPos = pos; | |
1348 | ||
1349 | // cycle with shift in order to track all possible intersections | |
1350 | for ( Standard_Integer iter=1; iter <= nbIter; iter++ ) { | |
1351 | ||
1352 | // data for intersection | |
1353 | IntRes2d_Domain iDom ( pppf, f, TOLINT, pppl, l, TOLINT ); | |
1354 | Geom2dAdaptor_Curve iGAC(c2d); | |
1355 | ||
1356 | // intersection | |
1357 | Geom2dInt_GInter Inter; | |
1358 | Inter.Perform ( jGAC, /*jDom,*/ iGAC, iDom, TOLINT, TOLINT ); | |
1359 | ||
1360 | // Fill arrays with new intersection points | |
1361 | if ( Inter.IsDone() ) { | |
1362 | ||
1363 | Standard_Integer i; | |
1364 | for ( i = 1; i <= Inter.NbPoints(); i++ ) { | |
1365 | IntRes2d_IntersectionPoint IP = Inter.Point (i); | |
1366 | IntLinePar.Append ( IP.ParamOnFirst() ); | |
1367 | IntEdgePar.Append ( IP.ParamOnSecond() ); | |
1368 | } | |
1369 | for ( i = 1; i <= Inter.NbSegments(); i++ ) { | |
1370 | IntRes2d_IntersectionSegment IS = Inter.Segment (i); | |
1371 | if ( IS.HasFirstPoint() ) { | |
1372 | IntRes2d_IntersectionPoint IP = IS.FirstPoint(); | |
1373 | IntLinePar.Append ( IP.ParamOnFirst() ); | |
1374 | IntEdgePar.Append ( IP.ParamOnSecond() ); | |
1375 | } | |
1376 | if ( IS.HasLastPoint() ) { | |
1377 | IntRes2d_IntersectionPoint IP = IS.LastPoint(); | |
1378 | IntLinePar.Append ( IP.ParamOnFirst() ); | |
1379 | IntEdgePar.Append ( IP.ParamOnSecond() ); | |
1380 | } | |
1381 | } | |
1382 | } | |
1383 | ||
1384 | if ( iter < nbIter ) { | |
1385 | if ( iter == 1 ) c2d = Handle(Geom2d_Curve)::DownCast ( c2d->Copy() ); | |
1386 | pppf += shiftNext.XY(); | |
1387 | pppl += shiftNext.XY(); | |
1388 | c2d->Translate ( shiftNext ); | |
1389 | } | |
1390 | } | |
1391 | ||
1392 | Standard_Integer start = IntEdgeInd.Length() + 1; // first of the new points | |
1393 | ||
1394 | // Move all points into range [f,l] (intersector sometimes gives params out of range) | |
1395 | Standard_Integer i; | |
1396 | for ( i = start; i <= IntEdgePar.Length(); i++ ) { | |
1397 | if ( IntEdgePar(i) < f ) IntEdgePar.SetValue ( i, f ); | |
1398 | else if ( IntEdgePar(i) > l ) IntEdgePar.SetValue ( i, l ); | |
1399 | } | |
1400 | ||
1401 | // Sort by parameter on edge | |
1402 | for ( i = IntEdgePar.Length(); i > start; i-- ) | |
1403 | for ( Standard_Integer j = start; j < i; j++ ) { | |
1404 | if ( isreversed == (Standard_Boolean) ( IntEdgePar(j+1) < IntEdgePar(j) ) ) continue; | |
1405 | IntLinePar.Exchange ( j, j+1 ); | |
1406 | IntEdgePar.Exchange ( j, j+1 ); | |
1407 | } | |
1408 | ||
1409 | // and fill indices | |
1410 | for ( i = start; i <= IntEdgePar.Length(); i++ ) | |
1411 | IntEdgeInd.Append ( iedge ); | |
1412 | ||
1413 | // Detect intersection at closing point | |
1414 | // Only wires which are not EXTERNAL are considered (as closed) | |
1415 | if ( iedge == nbe && wire.Orientation() != TopAbs_EXTERNAL && | |
1416 | wire.Orientation() != TopAbs_INTERNAL && | |
1417 | ( prevCode == IOR_UNDEF || prevCode != firstCode ) ) { | |
1418 | if ( ! closedDir || Abs ( firstDev - prevDev ) < halfPeriod ) { | |
1419 | IntLinePar.Append ( ParamPointsOnLine ( pos, firstPos, line ) ); | |
1420 | IntEdgePar.Append ( isreversed ? f : l ); | |
1421 | IntEdgeInd.Append ( iedge ); | |
1422 | } | |
1423 | } | |
1424 | } | |
1425 | ||
1426 | if ( IntEdgePar.Length() <1 ) { | |
1427 | //pdn Defining position of wire. There is no intersection, so by any point. | |
1428 | DefinePatchForWire ( wire, firstCode, isCutByU, cutIndex ); | |
1429 | return Standard_False; //pdn ?? | |
1430 | } | |
1431 | ||
1432 | //====================================== | |
1433 | // Fill sequence of transition codes for intersection points | |
1434 | TColStd_SequenceOfInteger IntCode; // parameter of intersection point on line | |
1435 | TColStd_SequenceOfInteger SegmentCodes; // classification codes for segments of wire | |
1436 | ||
1437 | // remove duplicated points to ensure correct results of ComputeCode | |
1438 | Standard_Integer i, j = IntEdgePar.Length(); | |
1439 | if ( myClosedMode && j >1 ) { | |
1440 | for ( i = 1; i <= IntEdgePar.Length(); ) { | |
1441 | if ( i == j ) break; | |
1442 | if ( IntEdgeInd(i) == IntEdgeInd(j) && | |
1443 | Abs ( IntEdgePar(i) - IntEdgePar(j) ) < ::Precision::PConfusion() ) { | |
1444 | IntLinePar.Remove(i); | |
1445 | IntEdgePar.Remove(i); | |
1446 | IntEdgeInd.Remove(i); | |
1447 | if ( j >i ) j--; | |
1448 | continue; | |
1449 | } | |
1450 | else if ( nbe ==1 || IntEdgeInd(i) == (IntEdgeInd(j)%nbe)+1 ) { | |
1451 | TopoDS_Edge E1 = sewd->Edge ( IntEdgeInd(j) ); | |
1452 | TopoDS_Edge E2 = sewd->Edge ( IntEdgeInd(i) ); | |
1453 | Standard_Real a1, b1, a2, b2; | |
1454 | BRep_Tool::Range ( E1, myFace, a1, b1 ); | |
1455 | BRep_Tool::Range ( E2, myFace, a2, b2 ); | |
1456 | if ( Abs ( IntEdgePar(j) - ( E1.Orientation() == TopAbs_FORWARD ? b1 : a1 ) ) < ::Precision::PConfusion() && | |
1457 | Abs ( IntEdgePar(i) - ( E2.Orientation() == TopAbs_FORWARD ? a2 : b2 ) ) < ::Precision::PConfusion() ) { | |
1458 | IntLinePar.Remove(i); | |
1459 | IntEdgePar.Remove(i); | |
1460 | IntEdgeInd.Remove(i); | |
1461 | if ( j >i ) j--; | |
1462 | continue; | |
1463 | } | |
1464 | } | |
1465 | j=i++; | |
1466 | } | |
1467 | } | |
1468 | ||
1469 | // Compute segment codes (left side of line, right or tangential) | |
1470 | for ( i=1; i <= IntEdgePar.Length(); i++ ) { | |
1471 | j = ( i < IntEdgePar.Length() ? i + 1 : 1 ); | |
1472 | Standard_Integer code = ComputeCode ( sewd, line, IntEdgeInd(i), IntEdgeInd(j), | |
1473 | IntEdgePar(i), IntEdgePar(j),isnonmanifold ); | |
1474 | SegmentCodes.Append ( code ); | |
1475 | } | |
1476 | ||
1477 | // for EXTERNAL wire, i.e. another joint line, every point is double intersection | |
1478 | if ( wire.Orientation() == TopAbs_EXTERNAL ) { | |
1479 | for ( i=1; i <= IntEdgePar.Length(); i++ ) | |
1480 | IntCode.Append ( ITP_TANG | IOR_BOTH ); | |
1481 | } | |
1482 | // For real (closed) wire, analyze tangencies | |
1483 | else { | |
1484 | if(wire.Orientation() != TopAbs_INTERNAL) { | |
1485 | // Two consecutive tangential segments are considered as one, merge them. | |
1486 | for ( i=1; i <= IntEdgePar.Length(); i++ ) { | |
1487 | j = ( i > 1 ? i-1 : IntEdgePar.Length() ); | |
d30c4db9 SS |
1488 | |
1489 | int k = ( i < IntEdgePar.Length() ? i + 1 : 1 ); // [ACIS22539] | |
1490 | ||
7fd59977 | 1491 | if ( SegmentCodes(j) == IOR_UNDEF && |
d30c4db9 SS |
1492 | SegmentCodes(i) == IOR_UNDEF ) { |
1493 | ||
1494 | // Very specific case when the constructed seam edge | |
1495 | // overlaps with spur edge [ACIS22539] | |
1496 | if (myClosedMode && (IntLinePar(i) - IntLinePar(j)) * (IntLinePar(k) - IntLinePar(i)) <= 0. ) | |
1497 | continue; | |
1498 | ||
1499 | IntEdgeInd.Remove(i); | |
1500 | IntEdgePar.Remove(i); | |
1501 | IntLinePar.Remove(i); | |
1502 | SegmentCodes.Remove(i); | |
1503 | i--; | |
7fd59977 | 1504 | } |
1505 | } | |
1506 | } | |
1507 | //pdn exit if all split points removed | |
1508 | if ( IntEdgePar.Length() <1 ) { | |
1509 | //DefinePatchForWire ( wire, firstCode, isCutByU, cutIndex ); | |
1510 | return Standard_False; //pdn ?? | |
1511 | } | |
1512 | ||
1513 | // Analyze type of intersection point and encode it | |
1514 | // Three kinds of points (ITP): clear intersection, tangency in-point, | |
1515 | // beginning and end of tangential segment. | |
1516 | // Orientation (IOR) tells on which side of line edge crosses it | |
1517 | j = IntEdgePar.Length(); | |
1518 | for ( i=1; i <= IntEdgePar.Length(); j = i++ ) { | |
1519 | Standard_Integer codej = SegmentCodes(j); | |
1520 | Standard_Integer codei = SegmentCodes(i); | |
1521 | if ( myClosedMode ) { | |
1522 | if ( ( codej & IOR_BOTH ) == IOR_BOTH ) //IOR_LEFT : IOR_RIGHT | |
1523 | codej = ( codej & IOR_POS ? IOR_RIGHT : IOR_LEFT ); | |
1524 | if ( ( codei & IOR_BOTH ) == IOR_BOTH ) //IOR_RIGHT : IOR_LEFT | |
1525 | codei = ( codei & IOR_POS ? IOR_LEFT : IOR_RIGHT ); | |
1526 | } | |
1527 | Standard_Integer ipcode = ( codej | codei ); | |
1528 | if ( codej == IOR_UNDEF ) { // previous segment was tangency | |
1529 | if ( IntLinePar(i) > IntLinePar (j) ) | |
1530 | ipcode |= ITP_ENDSEG; // end of segment | |
1531 | else ipcode |= ITP_BEGSEG; // beginning of segment | |
1532 | } | |
1533 | else if ( codei == IOR_UNDEF ) { // current segment is tangency | |
1534 | if ( IntLinePar ( i < IntLinePar.Length() ? i+1 : 1 ) > IntLinePar(i) ) | |
1535 | ipcode |= ITP_BEGSEG; // beginning of segment | |
1536 | else ipcode |= ITP_ENDSEG; // end of segment | |
1537 | } | |
1538 | //internal wire can be only tangent | |
1539 | else if ( i == j ) ipcode |= ( ( ipcode & IOR_BOTH ) == IOR_BOTH && !isnonmanifold ? ITP_INTER : ITP_TANG ); | |
1540 | else if ( codei == codej || isnonmanifold) ipcode |= ITP_TANG; // tangency in-point | |
1541 | else ipcode |= ITP_INTER; // standard crossing | |
1542 | IntCode.Append ( ipcode ); | |
1543 | } | |
1544 | } | |
1545 | ||
1546 | //======================================= | |
1547 | // Split edges in the wire by intersection points and fill vertices array | |
1548 | TopTools_SequenceOfShape IntVertices; | |
1549 | wire = SplitWire ( wire, IntEdgeInd, IntEdgePar, IntVertices, | |
1550 | SegmentCodes, isCutByU, cutIndex ); | |
1551 | ||
1552 | // add all data to input arrays | |
1553 | for ( i=1; i <= IntLinePar.Length(); i++ ) { | |
1554 | SplitLinePar.Append ( IntLinePar(i) ); | |
1555 | SplitLineCode.Append ( IntCode(i) ); | |
1556 | SplitLineVertex.Append ( IntVertices(i) ); | |
1557 | } | |
1558 | ||
1559 | return Standard_True; | |
1560 | } | |
1561 | ||
1562 | ||
1563 | //======================================================================= | |
1564 | //function : SplitByLine | |
1565 | //purpose : | |
1566 | //======================================================================= | |
1567 | ||
1568 | void ShapeFix_ComposeShell::SplitByLine (ShapeFix_SequenceOfWireSegment &wires, | |
1569 | const gp_Lin2d &line, | |
1570 | const Standard_Boolean isCutByU, | |
1571 | const Standard_Integer cutIndex) | |
1572 | { | |
1573 | TColStd_SequenceOfReal SplitLinePar; | |
1574 | TColStd_SequenceOfInteger SplitLineCode; | |
1575 | TopTools_SequenceOfShape SplitLineVertex; | |
1576 | ||
1577 | // split wires one by one, collecting data on intersection points | |
1578 | Standard_Integer i; // svv #1 | |
1579 | for ( i=1; i <= wires.Length(); i++ ) { | |
1580 | SplitByLine ( wires(i), line, isCutByU, cutIndex, | |
1581 | SplitLinePar, SplitLineCode, SplitLineVertex ); | |
1582 | } | |
1583 | ||
1584 | // sort intersection points along parameter on cutting line | |
1585 | for ( i = SplitLinePar.Length(); i >1; i-- ) | |
1586 | for ( Standard_Integer j=1; j < i; j++ ) { | |
1587 | if ( SplitLinePar(j) > SplitLinePar(j+1) ) { | |
1588 | SplitLinePar.Exchange ( j, j+1 ); | |
1589 | SplitLineCode.Exchange ( j, j+1 ); | |
1590 | SplitLineVertex.Exchange ( j, j+1 ); | |
1591 | } | |
1592 | } | |
1593 | ||
1594 | // merge null-length tangential segments into one-point tangencies or intersections | |
1595 | for ( i = 1; i < SplitLinePar.Length(); i++ ) { | |
1596 | if ( Abs ( SplitLinePar(i+1) - SplitLinePar(i) ) > ::Precision::PConfusion() ) continue; | |
1597 | if ( ( SplitLineCode(i) & ITP_ENDSEG && | |
1598 | SplitLineCode(i+1) & ITP_BEGSEG ) || | |
1599 | ( SplitLineCode(i) & ITP_BEGSEG && | |
1600 | SplitLineCode(i+1) & ITP_ENDSEG ) ) { | |
1601 | Standard_Integer code = ( SplitLineCode(i) | SplitLineCode(i+1) ) & IOR_BOTH; | |
1602 | SplitLineCode.SetValue ( i, code | ( code == IOR_BOTH ? ITP_INTER : ITP_TANG ) ); | |
1603 | SplitLinePar.Remove(i+1); | |
1604 | SplitLineCode.Remove(i+1); | |
1605 | SplitLineVertex.Remove(i+1); | |
1606 | } | |
1607 | } | |
1608 | ||
1609 | // go along line, split it by intersection points and create edges | |
1610 | // (only for internal parts, in particular not for tangential segments) | |
1611 | BRep_Builder B; | |
1612 | Standard_Integer parity = 0; // 0 - out, 1 - in | |
1613 | Standard_Integer halfparity = 0; // left/right for tangential segments | |
1614 | Standard_Integer tanglevel = 0; // tangency nesting level | |
1615 | for ( i = 1; i <= SplitLinePar.Length(); i++ ) { | |
1616 | Standard_Integer code = SplitLineCode(i); | |
1617 | Standard_Boolean interior = ( ! tanglevel && parity % 2 ); // create an edge | |
1618 | if ( code & ITP_INTER ) { // crossing | |
1619 | parity++; | |
1620 | } | |
1621 | else if ( code & ITP_BEGSEG ) { // beginning of tangential segment | |
1622 | tanglevel++; | |
1623 | if ( ! halfparity ) halfparity = ( code & IOR_BOTH ); | |
1624 | else if ( halfparity != ( code & IOR_BOTH ) ) parity++; | |
1625 | } | |
1626 | else if ( code & ITP_ENDSEG ) { // end of tangential segment | |
1627 | tanglevel--; | |
1628 | if ( ! halfparity ) halfparity = ( code & IOR_BOTH ); | |
1629 | else if ( halfparity != ( code & IOR_BOTH ) ) parity++; | |
1630 | } | |
1631 | if ( tanglevel <0 ) { | |
1632 | // myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL4 ); | |
0797d9d3 | 1633 | #ifdef OCCT_DEBUG |
7fd59977 | 1634 | cout << "Warning: ShapeFix_ComposeShell::SplitByLine: tangency level <0 !" << endl; |
1635 | #endif | |
1636 | } | |
1637 | if ( ! interior ) continue; | |
1638 | ||
1639 | // apply context to vertices (to perform replacing/merging vertices) | |
1640 | //smh#8 | |
1641 | TopoDS_Shape tmpV1 = Context()->Apply ( SplitLineVertex(i-1) ); | |
1642 | TopoDS_Shape tmpV2 = Context()->Apply ( SplitLineVertex(i) ); | |
1643 | TopoDS_Vertex V1 = TopoDS::Vertex ( tmpV1 ); | |
1644 | TopoDS_Vertex V2 = TopoDS::Vertex ( tmpV2 ); | |
1645 | // protection against creating null-length edges | |
1646 | if ( SplitLinePar(i) - SplitLinePar(i-1) < ::Precision::PConfusion() ) { | |
1647 | ||
0797d9d3 | 1648 | #ifdef OCCT_DEBUG |
7fd59977 | 1649 | cout << "Info: ShapeFix_ComposeShell::SplitByLine: Short segment ignored" << endl; |
1650 | #endif | |
1651 | if ( ! V1.IsSame ( V2 ) ) { // merge coincident vertices | |
1652 | ShapeBuild_Vertex sbv; | |
1653 | TopoDS_Vertex V = sbv.CombineVertex ( V1, V2 ); | |
1654 | Context()->Replace ( V1, V.Oriented ( V1.Orientation() ) ); | |
1655 | Context()->Replace ( V2, V.Oriented ( V2.Orientation() ) ); | |
1656 | V1 = V2 = V; | |
0797d9d3 | 1657 | #ifdef OCCT_DEBUG |
7fd59977 | 1658 | cout << "Info: ShapeFix_ComposeShell::SplitByLine: Coincided vertices merged" << endl; |
1659 | #endif | |
1660 | } | |
1661 | continue; | |
1662 | } | |
1663 | ||
1664 | // create an edge (without 3d curve), put it in wire segment and add to sequence | |
1665 | // NOTE: i here is always >1 | |
1666 | TopoDS_Edge edge; | |
1667 | B.MakeEdge ( edge ); | |
1668 | V1.Orientation ( TopAbs_FORWARD ); | |
1669 | V2.Orientation ( TopAbs_REVERSED ); | |
1670 | B.Add ( edge, V1 ); | |
1671 | B.Add ( edge, V2 ); | |
1672 | Handle(Geom2d_Line) Lin1 = new Geom2d_Line ( line ); | |
1673 | Handle(Geom2d_Line) Lin2 = new Geom2d_Line ( line ); | |
1674 | B.UpdateEdge ( edge, Lin1, Lin2, myFace, ::Precision::Confusion() ); | |
1675 | B.Range ( edge, myFace, SplitLinePar(i-1), SplitLinePar(i) ); | |
1676 | ||
1677 | Handle(ShapeExtend_WireData) sbwd = new ShapeExtend_WireData; | |
1678 | sbwd->Add ( edge ); | |
1679 | ShapeFix_WireSegment seg ( sbwd, TopAbs_EXTERNAL ); | |
1680 | ||
1681 | // set patch indices | |
1682 | DefinePatch ( seg, IOR_UNDEF, isCutByU, cutIndex ); | |
1683 | if ( ! isCutByU ) { | |
1684 | seg.DefineIUMin ( 1, GetPatchIndex ( SplitLinePar(i-1)+::Precision::PConfusion(), | |
1685 | myGrid->UJointValues(), myUClosed ) ); | |
1686 | seg.DefineIUMax ( 1, GetPatchIndex ( SplitLinePar(i)-::Precision::PConfusion(), | |
1687 | myGrid->UJointValues(), myUClosed ) + 1 ); | |
1688 | } | |
1689 | else { | |
1690 | seg.DefineIVMin ( 1, GetPatchIndex ( SplitLinePar(i-1)+::Precision::PConfusion(), | |
1691 | myGrid->VJointValues(), myVClosed ) ); | |
1692 | seg.DefineIVMax ( 1, GetPatchIndex ( SplitLinePar(i)-::Precision::PConfusion(), | |
1693 | myGrid->VJointValues(), myVClosed ) + 1 ); | |
1694 | } | |
1695 | ||
1696 | wires.Append ( seg ); | |
1697 | } | |
1698 | if ( parity % 2 ) { | |
1699 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL4 ); | |
0797d9d3 | 1700 | #ifdef OCCT_DEBUG |
7fd59977 | 1701 | cout << "Error: ShapeFix_ComposeShell::SplitByLine: parity error" << endl; |
1702 | #endif | |
1703 | } | |
1704 | ||
1705 | // Apply context to all wires to perform all recorded replacements/merging | |
1706 | for ( i=1; i <= wires.Length(); i++ ) { | |
1707 | for ( Standard_Integer j=1; j <= wires(i).NbEdges(); ) | |
1708 | j += ApplyContext ( wires(i), j, Context() ); | |
1709 | } | |
1710 | } | |
1711 | ||
1712 | ||
1713 | //======================================================================= | |
1714 | //function : SplitByGrid | |
1715 | //purpose : | |
1716 | //======================================================================= | |
1717 | ||
1718 | void ShapeFix_ComposeShell::SplitByGrid (ShapeFix_SequenceOfWireSegment &seqw) | |
1719 | { | |
1720 | // process splitting by U- anv V-seams (i.e. U=const and V=const curves) | |
1721 | // closed composite surface is processed as periodic | |
1722 | Standard_Real Uf,Ul,Vf,Vl; | |
1723 | BRepTools::UVBounds(myFace,Uf,Ul,Vf,Vl); | |
1724 | Standard_Real Umin,Umax,Vmin,Vmax; | |
1725 | myGrid->Bounds(Umin,Umax,Vmin,Vmax); | |
1726 | Standard_Real pprec = ::Precision::PConfusion(); | |
1727 | ||
1728 | // split by u lines | |
1729 | Standard_Integer i; // svv #1 | |
1730 | for ( i = ( myUClosed ? 1 : 2 ); i <= myGrid->NbUPatches(); i++ ) { | |
1731 | gp_Pnt2d pos ( myGrid->UJointValue(i), 0. ); // 0. - for infinite ranges: myGrid->VJointValue(1) ; | |
1732 | gp_Lin2d line ( pos, gp_Dir2d ( 0., 1. ) ); | |
1733 | if ( ! myClosedMode && myUClosed ) { | |
1734 | Standard_Real period = Umax - Umin; | |
1735 | Standard_Real X = pos.X(); | |
1736 | Standard_Real sh = ShapeAnalysis::AdjustToPeriod(X,Uf, Uf+period); | |
1737 | for( ; X+sh <= Ul+pprec; sh += period ) { | |
1738 | gp_Lin2d ln = line.Translated(gp_Vec2d(sh,0)); | |
1739 | Standard_Integer cutIndex = GetPatchIndex ( X+sh+pprec, myGrid->UJointValues(), myUClosed ); | |
1740 | SplitByLine ( seqw, ln, Standard_True, cutIndex ); | |
1741 | } | |
1742 | } | |
1743 | else | |
1744 | SplitByLine ( seqw, line, Standard_True, i ); | |
1745 | } | |
1746 | ||
1747 | // split by v lines | |
1748 | for ( i = ( myVClosed ? 1 : 2 ); i <= myGrid->NbVPatches(); i++ ) { | |
1749 | gp_Pnt2d pos ( 0., myGrid->VJointValue(i) ); | |
1750 | gp_Lin2d line ( pos, gp_Dir2d ( 1., 0. ) ); | |
1751 | if ( ! myClosedMode && myVClosed ) { | |
1752 | Standard_Real period = Vmax - Vmin; | |
1753 | Standard_Real Y = pos.Y(); | |
1754 | Standard_Real sh = ShapeAnalysis::AdjustToPeriod(Y,Vf, Vf+period); | |
1755 | for( ; Y+sh <= Vl+pprec; sh += period) { | |
1756 | gp_Lin2d ln = line.Translated(gp_Vec2d(0,sh)); | |
1757 | Standard_Integer cutIndex = GetPatchIndex ( Y+sh+pprec, myGrid->VJointValues(), myVClosed ); | |
1758 | SplitByLine ( seqw, ln, Standard_False, cutIndex ); | |
1759 | } | |
1760 | } | |
1761 | else | |
1762 | SplitByLine ( seqw, line, Standard_False, i ); | |
1763 | } | |
1764 | ||
1765 | // limit patch indices to be in range of grid (extended for periodic) | |
1766 | Standard_Integer iumin = GetPatchIndex ( Uf+pprec, myGrid->UJointValues(), myUClosed ); | |
1767 | Standard_Integer iumax = GetPatchIndex ( Ul-pprec, myGrid->UJointValues(), myUClosed ) + 1; | |
1768 | for ( i=1; i <= seqw.Length(); i++ ) { | |
1769 | ShapeFix_WireSegment &wire = seqw(i); | |
1770 | for ( Standard_Integer j=1; j <= wire.NbEdges(); j++ ) { | |
1771 | wire.DefineIUMin ( j, iumin ); | |
1772 | wire.DefineIUMax ( j, iumax ); | |
1773 | } | |
1774 | } | |
1775 | Standard_Integer ivmin = GetPatchIndex ( Vf+pprec, myGrid->VJointValues(), myVClosed ); | |
1776 | Standard_Integer ivmax = GetPatchIndex ( Vl-pprec, myGrid->VJointValues(), myVClosed ) + 1; | |
1777 | for ( i=1; i <= seqw.Length(); i++ ) { | |
1778 | ShapeFix_WireSegment &wire = seqw(i); | |
1779 | for ( Standard_Integer j=1; j <= wire.NbEdges(); j++ ) { | |
1780 | wire.DefineIVMin ( j, ivmin ); | |
1781 | wire.DefineIVMax ( j, ivmax ); | |
1782 | } | |
1783 | } | |
1784 | } | |
1785 | ||
1786 | ||
1787 | //======================================================================= | |
1788 | //function : BreakWires | |
1789 | //purpose : | |
1790 | //======================================================================= | |
1791 | ||
1792 | void ShapeFix_ComposeShell::BreakWires (ShapeFix_SequenceOfWireSegment &seqw) | |
1793 | { | |
1794 | ||
1795 | // split all the wires by vertices | |
1796 | TopTools_MapOfShape splitVertices; | |
1797 | ShapeAnalysis_Edge sae; | |
1798 | ||
1799 | // first collect splitting vertices | |
1800 | Standard_Integer i; // svv #1 | |
1801 | for ( i=1; i <= seqw.Length(); i++ ) { | |
1802 | TopAbs_Orientation ori_wire = seqw(i).Orientation(); | |
1803 | if ( ori_wire != TopAbs_EXTERNAL && | |
1804 | ori_wire != TopAbs_INTERNAL) continue; | |
1805 | ||
1806 | Handle(ShapeExtend_WireData) sbwd = seqw(i).WireData(); | |
1807 | for ( Standard_Integer j=1; j <= sbwd->NbEdges(); j++ ) { | |
1808 | TopoDS_Edge edge = sbwd->Edge ( j ); | |
1809 | TopAbs_Orientation ori_edge = (ori_wire == TopAbs_EXTERNAL ? ori_wire : edge.Orientation()); | |
1810 | if(ori_edge == TopAbs_EXTERNAL) { | |
1811 | splitVertices.Add ( sae.FirstVertex ( edge ) ); | |
1812 | splitVertices.Add ( sae.LastVertex ( edge ) ); | |
1813 | } | |
1814 | } | |
1815 | } | |
1816 | ||
1817 | // and then split each vire | |
1818 | // Here each wire is supposed to be connected (while probably not closed) | |
1819 | for ( i=1; i <= seqw.Length(); i++ ) { | |
1820 | TopAbs_Orientation ori = seqw(i).Orientation(); | |
1821 | ShapeFix_WireSegment wire = seqw(i); | |
1822 | if(wire.IsVertex()) | |
1823 | continue; | |
1824 | Handle(ShapeExtend_WireData) sbwd = wire.WireData(); | |
1825 | ||
1826 | // find first vertex for split | |
1827 | Standard_Integer j; // svv #1 | |
1828 | for ( j=1; j <= sbwd->NbEdges(); j++ ) { | |
1829 | TopoDS_Vertex V = sae.FirstVertex ( sbwd->Edge(j) ); | |
1830 | if ( splitVertices.Contains ( V ) ) break; | |
1831 | } | |
1832 | if ( j > sbwd->NbEdges() ) continue; // splitting not needed | |
1833 | ||
1834 | // if first split of closed edge is not its start, make permutation | |
1835 | Standard_Integer shift = 0; | |
1836 | if ( j >1 && ! myClosedMode && wire.IsClosed() ) { | |
1837 | TopoDS_Vertex V = sae.FirstVertex ( sbwd->Edge(1) ); | |
1838 | if ( ! splitVertices.Contains ( V ) ) | |
1839 | shift = j - 1; | |
1840 | // wire.SetLast ( j-1 ); | |
1841 | } | |
1842 | ||
1843 | // perform splitting | |
1844 | Standard_Integer nbnew = 0; | |
1845 | ShapeFix_WireSegment newwire; | |
1846 | TopAbs_Orientation curOri = ori; | |
1847 | for ( Standard_Integer ind=1; ind <= sbwd->NbEdges(); ind++ ) { | |
1848 | j = 1 + ( ind - 1 + shift ) % sbwd->NbEdges(); | |
1849 | TopoDS_Edge edge = sbwd->Edge(j); | |
1850 | TopoDS_Vertex V = sae.FirstVertex ( edge ); | |
1851 | if ( ind==1 || splitVertices.Contains ( V ) ) { | |
1852 | if ( newwire.NbEdges() ) { | |
1853 | newwire.Orientation ( curOri ); | |
1854 | // ShapeFix_WireSegment seg ( newwire, ori ); | |
1855 | seqw.InsertBefore ( i++, newwire ); | |
1856 | nbnew++; | |
1857 | } | |
1858 | newwire.Clear(); | |
1859 | curOri = ori; | |
1860 | } | |
1861 | Standard_Integer iumin, iumax, ivmin, ivmax; | |
1862 | wire.GetPatchIndex ( j, iumin, iumax, ivmin, ivmax ); | |
1863 | if(ori == TopAbs_INTERNAL && edge.Orientation() == TopAbs_EXTERNAL ) { | |
1864 | curOri = TopAbs_EXTERNAL; | |
1865 | edge.Orientation(TopAbs_FORWARD); | |
1866 | nbnew++; | |
1867 | } | |
1868 | ||
1869 | newwire.AddEdge ( 0, edge, iumin, iumax, ivmin, ivmax ); | |
1870 | } | |
1871 | if ( nbnew ) { | |
1872 | newwire.Orientation ( curOri ); | |
1873 | // ShapeFix_WireSegment seg ( newwire, ori ); | |
1874 | seqw.SetValue ( i, newwire ); | |
1875 | } | |
1876 | } | |
1877 | } | |
1878 | ||
1879 | ||
1880 | //======================================================================= | |
1881 | //function : IsShortSegment | |
1882 | //purpose : auxilary | |
1883 | //======================================================================= | |
1884 | // BUC60035 2053: check if wire segment is very short (in order not to skip it) | |
1885 | // 0 - long | |
1886 | // 1 - short even in 2d (to be taken always) | |
1887 | // -1 - short in 3d but not in 2d (to be checked after algo and atteching to | |
1888 | // another wire if alone) | |
1889 | static Standard_Integer IsShortSegment (const ShapeFix_WireSegment &seg, | |
1890 | const TopoDS_Face myFace, | |
1891 | const Handle(Geom_Surface)& myGrid, | |
1892 | const TopLoc_Location &myLoc, | |
1893 | const Standard_Real UResolution, | |
1894 | const Standard_Real VResolution) | |
1895 | { | |
1896 | TopoDS_Vertex Vf = seg.FirstVertex(); | |
1897 | if ( ! Vf.IsSame ( seg.LastVertex() ) ) return Standard_False; | |
1898 | ||
1899 | gp_Pnt pnt = BRep_Tool::Pnt(Vf); | |
1900 | Standard_Real tol = BRep_Tool::Tolerance(Vf); | |
1901 | Standard_Real tol2 = tol*tol; | |
1902 | ||
1903 | Standard_Integer code = 1; | |
1904 | ShapeAnalysis_Edge sae; | |
1905 | Handle(ShapeExtend_WireData) sbwd = seg.WireData(); | |
1906 | for ( Standard_Integer i=1; i <= sbwd->NbEdges(); i++ ) { | |
1907 | TopoDS_Edge edge = sbwd->Edge ( i ); | |
1908 | if ( ! Vf.IsSame ( sae.LastVertex ( edge ) ) ) return Standard_False; | |
1909 | Handle(Geom2d_Curve) c2d; | |
1910 | Standard_Real f, l; | |
1911 | if ( ! sae.PCurve ( edge, myFace, c2d, f, l ) ) continue; | |
1912 | ||
1913 | // check 2d | |
1914 | gp_Pnt2d endPnt = c2d->Value(l); | |
1915 | gp_Pnt2d midPnt = c2d->Value((f+l)/2); | |
1916 | if ( ! IsCoincided ( endPnt, midPnt, UResolution, VResolution, tol ) ) code = -1; | |
1917 | ||
1918 | // check 3d | |
1919 | gp_Pnt midPnt3d = myGrid->Value(midPnt.X(),midPnt.Y()); | |
1920 | if ( ! myLoc.IsIdentity() ) midPnt3d.Transform ( myLoc.Transformation() ); | |
1921 | if ( midPnt3d.SquareDistance(pnt) > tol2) return 0; | |
1922 | } | |
1923 | return code; | |
1924 | } | |
1925 | ||
1926 | ||
1927 | //======================================================================= | |
1928 | //function : IsSamePatch | |
1929 | //purpose : auxilary | |
1930 | //======================================================================= | |
1931 | static Standard_Boolean IsSamePatch (const ShapeFix_WireSegment wire, | |
1932 | const Standard_Integer NU, | |
1933 | const Standard_Integer NV, | |
1934 | Standard_Integer &iumin, | |
1935 | Standard_Integer &iumax, | |
1936 | Standard_Integer &ivmin, | |
1937 | Standard_Integer &ivmax, | |
1938 | const Standard_Boolean extend=Standard_False) | |
1939 | { | |
1940 | // get patch indices for current segment | |
1941 | Standard_Integer jumin, jumax, jvmin, jvmax; | |
1942 | wire.GetPatchIndex ( 1, jumin, jumax, jvmin, jvmax ); | |
1943 | ||
1944 | // shift to the same period | |
1945 | Standard_Integer du=0, dv=0; | |
1946 | if ( jumin - iumin > NU ) du =-( jumin - iumin ) / NU; | |
1947 | else if ( iumin - jumin > NU ) du = ( iumin - jumin ) / NU; | |
1948 | if ( jvmin - ivmin > NV ) dv =-( jvmin - ivmin ) / NV; | |
1949 | else if ( ivmin - jvmin > NV ) dv = ( ivmin - jvmin ) / NV; | |
1950 | if ( du ) { jumin += du * NU; jumax += du * NU; } | |
1951 | if ( dv ) { jvmin += dv * NV; jvmax += dv * NV; } | |
1952 | ||
1953 | // compute common (extended) indices | |
1954 | Standard_Integer iun = Min ( iumin, jumin ); | |
1955 | Standard_Integer iux = Max ( iumax, jumax ); | |
1956 | Standard_Integer ivn = Min ( ivmin, jvmin ); | |
1957 | Standard_Integer ivx = Max ( ivmax, jvmax ); | |
1958 | Standard_Boolean ok = ( iun == iux || iun+1 == iux ) && | |
1959 | ( ivn == ivx || ivn+1 == ivx ); | |
1960 | if ( ok && extend ) { iumin = iun; iumax = iux; ivmin = ivn; ivmax = ivx; } | |
1961 | return ok; | |
1962 | } | |
1963 | ||
1964 | ||
1965 | //======================================================================= | |
1966 | //function : CollectWires | |
1967 | //purpose : | |
1968 | //======================================================================= | |
1969 | ||
1970 | void ShapeFix_ComposeShell::CollectWires (ShapeFix_SequenceOfWireSegment &wires, | |
1971 | ShapeFix_SequenceOfWireSegment &seqw) | |
1972 | { | |
1973 | ||
1974 | ShapeAnalysis_Edge sae; | |
1975 | Standard_Integer i; // svv #1 | |
1976 | // Collect information on short closed segments | |
1977 | TColStd_Array1OfInteger shorts(1,seqw.Length()); | |
1978 | for ( i=1; i <= seqw.Length(); i++ ) { | |
1979 | if(seqw(i).IsVertex() || seqw(i).Orientation() == TopAbs_INTERNAL) { | |
1980 | wires.Append(seqw(i)); | |
1981 | seqw.Remove(i); | |
1982 | i--; | |
1983 | continue; | |
1984 | } | |
0797d9d3 | 1985 | #ifdef OCCT_DEBUG |
7fd59977 | 1986 | for ( Standard_Integer k=1; ! myClosedMode && k <= seqw(i).NbEdges(); k++ ) |
63c629aa | 1987 | if ( ! seqw(i).CheckPatchIndex ( k ) ) { |
1988 | cout << "Warning: ShapeFix_ComposeShell::CollectWires: Wrong patch indices" << endl; | |
1989 | break; | |
1990 | } | |
7fd59977 | 1991 | #endif |
1992 | Standard_Integer isshort = IsShortSegment ( seqw(i), myFace, myGrid, myLoc, | |
1993 | myUResolution, myVResolution ); | |
1994 | shorts.SetValue ( i, isshort ); | |
1995 | if ( isshort >0 && | |
1996 | ( seqw(i).Orientation() == TopAbs_EXTERNAL || | |
1997 | ( seqw(i).NbEdges() == 1 && //:abv 13.05.02: OCC320 - remove if degenerated | |
1998 | BRep_Tool::Degenerated ( seqw(i).Edge(1) ) ) ) ) { | |
0797d9d3 | 1999 | #ifdef OCCT_DEBUG |
7fd59977 | 2000 | cout << "Info: ShapeFix_ComposeShell::CollectWires: Short segment ignored" << endl; |
2001 | #endif | |
2002 | seqw(i).Orientation ( TopAbs_INTERNAL ); | |
2003 | } | |
2004 | } | |
2005 | ||
2006 | Handle(ShapeExtend_WireData) sbwd; | |
2007 | gp_Pnt2d endPnt, firstPnt; | |
2008 | gp_Vec2d endTan, firstTan; | |
2009 | TopoDS_Vertex firstV, endV; | |
2010 | TopoDS_Edge firstEdge, lastEdge; | |
2011 | Standard_Real tol = 0; | |
1d47d8d0 | 2012 | Standard_Integer iumin = 0, iumax = 0, ivmin = 0, ivmax = 0; |
7fd59977 | 2013 | Standard_Real dsu=0., dsv=0.; |
2014 | Standard_Boolean canBeClosed = Standard_False; | |
302f96fb | 2015 | for(;;) { |
7fd59977 | 2016 | Standard_Integer index = 0; |
2017 | Standard_Boolean misoriented = Standard_True, samepatch = Standard_False; | |
2018 | Standard_Boolean reverse = Standard_False, connected = Standard_False; | |
c6541a0c | 2019 | Standard_Real angle = -M_PI, mindist = RealLast(); |
7fd59977 | 2020 | Standard_Integer weigth = 0; |
2021 | Standard_Real shiftu=0., shiftv=0.; | |
2022 | ||
2023 | // find next segment to connect (or first if sbwd is NULL) | |
2024 | for ( i = 1; i <= seqw.Length(); i++ ) { | |
2025 | ShapeFix_WireSegment seg = seqw.Value(i); | |
2026 | if(seg.IsVertex()) | |
2027 | continue; | |
2028 | TopAbs_Orientation anOr = seg.Orientation(); | |
2029 | if ( anOr == TopAbs_INTERNAL ) continue; | |
2030 | ||
2031 | // for first segment, take any | |
2032 | if ( sbwd.IsNull() ) { | |
2033 | if ( shorts(i) >0 ) continue; | |
2034 | if ( anOr == TopAbs_EXTERNAL ) continue; | |
2035 | if ( anOr == TopAbs_FORWARD ) reverse = Standard_True; | |
2036 | index = i; | |
2037 | seg.GetPatchIndex ( 1, iumin, iumax, ivmin, ivmax ); | |
2038 | misoriented = Standard_False; | |
2039 | dsu = dsv = 0.; | |
2040 | break; | |
2041 | } | |
2042 | ||
2043 | // check whether current segment is on the same patch with previous | |
2044 | Standard_Integer sp = ( myClosedMode || // no indexation in closed mode | |
2045 | IsSamePatch ( seg, myGrid->NbUPatches(), myGrid->NbVPatches(), | |
2046 | iumin, iumax, ivmin, ivmax ) ); | |
2047 | ||
2048 | // not same patch has lowest priority | |
2049 | if ( ! sp && ( canBeClosed || ( index && samepatch ) ) ) continue; | |
2050 | ||
2051 | // try to connect, with the following priorities: | |
2052 | // The name of property Weigth: | |
2053 | // sharing vertex auto | |
2054 | // samepatch = 1 16 | |
2055 | // ! sameedge auto | |
2056 | // misorientation = 0 8 | |
2057 | // connected in 2d 4 | |
2058 | // distance 2 | |
2059 | // short auto | |
2060 | // angle ->> PI 1 | |
2061 | Handle(ShapeExtend_WireData) wire = seg.WireData(); | |
2062 | for ( Standard_Integer j=0; j <2; j++ ) { | |
2063 | if ( ! endV.IsSame ( j ? seg.LastVertex() : seg.FirstVertex() ) ) continue; | |
2064 | ||
2065 | // check for misorientation only if nothing better is found | |
2066 | Standard_Integer misor = ( anOr == ( j ? TopAbs_REVERSED : TopAbs_FORWARD ) ); | |
2067 | // if ( misor ) continue; // temporarily, to be improved | |
2068 | ||
2069 | // returning back by the same edge is lowest priority | |
2070 | if ( lastEdge.IsSame ( wire->Edge ( j ? wire->NbEdges() : 1 ) ) ) { | |
2071 | if ( ! index && ! canBeClosed ) { // || ( sp && ! samepatch ) ) { | |
2072 | index = i; | |
2073 | reverse = j; | |
2074 | connected = Standard_True; | |
2075 | misoriented = misor; | |
2076 | samepatch = sp; | |
2077 | weigth = ( sp ? 16 : 0 ) + ( connected ? 8 : 0 ) + (misor==0 ? 4 : 0); | |
2078 | dsu = dsv = 0.; | |
2079 | } | |
2080 | continue; | |
2081 | } | |
2082 | ||
2083 | // compute starting tangent | |
2084 | gp_Pnt2d lPnt; | |
2085 | gp_Vec2d lVec; | |
2086 | Standard_Integer k; | |
2087 | Standard_Real edgeTol = 0; | |
2088 | for ( k=1; k <= wire->NbEdges(); k++ ) { | |
2089 | TopoDS_Shape tmpE = wire->Edge(wire->NbEdges()-k+1).Reversed(); | |
2090 | TopoDS_Edge edge = ( j ? TopoDS::Edge ( tmpE ) : | |
2091 | wire->Edge(k) ); | |
2092 | edgeTol = BRep_Tool::Tolerance ( edge ); | |
2093 | //if ( sae.GetEndTangent2d ( edge, myFace, Standard_False, lPnt, lVec ) ) break; | |
2094 | if ( sae.GetEndTangent2d ( edge, myFace, Standard_False, lPnt, lVec, 1.e-3 ) ) break; | |
2095 | } | |
2096 | if ( k > wire->NbEdges() ) myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
2097 | ||
2098 | if ( myClosedMode ) { | |
2099 | if ( myUClosed ) { | |
2100 | shiftu = ShapeAnalysis::AdjustByPeriod ( lPnt.X(), endPnt.X(), myUPeriod ); | |
2101 | lPnt.SetX ( lPnt.X() + shiftu ); | |
2102 | } | |
2103 | if ( myVClosed ) { | |
2104 | shiftv = ShapeAnalysis::AdjustByPeriod ( lPnt.Y(), endPnt.Y(), myVPeriod ); | |
2105 | lPnt.SetY ( lPnt.Y() + shiftv ); | |
2106 | } | |
2107 | } | |
2108 | ||
2109 | // short segment is to be taken with highest priority by angle | |
c6541a0c D |
2110 | Standard_Real ang = ( shorts(i) >0 ? M_PI : endTan.Angle ( lVec ) ); |
2111 | if ( myClosedMode && shorts(i) <=0 && M_PI-ang < ::Precision::Angular() ) | |
7fd59977 | 2112 | ang = 0.; // abv 21 Mar 00: trj3_s1-md-214.stp #2471: avoid going back |
2113 | // abv 05 Feb 02: face from Parasolid: use tolerance of edges for check | |
2114 | // for coincidence (instead of vertex tolerance) in order | |
2115 | // this check to be in agreement with check for position of wire segments | |
2116 | // thus avoiding bad effects on overlapping edges | |
2117 | Standard_Real ctol = Max ( edgeTol, BRep_Tool::Tolerance(lastEdge) ); | |
2118 | Standard_Boolean conn = IsCoincided ( endPnt, lPnt, myUResolution, | |
2119 | myVResolution, ctol ); | |
2120 | Standard_Real dist = endPnt.SquareDistance ( lPnt ); | |
2121 | ||
2122 | // check if case is better than last found | |
2123 | ||
2124 | Standard_Integer w1 = ( sp ? 16 : 0 ) + ( conn ? 4 : 0 ) + (misor==0 ? 8 : 0); | |
2125 | Standard_Integer tail1 = ( !conn && (dist < mindist) ? 2 : 0) + (ang > angle ? 1 : 0); | |
2126 | Standard_Integer tail2 = ( !connected &&(dist > mindist) ? 2 : 0) + (ang < angle ? 1 : 0); | |
2127 | if(w1+tail1 <= weigth+tail2) | |
2128 | continue; | |
2129 | ||
2130 | index = i; | |
2131 | reverse = j; | |
2132 | angle = ang; | |
2133 | mindist = dist; | |
2134 | connected = conn; | |
2135 | misoriented = misor; | |
2136 | samepatch = sp; | |
2137 | weigth = w1; | |
2138 | dsu = shiftu; | |
2139 | dsv = shiftv; | |
2140 | } | |
2141 | } | |
2142 | ||
2143 | // if next segment found, connect it | |
2144 | if ( index ) { | |
2145 | if(misoriented) | |
2146 | myInvertEdgeStatus = Standard_True; | |
2147 | ShapeFix_WireSegment seg = seqw.Value(index); | |
2148 | if ( sbwd.IsNull() ) sbwd = new ShapeExtend_WireData; | |
2149 | else if ( samepatch ) { // extend patch indices | |
2150 | IsSamePatch ( seg, myGrid->NbUPatches(), myGrid->NbVPatches(), | |
2151 | iumin, iumax, ivmin, ivmax, Standard_True ); | |
2152 | } | |
2153 | // TopAbs_Orientation or = seg.Orientation(); | |
2154 | if ( ! reverse ) sbwd->Add ( seg.WireData() ); | |
2155 | else { | |
2156 | Handle(ShapeExtend_WireData) wire = new ShapeExtend_WireData; | |
2157 | wire->ManifoldMode() = Standard_False; | |
2158 | wire->Add ( seg.WireData() ); | |
2159 | wire->Reverse ( myFace ); | |
2160 | sbwd->Add ( wire ); | |
2161 | } | |
2162 | if ( seg.Orientation() == TopAbs_EXTERNAL ) | |
2163 | seg.Orientation ( reverse ? TopAbs_REVERSED : TopAbs_FORWARD ); | |
2164 | else seg.Orientation ( TopAbs_INTERNAL ); | |
2165 | seqw.SetValue ( index, seg ); | |
2166 | } | |
2167 | else if ( sbwd.IsNull() ) break; // stop when no free segments available | |
2168 | // for first segment, remember start point | |
2169 | if ( endV.IsNull() ) { | |
2170 | firstEdge = sbwd->Edge(1); | |
2171 | firstV = sae.FirstVertex ( firstEdge ); | |
2172 | //sae.GetEndTangent2d ( firstEdge, myFace, Standard_False, firstPnt, firstTan ); | |
2173 | sae.GetEndTangent2d ( firstEdge, myFace, Standard_False, firstPnt, firstTan, 1.e-3 ); | |
2174 | } | |
2175 | ||
2176 | // update last edge and vertex (only for not short segments) | |
2177 | Standard_Boolean doupdate = ( index && ( shorts(index) <=0 || endV.IsNull() ) ); | |
2178 | if ( doupdate ) { | |
2179 | lastEdge = sbwd->Edge ( sbwd->NbEdges() ); | |
2180 | endV = sae.LastVertex ( lastEdge ); | |
2181 | tol = BRep_Tool::Tolerance ( endV ); | |
2182 | // BUC60035 2053: iteration on edges is required | |
2183 | Standard_Integer k; // svv #1 | |
2184 | for ( k=sbwd->NbEdges(); k >=1; k-- ) | |
2185 | //if ( sae.GetEndTangent2d ( sbwd->Edge ( k ), myFace, Standard_True, endPnt, endTan ) ) | |
2186 | if ( sae.GetEndTangent2d ( sbwd->Edge ( k ), myFace, Standard_True, endPnt, endTan, 1.e-3 ) ) | |
2187 | break; | |
2188 | if ( k <1 ) myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); | |
2189 | if ( myUClosed ) endPnt.SetX ( endPnt.X() + dsu ); | |
2190 | if ( myVClosed ) endPnt.SetY ( endPnt.Y() + dsv ); | |
2191 | } | |
2192 | ||
2193 | // if closed or no next segment found, add to wires | |
2194 | canBeClosed = endV.IsSame ( firstV ); | |
2195 | if ( ! index || ( canBeClosed && | |
2196 | ! lastEdge.IsSame ( firstEdge ) && // cylinder (seam) | |
2197 | IsCoincided ( endPnt, firstPnt, myUResolution, myVResolution, 2.* tol ) ) ) { | |
2198 | if ( ! endV.IsSame ( sae.FirstVertex ( firstEdge ) ) ) { | |
2199 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL5 ); | |
0797d9d3 | 2200 | #ifdef OCCT_DEBUG |
7fd59977 | 2201 | cout << "Warning: ShapeFix_ComposeShell::CollectWires: can't close wire" << endl; |
2202 | #endif | |
2203 | } | |
2204 | ShapeFix_WireSegment s ( sbwd, TopAbs_FORWARD ); | |
2205 | s.DefineIUMin(1,iumin); | |
2206 | s.DefineIUMax(1,iumax); | |
2207 | s.DefineIVMin(1,ivmin); | |
2208 | s.DefineIVMax(1,ivmax); | |
2209 | wires.Append ( s ); | |
2210 | sbwd.Nullify(); | |
2211 | endV.Nullify(); | |
2212 | canBeClosed = Standard_False; | |
2213 | } | |
2214 | } | |
2215 | ||
2216 | // Check if some wires are short in 3d (lie entirely inside one vertex), | |
2217 | // and if yes try to merge them with others | |
2218 | //pdn The short seqments are stil plased in "in" sequence. | |
2219 | ||
2220 | for ( i=1; i <= seqw.Length(); i++ ) { | |
2221 | if ( shorts(i) != 1 || seqw(i).IsVertex() || seqw(i).Orientation() == TopAbs_INTERNAL || | |
2222 | seqw(i).Orientation() == TopAbs_EXTERNAL ) continue; | |
2223 | ||
2224 | // find any other wire containing the same vertex | |
2225 | Handle(ShapeExtend_WireData) wd = seqw(i).WireData(); | |
2226 | TopoDS_Vertex V = seqw(i).FirstVertex(); | |
2227 | Standard_Integer minj=0, mink=0; | |
2228 | gp_Pnt2d p2d; | |
2229 | gp_Vec2d vec; | |
2230 | Standard_Real mindist=0; | |
2231 | Standard_Boolean samepatch = Standard_False; | |
2232 | // Standard_Integer iumin, iumax, ivmin, ivmax; | |
2233 | seqw(i).GetPatchIndex ( 1, iumin, iumax, ivmin, ivmax ); | |
2234 | sae.GetEndTangent2d ( wd->Edge(1), myFace, Standard_False, p2d, vec ); | |
2235 | for ( Standard_Integer j=1; j <= wires.Length(); j++ ) { | |
2236 | // if ( j == i ) continue; | |
2237 | // Handle(ShapeExtend_WireData) | |
2238 | sbwd = wires(j).WireData(); | |
2239 | for ( Standard_Integer k=1; k <= sbwd->NbEdges(); k++ ) { | |
2240 | if ( !V.IsSame ( sae.FirstVertex ( sbwd->Edge(k) ) ) ) continue; //pdn I suppose that short segment should be inserted into the SAME vertex. | |
2241 | ||
2242 | Standard_Integer sp = IsSamePatch ( wires(j), myGrid->NbUPatches(), myGrid->NbVPatches(), | |
2243 | iumin, iumax, ivmin, ivmax ); | |
2244 | if ( samepatch && !sp) continue; | |
2245 | gp_Pnt2d pp; | |
2246 | sae.GetEndTangent2d ( sbwd->Edge(k), myFace, Standard_False, pp, vec ); | |
2247 | Standard_Real dist = pp.SquareDistance ( p2d ); | |
2248 | if ( sp && ! samepatch ) { minj = j; mink = k; mindist = dist;samepatch=sp;} | |
2249 | else | |
2250 | if ( ! minj || mindist > dist ) { minj = j; mink = k; mindist = dist;samepatch=sp; } | |
2251 | } | |
2252 | } | |
2253 | if ( ! minj ) { | |
2254 | //pdn add into resulting sequence! | |
2255 | ShapeFix_WireSegment s ( wd, TopAbs_FORWARD ); | |
2256 | wires.Append ( s ); | |
0797d9d3 | 2257 | #ifdef OCCT_DEBUG |
7fd59977 | 2258 | cout <<"Warning: Short segment processed as separate wire"<<endl; |
2259 | #endif | |
2260 | continue; | |
2261 | } | |
2262 | ||
2263 | // and if found, merge | |
2264 | // Handle(ShapeExtend_WireData) | |
2265 | sbwd = wires(minj).WireData(); | |
2266 | for ( Standard_Integer n=1; n <= wd->NbEdges(); n++ ) | |
2267 | sbwd->Add ( wd->Edge(n), mink++ ); | |
2268 | ||
2269 | // wires.Remove ( i ); | |
2270 | // i--; | |
2271 | } | |
2272 | ||
2273 | } | |
2274 | ||
2275 | //======================================================================= | |
2276 | //function : DispatchWires | |
2277 | //purpose : | |
2278 | //======================================================================= | |
2279 | ||
2280 | static gp_Pnt2d GetMiddlePoint (const ShapeFix_WireSegment wire, | |
2281 | const TopoDS_Face face) | |
2282 | { | |
2283 | if(wire.IsVertex()) { | |
2284 | TopoDS_Vertex aV = wire.GetVertex(); | |
2285 | gp_Pnt aP3D = BRep_Tool::Pnt(aV ); | |
2286 | Handle(Geom_Surface) surf = BRep_Tool::Surface(face); | |
2287 | Handle(ShapeAnalysis_Surface) aSurfTool = new ShapeAnalysis_Surface(surf); | |
2288 | return aSurfTool->ValueOfUV(aP3D,Precision::Confusion()); | |
2289 | } | |
2290 | Bnd_Box2d box; | |
2291 | ShapeAnalysis_Edge sae; | |
2292 | ShapeAnalysis_Curve sac; | |
2293 | Handle(ShapeExtend_WireData) wd = wire.WireData(); | |
2294 | for(Standard_Integer i = 1; i <= wd->NbEdges(); i++) { | |
2295 | TopoDS_Edge E = wd->Edge (i); | |
2296 | Standard_Real cf,cl; | |
2297 | Handle(Geom2d_Curve) c2d; | |
2298 | if(sae.PCurve (E,face,c2d,cf,cl,Standard_False)) { | |
2299 | sac.FillBndBox ( c2d, cf, cl, 3, Standard_False, box ); | |
2300 | // box.Add(c2d->Value(cf)); | |
2301 | // box.Add(c2d->Value(cl)); | |
2302 | // box.Add(c2d->Value((cl+cf)/2.)); | |
2303 | } | |
2304 | } | |
2305 | if ( box.IsVoid() ) return gp_Pnt2d(0.,0.); | |
2306 | Standard_Real aXmin, aYmin, aXmax, aYmax; | |
2307 | box.Get(aXmin, aYmin, aXmax, aYmax); | |
2308 | return gp_Pnt2d ( 0.5 * ( aXmax + aXmin ), 0.5 * ( aYmax + aYmin ) ); | |
2309 | } | |
2310 | ||
2311 | //======================================================================= | |
2312 | //function : MakeFacesOnPatch | |
2313 | //purpose : | |
2314 | //======================================================================= | |
2315 | ||
2316 | void ShapeFix_ComposeShell::MakeFacesOnPatch (TopTools_SequenceOfShape &faces, | |
2317 | const Handle(Geom_Surface)& surf, | |
2318 | TopTools_SequenceOfShape &loops) const | |
2319 | { | |
2320 | BRep_Builder B; | |
2321 | ||
2322 | // Case of single loop: just add it to face | |
2323 | if ( loops.Length() == 1 ) { | |
2324 | TopoDS_Face newFace; | |
2325 | B.MakeFace ( newFace, surf, myLoc, ::Precision::Confusion() ); | |
2326 | TopoDS_Shape aSH = loops.Value(1); | |
2327 | if( aSH.ShapeType() != TopAbs_WIRE) | |
2328 | return; | |
2329 | TopoDS_Wire wire = TopoDS::Wire ( loops.Value(1) ); | |
2330 | ||
2331 | B.Add ( newFace, wire ); | |
2332 | if(myInvertEdgeStatus) { | |
2333 | Handle(ShapeFix_Face) sff = new ShapeFix_Face(newFace); | |
2334 | sff->FixAddNaturalBoundMode() = Standard_False; | |
2335 | TopTools_DataMapOfShapeListOfShape MapWires; | |
2336 | MapWires.Clear(); | |
2337 | sff->FixOrientation(MapWires); | |
2338 | newFace = sff->Face(); | |
2339 | } | |
2340 | ||
2341 | faces.Append ( newFace ); | |
2342 | return; | |
2343 | } | |
2344 | ||
2345 | // For several loops, first find roots | |
2346 | // make pseudo-face, | |
2347 | TopoDS_Face pf; | |
2348 | B.MakeFace ( pf, surf, myLoc, ::Precision::Confusion() ); | |
2349 | Handle(Geom_Surface) atSurf = BRep_Tool::Surface(pf); | |
2350 | ||
2351 | Handle(ShapeAnalysis_Surface) aSurfTool = new ShapeAnalysis_Surface(atSurf); | |
2352 | TopTools_SequenceOfShape roots; | |
2353 | Standard_Integer i; // svv #1 | |
2354 | for ( i = 1; i <= loops.Length(); i++ ) { | |
2355 | gp_Pnt2d unp; | |
2356 | TopoDS_Wire wr; | |
2357 | TopoDS_Shape aShape = loops(i); | |
2358 | if(aShape.ShapeType() != TopAbs_WIRE || | |
2359 | (aShape.Orientation() != TopAbs_FORWARD && aShape.Orientation() != TopAbs_REVERSED)) | |
2360 | continue; | |
2361 | ||
2362 | wr = TopoDS::Wire ( loops(i) ); | |
2363 | TopoDS_Iterator ew (wr); | |
2364 | if ( ! ew.More() ) continue; | |
2365 | ||
2366 | TopoDS_Edge ed = TopoDS::Edge ( ew.Value() ); | |
2367 | while(ed.Orientation() != TopAbs_FORWARD && | |
2368 | ed.Orientation() != TopAbs_REVERSED ) { | |
2369 | ew.Next(); | |
2370 | if(ew.More()) | |
2371 | ed = TopoDS::Edge ( ew.Value() ); | |
2372 | else | |
2373 | break; | |
2374 | } | |
2375 | if ( ! ew.More() ) continue; | |
2376 | Standard_Real cf, cl; | |
2377 | Handle(Geom2d_Curve) cw = BRep_Tool::CurveOnSurface ( ed, pf, cf, cl ); | |
2378 | if ( cw.IsNull() ) continue; | |
2379 | unp = cw->Value ( 0.5 * ( cf + cl ) ); | |
2380 | ||
2381 | Standard_Integer j; // svv #1 | |
2382 | for ( j = 1; j <= loops.Length(); j++ ) { | |
2383 | if ( i == j ) continue; | |
2384 | TopoDS_Shape aShape2 = loops(j); | |
2385 | if(aShape2.ShapeType() != TopAbs_WIRE || | |
2386 | (aShape2.Orientation() != TopAbs_FORWARD && | |
2387 | aShape2.Orientation() != TopAbs_REVERSED)) | |
2388 | continue; | |
2389 | TopoDS_Wire w1 = TopoDS::Wire (aShape2); | |
2390 | TopoDS_Wire awtmp; | |
2391 | B.MakeWire(awtmp); | |
2392 | awtmp.Orientation(TopAbs_FORWARD); | |
2393 | TopoDS_Iterator aIt(w1); | |
2394 | Standard_Integer nbe =0; | |
2395 | for( ; aIt.More() ; aIt.Next()) { | |
2396 | if(aIt.Value().Orientation() == TopAbs_FORWARD || | |
2397 | aIt.Value().Orientation() == TopAbs_REVERSED) { | |
2398 | B.Add(awtmp,aIt.Value()); | |
2399 | nbe++; | |
2400 | } | |
2401 | ||
2402 | } | |
2403 | if(!nbe) | |
2404 | continue; | |
2405 | TopoDS_Face fc; | |
2406 | B.MakeFace ( fc, surf, myLoc, ::Precision::Confusion() ); | |
2407 | B.Add ( fc, awtmp ); | |
2408 | BRepTopAdaptor_FClass2d clas ( fc, ::Precision::PConfusion() ); | |
2409 | TopAbs_State stPoint = clas.Perform (unp,Standard_False); | |
2410 | if(stPoint == TopAbs_ON || stPoint == TopAbs_UNKNOWN) { | |
2411 | ||
51740958 | 2412 | TopoDS_Edge anEdge = TopoDS::Edge ( ew.Value() ); |
2413 | Standard_Real aCF, aCL; | |
2414 | Handle(Geom2d_Curve) aCW = BRep_Tool::CurveOnSurface ( anEdge, pf, aCF, aCL); | |
7fd59977 | 2415 | // handle tangential case (ON) |
2416 | while ( stPoint == TopAbs_ON || stPoint == TopAbs_UNKNOWN ) { | |
51740958 | 2417 | stPoint = clas.Perform (aCW->Value(aCL), Standard_False ); |
7fd59977 | 2418 | if ( ! ew.More() ) break; |
2419 | ew.Next(); | |
2420 | if ( ! ew.More() ) break; | |
2421 | TopoDS_Edge edge = TopoDS::Edge ( ew.Value() ); | |
2422 | if(edge.Orientation() !=TopAbs_FORWARD && | |
2423 | edge.Orientation() !=TopAbs_REVERSED) | |
2424 | continue; | |
51740958 | 2425 | Handle(Geom2d_Curve) c2d = BRep_Tool::CurveOnSurface ( edge, pf, aCF, aCL ); |
2426 | if ( ! c2d.IsNull() ) aCW = c2d; | |
7fd59977 | 2427 | } |
2428 | } | |
2429 | TopAbs_State stInfin = clas.PerformInfinitePoint(); | |
2430 | if ( stPoint != stInfin ) break; | |
2431 | } | |
2432 | if ( j > loops.Length()) { | |
2433 | roots.Append ( wr ); | |
2434 | // loops.Remove ( i-- ); | |
2435 | } | |
2436 | } | |
2437 | ||
2438 | // And remove them from the list of loops | |
2439 | for ( i = 1; i <= loops.Length(); i++ ) | |
2440 | for ( Standard_Integer j = 1; j <= roots.Length(); j++ ) | |
2441 | if ( loops(i).IsSame ( roots(j) ) ) { loops.Remove(i--); break; } | |
2442 | ||
2443 | // check for lost wires, and if they are, make them roots | |
2444 | if ( roots.Length() <=0 && loops.Length() >0 ) { | |
0797d9d3 | 2445 | #ifdef OCCT_DEBUG |
7fd59977 | 2446 | cout << "Error: ShapeFix_ComposeShell::MakeFacesOnPatch: can't dispatch wires" << endl; |
2447 | #endif | |
2448 | for ( Standard_Integer j=1; j <= loops.Length(); j++ ) { | |
2449 | roots.Append ( loops(j) ); | |
2450 | } | |
2451 | loops.Clear(); | |
2452 | } | |
2453 | ||
2454 | // Then iterate on loops | |
2455 | for ( i=1; i <= roots.Length(); i++ ) { | |
2456 | Standard_Boolean reverse = Standard_False; | |
2457 | TopoDS_Wire wire = TopoDS::Wire ( roots(i) ); | |
2458 | TopoDS_Face fc; | |
2459 | B.MakeFace ( fc, surf, myLoc, ::Precision::Confusion() ); | |
2460 | B.Add ( fc, wire ); | |
2461 | BRepTopAdaptor_FClass2d clas ( fc, ::Precision::PConfusion() ); | |
2462 | if ( clas.PerformInfinitePoint() == TopAbs_IN ) { | |
2463 | reverse = Standard_True; | |
0797d9d3 | 2464 | #ifdef OCCT_DEBUG |
7fd59977 | 2465 | cout << "Warning: ShapeFix_ComposeShell::MakeFacesOnPatch: badly oriented wire" << endl; |
2466 | #endif | |
2467 | } | |
2468 | ||
2469 | // find all holes for that loop | |
2470 | TopTools_SequenceOfShape holes; // holes in holes not supported | |
2471 | Standard_Integer j; // svv #1 | |
2472 | for ( j=1; j <= loops.Length(); j++ ) { | |
2473 | gp_Pnt2d unp; | |
2474 | if(loops(j).ShapeType() == TopAbs_WIRE) { | |
2475 | TopoDS_Wire bw = TopoDS::Wire ( loops(j) ); | |
2476 | TopoDS_Iterator ew ( bw ); | |
2477 | if ( ! ew.More() ) continue; | |
2478 | TopoDS_Edge ed = TopoDS::Edge ( ew.Value() ); | |
2479 | Standard_Real cf, cl; | |
2480 | Handle(Geom2d_Curve) cw = BRep_Tool::CurveOnSurface ( ed, pf, cf, cl ); | |
2481 | if ( cw.IsNull() ) continue; | |
2482 | unp = cw->Value ( 0.5 * ( cf + cl ) ); | |
2483 | } | |
2484 | else if(loops(j).ShapeType() == TopAbs_VERTEX) { | |
2485 | TopoDS_Vertex aV = TopoDS::Vertex(loops(j)); | |
2486 | gp_Pnt aP = BRep_Tool::Pnt(aV); | |
2487 | unp = aSurfTool->ValueOfUV(aP,Precision::Confusion()); | |
2488 | } | |
2489 | else | |
2490 | continue; | |
2491 | TopAbs_State state = clas.Perform (unp,Standard_False); | |
2492 | if ( (Standard_Boolean) ( state == TopAbs_OUT ) == reverse ) { | |
2493 | holes.Append ( loops(j) ); | |
2494 | loops.Remove ( j-- ); | |
2495 | } | |
2496 | } | |
2497 | ||
2498 | // and add them to new face (no orienting is done) | |
2499 | TopoDS_Face newFace; | |
2500 | B.MakeFace ( newFace, surf, myLoc, ::Precision::Confusion() ); | |
2501 | B.Add ( newFace, wire ); | |
2502 | for ( j=1; j <= holes.Length(); j++ ) { | |
2503 | TopoDS_Shape aSh = holes(j); | |
2504 | if(aSh.ShapeType() == TopAbs_VERTEX) { | |
2505 | TopoDS_Vertex aNewV = ShapeAnalysis_TransferParametersProj::CopyNMVertex(TopoDS::Vertex(aSh), newFace,myFace); | |
2506 | Context()->Replace(aSh,aNewV); | |
2507 | B.Add ( newFace,aNewV); | |
2508 | } | |
2509 | else | |
2510 | B.Add ( newFace, holes(j) ); | |
2511 | } | |
2512 | faces.Append ( newFace ); | |
2513 | ||
2514 | // check for lost wires, and if they are, make them roots | |
2515 | if ( i == roots.Length() && loops.Length() >0 ) { | |
0797d9d3 | 2516 | #ifdef OCCT_DEBUG |
7fd59977 | 2517 | cout << "Error: ShapeFix_ComposeShell::MakeFacesOnPatch: can't dispatch wires" << endl; |
2518 | #endif | |
2519 | for ( j=1; j <= loops.Length(); j++ ) { | |
2520 | TopoDS_Shape aSh = loops(j); | |
2521 | if(aSh.ShapeType() == TopAbs_WIRE && (aSh.Orientation() == TopAbs_FORWARD || | |
2522 | aSh.Orientation() == TopAbs_REVERSED)) | |
2523 | roots.Append ( loops(j) ); | |
2524 | } | |
2525 | loops.Clear(); | |
2526 | } | |
2527 | } | |
2528 | } | |
2529 | ||
2530 | //======================================================================= | |
2531 | //function : DispatchWires | |
2532 | //purpose : | |
2533 | //======================================================================= | |
2534 | ||
2535 | void ShapeFix_ComposeShell::DispatchWires (TopTools_SequenceOfShape &faces, | |
2536 | ShapeFix_SequenceOfWireSegment& wires) const | |
2537 | { | |
2538 | BRep_Builder B; | |
2539 | ||
2540 | // in closed mode, apply FixShifted to all wires before dispatching them | |
2541 | if ( myClosedMode ) { | |
2542 | ShapeFix_Wire sfw; | |
2543 | sfw.SetFace ( myFace ); | |
2544 | sfw.SetPrecision ( Precision() ); | |
2545 | ||
2546 | // pdn: shift pcurves in the seam to make OK shape w/o fixshifted | |
2547 | Standard_Integer i; | |
2548 | for ( i=1; i <= wires.Length(); i++ ) { | |
2549 | if(wires(i).IsVertex()) | |
2550 | continue; | |
2551 | Handle(ShapeExtend_WireData) sbwd = wires(i).WireData(); | |
2552 | ||
2553 | for(Standard_Integer jL=1; jL <= sbwd->NbEdges(); jL++ ) { | |
2554 | TopoDS_Edge E = sbwd->Edge(jL); | |
2555 | if ( E.Orientation() == TopAbs_REVERSED && BRep_Tool::IsClosed(E,myFace) ) { | |
2556 | Standard_Real f1,l1, f2, l2; | |
2557 | Handle(Geom2d_Curve) c21 = BRep_Tool::CurveOnSurface(E,myFace,f1,l1); | |
2558 | TopoDS_Shape dummy = E.Reversed(); | |
2559 | Handle(Geom2d_Curve) c22 = BRep_Tool::CurveOnSurface(TopoDS::Edge(dummy),myFace,f2,l2); | |
2560 | Standard_Real dPreci = ::Precision::PConfusion()*Precision::PConfusion(); | |
2561 | gp_Pnt2d pf1 = c21->Value(f1); | |
2562 | gp_Pnt2d pl1 = c21->Value(l1); | |
2563 | gp_Pnt2d pf2 = c22->Value(f2); | |
2564 | gp_Pnt2d pl2 = c22->Value(l2); | |
2565 | if ( c21 == c22 || pf1.SquareDistance(pf2) < dPreci || | |
2566 | pl1.SquareDistance(pl2) < dPreci ) { | |
2567 | gp_Vec2d shift(0.,0.); | |
2568 | if ( myUClosed && Abs ( pf2.X() - pl2.X() ) < ::Precision::PConfusion() ) | |
2569 | shift.SetX(myUPeriod); | |
2570 | if ( myVClosed && Abs ( pf2.Y() - pl2.Y() ) < ::Precision::PConfusion() ) | |
2571 | shift.SetY(myVPeriod); | |
2572 | c22->Translate(shift); | |
2573 | } | |
2574 | } | |
2575 | } | |
2576 | } | |
2577 | ||
2578 | for ( i=1; i <= wires.Length(); i++ ) { | |
2579 | if(wires(i).IsVertex()) | |
2580 | continue; | |
2581 | Handle(ShapeExtend_WireData) sbwd = wires(i).WireData(); | |
2582 | ||
2583 | //: abv 30.08.01: torHalf2.sat: if wire contains single degenerated | |
2584 | // edge, skip that wire | |
2585 | if ( sbwd->NbEdges() <=0 || | |
2586 | ( sbwd->NbEdges() ==1 && BRep_Tool::Degenerated(sbwd->Edge(1)) ) ) { | |
2587 | wires.Remove(i--); | |
2588 | continue; | |
2589 | } | |
2590 | ||
2591 | sfw.Load ( sbwd ); | |
2592 | sfw.FixShifted(); | |
2593 | ||
2594 | // force recomputation of degenerated edges (clear pcurves) | |
2595 | ShapeBuild_Edge sbe; | |
2596 | for (Standard_Integer jL=1; jL <= sbwd->NbEdges(); jL++ ) { | |
2597 | if ( BRep_Tool::Degenerated(sbwd->Edge(jL)) ) | |
2598 | sbe.RemovePCurve(sbwd->Edge(jL),myFace); | |
2599 | // sfw.FixDegenerated(jL); | |
2600 | } | |
2601 | sfw.FixDegenerated(); | |
2602 | } | |
2603 | } | |
2604 | ||
2605 | // Compute center points for wires | |
2606 | TColgp_SequenceOfPnt2d mPnts; | |
2607 | Standard_Integer nb = wires.Length(); | |
2608 | ||
2609 | // pdn protection on empty sequence | |
2610 | if(nb == 0) | |
2611 | return; | |
2612 | ||
2613 | Standard_Integer i; //svv #1 | |
2614 | for ( i = 1; i <= nb; i++ ) | |
2615 | mPnts.Append ( GetMiddlePoint ( wires(i), myFace ) ); | |
2616 | ||
2617 | // Put each wire on its own surface patch (by reassigning pcurves) | |
2618 | // and build 3d curve if necessary | |
2619 | ShapeBuild_ReShape rs; | |
2620 | ShapeBuild_Edge sbe; | |
2621 | ShapeAnalysis_Edge sae; | |
2622 | Handle(ShapeFix_Edge) sfe = new ShapeFix_Edge; | |
2623 | ||
2624 | Standard_Real U1,U2,V1,V2; | |
2625 | myGrid->Bounds(U1,U2,V1,V2); | |
2626 | for ( i = 1; i <= nb; i++ ) { | |
2627 | ||
2628 | gp_Pnt2d pnt = mPnts(i); | |
2629 | Standard_Real ush =0., vsh=0.; | |
2630 | if(myUClosed) { | |
2631 | ush = ShapeAnalysis::AdjustToPeriod(pnt.X(),U1,U2); | |
2632 | pnt.SetX(pnt.X()+ush); | |
2633 | } | |
2634 | if(myVClosed) { | |
2635 | vsh = ShapeAnalysis::AdjustToPeriod(pnt.Y(),V1,V2); | |
2636 | pnt.SetY(pnt.Y()+vsh); | |
2637 | } | |
2638 | mPnts(i) = pnt; | |
2639 | Standard_Integer indU = myGrid->LocateUParameter ( pnt.X() ); | |
2640 | Standard_Integer indV = myGrid->LocateVParameter ( pnt.Y() ); | |
2641 | ||
2642 | // compute parametric transformation | |
2643 | gp_Trsf2d T; | |
2644 | Standard_Real uFact=1.; | |
2645 | Standard_Boolean needT = myGrid->GlobalToLocalTransformation ( indU, indV, uFact, T ); | |
2646 | if ( ush != 0. || vsh != 0. ) { | |
2647 | gp_Trsf2d Sh; | |
2648 | Sh.SetTranslation ( gp_Vec2d ( ush, vsh ) ); | |
2649 | T.Multiply ( Sh ); | |
2650 | needT = Standard_True; | |
2651 | } | |
2652 | if(wires(i).IsVertex()) | |
2653 | continue; | |
2654 | Handle(Geom_Surface) surf = myGrid->Patch ( indU, indV ); | |
2655 | TopoDS_Face face; | |
2656 | B.MakeFace ( face, surf, myLoc, ::Precision::Confusion() ); | |
2657 | Handle(ShapeExtend_WireData) sewd = wires(i).WireData(); | |
2658 | for ( Standard_Integer j = 1; j <= sewd->NbEdges(); j++ ) { | |
2659 | // Standard_Integer nsplit = ApplyContext ( sewd, j, context ); | |
2660 | // if ( nsplit <1 ) { j--; continue; } | |
2661 | ||
2662 | TopoDS_Edge edge = sewd->Edge(j); | |
2663 | ||
2664 | // !! Accurately copy pcurves for SEAMS and SEAM-like edges !! | |
2665 | ||
2666 | // if edge is already copied, don`t copy any more | |
2667 | TopoDS_Edge newEdge; | |
2668 | TopoDS_Edge anInitEdge = edge; | |
2669 | Standard_Boolean ismanifold = (edge.Orientation() == TopAbs_FORWARD || | |
2670 | edge.Orientation() == TopAbs_REVERSED); | |
2671 | if ( rs.IsRecorded ( edge ) ) { | |
2672 | //smh#8 | |
2673 | TopoDS_Shape tmpNE = rs.Value(edge); | |
2674 | newEdge = TopoDS::Edge ( tmpNE ); | |
2675 | } | |
2676 | else { | |
2677 | ||
2678 | if(!ismanifold) | |
2679 | anInitEdge.Orientation(TopAbs_FORWARD); | |
2680 | ||
2681 | newEdge = sbe.Copy ( anInitEdge, Standard_False ); | |
2682 | if(!ismanifold) | |
2683 | newEdge.Orientation(edge.Orientation()); | |
2684 | rs.Replace ( edge, newEdge ); | |
2685 | Context()->Replace ( edge, newEdge ); | |
2686 | } | |
2687 | ||
2688 | sbe.ReassignPCurve ( newEdge, myFace, face ); | |
2689 | ||
2690 | // transform pcurve to parametric space of patch | |
2691 | if ( needT ) { | |
2692 | Standard_Real f, l; | |
2693 | Handle(Geom2d_Curve) c2d; | |
2694 | if ( sae.PCurve ( newEdge, face, c2d, f, l, Standard_False ) ) { | |
2695 | Standard_Real newf = f, newl = l; | |
2696 | Handle(Geom2d_Curve) c2dnew = sbe.TransformPCurve ( c2d, T, uFact, newf, newl ); | |
2697 | if ( BRep_Tool::IsClosed ( newEdge, face ) ) { | |
2698 | Standard_Real cf, cl; | |
2699 | Handle(Geom2d_Curve) c2d2; | |
2700 | //smh#8 | |
2701 | TopoDS_Shape tmpE = newEdge.Reversed(); | |
2702 | TopoDS_Edge e2 = TopoDS::Edge (tmpE ); | |
2703 | if ( sae.PCurve ( e2, face, c2d2, cf, cl, Standard_False ) ) { | |
2704 | if ( newEdge.Orientation() == TopAbs_FORWARD ) | |
2705 | B.UpdateEdge ( newEdge, c2dnew, c2d2, face, 0. ); | |
2706 | else B.UpdateEdge ( newEdge, c2d2, c2dnew, face, 0. ); | |
2707 | } | |
2708 | else B.UpdateEdge ( newEdge, c2dnew, face, 0. ); | |
2709 | } | |
2710 | else B.UpdateEdge ( newEdge, c2dnew, face, 0. ); | |
2711 | B.Range ( newEdge, face, newf, newl ); | |
2712 | if ( (newf != f || newl != l) && !BRep_Tool::Degenerated(newEdge) ) | |
2713 | B.SameRange ( newEdge, Standard_False ); | |
2714 | } | |
2715 | } | |
2716 | ||
2717 | if(!BRep_Tool::SameRange(newEdge)) { | |
2718 | TopoDS_Edge etmp; | |
2719 | if(!ismanifold) { | |
2720 | TopoDS_Edge afe = TopoDS::Edge(newEdge.Oriented(TopAbs_FORWARD)); | |
2721 | etmp = sbe.Copy (afe , Standard_False ); | |
2722 | } | |
2723 | else | |
2724 | etmp = sbe.Copy ( newEdge, Standard_False ); | |
2725 | sfe->FixAddCurve3d ( etmp ); | |
2726 | Standard_Real cf, cl; | |
2727 | Handle(Geom_Curve) c3d; | |
2728 | if(sae.Curve3d(etmp,c3d,cf,cl,Standard_False)) { | |
2729 | B.UpdateEdge ( newEdge, c3d, 0. ); | |
2730 | sbe.SetRange3d ( newEdge, cf, cl ); | |
2731 | } | |
2732 | } | |
2733 | else | |
2734 | sfe->FixAddCurve3d ( newEdge ); | |
2735 | sewd->Set ( newEdge, j ); | |
2736 | } | |
2737 | } | |
2738 | ||
2739 | // Collect wires in packets lying on same surface and dispatch them | |
2740 | TColStd_Array1OfBoolean used ( 1, nb ); | |
2741 | used.Init ( Standard_False ); | |
302f96fb | 2742 | for(;;) { |
7fd59977 | 2743 | TopTools_SequenceOfShape loops; |
2744 | ||
2745 | Handle(Geom_Surface) Surf; | |
2746 | for ( i = 1; i <= nb; i++ ) { | |
2747 | if ( used(i) ) continue; | |
2748 | Handle(Geom_Surface) S = myGrid->Patch ( mPnts(i) ); | |
2749 | if ( Surf.IsNull() ) Surf = S; | |
2750 | else if ( S != Surf ) continue; | |
2751 | used(i) = Standard_True; | |
2752 | ShapeFix_WireSegment aSeg = wires(i); | |
2753 | if(aSeg.IsVertex()) { | |
2754 | TopoDS_Vertex aVert = aSeg.GetVertex(); | |
2755 | if(aVert.Orientation() == TopAbs_INTERNAL) | |
2756 | loops.Append(wires(i).GetVertex()); | |
2757 | } | |
2758 | else { | |
2759 | Handle(ShapeExtend_WireData) aWD = aSeg.WireData(); | |
2760 | if(!aWD.IsNull()) | |
2761 | loops.Append ( aWD->Wire() ); | |
2762 | } | |
2763 | } | |
2764 | if ( Surf.IsNull() ) break; | |
2765 | ||
2766 | MakeFacesOnPatch ( faces, Surf, loops ); | |
2767 | } | |
2768 | } | |
2769 | ||
2770 | //====================================================================== | |
2771 | //function : SetTransferParamTool | |
2772 | //purpose : | |
2773 | //======================================================================= | |
2774 | ||
2775 | void ShapeFix_ComposeShell::SetTransferParamTool(const Handle(ShapeAnalysis_TransferParameters)& TransferParam) | |
2776 | { | |
2777 | myTransferParamTool = TransferParam; | |
2778 | } | |
2779 | ||
2780 | //======================================================================= | |
2781 | //function : GetTransferParamTool | |
2782 | //purpose : | |
2783 | //======================================================================= | |
2784 | ||
2785 | Handle(ShapeAnalysis_TransferParameters) ShapeFix_ComposeShell::GetTransferParamTool() const | |
2786 | { | |
2787 | return myTransferParamTool; | |
2788 | } | |
2789 | ||
2790 | //======================================================================= | |
2791 | //function : ClosedMode | |
2792 | //purpose : | |
2793 | //======================================================================= | |
2794 | ||
2795 | Standard_Boolean &ShapeFix_ComposeShell::ClosedMode() | |
2796 | { | |
2797 | return myClosedMode; | |
2798 | } |