b311480e |
1 | // Created on: 1997-07-29 |
2 | // Created by: Jerome LEMONIER |
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 | |
17 | #include <BRepBlend_SurfPointEvolRadInv.ixx> |
18 | |
19 | |
20 | //======================================================================= |
21 | //function : |
22 | //purpose : |
23 | //======================================================================= |
24 | BRepBlend_SurfPointEvolRadInv::BRepBlend_SurfPointEvolRadInv |
25 | (const Handle(Adaptor3d_HSurface)& S, |
26 | const Handle(Adaptor3d_HCurve)& C, |
27 | const Handle(Law_Function)& Evol |
28 | ) : surf(S), curv(C) |
29 | { tevol=Evol; |
30 | } |
31 | |
32 | //======================================================================= |
33 | //function : |
34 | //purpose : |
35 | //======================================================================= |
36 | void BRepBlend_SurfPointEvolRadInv::Set(const Standard_Integer Choix) |
37 | { choix = Choix; |
38 | switch (choix) { |
39 | case 1 : |
40 | case 2 : |
41 | sg1 = -1; |
42 | break; |
43 | case 3 : |
44 | case 4 : |
45 | sg1 = 1; |
46 | break; |
47 | default : |
48 | sg1 = -1; |
49 | break; |
50 | } |
51 | } |
52 | |
53 | //======================================================================= |
54 | //function : |
55 | //purpose : |
56 | //======================================================================= |
57 | Standard_Integer BRepBlend_SurfPointEvolRadInv::NbEquations() const |
58 | { |
59 | return 3; |
60 | } |
61 | |
62 | //======================================================================= |
63 | //function : |
64 | //purpose : |
65 | //======================================================================= |
66 | Standard_Boolean BRepBlend_SurfPointEvolRadInv::Value(const math_Vector& X,math_Vector& F) |
67 | { |
68 | Standard_Real theD,norm,unsurnorm; |
69 | gp_Pnt ptcur,pts; |
70 | gp_Vec d1cur,d1u,d1v; |
71 | gp_XYZ nplan(0.,0.,0.),ns(0.,0.,0.),ref(0.,0.,0.); |
72 | curv->D1(X(1),ptcur,d1cur); |
73 | ray = sg1*tevol->Value(X(1)); |
74 | nplan = d1cur.Normalized().XYZ(); |
75 | theD = -(nplan.Dot(ptcur.XYZ())); |
76 | surf->D1(X(2),X(3),pts,d1u,d1v); |
77 | F(1) = nplan.Dot(point.XYZ()) + theD; |
78 | F(2) = nplan.Dot(pts.XYZ()) + theD; |
79 | ns = d1u.Crossed(d1v).XYZ(); |
80 | norm = nplan.Crossed(ns).Modulus(); |
81 | unsurnorm = 1./norm; |
82 | ns.SetLinearForm(nplan.Dot(ns),nplan, -1.,ns); |
83 | ns.Multiply(unsurnorm); |
84 | ref = pts.XYZ() - point.XYZ(); |
85 | ref.SetLinearForm(ray,ns,ref); |
86 | F(3) = ref.SquareModulus() - ray*ray; |
87 | return Standard_True; |
88 | } |
89 | |
90 | //======================================================================= |
91 | //function : |
92 | //purpose : |
93 | //======================================================================= |
94 | Standard_Boolean BRepBlend_SurfPointEvolRadInv::Derivatives(const math_Vector& X,math_Matrix& D) |
95 | { |
96 | gp_Pnt ptcur,pts; |
97 | gp_Vec d1cur,d2cur,nplan,dnplan,d1u,d1v,d2u,d2v,duv; |
96a95605 |
98 | Standard_Real dtheD, normd1cur, unsurnormd1cur,dray; |
7fd59977 |
99 | |
100 | curv->D2(X(1),ptcur,d1cur,d2cur); |
101 | tevol->D1(X(1),ray,dray); |
102 | ray=sg1*ray; |
103 | dray=sg1*dray; |
104 | normd1cur = d1cur.Magnitude(); |
105 | unsurnormd1cur = 1./normd1cur; |
106 | nplan = unsurnormd1cur * d1cur; |
7fd59977 |
107 | dnplan.SetLinearForm(-nplan.Dot(d2cur),nplan,d2cur); |
108 | dnplan.Multiply(unsurnormd1cur); |
109 | dtheD = - nplan.XYZ().Dot(d1cur.XYZ()) - dnplan.XYZ().Dot(ptcur.XYZ()); |
110 | D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD; |
111 | D(1,2) = D(1,3) = 0.; |
112 | surf->D2(X(2),X(3),pts,d1u,d1v,d2u,d2v,duv); |
113 | D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD; |
114 | D(2,2) = nplan.Dot(d1u); |
115 | D(2,3) = nplan.Dot(d1v); |
116 | |
117 | gp_Vec nsurf = d1u.Crossed(d1v); |
118 | gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv)); |
119 | gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v)); |
120 | |
121 | gp_Vec nplancrosnsurf = nplan.Crossed(nsurf); |
122 | gp_Vec dwnplancrosnsurf = dnplan.Crossed(nsurf); |
123 | gp_Vec dunplancrosnsurf = nplan.Crossed(dunsurf); |
124 | gp_Vec dvnplancrosnsurf = nplan.Crossed(dvnsurf); |
125 | |
126 | Standard_Real norm2 = nplancrosnsurf.SquareMagnitude(); |
127 | Standard_Real norm = sqrt(norm2); |
128 | Standard_Real unsurnorm = 1./norm; |
129 | Standard_Real raysurnorm = ray*unsurnorm; |
130 | Standard_Real unsurnorm2 = unsurnorm * unsurnorm; |
131 | Standard_Real raysurnorm2 = ray*unsurnorm2; |
132 | Standard_Real dwnorm = unsurnorm*nplancrosnsurf.Dot(dwnplancrosnsurf); |
133 | Standard_Real dunorm = unsurnorm*nplancrosnsurf.Dot(dunplancrosnsurf); |
134 | Standard_Real dvnorm = unsurnorm*nplancrosnsurf.Dot(dvnplancrosnsurf); |
135 | |
136 | Standard_Real nplandotnsurf = nplan.Dot(nsurf); |
137 | Standard_Real dwnplandotnsurf = dnplan.Dot(nsurf); |
138 | Standard_Real dunplandotnsurf = nplan.Dot(dunsurf); |
139 | Standard_Real dvnplandotnsurf = nplan.Dot(dvnsurf); |
140 | |
141 | gp_Vec temp,dwtemp,dutemp,dvtemp; |
142 | temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf); |
143 | dwtemp.SetLinearForm(nplandotnsurf,dnplan,dwnplandotnsurf,nplan); |
144 | dutemp.SetLinearForm(dunplandotnsurf,nplan,-1.,dunsurf); |
145 | dvtemp.SetLinearForm(dvnplandotnsurf,nplan,-1.,dvnsurf); |
146 | |
147 | gp_Vec ref,dwref,duref,dvref,corde(point,pts); |
148 | ref.SetLinearForm(raysurnorm,temp,corde); |
149 | dwref.SetLinearForm(raysurnorm,dwtemp,-raysurnorm2*dwnorm,temp); |
150 | dwref.SetLinearForm(1.,dwref,dray*unsurnorm,temp); |
151 | duref.SetLinearForm(raysurnorm,dutemp,-raysurnorm2*dunorm,temp,d1u); |
152 | dvref.SetLinearForm(raysurnorm,dvtemp,-raysurnorm2*dvnorm,temp,d1v); |
153 | |
154 | ref.Add(ref); |
155 | D(3,1) = ref.Dot(dwref) - 2.*dray*ray; |
156 | D(3,2) = ref.Dot(duref); |
157 | D(3,3) = ref.Dot(dvref); |
158 | |
159 | return Standard_True; |
160 | } |
161 | |
162 | //======================================================================= |
163 | //function : |
164 | //purpose : |
165 | //======================================================================= |
166 | Standard_Boolean BRepBlend_SurfPointEvolRadInv::Values(const math_Vector& X,math_Vector& F,math_Matrix& D) |
167 | { |
168 | gp_Pnt ptcur,pts; |
169 | gp_Vec d1cur,d2cur,nplan,dnplan,d1u,d1v,d2u,d2v,duv; |
170 | Standard_Real theD, dtheD, normd1cur, unsurnormd1cur,dray; |
171 | |
172 | curv->D2(X(1),ptcur,d1cur,d2cur); |
173 | tevol->D1(X(1),ray,dray); |
174 | ray=sg1*ray; |
175 | dray=sg1*dray; |
176 | surf->D2(X(2),X(3),pts,d1u,d1v,d2u,d2v,duv); |
177 | normd1cur = d1cur.Magnitude(); |
178 | unsurnormd1cur = 1./normd1cur; |
179 | nplan = unsurnormd1cur * d1cur; |
180 | theD = -(nplan.XYZ().Dot(ptcur.XYZ())); |
181 | F(1) = nplan.XYZ().Dot(point.XYZ()) + theD; |
182 | F(2) = nplan.XYZ().Dot(pts.XYZ()) + theD; |
183 | |
184 | dnplan.SetLinearForm(-nplan.Dot(d2cur),nplan,d2cur); |
185 | dnplan.Multiply(unsurnormd1cur); |
186 | dtheD = - nplan.XYZ().Dot(d1cur.XYZ()) - dnplan.XYZ().Dot(ptcur.XYZ()); |
187 | D(1,1) = dnplan.XYZ().Dot(point.XYZ()) + dtheD; |
188 | D(1,2) = D(1,3) = 0.; |
189 | D(2,1) = dnplan.XYZ().Dot(pts.XYZ()) + dtheD; |
190 | D(2,2) = nplan.Dot(d1u); |
191 | D(2,3) = nplan.Dot(d1v); |
192 | |
193 | gp_Vec nsurf = d1u.Crossed(d1v); |
194 | gp_Vec dunsurf = d2u.Crossed(d1v).Added(d1u.Crossed(duv)); |
195 | gp_Vec dvnsurf = d1u.Crossed(d2v).Added(duv.Crossed(d1v)); |
196 | |
197 | gp_Vec nplancrosnsurf = nplan.Crossed(nsurf); |
198 | gp_Vec dwnplancrosnsurf = dnplan.Crossed(nsurf); |
199 | gp_Vec dunplancrosnsurf = nplan.Crossed(dunsurf); |
200 | gp_Vec dvnplancrosnsurf = nplan.Crossed(dvnsurf); |
201 | |
202 | Standard_Real norm2 = nplancrosnsurf.SquareMagnitude(); |
203 | Standard_Real norm = sqrt(norm2); |
204 | Standard_Real unsurnorm = 1./norm; |
205 | Standard_Real raysurnorm = ray*unsurnorm; |
206 | Standard_Real unsurnorm2 = unsurnorm * unsurnorm; |
207 | Standard_Real raysurnorm2 = ray*unsurnorm2; |
208 | Standard_Real dwnorm = unsurnorm*nplancrosnsurf.Dot(dwnplancrosnsurf); |
209 | Standard_Real dunorm = unsurnorm*nplancrosnsurf.Dot(dunplancrosnsurf); |
210 | Standard_Real dvnorm = unsurnorm*nplancrosnsurf.Dot(dvnplancrosnsurf); |
211 | |
212 | Standard_Real nplandotnsurf = nplan.Dot(nsurf); |
213 | Standard_Real dwnplandotnsurf = dnplan.Dot(nsurf); |
214 | Standard_Real dunplandotnsurf = nplan.Dot(dunsurf); |
215 | Standard_Real dvnplandotnsurf = nplan.Dot(dvnsurf); |
216 | |
217 | gp_Vec temp,dwtemp,dutemp,dvtemp; |
218 | temp.SetLinearForm(nplandotnsurf,nplan,-1.,nsurf); |
219 | dwtemp.SetLinearForm(nplandotnsurf,dnplan,dwnplandotnsurf,nplan); |
220 | dutemp.SetLinearForm(dunplandotnsurf,nplan,-1.,dunsurf); |
221 | dvtemp.SetLinearForm(dvnplandotnsurf,nplan,-1.,dvnsurf); |
222 | |
223 | gp_Vec ref,dwref,duref,dvref,corde(point,pts); |
224 | ref.SetLinearForm(raysurnorm,temp,corde); |
225 | F(3) = ref.SquareMagnitude() - ray*ray; |
226 | dwref.SetLinearForm(raysurnorm,dwtemp,-raysurnorm2*dwnorm,temp); |
227 | dwref.SetLinearForm(1.,dwref,dray*unsurnorm,temp); |
228 | duref.SetLinearForm(raysurnorm,dutemp,-raysurnorm2*dunorm,temp,d1u); |
229 | dvref.SetLinearForm(raysurnorm,dvtemp,-raysurnorm2*dvnorm,temp,d1v); |
230 | |
231 | ref.Add(ref); |
232 | D(3,1) = ref.Dot(dwref) - 2.*dray*ray; |
233 | D(3,2) = ref.Dot(duref); |
234 | D(3,3) = ref.Dot(dvref); |
235 | |
236 | return Standard_True; |
237 | } |
238 | |
239 | //======================================================================= |
240 | //function : |
241 | //purpose : |
242 | //======================================================================= |
243 | void BRepBlend_SurfPointEvolRadInv::Set(const gp_Pnt& P) |
244 | { |
245 | point = P; |
246 | } |
247 | |
248 | //======================================================================= |
249 | //function : |
250 | //purpose : |
251 | //======================================================================= |
252 | void BRepBlend_SurfPointEvolRadInv::GetTolerance(math_Vector& Tolerance,const Standard_Real Tol) const |
253 | { |
254 | Tolerance(1) = curv->Resolution(Tol); |
255 | Tolerance(2) = surf->UResolution(Tol); |
256 | Tolerance(3) = surf->VResolution(Tol); |
257 | } |
258 | |
259 | //======================================================================= |
260 | //function : |
261 | //purpose : |
262 | //======================================================================= |
263 | void BRepBlend_SurfPointEvolRadInv::GetBounds(math_Vector& InfBound,math_Vector& SupBound) const |
264 | { |
265 | InfBound(1) = curv->FirstParameter(); |
266 | SupBound(1) = curv->LastParameter(); |
267 | InfBound(2) = surf->FirstUParameter(); |
268 | SupBound(2) = surf->LastUParameter(); |
269 | InfBound(3) = surf->FirstVParameter(); |
270 | SupBound(3) = surf->LastVParameter(); |
271 | } |
272 | |
273 | //======================================================================= |
274 | //function : |
275 | //purpose : |
276 | //======================================================================= |
277 | Standard_Boolean BRepBlend_SurfPointEvolRadInv::IsSolution(const math_Vector& Sol,const Standard_Real Tol) |
278 | { |
279 | math_Vector valsol(1,3); |
280 | Value(Sol,valsol); |
281 | if (Abs(valsol(1)) <= Tol && |
282 | Abs(valsol(2)) <= Tol && |
283 | Abs(valsol(3)) <= 2*Tol*Abs(ray) ) { |
284 | return Standard_True; |
285 | } |
286 | return Standard_False; |
287 | } |
288 | |