1 // Created on: 1996-06-05
2 // Created by: Stagiaire Xuan Trang PHAMPHU
3 // Copyright (c) 1996-1999 Matra Datavision
4 // Copyright (c) 1999-2012 OPEN CASCADE SAS
6 // The content of this file is subject to the Open CASCADE Technology Public
7 // License Version 6.5 (the "License"). You may not use the content of this file
8 // except in compliance with the License. Please obtain a copy of the License
9 // at http://www.opencascade.org and read it completely before using this file.
11 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 // The Original Code and all software distributed under the License is
15 // distributed on an "AS IS" basis, without warranty of any kind, and the
16 // Initial Developer hereby disclaims all such warranties, including without
17 // limitation, any warranties of merchantability, fitness for a particular
18 // purpose or non-infringement. Please see the License for the specific terms
19 // and conditions governing the rights and limitations under the License.
22 // Modified : 20/08/96 PMN Ajout des methodes (Nb)Intervals et IsRationnal
23 // Modified : 30/12/96 PMN Ajout GetMinimalWeight, GetSectionSize;
25 #include <BlendFunc_Chamfer.ixx>
27 #include <BlendFunc.hxx>
29 #include <Precision.hxx>
30 #include <Standard_NotImplemented.hxx>
32 static Standard_Boolean putsderivatives = 0;
35 //=======================================================================
36 //function : BlendFunc_Chamfer
38 //=======================================================================
40 BlendFunc_Chamfer::BlendFunc_Chamfer(const Handle(Adaptor3d_HSurface)& S1,
41 const Handle(Adaptor3d_HSurface)& S2,
42 const Handle(Adaptor3d_HCurve)& CG) :
46 corde1(S1,CG),corde2(S2,CG)
50 //=======================================================================
51 //function : NbEquations
53 //=======================================================================
55 Standard_Integer BlendFunc_Chamfer::NbEquations () const
61 //=======================================================================
64 //=======================================================================
66 void BlendFunc_Chamfer::Set(const Standard_Real Dist1, const Standard_Real Dist2,
67 const Standard_Integer Choix)
69 corde1.SetDist(Dist1);
70 corde2.SetDist(Dist2);
74 //=======================================================================
77 //=======================================================================
79 void BlendFunc_Chamfer::Set(const Standard_Real Param)
81 corde1.SetParam(Param);
82 corde2.SetParam(Param);
85 //=======================================================================
88 //=======================================================================
90 void BlendFunc_Chamfer::Set(const Standard_Real, const Standard_Real)
94 //=======================================================================
95 //function : GetTolerance
97 //=======================================================================
99 void BlendFunc_Chamfer::GetTolerance(math_Vector& Tolerance, const Standard_Real Tol) const
101 Tolerance(1) = surf1->UResolution(Tol);
102 Tolerance(2) = surf1->VResolution(Tol);
103 Tolerance(3) = surf2->UResolution(Tol);
104 Tolerance(4) = surf2->VResolution(Tol);
107 //=======================================================================
108 //function : GetBounds
110 //=======================================================================
112 void BlendFunc_Chamfer::GetBounds(math_Vector& InfBound, math_Vector& SupBound) const
114 InfBound(1) = surf1->FirstUParameter();
115 InfBound(2) = surf1->FirstVParameter();
116 InfBound(3) = surf2->FirstUParameter();
117 InfBound(4) = surf2->FirstVParameter();
118 SupBound(1) = surf1->LastUParameter();
119 SupBound(2) = surf1->LastVParameter();
120 SupBound(3) = surf2->LastUParameter();
121 SupBound(4) = surf2->LastVParameter();
123 for(Standard_Integer i = 1; i <= 4; i++){
124 if(!Precision::IsInfinite(InfBound(i)) &&
125 !Precision::IsInfinite(SupBound(i))) {
126 const Standard_Real range = (SupBound(i) - InfBound(i));
127 InfBound(i) -= range;
128 SupBound(i) += range;
133 //=======================================================================
134 //function : IsSolution
136 //=======================================================================
138 Standard_Boolean BlendFunc_Chamfer::IsSolution(const math_Vector& Sol, const Standard_Real Tol)
140 math_Vector Sol1(1,2), Sol2(1,2);
147 Standard_Boolean issol = corde1.IsSolution(Sol1,Tol);
148 issol = issol && corde2.IsSolution(Sol2,Tol);
151 distmin = Min (distmin, corde1.PointOnS().Distance(corde2.PointOnS()));
156 //=======================================================================
157 //function : GetMinimalDistance
159 //=======================================================================
161 Standard_Real BlendFunc_Chamfer::GetMinimalDistance() const
166 //=======================================================================
169 //=======================================================================
171 Standard_Boolean BlendFunc_Chamfer::Value(const math_Vector& X, math_Vector& F)
173 math_Vector x(1,2), f(1,2);
175 x(1) = X(1); x(2) = X(2);
177 F(1) = f(1); F(2) = f(2);
179 x(1) = X(3); x(2) = X(4);
181 F(3) = f(1); F(4) = f(2);
183 return Standard_True;
187 //=======================================================================
188 //function : Derivatives
190 //=======================================================================
192 Standard_Boolean BlendFunc_Chamfer::Derivatives(const math_Vector& X, math_Matrix& D)
194 Standard_Integer i,j;
196 math_Matrix d(1,2,1,2);
198 x(1) = X(1); x(2) = X(2);
199 corde1.Derivatives(x,d);
200 for( i=1; i<3; i++ ){
201 for( j=1; j<3; j++ ){
207 x(1) = X(3); x(2) = X(4);
208 corde2.Derivatives(x,d);
209 for( i=1; i<3; i++ ){
210 for( j=1; j<3; j++ ){
216 return Standard_True;
219 //=======================================================================
222 //=======================================================================
224 Standard_Boolean BlendFunc_Chamfer::Values(const math_Vector& X, math_Vector& F, math_Matrix& D)
226 Standard_Boolean val = Value(X,F);
227 return (val && Derivatives(X,D));
230 //=======================================================================
231 //function : PointOnS1
233 //=======================================================================
235 const gp_Pnt& BlendFunc_Chamfer::PointOnS1 () const
237 return corde1.PointOnS();
240 //=======================================================================
241 //function : PointOnS2
243 //=======================================================================
245 const gp_Pnt& BlendFunc_Chamfer::PointOnS2 () const
247 return corde2.PointOnS();
251 //=======================================================================
252 //function : IsTangencyPoint
254 //=======================================================================
256 Standard_Boolean BlendFunc_Chamfer::IsTangencyPoint () const
258 return corde1.IsTangencyPoint() && corde2.IsTangencyPoint();
261 //=======================================================================
262 //function : TangentOnS1
264 //=======================================================================
266 const gp_Vec& BlendFunc_Chamfer::TangentOnS1 () const
268 return corde1.TangentOnS();
271 //=======================================================================
272 //function : TangentOnS2
274 //=======================================================================
276 const gp_Vec& BlendFunc_Chamfer::TangentOnS2 () const
278 return corde2.TangentOnS();
281 //=======================================================================
282 //function : Tangent2dOnS1
284 //=======================================================================
286 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS1 () const
288 return corde1.Tangent2dOnS();
291 //=======================================================================
292 //function : Tangent2dOnS2
294 //=======================================================================
296 const gp_Vec2d& BlendFunc_Chamfer::Tangent2dOnS2 () const
298 return corde2.Tangent2dOnS();
301 //=======================================================================
303 //purpose : TgF,NmF et TgL,NmL les tangentes et normales respectives
304 // aux surfaces S1 et S2
305 //=======================================================================
307 void BlendFunc_Chamfer::Tangent(const Standard_Real U1,
308 const Standard_Real V1,
309 const Standard_Real U2,
310 const Standard_Real V2,
316 gp_Pnt pt1,pt2,ptgui;
317 gp_Vec d1u1,d1v1,d1u2,d1v2;
319 Standard_Boolean revF = Standard_False;
320 Standard_Boolean revL = Standard_False;
322 ptgui = corde1.PointOnGuide();
323 nplan = corde1.NPlan();
324 surf1->D1(U1,V1,pt1,d1u1,d1v1);
325 NmF = d1u1.Crossed(d1v1);
327 surf2->D1(U2,V2,pt2,d1u2,d1v2);
328 NmL = d1u2.Crossed(d1v2);
330 TgF = (nplan.Crossed(NmF)).Normalized();
331 TgL = (nplan.Crossed(NmL)).Normalized();
333 if( (choix == 2)||(choix == 5) ){
334 revF = Standard_True;
335 revL = Standard_True;
337 if( (choix == 4)||(choix == 7) )
338 revL = Standard_True;
339 if( (choix == 3)||(choix == 8) )
340 revF = Standard_True;
348 //=======================================================================
351 //=======================================================================
353 void BlendFunc_Chamfer::Section(const Standard_Real /*Param*/,
354 const Standard_Real U1,
355 const Standard_Real V1,
356 const Standard_Real U2,
357 const Standard_Real V2,
362 const gp_Pnt pts1 = surf1->Value(U1,V1);
363 const gp_Pnt pts2 = surf2->Value(U2,V2);
364 const gp_Dir dir( gp_Vec(pts1,pts2) );
370 Pfin = ElCLib::Parameter(C,pts2);
373 //=======================================================================
374 //function : IsRational
376 //=======================================================================
378 Standard_Boolean BlendFunc_Chamfer::IsRational() const
380 return Standard_False;
383 //=======================================================================
384 //function : GetSectionSize
385 //purpose : Non implementee (non necessaire car non rationel)
386 //=======================================================================
387 Standard_Real BlendFunc_Chamfer::GetSectionSize() const
389 Standard_NotImplemented::Raise("BlendFunc_Chamfer::GetSectionSize()");
393 //=======================================================================
394 //function : GetMinimalWeight
396 //=======================================================================
397 void BlendFunc_Chamfer::GetMinimalWeight(TColStd_Array1OfReal& Weights) const
403 //=======================================================================
404 //function : NbIntervals
406 //=======================================================================
408 Standard_Integer BlendFunc_Chamfer::NbIntervals (const GeomAbs_Shape S) const
410 return curv->NbIntervals(BlendFunc::NextShape(S));
414 //=======================================================================
415 //function : Intervals
417 //=======================================================================
419 void BlendFunc_Chamfer::Intervals (TColStd_Array1OfReal& T, const GeomAbs_Shape S) const
421 curv->Intervals(T, BlendFunc::NextShape(S));
424 //=======================================================================
425 //function : GetShape
427 //=======================================================================
429 void BlendFunc_Chamfer::GetShape (Standard_Integer& NbPoles,
430 Standard_Integer& NbKnots,
431 Standard_Integer& Degree,
432 Standard_Integer& NbPoles2d)
440 //=======================================================================
441 //function : GetTolerance
442 //purpose : Determine les Tolerance a utiliser dans les approximations.
443 //=======================================================================
444 void BlendFunc_Chamfer::GetTolerance(const Standard_Real BoundTol,
450 Tol3d.Init(BoundTol);
453 //=======================================================================
456 //=======================================================================
458 void BlendFunc_Chamfer::Knots(TColStd_Array1OfReal& TKnots)
465 //=======================================================================
468 //=======================================================================
470 void BlendFunc_Chamfer::Mults(TColStd_Array1OfInteger& TMults)
476 //=======================================================================
479 //=======================================================================
481 Standard_Boolean BlendFunc_Chamfer::Section
482 (const Blend_Point& /*P*/,
483 TColgp_Array1OfPnt& /*Poles*/,
484 TColgp_Array1OfVec& /*DPoles*/,
485 TColgp_Array1OfVec& /*D2Poles*/,
486 TColgp_Array1OfPnt2d& /*Poles2d*/,
487 TColgp_Array1OfVec2d& /*DPoles2d*/,
488 TColgp_Array1OfVec2d& /*D2Poles2d*/,
489 TColStd_Array1OfReal& /*Weights*/,
490 TColStd_Array1OfReal& /*DWeights*/,
491 TColStd_Array1OfReal& /*D2Weights*/)
493 return Standard_False;
496 //=======================================================================
499 //=======================================================================
501 Standard_Boolean BlendFunc_Chamfer::Section
502 (const Blend_Point& P,
503 TColgp_Array1OfPnt& Poles,
504 TColgp_Array1OfVec& DPoles,
505 TColgp_Array1OfPnt2d& Poles2d,
506 TColgp_Array1OfVec2d& DPoles2d,
507 TColStd_Array1OfReal& Weights,
508 TColStd_Array1OfReal& DWeights)
510 math_Vector sol(1,4),valsol(1,4),secmember(1,4);
511 math_Matrix gradsol(1,4,1,4);
513 Standard_Real prm = P.Parameter();
514 Standard_Integer low = Poles.Lower();
515 Standard_Integer upp = Poles.Upper();
516 Standard_Boolean istgt;
518 P.ParametersOnS1(sol(1),sol(2));
519 P.ParametersOnS2(sol(3),sol(4));
523 Values(sol,valsol,gradsol);
526 istgt = IsTangencyPoint();
528 Poles2d(Poles2d.Lower()).SetCoord(sol(1),sol(2));
529 Poles2d(Poles2d.Upper()).SetCoord(sol(3),sol(4));
531 DPoles2d(Poles2d.Lower()).SetCoord(Tangent2dOnS1().X(),
532 Tangent2dOnS1().Y());
533 DPoles2d(Poles2d.Upper()).SetCoord(Tangent2dOnS2().X(),
534 Tangent2dOnS2().Y());
536 Poles(low) = PointOnS1();
537 Poles(upp) = PointOnS2();
541 DPoles(low) = TangentOnS1();
542 DPoles(upp) = TangentOnS2();
550 //=======================================================================
553 //=======================================================================
555 void BlendFunc_Chamfer::Section(const Blend_Point& P,
556 TColgp_Array1OfPnt& Poles,
557 TColgp_Array1OfPnt2d& Poles2d,
558 TColStd_Array1OfReal& Weights)
560 Standard_Real u1,v1,u2,v2,prm = P.Parameter();
561 Standard_Integer low = Poles.Lower();
562 Standard_Integer upp = Poles.Upper();
563 math_Vector X(1,4), F(1,4);
565 P.ParametersOnS1(u1,v1);
566 P.ParametersOnS2(u2,v2);
571 Poles2d(Poles2d.Lower()).SetCoord(u1,v1);
572 Poles2d(Poles2d.Upper()).SetCoord(u2,v2);
576 Poles(low) = PointOnS1();
577 Poles(upp) = PointOnS2();
582 void BlendFunc_Chamfer::Resolution(const Standard_Integer IC2d, const Standard_Real Tol,
583 Standard_Real& TolU, Standard_Real& TolV) const
586 TolU = surf1->UResolution(Tol);
587 TolV = surf1->VResolution(Tol);
590 TolU = surf2->UResolution(Tol);
591 TolV = surf2->VResolution(Tol);