1 // Created on: 2000-08-01
2 // Created by: Peter KURNEV
3 // Copyright (c) 2000-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
17 #include <BRep_Tool.hxx>
18 #include <BRepAdaptor_Curve.hxx>
19 #include <BRepGProp.hxx>
20 #include <gce_ErrorType.hxx>
21 #include <gce_MakeCirc.hxx>
22 #include <GCPnts_QuasiUniformDeflection.hxx>
23 #include <Geom_Curve.hxx>
24 #include <gp_Circ.hxx>
26 #include <GProp_GProps.hxx>
27 #include <IntTools.hxx>
28 #include <IntTools_Array1OfRoots.hxx>
29 #include <IntTools_CArray1OfReal.hxx>
30 #include <IntTools_Root.hxx>
31 #include <TColStd_ListIteratorOfListOfReal.hxx>
32 #include <TColStd_ListOfReal.hxx>
33 #include <TopoDS_Edge.hxx>
36 //=======================================================================
37 //function : IntTools::GetRadius
39 //=======================================================================
40 Standard_Integer IntTools::GetRadius(const BRepAdaptor_Curve& C,
41 const Standard_Real t1,
42 const Standard_Real t3,
45 GeomAbs_CurveType aType=C.GetType();
46 if (aType==GeomAbs_Line) {
50 if (aType==GeomAbs_Circle) {
51 gp_Circ aCrc=C.Circle();
66 gce_MakeCirc aMakeCirc(P1, P2, P3);
67 gce_ErrorType anErrorType;
69 anErrorType=aMakeCirc.Status();
71 if (!aMakeCirc.IsDone()) {
73 if (anErrorType==gce_ConfusedPoints ||
74 anErrorType==gce_IntersectionError ||
75 anErrorType==gce_ColinearPoints) {//modified by NIZNHY-PKV Fri Sep 24 09:54:05 2004ft
82 gp_Circ aCirc=aMakeCirc.Value();
88 //=======================================================================
89 //function : PrepareArgs
91 //=======================================================================
92 Standard_Integer IntTools::PrepareArgs(BRepAdaptor_Curve& C,
93 const Standard_Real Tmax,
94 const Standard_Real Tmin,
95 const Standard_Integer Discret,
96 const Standard_Real Deflection,
97 IntTools_CArray1OfReal& anArgs)
100 TColStd_ListOfReal aPars;
101 Standard_Real dt, tCurrent, tNext, aR, anAbsDeflection;
102 Standard_Integer ip, i, j, aNbDeflectionPoints, aDiscretBis;
103 Standard_Boolean aRFlag;
105 GeomAbs_CurveType aCurveType;
106 aCurveType=C.GetType();
108 dt=(Tmax-Tmin)/Discret;
110 for (i=1; i<=Discret; i++) {
111 tCurrent=Tmin+(i-1)*dt;
112 aPars.Append(tCurrent);
116 ///////////////////////////////////////////////////
120 if (aCurveType==GeomAbs_BSplineCurve||
121 aCurveType==GeomAbs_BezierCurve ||
122 aCurveType==GeomAbs_Ellipse ||
123 aCurveType==GeomAbs_OtherCurve) { //modified by NIZNHY-PKV Fri Sep 24 09:52:42 2004ft
127 ip=IntTools::GetRadius (C, tCurrent, tNext, aR);
133 anAbsDeflection=Deflection*aR;
134 GCPnts_QuasiUniformDeflection anUD;
135 anUD.Initialize (C, anAbsDeflection, tCurrent, tNext);
136 if (!anUD.IsDone()) {
140 aNbDeflectionPoints=anUD.NbPoints();
141 if (aNbDeflectionPoints > 2) {
142 aNbDeflectionPoints--;
143 for (j=2; j<=aNbDeflectionPoints; j++) {
144 tCurrent=anUD.Parameter(j);
145 aPars.Append(tCurrent);
152 aDiscretBis=aPars.Extent();
153 anArgs.Resize(aDiscretBis);
154 TColStd_ListIteratorOfListOfReal anIt(aPars);
155 for (i=0; anIt.More(); anIt.Next(), i++) {
156 anArgs(i)=anIt.Value();
161 //=======================================================================
162 //function : IntTools::Length
164 //=======================================================================
165 Standard_Real IntTools::Length (const TopoDS_Edge& anEdge)
167 Standard_Real aLength=0;
169 if (!BRep_Tool::Degenerated(anEdge) &&
170 BRep_Tool::IsGeometric(anEdge)) {
173 BRepGProp::LinearProperties(anEdge, Temp);
174 aLength = Temp.Mass();
179 //=======================================================================
180 //function : RemoveIdenticalRoots
182 //=======================================================================
183 void IntTools::RemoveIdenticalRoots(IntTools_SequenceOfRoots& aSR,
184 const Standard_Real anEpsT)
186 Standard_Integer aNbRoots, j, k;
187 Standard_Real anEpsT2=0.5*anEpsT;
188 aNbRoots=aSR.Length();
189 for (j=1; j<=aNbRoots; j++) {
190 const IntTools_Root& aRj=aSR(j);
191 for (k=j+1; k<=aNbRoots; k++) {
192 const IntTools_Root& aRk=aSR(k);
193 if (fabs (aRj.Root()-aRk.Root()) < anEpsT2) {
195 aNbRoots=aSR.Length();
201 //=======================================================================
204 // Auxiliary: comparator function for sorting roots
205 bool IntTools_RootComparator (const IntTools_Root& theLeft, const IntTools_Root& theRight)
207 return theLeft.Root() < theRight.Root();
211 //=======================================================================
212 //function : SortRoots
214 //=======================================================================
215 void IntTools::SortRoots(IntTools_SequenceOfRoots& mySequenceOfRoots,
216 const Standard_Real /*myEpsT*/)
218 Standard_Integer j, aNbRoots;
220 aNbRoots=mySequenceOfRoots.Length();
222 IntTools_Array1OfRoots anArray1OfRoots(1, aNbRoots);
223 for (j=1; j<=aNbRoots; j++) {
224 anArray1OfRoots(j)=mySequenceOfRoots(j);
227 std::sort (anArray1OfRoots.begin(), anArray1OfRoots.end(), IntTools_RootComparator);
229 mySequenceOfRoots.Clear();
230 for (j=1; j<=aNbRoots; j++) {
231 mySequenceOfRoots.Append(anArray1OfRoots(j));
234 //=======================================================================
235 //function :FindRootStates
237 //=======================================================================
238 void IntTools::FindRootStates(IntTools_SequenceOfRoots& mySequenceOfRoots,
239 const Standard_Real myEpsNull)
241 Standard_Integer aType, j, aNbRoots;
242 Standard_Real t1, t2, f1, f2, absf2;
244 aNbRoots=mySequenceOfRoots.Length();
246 for (j=1; j<=aNbRoots; j++) {
247 IntTools_Root& aR=mySequenceOfRoots.ChangeValue(j);
249 aR.Interval (t1, t2, f1, f2);
253 case 0: // Simple Root
254 if (f1>0. && f2<0.) {
255 aR.SetStateBefore(TopAbs_OUT);
256 aR.SetStateAfter (TopAbs_IN);
259 aR.SetStateBefore(TopAbs_IN);
260 aR.SetStateAfter (TopAbs_OUT);
264 case 1: // Complete 0;
265 aR.SetStateBefore(TopAbs_ON);
266 aR.SetStateAfter (TopAbs_ON);
271 if (absf2 < myEpsNull) {
272 aR.SetStateAfter (TopAbs_ON);
274 aR.SetStateBefore(TopAbs_OUT);
277 aR.SetStateBefore(TopAbs_IN);
282 aR.SetStateBefore(TopAbs_ON);
284 aR.SetStateAfter (TopAbs_OUT);
287 aR.SetStateAfter (TopAbs_IN);
296 #include <GeomAdaptor_Curve.hxx>
297 #include <gp_Pnt.hxx>
298 #include <ElCLib.hxx>
299 #include <gp_Lin.hxx>
300 #include <gp_Circ.hxx>
301 #include <gp_Elips.hxx>
302 #include <gp_Hypr.hxx>
303 #include <gp_Parab.hxx>
304 #include <GeomAPI_ProjectPointOnCurve.hxx>
306 //=======================================================================
307 //function :Parameter
309 //=======================================================================
310 Standard_Integer IntTools::Parameter (const gp_Pnt& aP,
311 const Handle(Geom_Curve)& aCurve,
312 Standard_Real& aParameter)
314 Standard_Real aFirst, aLast;
315 GeomAbs_CurveType aCurveType;
317 aFirst=aCurve->FirstParameter();
318 aLast =aCurve->LastParameter ();
320 GeomAdaptor_Curve aGAC;
322 aGAC.Load (aCurve, aFirst, aLast);
324 aCurveType=aGAC.GetType();
330 gp_Lin aLin=aGAC.Line();
331 aParameter=ElCLib::Parameter (aLin, aP);
336 gp_Circ aCircle=aGAC.Circle();
337 aParameter=ElCLib::Parameter (aCircle, aP);
340 case GeomAbs_Ellipse:
342 gp_Elips aElips=aGAC.Ellipse();
343 aParameter=ElCLib::Parameter (aElips, aP);
346 case GeomAbs_Hyperbola:
348 gp_Hypr aHypr=aGAC.Hyperbola();
349 aParameter=ElCLib::Parameter (aHypr, aP);
352 case GeomAbs_Parabola:
354 gp_Parab aParab=aGAC.Parabola();
355 aParameter=ElCLib::Parameter (aParab, aP);
359 case GeomAbs_BezierCurve:
360 case GeomAbs_BSplineCurve:
362 GeomAPI_ProjectPointOnCurve aProjector;
364 aProjector.Init(aP, aCurve, aFirst, aLast);
365 Standard_Integer aNbPoints=aProjector.NbPoints();
367 aParameter=aProjector.LowerDistanceParameter();
381 #pragma warning ( default : 4101 )