0024510: Remove unused local variables
[occt.git] / src / BlendFunc / BlendFunc_Chamfer.cxx
CommitLineData
b311480e 1// Created on: 1996-06-05
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//
973c2be1 8// This library is free software; you can redistribute it and / or modify it
9// under the terms of the GNU Lesser General Public 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.
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// Modified : 20/08/96 PMN Ajout des methodes (Nb)Intervals et IsRationnal
18// Modified : 30/12/96 PMN Ajout GetMinimalWeight, GetSectionSize;
19
20#include <BlendFunc_Chamfer.ixx>
21
22#include <BlendFunc.hxx>
23#include <ElCLib.hxx>
24#include <Precision.hxx>
25#include <Standard_NotImplemented.hxx>
7fd59977 26
27//=======================================================================
28//function : BlendFunc_Chamfer
29//purpose :
30//=======================================================================
31
32BlendFunc_Chamfer::BlendFunc_Chamfer(const Handle(Adaptor3d_HSurface)& S1,
33 const Handle(Adaptor3d_HSurface)& S2,
34 const Handle(Adaptor3d_HCurve)& CG) :
35 surf1(S1),surf2(S2),
36 curv(CG),
37 distmin(RealLast()),
38 corde1(S1,CG),corde2(S2,CG)
39{
40}
41
42//=======================================================================
43//function : NbEquations
44//purpose :
45//=======================================================================
46
47Standard_Integer BlendFunc_Chamfer::NbEquations () const
48{
49 return 4;
50}
51
52
53//=======================================================================
54//function : Set
55//purpose :
56//=======================================================================
57
58void BlendFunc_Chamfer::Set(const Standard_Real Dist1, const Standard_Real Dist2,
59 const Standard_Integer Choix)
60{
61 corde1.SetDist(Dist1);
62 corde2.SetDist(Dist2);
63 choix = Choix;
64}
65
66//=======================================================================
67//function : Set
68//purpose :
69//=======================================================================
70
71void BlendFunc_Chamfer::Set(const Standard_Real Param)
72{
73 corde1.SetParam(Param);
74 corde2.SetParam(Param);
75}
76
77//=======================================================================
78//function : Set
79//purpose :
80//=======================================================================
81
35e08fe8 82void BlendFunc_Chamfer::Set(const Standard_Real, const Standard_Real)
7fd59977 83{
7fd59977 84}
85
86//=======================================================================
87//function : GetTolerance
88//purpose :
89//=======================================================================
90
91void BlendFunc_Chamfer::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
92{
93 Tolerance(1) = surf1->UResolution(Tol);
94 Tolerance(2) = surf1->VResolution(Tol);
95 Tolerance(3) = surf2->UResolution(Tol);
96 Tolerance(4) = surf2->VResolution(Tol);
97}
98
99//=======================================================================
100//function : GetBounds
101//purpose :
102//=======================================================================
103
104void BlendFunc_Chamfer::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
105{
106 InfBound(1) = surf1->FirstUParameter();
107 InfBound(2) = surf1->FirstVParameter();
108 InfBound(3) = surf2->FirstUParameter();
109 InfBound(4) = surf2->FirstVParameter();
110 SupBound(1) = surf1->LastUParameter();
111 SupBound(2) = surf1->LastVParameter();
112 SupBound(3) = surf2->LastUParameter();
113 SupBound(4) = surf2->LastVParameter();
114
115 for(Standard_Integer i = 1; i <= 4; i++){
116 if(!Precision::IsInfinite(InfBound(i)) &&
117 !Precision::IsInfinite(SupBound(i))) {
118 const Standard_Real range = (SupBound(i) - InfBound(i));
119 InfBound(i) -= range;
120 SupBound(i) += range;
121 }
122 }
123}
124
125//=======================================================================
126//function : IsSolution
127//purpose :
128//=======================================================================
129
130Standard_Boolean BlendFunc_Chamfer::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
131{
132 math_Vector Sol1(1,2), Sol2(1,2);
133
134 Sol1(1) = Sol(1);
135 Sol1(2) = Sol(2);
136 Sol2(1) = Sol(3);
137 Sol2(2) = Sol(4);
138
139 Standard_Boolean issol = corde1.IsSolution(Sol1,Tol);
140 issol = issol && corde2.IsSolution(Sol2,Tol);
141 tol = Tol;
142 if (issol)
143 distmin = Min (distmin, corde1.PointOnS().Distance(corde2.PointOnS()));
144
145 return issol;
146}
147
148//=======================================================================
149//function : GetMinimalDistance
150//purpose :
151//=======================================================================
152
153Standard_Real BlendFunc_Chamfer::GetMinimalDistance() const
154{
155 return distmin;
156}
157
158//=======================================================================
159//function : Value
160//purpose :
161//=======================================================================
162
163Standard_Boolean BlendFunc_Chamfer::Value(const math_Vector& X, math_Vector& F)
164{
165 math_Vector x(1,2), f(1,2);
166
167 x(1) = X(1); x(2) = X(2);
168 corde1.Value(x,f);
169 F(1) = f(1); F(2) = f(2);
170
171 x(1) = X(3); x(2) = X(4);
172 corde2.Value(x,f);
173 F(3) = f(1); F(4) = f(2);
174
175 return Standard_True;
176}
177
178
179//=======================================================================
180//function : Derivatives
181//purpose :
182//=======================================================================
183
184Standard_Boolean BlendFunc_Chamfer::Derivatives(const math_Vector& X, math_Matrix& D)
185{
186 Standard_Integer i,j;
187 math_Vector x(1,2);
188 math_Matrix d(1,2,1,2);
189
190 x(1) = X(1); x(2) = X(2);
191 corde1.Derivatives(x,d);
192 for( i=1; i<3; i++ ){
193 for( j=1; j<3; j++ ){
194 D(i,j) = d(i,j);
195 D(i,j+2) = 0.;
196 }
197 }
198
199 x(1) = X(3); x(2) = X(4);
200 corde2.Derivatives(x,d);
201 for( i=1; i<3; i++ ){
202 for( j=1; j<3; j++ ){
203 D(i+2,j+2) = d(i,j);
204 D(i+2,j) = 0.;
205 }
206 }
207
208 return Standard_True;
209}
210
211//=======================================================================
212//function : Values
213//purpose :
214//=======================================================================
215
216Standard_Boolean BlendFunc_Chamfer::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
217{
218 Standard_Boolean val = Value(X,F);
219 return (val && Derivatives(X,D));
220}
221
222//=======================================================================
223//function : PointOnS1
224//purpose :
225//=======================================================================
226
227const gp_Pnt& BlendFunc_Chamfer::PointOnS1 () const
228{
229 return corde1.PointOnS();
230}
231
232//=======================================================================
233//function : PointOnS2
234//purpose :
235//=======================================================================
236
237const gp_Pnt& BlendFunc_Chamfer::PointOnS2 () const
238{
239 return corde2.PointOnS();
240}
241
242
243//=======================================================================
244//function : IsTangencyPoint
245//purpose :
246//=======================================================================
247
248Standard_Boolean BlendFunc_Chamfer::IsTangencyPoint () const
249{
250 return corde1.IsTangencyPoint() && corde2.IsTangencyPoint();
251}
252
253//=======================================================================
254//function : TangentOnS1
255//purpose :
256//=======================================================================
257
258const gp_Vec& BlendFunc_Chamfer::TangentOnS1 () const
259{
260 return corde1.TangentOnS();
261}
262
263//=======================================================================
264//function : TangentOnS2
265//purpose :
266//=======================================================================
267
268const gp_Vec& BlendFunc_Chamfer::TangentOnS2 () const
269{
270 return corde2.TangentOnS();
271}
272
273//=======================================================================
274//function : Tangent2dOnS1
275//purpose :
276//=======================================================================
277
278const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS1 () const
279{
280 return corde1.Tangent2dOnS();
281}
282
283//=======================================================================
284//function : Tangent2dOnS2
285//purpose :
286//=======================================================================
287
288const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS2 () const
289{
290 return corde2.Tangent2dOnS();
291}
292
293//=======================================================================
294//function : Tangent
295//purpose : TgF,NmF et TgL,NmL les tangentes et normales respectives
296// aux surfaces S1 et S2
297//=======================================================================
298
299void BlendFunc_Chamfer::Tangent(const Standard_Real U1,
300 const Standard_Real V1,
301 const Standard_Real U2,
302 const Standard_Real V2,
303 gp_Vec& TgF,
304 gp_Vec& TgL,
305 gp_Vec& NmF,
306 gp_Vec& NmL) const
307{
308 gp_Pnt pt1,pt2,ptgui;
309 gp_Vec d1u1,d1v1,d1u2,d1v2;
310 gp_Vec nplan;
311 Standard_Boolean revF = Standard_False;
312 Standard_Boolean revL = Standard_False;
313
314 ptgui = corde1.PointOnGuide();
315 nplan = corde1.NPlan();
316 surf1->D1(U1,V1,pt1,d1u1,d1v1);
317 NmF = d1u1.Crossed(d1v1);
318
319 surf2->D1(U2,V2,pt2,d1u2,d1v2);
320 NmL = d1u2.Crossed(d1v2);
321
322 TgF = (nplan.Crossed(NmF)).Normalized();
323 TgL = (nplan.Crossed(NmL)).Normalized();
324
325 if( (choix == 2)||(choix == 5) ){
326 revF = Standard_True;
327 revL = Standard_True;
328 }
329 if( (choix == 4)||(choix == 7) )
330 revL = Standard_True;
331 if( (choix == 3)||(choix == 8) )
332 revF = Standard_True;
333
334 if( revF )
335 TgF.Reverse();
336 if( revL )
337 TgL.Reverse();
338}
339
340//=======================================================================
341//function : Section
342//purpose :
343//=======================================================================
344
35e08fe8 345void BlendFunc_Chamfer::Section(const Standard_Real /*Param*/,
7fd59977 346 const Standard_Real U1,
347 const Standard_Real V1,
348 const Standard_Real U2,
349 const Standard_Real V2,
350 Standard_Real& Pdeb,
351 Standard_Real& Pfin,
352 gp_Lin& C)
353{
354 const gp_Pnt pts1 = surf1->Value(U1,V1);
355 const gp_Pnt pts2 = surf2->Value(U2,V2);
356 const gp_Dir dir( gp_Vec(pts1,pts2) );
357
358 C.SetLocation(pts1);
359 C.SetDirection(dir);
360
361 Pdeb = 0.;
362 Pfin = ElCLib::Parameter(C,pts2);
363}
364
365//=======================================================================
366//function : IsRational
367//purpose :
368//=======================================================================
369
370Standard_Boolean BlendFunc_Chamfer::IsRational() const
371{
372 return Standard_False;
373}
374
375//=======================================================================
376//function : GetSectionSize
377//purpose : Non implementee (non necessaire car non rationel)
378//=======================================================================
379Standard_Real BlendFunc_Chamfer::GetSectionSize() const
380{
381 Standard_NotImplemented::Raise("BlendFunc_Chamfer::GetSectionSize()");
382 return 0;
383}
384
385//=======================================================================
386//function : GetMinimalWeight
387//purpose :
388//=======================================================================
389void BlendFunc_Chamfer::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
390{
391 Weights.Init(1);
392}
393
394
395//=======================================================================
396//function : NbIntervals
397//purpose :
398//=======================================================================
399
400Standard_Integer BlendFunc_Chamfer::NbIntervals (const GeomAbs_Shape S) const
401{
402 return curv->NbIntervals(BlendFunc::NextShape(S));
403}
404
405
406//=======================================================================
407//function : Intervals
408//purpose :
409//=======================================================================
410
411void BlendFunc_Chamfer::Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
412{
413 curv->Intervals(T, BlendFunc::NextShape(S));
414}
415
416//=======================================================================
417//function : GetShape
418//purpose :
419//=======================================================================
420
421void BlendFunc_Chamfer::GetShape (Standard_Integer& NbPoles,
422 Standard_Integer& NbKnots,
423 Standard_Integer& Degree,
424 Standard_Integer& NbPoles2d)
425{
426 NbPoles = 2;
427 NbPoles2d = 2;
428 NbKnots = 2;
429 Degree = 1;
430}
431
432//=======================================================================
433//function : GetTolerance
434//purpose : Determine les Tolerance a utiliser dans les approximations.
435//=======================================================================
436void BlendFunc_Chamfer::GetTolerance(const Standard_Real BoundTol,
35e08fe8 437 const Standard_Real,
438 const Standard_Real,
7fd59977 439 math_Vector& Tol3d,
35e08fe8 440 math_Vector&) const
7fd59977 441{
442 Tol3d.Init(BoundTol);
443}
444
445//=======================================================================
446//function : Knots
447//purpose :
448//=======================================================================
449
450void BlendFunc_Chamfer::Knots(TColStd_Array1OfReal& TKnots)
451{
452 TKnots(1) = 0.;
453 TKnots(2) = 1.;
454}
455
456
457//=======================================================================
458//function : Mults
459//purpose :
460//=======================================================================
461
462void BlendFunc_Chamfer::Mults(TColStd_Array1OfInteger& TMults)
463{
464 TMults(1) = 2;
465 TMults(2) = 2;
466}
467
468//=======================================================================
469//function : Section
470//purpose :
471//=======================================================================
472
473Standard_Boolean BlendFunc_Chamfer::Section
35e08fe8 474 (const Blend_Point& /*P*/,
475 TColgp_Array1OfPnt& /*Poles*/,
476 TColgp_Array1OfVec& /*DPoles*/,
477 TColgp_Array1OfVec& /*D2Poles*/,
478 TColgp_Array1OfPnt2d& /*Poles2d*/,
479 TColgp_Array1OfVec2d& /*DPoles2d*/,
480 TColgp_Array1OfVec2d& /*D2Poles2d*/,
481 TColStd_Array1OfReal& /*Weights*/,
482 TColStd_Array1OfReal& /*DWeights*/,
483 TColStd_Array1OfReal& /*D2Weights*/)
7fd59977 484{
485 return Standard_False;
486}
487
488//=======================================================================
489//function : Section
490//purpose :
491//=======================================================================
492
493Standard_Boolean BlendFunc_Chamfer::Section
494 (const Blend_Point& P,
495 TColgp_Array1OfPnt& Poles,
496 TColgp_Array1OfVec& DPoles,
497 TColgp_Array1OfPnt2d& Poles2d,
498 TColgp_Array1OfVec2d& DPoles2d,
499 TColStd_Array1OfReal& Weights,
500 TColStd_Array1OfReal& DWeights)
501{
502 math_Vector sol(1,4),valsol(1,4),secmember(1,4);
503 math_Matrix gradsol(1,4,1,4);
504
505 Standard_Real prm = P.Parameter();
506 Standard_Integer low = Poles.Lower();
507 Standard_Integer upp = Poles.Upper();
508 Standard_Boolean istgt;
509
510 P.ParametersOnS1(sol(1),sol(2));
511 P.ParametersOnS2(sol(3),sol(4));
512
513 Set(prm);
514
515 Values(sol,valsol,gradsol);
516 IsSolution(sol,tol);
517
518 istgt = IsTangencyPoint();
519
520 Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2));
521 Poles2d(Poles2d.Upper()).SetCoord(sol(3),sol(4));
522 if (!istgt) {
523 DPoles2d(Poles2d.Lower()).SetCoord(Tangent2dOnS1().X(),
524 Tangent2dOnS1().Y());
525 DPoles2d(Poles2d.Upper()).SetCoord(Tangent2dOnS2().X(),
526 Tangent2dOnS2().Y());
527 }
528 Poles(low) = PointOnS1();
529 Poles(upp) = PointOnS2();
530 Weights(low) = 1.0;
531 Weights(upp) = 1.0;
532 if (!istgt) {
533 DPoles(low) = TangentOnS1();
534 DPoles(upp) = TangentOnS2();
535 DWeights(low) = 0.0;
536 DWeights(upp) = 0.0;
537 }
538
539 return (!istgt);
540}
541
542//=======================================================================
543//function : Section
544//purpose :
545//=======================================================================
546
547void BlendFunc_Chamfer::Section(const Blend_Point& P,
548 TColgp_Array1OfPnt& Poles,
549 TColgp_Array1OfPnt2d& Poles2d,
550 TColStd_Array1OfReal& Weights)
551{
552 Standard_Real u1,v1,u2,v2,prm = P.Parameter();
553 Standard_Integer low = Poles.Lower();
554 Standard_Integer upp = Poles.Upper();
555 math_Vector X(1,4), F(1,4);
556
557 P.ParametersOnS1(u1,v1);
558 P.ParametersOnS2(u2,v2);
559 X(1)=u1;
560 X(2)=v1;
561 X(3)=u2;
562 X(4)=v2;
563 Poles2d(Poles2d.Lower()).SetCoord(u1,v1);
564 Poles2d(Poles2d.Upper()).SetCoord(u2,v2);
565
566 Set(prm);
567 Value(X,F);
568 Poles(low) = PointOnS1();
569 Poles(upp) = PointOnS2();
570 Weights(low) = 1.0;
571 Weights(upp) = 1.0;
572}
573
574void BlendFunc_Chamfer::Resolution(const Standard_Integer IC2d, const Standard_Real Tol,
575 Standard_Real& TolU, Standard_Real& TolV) const
576{
577 if(IC2d == 1){
578 TolU = surf1->UResolution(Tol);
579 TolV = surf1->VResolution(Tol);
580 }
581 else {
582 TolU = surf2->UResolution(Tol);
583 TolV = surf2->VResolution(Tol);
584 }
585}