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