1 // Created on: 1995-05-29
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-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_CurveShapeIntersector.ixx>
25 #include <BRepIntCurveSurface_Inter.hxx>
26 #include <Geom_Circle.hxx>
28 #include <LocOpe_PntFace.hxx>
31 #include <Precision.hxx>
34 static void Perform(BRepIntCurveSurface_Inter&,
35 LocOpe_SequenceOfPntFace&);
38 //=======================================================================
41 //=======================================================================
43 void LocOpe_CurveShapeIntersector::Init(const gp_Ax1& Axis,
44 const TopoDS_Shape& S)
46 myDone = Standard_False;
51 Standard_Real Tol = Precision::Confusion();
53 BRepIntCurveSurface_Inter theInt;
54 theInt.Init(S,gp_Lin(Axis),Tol);
55 Perform(theInt,myPoints);
56 myDone = Standard_True;
60 //=======================================================================
63 //=======================================================================
65 void LocOpe_CurveShapeIntersector::Init(const gp_Circ& C,
66 const TopoDS_Shape& S)
68 myDone = Standard_False;
73 Standard_Real Tol = Precision::Confusion();
75 Handle(Geom_Circle) GC = new Geom_Circle(C);
76 GeomAdaptor_Curve AC(GC,0.,2.*M_PI);
78 BRepIntCurveSurface_Inter theInt;
79 theInt.Init(S,AC,Tol);
81 Perform(theInt,myPoints);
82 myDone = Standard_True;
86 //=======================================================================
87 //function : LocalizeAfter
89 //=======================================================================
91 Standard_Boolean LocOpe_CurveShapeIntersector::LocalizeAfter
92 (const Standard_Real From,
93 TopAbs_Orientation& Or,
94 Standard_Integer& IndFrom,
95 Standard_Integer& IndTo) const
98 StdFail_NotDone::Raise();
100 Standard_Real Eps = Precision::Confusion();
101 Standard_Real param,FMEPS = From - Eps;
102 Standard_Integer i,ifirst,nbpoints = myPoints.Length();
103 for (ifirst=1; ifirst<=nbpoints; ifirst++) {
104 if (myPoints(ifirst).Parameter() >= FMEPS) {
108 Standard_Boolean RetVal = Standard_False;
109 if (ifirst <= nbpoints) {
112 Standard_Boolean found = Standard_False;
114 Or = myPoints(i).Orientation();
115 param = myPoints(i).Parameter();
117 while (i<=nbpoints) {
118 if (myPoints(i).Parameter()-param <= Eps) {
119 if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation()) {
120 Or = TopAbs_EXTERNAL;
128 if (Or == TopAbs_EXTERNAL) {
129 found = (i > nbpoints);
132 else { // on a une intersection franche
134 found = Standard_True;
135 RetVal = Standard_True;
143 //=======================================================================
144 //function : LocalizeBefore
146 //=======================================================================
148 Standard_Boolean LocOpe_CurveShapeIntersector::LocalizeBefore
149 (const Standard_Real From,
150 TopAbs_Orientation& Or,
151 Standard_Integer& IndFrom,
152 Standard_Integer& IndTo) const
155 StdFail_NotDone::Raise();
157 Standard_Real Eps = Precision::Confusion();
158 Standard_Real param,FPEPS = From + Eps;
159 Standard_Integer i,ifirst,nbpoints = myPoints.Length();
160 for (ifirst=nbpoints; ifirst>=1; ifirst--) {
161 if (myPoints(ifirst).Parameter() <= FPEPS) {
165 Standard_Boolean RetVal = Standard_False;
169 Standard_Boolean found = Standard_False;
171 Or = myPoints(i).Orientation();
172 param = myPoints(i).Parameter();
175 if (param - myPoints(i).Parameter() <= Eps) {
176 if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation()) {
177 Or = TopAbs_EXTERNAL;
185 if (Or == TopAbs_EXTERNAL) {
189 else { // on a une intersection franche
191 found = Standard_True;
192 RetVal = Standard_True;
200 //=======================================================================
201 //function : LocalizeAfter
203 //=======================================================================
205 Standard_Boolean LocOpe_CurveShapeIntersector::LocalizeAfter
206 (const Standard_Integer FromInd,
207 TopAbs_Orientation& Or,
208 Standard_Integer& IndFrom,
209 Standard_Integer& IndTo) const
212 StdFail_NotDone::Raise();
214 Standard_Integer nbpoints = myPoints.Length();
215 if (FromInd >= nbpoints) {
216 return Standard_False;
219 Standard_Real Eps = Precision::Confusion();
220 Standard_Real param,FMEPS;
221 Standard_Integer i,ifirst;
223 FMEPS = myPoints(FromInd).Parameter() - Eps;
224 for (ifirst=FromInd+1; ifirst<=nbpoints; ifirst++) {
225 if (myPoints(ifirst).Parameter() >= FMEPS) {
234 Standard_Boolean RetVal = Standard_False;
235 if (ifirst <= nbpoints) {
238 Standard_Boolean found = Standard_False;
240 Or = myPoints(i).Orientation();
241 param = myPoints(i).Parameter();
243 while (i<=nbpoints) {
244 if (myPoints(i).Parameter()-param <= Eps) {
245 if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation()) {
246 Or = TopAbs_EXTERNAL;
254 if (Or == TopAbs_EXTERNAL) {
255 found = (i > nbpoints);
258 else { // on a une intersection franche
260 found = Standard_True;
261 RetVal = Standard_True;
269 //=======================================================================
270 //function : LocalizeBefore
272 //=======================================================================
274 Standard_Boolean LocOpe_CurveShapeIntersector::LocalizeBefore
275 (const Standard_Integer FromInd,
276 TopAbs_Orientation& Or,
277 Standard_Integer& IndFrom,
278 Standard_Integer& IndTo) const
281 StdFail_NotDone::Raise();
283 Standard_Integer nbpoints = myPoints.Length();
285 return Standard_False;
288 Standard_Real Eps = Precision::Confusion();
289 Standard_Real param,FPEPS;
290 Standard_Integer i,ifirst;
291 if (FromInd <= nbpoints) {
292 FPEPS = myPoints(FromInd).Parameter() + Eps;
293 for (ifirst=FromInd-1; ifirst>=1; ifirst--) {
294 if (myPoints(ifirst).Parameter() <= FPEPS) {
303 Standard_Boolean RetVal = Standard_False;
307 Standard_Boolean found = Standard_False;
309 Or = myPoints(i).Orientation();
310 param = myPoints(i).Parameter();
313 if (param - myPoints(i).Parameter() <= Eps) {
314 if (Or != TopAbs_EXTERNAL && Or != myPoints(i).Orientation()) {
315 Or = TopAbs_EXTERNAL;
323 if (Or == TopAbs_EXTERNAL) {
327 else { // on a une intersection franche
329 found = Standard_True;
330 RetVal = Standard_True;
338 //=======================================================================
341 //=======================================================================
343 static void Perform(BRepIntCurveSurface_Inter & theInt,
344 LocOpe_SequenceOfPntFace& thePoints)
346 Standard_Real param,paramu,paramv;
347 Standard_Integer i, nbpoints=0;
349 TopAbs_Orientation theor=TopAbs_FORWARD, orface;
351 while (theInt.More()) {
352 const gp_Pnt& thept = theInt.Pnt();
353 const TopoDS_Face& theface = theInt.Face();
354 orface = theface.Orientation();
359 switch (theInt.Transition()) {
360 case IntCurveSurface_In:
361 if ( orface == TopAbs_FORWARD) {
362 theor = TopAbs_FORWARD;
364 else if (orface == TopAbs_REVERSED) {
365 theor = TopAbs_REVERSED;
368 theor = TopAbs_EXTERNAL;
371 case IntCurveSurface_Out:
372 if ( orface == TopAbs_FORWARD) {
373 theor = TopAbs_REVERSED;
375 else if (orface == TopAbs_REVERSED) {
376 theor = TopAbs_FORWARD;
379 theor = TopAbs_EXTERNAL;
382 case IntCurveSurface_Tangent:
383 theor = TopAbs_EXTERNAL;
388 LocOpe_PntFace newpt(thept,theface,theor,param,paramu,paramv);
390 for (i=1; i <= nbpoints; i++) {
391 if (thePoints(i).Parameter() - param > 0.) {
396 thePoints.InsertBefore(i,newpt);
399 thePoints.Append(newpt);