1 // Created on: 1996-06-06
2 // Created by: Stagiaire Xuan Trang PHAMPHU
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2014 OPEN CASCADE SAS
6 // This file is part of Open CASCADE Technology software library.
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
18 #include <Adaptor2d_HCurve2d.hxx>
19 #include <Adaptor3d_HCurve.hxx>
20 #include <Adaptor3d_HSurface.hxx>
21 #include <BlendFunc.hxx>
22 #include <BlendFunc_ChamfInv.hxx>
23 #include <math_Matrix.hxx>
24 #include <Precision.hxx>
26 //=======================================================================
27 //function : BlendFunc_ChamfInv
29 //=======================================================================
30 BlendFunc_ChamfInv::BlendFunc_ChamfInv(const Handle(Adaptor3d_HSurface)& S1,
31 const Handle(Adaptor3d_HSurface)& S2,
32 const Handle(Adaptor3d_HCurve)& C) :
33 surf1(S1),surf2(S2),curv(C),corde1(surf1,curv),corde2(surf2,curv)
38 //=======================================================================
41 //=======================================================================
43 void BlendFunc_ChamfInv::Set(const Standard_Real Dist1, const Standard_Real Dist2,
44 const Standard_Integer Choix)
46 Standard_Real dis1,dis2;
86 //=======================================================================
87 //function : NbEquations
89 //=======================================================================
91 Standard_Integer BlendFunc_ChamfInv::NbEquations () const
96 //=======================================================================
97 //function : GetTolerance
99 //=======================================================================
101 void BlendFunc_ChamfInv::Set(const Standard_Boolean OnFirst, const Handle(Adaptor2d_HCurve2d)& C)
107 //=======================================================================
108 //function : GetTolerance
110 //=======================================================================
112 void BlendFunc_ChamfInv::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
114 Tolerance(1) = csurf->Resolution(Tol);
115 Tolerance(2) = curv->Resolution(Tol);
117 Tolerance(3) = surf2->UResolution(Tol);
118 Tolerance(4) = surf2->VResolution(Tol);
121 Tolerance(3) = surf1->UResolution(Tol);
122 Tolerance(4) = surf1->VResolution(Tol);
127 //=======================================================================
128 //function : GetBounds
130 //=======================================================================
132 void BlendFunc_ChamfInv::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
134 InfBound(1) = csurf->FirstParameter();
135 InfBound(2) = curv->FirstParameter();
136 SupBound(1) = csurf->LastParameter();
137 SupBound(2) = curv->LastParameter();
140 InfBound(3) = surf2->FirstUParameter();
141 InfBound(4) = surf2->FirstVParameter();
142 SupBound(3) = surf2->LastUParameter();
143 SupBound(4) = surf2->LastVParameter();
144 if(!Precision::IsInfinite(InfBound(3)) &&
145 !Precision::IsInfinite(SupBound(3))) {
146 const Standard_Real range = (SupBound(3) - InfBound(3));
147 InfBound(3) -= range;
148 SupBound(3) += range;
150 if(!Precision::IsInfinite(InfBound(4)) &&
151 !Precision::IsInfinite(SupBound(4))) {
152 const Standard_Real range = (SupBound(4) - InfBound(4));
153 InfBound(4) -= range;
154 SupBound(4) += range;
158 InfBound(3) = surf1->FirstUParameter();
159 InfBound(4) = surf1->FirstVParameter();
160 SupBound(3) = surf1->LastUParameter();
161 SupBound(4) = surf1->LastVParameter();
162 if(!Precision::IsInfinite(InfBound(3)) &&
163 !Precision::IsInfinite(SupBound(3))) {
164 const Standard_Real range = (SupBound(3) - InfBound(3));
165 InfBound(3) -= range;
166 SupBound(3) += range;
168 if(!Precision::IsInfinite(InfBound(4)) &&
169 !Precision::IsInfinite(SupBound(4))) {
170 const Standard_Real range = (SupBound(4) - InfBound(4));
171 InfBound(4) -= range;
172 SupBound(4) += range;
177 //=======================================================================
178 //function : IsSolution
180 //=======================================================================
182 Standard_Boolean BlendFunc_ChamfInv::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
186 csurf->D1(Sol(1),p2d,v2d);
188 math_Vector Sol1(1,2), Sol2(1,2);
189 Standard_Boolean issol;
198 issol = corde1.IsSolution(Sol1,Tol);
199 issol = issol && corde2.IsSolution(Sol2,Tol);
202 issol = corde1.IsSolution(Sol2,Tol);
203 issol = issol && corde2.IsSolution(Sol1,Tol);
211 //=======================================================================
214 //=======================================================================
216 Standard_Boolean BlendFunc_ChamfInv::Value(const math_Vector& X, math_Vector& F)
220 csurf->D1(X(1),p2d,v2d);
221 corde1.SetParam(X(2));
222 corde2.SetParam(X(2));
224 math_Vector x1(1,2), f1(1,2), x2(1,2), f2(1,2);
225 x1(1) = p2d.X(); x1(2) = p2d.Y();
226 x2(1) = X(3); x2(2) = X(4);
242 return Standard_True;
245 //=======================================================================
246 //function : Derivatives
248 //=======================================================================
250 Standard_Boolean BlendFunc_ChamfInv::Derivatives(const math_Vector& X, math_Matrix& D)
252 Standard_Integer i, j;
254 gp_Vec2d v2d, df1, df2;
256 gp_Vec temp, d1u, d1v, nplan;
257 math_Vector x1(1,2), x2(1,2);
258 math_Matrix d1(1,2,1,2), d2(1,2,1,2);
260 csurf->D1(X(1),p2d,v2d);
261 corde1.SetParam(X(2));
262 corde2.SetParam(X(2));
264 x1(1) = p2d.X(); x1(2) = p2d.Y();
265 x2(1) = X(3); x2(2) = X(4);
268 // p2d = pts est sur surf1
269 ptgui = corde1.PointOnGuide();
270 nplan = corde1.NPlan();
271 corde2.Derivatives(x2,d2);
272 corde1.DerFguide(x1,df1);
273 corde2.DerFguide(x2,df2);
274 surf1->D1(x1(1),x1(2),pts,d1u,d1v);
277 // p2d = pts est sur surf2
278 ptgui = corde2.PointOnGuide();
279 nplan = corde2.NPlan();
280 corde1.Derivatives(x2,d1);
281 corde1.DerFguide(x2,df1);
282 corde2.DerFguide(x1,df2);
283 surf2->D1(x1(1),x1(2),pts,d1u,d1v);
286 // derivees par rapport a T
287 temp.SetLinearForm(v2d.X(),d1u,v2d.Y(),d1v);
289 D(1,1) = nplan.Dot(temp);
290 D(2,1) = 2*(gp_Vec(ptgui,pts).Dot(temp));
297 D(3,1) = nplan.Dot(temp);
298 D(4,1) = 2*(gp_Vec(ptgui,pts).Dot(temp));
301 // derivees par rapport a W
307 // derivees par rapport a U et V
309 for( i=1; i<3; i++ ){
310 for( j=3; j<5; j++ ){
312 D(i+2,j) = d2(i,j-2);
317 for( i=1; i<3; i++ ){
318 for( j=3; j<5; j++ ){
325 return Standard_True;
328 //=======================================================================
331 //=======================================================================
333 Standard_Boolean BlendFunc_ChamfInv::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
337 return Standard_True;