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