Integration of OCCT 6.5.0 from SVN
[occt.git] / src / BRepBlend / BRepBlend_SurfCurvEvolRadInv.cxx
CommitLineData
7fd59977 1// File: BRepBlend_SurfCurvEvolRadInv.cxx
2// Created: Tue Jul 29 12:13:34 1997
3// Author: Jerome LEMONIER
4// <jlr@sgi64>
5
6
7#include <BRepBlend_SurfCurvEvolRadInv.ixx>
8
9//=======================================================================
10//function :
11//purpose :
12//=======================================================================
13BRepBlend_SurfCurvEvolRadInv::BRepBlend_SurfCurvEvolRadInv
14(const Handle(Adaptor3d_HSurface)& S,
15const Handle(Adaptor3d_HCurve)& C,
16const Handle(Adaptor3d_HCurve)& Cg,
17 const Handle(Law_Function)& Evol): surf(S),curv(C),guide(Cg)
18{ tevol=Evol;
19}
20
21//=======================================================================
22//function :
23//purpose :
24//=======================================================================
25 void BRepBlend_SurfCurvEvolRadInv::Set(const Standard_Integer Choix)
26{ choix = Choix;
27 switch (choix) {
28 case 1 :
29 case 2 :
30 sg1 = -1;
31 break;
32 case 3 :
33 case 4 :
34 sg1 = 1;
35 break;
36 default :
37 sg1 = -1;
38 break;
39 }
40
41}
42
43//=======================================================================
44//function :
45//purpose :
46//=======================================================================
47 Standard_Integer BRepBlend_SurfCurvEvolRadInv::NbEquations() const
48{
49 return 3;
50}
51
52//=======================================================================
53//function :
54//purpose :
55//=======================================================================
56 Standard_Boolean BRepBlend_SurfCurvEvolRadInv::Value(const math_Vector& X,math_Vector& F)
57{
58 gp_Pnt ptgui;
59 gp_Vec d1gui(0.,0.,0.);
60 guide->D1(X(1),ptgui,d1gui);
61 ray = sg1*tevol->Value(X(1));
62 gp_Vec nplan = d1gui.Normalized();
63// Standard_Real theD = -(nplan.XYZ().Dot(ptgui.XYZ()));
64 gp_XYZ nplanXYZ(nplan.XYZ());
65 gp_XYZ ptguiXYZ(ptgui.XYZ());
66 Standard_Real theD = nplanXYZ.Dot(ptguiXYZ) ;
67 theD = theD * (-1.) ;
68
69 gp_Pnt ptcur = curv->Value(X(2));
70 F(1) = nplan.XYZ().Dot(ptcur.XYZ()) + theD;
71 gp_Pnt2d p2drst = rst->Value(X(3));
72 gp_Pnt pts;
73 gp_Vec du,dv;
74 surf->D1(p2drst.X(),p2drst.Y(),pts,du,dv);
75 F(2) = nplan.XYZ().Dot(pts.XYZ()) + theD;
76 gp_Vec ns = du.Crossed(dv);
77 Standard_Real norm = nplan.Crossed(ns).Magnitude();
78 Standard_Real unsurnorm = 1./norm;
79 ns.SetLinearForm(nplan.Dot(ns),nplan, -1.,ns);
80 ns.Multiply(unsurnorm);
81 gp_Vec ref(ptcur,pts);
82
83 ref.SetLinearForm(ray,ns,ref);
84 F(3) = ref.SquareMagnitude() - ray*ray;
85 return Standard_True;
86}
87
88//=======================================================================
89//function :
90//purpose :
91//=======================================================================
92 Standard_Boolean BRepBlend_SurfCurvEvolRadInv::Derivatives(const math_Vector& X,math_Matrix& D)
93{
94 gp_Pnt ptgui;
95 gp_Vec d1gui,d2gui;
96 guide->D2(X(1),ptgui,d1gui,d2gui);
97 Standard_Real normd1gui = d1gui.Magnitude(),dray;
98 Standard_Real unsurnormd1gui = 1./normd1gui;
99 tevol->D1(X(1),ray,dray);
100 ray=sg1*ray;
101 dray=sg1*dray;
102 gp_Vec nplan = d1gui.Multiplied(unsurnormd1gui);
103#ifdef DEB
104 Standard_Real theD = -(nplan.XYZ().Dot(ptgui.XYZ()));
105#endif
106 gp_Vec dnplan;
107 dnplan.SetLinearForm(-nplan.Dot(d2gui),nplan,d2gui);
108 dnplan.Multiply(unsurnormd1gui);
109 Standard_Real dtheD = - nplan.XYZ().Dot(d1gui.XYZ()) - dnplan.XYZ().Dot(ptgui.XYZ());
110 gp_Pnt ptcur;
111 gp_Vec d1cur;
112 curv->D1(X(2),ptcur,d1cur);
113 D(1,1) = dnplan.XYZ().Dot(ptcur.XYZ()) + dtheD;
114 D(1,2) = nplan.XYZ().Dot(d1cur.XYZ());
115 D(1,3) = 0.;
116
117 gp_Pnt2d p2drst;
118 gp_Vec2d d1rst;
119 rst->D1(X(3),p2drst,d1rst);
120 gp_Pnt pts;
121 gp_Vec d1u,d1v,d2u,d2v,duv;
122 surf->D2(p2drst.X(),p2drst.Y(),pts,d1u,d1v,d2u,d2v,duv);
123 D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD;
124 D(2,2) = 0.;
125 gp_Vec dwrstpts;
126 dwrstpts.SetLinearForm(d1rst.X(),d1u,d1rst.Y(),d1v);
127 D(2,3) = nplan.XYZ().Dot(dwrstpts.XYZ());
128
129 gp_Vec nsurf = d1u.Crossed(d1v);
130 gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv));
131 gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v));
132 gp_Vec dwrstnsurf;
133 dwrstnsurf.SetLinearForm(d1rst.X(),dunsurf,d1rst.Y(),dvnsurf);
134
135 gp_Vec nplancrosnsurf = nplan.Crossed(nsurf);
136 gp_Vec dwguinplancrosnsurf = dnplan.Crossed(nsurf);
137 gp_Vec dwrstnplancrosnsurf = nplan.Crossed(dwrstnsurf);
138
139 Standard_Real norm2 = nplancrosnsurf.SquareMagnitude();
140 Standard_Real norm = sqrt(norm2);
141 Standard_Real unsurnorm = 1./norm;
142 Standard_Real raysurnorm = ray*unsurnorm;
143 Standard_Real unsurnorm2 = unsurnorm * unsurnorm;
144 Standard_Real raysurnorm2 = ray*unsurnorm2;
145 Standard_Real dwguinorm = unsurnorm*nplancrosnsurf.Dot(dwguinplancrosnsurf);
146 Standard_Real dwrstnorm = unsurnorm*nplancrosnsurf.Dot(dwrstnplancrosnsurf);
147
148 Standard_Real nplandotnsurf = nplan.Dot(nsurf);
149 Standard_Real dwguinplandotnsurf = dnplan.Dot(nsurf);
150 Standard_Real dwrstnplandotnsurf = nplan.Dot(dwrstnsurf);
151
152 gp_Vec temp,dwguitemp,dwrsttemp;
153 temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf);
154 dwguitemp.SetLinearForm(nplandotnsurf,dnplan,dwguinplandotnsurf,nplan);
155 dwrsttemp.SetLinearForm(dwrstnplandotnsurf,nplan,-1.,dwrstnsurf);
156
157 gp_Vec corde(ptcur,pts);
158 gp_Vec ref,dwguiref,dwrstref;
159 ref.SetLinearForm(raysurnorm,temp,corde);
160 dwguiref.SetLinearForm(raysurnorm,dwguitemp,-raysurnorm2*dwguinorm,temp);
161 dwguiref.SetLinearForm(1.,dwguiref,dray*unsurnorm,temp);
162 dwrstref.SetLinearForm(raysurnorm,dwrsttemp,-raysurnorm2*dwrstnorm,temp,dwrstpts);
163
164 ref.Add(ref);
165 D(3,1) = ref.Dot(dwguiref) - 2.*dray*ray;
166 D(3,2) = -ref.Dot(d1cur);
167 D(3,3) = ref.Dot(dwrstref);
168
169 return Standard_True;
170}
171
172//=======================================================================
173//function :
174//purpose :
175//=======================================================================
176 Standard_Boolean BRepBlend_SurfCurvEvolRadInv::Values(const math_Vector& X,math_Vector& F,math_Matrix& D)
177{
178 gp_Pnt ptgui;
179 gp_Vec d1gui(0.,0.,0.),d2gui(0.,0.,0.);
180 guide->D2(X(1),ptgui,d1gui,d2gui);
181 Standard_Real dray;
182 tevol->D1(X(1),ray,dray);
183 ray=sg1*ray;
184 dray=sg1*dray;
185 Standard_Real normd1gui = d1gui.Magnitude();
186 Standard_Real unsurnormd1gui = 1./normd1gui;
187 gp_Vec nplan = d1gui.Multiplied(unsurnormd1gui);
188// Standard_Real theD = -(nplan.XYZ().Dot(ptgui.XYZ()));
189 gp_XYZ nplanXYZ(nplan.XYZ());
190 gp_XYZ ptcurXYZ(ptgui.XYZ());
191 Standard_Real theD = nplanXYZ.Dot(ptcurXYZ) ;
192 theD = theD * (-1.) ;
193
194 gp_Vec dnplan;
195 dnplan.SetLinearForm(-nplan.Dot(d2gui),nplan,d2gui);
196 dnplan.Multiply(unsurnormd1gui);
197 Standard_Real dtheD = - nplan.XYZ().Dot(d1gui.XYZ()) - dnplan.XYZ().Dot(ptgui.XYZ());
198 gp_Pnt ptcur;
199 gp_Vec d1cur;
200 curv->D1(X(2),ptcur,d1cur);
201 F(1) = nplan.XYZ().Dot(ptcur.XYZ()) + theD;
202 D(1,1) = dnplan.XYZ().Dot(ptcur.XYZ()) + dtheD;
203 D(1,2) = nplan.XYZ().Dot(d1cur.XYZ());
204 D(1,3) = 0.;
205
206 gp_Pnt2d p2drst;
207 gp_Vec2d d1rst;
208 rst->D1(X(3),p2drst,d1rst);
209 gp_Pnt pts;
210 gp_Vec d1u,d1v,d2u,d2v,duv;
211 surf->D2(p2drst.X(),p2drst.Y(),pts,d1u,d1v,d2u,d2v,duv);
212 F(2) = nplan.XYZ().Dot(pts.XYZ()) + theD;
213 D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD;
214 D(2,2) = 0.;
215 gp_Vec dwrstpts;
216 dwrstpts.SetLinearForm(d1rst.X(),d1u,d1rst.Y(),d1v);
217 D(2,3) = nplan.XYZ().Dot(dwrstpts.XYZ());
218
219 gp_Vec nsurf = d1u.Crossed(d1v);
220 gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv));
221 gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v));
222 gp_Vec dwrstnsurf;
223 dwrstnsurf.SetLinearForm(d1rst.X(),dunsurf,d1rst.Y(),dvnsurf);
224
225 gp_Vec nplancrosnsurf = nplan.Crossed(nsurf);
226 gp_Vec dwguinplancrosnsurf = dnplan.Crossed(nsurf);
227 gp_Vec dwrstnplancrosnsurf = nplan.Crossed(dwrstnsurf);
228
229 Standard_Real norm2 = nplancrosnsurf.SquareMagnitude();
230 Standard_Real norm = sqrt(norm2);
231 Standard_Real unsurnorm = 1./norm;
232 Standard_Real raysurnorm = ray*unsurnorm;
233 Standard_Real unsurnorm2 = unsurnorm * unsurnorm;
234 Standard_Real raysurnorm2 = ray*unsurnorm2;
235 Standard_Real dwguinorm = unsurnorm*nplancrosnsurf.Dot(dwguinplancrosnsurf);
236 Standard_Real dwrstnorm = unsurnorm*nplancrosnsurf.Dot(dwrstnplancrosnsurf);
237
238 Standard_Real nplandotnsurf = nplan.Dot(nsurf);
239 Standard_Real dwguinplandotnsurf = dnplan.Dot(nsurf);
240 Standard_Real dwrstnplandotnsurf = nplan.Dot(dwrstnsurf);
241
242 gp_Vec temp,dwguitemp,dwrsttemp;
243 temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf);
244 dwguitemp.SetLinearForm(nplandotnsurf,dnplan,dwguinplandotnsurf,nplan);
245 dwrsttemp.SetLinearForm(dwrstnplandotnsurf,nplan,-1.,dwrstnsurf);
246
247 gp_Vec corde(ptcur,pts);
248 gp_Vec ref,dwguiref,dwrstref;
249 ref.SetLinearForm(raysurnorm,temp,corde);
250 F(3) = ref.SquareMagnitude() - ray*ray;
251 dwguiref.SetLinearForm(raysurnorm,dwguitemp,-raysurnorm2*dwguinorm,temp);
252 dwguiref.SetLinearForm(1.,dwguiref,dray*unsurnorm,temp);
253 dwrstref.SetLinearForm(raysurnorm,dwrsttemp,-raysurnorm2*dwrstnorm,temp,dwrstpts);
254
255 ref.Add(ref);
256 D(3,1) = ref.Dot(dwguiref) - 2.*dray*ray;
257 D(3,2) = -ref.Dot(d1cur);
258 D(3,3) = ref.Dot(dwrstref);
259 return Standard_True;
260}
261
262//=======================================================================
263//function :
264//purpose :
265//=======================================================================
266 void BRepBlend_SurfCurvEvolRadInv::Set(const Handle(Adaptor2d_HCurve2d)& Rst)
267{
268 rst = Rst;
269}
270
271//=======================================================================
272//function :
273//purpose :
274//=======================================================================
275 void BRepBlend_SurfCurvEvolRadInv::GetTolerance(math_Vector& Tolerance,const Standard_Real Tol) const
276{
277 Tolerance(1) = guide->Resolution(Tol);
278 Tolerance(2) = curv->Resolution(Tol);
279 Standard_Real ru,rv;
280 ru = surf->UResolution(Tol);
281 rv = surf->VResolution(Tol);
282 Tolerance(3) = rst->Resolution(Min(ru,rv));
283}
284
285//=======================================================================
286//function :
287//purpose :
288//=======================================================================
289 void BRepBlend_SurfCurvEvolRadInv::GetBounds(math_Vector& InfBound,math_Vector& SupBound) const
290{
291 InfBound(1) = guide->FirstParameter();
292 SupBound(1) = guide->LastParameter();
293 InfBound(2) = curv->FirstParameter();
294 SupBound(2) = curv->LastParameter();
295 InfBound(3) = rst->FirstParameter();
296 SupBound(3) = rst->LastParameter();
297}
298
299//=======================================================================
300//function :
301//purpose :
302//=======================================================================
303 Standard_Boolean BRepBlend_SurfCurvEvolRadInv::IsSolution(const math_Vector& Sol,const Standard_Real Tol)
304{
305 math_Vector valsol(1,3);
306 Value(Sol,valsol);
307 if (Abs(valsol(1)) <= Tol &&
308 Abs(valsol(2)) <= Tol &&
309 Abs(valsol(3)) <= 2*Tol*Abs(ray)) {
310 return Standard_True;
311 }
312 return Standard_False;
313}
314