b311480e |
1 | // Created on: 1996-06-11 |
2 | // Created by: Jacques GOUSSARD |
3 | // Copyright (c) 1996-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
7fd59977 |
16 | |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <Geom_Circle.hxx> |
c22b52d6 |
19 | #include <GeomAdaptor_Curve.hxx> |
42cf5bc1 |
20 | #include <IntCurvesFace_Intersector.hxx> |
21 | #include <LocOpe_CSIntersector.hxx> |
7fd59977 |
22 | #include <LocOpe_SequenceOfPntFace.hxx> |
42cf5bc1 |
23 | #include <Precision.hxx> |
7fd59977 |
24 | #include <Standard_ConstructionError.hxx> |
42cf5bc1 |
25 | #include <Standard_OutOfRange.hxx> |
26 | #include <StdFail_NotDone.hxx> |
27 | #include <TopExp_Explorer.hxx> |
7fd59977 |
28 | #include <TopoDS.hxx> |
42cf5bc1 |
29 | #include <TopoDS_Shape.hxx> |
7fd59977 |
30 | |
31 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&, |
32 | const Standard_Real, |
33 | const Standard_Real, |
34 | TopAbs_Orientation&, |
35 | Standard_Integer&, |
36 | Standard_Integer&); |
37 | |
38 | static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&, |
39 | const Standard_Real, |
40 | const Standard_Real, |
41 | TopAbs_Orientation&, |
42 | Standard_Integer&, |
43 | Standard_Integer&); |
44 | |
45 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&, |
46 | const Standard_Integer, |
47 | const Standard_Real, |
48 | TopAbs_Orientation&, |
49 | Standard_Integer&, |
50 | Standard_Integer&); |
51 | |
7fd59977 |
52 | static void AddPoints(IntCurvesFace_Intersector&, |
53 | LocOpe_SequenceOfPntFace&, |
54 | const TopoDS_Face&); |
55 | |
7fd59977 |
56 | //======================================================================= |
57 | //function : Init |
58 | //purpose : |
59 | //======================================================================= |
60 | |
61 | void LocOpe_CSIntersector::Init(const TopoDS_Shape& S) |
62 | { |
63 | myDone = Standard_False; |
64 | myShape = S; |
65 | if (myPoints != NULL) { |
66 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
67 | myPoints = NULL; |
68 | } |
69 | myNbelem = 0; |
70 | } |
71 | |
72 | |
73 | //======================================================================= |
74 | //function : Perform |
75 | //purpose : |
76 | //======================================================================= |
77 | |
78 | void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfLin& Slin) |
79 | { |
80 | if (myShape.IsNull() || Slin.Length() <= 0) { |
9775fa61 |
81 | throw Standard_ConstructionError(); |
7fd59977 |
82 | } |
83 | myDone = Standard_False; |
84 | |
85 | myNbelem = Slin.Length(); |
86 | if (myPoints != NULL) { |
87 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
88 | } |
89 | myPoints = |
90 | (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem]; |
91 | |
92 | Standard_Real binf = RealFirst(); |
93 | Standard_Real bsup = RealLast(); |
94 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
95 | for (; exp.More(); exp.Next()) { |
96 | const TopoDS_Face& theface = TopoDS::Face(exp.Current()); |
97 | IntCurvesFace_Intersector theInt(theface,Precision::PConfusion()); |
98 | for (Standard_Integer i = 1; i<=myNbelem; i++) { |
99 | theInt.Perform(Slin(i),binf,bsup); |
100 | if (theInt.IsDone()) { |
101 | AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface); |
102 | } |
103 | } |
104 | } |
105 | myDone = Standard_True; |
106 | } |
107 | |
108 | |
109 | //======================================================================= |
110 | //function : Perform |
111 | //purpose : |
112 | //======================================================================= |
113 | |
114 | void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfCirc& Scir) |
115 | { |
116 | if (myShape.IsNull() || Scir.Length() <= 0) { |
9775fa61 |
117 | throw Standard_ConstructionError(); |
7fd59977 |
118 | } |
119 | myDone = Standard_False; |
120 | |
121 | myNbelem = Scir.Length(); |
122 | if (myPoints != NULL) { |
123 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
124 | } |
125 | myPoints = |
126 | (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem]; |
127 | |
128 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
c22b52d6 |
129 | Handle(GeomAdaptor_Curve) HC = new GeomAdaptor_Curve (); |
7fd59977 |
130 | Standard_Real binf = 0.; |
c6541a0c |
131 | Standard_Real bsup = 2.*M_PI; |
7fd59977 |
132 | |
133 | |
134 | for (; exp.More(); exp.Next()) { |
135 | const TopoDS_Face& theface = TopoDS::Face(exp.Current()); |
136 | IntCurvesFace_Intersector theInt(theface,0.); |
7fd59977 |
137 | for (Standard_Integer i = 1; i<=myNbelem; i++) { |
138 | |
c22b52d6 |
139 | HC->Load(new Geom_Circle(Scir(i))); |
7fd59977 |
140 | theInt.Perform(HC,binf,bsup); |
141 | if (theInt.IsDone()) { |
142 | AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface); |
143 | } |
144 | } |
145 | } |
146 | myDone = Standard_True; |
147 | } |
148 | |
149 | |
150 | |
151 | //======================================================================= |
152 | //function : Perform |
153 | //purpose : |
154 | //======================================================================= |
155 | |
156 | void LocOpe_CSIntersector::Perform(const TColGeom_SequenceOfCurve& Scur) |
157 | { |
158 | if (myShape.IsNull() || Scur.Length() <= 0) { |
9775fa61 |
159 | throw Standard_ConstructionError(); |
7fd59977 |
160 | } |
161 | myDone = Standard_False; |
162 | |
163 | myNbelem = Scur.Length(); |
164 | if (myPoints != NULL) { |
165 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
166 | } |
167 | myPoints = |
168 | (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem]; |
169 | |
170 | TopExp_Explorer exp(myShape,TopAbs_FACE); |
c22b52d6 |
171 | Handle(GeomAdaptor_Curve) HC = new GeomAdaptor_Curve (); |
7fd59977 |
172 | for (; exp.More(); exp.Next()) { |
173 | const TopoDS_Face& theface = TopoDS::Face(exp.Current()); |
174 | IntCurvesFace_Intersector theInt(theface,0.); |
7fd59977 |
175 | for (Standard_Integer i = 1; i<=myNbelem; i++) { |
176 | if (Scur(i).IsNull()) { |
177 | continue; |
178 | } |
c22b52d6 |
179 | HC->Load(Scur(i)); |
7fd59977 |
180 | Standard_Real binf = HC->FirstParameter(); |
181 | Standard_Real bsup = HC->LastParameter(); |
182 | theInt.Perform(HC,binf,bsup); |
183 | if (theInt.IsDone()) { |
184 | AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface); |
185 | } |
186 | } |
187 | } |
188 | myDone = Standard_True; |
189 | } |
190 | |
191 | |
192 | |
193 | //======================================================================= |
194 | //function : NbPoints |
195 | //purpose : |
196 | //======================================================================= |
197 | |
198 | Standard_Integer LocOpe_CSIntersector::NbPoints |
199 | (const Standard_Integer I) const |
200 | { |
9775fa61 |
201 | if (!myDone) {throw StdFail_NotDone();} |
7fd59977 |
202 | if (I <= 0 || I > myNbelem) { |
9775fa61 |
203 | throw Standard_OutOfRange(); |
7fd59977 |
204 | } |
205 | return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1].Length(); |
206 | } |
207 | |
208 | //======================================================================= |
209 | //function : Point |
210 | //purpose : |
211 | //======================================================================= |
212 | |
213 | const LocOpe_PntFace& LocOpe_CSIntersector:: |
214 | Point(const Standard_Integer I, |
215 | const Standard_Integer Index) const |
216 | { |
9775fa61 |
217 | if (!myDone) {throw StdFail_NotDone();} |
7fd59977 |
218 | if (I <= 0 || I > myNbelem) { |
9775fa61 |
219 | throw Standard_OutOfRange(); |
7fd59977 |
220 | } |
221 | return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1](Index); |
222 | } |
223 | |
224 | //======================================================================= |
225 | //function : Destroy |
226 | //purpose : |
227 | //======================================================================= |
228 | |
229 | void LocOpe_CSIntersector::Destroy() |
230 | { |
231 | if (myPoints != NULL) { |
232 | delete [] (LocOpe_SequenceOfPntFace *)myPoints; |
233 | myPoints = NULL; |
234 | } |
235 | } |
236 | |
237 | |
238 | //======================================================================= |
239 | //function : LocalizeAfter |
240 | //purpose : |
241 | //======================================================================= |
242 | |
243 | Standard_Boolean LocOpe_CSIntersector::LocalizeAfter |
244 | (const Standard_Integer I, |
245 | const Standard_Real From, |
246 | const Standard_Real Tol, |
247 | TopAbs_Orientation& Or, |
248 | Standard_Integer& IndFrom, |
249 | Standard_Integer& IndTo) const |
250 | { |
251 | if (!myDone) { |
9775fa61 |
252 | throw StdFail_NotDone(); |
7fd59977 |
253 | } |
254 | if (I <= 0 || I > myNbelem) { |
9775fa61 |
255 | throw Standard_OutOfRange(); |
7fd59977 |
256 | } |
257 | return LocAfter((((LocOpe_SequenceOfPntFace*)myPoints)[I-1]), |
258 | From,Tol,Or,IndFrom,IndTo); |
259 | } |
260 | |
261 | |
262 | //======================================================================= |
263 | //function : LocalizeBefore |
264 | //purpose : |
265 | //======================================================================= |
266 | |
267 | Standard_Boolean LocOpe_CSIntersector::LocalizeBefore |
268 | (const Standard_Integer I, |
269 | const Standard_Real From, |
270 | const Standard_Real Tol, |
271 | TopAbs_Orientation& Or, |
272 | Standard_Integer& IndFrom, |
273 | Standard_Integer& IndTo) const |
274 | { |
275 | if (!myDone) { |
9775fa61 |
276 | throw StdFail_NotDone(); |
7fd59977 |
277 | } |
278 | if (I <= 0 || I > myNbelem) { |
9775fa61 |
279 | throw Standard_OutOfRange(); |
7fd59977 |
280 | } |
281 | return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1], |
282 | From,Tol,Or,IndFrom,IndTo); |
283 | } |
284 | |
285 | //======================================================================= |
286 | //function : LocalizeAfter |
287 | //purpose : |
288 | //======================================================================= |
289 | |
290 | Standard_Boolean LocOpe_CSIntersector::LocalizeAfter |
291 | (const Standard_Integer I, |
292 | const Standard_Integer FromInd, |
293 | const Standard_Real Tol, |
294 | TopAbs_Orientation& Or, |
295 | Standard_Integer& IndFrom, |
296 | Standard_Integer& IndTo) const |
297 | { |
298 | if (!myDone) { |
9775fa61 |
299 | throw StdFail_NotDone(); |
7fd59977 |
300 | } |
301 | if (I <= 0 || I > myNbelem) { |
9775fa61 |
302 | throw Standard_OutOfRange(); |
7fd59977 |
303 | } |
304 | return LocAfter(((LocOpe_SequenceOfPntFace*)myPoints)[I-1], |
305 | FromInd,Tol,Or,IndFrom,IndTo); |
306 | |
307 | } |
308 | |
309 | //======================================================================= |
310 | //function : LocalizeBefore |
311 | //purpose : |
312 | //======================================================================= |
313 | |
314 | Standard_Boolean LocOpe_CSIntersector::LocalizeBefore |
315 | (const Standard_Integer I, |
316 | const Standard_Integer FromInd, |
317 | const Standard_Real Tol, |
318 | TopAbs_Orientation& Or, |
319 | Standard_Integer& IndFrom, |
320 | Standard_Integer& IndTo) const |
321 | { |
322 | if (!myDone) { |
9775fa61 |
323 | throw StdFail_NotDone(); |
7fd59977 |
324 | } |
325 | if (I <= 0 || I > myNbelem) { |
9775fa61 |
326 | throw Standard_OutOfRange(); |
7fd59977 |
327 | } |
328 | return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1], |
329 | FromInd,Tol,Or,IndFrom,IndTo); |
330 | |
331 | } |
332 | |
333 | |
334 | |
335 | |
336 | //======================================================================= |
337 | //function : LocAfter |
338 | //purpose : |
339 | //======================================================================= |
340 | |
341 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace& Spt, |
342 | const Standard_Real From, |
343 | const Standard_Real Tol, |
344 | TopAbs_Orientation& Or, |
345 | Standard_Integer& IndFrom, |
346 | Standard_Integer& IndTo) |
347 | { |
348 | |
349 | Standard_Real param,FMEPS = From - Tol; |
350 | Standard_Integer i,ifirst,nbpoints = Spt.Length(); |
351 | for (ifirst=1; ifirst<=nbpoints; ifirst++) { |
352 | if (Spt(ifirst).Parameter() >= FMEPS) { |
353 | break; |
354 | } |
355 | } |
356 | Standard_Boolean RetVal = Standard_False; |
357 | if (ifirst <= nbpoints) { |
358 | i = ifirst; |
359 | IndFrom = ifirst; |
360 | Standard_Boolean found = Standard_False; |
361 | while (!found) { |
362 | Or = Spt(i).Orientation(); |
363 | param = Spt(i).Parameter(); |
364 | i = i+1; |
365 | while (i<=nbpoints) { |
366 | if (Spt(i).Parameter()-param <= Tol) { |
367 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
368 | Or = TopAbs_EXTERNAL; |
369 | } |
370 | i++; |
371 | } |
372 | else { |
373 | break; |
374 | } |
375 | } |
376 | if (Or == TopAbs_EXTERNAL) { |
377 | found = (i > nbpoints); |
378 | IndFrom = i; |
379 | } |
380 | else { // on a une intersection franche |
381 | IndTo = i-1; |
382 | found = Standard_True; |
383 | RetVal = Standard_True; |
384 | } |
385 | } |
386 | } |
387 | |
388 | return RetVal; |
389 | } |
390 | |
391 | //======================================================================= |
392 | //function : LocBefore |
393 | //purpose : |
394 | //======================================================================= |
395 | |
396 | static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace& Spt, |
397 | const Standard_Real From, |
398 | const Standard_Real Tol, |
399 | TopAbs_Orientation& Or, |
400 | Standard_Integer& IndFrom, |
401 | Standard_Integer& IndTo) |
402 | { |
403 | Standard_Real param,FPEPS = From + Tol; |
404 | Standard_Integer i,ifirst,nbpoints = Spt.Length(); |
405 | for (ifirst=nbpoints; ifirst>=1; ifirst--) { |
406 | if (Spt(ifirst).Parameter() <= FPEPS) { |
407 | break; |
408 | } |
409 | } |
410 | Standard_Boolean RetVal = Standard_False; |
411 | if (ifirst >= 1) { |
412 | i = ifirst; |
413 | IndTo = ifirst; |
414 | Standard_Boolean found = Standard_False; |
415 | while (!found) { |
416 | Or = Spt(i).Orientation(); |
417 | param = Spt(i).Parameter(); |
418 | i = i-1; |
419 | while (i>=1) { |
420 | if (param - Spt(i).Parameter() <= Tol) { |
421 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
422 | Or = TopAbs_EXTERNAL; |
423 | } |
424 | i--; |
425 | } |
426 | else { |
427 | break; |
428 | } |
429 | } |
430 | if (Or == TopAbs_EXTERNAL) { |
431 | found = (i < 1); |
432 | IndTo = i; |
433 | } |
434 | else { // on a une intersection franche |
435 | IndFrom = i+1; |
436 | found = Standard_True; |
437 | RetVal = Standard_True; |
438 | } |
439 | } |
440 | } |
441 | |
442 | return RetVal; |
443 | } |
444 | |
445 | //======================================================================= |
446 | //function : LocAfter |
447 | //purpose : |
448 | //======================================================================= |
449 | |
450 | static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace& Spt, |
451 | const Standard_Integer FromInd, |
452 | const Standard_Real Tol, |
453 | TopAbs_Orientation& Or, |
454 | Standard_Integer& IndFrom, |
455 | Standard_Integer& IndTo) |
456 | { |
457 | Standard_Integer nbpoints = Spt.Length(); |
458 | if (FromInd >= nbpoints) { |
459 | return Standard_False; |
460 | } |
461 | |
462 | Standard_Real param,FMEPS; |
463 | Standard_Integer i,ifirst; |
464 | if (FromInd >= 1) { |
465 | FMEPS = Spt(FromInd).Parameter() - Tol; |
466 | for (ifirst=FromInd+1; ifirst<=nbpoints; ifirst++) { |
467 | if (Spt(ifirst).Parameter() >= FMEPS) { |
468 | break; |
469 | } |
470 | } |
471 | } |
472 | else { |
473 | ifirst = 1; |
474 | } |
475 | |
476 | Standard_Boolean RetVal = Standard_False; |
477 | if (ifirst <= nbpoints) { |
478 | i = ifirst; |
479 | IndFrom = ifirst; |
480 | Standard_Boolean found = Standard_False; |
481 | while (!found) { |
482 | Or = Spt(i).Orientation(); |
483 | param = Spt(i).Parameter(); |
484 | i = i+1; |
485 | while (i<=nbpoints) { |
486 | if (Spt(i).Parameter()-param <= Tol) { |
487 | if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) { |
488 | Or = TopAbs_EXTERNAL; |
489 | } |
490 | i++; |
491 | } |
492 | else { |
493 | break; |
494 | } |
495 | } |
496 | if (Or == TopAbs_EXTERNAL) { |
497 | found = (i > nbpoints); |
498 | IndFrom = i; |
499 | } |
500 | else { // on a une intersection franche |
501 | IndTo = i-1; |
502 | found = Standard_True; |
503 | RetVal = Standard_True; |
504 | } |
505 | } |
506 | } |
507 | return RetVal; |
508 | } |
509 | |
7fd59977 |
510 | //======================================================================= |
511 | //function : AddPoints |
512 | //purpose : |
513 | //======================================================================= |
514 | |
515 | static void AddPoints(IntCurvesFace_Intersector& theInt, |
516 | LocOpe_SequenceOfPntFace& theSeq, |
517 | const TopoDS_Face& theface) |
518 | { |
519 | Standard_Integer nbpoints = theSeq.Length(); |
520 | Standard_Integer newpnt = theInt.NbPnt(); |
521 | Standard_Real param,paramu,paramv; |
7fd59977 |
522 | for (Standard_Integer j = 1; j<=newpnt; j++) { |
523 | const gp_Pnt& thept = theInt.Pnt(j); |
524 | param = theInt.WParameter(j); |
525 | paramu = theInt.UParameter(j); |
526 | paramv = theInt.VParameter(j); |
1d47d8d0 |
527 | |
7fd59977 |
528 | TopAbs_Orientation theor=TopAbs_FORWARD; |
1d47d8d0 |
529 | |
7fd59977 |
530 | switch (theInt.Transition(j)) { |
531 | case IntCurveSurface_In: |
532 | /* JAG 13.09.96 |
533 | if ( orface == TopAbs_FORWARD) { |
534 | theor = TopAbs_FORWARD; |
535 | } |
536 | else if (orface == TopAbs_REVERSED) { |
537 | theor = TopAbs_REVERSED; |
538 | } |
539 | else { |
540 | theor = TopAbs_EXTERNAL; |
541 | } |
542 | */ |
543 | theor = TopAbs_FORWARD; |
544 | |
545 | break; |
546 | case IntCurveSurface_Out: |
547 | /* JAG 13.09.96 |
548 | if ( orface == TopAbs_FORWARD) { |
549 | theor = TopAbs_REVERSED; |
550 | } |
551 | else if (orface == TopAbs_REVERSED) { |
552 | theor = TopAbs_FORWARD; |
553 | } |
554 | else { |
555 | theor = TopAbs_EXTERNAL; |
556 | } |
557 | */ |
558 | theor = TopAbs_REVERSED; |
559 | break; |
560 | case IntCurveSurface_Tangent: |
561 | theor = TopAbs_EXTERNAL; |
562 | break; |
563 | |
564 | } |
565 | LocOpe_PntFace newpt(thept,theface,theor,param,paramu,paramv); |
566 | // for (Standard_Integer k=1; k <= nbpoints; k++) { |
567 | Standard_Integer k; |
568 | for ( k=1; k <= nbpoints; k++) { |
569 | if (theSeq(k).Parameter() - param > 0.) { |
570 | break; |
571 | } |
572 | } |
573 | if (k <= nbpoints) { |
574 | theSeq.InsertBefore(k,newpt); |
575 | } |
576 | else { |
577 | theSeq.Append(newpt); |
578 | } |
579 | nbpoints++; |
580 | } |
581 | } |