Commit | Line | Data |
---|---|---|
b311480e | 1 | // Created on: 1995-07-18 |
2 | // Created by: Modelistation | |
3 | // Copyright (c) 1995-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 | |
17 | // Modified by skv - Thu Sep 30 15:21:07 2004 OCC593 | |
18 | ||
42cf5bc1 | 19 | #include <Adaptor3d_Curve.hxx> |
20 | #include <Adaptor3d_HCurve.hxx> | |
21 | #include <Adaptor3d_HSurface.hxx> | |
22 | #include <Adaptor3d_Surface.hxx> | |
92d1589b A |
23 | #include <Bnd_Array1OfSphere.hxx> |
24 | #include <Bnd_HArray1OfSphere.hxx> | |
42cf5bc1 | 25 | #include <Bnd_Sphere.hxx> |
26 | #include <Extrema_ExtFlag.hxx> | |
27 | #include <Extrema_GenExtPS.hxx> | |
28 | #include <Extrema_HUBTreeOfSphere.hxx> | |
29 | #include <Extrema_POnSurf.hxx> | |
30 | #include <Extrema_POnSurfParams.hxx> | |
31 | #include <Geom_BezierCurve.hxx> | |
5368adff | 32 | #include <Geom_BezierSurface.hxx> |
5368adff | 33 | #include <Geom_BSplineCurve.hxx> |
42cf5bc1 | 34 | #include <Geom_BSplineSurface.hxx> |
35 | #include <Geom_OffsetSurface.hxx> | |
36 | #include <Geom_RectangularTrimmedSurface.hxx> | |
37 | #include <GeomAbs_IsoType.hxx> | |
38 | #include <gp_Pnt.hxx> | |
39 | #include <math_FunctionSetRoot.hxx> | |
40 | #include <math_NewtonFunctionSetRoot.hxx> | |
41 | #include <math_Vector.hxx> | |
42 | #include <Precision.hxx> | |
43 | #include <Standard_OutOfRange.hxx> | |
44 | #include <Standard_TypeMismatch.hxx> | |
45 | #include <StdFail_NotDone.hxx> | |
46 | #include <TColgp_Array2OfPnt.hxx> | |
47 | #include <TColStd_Array2OfInteger.hxx> | |
48 | #include <TColStd_Array2OfReal.hxx> | |
92d1589b | 49 | |
42cf5bc1 | 50 | //IMPLEMENT_HARRAY1(Extrema_HArray1OfSphere) |
92d1589b A |
51 | class Bnd_SphereUBTreeSelector : public Extrema_UBTreeOfSphere::Selector |
52 | { | |
53 | public: | |
54 | ||
55 | Bnd_SphereUBTreeSelector (const Handle(Bnd_HArray1OfSphere)& theSphereArray, | |
56 | Bnd_Sphere& theSol) | |
57 | : myXYZ(0,0,0), | |
58 | mySphereArray(theSphereArray), | |
59 | mySol(theSol) | |
60 | { | |
92d1589b A |
61 | } |
62 | ||
63 | void DefineCheckPoint( const gp_Pnt& theXYZ ) | |
64 | { myXYZ = theXYZ; } | |
65 | ||
66 | Bnd_Sphere& Sphere() const | |
67 | { return mySol; } | |
68 | ||
69 | virtual Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const = 0; | |
70 | ||
71 | virtual Standard_Boolean Accept(const Standard_Integer& theObj) = 0; | |
92d1589b | 72 | protected: |
d390b166 | 73 | gp_Pnt myXYZ; |
74 | const Handle(Bnd_HArray1OfSphere)& mySphereArray; | |
75 | Bnd_Sphere& mySol; | |
76 | private: | |
77 | void operator= (const Bnd_SphereUBTreeSelector&); | |
92d1589b A |
78 | |
79 | }; | |
80 | ||
81 | class Bnd_SphereUBTreeSelectorMin : public Bnd_SphereUBTreeSelector | |
82 | { | |
83 | public: | |
84 | Bnd_SphereUBTreeSelectorMin (const Handle(Bnd_HArray1OfSphere)& theSphereArray, | |
85 | Bnd_Sphere& theSol) | |
86 | : Bnd_SphereUBTreeSelector(theSphereArray, theSol), | |
87 | myMinDist(RealLast()) | |
88 | {} | |
89 | ||
90 | void SetMinDist( const Standard_Real theMinDist ) | |
91 | { myMinDist = theMinDist; } | |
92 | ||
93 | Standard_Real MinDist() const | |
94 | { return myMinDist; } | |
95 | ||
96 | Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const | |
97 | { | |
98 | Bnd_SphereUBTreeSelectorMin* me = | |
99 | const_cast<Bnd_SphereUBTreeSelectorMin*>(this); | |
100 | // myMinDist is decreased each time a nearer object is found | |
101 | return theBnd.IsOut( myXYZ.XYZ(), me->myMinDist ); | |
102 | } | |
103 | ||
104 | Standard_Boolean Accept(const Standard_Integer&); | |
105 | ||
106 | private: | |
107 | Standard_Real myMinDist; | |
108 | }; | |
109 | ||
110 | Standard_Boolean Bnd_SphereUBTreeSelectorMin::Accept(const Standard_Integer& theInd) | |
111 | { | |
112 | const Bnd_Sphere& aSph = mySphereArray->Value(theInd); | |
113 | Standard_Real aCurDist; | |
114 | ||
aeaf53d5 | 115 | // if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) < mySol.SquareDistance(myXYZ.XYZ()) ) |
116 | if ( (aCurDist = aSph.Distance(myXYZ.XYZ())) < mySol.Distance(myXYZ.XYZ()) ) | |
92d1589b A |
117 | { |
118 | mySol = aSph; | |
119 | if ( aCurDist < myMinDist ) | |
120 | myMinDist = aCurDist; | |
121 | ||
122 | return Standard_True; | |
123 | } | |
124 | ||
125 | return Standard_False; | |
126 | } | |
127 | ||
128 | class Bnd_SphereUBTreeSelectorMax : public Bnd_SphereUBTreeSelector | |
129 | { | |
130 | public: | |
131 | Bnd_SphereUBTreeSelectorMax (const Handle(Bnd_HArray1OfSphere)& theSphereArray, | |
132 | Bnd_Sphere& theSol) | |
133 | : Bnd_SphereUBTreeSelector(theSphereArray, theSol), | |
134 | myMaxDist(0) | |
135 | {} | |
136 | ||
137 | void SetMaxDist( const Standard_Real theMaxDist ) | |
138 | { myMaxDist = theMaxDist; } | |
139 | ||
140 | Standard_Real MaxDist() const | |
141 | { return myMaxDist; } | |
142 | ||
143 | Standard_Boolean Reject( const Bnd_Sphere &theBnd ) const | |
144 | { | |
145 | Bnd_SphereUBTreeSelectorMax* me = | |
146 | const_cast<Bnd_SphereUBTreeSelectorMax*>(this); | |
147 | // myMaxDist is decreased each time a nearer object is found | |
148 | return theBnd.IsOut( myXYZ.XYZ(), me->myMaxDist ); | |
149 | } | |
150 | ||
151 | Standard_Boolean Accept(const Standard_Integer&); | |
152 | ||
153 | private: | |
154 | Standard_Real myMaxDist; | |
155 | }; | |
156 | ||
157 | Standard_Boolean Bnd_SphereUBTreeSelectorMax::Accept(const Standard_Integer& theInd) | |
158 | { | |
159 | const Bnd_Sphere& aSph = mySphereArray->Value(theInd); | |
160 | Standard_Real aCurDist; | |
161 | ||
aeaf53d5 | 162 | // if ( (aCurDist = aSph.SquareDistance(myXYZ.XYZ())) > mySol.SquareDistance(myXYZ.XYZ()) ) |
163 | if ( (aCurDist = aSph.Distance(myXYZ.XYZ())) > mySol.Distance(myXYZ.XYZ()) ) | |
92d1589b A |
164 | { |
165 | mySol = aSph; | |
166 | if ( aCurDist > myMaxDist ) | |
167 | myMaxDist = aCurDist; | |
168 | ||
169 | return Standard_True; | |
170 | } | |
171 | ||
172 | return Standard_False; | |
173 | } | |
7fd59977 | 174 | |
7fd59977 | 175 | //============================================================================= |
176 | ||
177 | /*----------------------------------------------------------------------------- | |
92d1589b A |
178 | Function: |
179 | Find all extremum distances between point P and surface | |
180 | S using sampling (NbU,NbV). | |
7fd59977 | 181 | |
92d1589b | 182 | Method: |
0d969553 Y |
183 | The algorithm bases on the hypothesis that sampling is precise enough, |
184 | if there exist N extreme distances between the point and the surface, | |
185 | so there also exist N extrema between the point and the grid. | |
92d1589b A |
186 | So, the algorithm consists in starting from extrema of the grid to find the |
187 | extrema of the surface. | |
188 | The extrema are calculated by the algorithm math_FunctionSetRoot with the | |
189 | following arguments: | |
190 | - F: Extrema_FuncExtPS created from P and S, | |
191 | - UV: math_Vector the components which of are parameters of the extremum on the | |
192 | grid, | |
193 | - Tol: Min(TolU,TolV), (Prov.:math_FunctionSetRoot does not autorize a vector) | |
194 | - UVinf: math_Vector the components which of are lower limits of u and v, | |
195 | - UVsup: math_Vector the components which of are upper limits of u and v. | |
196 | ||
197 | Processing: | |
198 | a- Creation of the table of distances (TbDist(0,NbU+1,0,NbV+1)): | |
199 | The table is expanded at will; lines 0 and NbU+1 and | |
200 | columns 0 and NbV+1 are initialized at RealFirst() or RealLast() | |
201 | to simplify the tests carried out at stage b | |
202 | (there is no need to test if the point is on border of the grid). | |
203 | b- Calculation of extrema: | |
204 | First the minimums and then the maximums are found. These 2 procedured | |
205 | pass in a similar way: | |
206 | b.a- Initialization: | |
207 | - 'borders' of table TbDist (RealLast() in case of minimums | |
208 | and RealLast() in case of maximums), | |
209 | - table TbSel(0,NbU+1,0,NbV+1) of selection of points for | |
210 | calculation of local extremum (0). When a point will selected, | |
211 | it will not be selectable, as well as the ajacent points | |
212 | (8 at least). The corresponding addresses will be set to 1. | |
213 | b.b- Calculation of minimums (or maximums): | |
214 | All distances from table TbDist are parsed in a loop: | |
215 | - search minimum (or maximum) in the grid, | |
216 | - calculate extremum on the surface, | |
217 | - update table TbSel. | |
7fd59977 | 218 | -----------------------------------------------------------------------------*/ |
219 | ||
7fd59977 | 220 | Extrema_GenExtPS::Extrema_GenExtPS() |
221 | { | |
222 | myDone = Standard_False; | |
223 | myInit = Standard_False; | |
92d1589b A |
224 | myFlag = Extrema_ExtFlag_MINMAX; |
225 | myAlgo = Extrema_ExtAlgo_Grad; | |
7fd59977 | 226 | } |
227 | ||
228 | ||
229 | Extrema_GenExtPS::Extrema_GenExtPS (const gp_Pnt& P, | |
150e93a7 | 230 | const Adaptor3d_Surface& S, |
231 | const Standard_Integer NbU, | |
232 | const Standard_Integer NbV, | |
233 | const Standard_Real TolU, | |
234 | const Standard_Real TolV, | |
235 | const Extrema_ExtFlag F, | |
236 | const Extrema_ExtAlgo A) | |
237 | : myF (P,S), | |
238 | myFlag(F), | |
239 | myAlgo(A) | |
7fd59977 | 240 | { |
241 | Initialize(S, NbU, NbV, TolU, TolV); | |
242 | Perform(P); | |
243 | } | |
244 | ||
245 | Extrema_GenExtPS::Extrema_GenExtPS (const gp_Pnt& P, | |
150e93a7 | 246 | const Adaptor3d_Surface& S, |
247 | const Standard_Integer NbU, | |
248 | const Standard_Integer NbV, | |
249 | const Standard_Real Umin, | |
250 | const Standard_Real Usup, | |
251 | const Standard_Real Vmin, | |
252 | const Standard_Real Vsup, | |
253 | const Standard_Real TolU, | |
254 | const Standard_Real TolV, | |
255 | const Extrema_ExtFlag F, | |
256 | const Extrema_ExtAlgo A) | |
257 | : myF (P,S), | |
258 | myFlag(F), | |
259 | myAlgo(A) | |
7fd59977 | 260 | { |
261 | Initialize(S, NbU, NbV, Umin, Usup, Vmin, Vsup, TolU, TolV); | |
262 | Perform(P); | |
263 | } | |
264 | ||
265 | ||
266 | void Extrema_GenExtPS::Initialize(const Adaptor3d_Surface& S, | |
150e93a7 | 267 | const Standard_Integer NbU, |
268 | const Standard_Integer NbV, | |
269 | const Standard_Real TolU, | |
270 | const Standard_Real TolV) | |
7fd59977 | 271 | { |
272 | myumin = S.FirstUParameter(); | |
273 | myusup = S.LastUParameter(); | |
274 | myvmin = S.FirstVParameter(); | |
275 | myvsup = S.LastVParameter(); | |
276 | Initialize(S,NbU,NbV,myumin,myusup,myvmin,myvsup,TolU,TolV); | |
277 | } | |
278 | ||
279 | ||
280 | void Extrema_GenExtPS::Initialize(const Adaptor3d_Surface& S, | |
150e93a7 | 281 | const Standard_Integer NbU, |
282 | const Standard_Integer NbV, | |
283 | const Standard_Real Umin, | |
284 | const Standard_Real Usup, | |
285 | const Standard_Real Vmin, | |
286 | const Standard_Real Vsup, | |
287 | const Standard_Real TolU, | |
288 | const Standard_Real TolV) | |
7fd59977 | 289 | { |
7fd59977 | 290 | myS = (Adaptor3d_SurfacePtr)&S; |
291 | myusample = NbU; | |
292 | myvsample = NbV; | |
293 | mytolu = TolU; | |
294 | mytolv = TolV; | |
295 | myumin = Umin; | |
296 | myusup = Usup; | |
297 | myvmin = Vmin; | |
298 | myvsup = Vsup; | |
299 | ||
300 | if ((myusample < 2) || | |
301 | (myvsample < 2)) { Standard_OutOfRange::Raise(); } | |
302 | ||
303 | myF.Initialize(S); | |
304 | ||
82469411 | 305 | mySphereUBTree.Nullify(); |
5368adff | 306 | myUParams.Nullify(); |
307 | myVParams.Nullify(); | |
308 | myInit = Standard_False; | |
309 | } | |
7fd59977 | 310 | |
5368adff | 311 | inline static void fillParams(const TColStd_Array1OfReal& theKnots, |
312 | Standard_Integer theDegree, | |
313 | Standard_Real theParMin, | |
314 | Standard_Real theParMax, | |
857ffd5e | 315 | Handle(TColStd_HArray1OfReal)& theParams, |
5368adff | 316 | Standard_Integer theSample) |
317 | { | |
318 | NCollection_Vector<Standard_Real> aParams; | |
319 | Standard_Integer i = 1; | |
320 | Standard_Real aPrevPar = theParMin; | |
321 | aParams.Append(aPrevPar); | |
322 | //calculation the array of parametric points depending on the knots array variation and degree of given surface | |
323 | for ( ; i < theKnots.Length() && theKnots(i) < (theParMax - Precision::PConfusion()); i++ ) | |
92d1589b | 324 | { |
5368adff | 325 | if ( theKnots(i+1) < theParMin + Precision::PConfusion()) |
326 | continue; | |
327 | ||
328 | Standard_Real aStep = (theKnots(i+1) - theKnots(i))/Max(theDegree,2); | |
329 | Standard_Integer k =1; | |
330 | for( ; k <= theDegree ; k++) | |
331 | { | |
332 | Standard_Real aPar = theKnots(i) + k * aStep; | |
333 | if(aPar > theParMax - Precision::PConfusion()) | |
334 | break; | |
335 | if(aPar > aPrevPar + Precision::PConfusion() ) | |
336 | { | |
337 | aParams.Append(aPar); | |
338 | aPrevPar = aPar; | |
339 | } | |
340 | } | |
341 | ||
342 | } | |
343 | aParams.Append(theParMax); | |
344 | Standard_Integer nbPar = aParams.Length(); | |
345 | //in case of an insufficient number of points the grid will be built later | |
346 | if (nbPar < theSample) | |
347 | return; | |
348 | theParams = new TColStd_HArray1OfReal(1, nbPar ); | |
349 | for( i = 0; i < nbPar; i++) | |
350 | theParams->SetValue(i+1,aParams(i)); | |
351 | } | |
352 | ||
353 | void Extrema_GenExtPS::GetGridPoints( const Adaptor3d_Surface& theSurf) | |
354 | { | |
355 | //creation parametric points for BSpline and Bezier surfaces | |
356 | //with taking into account of Degree and NbKnots of BSpline or Bezier geometry | |
357 | if(theSurf.GetType() == GeomAbs_OffsetSurface) | |
358 | GetGridPoints(theSurf.BasisSurface()->Surface()); | |
359 | //parametric points for BSpline surfaces | |
360 | else if( theSurf.GetType() == GeomAbs_BSplineSurface) | |
361 | { | |
362 | Handle(Geom_BSplineSurface) aBspl = theSurf.BSpline(); | |
363 | if(!aBspl.IsNull()) | |
364 | { | |
365 | TColStd_Array1OfReal aUKnots(1, aBspl->NbUKnots()); | |
366 | aBspl->UKnots( aUKnots); | |
367 | TColStd_Array1OfReal aVKnots(1, aBspl->NbVKnots()); | |
368 | aBspl->VKnots( aVKnots); | |
369 | fillParams(aUKnots,aBspl->UDegree(),myumin, myusup, myUParams, myusample); | |
370 | fillParams(aVKnots,aBspl->VDegree(),myvmin, myvsup, myVParams, myvsample); | |
371 | } | |
372 | } | |
373 | //calculation parametric points for Bezier surfaces | |
374 | else if(theSurf.GetType() == GeomAbs_BezierSurface) | |
375 | { | |
376 | Handle(Geom_BezierSurface) aBezier = theSurf.Bezier(); | |
377 | if(aBezier.IsNull()) | |
378 | return; | |
379 | ||
380 | TColStd_Array1OfReal aUKnots(1,2); | |
381 | TColStd_Array1OfReal aVKnots(1,2); | |
382 | aBezier->Bounds(aUKnots(1), aUKnots(2), aVKnots(1), aVKnots(2)); | |
383 | fillParams(aUKnots, aBezier->UDegree(), myumin, myusup, myUParams, myusample); | |
384 | fillParams(aVKnots, aBezier->VDegree(), myvmin, myvsup, myVParams, myvsample); | |
7fd59977 | 385 | |
5368adff | 386 | } |
387 | //creation points for surfaces based on BSpline or Bezier curves | |
388 | else if(theSurf.GetType() == GeomAbs_SurfaceOfRevolution || | |
389 | theSurf.GetType() == GeomAbs_SurfaceOfExtrusion) | |
390 | { | |
391 | Handle(TColStd_HArray1OfReal) anArrKnots; | |
392 | Standard_Integer aDegree = 0; | |
5368adff | 393 | if(theSurf.BasisCurve()->Curve().GetType() == GeomAbs_BSplineCurve) |
394 | { | |
395 | Handle(Geom_BSplineCurve) aBspl = theSurf.BasisCurve()->Curve().BSpline(); | |
396 | if(!aBspl.IsNull()) | |
397 | { | |
398 | anArrKnots = new TColStd_HArray1OfReal(1,aBspl->NbKnots()); | |
399 | aBspl->Knots( anArrKnots->ChangeArray1() ); | |
400 | aDegree = aBspl->Degree(); | |
401 | ||
402 | } | |
403 | ||
404 | } | |
405 | if(theSurf.BasisCurve()->Curve().GetType() == GeomAbs_BezierCurve) | |
406 | { | |
407 | Handle(Geom_BezierCurve) aBez = theSurf.BasisCurve()->Curve().Bezier(); | |
408 | if(!aBez.IsNull()) | |
409 | { | |
410 | anArrKnots = new TColStd_HArray1OfReal(1,2); | |
411 | anArrKnots->SetValue(1, aBez->FirstParameter()); | |
412 | anArrKnots->SetValue(2, aBez->LastParameter()); | |
413 | aDegree = aBez->Degree(); | |
414 | ||
415 | } | |
416 | } | |
417 | if(anArrKnots.IsNull()) | |
418 | return; | |
419 | if( theSurf.GetType() == GeomAbs_SurfaceOfRevolution ) | |
420 | fillParams( anArrKnots->Array1(), aDegree, myvmin, myvsup, myVParams, myvsample); | |
421 | else | |
422 | fillParams( anArrKnots->Array1(), aDegree, myumin, myusup, myUParams, myusample); | |
423 | } | |
424 | //update the number of points in sample | |
425 | if(!myUParams.IsNull()) | |
426 | myusample = myUParams->Length(); | |
427 | if( !myVParams.IsNull()) | |
428 | myvsample = myVParams->Length(); | |
429 | ||
430 | } | |
431 | ||
150e93a7 | 432 | /* |
433 | * This function computes the point on surface parameters on edge. | |
434 | * if it coincides with theParam0 or theParam1, it is returned. | |
435 | */ | |
436 | const Extrema_POnSurfParams& Extrema_GenExtPS::ComputeEdgeParameters | |
437 | (const Standard_Boolean IsUEdge, | |
438 | const Extrema_POnSurfParams &theParam0, | |
439 | const Extrema_POnSurfParams &theParam1, | |
440 | const gp_Pnt &thePoint, | |
441 | const Standard_Real theDiffTol) | |
442 | { | |
443 | const Standard_Real aSqrDist01 = | |
444 | theParam0.Value().SquareDistance(theParam1.Value()); | |
445 | ||
446 | if (aSqrDist01 <= theDiffTol) | |
447 | { | |
448 | // The points are confused. Get the first point and change its type. | |
449 | return theParam0; | |
450 | } | |
451 | else | |
452 | { | |
453 | const Standard_Real aDiffDist = | |
454 | Abs(theParam0.GetSqrDistance() - theParam1.GetSqrDistance()); | |
455 | ||
456 | if (aDiffDist >= aSqrDist01 - theDiffTol) | |
457 | { | |
458 | // The shortest distance is one of the nodes. | |
459 | if (theParam0.GetSqrDistance() > theParam1.GetSqrDistance()) | |
460 | { | |
461 | // The shortest distance is the point 1. | |
462 | return theParam1; | |
463 | } | |
464 | else | |
465 | { | |
466 | // The shortest distance is the point 0. | |
467 | return theParam0; | |
468 | } | |
469 | } | |
470 | else | |
471 | { | |
472 | // The shortest distance is inside the edge. | |
473 | gp_XYZ aPoP(thePoint.XYZ().Subtracted(theParam0.Value().XYZ())); | |
474 | gp_XYZ aPoP1(theParam1.Value().XYZ().Subtracted(theParam0.Value().XYZ())); | |
475 | Standard_Real aRatio = aPoP.Dot(aPoP1)/aSqrDist01; | |
476 | Standard_Real aU[2]; | |
477 | Standard_Real aV[2]; | |
478 | ||
479 | theParam0.Parameter(aU[0], aV[0]); | |
480 | theParam1.Parameter(aU[1], aV[1]); | |
481 | ||
482 | Standard_Real aUPar = aU[0]; | |
483 | Standard_Real aVPar = aV[0]; | |
484 | ||
485 | if (IsUEdge) | |
486 | { | |
487 | aUPar += aRatio*(aU[1] - aU[0]); | |
488 | } | |
489 | else | |
490 | { | |
491 | aVPar += aRatio*(aV[1] - aV[0]); | |
492 | } | |
493 | ||
494 | myGridParam.SetParameters(aUPar, aVPar, myS->Value(aUPar, aVPar)); | |
495 | Standard_Integer anIndices[2]; | |
496 | ||
497 | theParam0.GetIndices(anIndices[0], anIndices[1]); | |
498 | myGridParam.SetElementType(IsUEdge ? Extrema_UIsoEdge : Extrema_VIsoEdge); | |
499 | myGridParam.SetSqrDistance(thePoint.SquareDistance(myGridParam.Value())); | |
500 | myGridParam.SetIndices(anIndices[0], anIndices[1]); | |
501 | return myGridParam; | |
502 | } | |
503 | } | |
504 | } | |
505 | ||
6060dd1f | 506 | void Extrema_GenExtPS::BuildGrid(const gp_Pnt &thePoint) |
5368adff | 507 | { |
6060dd1f | 508 | Standard_Integer NoU, NoV; |
509 | ||
510 | //if grid was already built skip its creation | |
511 | if (!myInit) { | |
512 | //build parametric grid in case of a complex surface geometry (BSpline and Bezier surfaces) | |
513 | GetGridPoints(*myS); | |
514 | ||
515 | //build grid in other cases | |
516 | if( myUParams.IsNull() ) | |
517 | { | |
518 | Standard_Real PasU = myusup - myumin; | |
519 | Standard_Real U0 = PasU / myusample / 100.; | |
520 | PasU = (PasU - U0) / (myusample - 1); | |
521 | U0 = U0/2. + myumin; | |
522 | myUParams = new TColStd_HArray1OfReal(1,myusample ); | |
523 | Standard_Integer NoU; | |
524 | Standard_Real U = U0; | |
525 | for ( NoU = 1 ; NoU <= myusample; NoU++, U += PasU) | |
526 | myUParams->SetValue(NoU, U); | |
527 | } | |
5368adff | 528 | |
6060dd1f | 529 | if( myVParams.IsNull()) |
530 | { | |
531 | Standard_Real PasV = myvsup - myvmin; | |
532 | Standard_Real V0 = PasV / myvsample / 100.; | |
533 | PasV = (PasV - V0) / (myvsample - 1); | |
534 | V0 = V0/2. + myvmin; | |
535 | ||
536 | myVParams = new TColStd_HArray1OfReal(1,myvsample ); | |
537 | Standard_Integer NoV; | |
538 | Standard_Real V = V0; | |
539 | ||
540 | for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) | |
541 | myVParams->SetValue(NoV, V); | |
542 | } | |
543 | ||
544 | //If flag was changed and extrema not reinitialized Extrema would fail | |
545 | myPoints = new Extrema_HArray2OfPOnSurfParams | |
546 | (0, myusample + 1, 0, myvsample + 1); | |
547 | // Calculation of distances | |
5368adff | 548 | |
6060dd1f | 549 | for ( NoU = 1 ; NoU <= myusample; NoU++ ) { |
550 | for ( NoV = 1 ; NoV <= myvsample; NoV++) { | |
551 | gp_Pnt aP1 = myS->Value(myUParams->Value(NoU), myVParams->Value(NoV)); | |
552 | Extrema_POnSurfParams aParam | |
553 | (myUParams->Value(NoU), myVParams->Value(NoV), aP1); | |
554 | ||
555 | aParam.SetElementType(Extrema_Node); | |
556 | aParam.SetIndices(NoU, NoV); | |
557 | myPoints->SetValue(NoU, NoV, aParam); | |
558 | } | |
559 | } | |
5368adff | 560 | |
150e93a7 | 561 | myFacePntParams = |
562 | new Extrema_HArray2OfPOnSurfParams(0, myusample, 0, myvsample); | |
563 | ||
564 | myUEdgePntParams = | |
565 | new Extrema_HArray2OfPOnSurfParams(1, myusample - 1, 1, myvsample); | |
566 | myVEdgePntParams = | |
567 | new Extrema_HArray2OfPOnSurfParams(1, myusample, 1, myvsample - 1); | |
568 | ||
6060dd1f | 569 | // Fill boundary with negative square distance. |
570 | // It is used for computation of Maximum. | |
571 | for (NoV = 0; NoV <= myvsample + 1; NoV++) { | |
572 | myPoints->ChangeValue(0, NoV).SetSqrDistance(-1.); | |
573 | myPoints->ChangeValue(myusample + 1, NoV).SetSqrDistance(-1.); | |
574 | } | |
5368adff | 575 | |
6060dd1f | 576 | for (NoU = 1; NoU <= myusample; NoU++) { |
577 | myPoints->ChangeValue(NoU, 0).SetSqrDistance(-1.); | |
578 | myPoints->ChangeValue(NoU, myvsample + 1).SetSqrDistance(-1.); | |
579 | } | |
5368adff | 580 | |
6060dd1f | 581 | myInit = Standard_True; |
5368adff | 582 | } |
7fd59977 | 583 | |
6060dd1f | 584 | // Compute distances to mesh. |
585 | // Step 1. Compute distances to nodes. | |
5368adff | 586 | for ( NoU = 1 ; NoU <= myusample; NoU++ ) { |
587 | for ( NoV = 1 ; NoV <= myvsample; NoV++) { | |
6060dd1f | 588 | Extrema_POnSurfParams &aParam = myPoints->ChangeValue(NoU, NoV); |
589 | ||
590 | aParam.SetSqrDistance(thePoint.SquareDistance(aParam.Value())); | |
7fd59977 | 591 | } |
592 | } | |
5368adff | 593 | |
6060dd1f | 594 | // For search of minimum compute distances to mesh. |
595 | if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX) | |
596 | { | |
597 | // This is the tolerance of difference of squared values. | |
598 | // No need to set it too small. | |
599 | const Standard_Real aDiffTol = mytolu + mytolv; | |
600 | ||
601 | // Step 2. Compute distances to edges. | |
602 | // Assume UEdge(i, j) = { Point(i, j); Point(i + 1, j ) } | |
603 | // Assume VEdge(i, j) = { Point(i, j); Point(i, j + 1) } | |
150e93a7 | 604 | for ( NoU = 1 ; NoU <= myusample; NoU++ ) |
605 | { | |
606 | for ( NoV = 1 ; NoV <= myvsample; NoV++) | |
607 | { | |
6060dd1f | 608 | const Extrema_POnSurfParams &aParam0 = myPoints->Value(NoU, NoV); |
609 | ||
150e93a7 | 610 | if (NoU < myusample) |
611 | { | |
6060dd1f | 612 | // Compute parameters to UEdge. |
613 | const Extrema_POnSurfParams &aParam1 = myPoints->Value(NoU + 1, NoV); | |
150e93a7 | 614 | const Extrema_POnSurfParams &anEdgeParam = ComputeEdgeParameters(Standard_True, aParam0, aParam1, thePoint, aDiffTol); |
6060dd1f | 615 | |
150e93a7 | 616 | myUEdgePntParams->SetValue(NoU, NoV, anEdgeParam); |
6060dd1f | 617 | } |
92d1589b | 618 | |
150e93a7 | 619 | if (NoV < myvsample) |
620 | { | |
6060dd1f | 621 | // Compute parameters to VEdge. |
622 | const Extrema_POnSurfParams &aParam1 = myPoints->Value(NoU, NoV + 1); | |
150e93a7 | 623 | const Extrema_POnSurfParams &anEdgeParam = ComputeEdgeParameters(Standard_False, aParam0, aParam1, thePoint, aDiffTol); |
92d1589b | 624 | |
150e93a7 | 625 | myVEdgePntParams->SetValue(NoU, NoV, anEdgeParam); |
6060dd1f | 626 | } |
627 | } | |
628 | } | |
629 | ||
630 | // Step 3. Compute distances to faces. | |
631 | // Assume myFacePntParams(i, j) = | |
632 | // { Point(i, j); Point(i + 1, j); Point(i + 1, j + 1); Point(i, j + 1) } | |
633 | // Or | |
634 | // { UEdge(i, j); VEdge(i + 1, j); UEdge(i, j + 1); VEdge(i, j) } | |
6060dd1f | 635 | Standard_Real aSqrDist01; |
636 | Standard_Real aDiffDist; | |
637 | Standard_Boolean isOut; | |
638 | ||
639 | for ( NoU = 1 ; NoU < myusample; NoU++ ) { | |
640 | for ( NoV = 1 ; NoV < myvsample; NoV++) { | |
150e93a7 | 641 | const Extrema_POnSurfParams &aUE0 = myUEdgePntParams->Value(NoU, NoV); |
642 | const Extrema_POnSurfParams &aUE1 = myUEdgePntParams->Value(NoU, NoV+1); | |
643 | const Extrema_POnSurfParams &aVE0 = myVEdgePntParams->Value(NoU, NoV); | |
644 | const Extrema_POnSurfParams &aVE1 = myVEdgePntParams->Value(NoU+1, NoV); | |
6060dd1f | 645 | |
646 | aSqrDist01 = aUE0.Value().SquareDistance(aUE1.Value()); | |
647 | aDiffDist = Abs(aUE0.GetSqrDistance() - aUE1.GetSqrDistance()); | |
648 | isOut = Standard_False; | |
649 | ||
650 | if (aDiffDist >= aSqrDist01 - aDiffTol) { | |
651 | // The projection is outside the face. | |
652 | isOut = Standard_True; | |
653 | } else { | |
654 | aSqrDist01 = aVE0.Value().SquareDistance(aVE1.Value()); | |
655 | aDiffDist = Abs(aVE0.GetSqrDistance() - aVE1.GetSqrDistance()); | |
656 | ||
657 | if (aDiffDist >= aSqrDist01 - aDiffTol) { | |
658 | // The projection is outside the face. | |
659 | isOut = Standard_True; | |
660 | } | |
661 | } | |
662 | ||
663 | if (isOut) { | |
664 | // Get the closest point on an edge. | |
665 | const Extrema_POnSurfParams &aUEMin = | |
666 | aUE0.GetSqrDistance() < aUE1.GetSqrDistance() ? aUE0 : aUE1; | |
667 | const Extrema_POnSurfParams &aVEMin = | |
668 | aVE0.GetSqrDistance() < aVE1.GetSqrDistance() ? aVE0 : aVE1; | |
669 | const Extrema_POnSurfParams &aEMin = | |
670 | aUEMin.GetSqrDistance() < aVEMin.GetSqrDistance() ? aUEMin : aVEMin; | |
671 | ||
672 | myFacePntParams->SetValue(NoU, NoV, aEMin); | |
673 | } else { | |
674 | // Find closest point inside the face. | |
675 | Standard_Real aU[2]; | |
676 | Standard_Real aV[2]; | |
677 | Standard_Real aUPar; | |
678 | Standard_Real aVPar; | |
679 | ||
680 | // Compute U parameter. | |
681 | aUE0.Parameter(aU[0], aV[0]); | |
682 | aUE1.Parameter(aU[1], aV[1]); | |
683 | aUPar = 0.5*(aU[0] + aU[1]); | |
684 | // Compute V parameter. | |
685 | aVE0.Parameter(aU[0], aV[0]); | |
686 | aVE1.Parameter(aU[1], aV[1]); | |
687 | aVPar = 0.5*(aV[0] + aV[1]); | |
688 | ||
689 | Extrema_POnSurfParams aParam(aUPar, aVPar, myS->Value(aUPar, aVPar)); | |
690 | ||
691 | aParam.SetElementType(Extrema_Face); | |
692 | aParam.SetSqrDistance(thePoint.SquareDistance(aParam.Value())); | |
693 | aParam.SetIndices(NoU, NoV); | |
694 | myFacePntParams->SetValue(NoU, NoV, aParam); | |
695 | } | |
696 | } | |
697 | } | |
698 | ||
699 | // Fill boundary with RealLast square distance. | |
700 | for (NoV = 0; NoV <= myvsample; NoV++) { | |
701 | myFacePntParams->ChangeValue(0, NoV).SetSqrDistance(RealLast()); | |
702 | myFacePntParams->ChangeValue(myusample, NoV).SetSqrDistance(RealLast()); | |
703 | } | |
704 | ||
705 | for (NoU = 1; NoU < myusample; NoU++) { | |
706 | myFacePntParams->ChangeValue(NoU, 0).SetSqrDistance(RealLast()); | |
707 | myFacePntParams->ChangeValue(NoU, myvsample).SetSqrDistance(RealLast()); | |
708 | } | |
709 | } | |
710 | } | |
5368adff | 711 | |
0d969553 | 712 | // Parameterisation of the sample |
92d1589b A |
713 | void Extrema_GenExtPS::BuildTree() |
714 | { | |
82469411 A |
715 | // if tree already exists, assume it is already correctly filled |
716 | if ( ! mySphereUBTree.IsNull() ) | |
717 | return; | |
718 | ||
59fcbcae | 719 | if (myS->GetType() == GeomAbs_BSplineSurface) { |
720 | Handle(Geom_BSplineSurface) aBspl = myS->BSpline(); | |
721 | Standard_Integer aUValue = aBspl->UDegree() * aBspl->NbUKnots(); | |
722 | Standard_Integer aVValue = aBspl->VDegree() * aBspl->NbVKnots(); | |
723 | if (aUValue > myusample) | |
724 | myusample = aUValue; | |
725 | if (aVValue > myvsample) | |
726 | myvsample = aVValue; | |
727 | } | |
728 | ||
82469411 A |
729 | Standard_Real PasU = myusup - myumin; |
730 | Standard_Real PasV = myvsup - myvmin; | |
731 | Standard_Real U0 = PasU / myusample / 100.; | |
732 | Standard_Real V0 = PasV / myvsample / 100.; | |
733 | gp_Pnt P1; | |
734 | PasU = (PasU - U0) / (myusample - 1); | |
735 | PasV = (PasV - V0) / (myvsample - 1); | |
736 | U0 = U0/2. + myumin; | |
737 | V0 = V0/2. + myvmin; | |
738 | ||
5368adff | 739 | //build grid of parametric points |
740 | myUParams = new TColStd_HArray1OfReal(1,myusample ); | |
741 | myVParams = new TColStd_HArray1OfReal(1,myvsample ); | |
742 | Standard_Integer NoU, NoV; | |
743 | Standard_Real U = U0, V = V0; | |
744 | for ( NoU = 1 ; NoU <= myusample; NoU++, U += PasU) | |
745 | myUParams->SetValue(NoU, U); | |
746 | for ( NoV = 1, V = V0; NoV <= myvsample; NoV++, V += PasV) | |
747 | myVParams->SetValue(NoV, V); | |
748 | ||
0d969553 | 749 | // Calculation of distances |
82469411 A |
750 | mySphereUBTree = new Extrema_UBTreeOfSphere; |
751 | Extrema_UBTreeFillerOfSphere aFiller(*mySphereUBTree); | |
752 | Standard_Integer i = 0; | |
5368adff | 753 | |
82469411 | 754 | mySphereArray = new Bnd_HArray1OfSphere(0, myusample * myvsample); |
5368adff | 755 | |
756 | for ( NoU = 1; NoU <= myusample; NoU++ ) { | |
757 | for ( NoV = 1; NoV <= myvsample; NoV++) { | |
758 | P1 = myS->Value(myUParams->Value(NoU), myVParams->Value(NoV)); | |
82469411 A |
759 | Bnd_Sphere aSph(P1.XYZ(), 0/*mytolu < mytolv ? mytolu : mytolv*/, NoU, NoV); |
760 | aFiller.Add(i, aSph); | |
761 | mySphereArray->SetValue( i, aSph ); | |
762 | i++; | |
763 | } | |
764 | } | |
765 | aFiller.Fill(); | |
92d1589b A |
766 | } |
767 | ||
35e08fe8 | 768 | void Extrema_GenExtPS::FindSolution(const gp_Pnt& /*P*/, |
6060dd1f | 769 | const Extrema_POnSurfParams &theParams) |
92d1589b A |
770 | { |
771 | math_Vector Tol(1,2); | |
772 | Tol(1) = mytolu; | |
773 | Tol(2) = mytolv; | |
7fd59977 | 774 | |
6060dd1f | 775 | math_Vector UV(1, 2); |
6060dd1f | 776 | theParams.Parameter(UV(1), UV(2)); |
777 | ||
92d1589b A |
778 | math_Vector UVinf(1,2), UVsup(1,2); |
779 | UVinf(1) = myumin; | |
780 | UVinf(2) = myvmin; | |
781 | UVsup(1) = myusup; | |
782 | UVsup(2) = myvsup; | |
783 | ||
859a47c3 | 784 | math_FunctionSetRoot S(myF, Tol); |
785 | S.Perform(myF, UV, UVinf, UVsup); | |
92d1589b | 786 | |
92d1589b A |
787 | myDone = Standard_True; |
788 | } | |
789 | ||
790 | void Extrema_GenExtPS::SetFlag(const Extrema_ExtFlag F) | |
791 | { | |
792 | myFlag = F; | |
793 | } | |
794 | ||
795 | void Extrema_GenExtPS::SetAlgo(const Extrema_ExtAlgo A) | |
796 | { | |
5368adff | 797 | if(myAlgo != A) |
798 | myInit = Standard_False; | |
92d1589b | 799 | myAlgo = A; |
5368adff | 800 | |
92d1589b | 801 | } |
7fd59977 | 802 | |
803 | void Extrema_GenExtPS::Perform(const gp_Pnt& P) | |
804 | { | |
805 | myDone = Standard_False; | |
806 | myF.SetPoint(P); | |
5368adff | 807 | |
92d1589b A |
808 | if(myAlgo == Extrema_ExtAlgo_Grad) |
809 | { | |
6060dd1f | 810 | BuildGrid(P); |
92d1589b | 811 | Standard_Integer NoU,NoV; |
7fd59977 | 812 | |
92d1589b A |
813 | if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX) |
814 | { | |
6060dd1f | 815 | Extrema_ElementType anElemType; |
816 | Standard_Integer iU; | |
817 | Standard_Integer iV; | |
818 | Standard_Integer iU2; | |
819 | Standard_Integer iV2; | |
820 | Standard_Boolean isMin; | |
821 | Standard_Integer i; | |
822 | ||
823 | for (NoU = 1; NoU < myusample; NoU++) { | |
824 | for (NoV = 1; NoV < myvsample; NoV++) { | |
825 | const Extrema_POnSurfParams &aParam = | |
826 | myFacePntParams->Value(NoU, NoV); | |
827 | ||
828 | isMin = Standard_False; | |
829 | anElemType = aParam.GetElementType(); | |
830 | ||
831 | if (anElemType == Extrema_Face) { | |
832 | isMin = Standard_True; | |
833 | } else { | |
834 | // Check if it is a boundary edge or corner vertex. | |
835 | aParam.GetIndices(iU, iV); | |
836 | ||
837 | if (anElemType == Extrema_UIsoEdge) { | |
838 | isMin = (iV == 1 || iV == myvsample); | |
839 | } else if (anElemType == Extrema_VIsoEdge) { | |
840 | isMin = (iU == 1 || iU == myusample); | |
841 | } else if (anElemType == Extrema_Node) { | |
842 | isMin = (iU == 1 || iU == myusample) && | |
843 | (iV == 1 || iV == myvsample); | |
844 | } | |
845 | ||
846 | if (!isMin) { | |
847 | // This is a middle element. | |
848 | if (anElemType == Extrema_UIsoEdge || | |
849 | (anElemType == Extrema_Node && (iU == 1 || iU == myusample))) { | |
850 | // Check the down face. | |
851 | const Extrema_POnSurfParams &aDownParam = | |
852 | myFacePntParams->Value(NoU, NoV - 1); | |
853 | ||
854 | if (aDownParam.GetElementType() == anElemType) { | |
855 | aDownParam.GetIndices(iU2, iV2); | |
856 | isMin = (iU == iU2 && iV == iV2); | |
857 | } | |
858 | } else if (anElemType == Extrema_VIsoEdge || | |
859 | (anElemType == Extrema_Node && (iV == 1 || iV == myvsample))) { | |
860 | // Check the right face. | |
861 | const Extrema_POnSurfParams &aRightParam = | |
862 | myFacePntParams->Value(NoU - 1, NoV); | |
863 | ||
864 | if (aRightParam.GetElementType() == anElemType) { | |
865 | aRightParam.GetIndices(iU2, iV2); | |
866 | isMin = (iU == iU2 && iV == iV2); | |
867 | } | |
868 | } else if (iU == NoU && iV == NoV) { | |
869 | // Check the lower-left node. For this purpose it is necessary | |
870 | // to check lower-left, lower and left faces. | |
871 | isMin = Standard_True; | |
872 | ||
873 | const Extrema_POnSurfParams *anOtherParam[3] = | |
874 | { &myFacePntParams->Value(NoU, NoV - 1), // Down | |
875 | &myFacePntParams->Value(NoU - 1, NoV - 1), // Lower-left | |
876 | &myFacePntParams->Value(NoU - 1, NoV) }; // Left | |
877 | ||
878 | for (i = 0; i < 3 && isMin; i++) { | |
879 | if (anOtherParam[i]->GetElementType() == Extrema_Node) { | |
880 | anOtherParam[i]->GetIndices(iU2, iV2); | |
881 | isMin = (iU == iU2 && iV == iV2); | |
882 | } else { | |
883 | isMin = Standard_False; | |
884 | } | |
885 | } | |
886 | } | |
92d1589b | 887 | } |
6060dd1f | 888 | } |
889 | ||
890 | if (isMin) { | |
891 | FindSolution(P, aParam); | |
892 | } | |
92d1589b A |
893 | } |
894 | } | |
895 | } | |
896 | ||
897 | if(myFlag == Extrema_ExtFlag_MAX || myFlag == Extrema_ExtFlag_MINMAX) | |
898 | { | |
6060dd1f | 899 | Standard_Real Dist; |
900 | ||
92d1589b A |
901 | for (NoU = 1; NoU <= myusample; NoU++) { |
902 | for (NoV = 1; NoV <= myvsample; NoV++) { | |
6060dd1f | 903 | Dist = myPoints->Value(NoU, NoV).GetSqrDistance(); |
904 | if ((myPoints->Value(NoU-1,NoV-1).GetSqrDistance() <= Dist) && | |
905 | (myPoints->Value(NoU-1,NoV ).GetSqrDistance() <= Dist) && | |
906 | (myPoints->Value(NoU-1,NoV+1).GetSqrDistance() <= Dist) && | |
907 | (myPoints->Value(NoU ,NoV-1).GetSqrDistance() <= Dist) && | |
908 | (myPoints->Value(NoU ,NoV+1).GetSqrDistance() <= Dist) && | |
909 | (myPoints->Value(NoU+1,NoV-1).GetSqrDistance() <= Dist) && | |
910 | (myPoints->Value(NoU+1,NoV ).GetSqrDistance() <= Dist) && | |
911 | (myPoints->Value(NoU+1,NoV+1).GetSqrDistance() <= Dist)) { | |
912 | // Find maximum. | |
913 | FindSolution(P, myPoints->Value(NoU, NoV)); | |
914 | } | |
915 | } | |
92d1589b A |
916 | } |
917 | } | |
7fd59977 | 918 | } |
92d1589b A |
919 | else |
920 | { | |
921 | BuildTree(); | |
922 | if(myFlag == Extrema_ExtFlag_MIN || myFlag == Extrema_ExtFlag_MINMAX) | |
923 | { | |
924 | Bnd_Sphere aSol = mySphereArray->Value(0); | |
925 | Bnd_SphereUBTreeSelectorMin aSelector(mySphereArray, aSol); | |
926 | //aSelector.SetMaxDist( RealLast() ); | |
927 | aSelector.DefineCheckPoint( P ); | |
302f96fb | 928 | mySphereUBTree->Select( aSelector ); |
92d1589b A |
929 | //TODO: check if no solution in binary tree |
930 | Bnd_Sphere& aSph = aSelector.Sphere(); | |
6060dd1f | 931 | Standard_Real aU = myUParams->Value(aSph.U()); |
932 | Standard_Real aV = myVParams->Value(aSph.V()); | |
933 | Extrema_POnSurfParams aParams(aU, aV, myS->Value(aU, aV)); | |
92d1589b | 934 | |
6060dd1f | 935 | aParams.SetSqrDistance(P.SquareDistance(aParams.Value())); |
936 | aParams.SetIndices(aSph.U(), aSph.V()); | |
937 | FindSolution(P, aParams); | |
92d1589b A |
938 | } |
939 | if(myFlag == Extrema_ExtFlag_MAX || myFlag == Extrema_ExtFlag_MINMAX) | |
940 | { | |
941 | Bnd_Sphere aSol = mySphereArray->Value(0); | |
942 | Bnd_SphereUBTreeSelectorMax aSelector(mySphereArray, aSol); | |
943 | //aSelector.SetMaxDist( RealLast() ); | |
944 | aSelector.DefineCheckPoint( P ); | |
302f96fb | 945 | mySphereUBTree->Select( aSelector ); |
92d1589b A |
946 | //TODO: check if no solution in binary tree |
947 | Bnd_Sphere& aSph = aSelector.Sphere(); | |
6060dd1f | 948 | Standard_Real aU = myUParams->Value(aSph.U()); |
949 | Standard_Real aV = myVParams->Value(aSph.V()); | |
950 | Extrema_POnSurfParams aParams(aU, aV, myS->Value(aU, aV)); | |
6060dd1f | 951 | aParams.SetSqrDistance(P.SquareDistance(aParams.Value())); |
952 | aParams.SetIndices(aSph.U(), aSph.V()); | |
92d1589b | 953 | |
6060dd1f | 954 | FindSolution(P, aParams); |
7fd59977 | 955 | } |
956 | } | |
7fd59977 | 957 | } |
958 | //============================================================================= | |
959 | ||
960 | Standard_Boolean Extrema_GenExtPS::IsDone () const { return myDone; } | |
961 | //============================================================================= | |
962 | ||
963 | Standard_Integer Extrema_GenExtPS::NbExt () const | |
964 | { | |
965 | if (!IsDone()) { StdFail_NotDone::Raise(); } | |
966 | return myF.NbExt(); | |
967 | } | |
968 | //============================================================================= | |
969 | ||
970 | Standard_Real Extrema_GenExtPS::SquareDistance (const Standard_Integer N) const | |
971 | { | |
972 | if (!IsDone()) { StdFail_NotDone::Raise(); } | |
973 | return myF.SquareDistance(N); | |
974 | } | |
975 | //============================================================================= | |
976 | ||
5d99f2c8 | 977 | const Extrema_POnSurf& Extrema_GenExtPS::Point (const Standard_Integer N) const |
7fd59977 | 978 | { |
979 | if (!IsDone()) { StdFail_NotDone::Raise(); } | |
980 | return myF.Point(N); | |
981 | } | |
982 | //============================================================================= |