1 // File: BlendFunc_Chamfer.cxx
2 // Created: Wed Jun 5 09:41:42 1996
3 // Author: Stagiaire Xuan Trang PHAMPHU
4 // Copyright: OPEN CASCADE 1996
6 // Modified : 20/08/96 PMN Ajout des methodes (Nb)Intervals et IsRationnal
7 // Modified : 30/12/96 PMN Ajout GetMinimalWeight, GetSectionSize;
9 #include <BlendFunc_Chamfer.ixx>
11 #include <BlendFunc.hxx>
13 #include <Precision.hxx>
14 #include <Standard_NotImplemented.hxx>
16 static Standard_Boolean putsderivatives = 0;
19 //=======================================================================
20 //function : BlendFunc_Chamfer
22 //=======================================================================
24 BlendFunc_Chamfer::BlendFunc_Chamfer(const Handle(Adaptor3d_HSurface)& S1,
25 const Handle(Adaptor3d_HSurface)& S2,
26 const Handle(Adaptor3d_HCurve)& CG) :
30 corde1(S1,CG),corde2(S2,CG)
34 //=======================================================================
35 //function : NbEquations
37 //=======================================================================
39 Standard_Integer BlendFunc_Chamfer::NbEquations () const
45 //=======================================================================
48 //=======================================================================
50 void BlendFunc_Chamfer::Set(const Standard_Real Dist1, const Standard_Real Dist2,
51 const Standard_Integer Choix)
53 corde1.SetDist(Dist1);
54 corde2.SetDist(Dist2);
58 //=======================================================================
61 //=======================================================================
63 void BlendFunc_Chamfer::Set(const Standard_Real Param)
65 corde1.SetParam(Param);
66 corde2.SetParam(Param);
69 //=======================================================================
72 //=======================================================================
74 void BlendFunc_Chamfer::Set(const Standard_Real First, const Standard_Real Last)
76 // corde1.SetParam(First, Last);
77 // corde2.SetParam(First, Last);
80 //=======================================================================
81 //function : GetTolerance
83 //=======================================================================
85 void BlendFunc_Chamfer::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
87 Tolerance(1) = surf1->UResolution(Tol);
88 Tolerance(2) = surf1->VResolution(Tol);
89 Tolerance(3) = surf2->UResolution(Tol);
90 Tolerance(4) = surf2->VResolution(Tol);
93 //=======================================================================
94 //function : GetBounds
96 //=======================================================================
98 void BlendFunc_Chamfer::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
100 InfBound(1) = surf1->FirstUParameter();
101 InfBound(2) = surf1->FirstVParameter();
102 InfBound(3) = surf2->FirstUParameter();
103 InfBound(4) = surf2->FirstVParameter();
104 SupBound(1) = surf1->LastUParameter();
105 SupBound(2) = surf1->LastVParameter();
106 SupBound(3) = surf2->LastUParameter();
107 SupBound(4) = surf2->LastVParameter();
109 for(Standard_Integer i = 1; i <= 4; i++){
110 if(!Precision::IsInfinite(InfBound(i)) &&
111 !Precision::IsInfinite(SupBound(i))) {
112 const Standard_Real range = (SupBound(i) - InfBound(i));
113 InfBound(i) -= range;
114 SupBound(i) += range;
119 //=======================================================================
120 //function : IsSolution
122 //=======================================================================
124 Standard_Boolean BlendFunc_Chamfer::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
126 math_Vector Sol1(1,2), Sol2(1,2);
133 Standard_Boolean issol = corde1.IsSolution(Sol1,Tol);
134 issol = issol && corde2.IsSolution(Sol2,Tol);
137 distmin = Min (distmin, corde1.PointOnS().Distance(corde2.PointOnS()));
142 //=======================================================================
143 //function : GetMinimalDistance
145 //=======================================================================
147 Standard_Real BlendFunc_Chamfer::GetMinimalDistance() const
152 //=======================================================================
155 //=======================================================================
157 Standard_Boolean BlendFunc_Chamfer::Value(const math_Vector& X, math_Vector& F)
159 math_Vector x(1,2), f(1,2);
161 x(1) = X(1); x(2) = X(2);
163 F(1) = f(1); F(2) = f(2);
165 x(1) = X(3); x(2) = X(4);
167 F(3) = f(1); F(4) = f(2);
169 return Standard_True;
173 //=======================================================================
174 //function : Derivatives
176 //=======================================================================
178 Standard_Boolean BlendFunc_Chamfer::Derivatives(const math_Vector& X, math_Matrix& D)
180 Standard_Integer i,j;
182 math_Matrix d(1,2,1,2);
184 x(1) = X(1); x(2) = X(2);
185 corde1.Derivatives(x,d);
186 for( i=1; i<3; i++ ){
187 for( j=1; j<3; j++ ){
193 x(1) = X(3); x(2) = X(4);
194 corde2.Derivatives(x,d);
195 for( i=1; i<3; i++ ){
196 for( j=1; j<3; j++ ){
202 return Standard_True;
205 //=======================================================================
208 //=======================================================================
210 Standard_Boolean BlendFunc_Chamfer::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
212 Standard_Boolean val = Value(X,F);
213 return (val && Derivatives(X,D));
216 //=======================================================================
217 //function : PointOnS1
219 //=======================================================================
221 const gp_Pnt& BlendFunc_Chamfer::PointOnS1 () const
223 return corde1.PointOnS();
226 //=======================================================================
227 //function : PointOnS2
229 //=======================================================================
231 const gp_Pnt& BlendFunc_Chamfer::PointOnS2 () const
233 return corde2.PointOnS();
237 //=======================================================================
238 //function : IsTangencyPoint
240 //=======================================================================
242 Standard_Boolean BlendFunc_Chamfer::IsTangencyPoint () const
244 return corde1.IsTangencyPoint() && corde2.IsTangencyPoint();
247 //=======================================================================
248 //function : TangentOnS1
250 //=======================================================================
252 const gp_Vec& BlendFunc_Chamfer::TangentOnS1 () const
254 return corde1.TangentOnS();
257 //=======================================================================
258 //function : TangentOnS2
260 //=======================================================================
262 const gp_Vec& BlendFunc_Chamfer::TangentOnS2 () const
264 return corde2.TangentOnS();
267 //=======================================================================
268 //function : Tangent2dOnS1
270 //=======================================================================
272 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS1 () const
274 return corde1.Tangent2dOnS();
277 //=======================================================================
278 //function : Tangent2dOnS2
280 //=======================================================================
282 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS2 () const
284 return corde2.Tangent2dOnS();
287 //=======================================================================
289 //purpose : TgF,NmF et TgL,NmL les tangentes et normales respectives
290 // aux surfaces S1 et S2
291 //=======================================================================
293 void BlendFunc_Chamfer::Tangent(const Standard_Real U1,
294 const Standard_Real V1,
295 const Standard_Real U2,
296 const Standard_Real V2,
302 gp_Pnt pt1,pt2,ptgui;
303 gp_Vec d1u1,d1v1,d1u2,d1v2;
305 Standard_Boolean revF = Standard_False;
306 Standard_Boolean revL = Standard_False;
308 ptgui = corde1.PointOnGuide();
309 nplan = corde1.NPlan();
310 surf1->D1(U1,V1,pt1,d1u1,d1v1);
311 NmF = d1u1.Crossed(d1v1);
313 surf2->D1(U2,V2,pt2,d1u2,d1v2);
314 NmL = d1u2.Crossed(d1v2);
316 TgF = (nplan.Crossed(NmF)).Normalized();
317 TgL = (nplan.Crossed(NmL)).Normalized();
319 if( (choix == 2)||(choix == 5) ){
320 revF = Standard_True;
321 revL = Standard_True;
323 if( (choix == 4)||(choix == 7) )
324 revL = Standard_True;
325 if( (choix == 3)||(choix == 8) )
326 revF = Standard_True;
334 //=======================================================================
337 //=======================================================================
339 void BlendFunc_Chamfer::Section(const Standard_Real Param,
340 const Standard_Real U1,
341 const Standard_Real V1,
342 const Standard_Real U2,
343 const Standard_Real V2,
348 const gp_Pnt pts1 = surf1->Value(U1,V1);
349 const gp_Pnt pts2 = surf2->Value(U2,V2);
350 const gp_Dir dir( gp_Vec(pts1,pts2) );
356 Pfin = ElCLib::Parameter(C,pts2);
359 //=======================================================================
360 //function : IsRational
362 //=======================================================================
364 Standard_Boolean BlendFunc_Chamfer::IsRational() const
366 return Standard_False;
369 //=======================================================================
370 //function : GetSectionSize
371 //purpose : Non implementee (non necessaire car non rationel)
372 //=======================================================================
373 Standard_Real BlendFunc_Chamfer::GetSectionSize() const
375 Standard_NotImplemented::Raise("BlendFunc_Chamfer::GetSectionSize()");
379 //=======================================================================
380 //function : GetMinimalWeight
382 //=======================================================================
383 void BlendFunc_Chamfer::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
389 //=======================================================================
390 //function : NbIntervals
392 //=======================================================================
394 Standard_Integer BlendFunc_Chamfer::NbIntervals (const GeomAbs_Shape S) const
396 return curv->NbIntervals(BlendFunc::NextShape(S));
400 //=======================================================================
401 //function : Intervals
403 //=======================================================================
405 void BlendFunc_Chamfer::Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
407 curv->Intervals(T, BlendFunc::NextShape(S));
410 //=======================================================================
411 //function : GetShape
413 //=======================================================================
415 void BlendFunc_Chamfer::GetShape (Standard_Integer& NbPoles,
416 Standard_Integer& NbKnots,
417 Standard_Integer& Degree,
418 Standard_Integer& NbPoles2d)
426 //=======================================================================
427 //function : GetTolerance
428 //purpose : Determine les Tolerance a utiliser dans les approximations.
429 //=======================================================================
430 void BlendFunc_Chamfer::GetTolerance(const Standard_Real BoundTol,
431 const Standard_Real SurfTol,
432 const Standard_Real AngleTol,
434 math_Vector& Tol1D) const
436 Tol3d.Init(BoundTol);
439 //=======================================================================
442 //=======================================================================
444 void BlendFunc_Chamfer::Knots(TColStd_Array1OfReal& TKnots)
451 //=======================================================================
454 //=======================================================================
456 void BlendFunc_Chamfer::Mults(TColStd_Array1OfInteger& TMults)
462 //=======================================================================
465 //=======================================================================
467 Standard_Boolean BlendFunc_Chamfer::Section
468 (const Blend_Point& P,
469 TColgp_Array1OfPnt& Poles,
470 TColgp_Array1OfVec& DPoles,
471 TColgp_Array1OfVec& D2Poles,
472 TColgp_Array1OfPnt2d& Poles2d,
473 TColgp_Array1OfVec2d& DPoles2d,
474 TColgp_Array1OfVec2d& D2Poles2d,
475 TColStd_Array1OfReal& Weights,
476 TColStd_Array1OfReal& DWeights,
477 TColStd_Array1OfReal& D2Weights)
479 return Standard_False;
482 //=======================================================================
485 //=======================================================================
487 Standard_Boolean BlendFunc_Chamfer::Section
488 (const Blend_Point& P,
489 TColgp_Array1OfPnt& Poles,
490 TColgp_Array1OfVec& DPoles,
491 TColgp_Array1OfPnt2d& Poles2d,
492 TColgp_Array1OfVec2d& DPoles2d,
493 TColStd_Array1OfReal& Weights,
494 TColStd_Array1OfReal& DWeights)
496 math_Vector sol(1,4),valsol(1,4),secmember(1,4);
497 math_Matrix gradsol(1,4,1,4);
499 Standard_Real prm = P.Parameter();
500 Standard_Integer low = Poles.Lower();
501 Standard_Integer upp = Poles.Upper();
502 Standard_Boolean istgt;
504 P.ParametersOnS1(sol(1),sol(2));
505 P.ParametersOnS2(sol(3),sol(4));
509 Values(sol,valsol,gradsol);
512 istgt = IsTangencyPoint();
514 Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2));
515 Poles2d(Poles2d.Upper()).SetCoord(sol(3),sol(4));
517 DPoles2d(Poles2d.Lower()).SetCoord(Tangent2dOnS1().X(),
518 Tangent2dOnS1().Y());
519 DPoles2d(Poles2d.Upper()).SetCoord(Tangent2dOnS2().X(),
520 Tangent2dOnS2().Y());
522 Poles(low) = PointOnS1();
523 Poles(upp) = PointOnS2();
527 DPoles(low) = TangentOnS1();
528 DPoles(upp) = TangentOnS2();
536 //=======================================================================
539 //=======================================================================
541 void BlendFunc_Chamfer::Section(const Blend_Point& P,
542 TColgp_Array1OfPnt& Poles,
543 TColgp_Array1OfPnt2d& Poles2d,
544 TColStd_Array1OfReal& Weights)
546 Standard_Real u1,v1,u2,v2,prm = P.Parameter();
547 Standard_Integer low = Poles.Lower();
548 Standard_Integer upp = Poles.Upper();
549 math_Vector X(1,4), F(1,4);
551 P.ParametersOnS1(u1,v1);
552 P.ParametersOnS2(u2,v2);
557 Poles2d(Poles2d.Lower()).SetCoord(u1,v1);
558 Poles2d(Poles2d.Upper()).SetCoord(u2,v2);
562 Poles(low) = PointOnS1();
563 Poles(upp) = PointOnS2();
568 void BlendFunc_Chamfer::Resolution(const Standard_Integer IC2d, const Standard_Real Tol,
569 Standard_Real& TolU, Standard_Real& TolV) const
572 TolU = surf1->UResolution(Tol);
573 TolV = surf1->VResolution(Tol);
576 TolU = surf2->UResolution(Tol);
577 TolV = surf2->VResolution(Tol);