0031668: Visualization - WebGL sample doesn't work on Emscripten 1.39
[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
42cf5bc1 17
18#include <Bnd_Box.hxx>
19#include <BndLib_Add3dCurve.hxx>
20#include <BRepAdaptor_HSurface.hxx>
21#include <BRepAdaptor_Surface.hxx>
22#include <BRepBndLib.hxx>
23#include <BRepIntCurveSurface_Inter.hxx>
24#include <BRepTopAdaptor_TopolTool.hxx>
7fd59977 25#include <Geom_Line.hxx>
42cf5bc1 26#include <GeomAdaptor_Curve.hxx>
27#include <GeomAdaptor_HCurve.hxx>
28#include <gp_Lin.hxx>
29#include <gp_Pnt.hxx>
30#include <IntCurveSurface_IntersectionPoint.hxx>
31#include <StdFail_NotDone.hxx>
7fd59977 32#include <TopAbs_ShapeEnum.hxx>
33#include <TopoDS.hxx>
34#include <TopoDS_Face.hxx>
42cf5bc1 35#include <TopoDS_Shape.hxx>
7fd59977 36
37//===========================================================================
38//function :BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inte
39//purpose :
40//===========================================================================
41BRepIntCurveSurface_Inter::BRepIntCurveSurface_Inter()
7fd59977 42{
004e8466 43 myFastClass = new BRepTopAdaptor_TopolTool();
44 Clear();
7fd59977 45}
46
004e8466 47//===========================================================================
48//function :Init
49//purpose :
50//===========================================================================
51
52void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& theShape,
53 const GeomAdaptor_Curve& theCurve,
54 const Standard_Real theTol)
55{
56 Load(theShape, theTol);
57 Init(theCurve);
58}
59
60//===========================================================================
61//function :Init
62//purpose :
63//===========================================================================
64
65void BRepIntCurveSurface_Inter::Init(const TopoDS_Shape& theShape,
66 const gp_Lin& theLine,
67 const Standard_Real theTol)
68{
69
70 Handle(Geom_Line) geomline = new Geom_Line(theLine);
71 GeomAdaptor_Curve aCurve(geomline);
72 Load(theShape, theTol);
73 Init(aCurve);
74
75}
76
77//===========================================================================
78//function :Clear
79//purpose :
80//===========================================================================
81
82void BRepIntCurveSurface_Inter::Clear()
83{
84 myCurrentindex = 0;
85 myCurrentnbpoints = 0;
86 myIndFace = 0;
87 myCurrentstate = TopAbs_UNKNOWN;
88 myCurrentU = 0;
89 myCurrentV = 0;
90
7fd59977 91}
92
004e8466 93//===========================================================================
94//function :Load
95//purpose :
96//===========================================================================
97
98void BRepIntCurveSurface_Inter::Load(const TopoDS_Shape& theShape ,const Standard_Real theTol)
99{
100 Clear();
101 myFaces.Clear();
102 myFaceBoxes.Nullify();
103 myTolerance = theTol;
104 TopExp_Explorer explorer(theShape,TopAbs_FACE);
105 for( ; explorer.More(); explorer.Next())
106 myFaces.Append(explorer.Current());
107
7fd59977 108}
109
004e8466 110//===========================================================================
111//function :Init
112//purpose :
113//===========================================================================
114
115void BRepIntCurveSurface_Inter::Init(const GeomAdaptor_Curve& theCurve )
116{
117 Clear();
118 myCurveBox.SetVoid();
119 Standard_Real aFirst = theCurve.FirstParameter();
120 Standard_Real aLast = theCurve.LastParameter();
121 myCurve = new GeomAdaptor_HCurve(theCurve );
122 if( !Precision::IsInfinite(aFirst) && !Precision::IsInfinite(aLast) )
123 BndLib_Add3dCurve::Add(myCurve->Curve(),0., myCurveBox);
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;
175 Handle(BRepAdaptor_HSurface) aSurfForFastClass = new BRepAdaptor_HSurface(TopoDS::Face(aCurface));
176 myIntcs.Perform(myCurve,aSurfForFastClass);
177 myCurrentnbpoints = myIntcs.NbPoints();
178 if( !myCurrentnbpoints)
179 continue;
180
543a9964 181 const Handle(Adaptor3d_HSurface)& aSurf = aSurfForFastClass; // to avoid ambiguity
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