0022048: Visualization, AIS_InteractiveContext - single object selection should alway...
[occt.git] / src / BlendFunc / BlendFunc_ChamfInv.cxx
CommitLineData
b311480e 1// Created on: 1996-06-06
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 <Adaptor2d_HCurve2d.hxx>
19#include <Adaptor3d_HCurve.hxx>
20#include <Adaptor3d_HSurface.hxx>
7fd59977 21#include <BlendFunc.hxx>
42cf5bc1 22#include <BlendFunc_ChamfInv.hxx>
23#include <math_Matrix.hxx>
7fd59977 24#include <Precision.hxx>
25
26//=======================================================================
27//function : BlendFunc_ChamfInv
28//purpose :
29//=======================================================================
7fd59977 30BlendFunc_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)
34{
35}
36
37
38//=======================================================================
39//function : Set
40//purpose :
41//=======================================================================
42
43void BlendFunc_ChamfInv::Set(const Standard_Real Dist1, const Standard_Real Dist2,
44 const Standard_Integer Choix)
45{
46 Standard_Real dis1,dis2;
47
48 choix = Choix;
49 switch (choix) {
50 case 1:
51 case 2:
52 {
53 dis1 = -Dist1;
54 dis2 = -Dist2;
55 }
56 break;
57 case 3:
58 case 4:
59 {
60 dis1 = Dist1;
61 dis2 = -Dist2;
62 }
63 break;
64 case 5:
65 case 6:
66 {
67 dis1 = Dist1;
68 dis2 = Dist2;
69 }
70 break;
71 case 7:
72 case 8:
73 {
74 dis1 = -Dist1;
75 dis2 = Dist2;
76 }
77 break;
78 default:
79 dis1 = -Dist1;
80 dis2 = -Dist2;
81 }
82 corde1.SetDist(dis1);
83 corde2.SetDist(dis2);
84}
85
86//=======================================================================
87//function : NbEquations
88//purpose :
89//=======================================================================
90
91Standard_Integer BlendFunc_ChamfInv::NbEquations () const
92{
93 return 4;
94}
95
96//=======================================================================
97//function : GetTolerance
98//purpose :
99//=======================================================================
100
101void BlendFunc_ChamfInv::Set(const Standard_Boolean OnFirst, const Handle(Adaptor2d_HCurve2d)& C)
102{
103 first = OnFirst;
104 csurf = C;
105}
106
107//=======================================================================
108//function : GetTolerance
109//purpose :
110//=======================================================================
111
112void BlendFunc_ChamfInv::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
113{
114 Tolerance(1) = csurf->Resolution(Tol);
115 Tolerance(2) = curv->Resolution(Tol);
116 if (first) {
117 Tolerance(3) = surf2->UResolution(Tol);
118 Tolerance(4) = surf2->VResolution(Tol);
119 }
120 else {
121 Tolerance(3) = surf1->UResolution(Tol);
122 Tolerance(4) = surf1->VResolution(Tol);
123 }
124}
125
126
127//=======================================================================
128//function : GetBounds
129//purpose :
130//=======================================================================
131
132void BlendFunc_ChamfInv::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
133{
134 InfBound(1) = csurf->FirstParameter();
135 InfBound(2) = curv->FirstParameter();
136 SupBound(1) = csurf->LastParameter();
137 SupBound(2) = curv->LastParameter();
138
139 if (first) {
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;
149 }
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;
155 }
156 }
157 else {
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;
167 }
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;
173 }
174 }
175}
176
177//=======================================================================
178//function : IsSolution
179//purpose :
180//=======================================================================
181
182Standard_Boolean BlendFunc_ChamfInv::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
183{
184 gp_Pnt2d p2d;
185 gp_Vec2d v2d;
186 csurf->D1(Sol(1),p2d,v2d);
187
188 math_Vector Sol1(1,2), Sol2(1,2);
189 Standard_Boolean issol;
190
191 Sol1(1) = p2d.X();
192 Sol1(2) = p2d.Y();
193
194 Sol2(1) = Sol(3);
195 Sol2(2) = Sol(4);
196
197 if( first ){
198 issol = corde1.IsSolution(Sol1,Tol);
199 issol = issol && corde2.IsSolution(Sol2,Tol);
200 }
201 else{
202 issol = corde1.IsSolution(Sol2,Tol);
203 issol = issol && corde2.IsSolution(Sol1,Tol);
204 }
205
206 return issol;
207
208}
209
210
211//=======================================================================
212//function : Value
213//purpose :
214//=======================================================================
215
216Standard_Boolean BlendFunc_ChamfInv::Value(const math_Vector& X, math_Vector& F)
217{
218 gp_Pnt2d p2d;
219 gp_Vec2d v2d;
220 csurf->D1(X(1),p2d,v2d);
221 corde1.SetParam(X(2));
222 corde2.SetParam(X(2));
223
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);
227
228 if(first){
229 corde1.Value(x1,f1);
230 corde2.Value(x2,f2);
231 }
232
233 else{
234 corde1.Value(x2,f1);
235 corde2.Value(x1,f2);
236 }
237 F(1) = f1(1);
238 F(2) = f1(2);
239 F(3) = f2(1);
240 F(4) = f2(2);
241
242 return Standard_True;
243}
244
245//=======================================================================
246//function : Derivatives
247//purpose :
248//=======================================================================
249
250Standard_Boolean BlendFunc_ChamfInv::Derivatives(const math_Vector& X, math_Matrix& D)
251{
252 Standard_Integer i, j;
253 gp_Pnt2d p2d;
254 gp_Vec2d v2d, df1, df2;
255 gp_Pnt pts, ptgui;
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);
259
260 csurf->D1(X(1),p2d,v2d);
261 corde1.SetParam(X(2));
262 corde2.SetParam(X(2));
263
264 x1(1) = p2d.X(); x1(2) = p2d.Y();
265 x2(1) = X(3); x2(2) = X(4);
266
267 if( first ){
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);
275 }
276 else{
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);
284 }
285
286// derivees par rapport a T
287 temp.SetLinearForm(v2d.X(),d1u,v2d.Y(),d1v);
288 if( first ){
289 D(1,1) = nplan.Dot(temp);
290 D(2,1) = 2*(gp_Vec(ptgui,pts).Dot(temp));
291 D(3,1) = 0.;
292 D(4,1) = 0.;
293 }
294 else{
295 D(1,1) = 0.;
296 D(2,1) = 0.;
297 D(3,1) = nplan.Dot(temp);
298 D(4,1) = 2*(gp_Vec(ptgui,pts).Dot(temp));
299 }
300
301// derivees par rapport a W
302 D(1,2) = df1.X();
303 D(2,2) = df1.Y();
304 D(3,2) = df2.X();
305 D(4,2) = df2.Y();
306
307// derivees par rapport a U et V
308 if( first ){
309 for( i=1; i<3; i++ ){
310 for( j=3; j<5; j++ ){
311 D(i,j) = 0.;
312 D(i+2,j) = d2(i,j-2);
313 }
314 }
315 }
316 else{
317 for( i=1; i<3; i++ ){
318 for( j=3; j<5; j++ ){
319 D(i,j) = d1(i,j-2);
320 D(i+2,j) = 0.;
321 }
322 }
323 }
324
325 return Standard_True;
326}
327
328//=======================================================================
329//function : Values
330//purpose :
331//=======================================================================
332
333Standard_Boolean BlendFunc_ChamfInv::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
334{
335 Value(X,F);
336 Derivatives(X,D);
337 return Standard_True;
338}