0029069: Samples - handle UNICODE filenames within C++/CLI CSharp sample
[occt.git] / src / Extrema / Extrema_GenLocateExtPS.cxx
CommitLineData
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
42cf5bc1 17
42cf5bc1 18#include <Extrema_GenLocateExtPS.hxx>
e5260e1d 19
20#include <Adaptor3d_Surface.hxx>
21#include <Extrema_FuncPSNorm.hxx>
22#include <Extrema_FuncPSDist.hxx>
42cf5bc1 23#include <Extrema_POnSurf.hxx>
42cf5bc1 24#include <gp_Pnt.hxx>
7fd59977 25#include <math_FunctionSetRoot.hxx>
e5260e1d 26#include <math_BFGS.hxx>
7fd59977 27#include <math_Vector.hxx>
42cf5bc1 28#include <StdFail_NotDone.hxx>
7fd59977 29
e5260e1d 30//=======================================================================
31//function : Extrema_GenLocateExtPS
32//purpose :
33//=======================================================================
34Extrema_GenLocateExtPS::Extrema_GenLocateExtPS(const Adaptor3d_Surface& theS,
35 const Standard_Real theTolU,
36 const Standard_Real theTolV)
37: mySurf(theS),
38 myTolU(theTolU), myTolV(theTolV),
39 myDone(Standard_False),
40 mySqDist(-1.0)
41{
42}
43
44//=======================================================================
45//function : Perform
46//purpose :
47//=======================================================================
48void Extrema_GenLocateExtPS::Perform(const gp_Pnt& theP,
49 const Standard_Real theU0,
50 const Standard_Real theV0,
51 const Standard_Boolean isDistanceCriteria)
7fd59977 52{
53 myDone = Standard_False;
54
e5260e1d 55 // Prepare initial data structures.
56 math_Vector aTol(1, 2), aStart(1, 2), aBoundInf(1, 2), aBoundSup(1, 2);
57
58 // Tolerance.
59 aTol(1) = myTolU;
60 aTol(2) = myTolV;
61
62 // Initial solution approximation.
63 aStart(1) = theU0;
64 aStart(2) = theV0;
7fd59977 65
e5260e1d 66 // Borders.
67 aBoundInf(1) = mySurf.FirstUParameter();
68 aBoundInf(2) = mySurf.FirstVParameter();
69 aBoundSup(1) = mySurf.LastUParameter();
70 aBoundSup(2) = mySurf.LastVParameter();
7fd59977 71
e5260e1d 72 if (isDistanceCriteria == Standard_False)
73 {
74 // Normal projection criteria.
75 Extrema_FuncPSNorm F(theP,mySurf);
7fd59977 76
e5260e1d 77 math_FunctionSetRoot SR (F, aTol);
78 SR.Perform(F, aStart, aBoundInf, aBoundSup);
79 if (!SR.IsDone())
80 return;
7fd59977 81
e5260e1d 82 mySqDist = F.SquareDistance(1);
83 myPoint = F.Point(1);
84 myDone = Standard_True;
85 }
86 else
87 {
88 // Distance criteria.
89 Extrema_FuncPSDist F(mySurf, theP);
90 math_BFGS aSolver(2);
91 aSolver.Perform(F, aStart);
7fd59977 92
e5260e1d 93 if (!aSolver.IsDone())
94 return;
7fd59977 95
e5260e1d 96 math_Vector aResPnt(1,2);
97 aSolver.Location(aResPnt);
98 mySqDist = aSolver.Minimum();
99 myPoint.SetParameters(aResPnt(1), aResPnt(2), mySurf.Value(aResPnt(1), aResPnt(2)));
100 myDone = Standard_True;
101 }
7fd59977 102}
7fd59977 103
e5260e1d 104//=======================================================================
105//function : IsDone
106//purpose :
107//=======================================================================
108Standard_Boolean Extrema_GenLocateExtPS::IsDone () const
109{
110 return myDone;
111}
7fd59977 112
e5260e1d 113//=======================================================================
114//function : SquareDistance
115//purpose :
116//=======================================================================
7fd59977 117Standard_Real Extrema_GenLocateExtPS::SquareDistance () const
118{
9775fa61 119 if (!IsDone()) { throw StdFail_NotDone(); }
7fd59977 120 return mySqDist;
121}
7fd59977 122
e5260e1d 123//=======================================================================
124//function : Point
125//purpose :
126//=======================================================================
5d99f2c8 127const Extrema_POnSurf& Extrema_GenLocateExtPS::Point () const
7fd59977 128{
9775fa61 129 if (!IsDone()) { throw StdFail_NotDone(); }
7fd59977 130 return myPoint;
131}