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
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.
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.
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.
23 #include <LocOpe_CSIntersector.ixx>
25 #include <LocOpe_PntFace.hxx>
26 #include <LocOpe_SequenceOfPntFace.hxx>
27 #include <TopExp_Explorer.hxx>
29 #include <IntCurvesFace_Intersector.hxx>
30 #include <GeomAdaptor_HCurve.hxx>
31 #include <Geom_Circle.hxx>
34 #include <Standard_ConstructionError.hxx>
37 #include <Precision.hxx>
39 static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&,
46 static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&,
53 static Standard_Boolean LocAfter (const LocOpe_SequenceOfPntFace&,
54 const Standard_Integer,
61 static Standard_Boolean LocBefore (const LocOpe_SequenceOfPntFace&,
62 const Standard_Integer,
68 static void AddPoints(IntCurvesFace_Intersector&,
69 LocOpe_SequenceOfPntFace&,
75 //=======================================================================
78 //=======================================================================
80 void LocOpe_CSIntersector::Init(const TopoDS_Shape& S)
82 myDone = Standard_False;
84 if (myPoints != NULL) {
85 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
92 //=======================================================================
95 //=======================================================================
97 void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfLin& Slin)
99 if (myShape.IsNull() || Slin.Length() <= 0) {
100 Standard_ConstructionError::Raise();
102 myDone = Standard_False;
104 myNbelem = Slin.Length();
105 if (myPoints != NULL) {
106 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
109 (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem];
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);
124 myDone = Standard_True;
128 //=======================================================================
131 //=======================================================================
133 void LocOpe_CSIntersector::Perform(const LocOpe_SequenceOfCirc& Scir)
135 if (myShape.IsNull() || Scir.Length() <= 0) {
136 Standard_ConstructionError::Raise();
138 myDone = Standard_False;
140 myNbelem = Scir.Length();
141 if (myPoints != NULL) {
142 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
145 (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem];
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;
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++) {
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);
165 myDone = Standard_True;
170 //=======================================================================
173 //=======================================================================
175 void LocOpe_CSIntersector::Perform(const TColGeom_SequenceOfCurve& Scur)
177 if (myShape.IsNull() || Scur.Length() <= 0) {
178 Standard_ConstructionError::Raise();
180 myDone = Standard_False;
182 myNbelem = Scur.Length();
183 if (myPoints != NULL) {
184 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
187 (LocOpe_SequenceOfPntFace *) new LocOpe_SequenceOfPntFace[myNbelem];
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()) {
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);
207 myDone = Standard_True;
212 //=======================================================================
213 //function : NbPoints
215 //=======================================================================
217 Standard_Integer LocOpe_CSIntersector::NbPoints
218 (const Standard_Integer I) const
220 if (!myDone) {StdFail_NotDone::Raise();}
221 if (I <= 0 || I > myNbelem) {
222 Standard_OutOfRange::Raise();
224 return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1].Length();
227 //=======================================================================
230 //=======================================================================
232 const LocOpe_PntFace& LocOpe_CSIntersector::
233 Point(const Standard_Integer I,
234 const Standard_Integer Index) const
236 if (!myDone) {StdFail_NotDone::Raise();}
237 if (I <= 0 || I > myNbelem) {
238 Standard_OutOfRange::Raise();
240 return ((LocOpe_SequenceOfPntFace *)myPoints)[I-1](Index);
243 //=======================================================================
246 //=======================================================================
248 void LocOpe_CSIntersector::Destroy()
250 if (myPoints != NULL) {
251 delete [] (LocOpe_SequenceOfPntFace *)myPoints;
257 //=======================================================================
258 //function : LocalizeAfter
260 //=======================================================================
262 Standard_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
271 StdFail_NotDone::Raise();
273 if (I <= 0 || I > myNbelem) {
274 Standard_OutOfRange::Raise();
276 return LocAfter((((LocOpe_SequenceOfPntFace*)myPoints)[I-1]),
277 From,Tol,Or,IndFrom,IndTo);
281 //=======================================================================
282 //function : LocalizeBefore
284 //=======================================================================
286 Standard_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
295 StdFail_NotDone::Raise();
297 if (I <= 0 || I > myNbelem) {
298 Standard_OutOfRange::Raise();
300 return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1],
301 From,Tol,Or,IndFrom,IndTo);
304 //=======================================================================
305 //function : LocalizeAfter
307 //=======================================================================
309 Standard_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
318 StdFail_NotDone::Raise();
320 if (I <= 0 || I > myNbelem) {
321 Standard_OutOfRange::Raise();
323 return LocAfter(((LocOpe_SequenceOfPntFace*)myPoints)[I-1],
324 FromInd,Tol,Or,IndFrom,IndTo);
328 //=======================================================================
329 //function : LocalizeBefore
331 //=======================================================================
333 Standard_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
342 StdFail_NotDone::Raise();
344 if (I <= 0 || I > myNbelem) {
345 Standard_OutOfRange::Raise();
347 return LocBefore(((LocOpe_SequenceOfPntFace*)myPoints)[I-1],
348 FromInd,Tol,Or,IndFrom,IndTo);
355 //=======================================================================
356 //function : LocAfter
358 //=======================================================================
360 static 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)
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) {
375 Standard_Boolean RetVal = Standard_False;
376 if (ifirst <= nbpoints) {
379 Standard_Boolean found = Standard_False;
381 Or = Spt(i).Orientation();
382 param = Spt(i).Parameter();
384 while (i<=nbpoints) {
385 if (Spt(i).Parameter()-param <= Tol) {
386 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
387 Or = TopAbs_EXTERNAL;
395 if (Or == TopAbs_EXTERNAL) {
396 found = (i > nbpoints);
399 else { // on a une intersection franche
401 found = Standard_True;
402 RetVal = Standard_True;
410 //=======================================================================
411 //function : LocBefore
413 //=======================================================================
415 static 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)
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) {
429 Standard_Boolean RetVal = Standard_False;
433 Standard_Boolean found = Standard_False;
435 Or = Spt(i).Orientation();
436 param = Spt(i).Parameter();
439 if (param - Spt(i).Parameter() <= Tol) {
440 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
441 Or = TopAbs_EXTERNAL;
449 if (Or == TopAbs_EXTERNAL) {
453 else { // on a une intersection franche
455 found = Standard_True;
456 RetVal = Standard_True;
464 //=======================================================================
465 //function : LocAfter
467 //=======================================================================
469 static 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)
476 Standard_Integer nbpoints = Spt.Length();
477 if (FromInd >= nbpoints) {
478 return Standard_False;
481 Standard_Real param,FMEPS;
482 Standard_Integer i,ifirst;
484 FMEPS = Spt(FromInd).Parameter() - Tol;
485 for (ifirst=FromInd+1; ifirst<=nbpoints; ifirst++) {
486 if (Spt(ifirst).Parameter() >= FMEPS) {
495 Standard_Boolean RetVal = Standard_False;
496 if (ifirst <= nbpoints) {
499 Standard_Boolean found = Standard_False;
501 Or = Spt(i).Orientation();
502 param = Spt(i).Parameter();
504 while (i<=nbpoints) {
505 if (Spt(i).Parameter()-param <= Tol) {
506 if (Or != TopAbs_EXTERNAL && Or != Spt(i).Orientation()) {
507 Or = TopAbs_EXTERNAL;
515 if (Or == TopAbs_EXTERNAL) {
516 found = (i > nbpoints);
519 else { // on a une intersection franche
521 found = Standard_True;
522 RetVal = Standard_True;
529 //=======================================================================
530 //function : AddPoints
532 //=======================================================================
534 static void AddPoints(IntCurvesFace_Intersector& theInt,
535 LocOpe_SequenceOfPntFace& theSeq,
536 const TopoDS_Face& theface)
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);
547 TopAbs_Orientation theor;
549 TopAbs_Orientation theor=TopAbs_FORWARD;
551 switch (theInt.Transition(j)) {
552 case IntCurveSurface_In:
554 if ( orface == TopAbs_FORWARD) {
555 theor = TopAbs_FORWARD;
557 else if (orface == TopAbs_REVERSED) {
558 theor = TopAbs_REVERSED;
561 theor = TopAbs_EXTERNAL;
564 theor = TopAbs_FORWARD;
567 case IntCurveSurface_Out:
569 if ( orface == TopAbs_FORWARD) {
570 theor = TopAbs_REVERSED;
572 else if (orface == TopAbs_REVERSED) {
573 theor = TopAbs_FORWARD;
576 theor = TopAbs_EXTERNAL;
579 theor = TopAbs_REVERSED;
581 case IntCurveSurface_Tangent:
582 theor = TopAbs_EXTERNAL;
586 LocOpe_PntFace newpt(thept,theface,theor,param,paramu,paramv);
587 // for (Standard_Integer k=1; k <= nbpoints; k++) {
589 for ( k=1; k <= nbpoints; k++) {
590 if (theSeq(k).Parameter() - param > 0.) {
595 theSeq.InsertBefore(k,newpt);
598 theSeq.Append(newpt);