d33a8cde |
1 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include <IntTools_WLineTool.hxx> |
15 | |
16 | #include <Adaptor3d_TopolTool.hxx> |
17 | #include <BRep_Tool.hxx> |
18 | #include <Extrema_ExtCC.hxx> |
19 | #include <GeomAdaptor_Curve.hxx> |
20 | #include <GeomAdaptor_HSurface.hxx> |
21 | #include <GeomAdaptor_Surface.hxx> |
22 | #include <GeomAPI_ProjectPointOnSurf.hxx> |
23 | #include <GeomInt_LineConstructor.hxx> |
24 | #include <GeomInt.hxx> |
25 | #include <Geom2dAPI_InterCurveCurve.hxx> |
26 | #include <Geom2d_Circle.hxx> |
27 | #include <Geom2d_Line.hxx> |
28 | #include <Geom2d_TrimmedCurve.hxx> |
29 | #include <Geom_Circle.hxx> |
30 | #include <Geom_Surface.hxx> |
31 | #include <gp_Circ.hxx> |
32 | #include <IntTools_Context.hxx> |
33 | #include <Precision.hxx> |
34 | #include <TColgp_SequenceOfPnt2d.hxx> |
35 | #include <TColStd_Array1OfListOfInteger.hxx> |
36 | |
37 | /////////////////////// NotUseSurfacesForApprox ///////////////////////// |
38 | |
39 | // The block is dedicated to determine whether WLine [ifprm, ilprm] |
40 | // crosses the degenerated zone on each given surface or not. |
41 | // If Yes -> We will not use info about surfaces during approximation |
42 | // because inside degenerated zone of the surface the approx. algo. |
43 | // uses wrong values of normal, etc., and resulting curve will have |
44 | // oscillations that we would not like to have. |
45 | |
46 | //======================================================================= |
47 | //function : IsDegeneratedZone |
48 | //purpose : static subfunction in IsDegeneratedZone |
49 | //======================================================================= |
50 | static |
51 | Standard_Boolean IsDegeneratedZone(const gp_Pnt2d& aP2d, |
52 | const Handle(Geom_Surface)& aS, |
53 | const Standard_Integer iDir) |
54 | { |
55 | Standard_Boolean bFlag=Standard_True; |
56 | Standard_Real US1, US2, VS1, VS2, dY, dX, d1, d2, dD; |
57 | Standard_Real aXm, aYm, aXb, aYb, aXe, aYe; |
58 | aS->Bounds(US1, US2, VS1, VS2); |
59 | |
60 | gp_Pnt aPm, aPb, aPe; |
61 | |
62 | aXm=aP2d.X(); |
63 | aYm=aP2d.Y(); |
64 | |
65 | aS->D0(aXm, aYm, aPm); |
66 | |
67 | dX=1.e-5; |
68 | dY=1.e-5; |
69 | dD=1.e-12; |
70 | |
71 | if (iDir==1) { |
72 | aXb=aXm; |
73 | aXe=aXm; |
74 | aYb=aYm-dY; |
75 | if (aYb < VS1) { |
76 | aYb=VS1; |
77 | } |
78 | aYe=aYm+dY; |
79 | if (aYe > VS2) { |
80 | aYe=VS2; |
81 | } |
82 | aS->D0(aXb, aYb, aPb); |
83 | aS->D0(aXe, aYe, aPe); |
84 | |
85 | d1=aPm.Distance(aPb); |
86 | d2=aPm.Distance(aPe); |
87 | if (d1 < dD && d2 < dD) { |
88 | return bFlag; |
89 | } |
90 | return !bFlag; |
91 | } |
92 | // |
93 | else if (iDir==2) { |
94 | aYb=aYm; |
95 | aYe=aYm; |
96 | aXb=aXm-dX; |
97 | if (aXb < US1) { |
98 | aXb=US1; |
99 | } |
100 | aXe=aXm+dX; |
101 | if (aXe > US2) { |
102 | aXe=US2; |
103 | } |
104 | aS->D0(aXb, aYb, aPb); |
105 | aS->D0(aXe, aYe, aPe); |
106 | |
107 | d1=aPm.Distance(aPb); |
108 | d2=aPm.Distance(aPe); |
109 | if (d1 < dD && d2 < dD) { |
110 | return bFlag; |
111 | } |
112 | return !bFlag; |
113 | } |
114 | return !bFlag; |
115 | } |
116 | |
117 | //======================================================================= |
118 | //function : IsPointInDegeneratedZone |
119 | //purpose : static subfunction in NotUseSurfacesForApprox |
120 | //======================================================================= |
121 | static |
122 | Standard_Boolean IsPointInDegeneratedZone(const IntSurf_PntOn2S& aP2S, |
123 | const TopoDS_Face& aF1, |
124 | const TopoDS_Face& aF2) |
125 | |
126 | { |
127 | Standard_Boolean bFlag=Standard_True; |
128 | Standard_Real US11, US12, VS11, VS12, US21, US22, VS21, VS22; |
129 | Standard_Real U1, V1, U2, V2, aDelta, aD; |
130 | gp_Pnt2d aP2d; |
131 | |
132 | Handle(Geom_Surface)aS1 = BRep_Tool::Surface(aF1); |
133 | aS1->Bounds(US11, US12, VS11, VS12); |
134 | GeomAdaptor_Surface aGAS1(aS1); |
135 | |
136 | Handle(Geom_Surface)aS2 = BRep_Tool::Surface(aF2); |
137 | aS1->Bounds(US21, US22, VS21, VS22); |
138 | GeomAdaptor_Surface aGAS2(aS2); |
139 | // |
140 | //const gp_Pnt& aP=aP2S.Value(); |
141 | aP2S.Parameters(U1, V1, U2, V2); |
142 | // |
143 | aDelta=1.e-7; |
144 | // Check on Surf 1 |
145 | aD=aGAS1.UResolution(aDelta); |
146 | aP2d.SetCoord(U1, V1); |
147 | if (fabs(U1-US11) < aD) { |
148 | bFlag=IsDegeneratedZone(aP2d, aS1, 1); |
149 | if (bFlag) { |
150 | return bFlag; |
151 | } |
152 | } |
153 | if (fabs(U1-US12) < aD) { |
154 | bFlag=IsDegeneratedZone(aP2d, aS1, 1); |
155 | if (bFlag) { |
156 | return bFlag; |
157 | } |
158 | } |
159 | aD=aGAS1.VResolution(aDelta); |
160 | if (fabs(V1-VS11) < aDelta) { |
161 | bFlag=IsDegeneratedZone(aP2d, aS1, 2); |
162 | if (bFlag) { |
163 | return bFlag; |
164 | } |
165 | } |
166 | if (fabs(V1-VS12) < aDelta) { |
167 | bFlag=IsDegeneratedZone(aP2d, aS1, 2); |
168 | if (bFlag) { |
169 | return bFlag; |
170 | } |
171 | } |
172 | // Check on Surf 2 |
173 | aD=aGAS2.UResolution(aDelta); |
174 | aP2d.SetCoord(U2, V2); |
175 | if (fabs(U2-US21) < aDelta) { |
176 | bFlag=IsDegeneratedZone(aP2d, aS2, 1); |
177 | if (bFlag) { |
178 | return bFlag; |
179 | } |
180 | } |
181 | if (fabs(U2-US22) < aDelta) { |
182 | bFlag=IsDegeneratedZone(aP2d, aS2, 1); |
183 | if (bFlag) { |
184 | return bFlag; |
185 | } |
186 | } |
187 | aD=aGAS2.VResolution(aDelta); |
188 | if (fabs(V2-VS21) < aDelta) { |
189 | bFlag=IsDegeneratedZone(aP2d, aS2, 2); |
190 | if (bFlag) { |
191 | return bFlag; |
192 | } |
193 | } |
194 | if (fabs(V2-VS22) < aDelta) { |
195 | bFlag=IsDegeneratedZone(aP2d, aS2, 2); |
196 | if (bFlag) { |
197 | return bFlag; |
198 | } |
199 | } |
200 | return !bFlag; |
201 | } |
202 | |
203 | //======================================================================= |
204 | //function : NotUseSurfacesForApprox |
205 | //purpose : |
206 | //======================================================================= |
207 | Standard_Boolean IntTools_WLineTool::NotUseSurfacesForApprox(const TopoDS_Face& aF1, |
208 | const TopoDS_Face& aF2, |
209 | const Handle(IntPatch_WLine)& WL, |
210 | const Standard_Integer ifprm, |
211 | const Standard_Integer ilprm) |
212 | { |
213 | Standard_Boolean bPInDZ; |
214 | |
215 | Handle(IntSurf_LineOn2S) aLineOn2S=WL->Curve(); |
216 | |
217 | const IntSurf_PntOn2S& aP2Sfprm=aLineOn2S->Value(ifprm); |
218 | bPInDZ=IsPointInDegeneratedZone(aP2Sfprm, aF1, aF2); |
219 | if (bPInDZ) { |
220 | return bPInDZ; |
221 | } |
222 | |
223 | const IntSurf_PntOn2S& aP2Slprm=aLineOn2S->Value(ilprm); |
224 | bPInDZ=IsPointInDegeneratedZone(aP2Slprm, aF1, aF2); |
225 | |
226 | return bPInDZ; |
227 | } |
228 | |
229 | /////////////////////// end of NotUseSurfacesForApprox ////////////////// |
230 | |
231 | |
232 | //======================================================================= |
233 | //function : MakeBSpline2d |
234 | //purpose : |
235 | //======================================================================= |
236 | Handle(Geom2d_BSplineCurve) IntTools_WLineTool:: |
237 | MakeBSpline2d(const Handle(IntPatch_WLine)& theWLine, |
238 | const Standard_Integer ideb, |
239 | const Standard_Integer ifin, |
240 | const Standard_Boolean onFirst) |
241 | { |
242 | Standard_Integer i, nbpnt = ifin-ideb+1; |
243 | TColgp_Array1OfPnt2d poles(1,nbpnt); |
244 | TColStd_Array1OfReal knots(1,nbpnt); |
245 | TColStd_Array1OfInteger mults(1,nbpnt); |
246 | Standard_Integer ipidebm1; |
247 | |
248 | for(i = 1, ipidebm1 = i+ideb-1; i <= nbpnt; ipidebm1++, i++) { |
249 | Standard_Real U, V; |
250 | if(onFirst) |
251 | theWLine->Point(ipidebm1).ParametersOnS1(U, V); |
252 | else |
253 | theWLine->Point(ipidebm1).ParametersOnS2(U, V); |
254 | poles(i).SetCoord(U, V); |
255 | mults(i) = 1; |
256 | knots(i) = i-1; |
257 | } |
258 | mults(1) = mults(nbpnt) = 2; |
259 | |
260 | return new Geom2d_BSplineCurve(poles,knots,mults,1); |
261 | } |
262 | |
263 | /////////////////////// DecompositionOfWLine //////////////////////////// |
264 | |
265 | //======================================================================= |
266 | //function : CheckTangentZonesExist |
267 | //purpose : static subfunction in ComputeTangentZones |
268 | //======================================================================= |
269 | static |
270 | Standard_Boolean CheckTangentZonesExist(const Handle(GeomAdaptor_HSurface)& theSurface1, |
271 | const Handle(GeomAdaptor_HSurface)& theSurface2) |
272 | { |
273 | if ( ( theSurface1->GetType() != GeomAbs_Torus ) || |
274 | ( theSurface2->GetType() != GeomAbs_Torus ) ) |
275 | return Standard_False; |
276 | |
277 | gp_Torus aTor1 = theSurface1->Torus(); |
278 | gp_Torus aTor2 = theSurface2->Torus(); |
279 | |
280 | if ( aTor1.Location().Distance( aTor2.Location() ) > Precision::Confusion() ) |
281 | return Standard_False; |
282 | |
283 | if ( ( fabs( aTor1.MajorRadius() - aTor2.MajorRadius() ) > Precision::Confusion() ) || |
284 | ( fabs( aTor1.MinorRadius() - aTor2.MinorRadius() ) > Precision::Confusion() ) ) |
285 | return Standard_False; |
286 | |
287 | if ( ( aTor1.MajorRadius() < aTor1.MinorRadius() ) || |
288 | ( aTor2.MajorRadius() < aTor2.MinorRadius() ) ) |
289 | return Standard_False; |
290 | |
291 | return Standard_True; |
292 | } |
293 | |
294 | |
295 | //======================================================================= |
296 | //function : ComputeTangentZones |
297 | //purpose : static subfunction in DecompositionOfWLine |
298 | //======================================================================= |
299 | static |
300 | Standard_Integer ComputeTangentZones( const Handle(GeomAdaptor_HSurface)& theSurface1, |
301 | const Handle(GeomAdaptor_HSurface)& theSurface2, |
302 | const TopoDS_Face& theFace1, |
303 | const TopoDS_Face& theFace2, |
304 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS1, |
305 | Handle(TColgp_HArray1OfPnt2d)& theResultOnS2, |
306 | Handle(TColStd_HArray1OfReal)& theResultRadius, |
307 | const Handle(IntTools_Context)& aContext) |
308 | { |
309 | Standard_Integer aResult = 0; |
310 | if ( !CheckTangentZonesExist( theSurface1, theSurface2 ) ) |
311 | return aResult; |
312 | |
313 | |
314 | TColgp_SequenceOfPnt2d aSeqResultS1, aSeqResultS2; |
315 | TColStd_SequenceOfReal aSeqResultRad; |
316 | |
317 | gp_Torus aTor1 = theSurface1->Torus(); |
318 | gp_Torus aTor2 = theSurface2->Torus(); |
319 | |
320 | gp_Ax2 anax1( aTor1.Location(), aTor1.Axis().Direction() ); |
321 | gp_Ax2 anax2( aTor2.Location(), aTor2.Axis().Direction() ); |
322 | Standard_Integer j = 0; |
323 | |
324 | for ( j = 0; j < 2; j++ ) { |
325 | Standard_Real aCoef = ( j == 0 ) ? -1 : 1; |
326 | Standard_Real aRadius1 = fabs(aTor1.MajorRadius() + aCoef * aTor1.MinorRadius()); |
327 | Standard_Real aRadius2 = fabs(aTor2.MajorRadius() + aCoef * aTor2.MinorRadius()); |
328 | |
329 | gp_Circ aCircle1( anax1, aRadius1 ); |
330 | gp_Circ aCircle2( anax2, aRadius2 ); |
331 | |
332 | // roughly compute radius of tangent zone for perpendicular case |
333 | Standard_Real aCriteria = Precision::Confusion() * 0.5; |
334 | |
335 | Standard_Real aT1 = aCriteria; |
336 | Standard_Real aT2 = aCriteria; |
337 | if ( j == 0 ) { |
338 | // internal tangency |
339 | Standard_Real aR = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius(); |
340 | //aT1 = aCriteria * aCriteria + aR * aR - ( aR - aCriteria ) * ( aR - aCriteria ); |
341 | aT1 = 2. * aR * aCriteria; |
342 | aT2 = aT1; |
343 | } |
344 | else { |
345 | // external tangency |
346 | Standard_Real aRb = ( aRadius1 > aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius(); |
347 | Standard_Real aRm = ( aRadius1 < aTor2.MinorRadius() ) ? aRadius1 : aTor2.MinorRadius(); |
348 | Standard_Real aDelta = aRb - aCriteria; |
349 | aDelta *= aDelta; |
350 | aDelta -= aRm * aRm; |
351 | aDelta /= 2. * (aRb - aRm); |
352 | aDelta -= 0.5 * (aRb - aRm); |
353 | |
354 | aT1 = 2. * aRm * (aRm - aDelta); |
355 | aT2 = aT1; |
356 | } |
357 | aCriteria = ( aT1 > aT2) ? aT1 : aT2; |
358 | if ( aCriteria > 0 ) |
359 | aCriteria = sqrt( aCriteria ); |
360 | |
361 | if ( aCriteria > 0.5 * aTor1.MinorRadius() ) { |
362 | // too big zone -> drop to minimum |
363 | aCriteria = Precision::Confusion(); |
364 | } |
365 | |
366 | GeomAdaptor_Curve aC1( new Geom_Circle(aCircle1) ); |
367 | GeomAdaptor_Curve aC2( new Geom_Circle(aCircle2) ); |
368 | Extrema_ExtCC anExtrema(aC1, aC2, 0, 2. * M_PI, 0, 2. * M_PI, |
369 | Precision::PConfusion(), Precision::PConfusion()); |
370 | |
371 | if ( anExtrema.IsDone() ) { |
372 | |
373 | Standard_Integer i = 0; |
374 | for ( i = 1; i <= anExtrema.NbExt(); i++ ) { |
375 | if ( anExtrema.SquareDistance(i) > aCriteria * aCriteria ) |
376 | continue; |
377 | |
378 | Extrema_POnCurv P1, P2; |
379 | anExtrema.Points( i, P1, P2 ); |
380 | |
381 | Standard_Boolean bFoundResult = Standard_True; |
382 | gp_Pnt2d pr1, pr2; |
383 | |
384 | Standard_Integer surfit = 0; |
385 | for ( surfit = 0; surfit < 2; surfit++ ) { |
386 | GeomAPI_ProjectPointOnSurf& aProjector = |
387 | (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2); |
388 | |
389 | gp_Pnt aP3d = (surfit == 0) ? P1.Value() : P2.Value(); |
390 | aProjector.Perform(aP3d); |
391 | |
392 | if(!aProjector.IsDone()) |
393 | bFoundResult = Standard_False; |
394 | else { |
395 | if(aProjector.LowerDistance() > aCriteria) { |
396 | bFoundResult = Standard_False; |
397 | } |
398 | else { |
399 | Standard_Real foundU = 0, foundV = 0; |
400 | aProjector.LowerDistanceParameters(foundU, foundV); |
401 | if ( surfit == 0 ) |
402 | pr1 = gp_Pnt2d( foundU, foundV ); |
403 | else |
404 | pr2 = gp_Pnt2d( foundU, foundV ); |
405 | } |
406 | } |
407 | } |
408 | if ( bFoundResult ) { |
409 | aSeqResultS1.Append( pr1 ); |
410 | aSeqResultS2.Append( pr2 ); |
411 | aSeqResultRad.Append( aCriteria ); |
412 | |
413 | // torus is u and v periodic |
414 | const Standard_Real twoPI = M_PI + M_PI; |
415 | Standard_Real arr1tmp[2] = {pr1.X(), pr1.Y()}; |
416 | Standard_Real arr2tmp[2] = {pr2.X(), pr2.Y()}; |
417 | |
418 | // iteration on period bounds |
419 | for ( Standard_Integer k1 = 0; k1 < 2; k1++ ) { |
420 | Standard_Real aBound = ( k1 == 0 ) ? 0 : twoPI; |
421 | Standard_Real aShift = ( k1 == 0 ) ? twoPI : -twoPI; |
422 | |
423 | // iteration on surfaces |
424 | for ( Standard_Integer k2 = 0; k2 < 2; k2++ ) { |
425 | Standard_Real* arr1 = ( k2 == 0 ) ? arr1tmp : arr2tmp; |
426 | Standard_Real* arr2 = ( k2 != 0 ) ? arr1tmp : arr2tmp; |
427 | TColgp_SequenceOfPnt2d& aSeqS1 = ( k2 == 0 ) ? aSeqResultS1 : aSeqResultS2; |
428 | TColgp_SequenceOfPnt2d& aSeqS2 = ( k2 != 0 ) ? aSeqResultS1 : aSeqResultS2; |
429 | |
430 | if (fabs(arr1[0] - aBound) < Precision::PConfusion()) { |
431 | aSeqS1.Append( gp_Pnt2d( arr1[0] + aShift, arr1[1] ) ); |
432 | aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) ); |
433 | aSeqResultRad.Append( aCriteria ); |
434 | } |
435 | if (fabs(arr1[1] - aBound) < Precision::PConfusion()) { |
436 | aSeqS1.Append( gp_Pnt2d( arr1[0], arr1[1] + aShift) ); |
437 | aSeqS2.Append( gp_Pnt2d( arr2[0], arr2[1] ) ); |
438 | aSeqResultRad.Append( aCriteria ); |
439 | } |
440 | } |
441 | } // |
442 | } |
443 | } |
444 | } |
445 | } |
446 | aResult = aSeqResultRad.Length(); |
447 | |
448 | if ( aResult > 0 ) { |
449 | theResultOnS1 = new TColgp_HArray1OfPnt2d( 1, aResult ); |
450 | theResultOnS2 = new TColgp_HArray1OfPnt2d( 1, aResult ); |
451 | theResultRadius = new TColStd_HArray1OfReal( 1, aResult ); |
452 | |
453 | for ( Standard_Integer i = 1 ; i <= aResult; i++ ) { |
454 | theResultOnS1->SetValue( i, aSeqResultS1.Value(i) ); |
455 | theResultOnS2->SetValue( i, aSeqResultS2.Value(i) ); |
456 | theResultRadius->SetValue( i, aSeqResultRad.Value(i) ); |
457 | } |
458 | } |
459 | return aResult; |
460 | } |
461 | |
462 | //======================================================================= |
463 | //function : IsPointOnBoundary |
464 | //purpose : static subfunction in DecompositionOfWLine |
465 | //======================================================================= |
466 | static |
467 | Standard_Boolean IsPointOnBoundary(const Standard_Real theParameter, |
468 | const Standard_Real theFirstBoundary, |
469 | const Standard_Real theSecondBoundary, |
470 | const Standard_Real theResolution, |
471 | Standard_Boolean& IsOnFirstBoundary) |
472 | { |
473 | Standard_Boolean bRet; |
474 | Standard_Integer i; |
475 | Standard_Real adist; |
476 | // |
477 | bRet=Standard_False; |
478 | for(i = 0; i < 2; ++i) { |
479 | IsOnFirstBoundary = (i == 0); |
480 | if (IsOnFirstBoundary) { |
481 | adist = fabs(theParameter - theFirstBoundary); |
482 | } |
483 | else { |
484 | adist = fabs(theParameter - theSecondBoundary); |
485 | } |
486 | if(adist < theResolution) { |
487 | return !bRet; |
488 | } |
489 | } |
490 | return bRet; |
491 | } |
492 | |
493 | //======================================================================= |
494 | //function : IsInsideTanZone |
495 | //purpose : Check if point is inside a radial tangent zone. |
496 | // static subfunction in DecompositionOfWLine and FindPoint |
497 | //======================================================================= |
498 | static |
499 | Standard_Boolean IsInsideTanZone(const gp_Pnt2d& thePoint, |
500 | const gp_Pnt2d& theTanZoneCenter, |
501 | const Standard_Real theZoneRadius, |
502 | Handle(GeomAdaptor_HSurface) theGASurface) |
503 | { |
504 | Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius ); |
505 | Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius ); |
506 | Standard_Real aRadiusSQR = ( aUResolution < aVResolution ) ? aUResolution : aVResolution; |
507 | aRadiusSQR *= aRadiusSQR; |
508 | if ( thePoint.SquareDistance( theTanZoneCenter ) <= aRadiusSQR ) |
509 | return Standard_True; |
510 | |
511 | return Standard_False; |
512 | } |
513 | |
514 | //======================================================================= |
515 | //function : AdjustByNeighbour |
516 | //purpose : static subfunction in DecompositionOfWLine |
517 | //======================================================================= |
518 | static |
519 | gp_Pnt2d AdjustByNeighbour(const gp_Pnt2d& theaNeighbourPoint, |
520 | const gp_Pnt2d& theOriginalPoint, |
521 | Handle(GeomAdaptor_HSurface) theGASurface) |
522 | { |
523 | gp_Pnt2d ap1 = theaNeighbourPoint; |
524 | gp_Pnt2d ap2 = theOriginalPoint; |
525 | |
526 | if ( theGASurface->IsUPeriodic() ) { |
527 | Standard_Real aPeriod = theGASurface->UPeriod(); |
528 | gp_Pnt2d aPTest = ap2; |
529 | Standard_Real aSqDistMin = 1.e+100; |
530 | |
531 | for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) { |
532 | aPTest.SetX( theOriginalPoint.X() + aPeriod * pIt ); |
533 | Standard_Real dd = ap1.SquareDistance( aPTest ); |
534 | |
535 | if ( dd < aSqDistMin ) { |
536 | ap2 = aPTest; |
537 | aSqDistMin = dd; |
538 | } |
539 | } |
540 | } |
541 | if ( theGASurface->IsVPeriodic() ) { |
542 | Standard_Real aPeriod = theGASurface->VPeriod(); |
543 | gp_Pnt2d aPTest = ap2; |
544 | Standard_Real aSqDistMin = 1.e+100; |
545 | |
546 | for ( Standard_Integer pIt = -1; pIt <= 1; pIt++) { |
547 | aPTest.SetY( theOriginalPoint.Y() + aPeriod * pIt ); |
548 | Standard_Real dd = ap1.SquareDistance( aPTest ); |
549 | |
550 | if ( dd < aSqDistMin ) { |
551 | ap2 = aPTest; |
552 | aSqDistMin = dd; |
553 | } |
554 | } |
555 | } |
556 | return ap2; |
557 | } |
558 | |
559 | //======================================================================= |
560 | //function : RefineVector |
561 | //purpose : static subfunction in FindPoint |
562 | //======================================================================= |
563 | static |
564 | void RefineVector(gp_Vec2d& aV2D) |
565 | { |
566 | Standard_Integer k,m; |
567 | Standard_Real aC[2], aEps, aR1, aR2, aNum; |
568 | // |
569 | aEps=RealEpsilon(); |
570 | aR1=1.-aEps; |
571 | aR2=1.+aEps; |
572 | // |
573 | aV2D.Coord(aC[0], aC[1]); |
574 | // |
575 | for (k=0; k<2; ++k) { |
576 | m=(k+1)%2; |
577 | aNum=fabs(aC[k]); |
578 | if (aNum>aR1 && aNum<aR2) { |
579 | if (aC[k]<0.) { |
580 | aC[k]=-1.; |
581 | } |
582 | else { |
583 | aC[k]=1.; |
584 | } |
585 | aC[m]=0.; |
586 | break; |
587 | } |
588 | } |
589 | aV2D.SetCoord(aC[0], aC[1]); |
590 | } |
591 | |
592 | //======================================================================= |
593 | //function : FindPoint |
594 | //purpose : static subfunction in DecompositionOfWLine |
595 | //======================================================================= |
596 | static |
597 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, |
598 | const gp_Pnt2d& theLastPoint, |
599 | const Standard_Real theUmin, |
600 | const Standard_Real theUmax, |
601 | const Standard_Real theVmin, |
602 | const Standard_Real theVmax, |
603 | gp_Pnt2d& theNewPoint) |
604 | { |
605 | gp_Vec2d aVec(theFirstPoint, theLastPoint); |
606 | Standard_Integer i = 0, j = 0; |
607 | |
608 | for(i = 0; i < 4; i++) { |
609 | gp_Vec2d anOtherVec; |
610 | gp_Vec2d anOtherVecNormal; |
611 | gp_Pnt2d aprojpoint = theLastPoint; |
612 | |
613 | if((i % 2) == 0) { |
614 | anOtherVec.SetX(0.); |
615 | anOtherVec.SetY(1.); |
616 | anOtherVecNormal.SetX(1.); |
617 | anOtherVecNormal.SetY(0.); |
618 | |
619 | if(i < 2) |
620 | aprojpoint.SetX(theUmin); |
621 | else |
622 | aprojpoint.SetX(theUmax); |
623 | } |
624 | else { |
625 | anOtherVec.SetX(1.); |
626 | anOtherVec.SetY(0.); |
627 | anOtherVecNormal.SetX(0.); |
628 | anOtherVecNormal.SetY(1.); |
629 | |
630 | if(i < 2) |
631 | aprojpoint.SetY(theVmin); |
632 | else |
633 | aprojpoint.SetY(theVmax); |
634 | } |
635 | gp_Vec2d anormvec = aVec; |
636 | anormvec.Normalize(); |
637 | RefineVector(anormvec); |
638 | Standard_Real adot1 = anormvec.Dot(anOtherVecNormal); |
639 | |
640 | if(fabs(adot1) < Precision::Angular()) |
641 | continue; |
642 | Standard_Real adist = 0.; |
643 | Standard_Boolean bIsOut = Standard_False; |
644 | |
645 | if((i % 2) == 0) { |
646 | adist = (i < 2) ? fabs(theLastPoint.X() - theUmin) : fabs(theLastPoint.X() - theUmax); |
647 | bIsOut = (i < 2) ? (theLastPoint.X() < theUmin) : (theLastPoint.X() > theUmax); |
648 | } |
649 | else { |
650 | adist = (i < 2) ? fabs(theLastPoint.Y() - theVmin) : fabs(theLastPoint.Y() - theVmax); |
651 | bIsOut = (i < 2) ? (theLastPoint.Y() < theVmin) : (theLastPoint.Y() > theVmax); |
652 | } |
653 | Standard_Real anoffset = adist * anOtherVec.Dot(anormvec) / adot1; |
654 | |
655 | for(j = 0; j < 2; j++) { |
656 | anoffset = (j == 0) ? anoffset : -anoffset; |
657 | gp_Pnt2d acurpoint(aprojpoint.XY() + (anOtherVec.XY()*anoffset)); |
658 | gp_Vec2d acurvec(theLastPoint, acurpoint); |
659 | if ( bIsOut ) |
660 | acurvec.Reverse(); |
661 | |
662 | Standard_Real aDotX, anAngleX; |
663 | // |
664 | aDotX = aVec.Dot(acurvec); |
665 | anAngleX = aVec.Angle(acurvec); |
666 | // |
667 | if(aDotX > 0. && fabs(anAngleX) < Precision::PConfusion()) { |
668 | if((i % 2) == 0) { |
669 | if((acurpoint.Y() >= theVmin) && |
670 | (acurpoint.Y() <= theVmax)) { |
671 | theNewPoint = acurpoint; |
672 | return Standard_True; |
673 | } |
674 | } |
675 | else { |
676 | if((acurpoint.X() >= theUmin) && |
677 | (acurpoint.X() <= theUmax)) { |
678 | theNewPoint = acurpoint; |
679 | return Standard_True; |
680 | } |
681 | } |
682 | } |
683 | } |
684 | } |
685 | return Standard_False; |
686 | } |
687 | |
688 | //======================================================================= |
689 | //function : FindPoint |
690 | //purpose : Find point on the boundary of radial tangent zone |
691 | // static subfunction in DecompositionOfWLine |
692 | //======================================================================= |
693 | static |
694 | Standard_Boolean FindPoint(const gp_Pnt2d& theFirstPoint, |
695 | const gp_Pnt2d& theLastPoint, |
696 | const Standard_Real theUmin, |
697 | const Standard_Real theUmax, |
698 | const Standard_Real theVmin, |
699 | const Standard_Real theVmax, |
700 | const gp_Pnt2d& theTanZoneCenter, |
701 | const Standard_Real theZoneRadius, |
702 | Handle(GeomAdaptor_HSurface) theGASurface, |
703 | gp_Pnt2d& theNewPoint) { |
704 | theNewPoint = theLastPoint; |
705 | |
706 | if ( !IsInsideTanZone( theLastPoint, theTanZoneCenter, theZoneRadius, theGASurface) ) |
707 | return Standard_False; |
708 | |
709 | Standard_Real aUResolution = theGASurface->UResolution( theZoneRadius ); |
710 | Standard_Real aVResolution = theGASurface->VResolution( theZoneRadius ); |
711 | |
712 | Standard_Real aRadius = ( aUResolution < aVResolution ) ? aUResolution : aVResolution; |
713 | gp_Ax22d anAxis( theTanZoneCenter, gp_Dir2d(1, 0), gp_Dir2d(0, 1) ); |
714 | gp_Circ2d aCircle( anAxis, aRadius ); |
715 | |
716 | // |
717 | gp_Vec2d aDir( theLastPoint.XY() - theFirstPoint.XY() ); |
718 | Standard_Real aLength = aDir.Magnitude(); |
719 | if ( aLength <= gp::Resolution() ) |
720 | return Standard_False; |
721 | gp_Lin2d aLine( theFirstPoint, aDir ); |
722 | |
723 | // |
724 | Handle(Geom2d_Line) aCLine = new Geom2d_Line( aLine ); |
725 | Handle(Geom2d_TrimmedCurve) aC1 = new Geom2d_TrimmedCurve( aCLine, 0, aLength ); |
726 | Handle(Geom2d_Circle) aC2 = new Geom2d_Circle( aCircle ); |
727 | |
728 | Standard_Real aTol = aRadius * 0.001; |
729 | aTol = ( aTol < Precision::PConfusion() ) ? Precision::PConfusion() : aTol; |
730 | |
731 | Geom2dAPI_InterCurveCurve anIntersector; |
732 | anIntersector.Init( aC1, aC2, aTol ); |
733 | |
734 | if ( anIntersector.NbPoints() == 0 ) |
735 | return Standard_False; |
736 | |
737 | Standard_Boolean aFound = Standard_False; |
738 | Standard_Real aMinDist = aLength * aLength; |
739 | Standard_Integer i = 0; |
740 | for ( i = 1; i <= anIntersector.NbPoints(); i++ ) { |
741 | gp_Pnt2d aPInt = anIntersector.Point( i ); |
742 | if ( aPInt.SquareDistance( theFirstPoint ) < aMinDist ) { |
743 | if ( ( aPInt.X() >= theUmin ) && ( aPInt.X() <= theUmax ) && |
744 | ( aPInt.Y() >= theVmin ) && ( aPInt.Y() <= theVmax ) ) { |
745 | theNewPoint = aPInt; |
746 | aFound = Standard_True; |
747 | } |
748 | } |
749 | } |
750 | |
751 | return aFound; |
752 | } |
753 | |
754 | //======================================================================= |
755 | //function : DecompositionOfWLine |
756 | //purpose : |
757 | //======================================================================= |
758 | Standard_Boolean IntTools_WLineTool:: |
759 | DecompositionOfWLine(const Handle(IntPatch_WLine)& theWLine, |
760 | const Handle(GeomAdaptor_HSurface)& theSurface1, |
761 | const Handle(GeomAdaptor_HSurface)& theSurface2, |
762 | const TopoDS_Face& theFace1, |
763 | const TopoDS_Face& theFace2, |
764 | const GeomInt_LineConstructor& theLConstructor, |
765 | const Standard_Boolean theAvoidLConstructor, |
766 | IntPatch_SequenceOfLine& theNewLines, |
767 | Standard_Real& theReachedTol3d, |
768 | const Handle(IntTools_Context)& aContext) |
769 | { |
770 | |
771 | Standard_Boolean bRet, bAvoidLineConstructor; |
772 | Standard_Integer aNbPnts, aNbParts; |
773 | // |
774 | bRet=Standard_False; |
775 | aNbPnts=theWLine->NbPnts(); |
776 | bAvoidLineConstructor=theAvoidLConstructor; |
777 | // |
778 | if(!aNbPnts){ |
779 | return bRet; |
780 | } |
781 | if (!bAvoidLineConstructor) { |
782 | aNbParts=theLConstructor.NbParts(); |
783 | if (!aNbParts) { |
784 | return bRet; |
785 | } |
786 | } |
787 | // |
788 | Standard_Boolean bIsPrevPointOnBoundary, bIsPointOnBoundary, bIsCurrentPointOnBoundary; |
789 | Standard_Integer nblines, pit, i, j; |
790 | Standard_Real aTol; |
791 | TColStd_Array1OfListOfInteger anArrayOfLines(1, aNbPnts); |
792 | TColStd_Array1OfInteger anArrayOfLineType(1, aNbPnts); |
793 | TColStd_ListOfInteger aListOfPointIndex; |
794 | |
795 | Handle(TColgp_HArray1OfPnt2d) aTanZoneS1; |
796 | Handle(TColgp_HArray1OfPnt2d) aTanZoneS2; |
797 | Handle(TColStd_HArray1OfReal) aTanZoneRadius; |
798 | Standard_Integer aNbZone = ComputeTangentZones( theSurface1, theSurface2, theFace1, theFace2, |
799 | aTanZoneS1, aTanZoneS2, aTanZoneRadius, aContext); |
800 | |
801 | // |
802 | nblines=0; |
803 | aTol=Precision::Confusion(); |
804 | aTol=0.5*aTol; |
805 | bIsPrevPointOnBoundary=Standard_False; |
806 | bIsPointOnBoundary=Standard_False; |
807 | // |
808 | // 1. ... |
809 | // |
810 | // Points |
811 | for(pit = 1; pit <= aNbPnts; ++pit) { |
812 | Standard_Boolean bIsOnFirstBoundary, isperiodic; |
813 | Standard_Real aResolution, aPeriod, alowerboundary, aupperboundary, U, V; |
814 | Standard_Real aParameter, anoffset, anAdjustPar; |
815 | Standard_Real umin, umax, vmin, vmax; |
816 | // |
817 | bIsCurrentPointOnBoundary = Standard_False; |
818 | const IntSurf_PntOn2S& aPoint = theWLine->Point(pit); |
819 | // |
820 | // Surface |
821 | for(i = 0; i < 2; ++i) { |
822 | Handle(GeomAdaptor_HSurface) aGASurface = (!i) ? theSurface1 : theSurface2; |
823 | aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax); |
824 | if(!i) { |
825 | aPoint.ParametersOnS1(U, V); |
826 | } |
827 | else { |
828 | aPoint.ParametersOnS2(U, V); |
829 | } |
830 | // U, V |
831 | for(j = 0; j < 2; j++) { |
832 | isperiodic = (!j) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic(); |
833 | if(!isperiodic){ |
834 | continue; |
835 | } |
836 | // |
837 | if (!j) { |
838 | aResolution=aGASurface->UResolution(aTol); |
839 | aPeriod=aGASurface->UPeriod(); |
840 | alowerboundary=umin; |
841 | aupperboundary=umax; |
842 | aParameter=U; |
843 | } |
844 | else { |
845 | aResolution=aGASurface->VResolution(aTol); |
846 | aPeriod=aGASurface->VPeriod(); |
847 | alowerboundary=vmin; |
848 | aupperboundary=vmax; |
849 | aParameter=V; |
850 | } |
851 | |
852 | GeomInt::AdjustPeriodic(aParameter, |
853 | alowerboundary, |
854 | aupperboundary, |
855 | aPeriod, |
856 | anAdjustPar, |
857 | anoffset); |
858 | // |
859 | bIsOnFirstBoundary = Standard_True;// ? |
860 | bIsPointOnBoundary= |
861 | IsPointOnBoundary(anAdjustPar, |
862 | alowerboundary, |
863 | aupperboundary, |
864 | aResolution, |
865 | bIsOnFirstBoundary); |
866 | // |
867 | if(bIsPointOnBoundary) { |
868 | bIsCurrentPointOnBoundary = Standard_True; |
869 | break; |
870 | } |
871 | else { |
872 | // check if a point belong to a tangent zone. Begin |
873 | Standard_Integer zIt = 0; |
874 | for ( zIt = 1; zIt <= aNbZone; zIt++ ) { |
875 | gp_Pnt2d aPZone = (i == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt); |
876 | Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt); |
877 | |
878 | if ( IsInsideTanZone(gp_Pnt2d( U, V ), aPZone, aZoneRadius, aGASurface ) ) { |
879 | // set boundary flag to split the curve by a tangent zone |
880 | bIsPointOnBoundary = Standard_True; |
881 | bIsCurrentPointOnBoundary = Standard_True; |
882 | if ( theReachedTol3d < aZoneRadius ) { |
883 | theReachedTol3d = aZoneRadius; |
884 | } |
885 | break; |
886 | } |
887 | } |
888 | } |
889 | }//for(j = 0; j < 2; j++) { |
890 | |
891 | if(bIsCurrentPointOnBoundary){ |
892 | break; |
893 | } |
894 | }//for(i = 0; i < 2; ++i) { |
895 | // |
896 | if((bIsCurrentPointOnBoundary != bIsPrevPointOnBoundary)) { |
897 | if(!aListOfPointIndex.IsEmpty()) { |
898 | nblines++; |
899 | anArrayOfLines.SetValue(nblines, aListOfPointIndex); |
900 | anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary); |
901 | aListOfPointIndex.Clear(); |
902 | } |
903 | bIsPrevPointOnBoundary = bIsCurrentPointOnBoundary; |
904 | } |
905 | aListOfPointIndex.Append(pit); |
906 | } //for(pit = 1; pit <= aNbPnts; ++pit) { |
907 | // |
908 | if(!aListOfPointIndex.IsEmpty()) { |
909 | nblines++; |
910 | anArrayOfLines.SetValue(nblines, aListOfPointIndex); |
911 | anArrayOfLineType.SetValue(nblines, bIsPrevPointOnBoundary); |
912 | aListOfPointIndex.Clear(); |
913 | } |
914 | // |
915 | if(nblines<=1) { |
916 | return bRet; //Standard_False; |
917 | } |
918 | // |
919 | // |
920 | // 2. Correct wlines.begin |
921 | TColStd_Array1OfListOfInteger anArrayOfLineEnds(1, nblines); |
922 | Handle(IntSurf_LineOn2S) aSeqOfPntOn2S = new IntSurf_LineOn2S(); |
923 | // |
924 | for(i = 1; i <= nblines; i++) { |
925 | if(anArrayOfLineType.Value(i) != 0) { |
926 | continue; |
927 | } |
928 | const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i); |
929 | TColStd_ListOfInteger aListOfFLIndex; |
930 | |
931 | for(j = 0; j < 2; j++) { |
932 | Standard_Integer aneighbourindex = (j == 0) ? (i - 1) : (i + 1); |
933 | |
934 | if((aneighbourindex < 1) || (aneighbourindex > nblines)) |
935 | continue; |
936 | |
937 | if(anArrayOfLineType.Value(aneighbourindex) == 0) |
938 | continue; |
939 | const TColStd_ListOfInteger& aNeighbour = anArrayOfLines.Value(aneighbourindex); |
940 | Standard_Integer anIndex = (j == 0) ? aNeighbour.Last() : aNeighbour.First(); |
941 | const IntSurf_PntOn2S& aPoint = theWLine->Point(anIndex); |
942 | |
943 | IntSurf_PntOn2S aNewP = aPoint; |
944 | if(aListOfIndex.Extent() < 2) { |
945 | aSeqOfPntOn2S->Add(aNewP); |
946 | aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints()); |
947 | continue; |
948 | } |
949 | // |
950 | Standard_Integer iFirst = aListOfIndex.First(); |
951 | Standard_Integer iLast = aListOfIndex.Last(); |
952 | // |
953 | for(Standard_Integer surfit = 0; surfit < 2; surfit++) { |
954 | |
955 | Handle(GeomAdaptor_HSurface) aGASurface = (surfit == 0) ? theSurface1 : theSurface2; |
956 | Standard_Real umin=0., umax=0., vmin=0., vmax=0.; |
957 | aGASurface->ChangeSurface().Surface()->Bounds(umin, umax, vmin, vmax); |
958 | Standard_Real U=0., V=0.; |
959 | |
960 | if(surfit == 0) |
961 | aNewP.ParametersOnS1(U, V); |
962 | else |
963 | aNewP.ParametersOnS2(U, V); |
964 | Standard_Integer nbboundaries = 0; |
965 | |
966 | Standard_Boolean bIsNearBoundary = Standard_False; |
967 | Standard_Integer aZoneIndex = 0; |
968 | Standard_Integer bIsUBoundary = Standard_False; // use if nbboundaries == 1 |
969 | Standard_Integer bIsFirstBoundary = Standard_False; // use if nbboundaries == 1 |
970 | |
971 | |
972 | for(Standard_Integer parit = 0; parit < 2; parit++) { |
973 | Standard_Boolean isperiodic = (parit == 0) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic(); |
974 | |
975 | Standard_Real aResolution = (parit == 0) ? aGASurface->UResolution(aTol) : aGASurface->VResolution(aTol); |
976 | Standard_Real alowerboundary = (parit == 0) ? umin : vmin; |
977 | Standard_Real aupperboundary = (parit == 0) ? umax : vmax; |
978 | |
979 | Standard_Real aParameter = (parit == 0) ? U : V; |
980 | Standard_Boolean bIsOnFirstBoundary = Standard_True; |
981 | |
982 | if(!isperiodic) { |
983 | bIsPointOnBoundary= |
984 | IsPointOnBoundary(aParameter, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary); |
985 | if(bIsPointOnBoundary) { |
986 | bIsUBoundary = (parit == 0); |
987 | bIsFirstBoundary = bIsOnFirstBoundary; |
988 | nbboundaries++; |
989 | } |
990 | } |
991 | else { |
992 | Standard_Real aPeriod = (parit == 0) ? aGASurface->UPeriod() : aGASurface->VPeriod(); |
993 | Standard_Real anoffset, anAdjustPar; |
994 | GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary, |
995 | aPeriod, anAdjustPar, anoffset); |
996 | |
997 | bIsPointOnBoundary= |
998 | IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, aResolution, bIsOnFirstBoundary); |
999 | if(bIsPointOnBoundary) { |
1000 | bIsUBoundary = (parit == 0); |
1001 | bIsFirstBoundary = bIsOnFirstBoundary; |
1002 | nbboundaries++; |
1003 | } |
1004 | else { |
1005 | //check neighbourhood of boundary |
1006 | Standard_Real anEpsilon = aResolution * 100.; |
1007 | Standard_Real aPart = ( aupperboundary - alowerboundary ) * 0.1; |
1008 | anEpsilon = ( anEpsilon > aPart ) ? aPart : anEpsilon; |
1009 | |
1010 | bIsNearBoundary = IsPointOnBoundary(anAdjustPar, alowerboundary, aupperboundary, |
1011 | anEpsilon, bIsOnFirstBoundary); |
1012 | |
1013 | } |
1014 | } |
1015 | } |
1016 | |
1017 | // check if a point belong to a tangent zone. Begin |
1018 | for ( Standard_Integer zIt = 1; zIt <= aNbZone; zIt++ ) { |
1019 | gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(zIt) : aTanZoneS2->Value(zIt); |
1020 | Standard_Real aZoneRadius = aTanZoneRadius->Value(zIt); |
1021 | |
1022 | Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast; |
1023 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1); |
1024 | Standard_Real nU1, nV1; |
1025 | |
1026 | if(surfit == 0) |
1027 | aNeighbourPoint.ParametersOnS1(nU1, nV1); |
1028 | else |
1029 | aNeighbourPoint.ParametersOnS2(nU1, nV1); |
1030 | gp_Pnt2d ap1(nU1, nV1); |
1031 | gp_Pnt2d ap2 = AdjustByNeighbour( ap1, gp_Pnt2d( U, V ), aGASurface ); |
1032 | |
1033 | |
1034 | if ( IsInsideTanZone( ap2, aPZone, aZoneRadius, aGASurface ) ) { |
1035 | aZoneIndex = zIt; |
1036 | bIsNearBoundary = Standard_True; |
1037 | if ( theReachedTol3d < aZoneRadius ) { |
1038 | theReachedTol3d = aZoneRadius; |
1039 | } |
1040 | } |
1041 | } |
1042 | // check if a point belong to a tangent zone. End |
1043 | Standard_Boolean bComputeLineEnd = Standard_False; |
1044 | |
1045 | if(nbboundaries == 2) { |
1046 | //xf |
1047 | bComputeLineEnd = Standard_True; |
1048 | //xt |
1049 | } |
1050 | else if(nbboundaries == 1) { |
1051 | Standard_Boolean isperiodic = (bIsUBoundary) ? aGASurface->IsUPeriodic() : aGASurface->IsVPeriodic(); |
1052 | |
1053 | if(isperiodic) { |
1054 | Standard_Real alowerboundary = (bIsUBoundary) ? umin : vmin; |
1055 | Standard_Real aupperboundary = (bIsUBoundary) ? umax : vmax; |
1056 | Standard_Real aPeriod = (bIsUBoundary) ? aGASurface->UPeriod() : aGASurface->VPeriod(); |
1057 | Standard_Real aParameter = (bIsUBoundary) ? U : V; |
1058 | Standard_Real anoffset, anAdjustPar; |
1059 | GeomInt::AdjustPeriodic(aParameter, alowerboundary, aupperboundary, |
1060 | aPeriod, anAdjustPar, anoffset); |
1061 | |
1062 | Standard_Real adist = (bIsFirstBoundary) ? fabs(anAdjustPar - alowerboundary) : fabs(anAdjustPar - aupperboundary); |
1063 | Standard_Real anotherPar = (bIsFirstBoundary) ? (aupperboundary - adist) : (alowerboundary + adist); |
1064 | anotherPar += anoffset; |
1065 | Standard_Integer aneighbourpointindex = (j == 0) ? aListOfIndex.First() : aListOfIndex.Last(); |
1066 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex); |
1067 | Standard_Real nU1, nV1; |
1068 | |
1069 | if(surfit == 0) |
1070 | aNeighbourPoint.ParametersOnS1(nU1, nV1); |
1071 | else |
1072 | aNeighbourPoint.ParametersOnS2(nU1, nV1); |
1073 | |
1074 | Standard_Real adist1 = (bIsUBoundary) ? fabs(nU1 - U) : fabs(nV1 - V); |
1075 | Standard_Real adist2 = (bIsUBoundary) ? fabs(nU1 - anotherPar) : fabs(nV1 - anotherPar); |
1076 | bComputeLineEnd = Standard_True; |
1077 | Standard_Boolean bCheckAngle1 = Standard_False; |
1078 | Standard_Boolean bCheckAngle2 = Standard_False; |
1079 | gp_Vec2d aNewVec; |
1080 | Standard_Real anewU = (bIsUBoundary) ? anotherPar : U; |
1081 | Standard_Real anewV = (bIsUBoundary) ? V : anotherPar; |
1082 | |
1083 | if(((adist1 - adist2) > Precision::PConfusion()) && |
1084 | (adist2 < (aPeriod / 4.))) { |
1085 | bCheckAngle1 = Standard_True; |
1086 | aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(anewU, anewV)); |
1087 | |
1088 | if(aNewVec.SquareMagnitude() < gp::Resolution()) { |
1089 | aNewP.SetValue((surfit == 0), anewU, anewV); |
1090 | bCheckAngle1 = Standard_False; |
1091 | } |
1092 | } |
1093 | else if(adist1 < (aPeriod / 4.)) { |
1094 | bCheckAngle2 = Standard_True; |
1095 | aNewVec = gp_Vec2d(gp_Pnt2d(nU1, nV1), gp_Pnt2d(U, V)); |
1096 | |
1097 | if(aNewVec.SquareMagnitude() < gp::Resolution()) { |
1098 | bCheckAngle2 = Standard_False; |
1099 | } |
1100 | } |
1101 | |
1102 | if(bCheckAngle1 || bCheckAngle2) { |
1103 | // assume there are at least two points in line (see "if" above) |
1104 | Standard_Integer anindexother = aneighbourpointindex; |
1105 | |
1106 | while((anindexother <= iLast) && (anindexother >= iFirst)) { |
1107 | anindexother = (j == 0) ? (anindexother + 1) : (anindexother - 1); |
1108 | const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(anindexother); |
1109 | Standard_Real nU2, nV2; |
1110 | |
1111 | if(surfit == 0) |
1112 | aPrevNeighbourPoint.ParametersOnS1(nU2, nV2); |
1113 | else |
1114 | aPrevNeighbourPoint.ParametersOnS2(nU2, nV2); |
1115 | gp_Vec2d aVecOld(gp_Pnt2d(nU2, nV2), gp_Pnt2d(nU1, nV1)); |
1116 | |
1117 | if(aVecOld.SquareMagnitude() <= gp::Resolution()) { |
1118 | continue; |
1119 | } |
1120 | else { |
1121 | Standard_Real anAngle = aNewVec.Angle(aVecOld); |
1122 | |
1123 | if((fabs(anAngle) < (M_PI * 0.25)) && (aNewVec.Dot(aVecOld) > 0.)) { |
1124 | |
1125 | if(bCheckAngle1) { |
1126 | Standard_Real U1, U2, V1, V2; |
1127 | IntSurf_PntOn2S atmppoint = aNewP; |
1128 | atmppoint.SetValue((surfit == 0), anewU, anewV); |
1129 | atmppoint.Parameters(U1, V1, U2, V2); |
1130 | gp_Pnt P1 = theSurface1->Value(U1, V1); |
1131 | gp_Pnt P2 = theSurface2->Value(U2, V2); |
1132 | gp_Pnt P0 = aPoint.Value(); |
1133 | |
1134 | if(P0.IsEqual(P1, aTol) && |
1135 | P0.IsEqual(P2, aTol) && |
1136 | P1.IsEqual(P2, aTol)) { |
1137 | bComputeLineEnd = Standard_False; |
1138 | aNewP.SetValue((surfit == 0), anewU, anewV); |
1139 | } |
1140 | } |
1141 | |
1142 | if(bCheckAngle2) { |
1143 | bComputeLineEnd = Standard_False; |
1144 | } |
1145 | } |
1146 | break; |
1147 | } |
1148 | } // end while(anindexother...) |
1149 | } |
1150 | } |
1151 | } |
1152 | else if ( bIsNearBoundary ) { |
1153 | bComputeLineEnd = Standard_True; |
1154 | } |
1155 | |
1156 | if(bComputeLineEnd) { |
1157 | |
1158 | gp_Pnt2d anewpoint; |
1159 | Standard_Boolean found = Standard_False; |
1160 | |
1161 | if ( bIsNearBoundary ) { |
1162 | // re-compute point near natural boundary or near tangent zone |
1163 | Standard_Real u1, v1, u2, v2; |
1164 | aNewP.Parameters( u1, v1, u2, v2 ); |
1165 | if(surfit == 0) |
1166 | anewpoint = gp_Pnt2d( u1, v1 ); |
1167 | else |
1168 | anewpoint = gp_Pnt2d( u2, v2 ); |
1169 | |
1170 | Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast; |
1171 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1); |
1172 | Standard_Real nU1, nV1; |
1173 | |
1174 | if(surfit == 0) |
1175 | aNeighbourPoint.ParametersOnS1(nU1, nV1); |
1176 | else |
1177 | aNeighbourPoint.ParametersOnS2(nU1, nV1); |
1178 | gp_Pnt2d ap1(nU1, nV1); |
1179 | gp_Pnt2d ap2; |
1180 | |
1181 | |
1182 | if ( aZoneIndex ) { |
1183 | // exclude point from a tangent zone |
1184 | anewpoint = AdjustByNeighbour( ap1, anewpoint, aGASurface ); |
1185 | gp_Pnt2d aPZone = (surfit == 0) ? aTanZoneS1->Value(aZoneIndex) : aTanZoneS2->Value(aZoneIndex); |
1186 | Standard_Real aZoneRadius = aTanZoneRadius->Value(aZoneIndex); |
1187 | |
1188 | if ( FindPoint(ap1, anewpoint, umin, umax, vmin, vmax, |
1189 | aPZone, aZoneRadius, aGASurface, ap2) ) { |
1190 | anewpoint = ap2; |
1191 | found = Standard_True; |
1192 | } |
1193 | } |
1194 | else if ( aGASurface->IsUPeriodic() || aGASurface->IsVPeriodic() ) { |
1195 | // re-compute point near boundary if shifted on a period |
1196 | ap2 = AdjustByNeighbour( ap1, anewpoint, aGASurface ); |
1197 | |
1198 | if ( ( ap2.X() < umin ) || ( ap2.X() > umax ) || |
1199 | ( ap2.Y() < vmin ) || ( ap2.Y() > vmax ) ) { |
1200 | found = FindPoint(ap1, ap2, umin, umax, vmin, vmax, anewpoint); |
1201 | } |
1202 | else { |
1203 | anewpoint = ap2; |
1204 | aNewP.SetValue( (surfit == 0), anewpoint.X(), anewpoint.Y() ); |
1205 | } |
1206 | } |
1207 | } |
1208 | else { |
1209 | |
1210 | Standard_Integer aneighbourpointindex1 = (j == 0) ? iFirst : iLast; |
1211 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneighbourpointindex1); |
1212 | Standard_Real nU1, nV1; |
1213 | |
1214 | if(surfit == 0) |
1215 | aNeighbourPoint.ParametersOnS1(nU1, nV1); |
1216 | else |
1217 | aNeighbourPoint.ParametersOnS2(nU1, nV1); |
1218 | gp_Pnt2d ap1(nU1, nV1); |
1219 | gp_Pnt2d ap2(nU1, nV1); |
1220 | Standard_Integer aneighbourpointindex2 = aneighbourpointindex1; |
1221 | |
1222 | while((aneighbourpointindex2 <= iLast) && (aneighbourpointindex2 >= iFirst)) { |
1223 | aneighbourpointindex2 = (j == 0) ? (aneighbourpointindex2 + 1) : (aneighbourpointindex2 - 1); |
1224 | const IntSurf_PntOn2S& aPrevNeighbourPoint = theWLine->Point(aneighbourpointindex2); |
1225 | Standard_Real nU2, nV2; |
1226 | |
1227 | if(surfit == 0) |
1228 | aPrevNeighbourPoint.ParametersOnS1(nU2, nV2); |
1229 | else |
1230 | aPrevNeighbourPoint.ParametersOnS2(nU2, nV2); |
1231 | ap2.SetX(nU2); |
1232 | ap2.SetY(nV2); |
1233 | |
1234 | if(ap1.SquareDistance(ap2) > gp::Resolution()) { |
1235 | break; |
1236 | } |
1237 | } |
1238 | found = FindPoint(ap2, ap1, umin, umax, vmin, vmax, anewpoint); |
1239 | } |
1240 | |
1241 | if(found) { |
1242 | // check point |
1243 | Standard_Real aCriteria = BRep_Tool::Tolerance(theFace1) + BRep_Tool::Tolerance(theFace2); |
1244 | GeomAPI_ProjectPointOnSurf& aProjector = |
1245 | (surfit == 0) ? aContext->ProjPS(theFace2) : aContext->ProjPS(theFace1); |
1246 | Handle(GeomAdaptor_HSurface) aSurface = (surfit == 0) ? theSurface1 : theSurface2; |
1247 | |
1248 | Handle(GeomAdaptor_HSurface) aSurfaceOther = (surfit == 0) ? theSurface2 : theSurface1; |
1249 | |
1250 | gp_Pnt aP3d = aSurface->Value(anewpoint.X(), anewpoint.Y()); |
1251 | aProjector.Perform(aP3d); |
1252 | |
1253 | if(aProjector.IsDone()) { |
1254 | if(aProjector.LowerDistance() < aCriteria) { |
1255 | Standard_Real foundU = U, foundV = V; |
1256 | aProjector.LowerDistanceParameters(foundU, foundV); |
1257 | |
1258 | //Correction of projected coordinates. Begin |
1259 | //Note, it may be shifted on a period |
1260 | Standard_Integer aneindex1 = (j == 0) ? iFirst : iLast; |
1261 | const IntSurf_PntOn2S& aNeighbourPoint = theWLine->Point(aneindex1); |
1262 | Standard_Real nUn, nVn; |
1263 | |
1264 | if(surfit == 0) |
1265 | aNeighbourPoint.ParametersOnS2(nUn, nVn); |
1266 | else |
1267 | aNeighbourPoint.ParametersOnS1(nUn, nVn); |
1268 | gp_Pnt2d aNeighbour2d(nUn, nVn); |
1269 | gp_Pnt2d anAdjustedPoint = AdjustByNeighbour( aNeighbour2d, gp_Pnt2d(foundU, foundV), aSurfaceOther ); |
1270 | foundU = anAdjustedPoint.X(); |
1271 | foundV = anAdjustedPoint.Y(); |
1272 | |
1273 | if ( ( anAdjustedPoint.X() < umin ) && ( anAdjustedPoint.X() > umax ) && |
1274 | ( anAdjustedPoint.Y() < vmin ) && ( anAdjustedPoint.Y() > vmax ) ) { |
1275 | // attempt to roughly re-compute point |
1276 | foundU = ( foundU < umin ) ? umin : foundU; |
1277 | foundU = ( foundU > umax ) ? umax : foundU; |
1278 | foundV = ( foundV < vmin ) ? vmin : foundV; |
1279 | foundV = ( foundV > vmax ) ? vmax : foundV; |
1280 | |
1281 | GeomAPI_ProjectPointOnSurf& aProjector2 = |
1282 | (surfit == 0) ? aContext->ProjPS(theFace1) : aContext->ProjPS(theFace2); |
1283 | |
1284 | aP3d = aSurfaceOther->Value(foundU, foundV); |
1285 | aProjector2.Perform(aP3d); |
1286 | |
1287 | if(aProjector2.IsDone()) { |
1288 | if(aProjector2.LowerDistance() < aCriteria) { |
1289 | Standard_Real foundU2 = anewpoint.X(), foundV2 = anewpoint.Y(); |
1290 | aProjector2.LowerDistanceParameters(foundU2, foundV2); |
1291 | anewpoint.SetX(foundU2); |
1292 | anewpoint.SetY(foundV2); |
1293 | } |
1294 | } |
1295 | } |
1296 | //Correction of projected coordinates. End |
1297 | |
1298 | if(surfit == 0) |
1299 | aNewP.SetValue(aP3d, anewpoint.X(), anewpoint.Y(), foundU, foundV); |
1300 | else |
1301 | aNewP.SetValue(aP3d, foundU, foundV, anewpoint.X(), anewpoint.Y()); |
1302 | } |
1303 | } |
1304 | } |
1305 | } |
1306 | } |
1307 | aSeqOfPntOn2S->Add(aNewP); |
1308 | aListOfFLIndex.Append(aSeqOfPntOn2S->NbPoints()); |
1309 | } |
1310 | anArrayOfLineEnds.SetValue(i, aListOfFLIndex); |
1311 | } |
1312 | // Correct wlines.end |
1313 | |
1314 | // Split wlines.begin |
1315 | Standard_Integer nbiter; |
1316 | // |
1317 | nbiter=1; |
1318 | if (!bAvoidLineConstructor) { |
1319 | nbiter=theLConstructor.NbParts(); |
1320 | } |
1321 | // |
1322 | for(j = 1; j <= nbiter; ++j) { |
1323 | Standard_Real fprm, lprm; |
1324 | Standard_Integer ifprm, ilprm; |
1325 | // |
1326 | if(bAvoidLineConstructor) { |
1327 | ifprm = 1; |
1328 | ilprm = theWLine->NbPnts(); |
1329 | } |
1330 | else { |
1331 | theLConstructor.Part(j, fprm, lprm); |
1332 | ifprm = (Standard_Integer)fprm; |
1333 | ilprm = (Standard_Integer)lprm; |
1334 | } |
1335 | |
1336 | Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S(); |
1337 | // |
1338 | for(i = 1; i <= nblines; i++) { |
1339 | if(anArrayOfLineType.Value(i) != 0) { |
1340 | continue; |
1341 | } |
1342 | const TColStd_ListOfInteger& aListOfIndex = anArrayOfLines.Value(i); |
1343 | const TColStd_ListOfInteger& aListOfFLIndex = anArrayOfLineEnds.Value(i); |
1344 | Standard_Boolean bhasfirstpoint = (aListOfFLIndex.Extent() == 2); |
1345 | Standard_Boolean bhaslastpoint = (aListOfFLIndex.Extent() == 2); |
1346 | |
1347 | if(!bhasfirstpoint && !aListOfFLIndex.IsEmpty()) { |
1348 | bhasfirstpoint = (i != 1); |
1349 | } |
1350 | |
1351 | if(!bhaslastpoint && !aListOfFLIndex.IsEmpty()) { |
1352 | bhaslastpoint = (i != nblines); |
1353 | } |
1354 | |
1355 | Standard_Integer iFirst = aListOfIndex.First(); |
1356 | Standard_Integer iLast = aListOfIndex.Last(); |
1357 | Standard_Boolean bIsFirstInside = ((ifprm >= iFirst) && (ifprm <= iLast)); |
1358 | Standard_Boolean bIsLastInside = ((ilprm >= iFirst) && (ilprm <= iLast)); |
1359 | |
1360 | if(!bIsFirstInside && !bIsLastInside) { |
1361 | if((ifprm < iFirst) && (ilprm > iLast)) { |
1362 | // append whole line, and boundaries if neccesary |
1363 | if(bhasfirstpoint) { |
1364 | pit = aListOfFLIndex.First(); |
1365 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); |
1366 | aLineOn2S->Add(aP); |
1367 | } |
1368 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); |
1369 | |
1370 | for(; anIt.More(); anIt.Next()) { |
1371 | pit = anIt.Value(); |
1372 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
1373 | aLineOn2S->Add(aP); |
1374 | } |
1375 | |
1376 | if(bhaslastpoint) { |
1377 | pit = aListOfFLIndex.Last(); |
1378 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); |
1379 | aLineOn2S->Add(aP); |
1380 | } |
1381 | |
1382 | // check end of split line (end is almost always) |
1383 | Standard_Integer aneighbour = i + 1; |
1384 | Standard_Boolean bIsEndOfLine = Standard_True; |
1385 | |
1386 | if(aneighbour <= nblines) { |
1387 | const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour); |
1388 | |
1389 | if((anArrayOfLineType.Value(aneighbour) != 0) && |
1390 | (aListOfNeighbourIndex.IsEmpty())) { |
1391 | bIsEndOfLine = Standard_False; |
1392 | } |
1393 | } |
1394 | |
1395 | if(bIsEndOfLine) { |
1396 | if(aLineOn2S->NbPoints() > 1) { |
1397 | Handle(IntPatch_WLine) aNewWLine = |
1398 | new IntPatch_WLine(aLineOn2S, Standard_False); |
1399 | theNewLines.Append(aNewWLine); |
1400 | } |
1401 | aLineOn2S = new IntSurf_LineOn2S(); |
1402 | } |
1403 | } |
1404 | continue; |
1405 | } |
1406 | // end if(!bIsFirstInside && !bIsLastInside) |
1407 | |
1408 | if(bIsFirstInside && bIsLastInside) { |
1409 | // append inside points between ifprm and ilprm |
1410 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); |
1411 | |
1412 | for(; anIt.More(); anIt.Next()) { |
1413 | pit = anIt.Value(); |
1414 | if((pit < ifprm) || (pit > ilprm)) |
1415 | continue; |
1416 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
1417 | aLineOn2S->Add(aP); |
1418 | } |
1419 | } |
1420 | else { |
1421 | |
1422 | if(bIsFirstInside) { |
1423 | // append points from ifprm to last point + boundary point |
1424 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); |
1425 | |
1426 | for(; anIt.More(); anIt.Next()) { |
1427 | pit = anIt.Value(); |
1428 | if(pit < ifprm) |
1429 | continue; |
1430 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
1431 | aLineOn2S->Add(aP); |
1432 | } |
1433 | |
1434 | if(bhaslastpoint) { |
1435 | pit = aListOfFLIndex.Last(); |
1436 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); |
1437 | aLineOn2S->Add(aP); |
1438 | } |
1439 | // check end of split line (end is almost always) |
1440 | Standard_Integer aneighbour = i + 1; |
1441 | Standard_Boolean bIsEndOfLine = Standard_True; |
1442 | |
1443 | if(aneighbour <= nblines) { |
1444 | const TColStd_ListOfInteger& aListOfNeighbourIndex = anArrayOfLines.Value(aneighbour); |
1445 | |
1446 | if((anArrayOfLineType.Value(aneighbour) != 0) && |
1447 | (aListOfNeighbourIndex.IsEmpty())) { |
1448 | bIsEndOfLine = Standard_False; |
1449 | } |
1450 | } |
1451 | |
1452 | if(bIsEndOfLine) { |
1453 | if(aLineOn2S->NbPoints() > 1) { |
1454 | Handle(IntPatch_WLine) aNewWLine = |
1455 | new IntPatch_WLine(aLineOn2S, Standard_False); |
1456 | theNewLines.Append(aNewWLine); |
1457 | } |
1458 | aLineOn2S = new IntSurf_LineOn2S(); |
1459 | } |
1460 | } |
1461 | // end if(bIsFirstInside) |
1462 | |
1463 | if(bIsLastInside) { |
1464 | // append points from first boundary point to ilprm |
1465 | if(bhasfirstpoint) { |
1466 | pit = aListOfFLIndex.First(); |
1467 | const IntSurf_PntOn2S& aP = aSeqOfPntOn2S->Value(pit); |
1468 | aLineOn2S->Add(aP); |
1469 | } |
1470 | TColStd_ListIteratorOfListOfInteger anIt(aListOfIndex); |
1471 | |
1472 | for(; anIt.More(); anIt.Next()) { |
1473 | pit = anIt.Value(); |
1474 | if(pit > ilprm) |
1475 | continue; |
1476 | const IntSurf_PntOn2S& aP = theWLine->Point(pit); |
1477 | aLineOn2S->Add(aP); |
1478 | } |
1479 | } |
1480 | //end if(bIsLastInside) |
1481 | } |
1482 | } |
1483 | |
1484 | if(aLineOn2S->NbPoints() > 1) { |
1485 | Handle(IntPatch_WLine) aNewWLine = |
1486 | new IntPatch_WLine(aLineOn2S, Standard_False); |
1487 | theNewLines.Append(aNewWLine); |
1488 | } |
1489 | } |
1490 | // Split wlines.end |
1491 | |
1492 | return Standard_True; |
1493 | } |
1494 | |
1495 | ///////////////////// end of DecompositionOfWLine /////////////////////// |
1496 | |
1497 | /////////////////////// ComputePurgedWLine ////////////////////////////// |
1498 | |
1499 | //========================================================================= |
1500 | // function : FillPointsHash |
1501 | // purpose : Fill points hash by input data. |
1502 | // Static subfunction in ComputePurgedWLine. |
1503 | //========================================================================= |
1504 | static void FillPointsHash(const Handle(IntPatch_WLine) &theWLine, |
1505 | NCollection_Array1<Standard_Integer> &thePointsHash) |
1506 | { |
1507 | // 1 - Delete point. |
1508 | // 0 - Store point. |
1509 | // -1 - Vertex point (not delete). |
1510 | Standard_Integer i, v; |
1511 | |
1512 | for(i = 1; i <= theWLine->NbPnts(); i++) |
1513 | thePointsHash.SetValue(i, 0); |
1514 | |
1515 | for(v = 1; v <= theWLine->NbVertex(); v++) |
1516 | { |
1517 | IntPatch_Point aVertex = theWLine->Vertex(v); |
1518 | Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine(); |
1519 | thePointsHash.SetValue(avertexindex, -1); |
1520 | } |
1521 | } |
1522 | |
1523 | //========================================================================= |
1524 | // function : MakeNewWLine |
1525 | // purpose : Makes new walking line according to the points hash |
1526 | // Static subfunction in ComputePurgedWLine and DeleteOuter. |
1527 | //========================================================================= |
1528 | static Handle(IntPatch_WLine) MakeNewWLine(const Handle(IntPatch_WLine) &theWLine, |
1529 | const NCollection_Array1<Standard_Integer> &thePointsHash) |
1530 | { |
1531 | Standard_Integer i; |
1532 | |
1533 | Handle(IntSurf_LineOn2S) aPurgedLineOn2S = new IntSurf_LineOn2S(); |
1534 | Handle(IntPatch_WLine) aLocalWLine = new IntPatch_WLine(aPurgedLineOn2S, Standard_False); |
1535 | Standard_Integer anOldLineIdx = 1, aVertexIdx = 1; |
1536 | for(i = 1; i <= thePointsHash.Upper(); i++) |
1537 | { |
1538 | if (thePointsHash(i) == 0) |
1539 | { |
1540 | // Store this point. |
1541 | aPurgedLineOn2S->Add(theWLine->Point(i)); |
1542 | anOldLineIdx++; |
1543 | } |
1544 | else if (thePointsHash(i) == -1) |
1545 | { |
1546 | // Add vertex. |
1547 | IntPatch_Point aVertex = theWLine->Vertex(aVertexIdx++); |
1548 | aVertex.SetParameter(anOldLineIdx++); |
1549 | aLocalWLine->AddVertex(aVertex); |
1550 | aPurgedLineOn2S->Add(theWLine->Point(i)); |
1551 | } |
1552 | } |
1553 | |
1554 | return aLocalWLine; |
1555 | } |
1556 | |
1557 | //========================================================================= |
1558 | // function : MovePoint |
1559 | // purpose : Move point into surface param space. No interpolation used |
1560 | // because walking algorithm should care for closeness to the param space. |
1561 | // Static subfunction in ComputePurgedWLine. |
1562 | //========================================================================= |
1563 | static void MovePoint(const Handle(GeomAdaptor_HSurface) &theS1, |
1564 | Standard_Real &U1, Standard_Real &V1) |
1565 | { |
1566 | if (U1 < theS1->FirstUParameter()) |
1567 | U1 = theS1->FirstUParameter(); |
1568 | |
1569 | if (U1 > theS1->LastUParameter()) |
1570 | U1 = theS1->LastUParameter(); |
1571 | |
1572 | if (V1 < theS1->FirstVParameter()) |
1573 | V1 = theS1->FirstVParameter(); |
1574 | |
1575 | if (V1 > theS1->LastVParameter()) |
1576 | V1 = theS1->LastVParameter(); |
1577 | } |
1578 | |
1579 | //========================================================================= |
1580 | // function : DeleteOuterPoints |
1581 | // purpose : Check and delete out of bounds points on walking line. |
1582 | // Static subfunction in ComputePurgedWLine. |
1583 | //========================================================================= |
1584 | static Handle(IntPatch_WLine) |
1585 | DeleteOuterPoints(const Handle(IntPatch_WLine) &theWLine, |
1586 | const Handle(GeomAdaptor_HSurface) &theS1, |
1587 | const Handle(GeomAdaptor_HSurface) &theS2, |
1588 | const Handle(Adaptor3d_TopolTool) &theDom1, |
1589 | const Handle(Adaptor3d_TopolTool) &theDom2) |
1590 | { |
1591 | Standard_Integer i; |
1592 | |
1593 | NCollection_Array1<Standard_Integer> aDelOuterPointsHash(1, theWLine->NbPnts()); |
1594 | FillPointsHash(theWLine, aDelOuterPointsHash); |
1595 | |
1596 | if (theS1->IsUPeriodic() || theS1->IsVPeriodic() || |
1597 | theS2->IsUPeriodic() || theS2->IsVPeriodic() ) |
1598 | return theWLine; |
1599 | |
1600 | gp_Pnt2d aPntOnF1, aPntOnF2; |
1601 | Standard_Real aX1, aY1, aX2, aY2; |
1602 | |
1603 | // Iterate over points in walking line and delete which are out of bounds. |
1604 | // Forward. |
1605 | Standard_Boolean isAllDeleted = Standard_True; |
1606 | Standard_Boolean aChangedFirst = Standard_False; |
1607 | Standard_Integer aFirstGeomIdx = 1; |
1608 | for(i = 1; i <= theWLine->NbPnts(); i++) |
1609 | { |
1610 | theWLine->Point(i).Parameters(aX1, aY1, aX2, aY2); |
1611 | aPntOnF1.SetCoord(aX1, aY1); |
1612 | aPntOnF2.SetCoord(aX2, aY2); |
1613 | |
1614 | TopAbs_State aState1 = theDom1->Classify(aPntOnF1, Precision::Confusion()); |
1615 | TopAbs_State aState2 = theDom2->Classify(aPntOnF2, Precision::Confusion()); |
1616 | |
1617 | if (aState1 == TopAbs_OUT || |
1618 | aState2 == TopAbs_OUT ) |
1619 | { |
1620 | aDelOuterPointsHash(i) = 1; |
1621 | aChangedFirst = Standard_True; |
1622 | } |
1623 | else |
1624 | { |
1625 | isAllDeleted = Standard_False; |
1626 | |
1627 | aFirstGeomIdx = Max (i - 1, 1); |
1628 | if (aDelOuterPointsHash(i) == -1) |
1629 | aFirstGeomIdx = i; // Use data what lies in (i) point / vertex. |
1630 | |
1631 | aDelOuterPointsHash(i) = -1; |
1632 | break; |
1633 | } |
1634 | } |
1635 | |
1636 | if (isAllDeleted) |
1637 | { |
1638 | // ALL points are out of bounds: |
1639 | // case boolean bcut_complex F5 and similar. |
1640 | return theWLine; |
1641 | } |
1642 | |
1643 | // Backward. |
1644 | Standard_Boolean aChangedLast = Standard_False; |
1645 | Standard_Integer aLastGeomIdx = theWLine->NbPnts(); |
1646 | for(i = theWLine->NbPnts(); i >= 1; i--) |
1647 | { |
1648 | theWLine->Point(i).Parameters(aX1, aY1, aX2, aY2); |
1649 | aPntOnF1.SetCoord(aX1, aY1); |
1650 | aPntOnF2.SetCoord(aX2, aY2); |
1651 | |
1652 | TopAbs_State aState1 = theDom1->Classify(aPntOnF1, Precision::Confusion()); |
1653 | TopAbs_State aState2 = theDom2->Classify(aPntOnF2, Precision::Confusion()); |
1654 | |
1655 | if (aState1 == TopAbs_OUT || |
1656 | aState2 == TopAbs_OUT ) |
1657 | { |
1658 | aDelOuterPointsHash(i) = 1; |
1659 | aChangedLast = Standard_True; // Move vertex to first good point |
1660 | } |
1661 | else |
1662 | { |
1663 | aLastGeomIdx = Min (i + 1, theWLine->NbPnts()); |
1664 | if (aDelOuterPointsHash(i) == -1) |
1665 | aLastGeomIdx = i; // Use data what lies in (i) point / vertex. |
1666 | |
1667 | aDelOuterPointsHash(i) = -1; |
1668 | break; |
1669 | } |
1670 | } |
1671 | |
1672 | if (!aChangedFirst && !aChangedLast) |
1673 | { |
1674 | // Nothing is done, return input. |
1675 | return theWLine; |
1676 | } |
1677 | |
1678 | // Build new line and modify geometry of necessary vertexes. |
1679 | Handle(IntPatch_WLine) aLocalWLine = MakeNewWLine(theWLine, aDelOuterPointsHash); |
1680 | |
1681 | if (aChangedFirst) |
1682 | { |
1683 | // Vertex geometry. |
1684 | IntPatch_Point aVertex = aLocalWLine->Vertex(1); |
1685 | aVertex.SetValue(theWLine->Point(aFirstGeomIdx).Value()); |
1686 | Standard_Real aU1, aU2, aV1, aV2; |
1687 | theWLine->Point(aFirstGeomIdx).Parameters(aU1, aV1, aU2, aV2); |
1688 | MovePoint(theS1, aU1, aV1); |
1689 | MovePoint(theS2, aU2, aV2); |
1690 | aVertex.SetParameters(aU1, aV1, aU2, aV2); |
1691 | aLocalWLine->Replace(1, aVertex); |
1692 | // Change point in walking line. |
1693 | aLocalWLine->SetPoint(1, aVertex); |
1694 | } |
1695 | |
1696 | if (aChangedLast) |
1697 | { |
1698 | // Vertex geometry. |
1699 | IntPatch_Point aVertex = aLocalWLine->Vertex(aLocalWLine->NbVertex()); |
1700 | aVertex.SetValue(theWLine->Point(aLastGeomIdx).Value()); |
1701 | Standard_Real aU1, aU2, aV1, aV2; |
1702 | theWLine->Point(aLastGeomIdx).Parameters(aU1, aV1, aU2, aV2); |
1703 | MovePoint(theS1, aU1, aV1); |
1704 | MovePoint(theS2, aU2, aV2); |
1705 | aVertex.SetParameters(aU1, aV1, aU2, aV2); |
1706 | aLocalWLine->Replace(aLocalWLine->NbVertex(), aVertex); |
1707 | // Change point in walking line. |
1708 | aLocalWLine->SetPoint(aLocalWLine->NbPnts(), aVertex); |
1709 | } |
1710 | |
1711 | |
1712 | return aLocalWLine; |
1713 | } |
1714 | |
1715 | //========================================================================= |
1716 | // function : IsInsideIn2d |
1717 | // purpose : Check if aNextPnt lies inside of tube build on aBasePnt and aBaseVec. |
1718 | // In 2d space. Static subfunction in DeleteByTube. |
1719 | //========================================================================= |
1720 | static Standard_Boolean IsInsideIn2d(const gp_Pnt2d& aBasePnt, |
1721 | const gp_Vec2d& aBaseVec, |
1722 | const gp_Pnt2d& aNextPnt, |
1723 | const Standard_Real aSquareMaxDist) |
1724 | { |
1725 | gp_Vec2d aVec2d(aBasePnt, aNextPnt); |
1726 | |
1727 | //d*d = (basevec^(nextpnt-basepnt))**2 / basevec**2 |
1728 | Standard_Real aCross = aVec2d.Crossed(aBaseVec); |
1729 | Standard_Real aSquareDist = aCross * aCross |
1730 | / aBaseVec.SquareMagnitude(); |
1731 | |
1732 | return (aSquareDist <= aSquareMaxDist); |
1733 | } |
1734 | |
1735 | //========================================================================= |
1736 | // function : IsInsideIn3d |
1737 | // purpose : Check if aNextPnt lies inside of tube build on aBasePnt and aBaseVec. |
1738 | // In 3d space. Static subfunction in DeleteByTube. |
1739 | //========================================================================= |
1740 | static Standard_Boolean IsInsideIn3d(const gp_Pnt& aBasePnt, |
1741 | const gp_Vec& aBaseVec, |
1742 | const gp_Pnt& aNextPnt, |
1743 | const Standard_Real aSquareMaxDist) |
1744 | { |
1745 | gp_Vec aVec(aBasePnt, aNextPnt); |
1746 | |
1747 | //d*d = (basevec^(nextpnt-basepnt))**2 / basevec**2 |
1748 | Standard_Real aSquareDist = aVec.CrossSquareMagnitude(aBaseVec) |
1749 | / aBaseVec.SquareMagnitude(); |
1750 | |
1751 | return (aSquareDist <= aSquareMaxDist); |
1752 | } |
1753 | |
1754 | static const Standard_Integer aMinNbBadDistr = 15; |
1755 | static const Standard_Integer aNbSingleBezier = 30; |
1756 | |
1757 | //========================================================================= |
1758 | // function : DeleteByTube |
1759 | // purpose : Check and delete points using tube criteria. |
1760 | // Static subfunction in ComputePurgedWLine. |
1761 | //========================================================================= |
1762 | static Handle(IntPatch_WLine) |
1763 | DeleteByTube(const Handle(IntPatch_WLine) &theWLine, |
1764 | const Handle(GeomAdaptor_HSurface) &theS1, |
1765 | const Handle(GeomAdaptor_HSurface) &theS2) |
1766 | { |
1767 | // III: Check points for tube criteria: |
1768 | // Workaround to handle case of small amount points after purge. |
1769 | // Test "boolean boptuc_complex B5" and similar. |
1770 | Standard_Integer aNbPnt = 0 , i; |
1771 | |
1772 | if (theWLine->NbPnts() <= 2) |
1773 | return theWLine; |
1774 | |
1775 | NCollection_Array1<Standard_Integer> aNewPointsHash(1, theWLine->NbPnts()); |
1776 | FillPointsHash(theWLine, aNewPointsHash); |
1777 | |
1778 | // Inital computations. |
1779 | Standard_Real UonS1[3], VonS1[3], UonS2[3], VonS2[3]; |
1780 | theWLine->Point(1).ParametersOnS1(UonS1[0], VonS1[0]); |
1781 | theWLine->Point(2).ParametersOnS1(UonS1[1], VonS1[1]); |
1782 | theWLine->Point(1).ParametersOnS2(UonS2[0], VonS2[0]); |
1783 | theWLine->Point(2).ParametersOnS2(UonS2[1], VonS2[1]); |
1784 | |
1785 | gp_Pnt2d aBase2dPnt1(UonS1[0], VonS1[0]); |
1786 | gp_Pnt2d aBase2dPnt2(UonS2[0], VonS2[0]); |
1787 | gp_Vec2d aBase2dVec1(UonS1[1] - UonS1[0], VonS1[1] - VonS1[0]); |
1788 | gp_Vec2d aBase2dVec2(UonS2[1] - UonS2[0], VonS2[1] - VonS2[0]); |
1789 | gp_Pnt aBase3dPnt = theWLine->Point(1).Value(); |
1790 | gp_Vec aBase3dVec(theWLine->Point(1).Value(), theWLine->Point(2).Value()); |
1791 | |
1792 | // Choose base tolerance and scale it to pipe algorithm. |
1793 | const Standard_Real aBaseTolerance = Precision::Approximation(); |
1794 | Standard_Real aResS1Tol = Min(theS1->UResolution(aBaseTolerance), |
1795 | theS1->VResolution(aBaseTolerance)); |
1796 | Standard_Real aResS2Tol = Min(theS2->UResolution(aBaseTolerance), |
1797 | theS2->VResolution(aBaseTolerance)); |
1798 | Standard_Real aTol1 = aResS1Tol * aResS1Tol; |
1799 | Standard_Real aTol2 = aResS2Tol * aResS2Tol; |
1800 | Standard_Real aTol3d = aBaseTolerance * aBaseTolerance; |
1801 | |
1802 | const Standard_Real aLimitCoeff = 0.99 * 0.99; |
1803 | for(i = 3; i <= theWLine->NbPnts(); i++) |
1804 | { |
1805 | Standard_Boolean isDeleteState = Standard_False; |
1806 | |
1807 | theWLine->Point(i).ParametersOnS1(UonS1[2], VonS1[2]); |
1808 | theWLine->Point(i).ParametersOnS2(UonS2[2], VonS2[2]); |
1809 | gp_Pnt2d aPnt2dOnS1(UonS1[2], VonS1[2]); |
1810 | gp_Pnt2d aPnt2dOnS2(UonS2[2], VonS2[2]); |
1811 | const gp_Pnt& aPnt3d = theWLine->Point(i).Value(); |
1812 | |
1813 | if (aNewPointsHash(i - 1) != - 1 && |
1814 | IsInsideIn2d(aBase2dPnt1, aBase2dVec1, aPnt2dOnS1, aTol1) && |
1815 | IsInsideIn2d(aBase2dPnt2, aBase2dVec2, aPnt2dOnS2, aTol2) && |
1816 | IsInsideIn3d(aBase3dPnt, aBase3dVec, aPnt3d, aTol3d) ) |
1817 | { |
1818 | // Handle possible uneven parametrization on one of 2d subspaces. |
1819 | // Delete point only when expected lengths are close to each other (aLimitCoeff). |
1820 | // Example: |
1821 | // c2d1 - line |
1822 | // c3d - line |
1823 | // c2d2 - geometrically line, but have uneven parametrization -> c2d2 is bspline. |
1824 | gp_XY aPntOnS1[2]= { gp_XY(UonS1[1] - UonS1[0], VonS1[1] - VonS1[0]) |
1825 | , gp_XY(UonS1[2] - UonS1[1], VonS1[2] - VonS1[1])}; |
1826 | gp_XY aPntOnS2[2]= { gp_XY(UonS2[1] - UonS2[0], VonS2[1] - VonS2[0]) |
1827 | , gp_XY(UonS2[2] - UonS2[1], VonS2[2] - VonS2[1])}; |
1828 | |
1829 | Standard_Real aStepOnS1 = aPntOnS1[0].SquareModulus() / aPntOnS1[1].SquareModulus(); |
1830 | Standard_Real aStepOnS2 = aPntOnS2[0].SquareModulus() / aPntOnS2[1].SquareModulus(); |
1831 | |
1832 | Standard_Real aStepCoeff = Min(aStepOnS1, aStepOnS2) / Max(aStepOnS1, aStepOnS2); |
1833 | |
1834 | if (aStepCoeff > aLimitCoeff) |
1835 | { |
1836 | // Set hash flag to "Delete" state. |
1837 | isDeleteState = Standard_True; |
1838 | aNewPointsHash.SetValue(i - 1, 1); |
1839 | |
1840 | // Change middle point. |
1841 | UonS1[1] = UonS1[2]; |
1842 | UonS2[1] = UonS2[2]; |
1843 | VonS1[1] = VonS1[2]; |
1844 | VonS2[1] = VonS2[2]; |
1845 | } |
1846 | } |
1847 | |
1848 | if (!isDeleteState) |
1849 | { |
1850 | // Compute new pipe parameters. |
1851 | UonS1[0] = UonS1[1]; |
1852 | VonS1[0] = VonS1[1]; |
1853 | UonS2[0] = UonS2[1]; |
1854 | VonS2[0] = VonS2[1]; |
1855 | |
1856 | UonS1[1] = UonS1[2]; |
1857 | VonS1[1] = VonS1[2]; |
1858 | UonS2[1] = UonS2[2]; |
1859 | VonS2[1] = VonS2[2]; |
1860 | |
1861 | aBase2dPnt1.SetCoord(UonS1[0], VonS1[0]); |
1862 | aBase2dPnt2.SetCoord(UonS2[0], VonS2[0]); |
1863 | aBase2dVec1.SetCoord(UonS1[1] - UonS1[0], VonS1[1] - VonS1[0]); |
1864 | aBase2dVec2.SetCoord(UonS2[1] - UonS2[0], VonS2[1] - VonS2[0]); |
1865 | aBase3dPnt = theWLine->Point(i - 1).Value(); |
1866 | aBase3dVec = gp_Vec(theWLine->Point(i - 1).Value(), theWLine->Point(i).Value()); |
1867 | |
1868 | aNbPnt++; |
1869 | } |
1870 | } |
1871 | |
1872 | // Workaround to handle case of small amount of points after purge. |
1873 | // Test "boolean boptuc_complex B5" and similar. |
1874 | // This is possible since there are at least two points. |
1875 | if (aNewPointsHash(1) == -1 && |
1876 | aNewPointsHash(2) == -1 && |
1877 | aNbPnt <= 3) |
1878 | { |
1879 | // Delete first. |
1880 | aNewPointsHash(1) = 1; |
1881 | } |
1882 | if (aNewPointsHash(theWLine->NbPnts() - 1) == -1 && |
1883 | aNewPointsHash(theWLine->NbPnts() ) == -1 && |
1884 | aNbPnt <= 3) |
1885 | { |
1886 | // Delete last. |
1887 | aNewPointsHash(theWLine->NbPnts()) = 1; |
1888 | } |
1889 | |
1890 | // Purgre when too small amount of points left. |
1891 | if (aNbPnt <= 2) |
1892 | { |
1893 | for(i = aNewPointsHash.Lower(); i <= aNewPointsHash.Upper(); i++) |
1894 | { |
1895 | if (aNewPointsHash(i) != -1) |
1896 | { |
1897 | aNewPointsHash(i) = 1; |
1898 | } |
1899 | } |
1900 | } |
1901 | |
1902 | // Handle possible bad distribution of points, |
1903 | // which are will converted into one single bezier curve (less than 30 points). |
1904 | // Make distribution more even: |
1905 | // max step will be nearly to 0.1 of param distance. |
1906 | if (aNbPnt + 2 > aMinNbBadDistr && |
1907 | aNbPnt + 2 < aNbSingleBezier ) |
1908 | { |
1909 | for(Standard_Integer anIdx = 1; anIdx <= 8; anIdx++) |
1910 | { |
1911 | Standard_Integer aHashIdx = |
1912 | Standard_Integer(anIdx * theWLine->NbPnts() / 9); |
1913 | |
1914 | //Store this point. |
1915 | aNewPointsHash(aHashIdx) = 0; |
1916 | } |
1917 | } |
1918 | |
1919 | return MakeNewWLine(theWLine, aNewPointsHash); |
1920 | } |
1921 | |
1922 | //========================================================================= |
1923 | // function : ComputePurgedWLine |
1924 | // purpose : |
1925 | //========================================================================= |
1926 | Handle(IntPatch_WLine) IntTools_WLineTool:: |
1927 | ComputePurgedWLine(const Handle(IntPatch_WLine) &theWLine, |
1928 | const Handle(GeomAdaptor_HSurface) &theS1, |
1929 | const Handle(GeomAdaptor_HSurface) &theS2, |
1930 | const Handle(Adaptor3d_TopolTool) &theDom1, |
1931 | const Handle(Adaptor3d_TopolTool) &theDom2) |
1932 | { |
1933 | Standard_Integer i, k, v, nb, nbvtx; |
1934 | Handle(IntPatch_WLine) aResult; |
1935 | nbvtx = theWLine->NbVertex(); |
1936 | nb = theWLine->NbPnts(); |
1937 | if (nb==2) |
1938 | { |
1939 | const IntSurf_PntOn2S& p1 = theWLine->Point(1); |
1940 | const IntSurf_PntOn2S& p2 = theWLine->Point(2); |
1941 | if(p1.Value().IsEqual(p2.Value(), gp::Resolution())) |
1942 | return aResult; |
1943 | } |
1944 | |
1945 | Handle(IntPatch_WLine) aLocalWLine; |
1946 | Handle(IntPatch_WLine) aTmpWLine = theWLine; |
1947 | Handle(IntSurf_LineOn2S) aLineOn2S = new IntSurf_LineOn2S(); |
1948 | aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False); |
1949 | for(i = 1; i <= nb; i++) |
1950 | aLineOn2S->Add(theWLine->Point(i)); |
1951 | |
1952 | for(v = 1; v <= nbvtx; v++) |
1953 | aLocalWLine->AddVertex(theWLine->Vertex(v)); |
1954 | |
1955 | // I: Delete equal points |
1956 | for(i = 1; i <= aLineOn2S->NbPoints(); i++) |
1957 | { |
1958 | Standard_Integer aStartIndex = i + 1; |
1959 | Standard_Integer anEndIndex = i + 5; |
1960 | nb = aLineOn2S->NbPoints(); |
1961 | anEndIndex = (anEndIndex > nb) ? nb : anEndIndex; |
1962 | |
1963 | if((aStartIndex > nb) || (anEndIndex <= 1)) |
1964 | continue; |
1965 | |
1966 | k = aStartIndex; |
1967 | |
1968 | while(k <= anEndIndex) |
1969 | { |
1970 | if(i != k) |
1971 | { |
1972 | IntSurf_PntOn2S p1 = aLineOn2S->Value(i); |
1973 | IntSurf_PntOn2S p2 = aLineOn2S->Value(k); |
1974 | |
1975 | Standard_Real UV[8]; |
1976 | p1.Parameters(UV[0], UV[1], UV[2], UV[3]); |
1977 | p2.Parameters(UV[4], UV[5], UV[6], UV[7]); |
1978 | |
1979 | Standard_Real aMax = Abs(UV[0]); |
1980 | for(Standard_Integer anIdx = 1; anIdx < 8; anIdx++) |
1981 | { |
1982 | if (aMax < Abs(UV[anIdx])) |
1983 | aMax = Abs(UV[anIdx]); |
1984 | } |
1985 | |
1986 | if(p1.Value().IsEqual(p2.Value(), gp::Resolution()) || |
1987 | Abs(UV[0] - UV[4]) + Abs(UV[1] - UV[5]) < 1.0e-16 * aMax || |
1988 | Abs(UV[2] - UV[6]) + Abs(UV[3] - UV[7]) < 1.0e-16 * aMax ) |
1989 | { |
1990 | aTmpWLine = aLocalWLine; |
1991 | aLocalWLine = new IntPatch_WLine(aLineOn2S, Standard_False); |
1992 | |
1993 | for(v = 1; v <= aTmpWLine->NbVertex(); v++) |
1994 | { |
1995 | IntPatch_Point aVertex = aTmpWLine->Vertex(v); |
1996 | Standard_Integer avertexindex = (Standard_Integer)aVertex.ParameterOnLine(); |
1997 | |
1998 | if(avertexindex >= k) |
1999 | { |
2000 | aVertex.SetParameter(aVertex.ParameterOnLine() - 1.); |
2001 | } |
2002 | aLocalWLine->AddVertex(aVertex); |
2003 | } |
2004 | aLineOn2S->RemovePoint(k); |
2005 | anEndIndex--; |
2006 | continue; |
2007 | } |
2008 | } |
2009 | k++; |
2010 | } |
2011 | } |
2012 | |
2013 | if (aLineOn2S->NbPoints() <= 2) |
2014 | { |
2015 | if (aLineOn2S->NbPoints() == 2) |
2016 | return aLocalWLine; |
2017 | else |
2018 | return aResult; |
2019 | } |
2020 | |
2021 | // Avoid purge in case of C0 continuity: |
2022 | // Intersection approximator may produce invalid curve after purge, example: |
2023 | // bugs modalg_5 bug24731. |
2024 | // Do not run purger when base number of points is too small. |
2025 | if (theS1->UContinuity() == GeomAbs_C0 || |
2026 | theS1->VContinuity() == GeomAbs_C0 || |
2027 | theS2->UContinuity() == GeomAbs_C0 || |
2028 | theS2->VContinuity() == GeomAbs_C0 || |
2029 | nb < aNbSingleBezier) |
2030 | { |
2031 | return aLocalWLine; |
2032 | } |
2033 | |
2034 | // II: Delete out of borders points. |
2035 | Handle(IntPatch_WLine) aLocalWLineOuter = |
2036 | DeleteOuterPoints(aLocalWLine, theS1, theS2, theDom1, theDom2); |
2037 | |
2038 | /// III: Delete points by tube criteria. |
2039 | Handle(IntPatch_WLine) aLocalWLineTube = |
2040 | DeleteByTube(aLocalWLineOuter, theS1, theS2); |
2041 | |
2042 | if(aLocalWLineTube->NbPnts() > 1) |
2043 | { |
2044 | aResult = aLocalWLineTube; |
2045 | } |
2046 | return aResult; |
2047 | } |
2048 | |
2049 | /////////////////////// end of ComputePurgedWLine /////////////////////// |