Commit | Line | Data |
---|---|---|
b311480e | 1 | // Copyright (c) 1995-1999 Matra Datavision |
973c2be1 | 2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e | 3 | // |
973c2be1 | 4 | // This file is part of Open CASCADE Technology software library. |
b311480e | 5 | // |
973c2be1 | 6 | // This library is free software; you can redistribute it and / or modify it |
7 | // under the terms of the GNU Lesser General Public version 2.1 as published | |
8 | // by the Free Software Foundation, with special exception defined in the file | |
9 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT | |
10 | // distribution for complete text of the license and disclaimer of any warranty. | |
b311480e | 11 | // |
973c2be1 | 12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. | |
b311480e | 14 | |
7fd59977 | 15 | //----------------------------------------------------------------- |
7fd59977 | 16 | |
17 | #include <Extrema_ExtPS.ixx> | |
18 | #include <Extrema_GenExtPS.hxx> | |
19 | #include <StdFail_NotDone.hxx> | |
20 | #include <Standard_NotImplemented.hxx> | |
21 | #include <Precision.hxx> | |
22 | #include <GeomAbs_CurveType.hxx> | |
23 | #include <Adaptor3d_SurfaceOfLinearExtrusion.hxx> | |
24 | #include <Adaptor3d_SurfaceOfRevolution.hxx> | |
25 | #include <ElCLib.hxx> | |
26 | #include <gp_Pnt.hxx> | |
27 | #include <gp_Pln.hxx> | |
28 | #include <gp_Cylinder.hxx> | |
29 | #include <gp_Cone.hxx> | |
30 | #include <gp_Sphere.hxx> | |
31 | #include <gp_Torus.hxx> | |
32 | #include <Extrema_ExtPExtS.hxx> | |
33 | #include <Extrema_ExtPRevS.hxx> | |
34 | #include <Extrema_POnSurf.hxx> | |
35 | #include <GeomAbs_IsoType.hxx> | |
36 | ||
37 | //======================================================================= | |
38 | //function : IsoIsDeg | |
39 | //purpose : | |
40 | //======================================================================= | |
41 | ||
42 | static Standard_Boolean IsoIsDeg (const Adaptor3d_Surface& S, | |
43 | const Standard_Real Param, | |
44 | const GeomAbs_IsoType IT, | |
45 | const Standard_Real TolMin, | |
46 | const Standard_Real TolMax) | |
47 | { | |
48 | Standard_Real U1=0.,U2=0.,V1=0.,V2=0.,T; | |
49 | Standard_Boolean Along = Standard_True; | |
50 | U1 = S.FirstUParameter(); | |
51 | U2 = S.LastUParameter(); | |
52 | V1 = S.FirstVParameter(); | |
53 | V2 = S.LastVParameter(); | |
54 | gp_Vec D1U,D1V; | |
55 | gp_Pnt P; | |
56 | Standard_Real Step,D1NormMax; | |
57 | if (IT == GeomAbs_IsoV) | |
58 | { | |
5368adff | 59 | if( !Precision::IsInfinite(U1) && !Precision::IsInfinite(U2) ) |
7fd59977 | 60 | { |
5368adff | 61 | Step = (U2 - U1)/10; |
62 | if(Step < Precision::PConfusion()) { | |
63 | return Standard_False; | |
64 | } | |
65 | D1NormMax=0.; | |
66 | ||
67 | for (T=U1;T<=U2;T=T+Step) | |
68 | { | |
69 | S.D1(T,Param,P,D1U,D1V); | |
70 | D1NormMax=Max(D1NormMax,D1U.Magnitude()); | |
71 | } | |
72 | ||
73 | if (D1NormMax >TolMax || D1NormMax < TolMin ) | |
74 | Along = Standard_False; | |
7fd59977 | 75 | } |
7fd59977 | 76 | } |
77 | else | |
78 | { | |
5368adff | 79 | if( !Precision::IsInfinite(V1) && !Precision::IsInfinite(V2) ) |
7fd59977 | 80 | { |
5368adff | 81 | Step = (V2 - V1)/10; |
82 | if(Step < Precision::PConfusion()) { | |
83 | return Standard_False; | |
84 | } | |
85 | D1NormMax=0.; | |
86 | for (T=V1;T<=V2;T=T+Step) | |
87 | { | |
88 | S.D1(Param,T,P,D1U,D1V); | |
89 | D1NormMax=Max(D1NormMax,D1V.Magnitude()); | |
90 | } | |
91 | ||
92 | if (D1NormMax >TolMax || D1NormMax < TolMin ) | |
93 | Along = Standard_False; | |
7fd59977 | 94 | } |
95 | ||
7fd59977 | 96 | |
97 | ||
98 | } | |
99 | return Along; | |
100 | } | |
101 | ||
102 | //======================================================================= | |
103 | //function : TreatSolution | |
104 | //purpose : | |
105 | //======================================================================= | |
106 | ||
107 | void Extrema_ExtPS::TreatSolution (const Extrema_POnSurf& PS, | |
108 | const Standard_Real Val) | |
109 | { | |
110 | Standard_Real U, V; | |
111 | PS.Parameter(U, V); | |
112 | if (myS->IsUPeriodic()) { | |
113 | U = ElCLib::InPeriod(U, myuinf, myuinf+myS->UPeriod()); | |
114 | } | |
115 | if (myS->IsVPeriodic()) { | |
116 | V = ElCLib::InPeriod(V, myvinf, myvinf+myS->VPeriod()); | |
117 | } | |
118 | if ((myuinf-U) <= mytolu && (U-myusup) <= mytolu && | |
119 | (myvinf-V) <= mytolv && (V-myvsup) <= mytolv) { | |
120 | myPoints.Append(Extrema_POnSurf (U, V, PS.Value())); | |
121 | mySqDist.Append(Val); | |
122 | } | |
123 | } | |
124 | ||
125 | ||
126 | //======================================================================= | |
127 | //function : Extrema_ExtPS | |
128 | //purpose : | |
129 | //======================================================================= | |
130 | ||
131 | Extrema_ExtPS::Extrema_ExtPS() | |
132 | { | |
133 | myDone = Standard_False; | |
134 | } | |
135 | ||
136 | ||
137 | //======================================================================= | |
138 | //function : Extrema_ExtPS | |
139 | //purpose : | |
140 | //======================================================================= | |
141 | ||
142 | Extrema_ExtPS::Extrema_ExtPS(const gp_Pnt& P, | |
143 | const Adaptor3d_Surface& S, | |
144 | const Standard_Real TolU, | |
92d1589b A |
145 | const Standard_Real TolV, |
146 | const Extrema_ExtFlag F, | |
147 | const Extrema_ExtAlgo A) | |
7fd59977 | 148 | |
149 | { | |
92d1589b A |
150 | myExtPS.SetFlag(F); |
151 | myExtPS.SetAlgo(A); | |
7fd59977 | 152 | Initialize(S, S.FirstUParameter(), S.LastUParameter(), |
153 | S.FirstVParameter(), S.LastVParameter(), | |
154 | TolU, TolV); | |
155 | Perform(P); | |
156 | } | |
157 | ||
158 | //======================================================================= | |
159 | //function : Extrema_ExtPS | |
160 | //purpose : | |
161 | //======================================================================= | |
162 | ||
163 | Extrema_ExtPS::Extrema_ExtPS(const gp_Pnt& P, | |
164 | const Adaptor3d_Surface& S, | |
165 | const Standard_Real Uinf, | |
166 | const Standard_Real Usup, | |
167 | const Standard_Real Vinf, | |
168 | const Standard_Real Vsup, | |
169 | const Standard_Real TolU, | |
92d1589b A |
170 | const Standard_Real TolV, |
171 | const Extrema_ExtFlag F, | |
172 | const Extrema_ExtAlgo A) | |
7fd59977 | 173 | |
174 | { | |
92d1589b A |
175 | myExtPS.SetFlag(F); |
176 | myExtPS.SetAlgo(A); | |
7fd59977 | 177 | Initialize(S, Uinf, Usup, Vinf, Vsup, TolU, TolV); |
178 | Perform(P); | |
179 | } | |
180 | ||
181 | ||
182 | //======================================================================= | |
183 | //function : Initialize | |
184 | //purpose : | |
185 | //======================================================================= | |
186 | ||
187 | void Extrema_ExtPS::Initialize(const Adaptor3d_Surface& S, | |
188 | const Standard_Real Uinf, | |
189 | const Standard_Real Usup, | |
190 | const Standard_Real Vinf, | |
191 | const Standard_Real Vsup, | |
192 | const Standard_Real TolU, | |
193 | const Standard_Real TolV) | |
194 | { | |
195 | myS = (Adaptor3d_SurfacePtr)&S; | |
196 | myuinf = Uinf; | |
197 | myusup = Usup; | |
198 | myvinf = Vinf; | |
199 | myvsup = Vsup; | |
200 | ||
201 | if (Precision::IsNegativeInfinite(myuinf)) myuinf = -1e10; | |
202 | if (Precision::IsPositiveInfinite(myusup)) myusup = 1e10; | |
203 | if (Precision::IsNegativeInfinite(myvinf)) myvinf = -1e10; | |
204 | if (Precision::IsPositiveInfinite(myvsup)) myvsup = 1e10; | |
205 | ||
206 | mytolu = TolU; | |
207 | mytolv = TolV; | |
208 | mytype = myS->GetType(); | |
209 | ||
210 | Standard_Boolean isB = ( myS->GetType() == GeomAbs_BSplineSurface || | |
211 | myS->GetType() == GeomAbs_BezierSurface ); | |
212 | ||
213 | Standard_Integer nbU = (isB) ? 44 : 32; | |
214 | Standard_Integer nbV = (isB) ? 44 : 32; | |
215 | ||
216 | Standard_Boolean bUIsoIsDeg = Standard_False, bVIsoIsDeg = Standard_False; | |
217 | ||
218 | if(myS->GetType() != GeomAbs_Plane) { | |
219 | bUIsoIsDeg = IsoIsDeg(S, myuinf, GeomAbs_IsoU, 0., 1.e-9) || | |
220 | IsoIsDeg(S, myusup, GeomAbs_IsoU, 0., 1.e-9); | |
221 | bVIsoIsDeg = IsoIsDeg(S, myvinf, GeomAbs_IsoV, 0., 1.e-9) || | |
222 | IsoIsDeg(S, myvsup, GeomAbs_IsoV, 0., 1.e-9); | |
223 | } | |
224 | ||
225 | if(bUIsoIsDeg) nbU = 300; | |
226 | if(bVIsoIsDeg) nbV = 300; | |
227 | ||
228 | myExtPS.Initialize(*myS, nbU, nbV, myuinf, myusup, myvinf, myvsup, mytolu, mytolv); | |
229 | } | |
230 | ||
231 | //======================================================================= | |
232 | //function : Perform | |
233 | //purpose : | |
234 | //======================================================================= | |
235 | ||
236 | void Extrema_ExtPS::Perform(const gp_Pnt& P) | |
237 | { | |
238 | myPoints.Clear(); | |
239 | mySqDist.Clear(); | |
240 | Standard_Integer i; | |
5368adff | 241 | |
7fd59977 | 242 | |
243 | switch(mytype) { | |
244 | ||
245 | case GeomAbs_Cylinder: | |
246 | myExtPElS.Perform(P, myS->Cylinder(), Precision::Confusion()); | |
247 | break; | |
248 | case GeomAbs_Plane: | |
249 | myExtPElS.Perform(P, myS->Plane(), Precision::Confusion()); | |
250 | break; | |
251 | case GeomAbs_Cone: | |
252 | myExtPElS.Perform(P, myS->Cone(), Precision::Confusion()); | |
253 | break; | |
254 | case GeomAbs_Sphere: | |
255 | myExtPElS.Perform(P, myS->Sphere(), Precision::Confusion()); | |
256 | break; | |
257 | case GeomAbs_Torus: | |
258 | myExtPElS.Perform(P, myS->Torus(), Precision::Confusion()); | |
259 | break; | |
260 | ||
261 | ||
262 | case GeomAbs_SurfaceOfExtrusion: { | |
263 | Extrema_ExtPExtS anExtPExtS(P, | |
264 | Adaptor3d_SurfaceOfLinearExtrusion(myS->BasisCurve(), | |
265 | myS->Direction()), | |
266 | myuinf,myusup, myvinf,myvsup, mytolu,mytolv); | |
267 | myDone = anExtPExtS.IsDone(); | |
268 | if (myDone) | |
269 | for (i = 1; i <= anExtPExtS.NbExt(); i++) { | |
270 | TreatSolution (anExtPExtS.Point(i), anExtPExtS.SquareDistance(i)); | |
271 | } | |
272 | return; | |
273 | } | |
274 | ||
275 | ||
276 | case GeomAbs_SurfaceOfRevolution: { | |
277 | Extrema_ExtPRevS anExtPRevS(P, | |
278 | Adaptor3d_SurfaceOfRevolution(myS->BasisCurve(), | |
279 | myS->AxeOfRevolution()), | |
280 | myuinf, myusup,myvinf, myvsup,mytolu, mytolv); | |
281 | myDone = anExtPRevS.IsDone(); | |
282 | if (myDone) | |
283 | for (i = 1; i <= anExtPRevS.NbExt(); i++) { | |
284 | TreatSolution (anExtPRevS.Point(i), anExtPRevS.SquareDistance(i)); | |
285 | } | |
286 | return; | |
287 | } | |
288 | ||
289 | ||
290 | default: | |
291 | myExtPS.Perform(P); | |
292 | myDone = myExtPS.IsDone(); | |
293 | if (myDone) | |
294 | for (i = 1; i <= myExtPS.NbExt(); i++) | |
295 | TreatSolution (myExtPS.Point(i), myExtPS.SquareDistance(i)); | |
296 | return; | |
297 | } | |
298 | ||
299 | ||
300 | myDone = myExtPElS.IsDone(); | |
301 | if (myDone) | |
302 | for (i = 1; i <= myExtPElS.NbExt(); i++) | |
303 | TreatSolution (myExtPElS.Point(i), myExtPElS.SquareDistance(i)); | |
304 | return; | |
305 | } | |
306 | ||
307 | ||
308 | ||
309 | Standard_Boolean Extrema_ExtPS::IsDone() const | |
310 | { | |
311 | return myDone; | |
312 | } | |
313 | ||
314 | ||
315 | Standard_Real Extrema_ExtPS::SquareDistance(const Standard_Integer N) const | |
316 | { | |
317 | if(!myDone) StdFail_NotDone::Raise(); | |
318 | if ((N < 1) || (N > mySqDist.Length())) Standard_OutOfRange::Raise(); | |
319 | return mySqDist.Value(N); | |
320 | } | |
321 | ||
322 | ||
323 | Standard_Integer Extrema_ExtPS::NbExt() const | |
324 | { | |
325 | if(!myDone) StdFail_NotDone::Raise(); | |
326 | return mySqDist.Length(); | |
327 | } | |
328 | ||
329 | ||
330 | ||
5d99f2c8 | 331 | const Extrema_POnSurf& Extrema_ExtPS::Point(const Standard_Integer N) const |
7fd59977 | 332 | { |
333 | if(!myDone) StdFail_NotDone::Raise(); | |
334 | return myPoints.Value(N); | |
335 | } | |
336 | ||
337 | ||
338 | void Extrema_ExtPS::TrimmedSquareDistances(Standard_Real& dUfVf, | |
339 | Standard_Real& dUfVl, | |
340 | Standard_Real& dUlVf, | |
341 | Standard_Real& dUlVl, | |
342 | gp_Pnt& PUfVf, | |
343 | gp_Pnt& PUfVl, | |
344 | gp_Pnt& PUlVf, | |
345 | gp_Pnt& PUlVl) const | |
346 | { | |
347 | dUfVf = d11; | |
348 | dUfVl = d12; | |
349 | dUlVf = d21; | |
350 | dUlVl = d22; | |
351 | PUfVf = P11; | |
352 | PUfVl = P12; | |
353 | PUlVf = P21; | |
354 | PUlVl = P22; | |
355 | } | |
92d1589b A |
356 | |
357 | void Extrema_ExtPS::SetFlag(const Extrema_ExtFlag F) | |
358 | { | |
359 | myExtPS.SetFlag(F); | |
360 | } | |
361 | ||
362 | void Extrema_ExtPS::SetAlgo(const Extrema_ExtAlgo A) | |
363 | { | |
364 | myExtPS.SetAlgo(A); | |
0d969553 | 365 | } |