1 // File: LocOpe_CSIntersector.lxx
2 // Created: Tue Jun 11 09:11:57 1996
3 // Author: Jacques GOUSSARD
7 #include <LocOpe_CSIntersector.ixx>
9 #include <LocOpe_PntFace.hxx>
10 #include <LocOpe_SequenceOfPntFace.hxx>
11 #include <TopExp_Explorer.hxx>
13 #include <IntCurvesFace_Intersector.hxx>
14 #include <GeomAdaptor_HCurve.hxx>
15 #include <Geom_Circle.hxx>
18 #include <Standard_ConstructionError.hxx>
21 #include <Precision.hxx>
23 static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&,
30 static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&,
37 static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&,
38 const Standard_Integer,
45 static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&,
46 const Standard_Integer,
52 static void AddPoints(IntCurvesFace_Intersector&,
53 LocOpe_SequenceOfPntFace&,
59 //=======================================================================
62 //=======================================================================
64 void LocOpe_CSIntersector::Init(const TopoDS_Shape& S)
66 myDone = Standard_False;
68 if (myPoints != NULL) {
69 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
76 //=======================================================================
79 //=======================================================================
81 void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfLin& Slin)
83 if (myShape.IsNull() || Slin.Length() <= 0) {
84 Standard_ConstructionError::Raise();
86 myDone = Standard_False;
88 myNbelem = Slin.Length();
89 if (myPoints != NULL) {
90 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
93 (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem];
95 Standard_Real binf = RealFirst();
96 Standard_Real bsup = RealLast();
97 TopExp_Explorer exp(myShape,TopAbs_FACE);
98 for (; exp.More(); exp.Next()) {
99 const TopoDS_Face& theface = TopoDS::Face(exp.Current());
100 IntCurvesFace_Intersector theInt(theface,Precision::PConfusion());
101 for (Standard_Integer i = 1; i<=myNbelem; i++) {
102 theInt.Perform(Slin(i),binf,bsup);
103 if (theInt.IsDone()) {
104 AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface);
108 myDone = Standard_True;
112 //=======================================================================
115 //=======================================================================
117 void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfCirc& Scir)
119 if (myShape.IsNull() || Scir.Length() <= 0) {
120 Standard_ConstructionError::Raise();
122 myDone = Standard_False;
124 myNbelem = Scir.Length();
125 if (myPoints != NULL) {
126 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
129 (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem];
131 TopExp_Explorer exp(myShape,TopAbs_FACE);
132 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve ();
133 Standard_Real binf = 0.;
134 Standard_Real bsup = 2.*PI;
137 for (; exp.More(); exp.Next()) {
138 const TopoDS_Face& theface = TopoDS::Face(exp.Current());
139 IntCurvesFace_Intersector theInt(theface,0.);
141 TopAbs_Orientation orface =
143 theface.Orientation();
144 for (Standard_Integer i = 1; i<=myNbelem; i++) {
146 HC->ChangeCurve().Load(new Geom_Circle(Scir(i)));
147 theInt.Perform(HC,binf,bsup);
148 if (theInt.IsDone()) {
149 AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface);
153 myDone = Standard_True;
158 //=======================================================================
161 //=======================================================================
163 void LocOpe_CSIntersector::Perform(const TColGeom_SequenceOfCurve& Scur)
165 if (myShape.IsNull() || Scur.Length() <= 0) {
166 Standard_ConstructionError::Raise();
168 myDone = Standard_False;
170 myNbelem = Scur.Length();
171 if (myPoints != NULL) {
172 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
175 (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem];
177 TopExp_Explorer exp(myShape,TopAbs_FACE);
178 Handle(GeomAdaptor_HCurve) HC = new GeomAdaptor_HCurve ();
179 for (; exp.More(); exp.Next()) {
180 const TopoDS_Face& theface = TopoDS::Face(exp.Current());
181 IntCurvesFace_Intersector theInt(theface,0.);
183 TopAbs_Orientation orface =
185 theface.Orientation();
186 for (Standard_Integer i = 1; i<=myNbelem; i++) {
187 if (Scur(i).IsNull()) {
190 HC->ChangeCurve().Load(Scur(i));
191 Standard_Real binf = HC->FirstParameter();
192 Standard_Real bsup = HC->LastParameter();
193 theInt.Perform(HC,binf,bsup);
194 if (theInt.IsDone()) {
195 AddPoints(theInt,(((LocOpe_SequenceOfPntFace*)myPoints)[i-1]),theface);
199 myDone = Standard_True;
204 //=======================================================================
205 //function : NbPoints
207 //=======================================================================
209 Standard_Integer LocOpe_CSIntersector::NbPoints
210 (const Standard_Integer I) const
212 if (!myDone) {StdFail_NotDone::Raise();}
213 if (I <= 0 || I > myNbelem) {
214 Standard_OutOfRange::Raise();
216 return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1].Length();
219 //=======================================================================
222 //=======================================================================
224 const LocOpe_PntFace& LocOpe_CSIntersector::
225 Point(const Standard_Integer I,
226 const Standard_Integer Index) const
228 if (!myDone) {StdFail_NotDone::Raise();}
229 if (I <= 0 || I > myNbelem) {
230 Standard_OutOfRange::Raise();
232 return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1](Index);
235 //=======================================================================
238 //=======================================================================
240 void LocOpe_CSIntersector::Destroy()
242 if (myPoints != NULL) {
243 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
249 //=======================================================================
250 //function : LocalizeAfter
252 //=======================================================================
254 Standard_Boolean LocOpe_CSIntersector::LocalizeAfter
255 (const Standard_Integer I,
256 const Standard_Real From,
257 const Standard_Real Tol,
258 TopAbs_Orientation& Or,
259 Standard_Integer& IndFrom,
260 Standard_Integer& IndTo) const
263 StdFail_NotDone::Raise();
265 if (I <= 0 || I > myNbelem) {
266 Standard_OutOfRange::Raise();
268 return LocAfter((((LocOpe_SequenceOfPntFace*)myPoints)[I-1]),
269 From,Tol,Or,IndFrom,IndTo);
273 //=======================================================================
274 //function : LocalizeBefore
276 //=======================================================================
278 Standard_Boolean LocOpe_CSIntersector::LocalizeBefore
279 (const Standard_Integer I,
280 const Standard_Real From,
281 const Standard_Real Tol,
282 TopAbs_Orientation& Or,
283 Standard_Integer& IndFrom,
284 Standard_Integer& IndTo) const
287 StdFail_NotDone::Raise();
289 if (I <= 0 || I > myNbelem) {
290 Standard_OutOfRange::Raise();
292 return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1],
293 From,Tol,Or,IndFrom,IndTo);
296 //=======================================================================
297 //function : LocalizeAfter
299 //=======================================================================
301 Standard_Boolean LocOpe_CSIntersector::LocalizeAfter
302 (const Standard_Integer I,
303 const Standard_Integer FromInd,
304 const Standard_Real Tol,
305 TopAbs_Orientation& Or,
306 Standard_Integer& IndFrom,
307 Standard_Integer& IndTo) const
310 StdFail_NotDone::Raise();
312 if (I <= 0 || I > myNbelem) {
313 Standard_OutOfRange::Raise();
315 return LocAfter(((LocOpe_SequenceOfPntFace*)myPoints)[I-1],
316 FromInd,Tol,Or,IndFrom,IndTo);
320 //=======================================================================
321 //function : LocalizeBefore
323 //=======================================================================
325 Standard_Boolean LocOpe_CSIntersector::LocalizeBefore
326 (const Standard_Integer I,
327 const Standard_Integer FromInd,
328 const Standard_Real Tol,
329 TopAbs_Orientation& Or,
330 Standard_Integer& IndFrom,
331 Standard_Integer& IndTo) const
334 StdFail_NotDone::Raise();
336 if (I <= 0 || I > myNbelem) {
337 Standard_OutOfRange::Raise();
339 return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1],
340 FromInd,Tol,Or,IndFrom,IndTo);
347 //=======================================================================
348 //function : LocAfter
350 //=======================================================================
352 static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace& Spt,
353 const Standard_Real From,
354 const Standard_Real Tol,
355 TopAbs_Orientation& Or,
356 Standard_Integer& IndFrom,
357 Standard_Integer& IndTo)
360 Standard_Real param,FMEPS = From - Tol;
361 Standard_Integer i,ifirst,nbpoints = Spt.Length();
362 for (ifirst=1; ifirst<=nbpoints; ifirst++) {
363 if (Spt(ifirst).Parameter() >= FMEPS) {
367 Standard_Boolean RetVal = Standard_False;
368 if (ifirst <= nbpoints) {
371 Standard_Boolean found = Standard_False;
373 Or = Spt(i).Orientation();
374 param = Spt(i).Parameter();
376 while (i<=nbpoints) {
377 if (Spt(i).Parameter()-param <= Tol) {
378 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
379 Or = TopAbs_EXTERNAL;
387 if (Or == TopAbs_EXTERNAL) {
388 found = (i > nbpoints);
391 else { // on a une intersection franche
393 found = Standard_True;
394 RetVal = Standard_True;
402 //=======================================================================
403 //function : LocBefore
405 //=======================================================================
407 static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace& Spt,
408 const Standard_Real From,
409 const Standard_Real Tol,
410 TopAbs_Orientation& Or,
411 Standard_Integer& IndFrom,
412 Standard_Integer& IndTo)
414 Standard_Real param,FPEPS = From + Tol;
415 Standard_Integer i,ifirst,nbpoints = Spt.Length();
416 for (ifirst=nbpoints; ifirst>=1; ifirst--) {
417 if (Spt(ifirst).Parameter() <= FPEPS) {
421 Standard_Boolean RetVal = Standard_False;
425 Standard_Boolean found = Standard_False;
427 Or = Spt(i).Orientation();
428 param = Spt(i).Parameter();
431 if (param - Spt(i).Parameter() <= Tol) {
432 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
433 Or = TopAbs_EXTERNAL;
441 if (Or == TopAbs_EXTERNAL) {
445 else { // on a une intersection franche
447 found = Standard_True;
448 RetVal = Standard_True;
456 //=======================================================================
457 //function : LocAfter
459 //=======================================================================
461 static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace& Spt,
462 const Standard_Integer FromInd,
463 const Standard_Real Tol,
464 TopAbs_Orientation& Or,
465 Standard_Integer& IndFrom,
466 Standard_Integer& IndTo)
468 Standard_Integer nbpoints = Spt.Length();
469 if (FromInd >= nbpoints) {
470 return Standard_False;
473 Standard_Real param,FMEPS;
474 Standard_Integer i,ifirst;
476 FMEPS = Spt(FromInd).Parameter() - Tol;
477 for (ifirst=FromInd+1; ifirst<=nbpoints; ifirst++) {
478 if (Spt(ifirst).Parameter() >= FMEPS) {
487 Standard_Boolean RetVal = Standard_False;
488 if (ifirst <= nbpoints) {
491 Standard_Boolean found = Standard_False;
493 Or = Spt(i).Orientation();
494 param = Spt(i).Parameter();
496 while (i<=nbpoints) {
497 if (Spt(i).Parameter()-param <= Tol) {
498 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
499 Or = TopAbs_EXTERNAL;
507 if (Or == TopAbs_EXTERNAL) {
508 found = (i > nbpoints);
511 else { // on a une intersection franche
513 found = Standard_True;
514 RetVal = Standard_True;
522 //=======================================================================
523 //function : LocBefore
525 //=======================================================================
528 static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace& Spt,
529 const Standard_Integer FromInd,
530 const Standard_Real Tol,
531 TopAbs_Orientation& Or,
532 Standard_Integer& IndFrom,
533 Standard_Integer& IndTo)
535 Standard_Integer nbpoints = Spt.Length();
537 return Standard_False;
540 Standard_Real param,FPEPS;
541 Standard_Integer i,ifirst;
542 if (FromInd <= nbpoints) {
543 FPEPS = Spt(FromInd).Parameter() + Tol;
544 for (ifirst=FromInd-1; ifirst>=1; ifirst--) {
545 if (Spt(ifirst).Parameter() <= FPEPS) {
554 Standard_Boolean RetVal = Standard_False;
558 Standard_Boolean found = Standard_False;
560 Or = Spt(i).Orientation();
561 param = Spt(i).Parameter();
564 if (param - Spt(i).Parameter() <= Tol) {
565 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
566 Or = TopAbs_EXTERNAL;
574 if (Or == TopAbs_EXTERNAL) {
578 else { // on a une intersection franche
580 found = Standard_True;
581 RetVal = Standard_True;
590 //=======================================================================
591 //function : AddPoints
593 //=======================================================================
595 static void AddPoints(IntCurvesFace_Intersector& theInt,
596 LocOpe_SequenceOfPntFace& theSeq,
597 const TopoDS_Face& theface)
599 Standard_Integer nbpoints = theSeq.Length();
600 Standard_Integer newpnt = theInt.NbPnt();
601 Standard_Real param,paramu,paramv;
603 TopAbs_Orientation orface =
605 theface.Orientation();
606 for (Standard_Integer j = 1; j<=newpnt; j++) {
607 const gp_Pnt& thept = theInt.Pnt(j);
608 param = theInt.WParameter(j);
609 paramu = theInt.UParameter(j);
610 paramv = theInt.VParameter(j);
612 TopAbs_Orientation theor;
614 TopAbs_Orientation theor=TopAbs_FORWARD;
616 switch (theInt.Transition(j)) {
617 case IntCurveSurface_In:
619 if ( orface == TopAbs_FORWARD) {
620 theor = TopAbs_FORWARD;
622 else if (orface == TopAbs_REVERSED) {
623 theor = TopAbs_REVERSED;
626 theor = TopAbs_EXTERNAL;
629 theor = TopAbs_FORWARD;
632 case IntCurveSurface_Out:
634 if ( orface == TopAbs_FORWARD) {
635 theor = TopAbs_REVERSED;
637 else if (orface == TopAbs_REVERSED) {
638 theor = TopAbs_FORWARD;
641 theor = TopAbs_EXTERNAL;
644 theor = TopAbs_REVERSED;
646 case IntCurveSurface_Tangent:
647 theor = TopAbs_EXTERNAL;
651 LocOpe_PntFace newpt(thept,theface,theor,param,paramu,paramv);
652 // for (Standard_Integer k=1; k <= nbpoints; k++) {
654 for ( k=1; k <= nbpoints; k++) {
655 if (theSeq(k).Parameter() - param > 0.) {
660 theSeq.InsertBefore(k,newpt);
663 theSeq.Append(newpt);