0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / BRepIntCurveSurface / BRepIntCurveSurface_Inter.cxx
1 // Created on: 1994-02-07
2 // Created by: Modelistation
3 // Copyright (c) 1994-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17 #include <BRepIntCurveSurface_Inter.hxx>
18
19 #include <Bnd_Box.hxx>
20 #include <BndLib_Add3dCurve.hxx>
21 #include <BRepAdaptor_Surface.hxx>
22 #include <BRepBndLib.hxx>
23 #include <BRepTopAdaptor_TopolTool.hxx>
24 #include <Geom_Line.hxx>
25 #include <GeomAdaptor_Curve.hxx>
26 #include <gp_Lin.hxx>
27 #include <gp_Pnt.hxx>
28 #include <IntCurveSurface_IntersectionPoint.hxx>
29 #include <StdFail_NotDone.hxx>
30 #include <TopAbs_ShapeEnum.hxx>
31 #include <TopoDS.hxx>
32 #include <TopoDS_Face.hxx>
33 #include <TopoDS_Shape.hxx>
34
35 //===========================================================================
36 //function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte
37 //purpose  : 
38 //===========================================================================
39 BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter()
40 {
41   myFastClass = new  BRepTopAdaptor_TopolTool();
42   Clear();
43 }
44
45 //===========================================================================
46 //function :Init
47 //purpose  : 
48 //===========================================================================
49
50 void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& theShape,
51                                      const GeomAdaptor_Curve& theCurve,
52                                      const Standard_Real theTol) 
53
54   Load(theShape, theTol);
55   Init(theCurve);
56 }
57
58 //===========================================================================
59 //function :Init
60 //purpose  : 
61 //===========================================================================
62
63 void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& theShape,
64                                      const gp_Lin&       theLine,
65                                      const Standard_Real theTol) 
66
67  
68   Handle(Geom_Line) geomline = new Geom_Line(theLine);
69   GeomAdaptor_Curve aCurve(geomline);
70   Load(theShape, theTol);
71   Init(aCurve);
72   
73 }
74
75 //===========================================================================
76 //function :Clear
77 //purpose  : 
78 //===========================================================================
79
80 void BRepIntCurveSurface_Inter::Clear()
81 {  
82   myCurrentindex = 0;
83   myCurrentnbpoints = 0;
84   myIndFace = 0;
85   myCurrentstate = TopAbs_UNKNOWN;
86   myCurrentU = 0;
87   myCurrentV = 0;
88
89 }
90
91 //===========================================================================
92 //function :Load
93 //purpose  : 
94 //===========================================================================
95
96 void BRepIntCurveSurface_Inter::Load(const TopoDS_Shape& theShape ,const Standard_Real theTol)
97 {
98   Clear();
99   myFaces.Clear();
100   myFaceBoxes.Nullify();
101   myTolerance = theTol;
102   TopExp_Explorer explorer(theShape,TopAbs_FACE);
103   for( ; explorer.More(); explorer.Next())
104     myFaces.Append(explorer.Current());
105
106 }
107
108 //===========================================================================
109 //function :Init
110 //purpose  : 
111 //===========================================================================
112
113 void BRepIntCurveSurface_Inter::Init(const GeomAdaptor_Curve& theCurve )
114 {
115   Clear();
116   myCurveBox.SetVoid();
117   Standard_Real aFirst =  theCurve.FirstParameter();
118   Standard_Real aLast =   theCurve.LastParameter();
119   myCurve = new GeomAdaptor_Curve(theCurve );
120   if( !Precision::IsInfinite(aFirst) && !Precision::IsInfinite(aLast) )
121   {
122     BndLib_Add3dCurve::Add (*myCurve, 0., myCurveBox);
123   }
124   Find();
125 }
126
127 //===========================================================================
128 //function :More
129 //purpose  : 
130 //===========================================================================
131 Standard_Boolean BRepIntCurveSurface_Inter::More() const 
132 {
133   return (myIndFace <= myFaces.Length()  );
134 }
135
136 //===========================================================================
137 //function :Next
138 //purpose  : 
139 //===========================================================================
140 void BRepIntCurveSurface_Inter::Next() 
141
142   if(myCurrentnbpoints)
143     myCurrentindex++;
144   Find();
145 }
146
147 //===========================================================================
148 //function :Find
149 //purpose  : 
150 //===========================================================================
151 void BRepIntCurveSurface_Inter::Find() 
152
153   if(myCurrentnbpoints && myCurrentindex <= myCurrentnbpoints && FindPoint())
154     return;
155   
156   myCurrentnbpoints = 0;
157   myCurrentindex = 0;
158
159   Standard_Integer i = myIndFace +1;
160   for( ; i <= myFaces.Length(); i++)
161   {
162     TopoDS_Shape aCurface= myFaces(i);       
163     if( myFaceBoxes.IsNull())
164       myFaceBoxes = new Bnd_HArray1OfBox(1, myFaces.Length());
165     Bnd_Box& aFaceBox  = myFaceBoxes->ChangeValue(i);
166     if( aFaceBox.IsVoid())
167     {
168       BRepBndLib::Add(aCurface, aFaceBox);
169       aFaceBox.SetGap(myTolerance);//Precision::Confusion());
170     }
171     Standard_Boolean isOut = ( myCurve->GetType() == GeomAbs_Line ? aFaceBox.IsOut(myCurve->Line()) :
172       ( !myCurveBox.IsVoid() ? aFaceBox.IsOut(myCurveBox ) : Standard_False ) );
173     if(isOut )
174       continue;
175     Handle(BRepAdaptor_Surface) aSurfForFastClass = new BRepAdaptor_Surface(TopoDS::Face(aCurface));
176     myIntcs.Perform(myCurve,aSurfForFastClass);
177     myCurrentnbpoints = myIntcs.NbPoints();
178     if( !myCurrentnbpoints)
179       continue;
180
181     const Handle(Adaptor3d_Surface)& aSurf = aSurfForFastClass; // to avoid ambiguity
182     myFastClass->Initialize(aSurf);
183     myIndFace = i;
184     if(FindPoint())
185       return; 
186     myCurrentnbpoints = 0;
187   }
188
189   if(!myCurrentnbpoints && i > myFaces.Length())
190   {
191     myIndFace = i;
192     return;
193   }
194 }
195
196 //===========================================================================
197 //function :FindPoint
198 //purpose  : 
199 //===========================================================================
200 Standard_Boolean BRepIntCurveSurface_Inter::FindPoint()
201 {
202   Standard_Integer j =  (!myCurrentindex ?  1 : myCurrentindex);
203   
204   for( ; j <= myCurrentnbpoints; j++ )
205   {
206     Standard_Real anU = myIntcs.Point(j).U();
207     Standard_Real aV = myIntcs.Point(j).V();
208   
209     gp_Pnt2d Puv( anU,aV );
210
211     myCurrentstate = myFastClass->Classify(Puv,myTolerance); 
212     if(myCurrentstate == TopAbs_ON || myCurrentstate == TopAbs_IN) 
213     { 
214       myCurrentindex = j;
215       myCurrentU = anU;
216       myCurrentV = aV;  
217       return Standard_True; 
218     }
219   }
220   return Standard_False;
221 }
222
223 //===========================================================================
224 //function :Point
225 //purpose  : 
226 //===========================================================================
227
228 IntCurveSurface_IntersectionPoint BRepIntCurveSurface_Inter::Point() const 
229 {
230   if(myCurrentindex==0) 
231     throw StdFail_NotDone();
232   const IntCurveSurface_IntersectionPoint& ICPS = myIntcs.Point(myCurrentindex);
233   return(IntCurveSurface_IntersectionPoint(ICPS.Pnt(),
234                                            myCurrentU,     // ICPS.U(),
235                                            myCurrentV,     // ICPS.V(),
236                                            ICPS.W(),
237                                            ICPS.Transition()));
238   //-- return(myIntcs.Point(myCurrentindex));
239 }
240
241 //===========================================================================
242 //function :U
243 //purpose  : 
244 //===========================================================================
245 Standard_Real BRepIntCurveSurface_Inter::U() const 
246 {
247   if(myCurrentindex==0) 
248     throw StdFail_NotDone();
249   //-- return(myIntcs.Point(myCurrentindex).U());
250   return(myCurrentU);
251 }
252
253 //===========================================================================
254 //function :V
255 //purpose  : 
256 //===========================================================================
257 Standard_Real BRepIntCurveSurface_Inter::V() const 
258 {
259   if(myCurrentindex==0) 
260     throw StdFail_NotDone();
261   //-- return(myIntcs.Point(myCurrentindex).V());
262   return(myCurrentV);
263 }
264
265 //===========================================================================
266 //function :W
267 //purpose  : 
268 //===========================================================================
269 Standard_Real BRepIntCurveSurface_Inter::W() const 
270 {
271   if(myCurrentindex==0) 
272     throw StdFail_NotDone();
273   return(myIntcs.Point(myCurrentindex).W());
274 }
275
276 //===========================================================================
277 //function :State
278 //purpose  : 
279 //===========================================================================
280 TopAbs_State BRepIntCurveSurface_Inter::State() const 
281 {
282   if(myCurrentindex==0) 
283     throw StdFail_NotDone();
284   //-- return(classifier.State());
285   return(myCurrentstate);
286 }
287
288 //===========================================================================
289 //function :Transition
290 //purpose  : 
291 //===========================================================================
292 IntCurveSurface_TransitionOnCurve BRepIntCurveSurface_Inter::Transition() const 
293 {
294   if(myCurrentindex==0) 
295     throw StdFail_NotDone();
296   return(myIntcs.Point(myCurrentindex).Transition());
297 }
298
299 //===========================================================================
300 //function :Face
301 //purpose  : 
302 //===========================================================================
303 const TopoDS_Face& BRepIntCurveSurface_Inter::Face() const 
304
305   return(TopoDS::Face(myFaces.Value(myIndFace)));
306 }
307
308 //===========================================================================
309 //function :Pnt
310 //purpose  : 
311 //===========================================================================
312 const gp_Pnt& BRepIntCurveSurface_Inter::Pnt() const { 
313   if(myCurrentindex==0) 
314     throw StdFail_NotDone();
315   return(myIntcs.Point(myCurrentindex).Pnt());
316 }
317