0030686: Visualization, SelectMgr_ViewerSelector - sorting issues of transformation...
[occt.git] / src / Extrema / Extrema_FuncPSNorm.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
7fd59977 17
e5260e1d 18#include <Extrema_FuncPSNorm.hxx>
42cf5bc1 19#include <Adaptor3d_Surface.hxx>
42cf5bc1 20#include <Extrema_POnSurf.hxx>
21#include <GeomAbs_IsoType.hxx>
7fd59977 22#include <gp_Pnt.hxx>
42cf5bc1 23#include <gp_Vec.hxx>
24#include <math_Matrix.hxx>
7fd59977 25#include <Precision.hxx>
42cf5bc1 26#include <Standard_TypeMismatch.hxx>
7fd59977 27
e5260e1d 28Extrema_FuncPSNorm::Extrema_FuncPSNorm ()
7fd59977 29{
30 myPinit = Standard_False;
31 mySinit = Standard_False;
7fd59977 32}
6062bf3e 33
7fd59977 34//=============================================================================
e5260e1d 35Extrema_FuncPSNorm::Extrema_FuncPSNorm (const gp_Pnt& P,
7fd59977 36 const Adaptor3d_Surface& S)
37{
38 myP = P;
39 myS = (Adaptor3d_SurfacePtr)&S;
7fd59977 40 myPinit = Standard_True;
41 mySinit = Standard_True;
42}
43
44//=============================================================================
e5260e1d 45void Extrema_FuncPSNorm::Initialize(const Adaptor3d_Surface& S)
7fd59977 46{
47 myS = (Adaptor3d_SurfacePtr)&S;
7fd59977 48 mySinit = Standard_True;
49 myPoint.Clear();
50 mySqDist.Clear();
51}
52
53//=============================================================================
54
e5260e1d 55void Extrema_FuncPSNorm::SetPoint(const gp_Pnt& P)
7fd59977 56{
57 myP = P;
58 myPinit = Standard_True;
59 myPoint.Clear();
60 mySqDist.Clear();
61}
62
63//=============================================================================
64
65//=============================================================================
66
e5260e1d 67Standard_Integer Extrema_FuncPSNorm::NbVariables () const { return 2;}
7fd59977 68//=============================================================================
69
e5260e1d 70Standard_Integer Extrema_FuncPSNorm::NbEquations () const { return 2;}
7fd59977 71//=============================================================================
72
e5260e1d 73Standard_Boolean Extrema_FuncPSNorm::Value (const math_Vector& UV,
7fd59977 74 math_Vector& F)
75{
9775fa61 76 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
7fd59977 77 myU = UV(1);
78 myV = UV(2);
79 gp_Vec Dus, Dvs;
80 myS->D1(myU,myV,myPs,Dus,Dvs);
81
82 gp_Vec PPs (myP,myPs);
6062bf3e 83
7fd59977 84 F(1) = PPs.Dot(Dus);
85 F(2) = PPs.Dot(Dvs);
86
87 return Standard_True;
88}
89//=============================================================================
90
e5260e1d 91Standard_Boolean Extrema_FuncPSNorm::Derivatives (const math_Vector& UV,
7fd59977 92 math_Matrix& Df)
93{
94 math_Vector F(1,2);
95 return Values(UV,F,Df);
96}
97//=============================================================================
98
e5260e1d 99Standard_Boolean Extrema_FuncPSNorm::Values (const math_Vector& UV,
7fd59977 100 math_Vector& F,
101 math_Matrix& Df)
102{
9775fa61 103 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
7fd59977 104 myU = UV(1);
105 myV = UV(2);
106 gp_Vec Dus, Dvs, Duus, Dvvs, Duvs;
107 myS->D2(myU,myV,myPs,Dus,Dvs,Duus,Dvvs,Duvs);
108
109 gp_Vec PPs (myP,myPs);
7fd59977 110
6062bf3e
G
111 Df(1,1) = Dus.SquareMagnitude() + PPs.Dot(Duus);
112 Df(1,2) = Dvs.Dot(Dus) + PPs.Dot(Duvs);
113 Df(2,1) = Df(1,2);
114 Df(2,2) = Dvs.SquareMagnitude() + PPs.Dot(Dvvs);
7fd59977 115
6062bf3e 116 // 3. Value
7fd59977 117 F(1) = PPs.Dot(Dus);
118 F(2) = PPs.Dot(Dvs);
119
120 return Standard_True;
121}
122//=============================================================================
123
e5260e1d 124Standard_Integer Extrema_FuncPSNorm::GetStateNumber ()
7fd59977 125{
9775fa61 126 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
5368adff 127 //comparison of solution with previous solutions
128 Standard_Integer i = 1, nbSol = mySqDist.Length();
129 Standard_Real tol2d = Precision::PConfusion() * Precision::PConfusion();
130
131 for( ; i <= nbSol; i++)
132 {
133 Standard_Real aU, aV;
134 myPoint(i).Parameter(aU, aV);
135 if( ((myU - aU ) * (myU - aU ) + (myV - aV ) * (myV - aV )) <= tol2d )
136 break;
137 }
138 if( i <= nbSol)
139 return 0;
7fd59977 140 mySqDist.Append(myPs.SquareDistance(myP));
141 myPoint.Append(Extrema_POnSurf(myU,myV,myPs));
142 return 0;
143}
144//=============================================================================
145
e5260e1d 146Standard_Integer Extrema_FuncPSNorm::NbExt () const
7fd59977 147{
148 return mySqDist.Length();
149}
150//=============================================================================
151
e5260e1d 152Standard_Real Extrema_FuncPSNorm::SquareDistance (const Standard_Integer N) const
7fd59977 153{
9775fa61 154 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
7fd59977 155 return mySqDist.Value(N);
156}
157//=============================================================================
158
e5260e1d 159const Extrema_POnSurf& Extrema_FuncPSNorm::Point (const Standard_Integer N) const
7fd59977 160{
9775fa61 161 if (!myPinit || !mySinit) throw Standard_TypeMismatch();
7fd59977 162 return myPoint.Value(N);
163}