0027961: Visualization - remove unused and no more working OpenGl_AVIWriter
[occt.git] / src / Extrema / Extrema_FuncPSNorm.cxx
1 // Created on: 1995-07-18
2 // Created by: Modelistation
3 // Copyright (c) 1995-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Extrema_FuncPSNorm.hxx>
19 #include <Adaptor3d_Surface.hxx>
20 #include <Extrema_POnSurf.hxx>
21 #include <GeomAbs_IsoType.hxx>
22 #include <gp_Pnt.hxx>
23 #include <gp_Vec.hxx>
24 #include <math_Matrix.hxx>
25 #include <Precision.hxx>
26 #include <Standard_TypeMismatch.hxx>
27
28 Extrema_FuncPSNorm::Extrema_FuncPSNorm ()
29 {
30   myPinit = Standard_False;
31   mySinit = Standard_False;
32 }
33
34 //=============================================================================
35 Extrema_FuncPSNorm::Extrema_FuncPSNorm (const gp_Pnt& P,
36                                       const Adaptor3d_Surface& S)
37 {
38   myP = P;
39   myS = (Adaptor3d_SurfacePtr)&S;
40   myPinit = Standard_True;
41   mySinit = Standard_True;
42 }
43
44 //=============================================================================
45 void Extrema_FuncPSNorm::Initialize(const Adaptor3d_Surface& S)
46 {
47   myS = (Adaptor3d_SurfacePtr)&S;
48   mySinit = Standard_True;
49   myPoint.Clear();
50   mySqDist.Clear();
51 }
52
53 //=============================================================================
54
55 void Extrema_FuncPSNorm::SetPoint(const gp_Pnt& P)
56 {
57   myP = P;
58   myPinit = Standard_True;
59   myPoint.Clear();
60   mySqDist.Clear();
61 }
62
63 //=============================================================================
64
65 //=============================================================================
66
67 Standard_Integer Extrema_FuncPSNorm::NbVariables () const { return 2;}
68 //=============================================================================
69
70 Standard_Integer Extrema_FuncPSNorm::NbEquations () const { return 2;}
71 //=============================================================================
72
73 Standard_Boolean Extrema_FuncPSNorm::Value (const math_Vector& UV, 
74                                            math_Vector& F)
75 {
76   if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
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);
83
84   F(1) = PPs.Dot(Dus);
85   F(2) = PPs.Dot(Dvs);
86
87   return Standard_True;
88 }
89 //=============================================================================
90
91 Standard_Boolean Extrema_FuncPSNorm::Derivatives (const math_Vector& UV, 
92                                                  math_Matrix& Df)
93 {
94   math_Vector F(1,2);
95   return Values(UV,F,Df);
96 }
97 //=============================================================================
98
99 Standard_Boolean Extrema_FuncPSNorm::Values (const math_Vector& UV, 
100                                             math_Vector& F,
101                                             math_Matrix& Df)
102 {
103   if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
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);
110
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);
115
116   // 3. Value
117   F(1) = PPs.Dot(Dus);
118   F(2) = PPs.Dot(Dvs);
119
120   return Standard_True;
121 }
122 //=============================================================================
123
124 Standard_Integer Extrema_FuncPSNorm::GetStateNumber ()
125 {
126   if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
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;
140   mySqDist.Append(myPs.SquareDistance(myP));
141   myPoint.Append(Extrema_POnSurf(myU,myV,myPs));
142   return 0;
143 }
144 //=============================================================================
145
146 Standard_Integer Extrema_FuncPSNorm::NbExt () const
147 {
148   return mySqDist.Length();
149 }
150 //=============================================================================
151
152 Standard_Real Extrema_FuncPSNorm::SquareDistance (const Standard_Integer N) const
153 {
154   if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
155   return mySqDist.Value(N);
156 }
157 //=============================================================================
158
159 const Extrema_POnSurf& Extrema_FuncPSNorm::Point (const Standard_Integer N) const
160 {
161   if (!myPinit || !mySinit) Standard_TypeMismatch::Raise();
162   return myPoint.Value(N);
163 }