b311480e |
1 | // Created on: 2000-08-01 |
2 | // Created by: Peter KURNEV |
973c2be1 |
3 | // Copyright (c) 2000-2014 OPEN CASCADE SAS |
b311480e |
4 | // |
973c2be1 |
5 | // This file is part of Open CASCADE Technology software library. |
b311480e |
6 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
b311480e |
12 | // |
973c2be1 |
13 | // Alternatively, this file may be used under the terms of Open CASCADE |
14 | // commercial license or contractual agreement. |
7fd59977 |
15 | |
ae64fe01 |
16 | #include <IntTools.hxx> |
7fd59977 |
17 | |
42cf5bc1 |
18 | #include <BRep_Tool.hxx> |
19 | #include <BRepAdaptor_Curve.hxx> |
20 | #include <BRepGProp.hxx> |
7fd59977 |
21 | #include <gce_MakeCirc.hxx> |
42cf5bc1 |
22 | #include <GCPnts_QuasiUniformDeflection.hxx> |
23 | #include <Geom_Curve.hxx> |
7fd59977 |
24 | #include <gp_Circ.hxx> |
42cf5bc1 |
25 | #include <gp_Pnt.hxx> |
26 | #include <GProp_GProps.hxx> |
42cf5bc1 |
27 | #include <IntTools_Array1OfRoots.hxx> |
42cf5bc1 |
28 | #include <IntTools_Root.hxx> |
42cf5bc1 |
29 | #include <TColStd_ListOfReal.hxx> |
30 | #include <TopoDS_Edge.hxx> |
7fd59977 |
31 | |
e35db416 |
32 | #include <algorithm> |
ae64fe01 |
33 | |
7fd59977 |
34 | //======================================================================= |
35 | //function : IntTools::GetRadius |
36 | //purpose : |
37 | //======================================================================= |
38 | Standard_Integer IntTools::GetRadius(const BRepAdaptor_Curve& C, |
39 | const Standard_Real t1, |
40 | const Standard_Real t3, |
41 | Standard_Real& aR) |
42 | { |
43 | GeomAbs_CurveType aType=C.GetType(); |
44 | if (aType==GeomAbs_Line) { |
45 | return 1; |
46 | } |
47 | |
48 | if (aType==GeomAbs_Circle) { |
49 | gp_Circ aCrc=C.Circle(); |
50 | aR=aCrc.Radius(); |
51 | return 0; |
52 | } |
53 | |
54 | Standard_Real t2; |
55 | gp_Pnt P1, P2, P3; |
56 | |
57 | t2=0.5*(t1+t3); |
58 | |
59 | P1=C.Value(t1); |
60 | P2=C.Value(t2); |
61 | P3=C.Value(t3); |
62 | // |
63 | // |
64 | gce_MakeCirc aMakeCirc(P1, P2, P3); |
65 | gce_ErrorType anErrorType; |
66 | |
67 | anErrorType=aMakeCirc.Status(); |
68 | |
69 | if (!aMakeCirc.IsDone()) { |
70 | |
71 | if (anErrorType==gce_ConfusedPoints || |
72 | anErrorType==gce_IntersectionError || |
73 | anErrorType==gce_ColinearPoints) {//modified by NIZNHY-PKV Fri Sep 24 09:54:05 2004ft |
74 | return 2; |
75 | } |
76 | return -1; |
77 | } |
78 | // |
79 | // |
80 | gp_Circ aCirc=aMakeCirc.Value(); |
81 | aR=aCirc.Radius(); |
82 | |
83 | return 0; |
84 | } |
85 | |
86 | //======================================================================= |
87 | //function : PrepareArgs |
88 | //purpose : |
89 | //======================================================================= |
ae64fe01 |
90 | Standard_Integer IntTools::PrepareArgs (BRepAdaptor_Curve& C, |
91 | const Standard_Real Tmax, |
92 | const Standard_Real Tmin, |
93 | const Standard_Integer Discret, |
94 | const Standard_Real Deflection, |
95 | TColStd_Array1OfReal& anArgs) |
7fd59977 |
96 | { |
97 | |
98 | TColStd_ListOfReal aPars; |
99 | Standard_Real dt, tCurrent, tNext, aR, anAbsDeflection; |
ae64fe01 |
100 | Standard_Integer ip, i, j, aNbDeflectionPoints; |
7fd59977 |
101 | Standard_Boolean aRFlag; |
102 | |
103 | GeomAbs_CurveType aCurveType; |
104 | aCurveType=C.GetType(); |
105 | |
106 | dt=(Tmax-Tmin)/Discret; |
107 | aRFlag=(dt > 1.e-5); |
108 | for (i=1; i<=Discret; i++) { |
109 | tCurrent=Tmin+(i-1)*dt; |
110 | aPars.Append(tCurrent); |
111 | tNext=tCurrent+dt; |
112 | if (i==Discret) |
113 | tNext=Tmax; |
114 | /////////////////////////////////////////////////// |
115 | if (!aRFlag) { |
116 | continue; |
117 | } |
118 | if (aCurveType==GeomAbs_BSplineCurve|| |
119 | aCurveType==GeomAbs_BezierCurve || |
1aec3320 |
120 | aCurveType==GeomAbs_OffsetCurve || |
7fd59977 |
121 | aCurveType==GeomAbs_Ellipse || |
122 | aCurveType==GeomAbs_OtherCurve) { //modified by NIZNHY-PKV Fri Sep 24 09:52:42 2004ft |
123 | continue; |
124 | } |
125 | // |
126 | ip=IntTools::GetRadius (C, tCurrent, tNext, aR); |
127 | if (ip<0) { |
128 | return 1; |
129 | } |
130 | // |
131 | if (!ip) { |
132 | anAbsDeflection=Deflection*aR; |
133 | GCPnts_QuasiUniformDeflection anUD; |
134 | anUD.Initialize (C, anAbsDeflection, tCurrent, tNext); |
135 | if (!anUD.IsDone()) { |
136 | return 2; |
137 | } |
138 | |
139 | aNbDeflectionPoints=anUD.NbPoints(); |
140 | if (aNbDeflectionPoints > 2) { |
141 | aNbDeflectionPoints--; |
142 | for (j=2; j<=aNbDeflectionPoints; j++) { |
143 | tCurrent=anUD.Parameter(j); |
144 | aPars.Append(tCurrent); |
145 | } |
146 | } |
147 | } |
148 | } |
149 | |
150 | aPars.Append(Tmax); |
ae64fe01 |
151 | const Standard_Integer aDiscretBis = aPars.Extent(); |
152 | anArgs.Resize (0, aDiscretBis - 1, false); |
7fd59977 |
153 | TColStd_ListIteratorOfListOfReal anIt(aPars); |
ae64fe01 |
154 | for (i = 0; anIt.More(); anIt.Next(), i++) |
155 | { |
156 | anArgs.SetValue (i, anIt.Value()); |
7fd59977 |
157 | } |
158 | return 0; |
159 | } |
160 | |
161 | //======================================================================= |
162 | //function : IntTools::Length |
163 | //purpose : |
164 | //======================================================================= |
165 | Standard_Real IntTools::Length (const TopoDS_Edge& anEdge) |
166 | { |
167 | Standard_Real aLength=0; |
168 | |
169 | if (!BRep_Tool::Degenerated(anEdge) && |
170 | BRep_Tool::IsGeometric(anEdge)) { |
171 | |
172 | GProp_GProps Temp; |
173 | BRepGProp::LinearProperties(anEdge, Temp); |
174 | aLength = Temp.Mass(); |
175 | } |
176 | return aLength; |
177 | } |
178 | |
179 | //======================================================================= |
180 | //function : RemoveIdenticalRoots |
181 | //purpose : |
182 | //======================================================================= |
183 | void IntTools::RemoveIdenticalRoots(IntTools_SequenceOfRoots& aSR, |
184 | const Standard_Real anEpsT) |
185 | { |
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) { |
194 | aSR.Remove(k); |
195 | aNbRoots=aSR.Length(); |
196 | } |
197 | } |
198 | } |
199 | } |
200 | |
e35db416 |
201 | //======================================================================= |
202 | |
203 | namespace { |
204 | // Auxiliary: comparator function for sorting roots |
205 | bool IntTools_RootComparator (const IntTools_Root& theLeft, const IntTools_Root& theRight) |
206 | { |
207 | return theLeft.Root() < theRight.Root(); |
208 | } |
a3f6f591 |
209 | } |
e35db416 |
210 | |
7fd59977 |
211 | //======================================================================= |
212 | //function : SortRoots |
213 | //purpose : |
214 | //======================================================================= |
215 | void IntTools::SortRoots(IntTools_SequenceOfRoots& mySequenceOfRoots, |
e35db416 |
216 | const Standard_Real /*myEpsT*/) |
7fd59977 |
217 | { |
218 | Standard_Integer j, aNbRoots; |
219 | |
220 | aNbRoots=mySequenceOfRoots.Length(); |
221 | |
e35db416 |
222 | IntTools_Array1OfRoots anArray1OfRoots(1, aNbRoots); |
7fd59977 |
223 | for (j=1; j<=aNbRoots; j++) { |
224 | anArray1OfRoots(j)=mySequenceOfRoots(j); |
225 | } |
226 | |
e35db416 |
227 | std::sort (anArray1OfRoots.begin(), anArray1OfRoots.end(), IntTools_RootComparator); |
7fd59977 |
228 | |
229 | mySequenceOfRoots.Clear(); |
230 | for (j=1; j<=aNbRoots; j++) { |
231 | mySequenceOfRoots.Append(anArray1OfRoots(j)); |
232 | } |
233 | } |
234 | //======================================================================= |
235 | //function :FindRootStates |
236 | //purpose : |
237 | //======================================================================= |
238 | void IntTools::FindRootStates(IntTools_SequenceOfRoots& mySequenceOfRoots, |
239 | const Standard_Real myEpsNull) |
240 | { |
241 | Standard_Integer aType, j, aNbRoots; |
96a95605 |
242 | Standard_Real t1, t2, f1, f2, absf2; |
7fd59977 |
243 | |
244 | aNbRoots=mySequenceOfRoots.Length(); |
245 | |
246 | for (j=1; j<=aNbRoots; j++) { |
247 | IntTools_Root& aR=mySequenceOfRoots.ChangeValue(j); |
248 | |
7fd59977 |
249 | aR.Interval (t1, t2, f1, f2); |
250 | |
251 | aType=aR.Type(); |
252 | switch (aType) { |
253 | case 0: // Simple Root |
254 | if (f1>0. && f2<0.) { |
255 | aR.SetStateBefore(TopAbs_OUT); |
256 | aR.SetStateAfter (TopAbs_IN); |
257 | } |
258 | else { |
259 | aR.SetStateBefore(TopAbs_IN); |
260 | aR.SetStateAfter (TopAbs_OUT); |
261 | } |
262 | break; |
263 | |
264 | case 1: // Complete 0; |
265 | aR.SetStateBefore(TopAbs_ON); |
266 | aR.SetStateAfter (TopAbs_ON); |
267 | break; |
268 | |
269 | case 2: // Smart; |
7fd59977 |
270 | absf2=fabs(f2); |
271 | if (absf2 < myEpsNull) { |
272 | aR.SetStateAfter (TopAbs_ON); |
273 | if (f1>0.) { |
274 | aR.SetStateBefore(TopAbs_OUT); |
275 | } |
276 | else { |
277 | aR.SetStateBefore(TopAbs_IN); |
278 | } |
279 | } |
280 | |
281 | else { |
282 | aR.SetStateBefore(TopAbs_ON); |
283 | if (f2>0.) { |
284 | aR.SetStateAfter (TopAbs_OUT); |
285 | } |
286 | else { |
287 | aR.SetStateAfter (TopAbs_IN); |
288 | } |
289 | } |
290 | |
291 | default: break; |
292 | } // switch (aType) |
293 | } |
294 | } |
295 | |
296 | #include <GeomAdaptor_Curve.hxx> |
7fd59977 |
297 | #include <ElCLib.hxx> |
298 | #include <gp_Lin.hxx> |
7fd59977 |
299 | #include <gp_Elips.hxx> |
300 | #include <gp_Hypr.hxx> |
301 | #include <gp_Parab.hxx> |
302 | #include <GeomAPI_ProjectPointOnCurve.hxx> |
303 | |
304 | //======================================================================= |
305 | //function :Parameter |
306 | //purpose : |
307 | //======================================================================= |
308 | Standard_Integer IntTools::Parameter (const gp_Pnt& aP, |
309 | const Handle(Geom_Curve)& aCurve, |
310 | Standard_Real& aParameter) |
311 | { |
312 | Standard_Real aFirst, aLast; |
313 | GeomAbs_CurveType aCurveType; |
314 | |
315 | aFirst=aCurve->FirstParameter(); |
316 | aLast =aCurve->LastParameter (); |
317 | |
318 | GeomAdaptor_Curve aGAC; |
319 | |
320 | aGAC.Load (aCurve, aFirst, aLast); |
321 | |
322 | aCurveType=aGAC.GetType(); |
323 | |
324 | switch (aCurveType){ |
325 | |
326 | case GeomAbs_Line: |
327 | { |
328 | gp_Lin aLin=aGAC.Line(); |
329 | aParameter=ElCLib::Parameter (aLin, aP); |
330 | return 0; |
331 | } |
332 | case GeomAbs_Circle: |
333 | { |
334 | gp_Circ aCircle=aGAC.Circle(); |
335 | aParameter=ElCLib::Parameter (aCircle, aP); |
336 | return 0; |
337 | } |
338 | case GeomAbs_Ellipse: |
339 | { |
340 | gp_Elips aElips=aGAC.Ellipse(); |
341 | aParameter=ElCLib::Parameter (aElips, aP); |
342 | return 0; |
343 | } |
344 | case GeomAbs_Hyperbola: |
345 | { |
346 | gp_Hypr aHypr=aGAC.Hyperbola(); |
347 | aParameter=ElCLib::Parameter (aHypr, aP); |
348 | return 0; |
349 | } |
350 | case GeomAbs_Parabola: |
351 | { |
352 | gp_Parab aParab=aGAC.Parabola(); |
353 | aParameter=ElCLib::Parameter (aParab, aP); |
354 | return 0; |
355 | } |
356 | |
357 | case GeomAbs_BezierCurve: |
358 | case GeomAbs_BSplineCurve: |
359 | { |
360 | GeomAPI_ProjectPointOnCurve aProjector; |
361 | |
362 | aProjector.Init(aP, aCurve, aFirst, aLast); |
363 | Standard_Integer aNbPoints=aProjector.NbPoints(); |
364 | if (aNbPoints) { |
365 | aParameter=aProjector.LowerDistanceParameter(); |
366 | return 0; |
367 | } |
368 | else { |
369 | return 2; |
370 | } |
7fd59977 |
371 | } |
372 | default: |
373 | break; |
374 | } |
375 | return 1; |
376 | } |