0031682: Visualization - Prs3d_ShadingAspect::SetTransparency() has no effect with...
[occt.git] / src / BlendFunc / BlendFunc_Corde.cxx
1 // Created on: 1996-06-04
2 // Created by: Stagiaire Xuan Trang PHAMPHU
3 // Copyright (c) 1996-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 <Adaptor3d_HCurve.hxx>
19 #include <Adaptor3d_HSurface.hxx>
20 #include <BlendFunc.hxx>
21 #include <BlendFunc_Corde.hxx>
22 #include <ElCLib.hxx>
23 #include <gp.hxx>
24 #include <gp_Pnt.hxx>
25 #include <gp_Vec.hxx>
26 #include <gp_Vec2d.hxx>
27 #include <math_Gauss.hxx>
28 #include <math_Matrix.hxx>
29 #include <Standard_DomainError.hxx>
30 #include <Standard_NotImplemented.hxx>
31
32 //=======================================================================
33 //function : BlendFunc_Corde
34 //purpose  : 
35 //=======================================================================
36 BlendFunc_Corde::BlendFunc_Corde(const Handle(Adaptor3d_HSurface)&   S,
37                                  const Handle(Adaptor3d_HCurve)&     CG)
38 : surf(S),
39   guide(CG),
40   dis(0.0),
41   normtg(0.0),
42   theD(0.0),
43   istangent(Standard_False)
44 {
45 }
46
47 //=======================================================================
48 //function : SetDist
49 //purpose  : 
50 //=======================================================================
51
52 void BlendFunc_Corde::SetDist(const Standard_Real Dist)
53 {
54   dis = Dist;
55 }
56
57 //=======================================================================
58 //function : SetParam
59 //purpose  : 
60 //=======================================================================
61
62 void BlendFunc_Corde::SetParam(const Standard_Real Param)
63 {
64   guide->D2(Param,ptgui,d1gui,d2gui);
65   normtg = d1gui.Magnitude();
66   nplan  = d1gui.Normalized();
67   theD = - (nplan.XYZ().Dot(ptgui.XYZ()));
68 }
69
70 //=======================================================================
71 //function : Value
72 //purpose  : returns F(U,V)
73 //=======================================================================
74
75 Standard_Boolean BlendFunc_Corde::Value(const math_Vector& X, math_Vector& F)
76 {
77   gp_Vec d1u,d1v;
78   surf->D1(X(1),X(2),pts,d1u,d1v);
79
80   F(1) = nplan.XYZ().Dot(pts.XYZ()) + theD;
81   const gp_Vec vref(ptgui,pts);
82   F(2) = vref.SquareMagnitude() - dis*dis; 
83
84   return Standard_True;
85 }
86
87 //=======================================================================
88 //function : Derivatives
89 //purpose  : D = grad F(U,V)
90 //=======================================================================
91
92 Standard_Boolean BlendFunc_Corde::Derivatives(const math_Vector& X, math_Matrix& D)
93 {
94   gp_Vec d1u,d1v;
95   surf->D1(X(1),X(2),pts,d1u,d1v);  
96
97   D(1,1) = nplan.Dot(d1u);
98   D(1,2) = nplan.Dot(d1v); 
99   D(2,1) = 2.*gp_Vec(ptgui,pts).Dot(d1u);
100   D(2,2) = 2.*gp_Vec(ptgui,pts).Dot(d1v);
101
102   return Standard_True;
103 }
104
105 //=======================================================================
106 //function : PointOnS
107 //purpose  : 
108 //=======================================================================
109
110 const gp_Pnt& BlendFunc_Corde::PointOnS () const
111 {
112   return pts;
113 }
114
115
116 //=======================================================================
117 //function : PointOnGuide
118 //purpose  : 
119 //=======================================================================
120
121 const gp_Pnt& BlendFunc_Corde::PointOnGuide () const
122 {
123   return ptgui;
124 }
125
126
127 //=======================================================================
128 //function : Nplan
129 //purpose  : 
130 //=======================================================================
131
132 const gp_Vec& BlendFunc_Corde::NPlan () const
133 {
134   return nplan;
135 }
136
137
138 //=======================================================================
139 //function : IsTangencyPoint
140 //purpose  : 
141 //=======================================================================
142
143 Standard_Boolean BlendFunc_Corde::IsTangencyPoint () const
144 {
145   return istangent;
146 }
147
148
149 //=======================================================================
150 //function : TangentOnS
151 //purpose  : 
152 //=======================================================================
153
154 const gp_Vec& BlendFunc_Corde::TangentOnS () const
155 {
156   if (istangent)
157     throw Standard_DomainError("BlendFunc_Corde::TangentOnS");
158   return tgs;
159 }
160
161
162 //=======================================================================
163 //function : Tangent2dOnS
164 //purpose  : 
165 //=======================================================================
166
167 const gp_Vec2d& BlendFunc_Corde::Tangent2dOnS () const
168 {
169   if (istangent) 
170     throw Standard_DomainError("BlendFunc_Corde::Tangent2dOnS");
171   return tg2d;
172 }
173
174
175 //=======================================================================
176 //function : DerFguide
177 //purpose  : dF/dw
178 //=======================================================================
179
180 void BlendFunc_Corde::DerFguide (const math_Vector& Sol, gp_Vec2d& DerF)
181 {
182   gp_Vec d1u,d1v;
183   surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
184
185   gp_Vec dnplan;
186   dnplan.SetLinearForm(1./normtg,d2gui,-1./normtg*(nplan.Dot(d2gui)),nplan);
187
188   const gp_Vec temp(pts.XYZ()-ptgui.XYZ());
189
190   DerF.SetX( dnplan.Dot(temp)-nplan.Dot(d1gui) );
191   DerF.SetY( -2.*d1gui.Dot(temp) );
192 }
193
194 //=======================================================================
195 //function : IsSolution
196 //purpose  :
197 //=======================================================================
198
199 Standard_Boolean BlendFunc_Corde::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
200 {
201   math_Vector secmember(1,2),valsol(1,2);
202   math_Matrix gradsol(1,2,1,2);
203
204   gp_Vec dnplan,temp,d1u,d1v;
205
206   Value(Sol,valsol);
207   Derivatives(Sol,gradsol);
208   if (Abs(valsol(1)) <= Tol &&
209       Abs(valsol(2)) <= Tol*Tol) {
210
211     surf->D1(Sol(1),Sol(2),pts,d1u,d1v);
212     dnplan.SetLinearForm(1./normtg,d2gui,
213                          -1./normtg*(nplan.Dot(d2gui)),nplan); 
214
215     temp.SetXYZ(pts.XYZ()-ptgui.XYZ());
216
217     secmember(1) = nplan.Dot(d1gui) - dnplan.Dot(temp);
218     secmember(2) = 2.*d1gui.Dot(temp);
219
220 //  gradsol*der = secmember
221 //  with  der(1) = dU/dW, der(2) = dU/dW, W is the guide parameter
222
223     math_Gauss Resol(gradsol);
224     if (Resol.IsDone()) {
225       Resol.Solve(secmember);
226       tgs.SetLinearForm(secmember(1),d1u,secmember(2),d1v);
227       tg2d.SetCoord(secmember(1),secmember(2));
228       istangent = Standard_False;
229     }
230     else {
231       istangent = Standard_True;
232     }
233     return Standard_True;
234   }
235
236   return Standard_False;
237 }