1 // Created on: 1996-06-05
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
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.
14 // Alternatively, this file may be used under the terms of Open CASCADE
15 // commercial license or contractual agreement.
17 // Modified : 20/08/96 PMN Ajout des methodes (Nb)Intervals et IsRationnal
18 // Modified : 30/12/96 PMN Ajout GetMinimalWeight, GetSectionSize;
20 #include <BlendFunc_Chamfer.ixx>
22 #include <BlendFunc.hxx>
24 #include <Precision.hxx>
25 #include <Standard_NotImplemented.hxx>
27 static Standard_Boolean putsderivatives = 0;
30 //=======================================================================
31 //function : BlendFunc_Chamfer
33 //=======================================================================
35 BlendFunc_Chamfer::BlendFunc_Chamfer(const Handle(Adaptor3d_HSurface)& S1,
36 const Handle(Adaptor3d_HSurface)& S2,
37 const Handle(Adaptor3d_HCurve)& CG) :
41 corde1(S1,CG),corde2(S2,CG)
45 //=======================================================================
46 //function : NbEquations
48 //=======================================================================
50 Standard_Integer BlendFunc_Chamfer::NbEquations () const
56 //=======================================================================
59 //=======================================================================
61 void BlendFunc_Chamfer::Set(const Standard_Real Dist1, const Standard_Real Dist2,
62 const Standard_Integer Choix)
64 corde1.SetDist(Dist1);
65 corde2.SetDist(Dist2);
69 //=======================================================================
72 //=======================================================================
74 void BlendFunc_Chamfer::Set(const Standard_Real Param)
76 corde1.SetParam(Param);
77 corde2.SetParam(Param);
80 //=======================================================================
83 //=======================================================================
85 void BlendFunc_Chamfer::Set(const Standard_Real, const Standard_Real)
89 //=======================================================================
90 //function : GetTolerance
92 //=======================================================================
94 void BlendFunc_Chamfer::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
96 Tolerance(1) = surf1->UResolution(Tol);
97 Tolerance(2) = surf1->VResolution(Tol);
98 Tolerance(3) = surf2->UResolution(Tol);
99 Tolerance(4) = surf2->VResolution(Tol);
102 //=======================================================================
103 //function : GetBounds
105 //=======================================================================
107 void BlendFunc_Chamfer::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
109 InfBound(1) = surf1->FirstUParameter();
110 InfBound(2) = surf1->FirstVParameter();
111 InfBound(3) = surf2->FirstUParameter();
112 InfBound(4) = surf2->FirstVParameter();
113 SupBound(1) = surf1->LastUParameter();
114 SupBound(2) = surf1->LastVParameter();
115 SupBound(3) = surf2->LastUParameter();
116 SupBound(4) = surf2->LastVParameter();
118 for(Standard_Integer i = 1; i <= 4; i++){
119 if(!Precision::IsInfinite(InfBound(i)) &&
120 !Precision::IsInfinite(SupBound(i))) {
121 const Standard_Real range = (SupBound(i) - InfBound(i));
122 InfBound(i) -= range;
123 SupBound(i) += range;
128 //=======================================================================
129 //function : IsSolution
131 //=======================================================================
133 Standard_Boolean BlendFunc_Chamfer::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
135 math_Vector Sol1(1,2), Sol2(1,2);
142 Standard_Boolean issol = corde1.IsSolution(Sol1,Tol);
143 issol = issol && corde2.IsSolution(Sol2,Tol);
146 distmin = Min (distmin, corde1.PointOnS().Distance(corde2.PointOnS()));
151 //=======================================================================
152 //function : GetMinimalDistance
154 //=======================================================================
156 Standard_Real BlendFunc_Chamfer::GetMinimalDistance() const
161 //=======================================================================
164 //=======================================================================
166 Standard_Boolean BlendFunc_Chamfer::Value(const math_Vector& X, math_Vector& F)
168 math_Vector x(1,2), f(1,2);
170 x(1) = X(1); x(2) = X(2);
172 F(1) = f(1); F(2) = f(2);
174 x(1) = X(3); x(2) = X(4);
176 F(3) = f(1); F(4) = f(2);
178 return Standard_True;
182 //=======================================================================
183 //function : Derivatives
185 //=======================================================================
187 Standard_Boolean BlendFunc_Chamfer::Derivatives(const math_Vector& X, math_Matrix& D)
189 Standard_Integer i,j;
191 math_Matrix d(1,2,1,2);
193 x(1) = X(1); x(2) = X(2);
194 corde1.Derivatives(x,d);
195 for( i=1; i<3; i++ ){
196 for( j=1; j<3; j++ ){
202 x(1) = X(3); x(2) = X(4);
203 corde2.Derivatives(x,d);
204 for( i=1; i<3; i++ ){
205 for( j=1; j<3; j++ ){
211 return Standard_True;
214 //=======================================================================
217 //=======================================================================
219 Standard_Boolean BlendFunc_Chamfer::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
221 Standard_Boolean val = Value(X,F);
222 return (val && Derivatives(X,D));
225 //=======================================================================
226 //function : PointOnS1
228 //=======================================================================
230 const gp_Pnt& BlendFunc_Chamfer::PointOnS1 () const
232 return corde1.PointOnS();
235 //=======================================================================
236 //function : PointOnS2
238 //=======================================================================
240 const gp_Pnt& BlendFunc_Chamfer::PointOnS2 () const
242 return corde2.PointOnS();
246 //=======================================================================
247 //function : IsTangencyPoint
249 //=======================================================================
251 Standard_Boolean BlendFunc_Chamfer::IsTangencyPoint () const
253 return corde1.IsTangencyPoint() && corde2.IsTangencyPoint();
256 //=======================================================================
257 //function : TangentOnS1
259 //=======================================================================
261 const gp_Vec& BlendFunc_Chamfer::TangentOnS1 () const
263 return corde1.TangentOnS();
266 //=======================================================================
267 //function : TangentOnS2
269 //=======================================================================
271 const gp_Vec& BlendFunc_Chamfer::TangentOnS2 () const
273 return corde2.TangentOnS();
276 //=======================================================================
277 //function : Tangent2dOnS1
279 //=======================================================================
281 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS1 () const
283 return corde1.Tangent2dOnS();
286 //=======================================================================
287 //function : Tangent2dOnS2
289 //=======================================================================
291 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS2 () const
293 return corde2.Tangent2dOnS();
296 //=======================================================================
298 //purpose : TgF,NmF et TgL,NmL les tangentes et normales respectives
299 // aux surfaces S1 et S2
300 //=======================================================================
302 void BlendFunc_Chamfer::Tangent(const Standard_Real U1,
303 const Standard_Real V1,
304 const Standard_Real U2,
305 const Standard_Real V2,
311 gp_Pnt pt1,pt2,ptgui;
312 gp_Vec d1u1,d1v1,d1u2,d1v2;
314 Standard_Boolean revF = Standard_False;
315 Standard_Boolean revL = Standard_False;
317 ptgui = corde1.PointOnGuide();
318 nplan = corde1.NPlan();
319 surf1->D1(U1,V1,pt1,d1u1,d1v1);
320 NmF = d1u1.Crossed(d1v1);
322 surf2->D1(U2,V2,pt2,d1u2,d1v2);
323 NmL = d1u2.Crossed(d1v2);
325 TgF = (nplan.Crossed(NmF)).Normalized();
326 TgL = (nplan.Crossed(NmL)).Normalized();
328 if( (choix == 2)||(choix == 5) ){
329 revF = Standard_True;
330 revL = Standard_True;
332 if( (choix == 4)||(choix == 7) )
333 revL = Standard_True;
334 if( (choix == 3)||(choix == 8) )
335 revF = Standard_True;
343 //=======================================================================
346 //=======================================================================
348 void BlendFunc_Chamfer::Section(const Standard_Real /*Param*/,
349 const Standard_Real U1,
350 const Standard_Real V1,
351 const Standard_Real U2,
352 const Standard_Real V2,
357 const gp_Pnt pts1 = surf1->Value(U1,V1);
358 const gp_Pnt pts2 = surf2->Value(U2,V2);
359 const gp_Dir dir( gp_Vec(pts1,pts2) );
365 Pfin = ElCLib::Parameter(C,pts2);
368 //=======================================================================
369 //function : IsRational
371 //=======================================================================
373 Standard_Boolean BlendFunc_Chamfer::IsRational() const
375 return Standard_False;
378 //=======================================================================
379 //function : GetSectionSize
380 //purpose : Non implementee (non necessaire car non rationel)
381 //=======================================================================
382 Standard_Real BlendFunc_Chamfer::GetSectionSize() const
384 Standard_NotImplemented::Raise("BlendFunc_Chamfer::GetSectionSize()");
388 //=======================================================================
389 //function : GetMinimalWeight
391 //=======================================================================
392 void BlendFunc_Chamfer::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
398 //=======================================================================
399 //function : NbIntervals
401 //=======================================================================
403 Standard_Integer BlendFunc_Chamfer::NbIntervals (const GeomAbs_Shape S) const
405 return curv->NbIntervals(BlendFunc::NextShape(S));
409 //=======================================================================
410 //function : Intervals
412 //=======================================================================
414 void BlendFunc_Chamfer::Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
416 curv->Intervals(T, BlendFunc::NextShape(S));
419 //=======================================================================
420 //function : GetShape
422 //=======================================================================
424 void BlendFunc_Chamfer::GetShape (Standard_Integer& NbPoles,
425 Standard_Integer& NbKnots,
426 Standard_Integer& Degree,
427 Standard_Integer& NbPoles2d)
435 //=======================================================================
436 //function : GetTolerance
437 //purpose : Determine les Tolerance a utiliser dans les approximations.
438 //=======================================================================
439 void BlendFunc_Chamfer::GetTolerance(const Standard_Real BoundTol,
445 Tol3d.Init(BoundTol);
448 //=======================================================================
451 //=======================================================================
453 void BlendFunc_Chamfer::Knots(TColStd_Array1OfReal& TKnots)
460 //=======================================================================
463 //=======================================================================
465 void BlendFunc_Chamfer::Mults(TColStd_Array1OfInteger& TMults)
471 //=======================================================================
474 //=======================================================================
476 Standard_Boolean BlendFunc_Chamfer::Section
477 (const Blend_Point& /*P*/,
478 TColgp_Array1OfPnt& /*Poles*/,
479 TColgp_Array1OfVec& /*DPoles*/,
480 TColgp_Array1OfVec& /*D2Poles*/,
481 TColgp_Array1OfPnt2d& /*Poles2d*/,
482 TColgp_Array1OfVec2d& /*DPoles2d*/,
483 TColgp_Array1OfVec2d& /*D2Poles2d*/,
484 TColStd_Array1OfReal& /*Weights*/,
485 TColStd_Array1OfReal& /*DWeights*/,
486 TColStd_Array1OfReal& /*D2Weights*/)
488 return Standard_False;
491 //=======================================================================
494 //=======================================================================
496 Standard_Boolean BlendFunc_Chamfer::Section
497 (const Blend_Point& P,
498 TColgp_Array1OfPnt& Poles,
499 TColgp_Array1OfVec& DPoles,
500 TColgp_Array1OfPnt2d& Poles2d,
501 TColgp_Array1OfVec2d& DPoles2d,
502 TColStd_Array1OfReal& Weights,
503 TColStd_Array1OfReal& DWeights)
505 math_Vector sol(1,4),valsol(1,4),secmember(1,4);
506 math_Matrix gradsol(1,4,1,4);
508 Standard_Real prm = P.Parameter();
509 Standard_Integer low = Poles.Lower();
510 Standard_Integer upp = Poles.Upper();
511 Standard_Boolean istgt;
513 P.ParametersOnS1(sol(1),sol(2));
514 P.ParametersOnS2(sol(3),sol(4));
518 Values(sol,valsol,gradsol);
521 istgt = IsTangencyPoint();
523 Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2));
524 Poles2d(Poles2d.Upper()).SetCoord(sol(3),sol(4));
526 DPoles2d(Poles2d.Lower()).SetCoord(Tangent2dOnS1().X(),
527 Tangent2dOnS1().Y());
528 DPoles2d(Poles2d.Upper()).SetCoord(Tangent2dOnS2().X(),
529 Tangent2dOnS2().Y());
531 Poles(low) = PointOnS1();
532 Poles(upp) = PointOnS2();
536 DPoles(low) = TangentOnS1();
537 DPoles(upp) = TangentOnS2();
545 //=======================================================================
548 //=======================================================================
550 void BlendFunc_Chamfer::Section(const Blend_Point& P,
551 TColgp_Array1OfPnt& Poles,
552 TColgp_Array1OfPnt2d& Poles2d,
553 TColStd_Array1OfReal& Weights)
555 Standard_Real u1,v1,u2,v2,prm = P.Parameter();
556 Standard_Integer low = Poles.Lower();
557 Standard_Integer upp = Poles.Upper();
558 math_Vector X(1,4), F(1,4);
560 P.ParametersOnS1(u1,v1);
561 P.ParametersOnS2(u2,v2);
566 Poles2d(Poles2d.Lower()).SetCoord(u1,v1);
567 Poles2d(Poles2d.Upper()).SetCoord(u2,v2);
571 Poles(low) = PointOnS1();
572 Poles(upp) = PointOnS2();
577 void BlendFunc_Chamfer::Resolution(const Standard_Integer IC2d, const Standard_Real Tol,
578 Standard_Real& TolU, Standard_Real& TolV) const
581 TolU = surf1->UResolution(Tol);
582 TolV = surf1->VResolution(Tol);
585 TolU = surf2->UResolution(Tol);
586 TolV = surf2->VResolution(Tol);