Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 2001-02-26 |
2 | // Created by: Peter KURNEV | |
3 | // Copyright (c) 2001-2012 OPEN CASCADE SAS | |
7fd59977 | 4 | // |
b311480e | 5 | // The content of this file is subject to the Open CASCADE Technology Public |
6 | // License Version 6.5 (the "License"). You may not use the content of this file | |
7 | // except in compliance with the License. Please obtain a copy of the License | |
8 | // at http://www.opencascade.org and read it completely before using this file. | |
9 | // | |
10 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its | |
11 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. | |
12 | // | |
13 | // The Original Code and all software distributed under the License is | |
14 | // distributed on an "AS IS" basis, without warranty of any kind, and the | |
15 | // Initial Developer hereby disclaims all such warranties, including without | |
16 | // limitation, any warranties of merchantability, fitness for a particular | |
17 | // purpose or non-infringement. Please see the License for the specific terms | |
18 | // and conditions governing the rights and limitations under the License. | |
19 | ||
7fd59977 | 20 | |
21 | #include <IntTools_EdgeFace.ixx> | |
22 | ||
23 | ||
24 | ||
25 | #include <IntTools_CArray1OfReal.hxx> | |
26 | #include <IntTools.hxx> | |
27 | #include <IntTools_CArray1OfInteger.hxx> | |
28 | #include <IntTools_Range.hxx> | |
29 | #include <IntTools_Tools.hxx> | |
30 | #include <IntTools_Array1OfRange.hxx> | |
31 | #include <IntTools_QuickSortRange.hxx> | |
32 | #include <IntTools_CompareRange.hxx> | |
33 | #include <IntTools_CommonPrt.hxx> | |
34 | #include <IntTools_Root.hxx> | |
35 | #include <IntTools_BeanFaceIntersector.hxx> | |
4e57c75e | 36 | #include <BOPInt_Context.hxx> |
7fd59977 | 37 | |
38 | #include <BRep_Tool.hxx> | |
39 | ||
40 | #include <GeomAdaptor_Surface.hxx> | |
41 | #include <GeomAdaptor_Curve.hxx> | |
42 | ||
43 | #include <Geom_Surface.hxx> | |
44 | #include <Geom_Curve.hxx> | |
45 | ||
46 | #include <GeomAPI_ProjectPointOnSurf.hxx> | |
47 | ||
48 | #include <Precision.hxx> | |
49 | ||
50 | #include <Bnd_Box.hxx> | |
51 | #include <BndLib_AddSurface.hxx> | |
52 | ||
53 | #include <gp_Cylinder.hxx> | |
54 | #include <gp_Ax1.hxx> | |
55 | #include <gp_Lin.hxx> | |
56 | #include <gp_Cone.hxx> | |
57 | #include <gp_Torus.hxx> | |
58 | #include <gp_Circ.hxx> | |
59 | #include <gp_Pln.hxx> | |
60 | ||
61 | ||
62 | #include <Extrema_ExtCS.hxx> | |
63 | #include <Extrema_POnCurv.hxx> | |
64 | #include <Extrema_POnSurf.hxx> | |
65 | ||
66 | // modified by NIZHNY-MKK Thu Jul 21 11:35:59 2005 | |
67 | #include <IntCurveSurface_HInter.hxx> | |
68 | #include <GeomAdaptor_HCurve.hxx> | |
69 | #include <GeomAdaptor_HSurface.hxx> | |
70 | #include <IntCurveSurface_IntersectionPoint.hxx> | |
71 | ||
72 | #ifdef WNT | |
73 | #pragma warning ( disable : 4101 ) | |
74 | #endif | |
75 | ||
76 | static | |
77 | Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& , | |
78 | const BRepAdaptor_Surface& ); | |
79 | static | |
80 | Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve , | |
81 | const BRepAdaptor_Surface& aSurface); | |
82 | static | |
83 | Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret, | |
84 | const BRepAdaptor_Curve& aCurve , | |
85 | const BRepAdaptor_Surface& aSurface); | |
86 | ||
87 | //======================================================================= | |
88 | //function : IntTools_EdgeFace::IntTools_EdgeFace | |
89 | //purpose : | |
90 | //======================================================================= | |
91 | IntTools_EdgeFace::IntTools_EdgeFace() | |
92 | { | |
93 | myTolE=1.e-7; | |
94 | myTolF=1.e-7; | |
95 | myDiscret=30; | |
96 | myEpsT =1e-12; | |
97 | myEpsNull=1e-12; | |
98 | myDeflection=0.01; | |
99 | myIsDone=Standard_False; | |
100 | myErrorStatus=1; | |
101 | myParallel=Standard_False; | |
102 | myPar1=0.; | |
4f189102 P |
103 | } |
104 | //======================================================================= | |
105 | //function : SetContext | |
106 | //purpose : | |
107 | //======================================================================= | |
4e57c75e | 108 | void IntTools_EdgeFace::SetContext(const Handle(BOPInt_Context)& theContext) |
4f189102 P |
109 | { |
110 | myContext = theContext; | |
7fd59977 | 111 | } |
112 | ||
4f189102 P |
113 | //======================================================================= |
114 | //function : Context | |
115 | //purpose : | |
116 | //======================================================================= | |
4e57c75e | 117 | const Handle(BOPInt_Context)& IntTools_EdgeFace::Context()const |
4f189102 P |
118 | { |
119 | return myContext; | |
120 | } | |
7fd59977 | 121 | //======================================================================= |
122 | //function : SetEdge | |
123 | //purpose : | |
124 | //======================================================================= | |
125 | void IntTools_EdgeFace::SetEdge(const TopoDS_Edge& anEdge) | |
126 | { | |
127 | myEdge=anEdge; | |
128 | } | |
129 | ||
130 | //======================================================================= | |
131 | //function : SetFace | |
132 | //purpose : | |
133 | //======================================================================= | |
134 | void IntTools_EdgeFace::SetFace(const TopoDS_Face& aFace) | |
135 | { | |
136 | myFace=aFace; | |
137 | } | |
138 | ||
139 | //======================================================================= | |
140 | //function : SetTolE | |
141 | //purpose : | |
142 | //======================================================================= | |
143 | void IntTools_EdgeFace::SetTolE(const Standard_Real aTol) | |
144 | { | |
145 | myTolE=aTol; | |
146 | } | |
147 | //======================================================================= | |
148 | //function : SetTolF | |
149 | //purpose : | |
150 | //======================================================================= | |
151 | void IntTools_EdgeFace::SetTolF(const Standard_Real aTol) | |
152 | { | |
153 | myTolF=aTol; | |
154 | } | |
155 | ||
156 | //======================================================================= | |
157 | //function : SetDiscretize | |
158 | //purpose : | |
159 | //======================================================================= | |
160 | void IntTools_EdgeFace::SetDiscretize(const Standard_Integer aDiscret) | |
161 | { | |
162 | myDiscret=aDiscret; | |
163 | } | |
164 | //======================================================================= | |
165 | //function : SetDeflection | |
166 | //purpose : | |
167 | //======================================================================= | |
168 | void IntTools_EdgeFace::SetDeflection(const Standard_Real aDefl) | |
169 | { | |
170 | myDeflection=aDefl; | |
171 | } | |
172 | //======================================================================= | |
173 | //function : SetEpsilonT | |
174 | //purpose : | |
175 | //======================================================================= | |
176 | void IntTools_EdgeFace::SetEpsilonT(const Standard_Real anEpsT) | |
177 | { | |
178 | myEpsT=anEpsT; | |
179 | } | |
180 | //======================================================================= | |
181 | //function : SetEpsilonNull | |
182 | //purpose : | |
183 | //======================================================================= | |
184 | void IntTools_EdgeFace::SetEpsilonNull(const Standard_Real anEpsNull) | |
185 | { | |
186 | myEpsNull=anEpsNull; | |
187 | } | |
188 | ||
189 | //======================================================================= | |
190 | //function : SetRange | |
191 | //purpose : | |
192 | //======================================================================= | |
193 | void IntTools_EdgeFace::SetRange(const Standard_Real aFirst, | |
194 | const Standard_Real aLast) | |
195 | { | |
196 | myRange.SetFirst (aFirst); | |
197 | myRange.SetLast (aLast); | |
198 | } | |
199 | ||
200 | //======================================================================= | |
201 | //function : SetRange | |
202 | //purpose : | |
203 | //======================================================================= | |
204 | void IntTools_EdgeFace::SetRange(const IntTools_Range& aRange) | |
205 | { | |
206 | myRange.SetFirst (aRange.First()); | |
207 | myRange.SetLast (aRange.Last()); | |
208 | } | |
209 | //======================================================================= | |
210 | //function : IsDone | |
211 | //purpose : | |
212 | //======================================================================= | |
4f189102 | 213 | Standard_Boolean IntTools_EdgeFace::IsDone()const |
7fd59977 | 214 | { |
215 | return myIsDone; | |
216 | } | |
217 | //======================================================================= | |
218 | //function : ErrorStatus | |
219 | //purpose : | |
220 | //======================================================================= | |
4f189102 | 221 | Standard_Integer IntTools_EdgeFace::ErrorStatus()const |
7fd59977 | 222 | { |
223 | return myErrorStatus; | |
224 | } | |
225 | //======================================================================= | |
226 | //function : CommonParts | |
227 | //purpose : | |
228 | //======================================================================= | |
4f189102 | 229 | const IntTools_SequenceOfCommonPrts& IntTools_EdgeFace::CommonParts() const |
7fd59977 | 230 | { |
231 | return mySeqOfCommonPrts; | |
232 | } | |
233 | //======================================================================= | |
234 | //function : Range | |
235 | //purpose : | |
236 | //======================================================================= | |
4f189102 | 237 | const IntTools_Range& IntTools_EdgeFace::Range() const |
7fd59977 | 238 | { |
239 | return myRange; | |
240 | } | |
241 | ||
242 | //======================================================================= | |
243 | //function : CheckData | |
244 | //purpose : | |
245 | //======================================================================= | |
4f189102 | 246 | void IntTools_EdgeFace::CheckData() |
7fd59977 | 247 | { |
248 | if (BRep_Tool::Degenerated(myEdge)) { | |
249 | myErrorStatus=2; | |
250 | } | |
251 | if (!BRep_Tool::IsGeometric(myEdge)) { | |
252 | myErrorStatus=3; | |
253 | } | |
254 | } | |
7fd59977 | 255 | //======================================================================= |
256 | //function : Prepare | |
257 | //purpose : | |
258 | //======================================================================= | |
259 | void IntTools_EdgeFace::Prepare() | |
260 | { | |
261 | Standard_Integer pri; | |
262 | IntTools_CArray1OfReal aPars; | |
263 | ||
264 | // | |
265 | // 1.Prepare Curve's data and Surface's data | |
266 | myC.Initialize(myEdge); | |
267 | GeomAbs_CurveType aCurveType; | |
268 | aCurveType=myC.GetType(); | |
269 | // | |
270 | // 2.Prepare myCriteria | |
271 | if (aCurveType==GeomAbs_BSplineCurve|| | |
272 | aCurveType==GeomAbs_BezierCurve) { | |
273 | myCriteria=1.5*myTolE+myTolF; | |
274 | } | |
275 | else { | |
276 | myCriteria=myTolE+myTolF; | |
277 | } | |
278 | // 2.a myTmin, myTmax | |
279 | myTmin=myRange.First(); | |
280 | myTmax=myRange.Last(); | |
281 | // 2.b myFClass2d | |
282 | myS.Initialize (myFace,Standard_True); | |
283 | myFClass2d.Init(myFace, 1.e-6); | |
284 | // | |
285 | // 2.c Prepare adaptive myDiscret | |
286 | myDiscret=AdaptiveDiscret(myDiscret, myC, myS); | |
287 | // | |
288 | // | |
289 | // 3.Prepare myPars | |
290 | pri = IntTools::PrepareArgs(myC, myTmax, myTmin, myDiscret, myDeflection, aPars); | |
291 | if (pri) { | |
292 | myErrorStatus=6; | |
293 | return; | |
294 | } | |
295 | // 4. | |
296 | //ProjectableRanges | |
297 | Standard_Integer i, iProj, aNb, aNbProj, ind0, ind1; | |
298 | Standard_Real t0, t1, tRoot; | |
299 | ||
300 | // | |
301 | // Table of Projection's function values | |
302 | aNb=aPars.Length(); | |
303 | IntTools_CArray1OfInteger anArrProjectability; | |
304 | anArrProjectability.Resize(aNb); | |
305 | ||
306 | for (iProj=0, i=0; i<aNb; i++) { | |
307 | t0=aPars(i); | |
308 | aNbProj=IsProjectable (t0); | |
309 | ||
310 | anArrProjectability(i)=0; | |
311 | if (aNbProj) { | |
312 | anArrProjectability(i)=1; | |
313 | iProj++; | |
314 | } | |
315 | } | |
316 | // | |
317 | // Checking | |
318 | if (!iProj ) { | |
319 | myErrorStatus=7; | |
320 | return; | |
321 | } | |
322 | ||
323 | // | |
324 | // Projectable Ranges | |
325 | IntTools_Range aRange; | |
326 | ||
327 | ind0=anArrProjectability(0); | |
328 | if (ind0) { | |
329 | t0=aPars(0); | |
330 | aRange.SetFirst(t0); | |
331 | } | |
332 | ||
333 | for(i=1; i<aNb; i++) { | |
334 | ind1=anArrProjectability(i); | |
335 | t0=aPars(i-1); | |
336 | t1=aPars(i); | |
337 | ||
338 | if (i==(aNb-1)) { | |
339 | if (ind1 && ind0) { | |
340 | aRange.SetLast(t1); | |
341 | myProjectableRanges.Append(aRange); | |
342 | } | |
343 | if (ind1 && !ind0) { | |
344 | FindProjectableRoot(t0, t1, ind0, ind1, tRoot); | |
345 | aRange.SetFirst(tRoot); | |
346 | aRange.SetLast(t1); | |
347 | myProjectableRanges.Append(aRange); | |
348 | } | |
349 | // | |
350 | if (ind0 && !ind1) { | |
351 | FindProjectableRoot(t0, t1, ind0, ind1, tRoot); | |
352 | aRange.SetLast(tRoot); | |
353 | myProjectableRanges.Append(aRange); | |
354 | } | |
355 | // | |
356 | break; | |
357 | } | |
358 | ||
359 | if (ind0 != ind1) { | |
360 | FindProjectableRoot(t0, t1, ind0, ind1, tRoot); | |
361 | ||
362 | if (ind0 && !ind1) { | |
363 | aRange.SetLast(tRoot); | |
364 | myProjectableRanges.Append(aRange); | |
365 | } | |
366 | else { | |
367 | aRange.SetFirst(tRoot); | |
368 | } | |
369 | } // if (ind0 != ind1) | |
370 | ind0=ind1; | |
371 | } // for(i=1; i<aNb; i++) { | |
372 | } | |
373 | ||
374 | //======================================================================= | |
375 | //function : FindProjectableRoot | |
376 | //purpose : | |
377 | //======================================================================= | |
378 | void IntTools_EdgeFace::FindProjectableRoot (const Standard_Real tt1, | |
379 | const Standard_Real tt2, | |
380 | const Standard_Integer ff1, | |
381 | const Standard_Integer ff2, | |
382 | Standard_Real& tRoot) | |
383 | { | |
384 | Standard_Real tm, t1, t2, aEpsT; | |
385 | Standard_Integer anIsProj1, anIsProj2, anIsProjm; | |
386 | aEpsT=0.5*myEpsT; | |
387 | // | |
388 | // Root is inside [tt1, tt2] | |
389 | t1=tt1; | |
390 | t2=tt2; | |
391 | anIsProj1=ff1; | |
392 | anIsProj2=ff2; | |
393 | ||
302f96fb | 394 | for(;;) { |
7fd59977 | 395 | if (fabs(t1-t2) < aEpsT) { |
396 | tRoot=(anIsProj1) ? t1 : t2; | |
397 | return; | |
398 | } | |
399 | tm=.5*(t1+t2); | |
400 | anIsProjm=IsProjectable(tm); | |
401 | ||
402 | if (anIsProjm != anIsProj1) { | |
403 | t2=tm; | |
404 | anIsProj2=anIsProjm; | |
405 | } | |
406 | else { | |
407 | t1=tm; | |
408 | anIsProj1=anIsProjm; | |
409 | } | |
410 | } | |
411 | } | |
412 | //======================================================================= | |
413 | //function : IsProjectable | |
414 | //purpose : | |
415 | //======================================================================= | |
66993778 | 416 | Standard_Boolean IntTools_EdgeFace::IsProjectable(const Standard_Real aT) const |
7fd59977 | 417 | { |
66993778 | 418 | Standard_Boolean bFlag; |
419 | gp_Pnt aPC; | |
7fd59977 | 420 | // |
66993778 | 421 | myC.D0(aT, aPC); |
422 | bFlag=myContext->IsValidPointForFace(aPC, myFace, myCriteria); | |
7fd59977 | 423 | // |
7fd59977 | 424 | return bFlag; |
425 | } | |
7fd59977 | 426 | //======================================================================= |
427 | //function : DistanceFunction | |
428 | //purpose : | |
429 | //======================================================================= | |
66993778 | 430 | Standard_Real IntTools_EdgeFace::DistanceFunction(const Standard_Real t) |
7fd59977 | 431 | { |
432 | Standard_Real Umin, Usup, Vmin, Vsup, aD; | |
433 | // | |
434 | gp_Pnt P; | |
435 | myC.D0(t, P); | |
436 | // | |
437 | Standard_Boolean bIsEqDistance; | |
438 | ||
439 | bIsEqDistance= IntTools_EdgeFace::IsEqDistance(P, myS, 1.e-7, aD); | |
440 | if (bIsEqDistance) { | |
441 | aD=aD-myCriteria; | |
442 | return aD; | |
443 | } | |
7fd59977 | 444 | |
445 | Umin=myS.FirstUParameter(); | |
446 | Usup=myS.LastUParameter(); | |
447 | Vmin=myS.FirstVParameter(); | |
448 | Vsup=myS.LastVParameter (); | |
449 | ||
450 | // | |
451 | Standard_Boolean bFlag = Standard_False; | |
452 | ||
4f189102 P |
453 | GeomAPI_ProjectPointOnSurf& aLocProj = myContext->ProjPS(myFace); |
454 | aLocProj.Perform(P); | |
455 | bFlag = aLocProj.IsDone(); | |
456 | ||
457 | if(bFlag) { | |
458 | aD = aLocProj.LowerDistance(); | |
7fd59977 | 459 | } |
460 | // | |
461 | ||
462 | if (!bFlag) { | |
463 | myErrorStatus=11; | |
464 | return 99.; | |
465 | } | |
466 | ||
467 | // | |
468 | // aD=aProjector.LowerDistance(); | |
469 | // | |
470 | aD=aD-myCriteria; | |
471 | return aD; | |
472 | } | |
473 | // | |
474 | //======================================================================= | |
475 | //function : IsEqDistance | |
476 | //purpose : | |
477 | //======================================================================= | |
478 | Standard_Boolean IntTools_EdgeFace::IsEqDistance(const gp_Pnt& aP, | |
479 | const BRepAdaptor_Surface& aBAS, | |
480 | const Standard_Real aTol, | |
481 | Standard_Real& aD) | |
482 | { | |
483 | Standard_Boolean bRetFlag=Standard_True; | |
484 | ||
485 | GeomAbs_SurfaceType aSurfType=aBAS.GetType(); | |
486 | ||
487 | if (aSurfType==GeomAbs_Cylinder) { | |
488 | gp_Cylinder aCyl=aBAS.Cylinder(); | |
489 | const gp_Ax1& anAx1 =aCyl.Axis(); | |
490 | gp_Lin aLinAxis(anAx1); | |
491 | Standard_Real aDC, aRadius=aCyl.Radius(); | |
492 | aDC=aLinAxis.Distance(aP); | |
493 | if (aDC < aTol) { | |
494 | aD=aRadius; | |
495 | return bRetFlag; | |
496 | } | |
497 | } | |
498 | ||
499 | if (aSurfType==GeomAbs_Cone) { | |
500 | gp_Cone aCone=aBAS.Cone(); | |
501 | const gp_Ax1& anAx1 =aCone.Axis(); | |
502 | gp_Lin aLinAxis(anAx1); | |
503 | Standard_Real aDC, aRadius, aDS, aSemiAngle; | |
504 | aDC=aLinAxis.Distance(aP); | |
505 | if (aDC < aTol) { | |
506 | gp_Pnt anApex=aCone.Apex(); | |
507 | aSemiAngle=aCone.SemiAngle(); | |
508 | aDS=aP.Distance(anApex); | |
509 | ||
510 | aRadius=aDS*tan(aSemiAngle); | |
511 | aD=aRadius; | |
512 | return bRetFlag; | |
513 | } | |
514 | } | |
515 | ||
516 | if (aSurfType==GeomAbs_Torus) { | |
517 | Standard_Real aMajorRadius, aMinorRadius, aDC; | |
518 | ||
519 | gp_Torus aTorus=aBAS.Torus(); | |
520 | gp_Pnt aPLoc=aTorus.Location(); | |
521 | aMajorRadius=aTorus.MajorRadius(); | |
522 | ||
523 | aDC=fabs(aPLoc.Distance(aP)-aMajorRadius); | |
524 | if (aDC < aTol) { | |
525 | aMinorRadius=aTorus.MinorRadius(); | |
526 | aD=aMinorRadius; | |
527 | return bRetFlag; | |
528 | } | |
529 | } | |
530 | return !bRetFlag; | |
531 | } | |
532 | // | |
533 | //======================================================================= | |
534 | //function : PrepareArgsFuncArrays | |
535 | //purpose : Obtain | |
536 | // myFuncArray and myArgsArray for the interval [ta, tb] | |
537 | //======================================================================= | |
538 | void IntTools_EdgeFace::PrepareArgsFuncArrays(const Standard_Real ta, | |
539 | const Standard_Real tb) | |
540 | { | |
541 | IntTools_CArray1OfReal anArgs, aFunc; | |
542 | Standard_Integer i, aNb, pri; | |
543 | Standard_Real t, f, f1; | |
544 | // | |
545 | // Prepare values of arguments for the interval [ta, tb] | |
546 | pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs); | |
547 | ||
548 | if (pri) { | |
549 | myErrorStatus=8; | |
550 | return; | |
551 | } | |
552 | //... | |
553 | aNb=anArgs.Length(); | |
554 | ||
555 | if (!aNb){ | |
556 | myErrorStatus=9; | |
557 | return; | |
558 | } | |
559 | // | |
560 | // Prepare values of functions for the interval [ta, tb] | |
561 | aFunc.Resize(aNb); | |
562 | for (i=0; i<aNb; i++) { | |
563 | t=anArgs(i); | |
564 | f1=DistanceFunction(t); | |
565 | f=f1+myCriteria; | |
566 | ||
567 | if (myErrorStatus==11) | |
568 | return; | |
569 | ||
570 | if (f1 < myEpsNull) { | |
571 | f=0.; | |
572 | } | |
573 | aFunc(i)=f; | |
574 | } | |
575 | // | |
576 | // Add points where the derivative = 0 | |
577 | AddDerivativePoints(anArgs, aFunc); | |
578 | ||
579 | } | |
580 | ||
581 | ||
582 | //======================================================================= | |
583 | //function : AddDerivativePoints | |
584 | //purpose : | |
585 | //======================================================================= | |
586 | void IntTools_EdgeFace::AddDerivativePoints(const IntTools_CArray1OfReal& t, | |
587 | const IntTools_CArray1OfReal& f) | |
588 | { | |
589 | Standard_Integer i, j, n, k, nn=100; | |
590 | Standard_Real fr, tr, tr1, dEpsNull=10.*myEpsNull; | |
591 | IntTools_CArray1OfReal fd; | |
592 | TColStd_SequenceOfReal aTSeq, aFSeq; | |
593 | ||
594 | n=t.Length(); | |
595 | fd.Resize(n+1); | |
596 | // | |
597 | // Table of derivatives | |
598 | Standard_Real dfx, tx, tx1, fx, fx1, dt=1.e-6; | |
599 | // Left limit | |
600 | tx=t(0); | |
601 | tx1=tx+dt; | |
602 | fx=f(0); | |
603 | fx1=DistanceFunction(tx1); | |
604 | fx1=fx1+myCriteria; | |
605 | if (fx1 < myEpsNull) { | |
606 | fx1=0.; | |
607 | } | |
608 | dfx=(fx1-fx)/dt; | |
609 | fd(0)=dfx; | |
610 | ||
611 | if (fabs(fd(0)) < dEpsNull){ | |
612 | fd(0)=0.; | |
613 | } | |
614 | ||
615 | ||
616 | k=n-1; | |
617 | for (i=1; i<k; i++) { | |
618 | Standard_Real ti, ti1; | |
619 | ti=t(i); | |
620 | ti1=t(i-1); | |
621 | fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1)); | |
622 | if (fabs(fd(i)) < dEpsNull){ | |
623 | fd(i)=0.; | |
624 | } | |
625 | } | |
626 | // Right limit | |
627 | tx=t(n-1); | |
628 | tx1=tx-dt; | |
629 | fx=f(n-1); | |
630 | fx1=DistanceFunction(tx1); | |
631 | fx1=fx1+myCriteria; | |
632 | if (fx1 < myEpsNull) { | |
633 | fx1=0.; | |
634 | } | |
635 | dfx=(fx-fx1)/dt; | |
636 | fd(n-1)=dfx; | |
637 | ||
638 | if (fabs(fd(n-1)) < dEpsNull){ | |
639 | fd(n-1)=0.; | |
640 | } | |
641 | // | |
642 | // Finding the range where the derivatives have different signs | |
643 | // for neighbouring points | |
644 | for (i=1; i<n; i++) { | |
645 | Standard_Real fd1, fd2, t1, t2; | |
646 | t1 =t(i-1); | |
647 | t2 =t(i); | |
648 | fd1=fd(i-1); | |
649 | fd2=fd(i); | |
650 | ||
651 | if (fd1*fd2 < 0.) { | |
652 | if (fabs(fd1) < myEpsNull) { | |
653 | tr=t1; | |
654 | fr=DistanceFunction(tr);//fd1; | |
655 | } | |
656 | else if (fabs(fd2) < myEpsNull) { | |
657 | tr=t2; | |
658 | fr=DistanceFunction(tr); | |
659 | } | |
660 | else { | |
661 | tr=FindSimpleRoot(2, t1, t2, fd1); | |
662 | fr=DistanceFunction(tr); | |
663 | } | |
664 | ||
665 | aTSeq.Append(tr); | |
666 | aFSeq.Append(fr); | |
667 | } | |
668 | } // end of for (i=1; i<n; i++) | |
669 | // | |
670 | // remove identical t, f | |
671 | nn=aTSeq.Length(); | |
672 | if (nn) { | |
673 | for (i=1; i<=aTSeq.Length(); i++) { | |
674 | tr=aTSeq(i); | |
675 | for (j=0; j<n; j++) { | |
676 | tr1=t(j); | |
677 | if (fabs (tr1-tr) < myEpsT) { | |
678 | aTSeq.Remove(i); | |
679 | aFSeq.Remove(i); | |
680 | } | |
681 | } | |
682 | } | |
683 | nn=aTSeq.Length(); | |
684 | } | |
685 | // | |
686 | // sorting args and funcs in increasing order | |
687 | if (nn) { | |
688 | k=nn+n; | |
689 | IntTools_Array1OfRange anArray1OfRange(1, k); | |
690 | for (i=1; i<=n; i++) { | |
691 | anArray1OfRange(i).SetFirst(t(i-1)); | |
692 | anArray1OfRange(i).SetLast (f(i-1)); | |
693 | } | |
694 | for (i=1; i<=nn; i++) { | |
695 | anArray1OfRange(n+i).SetFirst(aTSeq(i)); | |
696 | anArray1OfRange(n+i).SetLast (aFSeq(i)); | |
697 | } | |
698 | ||
699 | IntTools_QuickSortRange aQuickSortRange; | |
700 | IntTools_CompareRange aComparator; | |
701 | aQuickSortRange.Sort (anArray1OfRange, aComparator); | |
702 | ||
703 | // filling the output arrays | |
704 | myArgsArray.Resize(k); | |
705 | myFuncArray.Resize(k); | |
706 | for (i=1; i<=k; i++) { | |
707 | myArgsArray(i-1)=anArray1OfRange(i).First(); | |
708 | myFuncArray(i-1)=anArray1OfRange(i).Last (); | |
709 | } | |
710 | } | |
711 | ||
712 | else { // nn=0 | |
713 | myArgsArray.Resize(n); | |
714 | myFuncArray.Resize(n); | |
715 | for (i=0; i<n; i++) { | |
716 | myArgsArray(i)=t(i); | |
717 | myFuncArray(i)=f(i); | |
718 | } | |
719 | } | |
720 | } | |
721 | ||
722 | //======================================================================= | |
723 | //function : DerivativeFunction | |
724 | //purpose : | |
725 | //======================================================================= | |
726 | Standard_Real IntTools_EdgeFace::DerivativeFunction(const Standard_Real t2) | |
727 | { | |
728 | Standard_Real t1, t3, aD1, aD2, aD3; | |
729 | Standard_Real dt=1.e-9; | |
730 | t1=t2-dt; | |
731 | aD1=DistanceFunction(t1); | |
732 | t3=t2+dt; | |
733 | aD3=DistanceFunction(t3); | |
734 | ||
735 | aD2=.5*(aD3-aD1)/dt; | |
736 | return aD2; | |
737 | } | |
738 | ||
739 | //======================================================================= | |
740 | //function : FindSimpleRoot | |
741 | //purpose : [private] | |
742 | //======================================================================= | |
743 | Standard_Real IntTools_EdgeFace::FindSimpleRoot (const Standard_Integer IP, | |
744 | const Standard_Real tA, | |
745 | const Standard_Real tB, | |
746 | const Standard_Real fA) | |
747 | { | |
748 | Standard_Real r, a, b, y, x0, s; | |
749 | ||
750 | a=tA; b=tB; r=fA; | |
751 | ||
302f96fb | 752 | for(;;) { |
7fd59977 | 753 | x0=.5*(a+b); |
754 | ||
755 | if (IP==1) | |
756 | y=DistanceFunction(x0); | |
757 | else | |
758 | y=DerivativeFunction(x0); | |
759 | ||
760 | if (fabs(b-a) < myEpsT || y==0.) { | |
761 | return x0; | |
762 | } | |
763 | ||
764 | ||
765 | s=y*r; | |
766 | ||
767 | if (s<0.) { | |
768 | b=x0; | |
769 | continue; | |
770 | } | |
771 | ||
772 | if (s>0.) { | |
773 | a=x0; r=y; | |
774 | } | |
775 | } | |
776 | } | |
777 | //======================================================================= | |
778 | //function : FindGoldRoot | |
779 | //purpose : [private] | |
780 | //======================================================================= | |
781 | Standard_Real IntTools_EdgeFace::FindGoldRoot (const Standard_Real tA, | |
782 | const Standard_Real tB, | |
783 | const Standard_Real coeff) | |
784 | { | |
785 | Standard_Real gs=0.61803399; | |
786 | Standard_Real a, b, xp, xl, yp, yl; | |
787 | ||
788 | a=tA; b=tB; | |
789 | ||
790 | xp=a+(b-a)*gs; | |
791 | xl=b-(b-a)*gs; | |
792 | yp=coeff*DistanceFunction(xp); | |
793 | yl=coeff*DistanceFunction(xl); | |
794 | ||
795 | ||
302f96fb | 796 | for(;;) { |
7fd59977 | 797 | |
798 | if (fabs(b-a) < myEpsT) { | |
799 | return .5*(b+a); | |
800 | } | |
801 | ||
802 | if (yp < yl) { | |
803 | a=xl; | |
804 | xl=xp; | |
805 | xp=a+(b-a)*gs; | |
806 | yp=coeff*DistanceFunction(xp); | |
807 | } | |
808 | ||
809 | else { | |
810 | b=xp; | |
811 | xp=xl; | |
812 | yp=yl; | |
813 | xl=b-(b-a)*gs; | |
814 | yl=coeff*DistanceFunction(xl); | |
815 | } | |
816 | } | |
817 | } | |
818 | ||
819 | //======================================================================= | |
820 | //function : MakeType | |
821 | //purpose : | |
822 | //======================================================================= | |
823 | Standard_Integer IntTools_EdgeFace::MakeType(IntTools_CommonPrt& aCommonPrt) | |
824 | { | |
825 | Standard_Real af1, al1; | |
295cb053 | 826 | Standard_Real df1, tm; |
7fd59977 | 827 | Standard_Boolean bAllNullFlag; |
828 | // | |
829 | bAllNullFlag=aCommonPrt.AllNullFlag(); | |
830 | if (bAllNullFlag) { | |
831 | aCommonPrt.SetType(TopAbs_EDGE); | |
832 | return 0; | |
833 | } | |
834 | // | |
835 | aCommonPrt.Range1(af1, al1); | |
836 | ||
837 | { | |
838 | gp_Pnt aPF, aPL; | |
839 | myC.D0(af1, aPF); | |
840 | myC.D0(al1, aPL); | |
841 | df1=aPF.Distance(aPL); | |
842 | Standard_Boolean isWholeRange = Standard_False; | |
843 | ||
844 | if((Abs(af1 - myRange.First()) < myC.Resolution(myCriteria)) && | |
845 | (Abs(al1 - myRange.Last()) < myC.Resolution(myCriteria))) | |
846 | isWholeRange = Standard_True; | |
847 | ||
848 | ||
849 | if ((df1 > myCriteria * 2.) && isWholeRange) { | |
850 | aCommonPrt.SetType(TopAbs_EDGE); | |
851 | } | |
852 | else { | |
853 | if(isWholeRange) { | |
854 | tm = (af1 + al1) * 0.5; | |
855 | ||
856 | if(aPF.Distance(myC.Value(tm)) > myCriteria * 2.) { | |
857 | aCommonPrt.SetType(TopAbs_EDGE); | |
858 | return 0; | |
859 | } | |
860 | } | |
861 | ||
862 | if(!CheckTouch(aCommonPrt, tm)) { | |
863 | tm = (af1 + al1) * 0.5; | |
864 | } | |
865 | aCommonPrt.SetType(TopAbs_VERTEX); | |
866 | aCommonPrt.SetVertexParameter1(tm); | |
867 | aCommonPrt.SetRange1 (af1, al1); | |
868 | } | |
4e76d93b | 869 | return 0; |
7fd59977 | 870 | } |
295cb053 | 871 | |
4e76d93b | 872 | /* |
7fd59977 | 873 | dt=al1-af1; |
874 | if (dt<1.e-5) { | |
875 | gp_Pnt aPF, aPL; | |
876 | myC.D0(af1, aPF); | |
877 | myC.D0(al1, aPL); | |
878 | df1=aPF.Distance(aPL); | |
879 | if (df1<myCriteria) { | |
880 | // | |
881 | tm=.5*(af1+al1); | |
882 | aCommonPrt.SetType(TopAbs_VERTEX); | |
883 | aCommonPrt.SetVertexParameter1(tm); | |
884 | aCommonPrt.SetRange1 (af1, al1); | |
885 | return 0; | |
886 | } | |
887 | } | |
888 | // | |
889 | IsIntersection (af1, al1); | |
890 | // | |
891 | if (!myParallel) { | |
892 | aCommonPrt.SetType(TopAbs_VERTEX); | |
893 | aCommonPrt.SetVertexParameter1(myPar1); | |
894 | aCommonPrt.SetRange1 (af1, al1); | |
895 | } | |
896 | else { | |
897 | dt=al1-af1; | |
898 | if (dt<1.e-5) { | |
899 | df1=DistanceFunction(af1); | |
900 | df2=DistanceFunction(al1); | |
901 | tm=(df1 < df2) ? af1 : al1; | |
902 | aCommonPrt.SetType(TopAbs_VERTEX); | |
903 | aCommonPrt.SetVertexParameter1(tm); | |
904 | aCommonPrt.SetRange1 (af1, al1); | |
905 | } | |
906 | ||
907 | else { | |
908 | aCommonPrt.SetType(TopAbs_EDGE); | |
909 | } | |
910 | } | |
295cb053 | 911 | |
912 | return 0;*/ | |
7fd59977 | 913 | } |
914 | ||
915 | ||
916 | //======================================================================= | |
917 | //function : IsIntersection | |
918 | //purpose : | |
919 | //======================================================================= | |
920 | void IntTools_EdgeFace::IsIntersection (const Standard_Real ta, | |
921 | const Standard_Real tb) | |
922 | { | |
923 | IntTools_CArray1OfReal anArgs, aFunc; | |
924 | Standard_Integer i, aNb, pri, aCnt=0; | |
925 | // | |
926 | Standard_Integer aCntIncreasing=1, aCntDecreasing=1; | |
927 | Standard_Real t, f, f1; | |
928 | // | |
929 | // Prepare values of arguments for the interval [ta, tb] | |
930 | pri=IntTools::PrepareArgs (myC, tb, ta, myDiscret, myDeflection, anArgs); | |
931 | aNb=anArgs.Length(); | |
932 | ||
933 | aFunc.Resize(aNb); | |
934 | for (i=0; i<aNb; i++) { | |
935 | t=anArgs(i); | |
936 | ||
937 | f1=DistanceFunction(t); | |
938 | f=f1+myCriteria; | |
939 | ||
940 | if (fabs(f1) < myEpsNull) { | |
941 | aCnt++; | |
942 | f=0.; | |
943 | } | |
944 | aFunc(i)=f; | |
945 | // | |
946 | if (i) { | |
947 | if (aFunc(i)>aFunc(i-1)) { | |
948 | aCntIncreasing++; | |
949 | } | |
950 | if (aFunc(i)<aFunc(i-1)) { | |
951 | aCntDecreasing++; | |
952 | } | |
953 | } | |
954 | // | |
955 | } | |
956 | ||
957 | if (aCnt==aNb) { | |
958 | myParallel=Standard_True; | |
959 | return; | |
960 | } | |
961 | ||
962 | FindDerivativeRoot(anArgs, aFunc); | |
963 | ||
964 | // | |
965 | if (myParallel) { | |
966 | if (!(myC.GetType()==GeomAbs_Line | |
967 | && | |
968 | myS.GetType()==GeomAbs_Cylinder)) { | |
969 | if (aCntDecreasing==aNb) { | |
970 | myPar1=anArgs(aNb-1); | |
971 | myParallel=Standard_False; | |
972 | } | |
973 | if (aCntIncreasing==aNb) { | |
974 | myPar1=anArgs(0); | |
975 | myParallel=Standard_False; | |
976 | } | |
977 | } | |
978 | } | |
979 | // | |
980 | return ; | |
981 | } | |
982 | ||
983 | //======================================================================= | |
984 | //function : FindDerivativeRoot | |
985 | //purpose : | |
986 | //======================================================================= | |
987 | void IntTools_EdgeFace::FindDerivativeRoot(const IntTools_CArray1OfReal& t, | |
988 | const IntTools_CArray1OfReal& f) | |
989 | { | |
990 | Standard_Integer i, n, k; | |
991 | Standard_Real fr, tr; | |
992 | IntTools_CArray1OfReal fd; | |
993 | TColStd_SequenceOfReal aTSeq, aFSeq; | |
994 | ||
995 | myPar1=0.; | |
996 | myParallel=Standard_True; | |
997 | ||
998 | n=t.Length(); | |
999 | fd.Resize(n+1); | |
1000 | // | |
1001 | // Table of derivatives | |
1002 | fd(0)=(f(1)-f(0))/(t(1)-t(0)); | |
1003 | if (fabs(fd(0)) < myEpsNull) { | |
1004 | fd(0)=0.; | |
1005 | } | |
1006 | ||
1007 | k=n-1; | |
1008 | for (i=1; i<k; i++) { | |
1009 | fd(i)=.5*(f(i+1)-f(i-1))/(t(i)-t(i-1)); | |
1010 | if (fabs(fd(i)) < myEpsNull) { | |
1011 | fd(i)=0.; | |
1012 | } | |
1013 | } | |
1014 | ||
1015 | fd(n-1)=(f(n-1)-f(n-2))/(t(n-1)-t(n-2)); | |
1016 | if (fabs(fd(n-1)) < myEpsNull) { | |
1017 | fd(n-1)=0.; | |
1018 | } | |
1019 | // | |
1020 | // Finding the range where the derivatives have different signs | |
1021 | // for neighbouring points | |
1022 | for (i=1; i<n; i++) { | |
1023 | Standard_Real fd1, fd2, t1, t2, fabsfd1, fabsfd2; | |
1024 | Standard_Boolean bF1, bF2; | |
1025 | t1 =t(i-1); | |
1026 | t2 =t(i); | |
1027 | fd1=fd(i-1); | |
1028 | fd2=fd(i); | |
1029 | ||
1030 | fabsfd1=fabs(fd1); | |
1031 | bF1=fabsfd1 < myEpsNull; | |
1032 | ||
1033 | fabsfd2=fabs(fd2); | |
1034 | bF2=fabsfd2 < myEpsNull; | |
1035 | // | |
1036 | if (fd1*fd2 < 0.) { | |
1037 | tr=FindSimpleRoot(2, t1, t2, fd1); | |
1038 | fr=DistanceFunction(tr); | |
1039 | myPar1=tr; | |
1040 | myParallel=Standard_False; | |
1041 | break; | |
1042 | } | |
1043 | ||
1044 | if (!bF1 && bF2) { | |
1045 | tr=t2; | |
1046 | fr=fd2; | |
1047 | myPar1=tr; | |
1048 | myParallel=Standard_False; | |
1049 | break; | |
1050 | } | |
1051 | ||
1052 | if (bF1 && !bF2) { | |
1053 | tr=t1; | |
1054 | fr=fd1; | |
1055 | myPar1=tr; | |
1056 | myParallel=Standard_False; | |
1057 | break; | |
1058 | } | |
1059 | ||
1060 | } | |
1061 | } | |
1062 | //======================================================================= | |
1063 | //function : RemoveIdenticalRoots | |
1064 | //purpose : | |
1065 | //======================================================================= | |
1066 | void IntTools_EdgeFace::RemoveIdenticalRoots() | |
1067 | { | |
1068 | Standard_Integer aNbRoots, j, k; | |
1069 | ||
1070 | aNbRoots=mySequenceOfRoots.Length(); | |
1071 | for (j=1; j<=aNbRoots; j++) { | |
1072 | const IntTools_Root& aRj=mySequenceOfRoots(j); | |
1073 | for (k=j+1; k<=aNbRoots; k++) { | |
1074 | const IntTools_Root& aRk=mySequenceOfRoots(k); | |
1075 | ||
1076 | Standard_Real aTj, aTk, aDistance; | |
1077 | gp_Pnt aPj, aPk; | |
1078 | ||
1079 | aTj=aRj.Root(); | |
1080 | aTk=aRk.Root(); | |
1081 | ||
1082 | myC.D0(aTj, aPj); | |
1083 | myC.D0(aTk, aPk); | |
1084 | ||
1085 | aDistance=aPj.Distance(aPk); | |
1086 | if (aDistance < myCriteria) { | |
1087 | mySequenceOfRoots.Remove(k); | |
1088 | aNbRoots=mySequenceOfRoots.Length(); | |
1089 | } | |
1090 | } | |
1091 | } | |
1092 | } | |
1093 | ||
1094 | //======================================================================= | |
1095 | //function : CheckTouch | |
1096 | //purpose : | |
1097 | //======================================================================= | |
1098 | Standard_Boolean IntTools_EdgeFace::CheckTouch(const IntTools_CommonPrt& aCP, | |
1099 | Standard_Real& aTx) | |
1100 | { | |
1101 | Standard_Real aTF, aTL, Tol, U1f, U1l, V1f, V1l, af, al,aDist2, aMinDist2; | |
1102 | Standard_Boolean theflag=Standard_False; | |
1103 | Standard_Integer aNbExt, i, iLower ; | |
1104 | ||
1105 | aCP.Range1(aTF, aTL); | |
1106 | ||
1107 | // | |
1108 | Standard_Real aCR; | |
1109 | aCR=myC.Resolution(myCriteria); | |
1110 | if((Abs(aTF - myRange.First()) < aCR) && | |
1111 | (Abs(aTL - myRange.Last()) < aCR)) { | |
1112 | return theflag; // EDGE | |
1113 | } | |
1114 | // | |
1115 | ||
1116 | Tol = Precision::PConfusion(); | |
1117 | ||
1118 | const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al); | |
1119 | const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face()); | |
1120 | // Surface->Bounds(U1f,U1l,V1f,V1l); | |
1121 | U1f = myS.FirstUParameter(); | |
1122 | U1l = myS.LastUParameter(); | |
1123 | V1f = myS.FirstVParameter(); | |
1124 | V1l = myS.LastVParameter(); | |
1125 | ||
1126 | GeomAdaptor_Curve TheCurve (Curve,aTF, aTL); | |
1127 | GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l); | |
1128 | ||
1129 | Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol); | |
1130 | ||
1131 | aDist2 = 1.e100; | |
1132 | ||
1133 | if(anExtrema.IsDone()) { | |
1134 | aMinDist2 = aDist2; | |
1135 | ||
1136 | if(!anExtrema.IsParallel()) { | |
1137 | aNbExt=anExtrema.NbExt(); | |
1138 | ||
1139 | if(aNbExt > 0) { | |
1140 | iLower=1; | |
1141 | for (i=1; i<=aNbExt; i++) { | |
1142 | aDist2=anExtrema.SquareDistance(i); | |
1143 | if (aDist2 < aMinDist2) { | |
1144 | aMinDist2=aDist2; | |
1145 | iLower=i; | |
1146 | } | |
1147 | } | |
1148 | aDist2=anExtrema.SquareDistance(iLower); | |
1149 | Extrema_POnCurv aPOnC; | |
1150 | Extrema_POnSurf aPOnS; | |
1151 | anExtrema.Points(iLower, aPOnC, aPOnS); | |
1152 | aTx=aPOnC.Parameter(); | |
1153 | } | |
1154 | else { | |
1155 | // modified by NIZHNY-MKK Thu Jul 21 11:35:32 2005.BEGIN | |
1156 | IntCurveSurface_HInter anExactIntersector; | |
1157 | ||
1158 | Handle(GeomAdaptor_HCurve) aCurve = new GeomAdaptor_HCurve(TheCurve); | |
1159 | Handle(GeomAdaptor_HSurface) aSurface = new GeomAdaptor_HSurface(TheSurface); | |
1160 | ||
1161 | anExactIntersector.Perform(aCurve, aSurface); | |
1162 | ||
1163 | if(anExactIntersector.IsDone()) { | |
1164 | Standard_Integer i = 0; | |
1165 | ||
1166 | for(i = 1; i <= anExactIntersector.NbPoints(); i++) { | |
1167 | const IntCurveSurface_IntersectionPoint& aPoint = anExactIntersector.Point(i); | |
1168 | ||
1169 | if((aPoint.W() >= aTF) && (aPoint.W() <= aTL)) { | |
1170 | aDist2=0.; | |
1171 | aTx = aPoint.W(); | |
1172 | } | |
1173 | } | |
1174 | } | |
1175 | // modified by NIZHNY-MKK Thu Jul 21 11:35:40 2005.END | |
1176 | } | |
1177 | } | |
1178 | else { | |
1179 | return theflag; | |
1180 | } | |
1181 | } | |
1182 | ||
1183 | Standard_Real aBoundaryDist; | |
1184 | ||
1185 | aBoundaryDist = DistanceFunction(aTF) + myCriteria; | |
1186 | if(aBoundaryDist * aBoundaryDist < aDist2) { | |
1187 | aDist2 = aBoundaryDist * aBoundaryDist; | |
1188 | aTx = aTF; | |
1189 | } | |
1190 | ||
1191 | aBoundaryDist = DistanceFunction(aTL) + myCriteria; | |
1192 | if(aBoundaryDist * aBoundaryDist < aDist2) { | |
1193 | aDist2 = aBoundaryDist * aBoundaryDist; | |
1194 | aTx = aTL; | |
1195 | } | |
1196 | ||
1197 | Standard_Real aParameter = (aTF + aTL) * 0.5; | |
1198 | aBoundaryDist = DistanceFunction(aParameter) + myCriteria; | |
1199 | if(aBoundaryDist * aBoundaryDist < aDist2) { | |
1200 | aDist2 = aBoundaryDist * aBoundaryDist; | |
1201 | aTx = aParameter; | |
1202 | } | |
1203 | ||
1204 | if(aDist2 > myCriteria * myCriteria) { | |
1205 | return theflag; | |
1206 | } | |
1207 | ||
1208 | if (fabs (aTx-aTF) < myEpsT) { | |
1209 | return !theflag; | |
1210 | } | |
1211 | ||
1212 | if (fabs (aTx-aTL) < myEpsT) { | |
1213 | return !theflag; | |
1214 | } | |
1215 | ||
1216 | if (aTx>aTF && aTx<aTL) { | |
1217 | return !theflag; | |
1218 | } | |
1219 | ||
1220 | return theflag; | |
1221 | } | |
1222 | ||
7fd59977 | 1223 | |
1224 | //======================================================================= | |
1225 | //function : Perform | |
1226 | //purpose : | |
1227 | //======================================================================= | |
1228 | void IntTools_EdgeFace::Perform() | |
1229 | { | |
1230 | Standard_Integer i, aNb; | |
1231 | IntTools_CommonPrt aCommonPrt; | |
7fd59977 | 1232 | // |
4f189102 | 1233 | aCommonPrt.SetEdge1(myEdge); |
7fd59977 | 1234 | // |
1235 | myErrorStatus=0; | |
1236 | CheckData(); | |
4f189102 | 1237 | if (myErrorStatus) { |
7fd59977 | 1238 | return; |
4f189102 P |
1239 | } |
1240 | // | |
1241 | if (myContext.IsNull()) { | |
4e57c75e | 1242 | myContext=new BOPInt_Context; |
4f189102 P |
1243 | } |
1244 | // | |
7fd59977 | 1245 | myIsDone = Standard_False; |
1246 | myC.Initialize(myEdge); | |
1247 | GeomAbs_CurveType aCurveType; | |
1248 | aCurveType=myC.GetType(); | |
1249 | // | |
1250 | // Prepare myCriteria | |
1251 | if (aCurveType==GeomAbs_BSplineCurve|| | |
1252 | aCurveType==GeomAbs_BezierCurve) { | |
1253 | //--- 5112 | |
1254 | Standard_Real diff1 = (myTolE/myTolF); | |
1255 | Standard_Real diff2 = (myTolF/myTolE); | |
1256 | if( diff1 > 100 || diff2 > 100 ) { | |
1257 | myCriteria = Max(myTolE,myTolF); | |
1258 | } | |
1259 | else //--- 5112 | |
1260 | myCriteria=1.5*myTolE+myTolF; | |
1261 | } | |
1262 | else { | |
1263 | myCriteria=myTolE+myTolF; | |
1264 | } | |
1265 | ||
1266 | myTmin=myRange.First(); | |
1267 | myTmax=myRange.Last(); | |
1268 | ||
1269 | myS.Initialize (myFace,Standard_True); | |
1270 | ||
4f189102 | 1271 | if(myContext.IsNull()) { |
7fd59977 | 1272 | myFClass2d.Init(myFace, 1.e-6); |
1273 | } | |
1274 | ||
1275 | IntTools_BeanFaceIntersector anIntersector(myC, myS, myTolE, myTolF); | |
1276 | anIntersector.SetBeanParameters(myRange.First(), myRange.Last()); | |
1277 | // | |
1278 | anIntersector.SetContext(myContext); | |
1279 | // | |
1280 | anIntersector.Perform(); | |
1281 | ||
1282 | if(!anIntersector.IsDone()) { | |
1283 | return; | |
1284 | } | |
1285 | ||
1286 | for(Standard_Integer r = 1; r <= anIntersector.Result().Length(); r++) { | |
1287 | const IntTools_Range& aRange = anIntersector.Result().Value(r); | |
1288 | ||
1289 | if(IsProjectable(IntTools_Tools::IntermediatePoint(aRange.First(), aRange.Last()))) { | |
1290 | aCommonPrt.SetRange1(aRange.First(), aRange.Last()); | |
1291 | mySeqOfCommonPrts.Append(aCommonPrt); | |
1292 | } | |
1293 | } | |
1294 | ||
1295 | aNb = mySeqOfCommonPrts.Length(); | |
1296 | ||
1297 | for (i=1; i<=aNb; i++) { | |
1298 | IntTools_CommonPrt& aCP=mySeqOfCommonPrts.ChangeValue(i); | |
1299 | // | |
1300 | Standard_Real aTx1, aTx2; | |
1301 | gp_Pnt aPx1, aPx2; | |
1302 | // | |
1303 | aCP.Range1(aTx1, aTx2); | |
1304 | myC.D0(aTx1, aPx1); | |
1305 | myC.D0(aTx2, aPx2); | |
1306 | aCP.SetBoundingPoints(aPx1, aPx2); | |
1307 | // | |
1308 | MakeType (aCP); | |
1309 | } | |
1310 | { | |
1311 | // Line\Cylinder's Common Parts treatement | |
1312 | GeomAbs_CurveType aCType; | |
1313 | GeomAbs_SurfaceType aSType; | |
1314 | TopAbs_ShapeEnum aType; | |
1315 | Standard_Boolean bIsTouch; | |
1316 | Standard_Real aTx; | |
1317 | ||
1318 | aCType=myC.GetType(); | |
1319 | aSType=myS.GetType(); | |
1320 | ||
1321 | if (aCType==GeomAbs_Line && aSType==GeomAbs_Cylinder) { | |
1322 | for (i=1; i<=aNb; i++) { | |
1323 | IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i); | |
1324 | aType=aCP.Type(); | |
1325 | if (aType==TopAbs_EDGE) { | |
1326 | bIsTouch=CheckTouch (aCP, aTx); | |
1327 | if (bIsTouch) { | |
1328 | aCP.SetType(TopAbs_VERTEX); | |
1329 | aCP.SetVertexParameter1(aTx); | |
1330 | aCP.SetRange1 (aTx, aTx); | |
1331 | } | |
1332 | } | |
1333 | if (aType==TopAbs_VERTEX) { | |
1334 | bIsTouch=CheckTouchVertex (aCP, aTx); | |
1335 | if (bIsTouch) { | |
1336 | aCP.SetVertexParameter1(aTx); | |
1337 | aCP.SetRange1 (aTx, aTx); | |
1338 | } | |
1339 | } | |
1340 | } | |
1341 | } | |
1342 | ||
1343 | // Circle\Plane's Common Parts treatement | |
1344 | ||
1345 | if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) { | |
1346 | Standard_Boolean bIsCoplanar, bIsRadius; | |
1347 | bIsCoplanar=IsCoplanar(myC, myS); | |
1348 | bIsRadius=IsRadius(myC, myS); | |
1349 | if (!bIsCoplanar && !bIsRadius) { | |
1350 | for (i=1; i<=aNb; i++) { | |
1351 | IntTools_CommonPrt& aCP=mySeqOfCommonPrts(i); | |
1352 | aType=aCP.Type(); | |
1353 | if (aType==TopAbs_EDGE) { | |
1354 | bIsTouch=CheckTouch (aCP, aTx); | |
1355 | if (bIsTouch) { | |
1356 | aCP.SetType(TopAbs_VERTEX); | |
1357 | aCP.SetVertexParameter1(aTx); | |
1358 | aCP.SetRange1 (aTx, aTx); | |
1359 | } | |
1360 | } | |
1361 | } | |
1362 | } | |
1363 | } | |
1364 | } | |
1365 | myIsDone=Standard_True; | |
1366 | } | |
1367 | ||
1368 | // | |
1369 | // myErrorStatus | |
1370 | // 1 - the method Perform() is not invoked | |
1371 | // 2,3,4,5 -the method CheckData() fails | |
1372 | // 6 - PrepareArgs() problems | |
1373 | // 7 - No Projectable ranges | |
1374 | // 8,9 - PrepareArgs() problems occured inside projectable Ranges | |
1375 | // 11 - can't fill array aFunc(i) in PrepareArgsFuncArrays | |
1376 | ||
1377 | ||
1378 | //======================================================================= | |
1379 | //function : CheckTouch | |
1380 | //purpose : | |
1381 | //======================================================================= | |
1382 | Standard_Boolean IntTools_EdgeFace::CheckTouchVertex (const IntTools_CommonPrt& aCP, | |
1383 | Standard_Real& aTx) | |
1384 | { | |
1385 | Standard_Real aTF, aTL, Tol, U1f,U1l,V1f,V1l, af, al,aDist2, aMinDist2, aTm, aDist2New; | |
ddd95bbf | 1386 | Standard_Real aEpsT; |
7fd59977 | 1387 | Standard_Boolean theflag=Standard_False; |
1388 | Standard_Integer aNbExt, i, iLower ; | |
1389 | ||
1390 | aCP.Range1(aTF, aTL); | |
ddd95bbf | 1391 | aEpsT=8.e-5; |
7fd59977 | 1392 | aTm=0.5*(aTF+aTL); |
1393 | aDist2=DistanceFunction(aTm); | |
1394 | aDist2 *= aDist2; | |
1395 | ||
1396 | Tol = Precision::PConfusion(); | |
1397 | ||
1398 | const Handle(Geom_Curve)& Curve =BRep_Tool::Curve (myC.Edge(), af, al); | |
1399 | const Handle(Geom_Surface)& Surface=BRep_Tool::Surface(myS.Face()); | |
1400 | ||
1401 | Surface->Bounds(U1f,U1l,V1f,V1l); | |
1402 | ||
1403 | GeomAdaptor_Curve TheCurve (Curve,aTF, aTL); | |
1404 | GeomAdaptor_Surface TheSurface (Surface, U1f, U1l, V1f, V1l); | |
1405 | ||
1406 | Extrema_ExtCS anExtrema (TheCurve, TheSurface, Tol, Tol); | |
1407 | ||
1408 | if(!anExtrema.IsDone()) { | |
1409 | return theflag; | |
1410 | } | |
1411 | if (anExtrema.IsParallel()) { | |
1412 | return theflag; | |
1413 | } | |
1414 | ||
1415 | aNbExt=anExtrema.NbExt() ; | |
1416 | if (!aNbExt) { | |
1417 | return theflag; | |
1418 | } | |
1419 | ||
1420 | iLower=1; | |
1421 | aMinDist2=1.e100; | |
1422 | for (i=1; i<=aNbExt; ++i) { | |
1423 | aDist2=anExtrema.SquareDistance(i); | |
1424 | if (aDist2 < aMinDist2) { | |
1425 | aMinDist2=aDist2; | |
1426 | iLower=i; | |
1427 | } | |
1428 | } | |
1429 | ||
1430 | aDist2New=anExtrema.SquareDistance(iLower); | |
1431 | ||
1432 | if (aDist2New > aDist2) { | |
1433 | aTx=aTm; | |
1434 | return !theflag; | |
1435 | } | |
1436 | ||
1437 | if (aDist2New > myCriteria * myCriteria) { | |
1438 | return theflag; | |
1439 | } | |
1440 | ||
1441 | Extrema_POnCurv aPOnC; | |
1442 | Extrema_POnSurf aPOnS; | |
1443 | anExtrema.Points(iLower, aPOnC, aPOnS); | |
1444 | ||
ddd95bbf | 1445 | |
7fd59977 | 1446 | aTx=aPOnC.Parameter(); |
ddd95bbf | 1447 | /// |
1448 | if (fabs (aTx-aTF) < aEpsT) { | |
1449 | return theflag; | |
7fd59977 | 1450 | } |
1451 | ||
ddd95bbf | 1452 | if (fabs (aTx-aTL) < aEpsT) { |
1453 | return theflag; | |
7fd59977 | 1454 | } |
1455 | ||
1456 | if (aTx>aTF && aTx<aTL) { | |
1457 | return !theflag; | |
1458 | } | |
1459 | ||
1460 | return theflag; | |
1461 | } | |
1462 | ||
1463 | ||
1464 | //======================================================================= | |
1465 | //function : IsCoplanar | |
1466 | //purpose : | |
1467 | //======================================================================= | |
1468 | Standard_Boolean IsCoplanar (const BRepAdaptor_Curve& aCurve , | |
1469 | const BRepAdaptor_Surface& aSurface) | |
1470 | { | |
1471 | Standard_Boolean bFlag=Standard_False; | |
1472 | ||
1473 | GeomAbs_CurveType aCType; | |
1474 | GeomAbs_SurfaceType aSType; | |
1475 | ||
1476 | aCType=aCurve.GetType(); | |
1477 | aSType=aSurface.GetType(); | |
1478 | ||
1479 | if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) { | |
1480 | gp_Circ aCirc=aCurve.Circle(); | |
1481 | const gp_Ax1& anAx1=aCirc.Axis(); | |
1482 | const gp_Dir& aDirAx1=anAx1.Direction(); | |
1483 | ||
1484 | gp_Pln aPln=aSurface.Plane(); | |
1485 | const gp_Ax1& anAx=aPln.Axis(); | |
1486 | const gp_Dir& aDirPln=anAx.Direction(); | |
1487 | ||
1488 | bFlag=IntTools_Tools::IsDirsCoinside(aDirAx1, aDirPln); | |
1489 | } | |
1490 | return bFlag; | |
1491 | } | |
1492 | //======================================================================= | |
1493 | //function : IsRadius | |
1494 | //purpose : | |
1495 | //======================================================================= | |
1496 | Standard_Boolean IsRadius (const BRepAdaptor_Curve& aCurve , | |
1497 | const BRepAdaptor_Surface& aSurface) | |
1498 | { | |
1499 | Standard_Boolean bFlag=Standard_False; | |
1500 | ||
1501 | GeomAbs_CurveType aCType; | |
1502 | GeomAbs_SurfaceType aSType; | |
1503 | ||
1504 | aCType=aCurve.GetType(); | |
1505 | aSType=aSurface.GetType(); | |
1506 | ||
1507 | if (aCType==GeomAbs_Circle && aSType==GeomAbs_Plane) { | |
1508 | gp_Circ aCirc=aCurve.Circle(); | |
1509 | const gp_Pnt aCenter=aCirc.Location(); | |
1510 | Standard_Real aR=aCirc.Radius(); | |
1511 | gp_Pln aPln=aSurface.Plane(); | |
1512 | Standard_Real aD=aPln.Distance(aCenter); | |
1513 | if (fabs (aD-aR) < 1.e-7) { | |
1514 | return !bFlag; | |
1515 | } | |
1516 | } | |
1517 | return bFlag; | |
1518 | } | |
1519 | // | |
1520 | //======================================================================= | |
1521 | //function : AdaptiveDiscret | |
1522 | //purpose : | |
1523 | //======================================================================= | |
1524 | Standard_Integer AdaptiveDiscret (const Standard_Integer iDiscret, | |
1525 | const BRepAdaptor_Curve& aCurve , | |
1526 | const BRepAdaptor_Surface& aSurface) | |
1527 | { | |
1528 | Standard_Integer iDiscretNew; | |
1529 | ||
1530 | iDiscretNew=iDiscret; | |
1531 | ||
1532 | GeomAbs_CurveType aCType; | |
1533 | GeomAbs_SurfaceType aSType; | |
1534 | ||
1535 | aCType=aCurve.GetType(); | |
1536 | aSType=aSurface.GetType(); | |
1537 | ||
1538 | if (aSType==GeomAbs_Cylinder) { | |
1539 | Standard_Real aELength, aRadius, dL, dLR; | |
1540 | ||
1541 | aELength=IntTools::Length(aCurve.Edge()); | |
1542 | dL=aELength/iDiscret; | |
1543 | ||
1544 | gp_Cylinder aCylinder=aSurface.Cylinder(); | |
1545 | aRadius=aCylinder.Radius(); | |
1546 | dLR=2*aRadius; | |
1547 | ||
1548 | iDiscretNew=(Standard_Integer)(aELength/dLR); | |
1549 | ||
1550 | if (iDiscretNew<iDiscret) { | |
1551 | iDiscretNew=iDiscret; | |
1552 | } | |
1553 | ||
1554 | } | |
1555 | return iDiscretNew; | |
1556 | } | |
1557 | ||
1558 | ||
1559 | #ifdef WNT | |
1560 | #pragma warning ( default : 4101 ) | |
1561 | #endif |