1 // Created on: 1995-07-24
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503
19 #include <Adaptor3d_HSurface.hxx>
20 #include <Adaptor3d_Surface.hxx>
21 #include <Bnd_Box.hxx>
23 #include <BndLib_AddSurface.hxx>
24 #include <BSplCLib.hxx>
27 #include <Geom_BezierSurface.hxx>
28 #include <Geom_BSplineSurface.hxx>
29 #include <GeomAbs_SurfaceType.hxx>
32 #include <gp_Cylinder.hxx>
33 #include <gp_Cone.hxx>
35 #include <Precision.hxx>
36 #include <TColgp_Array2OfPnt.hxx>
37 #include <TColStd_Array1OfInteger.hxx>
38 #include <TColStd_Array1OfReal.hxx>
39 #include <BndLib_Add3dCurve.hxx>
40 #include <math_MultipleVarFunction.hxx>
41 #include <math_PSO.hxx>
42 #include <math_Matrix.hxx>
43 #include <math_Powell.hxx>
45 static Standard_Integer NbUSamples(const Adaptor3d_Surface& S,
46 const Standard_Real Umin,
47 const Standard_Real Umax);
49 static Standard_Integer NbVSamples(const Adaptor3d_Surface& S,
50 const Standard_Real Vmin,
51 const Standard_Real Vmax);
53 static Standard_Real AdjustExtr(const Adaptor3d_Surface& S,
54 const Standard_Real UMin,
55 const Standard_Real UMax,
56 const Standard_Real VMin,
57 const Standard_Real VMax,
58 const Standard_Real Extr0,
59 const Standard_Integer CoordIndx,
60 const Standard_Real Tol,
61 const Standard_Boolean IsMin);
63 //=======================================================================
66 //=======================================================================
67 void BndLib_AddSurface::Add(const Adaptor3d_Surface& S,
68 const Standard_Real Tol,
72 BndLib_AddSurface::Add(S,
76 S.LastVParameter (),Tol,B);
78 //=======================================================================
79 //function : NbUSamples
81 //=======================================================================
83 static Standard_Integer NbUSamples(const Adaptor3d_Surface& S)
86 GeomAbs_SurfaceType Type = S.GetType();
88 case GeomAbs_BezierSurface:
93 case GeomAbs_BSplineSurface:
95 const Handle(Geom_BSplineSurface)& BS = S.BSpline();
96 N = 2*(BS->UDegree() + 1)*(BS->NbUKnots() -1);
105 //=======================================================================
106 //function : NbVSamples
108 //=======================================================================
110 static Standard_Integer NbVSamples(const Adaptor3d_Surface& S)
113 GeomAbs_SurfaceType Type = S.GetType();
115 case GeomAbs_BezierSurface:
120 case GeomAbs_BSplineSurface:
122 const Handle(Geom_BSplineSurface)& BS = S.BSpline();
123 N = 2*(BS->VDegree() + 1)*(BS->NbVKnots() - 1) ;
132 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 Begin
133 static gp_Pnt BaryCenter(const gp_Pln &aPlane,
134 const Standard_Real aUMin,
135 const Standard_Real aUMax,
136 const Standard_Real aVMin,
137 const Standard_Real aVMax)
139 Standard_Real aU, aV;
140 Standard_Boolean isU1Inf = Precision::IsInfinite(aUMin);
141 Standard_Boolean isU2Inf = Precision::IsInfinite(aUMax);
142 Standard_Boolean isV1Inf = Precision::IsInfinite(aVMin);
143 Standard_Boolean isV2Inf = Precision::IsInfinite(aVMax);
145 if (isU1Inf && isU2Inf)
152 aU = (aUMin + aUMax)/2.;
154 if (isV1Inf && isV2Inf)
161 aV = (aVMin + aVMax)/2.;
163 gp_Pnt aCenter = ElSLib::Value(aU, aV, aPlane);
168 static void TreatInfinitePlane(const gp_Pln &aPlane,
169 const Standard_Real aUMin,
170 const Standard_Real aUMax,
171 const Standard_Real aVMin,
172 const Standard_Real aVMax,
173 const Standard_Real aTol,
176 // Get 3 coordinate axes of the plane.
177 const gp_Dir &aNorm = aPlane.Axis().Direction();
178 const Standard_Real anAngularTol = RealEpsilon();
180 // Get location of the plane as its barycenter
181 gp_Pnt aLocation = BaryCenter(aPlane, aUMin, aUMax, aVMin, aVMax);
183 if (aNorm.IsParallel(gp::DX(), anAngularTol)) {
189 } else if (aNorm.IsParallel(gp::DY(), anAngularTol)) {
195 } else if (aNorm.IsParallel(gp::DZ(), anAngularTol)) {
209 // Compute start and finish indexes used in convex hull.
210 // theMinIdx - minimum poles index, that can be used.
211 // theMaxIdx - maximum poles index, that can be used.
212 // theShiftCoeff - shift between flatknots array and poles array.
213 // This vaule should be equal to 1 in case of non periodic BSpline,
214 // and (degree + 1) - mults(the lowest index).
215 void ComputePolesIndexes(const TColStd_Array1OfReal &theFlatKnots,
216 const Standard_Integer theDegree,
217 const Standard_Real theMin,
218 const Standard_Real theMax,
219 const Standard_Integer theMinIdx,
220 const Standard_Integer theMaxIdx,
221 const Standard_Integer theShiftCoeff,
222 Standard_Integer &theOutMinIdx,
223 Standard_Integer &theOutMaxIdx)
225 // Set initial values for the result indexes to handle situation when requested parameter space
226 // is slightly greater than B-spline parameter space.
227 theOutMinIdx = theFlatKnots.Lower();
228 theOutMaxIdx = theFlatKnots.Upper();
230 // Compute first and last used flat knots.
231 for(Standard_Integer aKnotIdx = theFlatKnots.Lower();
232 aKnotIdx < theFlatKnots.Upper();
235 if (theFlatKnots(aKnotIdx) <= theMin)
236 theOutMinIdx = aKnotIdx;
238 if (theFlatKnots(theFlatKnots.Upper() - aKnotIdx + theFlatKnots.Lower()) >= theMax)
239 theOutMaxIdx = theFlatKnots.Upper() - aKnotIdx + theFlatKnots.Lower();
242 theOutMinIdx = Max(theOutMinIdx - 2 * theDegree + 2 - theShiftCoeff, theMinIdx);
243 theOutMaxIdx = Min(theOutMaxIdx - 2 + theDegree + 1 - theShiftCoeff, theMaxIdx);
246 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 End
247 //=======================================================================
250 //=======================================================================
251 void BndLib_AddSurface::Add(const Adaptor3d_Surface& S,
252 const Standard_Real UMin,
253 const Standard_Real UMax,
254 const Standard_Real VMin,
255 const Standard_Real VMax,
256 const Standard_Real Tol,
259 GeomAbs_SurfaceType Type = S.GetType(); // skv OCC6503
261 if (Precision::IsInfinite(VMin) ||
262 Precision::IsInfinite(VMax) ||
263 Precision::IsInfinite(UMin) ||
264 Precision::IsInfinite(UMax) ) {
265 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 Begin
271 TreatInfinitePlane(S.Plane(), UMin, UMax, VMin, VMax, Tol, B);
280 // Modified by skv - Fri Aug 27 12:29:04 2004 OCC6503 End
283 // GeomAbs_SurfaceType Type = S.GetType(); // skv OCC6503
289 gp_Pln Plan = S.Plane();
290 B.Add(ElSLib::Value(UMin,VMin,Plan));
291 B.Add(ElSLib::Value(UMin,VMax,Plan));
292 B.Add(ElSLib::Value(UMax,VMin,Plan));
293 B.Add(ElSLib::Value(UMax,VMax,Plan));
297 case GeomAbs_Cylinder:
299 BndLib::Add(S.Cylinder(),UMin,UMax,VMin,VMax,Tol,B);
304 BndLib::Add(S.Cone(),UMin,UMax,VMin,VMax,Tol,B);
309 BndLib::Add(S.Torus(),UMin,UMax,VMin,VMax,Tol,B);
314 if (Abs(UMin) < Precision::Angular() &&
315 Abs(UMax - 2.*M_PI) < Precision::Angular() &&
316 Abs(VMin + M_PI/2.) < Precision::Angular() &&
317 Abs(VMax - M_PI/2.) < Precision::Angular()) // a whole sphere
318 BndLib::Add(S.Sphere(),Tol,B);
320 BndLib::Add(S.Sphere(),UMin,UMax,VMin,VMax,Tol,B);
323 case GeomAbs_OffsetSurface:
325 Handle(Adaptor3d_HSurface) HS = S.BasisSurface();
326 Add (HS->Surface(),UMin,UMax,VMin,VMax,Tol,B);
327 B.Enlarge(S.OffsetValue());
331 case GeomAbs_BezierSurface:
332 case GeomAbs_BSplineSurface:
334 Standard_Boolean isUseConvexHullAlgorithm = Standard_True;
335 Standard_Real PTol = Precision::Parametric(Precision::Confusion());
336 // Borders of underlying geometry.
337 Standard_Real anUMinParam = UMin, anUMaxParam = UMax,// BSpline case.
338 aVMinParam = VMin, aVMaxParam = VMax;
339 if (Type == GeomAbs_BezierSurface)
342 // All of poles used for any parameter,
343 // thats why in case of trimmed parameters handled by grid algorithm.
345 if (Abs(UMin-S.FirstUParameter()) > PTol ||
346 Abs(VMin-S.FirstVParameter()) > PTol ||
347 Abs(UMax-S.LastUParameter ()) > PTol ||
348 Abs(VMax-S.LastVParameter ()) > PTol )
350 // Borders not equal to topology borders.
351 isUseConvexHullAlgorithm = Standard_False;
357 // If Umin, Vmin, Umax, Vmax lies inside geometry bounds then:
358 // use convex hull algorithm,
359 // if Umin, VMin, Umax, Vmax lies outside then:
360 // use grid algorithm on analytic continuation (default case).
361 S.BSpline()->Bounds(anUMinParam, anUMaxParam, aVMinParam, aVMaxParam);
363 if ( (UMin - anUMinParam) < -PTol ||
364 (VMin - aVMinParam) < -PTol ||
365 (UMax - anUMaxParam) > PTol ||
366 (VMax - aVMaxParam) > PTol )
368 // Out of geometry borders.
369 isUseConvexHullAlgorithm = Standard_False;
373 if (isUseConvexHullAlgorithm)
375 TColgp_Array2OfPnt Tp(1,S.NbUPoles(),1,S.NbVPoles());
376 Standard_Integer UMinIdx = 0, UMaxIdx = 0;
377 Standard_Integer VMinIdx = 0, VMaxIdx = 0;
378 if (Type == GeomAbs_BezierSurface)
380 S.Bezier()->Poles(Tp);
382 UMinIdx = Tp.LowerRow();
383 UMaxIdx = Tp.UpperRow();
384 VMinIdx = Tp.LowerCol();
385 VMaxIdx = Tp.UpperCol();
389 S.BSpline()->Poles(Tp);
391 UMinIdx = Tp.LowerRow();
392 UMaxIdx = Tp.UpperRow();
393 VMinIdx = Tp.LowerCol();
394 VMaxIdx = Tp.UpperCol();
396 if (UMin > anUMinParam ||
399 Standard_Integer anUFlatKnotsCount = S.BSpline()->NbUPoles() + S.BSpline()->UDegree() + 1;
400 Standard_Integer aShift = 1;
402 if (S.BSpline()->IsUPeriodic())
404 TColStd_Array1OfInteger aMults(1, S.BSpline()->NbUKnots());
405 S.BSpline()->UMultiplicities(aMults);
406 anUFlatKnotsCount = BSplCLib::KnotSequenceLength(aMults, S.BSpline()->UDegree(), Standard_True);
408 aShift = S.BSpline()->UDegree() + 1 - S.BSpline()->UMultiplicity(1);
411 TColStd_Array1OfReal anUFlatKnots(1, anUFlatKnotsCount);
412 S.BSpline()->UKnotSequence(anUFlatKnots);
414 ComputePolesIndexes(anUFlatKnots,
415 S.BSpline()->UDegree(),
417 UMinIdx, UMaxIdx, // Min and Max Indexes
419 UMinIdx, UMaxIdx); // the Output indexes
422 if (VMin > aVMinParam ||
425 Standard_Integer anVFlatKnotsCount = S.BSpline()->NbVPoles() + S.BSpline()->VDegree() + 1;
426 Standard_Integer aShift = 1;
428 if (S.BSpline()->IsVPeriodic())
430 TColStd_Array1OfInteger aMults(1, S.BSpline()->NbVKnots());
431 S.BSpline()->VMultiplicities(aMults);
432 anVFlatKnotsCount = BSplCLib::KnotSequenceLength(aMults, S.BSpline()->VDegree(), Standard_True);
434 aShift = S.BSpline()->VDegree() + 1 - S.BSpline()->VMultiplicity(1);
437 TColStd_Array1OfReal anVFlatKnots(1, anVFlatKnotsCount);
438 S.BSpline()->VKnotSequence(anVFlatKnots);
440 ComputePolesIndexes(anVFlatKnots,
441 S.BSpline()->VDegree(),
443 VMinIdx, VMaxIdx, // Min and Max Indexes
445 VMinIdx, VMaxIdx); // the Output indexes
450 // Use poles to build convex hull.
451 for (Standard_Integer i = UMinIdx; i <= UMaxIdx; i++)
453 for (Standard_Integer j = VMinIdx; j <= VMaxIdx; j++)
466 Standard_Integer Nu = NbUSamples(S);
467 Standard_Integer Nv = NbVSamples(S);
469 for (Standard_Integer i =1 ;i<=Nu;i++){
470 Standard_Real U = UMin + ((UMax-UMin)*(i-1)/(Nu-1));
471 for (Standard_Integer j=1 ;j<=Nv;j++){
472 Standard_Real V = VMin + ((VMax-VMin)*(j-1)/(Nv-1));
481 //----- Methods for AddOptimal ---------------------------------------
483 //=======================================================================
484 //function : AddOptimal
486 //=======================================================================
487 void BndLib_AddSurface::AddOptimal(const Adaptor3d_Surface& S,
488 const Standard_Real Tol,
492 BndLib_AddSurface::AddOptimal(S,
496 S.LastVParameter (),Tol,B);
498 //=======================================================================
499 //function : AddOptimal
501 //=======================================================================
503 void BndLib_AddSurface::AddOptimal(const Adaptor3d_Surface& S,
504 const Standard_Real UMin,
505 const Standard_Real UMax,
506 const Standard_Real VMin,
507 const Standard_Real VMax,
508 const Standard_Real Tol,
511 GeomAbs_SurfaceType Type = S.GetType();
513 if (Precision::IsInfinite(VMin) ||
514 Precision::IsInfinite(VMax) ||
515 Precision::IsInfinite(UMin) ||
516 Precision::IsInfinite(UMax) ) {
520 TreatInfinitePlane(S.Plane(), UMin, UMax, VMin, VMax, Tol, B);
535 gp_Pln Plan = S.Plane();
536 B.Add(ElSLib::Value(UMin,VMin,Plan));
537 B.Add(ElSLib::Value(UMin,VMax,Plan));
538 B.Add(ElSLib::Value(UMax,VMin,Plan));
539 B.Add(ElSLib::Value(UMax,VMax,Plan));
543 case GeomAbs_Cylinder:
545 BndLib::Add(S.Cylinder(), UMin, UMax, VMin, VMax, Tol, B);
550 BndLib::Add(S.Cone(), UMin, UMax, VMin, VMax, Tol, B);
555 BndLib::Add(S.Sphere(), UMin, UMax, VMin, VMax, Tol, B);
560 AddGenSurf(S, UMin, UMax, VMin, VMax, Tol, B);
564 //=======================================================================
565 //function : AddGenSurf
567 //=======================================================================
568 void BndLib_AddSurface::AddGenSurf(const Adaptor3d_Surface& S,
569 const Standard_Real UMin,
570 const Standard_Real UMax,
571 const Standard_Real VMin,
572 const Standard_Real VMax,
573 const Standard_Real Tol,
576 Standard_Integer Nu = NbUSamples(S, UMin, UMax);
577 Standard_Integer Nv = NbVSamples(S, VMin, VMax);
579 Standard_Real CoordMin[3] = {RealLast(), RealLast(), RealLast()};
580 Standard_Real CoordMax[3] = {-RealLast(), -RealLast(), -RealLast()};
581 Standard_Real DeflMax[3] = {-RealLast(), -RealLast(), -RealLast()};
584 Standard_Real du = (UMax-UMin)/(Nu-1), du2 = du / 2.;
585 Standard_Real dv = (VMax-VMin)/(Nv-1), dv2 = dv / 2.;
586 NCollection_Array2<gp_XYZ> aPnts(1, Nu, 1, Nv);
588 Standard_Integer i, j, k;
590 for (i = 1, u = UMin; i <= Nu; i++, u += du){
591 for (j = 1, v = VMin;j <= Nv; j++, v += dv){
593 aPnts(i, j) = P.XYZ();
595 for(k = 0; k < 3; ++k)
597 if(CoordMin[k] > P.Coord(k+1))
599 CoordMin[k] = P.Coord(k+1);
601 if(CoordMax[k] < P.Coord(k+1))
603 CoordMax[k] = P.Coord(k+1);
609 gp_XYZ aPm = 0.5 * (aPnts(i-1,j) + aPnts(i, j));
611 gp_XYZ aD = (P.XYZ() - aPm);
612 for(k = 0; k < 3; ++k)
614 if(CoordMin[k] > P.Coord(k+1))
616 CoordMin[k] = P.Coord(k+1);
618 if(CoordMax[k] < P.Coord(k+1))
620 CoordMax[k] = P.Coord(k+1);
622 Standard_Real d = Abs(aD.Coord(k+1));
631 gp_XYZ aPm = 0.5 * (aPnts(i,j-1) + aPnts(i, j));
632 S.D0(u , v - dv2, P);
633 gp_XYZ aD = (P.XYZ() - aPm);
634 for(k = 0; k < 3; ++k)
636 if(CoordMin[k] > P.Coord(k+1))
638 CoordMin[k] = P.Coord(k+1);
640 if(CoordMax[k] < P.Coord(k+1))
642 CoordMax[k] = P.Coord(k+1);
644 Standard_Real d = Abs(aD.Coord(k+1));
655 Standard_Real eps = Max(Tol, Precision::Confusion());
656 for(k = 0; k < 3; ++k)
658 Standard_Real d = DeflMax[k];
664 Standard_Real CMin = CoordMin[k];
665 Standard_Real CMax = CoordMax[k];
666 for(i = 1; i <= Nu; ++i)
668 for(j = 1; j <= Nv; ++j)
670 if(aPnts(i,j).Coord(k+1) - CMin < d)
672 Standard_Real umin, umax, vmin, vmax;
673 umin = UMin + Max(0, i-2) * du;
674 umax = UMin + Min(Nu-1, i) * du;
675 vmin = VMin + Max(0, j-2) * dv;
676 vmax = VMin + Min(Nv-1, j) * dv;
677 Standard_Real cmin = AdjustExtr(S, umin, umax, vmin, vmax,
678 CMin, k + 1, eps, Standard_True);
684 else if(CMax - aPnts(i,j).Coord(k+1) < d)
686 Standard_Real umin, umax, vmin, vmax;
687 umin = UMin + Max(0, i-2) * du;
688 umax = UMin + Min(Nu-1, i) * du;
689 vmin = VMin + Max(0, j-2) * dv;
690 vmax = VMin + Min(Nv-1, j) * dv;
691 Standard_Real cmax = AdjustExtr(S, umin, umax, vmin, vmax,
692 CMax, k + 1, eps, Standard_False);
705 B.Add(gp_Pnt(CoordMin[0], CoordMin[1], CoordMin[2]));
706 B.Add(gp_Pnt(CoordMax[0], CoordMax[1], CoordMax[2]));
712 class SurfMaxMinCoord : public math_MultipleVarFunction
715 SurfMaxMinCoord(const Adaptor3d_Surface& theSurf,
716 const Standard_Real UMin,
717 const Standard_Real UMax,
718 const Standard_Real VMin,
719 const Standard_Real VMax,
720 const Standard_Integer CoordIndx,
721 const Standard_Real Sign)
727 myCoordIndx(CoordIndx),
732 X(2) = (VMin + VMax) / 2.;
733 Standard_Real F1, F2;
737 Standard_Real DU = Abs((F2 - F1) / (UMax - UMin));
738 X(1) = (UMin + UMax) / 2.;
743 Standard_Real DV = Abs((F2 - F1) / (VMax - VMin));
744 myPenalty = 10. * Max(DU, DV);
745 myPenalty = Max(myPenalty, 1.);
748 Standard_Boolean Value (const math_Vector& X,
751 if (CheckInputData(X))
753 gp_Pnt aP = mySurf.Value(X(1), X(2));
754 F = mySign * aP.Coord(myCoordIndx);
758 Standard_Real UPen = 0., VPen = 0., u0, v0;
761 UPen = myPenalty * (myUMin - X(1));
764 else if(X(1) > myUMax)
766 UPen = myPenalty * (X(1) - myUMax);
776 VPen = myPenalty * (myVMin - X(2));
779 else if(X(2) > myVMax)
781 VPen = myPenalty * (X(2) - myVMax);
789 gp_Pnt aP = mySurf.Value(u0, v0);
790 F = mySign * aP.Coord(myCoordIndx) + UPen + VPen;
793 return Standard_True;
798 Standard_Integer NbVariables() const
804 SurfMaxMinCoord & operator = (const SurfMaxMinCoord & theOther);
806 Standard_Boolean CheckInputData(const math_Vector theParams)
808 if (theParams(1) < myUMin ||
809 theParams(1) > myUMax ||
810 theParams(2) < myVMin ||
811 theParams(2) > myVMax)
812 return Standard_False;
813 return Standard_True;
816 const Adaptor3d_Surface& mySurf;
817 Standard_Real myUMin;
818 Standard_Real myUMax;
819 Standard_Real myVMin;
820 Standard_Real myVMax;
821 Standard_Integer myCoordIndx;
822 Standard_Real mySign;
823 Standard_Real myPenalty;
826 //=======================================================================
827 //function : AdjustExtr
829 //=======================================================================
831 Standard_Real AdjustExtr(const Adaptor3d_Surface& S,
832 const Standard_Real UMin,
833 const Standard_Real UMax,
834 const Standard_Real VMin,
835 const Standard_Real VMax,
836 const Standard_Real Extr0,
837 const Standard_Integer CoordIndx,
838 const Standard_Real Tol,
839 const Standard_Boolean IsMin)
841 Standard_Real aSign = IsMin ? 1.:-1.;
842 Standard_Real extr = aSign * Extr0;
843 Standard_Real relTol = 2.*Tol;
848 Standard_Real Du = (S.LastUParameter() - S.FirstUParameter());
849 Standard_Real Dv = (S.LastVParameter() - S.FirstVParameter());
852 math_Vector aLowBorder(1,2);
853 math_Vector aUppBorder(1,2);
854 math_Vector aSteps(1,2);
855 aLowBorder(1) = UMin;
856 aUppBorder(1) = UMax;
857 aLowBorder(2) = VMin;
858 aUppBorder(2) = VMax;
860 Standard_Integer aNbU = Max(8, RealToInt(32 * (UMax - UMin) / Du));
861 Standard_Integer aNbV = Max(8, RealToInt(32 * (VMax - VMin) / Dv));
862 Standard_Integer aNbParticles = aNbU * aNbV;
863 Standard_Real aMaxUStep = (UMax - UMin) / (aNbU + 1);
864 aSteps(1) = Min(0.1 * Du, aMaxUStep);
865 Standard_Real aMaxVStep = (VMax - VMin) / (aNbV + 1);
866 aSteps(2) = Min(0.1 * Dv, aMaxVStep);
868 SurfMaxMinCoord aFunc(S, UMin, UMax, VMin, VMax, CoordIndx, aSign);
869 math_PSO aFinder(&aFunc, aLowBorder, aUppBorder, aSteps, aNbParticles);
870 aFinder.Perform(aSteps, extr, aT);
872 //Refinement of extremal value
873 math_Matrix aDir(1, 2, 1, 2, 0.0);
879 Standard_Integer aNbIter = 200;
880 math_Powell powell(aFunc, relTol, aNbIter, Tol);
881 powell.Perform(aFunc, aT, aDir);
886 extr = powell.Minimum();
892 //=======================================================================
893 //function : NbUSamples
895 //=======================================================================
897 Standard_Integer NbUSamples(const Adaptor3d_Surface& S,
898 const Standard_Real Umin,
899 const Standard_Real Umax)
902 GeomAbs_SurfaceType Type = S.GetType();
904 case GeomAbs_BezierSurface:
907 //By default parametric range of Bezier surf is [0, 1] [0, 1]
908 Standard_Real du = Umax - Umin;
911 N = RealToInt(du*N) + 1;
916 case GeomAbs_BSplineSurface:
918 const Handle(Geom_BSplineSurface)& BS = S.BSpline();
919 N = 2*(BS->UDegree() + 1)*(BS->NbUKnots() -1);
920 Standard_Real umin, umax, vmin, vmax;
921 BS->Bounds(umin, umax, vmin, vmax);
922 Standard_Real du = (Umax - Umin) / (umax - umin);
925 N = RealToInt(du*N) + 1;
936 //=======================================================================
937 //function : NbVSamples
939 //=======================================================================
941 Standard_Integer NbVSamples(const Adaptor3d_Surface& S,
942 const Standard_Real Vmin,
943 const Standard_Real Vmax)
946 GeomAbs_SurfaceType Type = S.GetType();
948 case GeomAbs_BezierSurface:
951 //By default parametric range of Bezier surf is [0, 1] [0, 1]
952 Standard_Real dv = Vmax - Vmin;
955 N = RealToInt(dv*N) + 1;
960 case GeomAbs_BSplineSurface:
962 const Handle(Geom_BSplineSurface)& BS = S.BSpline();
963 N = 2*(BS->VDegree() + 1)*(BS->NbVKnots() - 1) ;
964 Standard_Real umin, umax, vmin, vmax;
965 BS->Bounds(umin, umax, vmin, vmax);
966 Standard_Real dv = (Vmax - Vmin) / (vmax - vmin);
969 N = RealToInt(dv*N) + 1;