0028966: Coding Rules - remove Adaptor2d_HCurve2d, Adaptor3d_HCurve and Adaptor3d_HSu...
[occt.git] / src / BlendFunc / BlendFunc_ChamfInv.cxx
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
5 //
6 // This file is part of Open CASCADE Technology software library.
7 //
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.
13 //
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
16
17
18 #include <Adaptor2d_Curve2d.hxx>
19 #include <Adaptor3d_Curve.hxx>
20 #include <Adaptor3d_Surface.hxx>
21 #include <BlendFunc.hxx>
22 #include <BlendFunc_ChamfInv.hxx>
23 #include <math_Matrix.hxx>
24 #include <Precision.hxx>
25
26 //=======================================================================
27 //function : BlendFunc_ChamfInv
28 //purpose  : 
29 //=======================================================================
30
31 BlendFunc_ChamfInv::BlendFunc_ChamfInv(const Handle(Adaptor3d_Surface)& S1,
32                                        const Handle(Adaptor3d_Surface)& S2,
33                                        const Handle(Adaptor3d_Curve)&   C)
34   : BlendFunc_GenChamfInv(S1,S2,C),
35     corde1(surf1,curv),corde2(surf2,curv)
36 {
37 }
38
39
40 //=======================================================================
41 //function : Set
42 //purpose  : 
43 //=======================================================================
44
45 void BlendFunc_ChamfInv::Set(const Standard_Real Dist1, const Standard_Real Dist2,
46                              const Standard_Integer Choix)
47 {
48   Standard_Real dis1,dis2;
49
50   choix = Choix;
51   switch (choix) {
52   case 1:
53   case 2:
54     {
55       dis1 = -Dist1;
56       dis2 = -Dist2;
57     }
58     break;
59   case 3:
60   case 4:
61     {
62       dis1 = Dist1;
63       dis2 = -Dist2;
64     }
65     break;
66   case 5:
67   case 6:
68     {
69       dis1 = Dist1;
70       dis2 = Dist2;
71     }
72     break;
73   case 7:
74   case 8:
75     {
76       dis1 = -Dist1;
77       dis2 = Dist2;
78     }
79     break;
80   default:
81     dis1 = -Dist1;
82     dis2 = -Dist2;
83   }
84   corde1.SetDist(dis1);
85   corde2.SetDist(dis2);
86 }
87
88 //=======================================================================
89 //function : IsSolution
90 //purpose  : 
91 //=======================================================================
92
93 Standard_Boolean BlendFunc_ChamfInv::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
94 {
95   gp_Pnt2d p2d;
96   gp_Vec2d v2d;
97   csurf->D1(Sol(1),p2d,v2d);  
98
99   math_Vector Sol1(1,2), Sol2(1,2);
100   Standard_Boolean issol;
101
102   Sol1(1) = p2d.X();
103   Sol1(2) = p2d.Y();
104
105   Sol2(1) = Sol(3); 
106   Sol2(2) = Sol(4); 
107
108   if( first ){
109     issol =  corde1.IsSolution(Sol1,Tol);
110     issol = issol && corde2.IsSolution(Sol2,Tol);
111   }
112   else{
113     issol =  corde1.IsSolution(Sol2,Tol);
114     issol = issol && corde2.IsSolution(Sol1,Tol);
115   }
116
117   return issol;
118
119 }
120
121 //=======================================================================
122 //function : Value
123 //purpose  : 
124 //=======================================================================
125
126 Standard_Boolean BlendFunc_ChamfInv::Value(const math_Vector& X, math_Vector& F)
127 {
128   gp_Pnt2d p2d;
129   gp_Vec2d v2d;
130   csurf->D1(X(1),p2d,v2d);  
131   corde1.SetParam(X(2));
132   corde2.SetParam(X(2));
133
134   math_Vector x1(1,2), f1(1,2), x2(1,2), f2(1,2);
135   x1(1) = p2d.X(); x1(2) = p2d.Y();
136   x2(1) = X(3); x2(2) = X(4);
137
138   if(first){
139     corde1.Value(x1,f1);
140     corde2.Value(x2,f2);
141   }
142
143   else{
144     corde1.Value(x2,f1);
145     corde2.Value(x1,f2);
146   }
147   F(1) = f1(1);
148   F(2) = f1(2); 
149   F(3) = f2(1);
150   F(4) = f2(2);
151
152   return Standard_True;
153 }
154
155 //=======================================================================
156 //function : Derivatives
157 //purpose  : 
158 //=======================================================================
159
160 Standard_Boolean BlendFunc_ChamfInv::Derivatives(const math_Vector& X, math_Matrix& D)
161 {
162   Standard_Integer i, j;
163   gp_Pnt2d p2d;
164   gp_Vec2d v2d, df1, df2;
165   gp_Pnt pts, ptgui;
166   gp_Vec temp, d1u, d1v, nplan;
167   math_Vector x1(1,2), x2(1,2);
168   math_Matrix d1(1,2,1,2), d2(1,2,1,2);
169
170   csurf->D1(X(1),p2d,v2d);  
171   corde1.SetParam(X(2));
172   corde2.SetParam(X(2));
173
174   x1(1) = p2d.X(); x1(2) = p2d.Y();
175   x2(1) = X(3); x2(2) = X(4);
176
177   if( first ){
178     // p2d = pts est sur surf1
179     ptgui = corde1.PointOnGuide();
180     nplan = corde1.NPlan();
181     corde2.Derivatives(x2,d2); 
182     corde1.DerFguide(x1,df1);
183     corde2.DerFguide(x2,df2);
184     surf1->D1(x1(1),x1(2),pts,d1u,d1v);
185   }   
186   else{
187     //  p2d = pts est sur surf2
188     ptgui = corde2.PointOnGuide();
189     nplan = corde2.NPlan();
190     corde1.Derivatives(x2,d1); 
191     corde1.DerFguide(x2,df1);
192     corde2.DerFguide(x1,df2);
193     surf2->D1(x1(1),x1(2),pts,d1u,d1v);
194   }
195
196 // derivees par rapport a T
197   temp.SetLinearForm(v2d.X(),d1u,v2d.Y(),d1v);
198   if( first ){    
199     D(1,1) = nplan.Dot(temp);
200     D(2,1) = 2*(gp_Vec(ptgui,pts).Dot(temp));
201     D(3,1) = 0.;
202     D(4,1) = 0.;
203   }
204   else{
205     D(1,1) = 0.; 
206     D(2,1) = 0.;
207     D(3,1) = nplan.Dot(temp);
208     D(4,1) = 2*(gp_Vec(ptgui,pts).Dot(temp)); 
209   }
210
211 // derivees par rapport a W
212   D(1,2) = df1.X();
213   D(2,2) = df1.Y();
214   D(3,2) = df2.X();
215   D(4,2) = df2.Y();
216
217 // derivees par rapport a U et V
218   if( first ){
219     for( i=1; i<3; i++ ){
220        for( j=3; j<5; j++ ){
221          D(i,j) = 0.;
222          D(i+2,j) = d2(i,j-2);
223        }
224      }
225   }
226   else{
227     for( i=1; i<3; i++ ){
228        for( j=3; j<5; j++ ){ 
229          D(i,j) = d1(i,j-2);
230          D(i+2,j) = 0.;
231        }
232      }
233   }    
234
235   return Standard_True;
236