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