0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / BRepIntCurveSurface / BRepIntCurveSurface_Inter.cxx
CommitLineData
b311480e 1// Created on: 1994-02-07
2// Created by: Modelistation
3// Copyright (c) 1994-1999 Matra Datavision
973c2be1 4// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 5//
973c2be1 6// This file is part of Open CASCADE Technology software library.
b311480e 7//
d5f74e42 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
973c2be1 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.
b311480e 13//
973c2be1 14// Alternatively, this file may be used under the terms of Open CASCADE
15// commercial license or contractual agreement.
7fd59977 16
c22b52d6 17#include <BRepIntCurveSurface_Inter.hxx>
42cf5bc1 18
19#include <Bnd_Box.hxx>
20#include <BndLib_Add3dCurve.hxx>
42cf5bc1 21#include <BRepAdaptor_Surface.hxx>
22#include <BRepBndLib.hxx>
42cf5bc1 23#include <BRepTopAdaptor_TopolTool.hxx>
7fd59977 24#include <Geom_Line.hxx>
42cf5bc1 25#include <GeomAdaptor_Curve.hxx>
42cf5bc1 26#include <gp_Lin.hxx>
27#include <gp_Pnt.hxx>
28#include <IntCurveSurface_IntersectionPoint.hxx>
29#include <StdFail_NotDone.hxx>
7fd59977 30#include <TopAbs_ShapeEnum.hxx>
31#include <TopoDS.hxx>
32#include <TopoDS_Face.hxx>
42cf5bc1 33#include <TopoDS_Shape.hxx>
7fd59977 34
35//===========================================================================
36//function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte
37//purpose :
38//===========================================================================
39BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter()
7fd59977 40{
004e8466 41 myFastClass = new BRepTopAdaptor_TopolTool();
42 Clear();
7fd59977 43}
44
004e8466 45//===========================================================================
46//function :Init
47//purpose :
48//===========================================================================
49
50void 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
63void 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
80void BRepIntCurveSurface_Inter::Clear()
81{
82 myCurrentindex = 0;
83 myCurrentnbpoints = 0;
84 myIndFace = 0;
85 myCurrentstate = TopAbs_UNKNOWN;
86 myCurrentU = 0;
87 myCurrentV = 0;
88
7fd59977 89}
90
004e8466 91//===========================================================================
92//function :Load
93//purpose :
94//===========================================================================
95
96void 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
7fd59977 106}
107
004e8466 108//===========================================================================
109//function :Init
110//purpose :
111//===========================================================================
112
113void 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();
c22b52d6 119 myCurve = new GeomAdaptor_Curve(theCurve );
004e8466 120 if( !Precision::IsInfinite(aFirst) && !Precision::IsInfinite(aLast) )
c22b52d6 121 {
122 BndLib_Add3dCurve::Add (*myCurve, 0., myCurveBox);
123 }
7fd59977 124 Find();
125}
126
004e8466 127//===========================================================================
128//function :More
129//purpose :
130//===========================================================================
131Standard_Boolean BRepIntCurveSurface_Inter::More() const
132{
133 return (myIndFace <= myFaces.Length() );
134}
135
136//===========================================================================
137//function :Next
138//purpose :
139//===========================================================================
140void BRepIntCurveSurface_Inter::Next()
141{
142 if(myCurrentnbpoints)
143 myCurrentindex++;
144 Find();
145}
7fd59977 146
004e8466 147//===========================================================================
148//function :Find
149//purpose :
150//===========================================================================
151void BRepIntCurveSurface_Inter::Find()
152{
153 if(myCurrentnbpoints && myCurrentindex <= myCurrentnbpoints && FindPoint())
154 return;
7fd59977 155
004e8466 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());
7fd59977 170 }
004e8466 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;
c22b52d6 175 Handle(BRepAdaptor_Surface) aSurfForFastClass = new BRepAdaptor_Surface(TopoDS::Face(aCurface));
004e8466 176 myIntcs.Perform(myCurve,aSurfForFastClass);
177 myCurrentnbpoints = myIntcs.NbPoints();
178 if( !myCurrentnbpoints)
179 continue;
180
c22b52d6 181 const Handle(Adaptor3d_Surface)& aSurf = aSurfForFastClass; // to avoid ambiguity
543a9964 182 myFastClass->Initialize(aSurf);
004e8466 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;
7fd59977 193 }
004e8466 194}
195
196//===========================================================================
197//function :FindPoint
198//purpose :
199//===========================================================================
200Standard_Boolean BRepIntCurveSurface_Inter::FindPoint()
201{
202 Standard_Integer j = (!myCurrentindex ? 1 : myCurrentindex);
7fd59977 203
004e8466 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 );
7fd59977 210
004e8466 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;
7fd59977 218 }
7fd59977 219 }
004e8466 220 return Standard_False;
7fd59977 221}
222
004e8466 223//===========================================================================
224//function :Point
225//purpose :
226//===========================================================================
7fd59977 227
004e8466 228IntCurveSurface_IntersectionPoint BRepIntCurveSurface_Inter::Point() const
229{
230 if(myCurrentindex==0)
9775fa61 231 throw StdFail_NotDone();
004e8466 232 const IntCurveSurface_IntersectionPoint& ICPS = myIntcs.Point(myCurrentindex);
7fd59977 233 return(IntCurveSurface_IntersectionPoint(ICPS.Pnt(),
004e8466 234 myCurrentU, // ICPS.U(),
235 myCurrentV, // ICPS.V(),
7fd59977 236 ICPS.W(),
237 ICPS.Transition()));
004e8466 238 //-- return(myIntcs.Point(myCurrentindex));
7fd59977 239}
240
004e8466 241//===========================================================================
242//function :U
243//purpose :
244//===========================================================================
245Standard_Real BRepIntCurveSurface_Inter::U() const
246{
247 if(myCurrentindex==0)
9775fa61 248 throw StdFail_NotDone();
004e8466 249 //-- return(myIntcs.Point(myCurrentindex).U());
250 return(myCurrentU);
7fd59977 251}
252
004e8466 253//===========================================================================
254//function :V
255//purpose :
256//===========================================================================
257Standard_Real BRepIntCurveSurface_Inter::V() const
258{
259 if(myCurrentindex==0)
9775fa61 260 throw StdFail_NotDone();
004e8466 261 //-- return(myIntcs.Point(myCurrentindex).V());
262 return(myCurrentV);
7fd59977 263}
264
004e8466 265//===========================================================================
266//function :W
267//purpose :
268//===========================================================================
269Standard_Real BRepIntCurveSurface_Inter::W() const
270{
271 if(myCurrentindex==0)
9775fa61 272 throw StdFail_NotDone();
004e8466 273 return(myIntcs.Point(myCurrentindex).W());
7fd59977 274}
275
004e8466 276//===========================================================================
277//function :State
278//purpose :
279//===========================================================================
280TopAbs_State BRepIntCurveSurface_Inter::State() const
281{
282 if(myCurrentindex==0)
9775fa61 283 throw StdFail_NotDone();
7fd59977 284 //-- return(classifier.State());
004e8466 285 return(myCurrentstate);
7fd59977 286}
287
004e8466 288//===========================================================================
289//function :Transition
290//purpose :
291//===========================================================================
292IntCurveSurface_TransitionOnCurve BRepIntCurveSurface_Inter::Transition() const
293{
294 if(myCurrentindex==0)
9775fa61 295 throw StdFail_NotDone();
004e8466 296 return(myIntcs.Point(myCurrentindex).Transition());
7fd59977 297}
298
004e8466 299//===========================================================================
300//function :Face
301//purpose :
302//===========================================================================
303const TopoDS_Face& BRepIntCurveSurface_Inter::Face() const
304{
305 return(TopoDS::Face(myFaces.Value(myIndFace)));
7fd59977 306}
307
004e8466 308//===========================================================================
309//function :Pnt
310//purpose :
311//===========================================================================
7fd59977 312const gp_Pnt& BRepIntCurveSurface_Inter::Pnt() const {
004e8466 313 if(myCurrentindex==0)
9775fa61 314 throw StdFail_NotDone();
004e8466 315 return(myIntcs.Point(myCurrentindex).Pnt());
7fd59977 316}
004e8466 317