1 // Created on: 1997-01-15
2 // Created by: Stagiaire Francois DUMONT
3 // Copyright (c) 1997-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 under
9 // the terms of the GNU Lesser General Public License 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.
18 #include <BSplCLib.hxx>
19 #include <Geom2d_BSplineCurve.hxx>
20 #include <Geom_BSplineCurve.hxx>
21 #include <gp_Pnt2d.hxx>
24 #include <Precision.hxx>
25 #include <Standard_Boolean.hxx>
26 #include <Standard_DimensionError.hxx>
27 #include <Standard_Real.hxx>
28 #include <TColgp_Array1OfPnt2d.hxx>
29 #include <TColStd_Array1OfInteger.hxx>
30 #include <TColStd_Array1OfReal.hxx>
31 #include <TColStd_HArray1OfInteger.hxx>
32 #include <TColStd_HArray1OfReal.hxx>
35 //=======================================================================
36 //function : HermiteCoeff
37 //purpose : calculate the Hermite coefficients of degree 3 from BS and
38 // store them in TAB(4 coefficients)
39 //=======================================================================
40 static void HermiteCoeff(const Handle(Geom_BSplineCurve)& BS,
41 TColStd_Array1OfReal& TAB)
44 TColStd_Array1OfReal Knots(1,BS->NbKnots());
45 TColStd_Array1OfReal Weights(1,BS->NbPoles());
46 TColStd_Array1OfInteger Mults(1,BS->NbKnots());
47 Standard_Integer Degree,Index0,Index1; // denominateur value for u=0 & u=1
48 Standard_Real Denom0,Denom1, // denominator value for u=0 & u=1
49 Deriv0,Deriv1 ; // derivative denominator value for u=0 & 1
50 Standard_Boolean Periodic;
53 BSplCLib::Reparametrize(0.0,1.0,Knots); //affinity on the nodal vector
55 BS->Multiplicities(Mults);
56 Degree = BS->Degree();
57 Periodic = BS->IsPeriodic();
58 Index0 = BS->FirstUKnotIndex();
59 Index1 = BS->LastUKnotIndex()-1;
61 BSplCLib::D1(0.0,Index0,Degree,Periodic,Weights,BSplCLib::NoWeights(),Knots,&Mults,Denom0,Deriv0);
62 BSplCLib::D1(1.0,Index1,Degree,Periodic,Weights,BSplCLib::NoWeights(),Knots,&Mults,Denom1,Deriv1);
63 TAB(0) = 1/Denom0; //Hermit coefficients
64 TAB(1) = -Deriv0/(Denom0*Denom0);
65 TAB(2) = -Deriv1/(Denom1*Denom1);
70 //=======================================================================
71 //function : HermiteCoeff
72 //purpose : calculate the Hermite coefficients of degree 3 from BS and
73 // store them in TAB(4 coefficients)
74 //=======================================================================
76 static void HermiteCoeff(const Handle(Geom2d_BSplineCurve)& BS,
77 TColStd_Array1OfReal& TAB)
80 TColStd_Array1OfReal Knots(1,BS->NbKnots());
81 TColStd_Array1OfReal Weights(1,BS->NbPoles());
82 TColStd_Array1OfInteger Mults(1,BS->NbKnots());
83 Standard_Integer Degree,Index0,Index1;
84 Standard_Real Denom0,Denom1, // denominateur value for u=0 & u=1
85 Deriv0,Deriv1 ; // denominator value for u=0 & u=1
86 Standard_Boolean Periodic; // derivative denominatur value for u=0 & 1
89 BSplCLib::Reparametrize(0.0,1.0,Knots); //affinity on the nodal vector
91 BS->Multiplicities(Mults);
92 Degree = BS->Degree();
93 Periodic = BS->IsPeriodic();
94 Index0 = BS->FirstUKnotIndex();
95 Index1 = BS->LastUKnotIndex()-1;
97 BSplCLib::D1(0.0,Index0,Degree,Periodic,Weights,BSplCLib::NoWeights(),Knots,&Mults,Denom0,Deriv0);
98 BSplCLib::D1(1.0,Index1,Degree,Periodic,Weights,BSplCLib::NoWeights(),Knots,&Mults,Denom1,Deriv1);
99 TAB(0) = 1/Denom0; //Hermit coefficients
100 TAB(1) = -Deriv0/(Denom0*Denom0);
101 TAB(2) = -Deriv1/(Denom1*Denom1);
106 //=======================================================================
107 //function : SignDenom
108 //purpose : give the sign of Herm(0) True=Positive
109 //=======================================================================
111 static Standard_Boolean SignDenom(const TColgp_Array1OfPnt2d& Poles)
114 Standard_Boolean Result;
117 Result=Standard_False;
118 else Result=Standard_True;
122 //=======================================================================
124 //purpose : give the max and the min of the Poles (by their index)
125 //=======================================================================
128 static void Polemax(const TColgp_Array1OfPnt2d& Poles,
129 Standard_Integer& min,
130 Standard_Integer& max)
133 // Standard_Integer i,index=0;
135 Standard_Real Max,Min; //intermediate value of max and min ordinates
136 min=0;max=0; //initialisation of the indices
138 Min=Poles(0).Y(); //initialisation of the intermediate value
140 for (i=1;i<=(Poles.Length()-1);i++){
141 if (Poles(i).Y()<Min){
145 if (Poles(i).Y()>Max){
152 //=======================================================================
153 //function : PolyTest
154 //purpose : give the knots U4 and U5 to insert to a(u)
155 //=======================================================================
158 static void PolyTest(const TColStd_Array1OfReal& Herm,
159 const Handle(Geom_BSplineCurve)& BS,
162 Standard_Integer& boucle,
163 const Standard_Real TolPoles,
164 // const Standard_Real TolKnots,
165 const Standard_Real ,
166 const Standard_Real Ux,
167 const Standard_Real Uy)
170 Standard_Integer index,i,
171 I1=0,I2=0,I3=0,I4=0; //knots index
172 TColgp_Array1OfPnt2d Polesinit(0,3) ;
173 Handle(TColStd_HArray1OfReal) Knots; //array of the BSpline knots + the ones inserted
174 Standard_Integer cas=0,mark=0,dercas=0, //loop marks
175 min,max; //Pole min and max indices
176 Standard_Real Us1,Us2,a; //boundaries value of the knots to be inserted
178 U4=0.0;U5=1.0; //default value
180 BS->LocateU(Ux,0.0,I1,I2); //localization of the inserted knots
182 BS->LocateU(Uy,0.0,I3,I4);
185 if (I1==I2) //definition and filling of the
186 if((I3==I4)||(I3==0)){ //array of knots
187 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots());
188 for (i=1;i<=BS->NbKnots();i++)
189 Knots->SetValue(i,BS->Knot(i));
192 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots()+1);
193 for (i=1;i<=BS->NbKnots();i++)
194 Knots->SetValue(i,BS->Knot(i));
195 Knots->SetValue(BS->NbKnots()+1,Uy);
198 if((I3==I4)||(I3==0)){
199 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots()+1);
200 for (i=1;i<=BS->NbKnots();i++)
201 Knots->SetValue(i,BS->Knot(i));
202 Knots->SetValue(BS->NbKnots()+1,Ux);
205 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots()+2);
206 for (i=1;i<=BS->NbKnots();i++)
207 Knots->SetValue(i,BS->Knot(i));
208 Knots->SetValue(BS->NbKnots()+1,Ux);
209 Knots->SetValue(BS->NbKnots()+2,Uy);
213 TColStd_Array1OfReal knots(1,Knots->Length());
214 knots=Knots->ChangeArray1();
216 //sort of the array of knots
217 std::sort (knots.begin(), knots.end());
219 Polesinit(0).SetCoord(0.0,Herm(0)); //poles of the Hermite polynome in the BSpline form
220 Polesinit(1).SetCoord(0.0,Herm(0)+Herm(1)/3.0);
221 Polesinit(2).SetCoord(0.0,Herm(3)-Herm(2)/3.0);
222 Polesinit(3).SetCoord(0.0,Herm(3));
224 //loop to check the tolerances on poles
226 Polemax(Polesinit,min,max);
227 Standard_Real Polemin=Polesinit(min).Y();
228 Standard_Real Polemax=Polesinit(max).Y();
229 if (((Polemax)>=((1/TolPoles)*Polemin))||((Polemin==0.0)&&(Polemax>=(1/TolPoles)))){
230 if (Polesinit(0).Y()>=(1/TolPoles)*Polesinit(3).Y()||Polesinit(0).Y()<=TolPoles*Polesinit(3).Y())
231 throw Standard_DimensionError("Hermit Impossible Tolerance");
232 if ((max==0)||(max==3))
235 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-TolPoles*Polemax));
237 else if ((max==1)||(max==2)) {
238 if ((min==0)||(min==3))
241 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-(1/TolPoles)*Polemin));
244 if ((TolPoles*Polemax<Polesinit(0).Y())&&(TolPoles*Polemax<Polesinit(3).Y())){
246 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-TolPoles*Polemax));
249 if ((1/TolPoles*Polemin>Polesinit(0).Y())&&(1/TolPoles*Polemin>Polesinit(3).Y())&&(mark==0)){
251 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-1/TolPoles*Polemin));
255 Standard_Real Pole0,Pole3;
256 Pole0=Polesinit(0).Y();
257 Pole3=Polesinit(3).Y();
259 a=Log10(Pole3/Pole0);
263 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole3*(Pow(10.0,(-0.5*Log10(TolPoles)-a/2.0)))));
268 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole0*(Pow(10.0,(a/2.0+0.5*Log10(TolPoles))))));
274 a=Log10(Pole0/Pole3);
278 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole0*(Pow(10.0,(-0.5*Log10(TolPoles)-a/2.0)))));
283 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole3*(Pow(10.0,(a/2.0+0.5*Log10(TolPoles))))));
293 if (!SignDenom(Polesinit)) //invertion of the polynome sign
295 for (index=0;index<=3;index++)
296 Polesinit(index).SetCoord(0.0,-Polesinit(index).Y());
299 // loop of positivity
300 if ((Polesinit(1).Y()<0.0)&&(Polesinit(2).Y()>=0.0))
302 Us1=Polesinit(0).Y()/(Polesinit(0).Y()-Polesinit(1).Y());
308 BSplCLib::LocateParameter(3,knots,Us1,Standard_False,1,knots.Length(),I1,Us1);
315 if ((Polesinit(1).Y()>=0.0)&&(Polesinit(2).Y()<0.0))
317 Us2=Polesinit(2).Y()/(Polesinit(2).Y()-Polesinit(3).Y());
319 Us2=knots(knots.Length()-1)+Us2*(1-knots(knots.Length()-1));
323 BSplCLib::LocateParameter(3,knots,Us2,Standard_False,1,knots.Length(),I1,Us2);
324 if (I1>=(knots.Length()-1))
333 if ((Polesinit(1).Y()<0.0)&&(Polesinit(2).Y()<0.0)){
334 Us1=Polesinit(0).Y()/(Polesinit(0).Y()-Polesinit(1).Y());
335 Us2=Polesinit(2).Y()/(Polesinit(2).Y()-Polesinit(3).Y());
342 BSplCLib::LocateParameter(3,knots,Us1,Standard_False,1,knots.Length(),I1,Us1);
343 if (knots(I1)>=Us2) //insertion of one knot for the two poles
346 if (I1>=2){ //insertion to the left and
347 U4=knots(I1); //to the right without a new knot
348 BSplCLib::LocateParameter(3,knots,Us2,Standard_False,1,knots.Length(),I3,Us2);
349 if (I3<(BS->NbKnots()-1)){
354 if(cas==0) //insertion of only one new knot
358 else{ //insertion of two knots
359 BSplCLib::LocateParameter(3,knots,Us1,Standard_False,1,knots.Length(),I1,Us1);
364 BSplCLib::LocateParameter(3,knots,Us2,Standard_False,1,knots.Length(),I3,Us2);
365 if (I3<(BS->NbKnots()-1))
373 //=======================================================================
374 //function : PolyTest
375 //purpose : give the knots U4 and U5 to insert to a(u)
376 //=======================================================================
379 static void PolyTest(const TColStd_Array1OfReal& Herm,
380 const Handle(Geom2d_BSplineCurve)& BS,
383 Standard_Integer& boucle,
384 const Standard_Real TolPoles,
385 // const Standard_Real TolKnots,
386 const Standard_Real ,
387 const Standard_Real Ux,
388 const Standard_Real Uy)
391 Standard_Integer index,i,
392 I1=0,I2=0,I3=0,I4=0; //knots index
393 TColgp_Array1OfPnt2d Polesinit(0,3) ;
394 Handle(TColStd_HArray1OfReal) Knots; //array of the BSpline knots + the ones inserted
395 Standard_Integer cas=0,mark=0,dercas=0, //loop marks
396 min,max; //Pole min and max indices
397 Standard_Real Us1,Us2,a; //boundaries value of the knots to be inserted
399 U4=0.0;U5=1.0; //default value
401 BS->LocateU(Ux,0.0,I1,I2); //localization of the inserted knots
403 BS->LocateU(Uy,0.0,I3,I4);
406 if (I1==I2) //definition and filling of the
408 if((I3==I4)||(I3==0)){ //array of knots
409 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots());
410 for (i=1;i<=BS->NbKnots();i++)
411 Knots->SetValue(i,BS->Knot(i));
414 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots()+1);
415 for (i=1;i<=BS->NbKnots();i++)
416 Knots->SetValue(i,BS->Knot(i));
417 Knots->SetValue(BS->NbKnots()+1,Uy);
422 if((I3==I4)||(I3==0)){
423 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots()+1);
424 for (i=1;i<=BS->NbKnots();i++)
425 Knots->SetValue(i,BS->Knot(i));
426 Knots->SetValue(BS->NbKnots()+1,Ux);
429 Knots=new TColStd_HArray1OfReal(1,BS->NbKnots()+2);
430 for (i=1;i<=BS->NbKnots();i++)
431 Knots->SetValue(i,BS->Knot(i));
432 Knots->SetValue(BS->NbKnots()+1,Ux);
433 Knots->SetValue(BS->NbKnots()+2,Uy);
437 TColStd_Array1OfReal knots(1,Knots->Length());
438 knots=Knots->ChangeArray1();
440 //sort of the array of knots
441 std::sort (knots.begin(), knots.end());
443 Polesinit(0).SetCoord(0.0,Herm(0)); //poles of the Hermite polynome in the BSpline form
444 Polesinit(1).SetCoord(0.0,Herm(0)+Herm(1)/3.0);
445 Polesinit(2).SetCoord(0.0,Herm(3)-Herm(2)/3.0);
446 Polesinit(3).SetCoord(0.0,Herm(3));
448 // loop to check the tolerances on poles
451 Polemax(Polesinit,min,max);
452 Standard_Real Polemin=Polesinit(min).Y();
453 Standard_Real Polemax=Polesinit(max).Y();
454 if (((Polemax)>=((1/TolPoles)*Polemin))||((Polemin==0.0)&&(Polemax>=(1/TolPoles))))
456 if (Polesinit(0).Y()>=(1/TolPoles)*Polesinit(3).Y()||Polesinit(0).Y()<=TolPoles*Polesinit(3).Y())
457 throw Standard_DimensionError("Hermit Impossible Tolerance");
458 if ((max==0)||(max==3))
461 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-TolPoles*Polemax));
463 else if ((max==1)||(max==2))
465 if ((min==0)||(min==3))
468 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-(1/TolPoles)*Polemin));
472 if ((TolPoles*Polemax<Polesinit(0).Y())&&(TolPoles*Polemax<Polesinit(3).Y()))
475 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-TolPoles*Polemax));
479 if ((1/TolPoles*Polemin>Polesinit(0).Y())&&(1/TolPoles*Polemin>Polesinit(3).Y())&&(mark==0))
482 Polesinit(i).SetCoord(0.0,(Polesinit(i).Y()-1/TolPoles*Polemin));
487 Standard_Real Pole0,Pole3;
488 Pole0=Polesinit(0).Y();
489 Pole3=Polesinit(3).Y();
492 a=Log10(Pole3/Pole0);
496 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole3*(Pow(10.0,(-0.5*Log10(TolPoles)-a/2.0)))));
501 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole0*(Pow(10.0,(a/2.0+0.5*Log10(TolPoles))))));
507 a=Log10(Pole0/Pole3);
511 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole0*(Pow(10.0,(-0.5*Log10(TolPoles)-a/2.0)))));
516 Polesinit(i).SetCoord(0.0, Polesinit(i).Y()-(Pole3*(Pow(10.0,(a/2.0+0.5*Log10(TolPoles))))));
526 if (!SignDenom(Polesinit)) // invertion of the polynome sign
528 for (index=0;index<=3;index++)
529 Polesinit(index).SetCoord(0.0,-Polesinit(index).Y());
532 // boucle de positivite
533 if ((Polesinit(1).Y()<0.0)&&(Polesinit(2).Y()>=0.0))
535 Us1=Polesinit(0).Y()/(Polesinit(0).Y()-Polesinit(1).Y());
541 BSplCLib::LocateParameter(3,knots,Us1,Standard_False,1,knots.Length(),I1,Us1);
548 if ((Polesinit(1).Y()>=0.0)&&(Polesinit(2).Y()<0.0))
550 Us2=Polesinit(2).Y()/(Polesinit(2).Y()-Polesinit(3).Y());
552 Us2=knots(knots.Length()-1)+Us2*(1-knots(knots.Length()-1));
556 BSplCLib::LocateParameter(3,knots,Us2,Standard_False,1,knots.Length(),I1,Us2);
557 if (I1>=(knots.Length()-1))
566 if ((Polesinit(1).Y()<0.0)&&(Polesinit(2).Y()<0.0)){
567 Us1=Polesinit(0).Y()/(Polesinit(0).Y()-Polesinit(1).Y());
568 Us2=Polesinit(2).Y()/(Polesinit(2).Y()-Polesinit(3).Y());
575 BSplCLib::LocateParameter(3,knots,Us1,Standard_False,1,knots.Length(),I1,Us1);
576 if (knots(I1)>=Us2) //insertion of one knot for the two poles
579 if (I1>=2){ //insertion to the left and
580 U4=knots(I1); //to the right without a new knot
581 BSplCLib::LocateParameter(3,knots,Us2,Standard_False,1,knots.Length(),I3,Us2);
582 if (I3<(BS->NbKnots()-1)){
587 if(cas==0) //insertion of only one new knot
591 else{ //insertion of two knots
592 BSplCLib::LocateParameter(3,knots,Us1,Standard_False,1,knots.Length(),I1,Us1);
597 BSplCLib::LocateParameter(3,knots,Us2,Standard_False,1,knots.Length(),I3,Us2);
598 if (I3<(BS->NbKnots()-1))
606 //=======================================================================
607 //function : InsertKnots
608 //purpose : insert the knots in BS knot sequence if they are not null.
609 //=======================================================================
611 static void InsertKnots(Handle(Geom2d_BSplineCurve)& BS,
612 const Standard_Real U4,
613 const Standard_Real U5)
616 if (U4!=0.0) //insertion of :0 knot if U4=0
617 BS->InsertKnot(U4); // 1 knot if U4=U5
618 if ((U5!=1.0)&&(U5!=U4)) // 2 knots otherwise
623 //=======================================================================
624 //function : MovePoles
625 //purpose : move the poles above the x axis
626 //=======================================================================
628 static void MovePoles(Handle(Geom2d_BSplineCurve)& BS)
632 // Standard_Integer i,index;
635 for (i=3;i<=(BS->NbPoles()-2);i++){
636 P.SetCoord(1,(BS->Pole(i).Coord(1))); //raising of the no constrained poles to
637 P.SetCoord(2,(BS->Pole(1).Coord(2))); //the first pole level
642 //=======================================================================
643 //function : Solution
645 //=======================================================================
647 Handle(Geom2d_BSplineCurve) Hermit::Solution(const Handle(Geom_BSplineCurve)& BS,
648 const Standard_Real TolPoles,
649 const Standard_Real TolKnots)
652 TColStd_Array1OfReal Herm(0,3);
653 Standard_Real Upos1=0.0, Upos2=1.0, //positivity knots
655 Utol1=0.0, Utol2=1.0, //tolerance knots
656 Uint1=0.0, Uint2=1.0; //tolerance knots for the first loop
657 Standard_Integer boucle=1; //loop mark
658 TColStd_Array1OfReal Knots(1,2);
659 TColStd_Array1OfInteger Multiplicities(1,2);
660 TColgp_Array1OfPnt2d Poles(1,4);
661 Standard_Integer zeroboucle = 0 ;
662 HermiteCoeff(BS,Herm); //computation of the Hermite coefficient
664 Poles(1).SetCoord(0.0,Herm(0)); //poles of the Hermite polynome in the BSpline form
665 Poles(2).SetCoord(0.0,Herm(0)+Herm(1)/3.0);
666 Poles(3).SetCoord(0.0,Herm(3)-Herm(2)/3.0);
667 Poles(4).SetCoord(0.0,Herm(3));
673 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(Poles,Knots,Multiplicities,3);//creation of the basic
674 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(Poles,Knots,Multiplicities,3);//BSpline without modif
676 PolyTest(Herm,BS,Upos1,Upos2,zeroboucle,Precision::Confusion(),Precision::Confusion(),1.0,0.0);//computation of the positivity knots
677 InsertKnots(BS2,Upos1,Upos2); //and insertion
693 Herm(0)=BS2->Pole(1).Y(); //computation of the Hermite coefficient on the
694 Herm(1)=3*(BS2->Pole(2).Y()-BS2->Pole(1).Y()); //positive BSpline
695 Herm(2)=3*(BS2->Pole(BS2->NbPoles()).Y()-BS2->Pole(BS2->NbPoles()-1).Y());
696 Herm(3)=BS2->Pole(BS2->NbPoles()).Y();
698 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Ux,Uy); //computation of the tolerance knots
699 InsertKnots(BS2,Utol1,Utol2); //and insertion
701 if (boucle==2){ //insertion of two knots
702 Herm(0)=BS2->Pole(1).Y();
703 Herm(1)=3*(BS2->Pole(2).Y()-BS2->Pole(1).Y());
704 Herm(2)=3*(BS2->Pole(BS2->NbPoles()).Y()-BS2->Pole(BS2->NbPoles()-1).Y());
705 Herm(3)=BS2->Pole(BS2->NbPoles()).Y();
708 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Uint2,0.0);
712 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Uint1,0.0);
714 InsertKnots(BS2,Utol1,Utol2);
716 if ((BS2->Knot(2)<TolKnots)||(BS2->Knot(BS2->NbKnots()-1)>(1-TolKnots))) //checking of the knots tolerance
717 throw Standard_DimensionError("Hermit Impossible Tolerance");
719 if ((Upos2==1.0)&&(Utol2==1.0)&&(Uint2==1.0)) //test on the final inserted knots
720 InsertKnots(BS1,BS2->Knot(2),1.0);
722 if ((Upos1==0.0)&&(Utol1==0.0)&&(Uint1==0.0))
723 InsertKnots(BS1,BS2->Knot(BS2->NbKnots()-1),1.0);
725 InsertKnots(BS1,BS2->Knot(BS2->NbKnots()-1),BS2->Knot(2));
727 MovePoles(BS1); //relocation of the no-contrained knots
733 //=======================================================================
735 //=======================================================================
737 Handle(Geom2d_BSplineCurve) Hermit::Solution(const Handle(Geom2d_BSplineCurve)& BS,
738 const Standard_Real TolPoles,
739 const Standard_Real TolKnots)
742 TColStd_Array1OfReal Herm(0,3);
743 Standard_Real Upos1=0.0, Upos2=1.0, //positivity knots
745 Utol1=0.0, Utol2=1.0, //tolerance knots
746 Uint1=0.0, Uint2=1.0; //tolerance knots for the first loop
747 Standard_Integer boucle=1; //loop mark
748 TColStd_Array1OfReal Knots(1,2);
749 TColStd_Array1OfInteger Multiplicities(1,2);
750 TColgp_Array1OfPnt2d Poles(1,4);
751 Standard_Integer zeroboucle = 0 ;
752 HermiteCoeff(BS,Herm); //computation of the Hermite coefficient
754 Poles(1).SetCoord(0.0,Herm(0)); //poles of the Hermite polynome in the BSpline form
755 Poles(2).SetCoord(0.0,Herm(0)+Herm(1)/3.0);
756 Poles(3).SetCoord(0.0,Herm(3)-Herm(2)/3.0);
757 Poles(4).SetCoord(0.0,Herm(3));
763 Handle(Geom2d_BSplineCurve) BS1=new Geom2d_BSplineCurve(Poles,Knots,Multiplicities,3);//creation of the basic
764 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(Poles,Knots,Multiplicities,3);//BSpline without modif
766 PolyTest(Herm,BS,Upos1,Upos2,zeroboucle,Precision::Confusion(),Precision::Confusion(),1.0,0.0);//computation of the positivity knots
767 InsertKnots(BS2,Upos1,Upos2); //and insertion
783 Herm(0)=BS2->Pole(1).Y(); //computation of the Hermite coefficient on the
784 Herm(1)=3*(BS2->Pole(2).Y()-BS2->Pole(1).Y()); //positive BSpline
785 Herm(2)=3*(BS2->Pole(BS2->NbPoles()).Y()-BS2->Pole(BS2->NbPoles()-1).Y());
786 Herm(3)=BS2->Pole(BS2->NbPoles()).Y();
788 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Ux,Uy); //computation of the tolerance knots
789 InsertKnots(BS2,Utol1,Utol2); //and insertion
791 if (boucle==2){ //insertion of two knots
792 Herm(0)=BS2->Pole(1).Y();
793 Herm(1)=3*(BS2->Pole(2).Y()-BS2->Pole(1).Y());
794 Herm(2)=3*(BS2->Pole(BS2->NbPoles()).Y()-BS2->Pole(BS2->NbPoles()-1).Y());
795 Herm(3)=BS2->Pole(BS2->NbPoles()).Y();
798 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Uint2,0.0);
802 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Uint1,0.0);
804 InsertKnots(BS2,Utol1,Utol2);
806 if ((BS2->Knot(2)<TolKnots)||(BS2->Knot(BS2->NbKnots()-1)>(1-TolKnots))) //checking of the knots tolerance
807 throw Standard_DimensionError("Hermit Impossible Tolerance");
809 if ((Upos2==1.0)&&(Utol2==1.0)&&(Uint2==1.0)) //test on the final inserted knots
810 InsertKnots(BS1,BS2->Knot(2),1.0);
812 if ((Upos1==0.0)&&(Utol1==0.0)&&(Uint1==0.0))
813 InsertKnots(BS1,BS2->Knot(BS2->NbKnots()-1),1.0);
815 InsertKnots(BS1,BS2->Knot(BS2->NbKnots()-1),BS2->Knot(2));
817 MovePoles(BS1); //relocation of the no-contrained knots
822 //=======================================================================
823 //function : Solutionbis
825 //=======================================================================
827 void Hermit::Solutionbis(const Handle(Geom_BSplineCurve)& BS,
828 Standard_Real & Knotmin,
829 Standard_Real & Knotmax,
830 const Standard_Real TolPoles,
831 const Standard_Real TolKnots)
834 TColStd_Array1OfReal Herm(0,3);
835 Standard_Real Upos1=0.0, Upos2=1.0, //positivity knots
837 Utol1=0.0, Utol2=1.0, //tolerance knots
838 Uint1=0.0, Uint2=1.0; //tolerance knots for the first loop
839 Standard_Integer boucle=1; //loop mark
840 TColStd_Array1OfReal Knots(1,2);
841 TColStd_Array1OfInteger Multiplicities(1,2);
842 TColgp_Array1OfPnt2d Poles(1,4);
843 Standard_Integer zeroboucle = 0 ;
844 HermiteCoeff(BS,Herm); //computation of the Hermite coefficient
846 Poles(1).SetCoord(0.0,Herm(0)); //poles of the Hermite polynome in the BSpline form
847 Poles(2).SetCoord(0.0,Herm(0)+Herm(1)/3.0);
848 Poles(3).SetCoord(0.0,Herm(3)-Herm(2)/3.0);
849 Poles(4).SetCoord(0.0,Herm(3));
855 Handle(Geom2d_BSplineCurve) BS2=new Geom2d_BSplineCurve(Poles,Knots,Multiplicities,3);//creation of the basic
856 //BSpline without modif
858 PolyTest(Herm,BS,Upos1,Upos2,zeroboucle,Precision::Confusion(),Precision::Confusion(),1.0,0.0);//computation of the positivity knots
859 InsertKnots(BS2,Upos1,Upos2); //and insertion
875 Herm(0)=BS2->Pole(1).Y(); //computation of the Hermite coefficient on the
876 Herm(1)=3*(BS2->Pole(2).Y()-BS2->Pole(1).Y()); //positive BSpline
877 Herm(2)=3*(BS2->Pole(BS2->NbPoles()).Y()-BS2->Pole(BS2->NbPoles()-1).Y());
878 Herm(3)=BS2->Pole(BS2->NbPoles()).Y();
880 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Ux,Uy); //computation of the tolerance knots
881 InsertKnots(BS2,Utol1,Utol2); //and insertion
883 if (boucle==2){ //insertion of two knots
884 Herm(0)=BS2->Pole(1).Y();
885 Herm(1)=3*(BS2->Pole(2).Y()-BS2->Pole(1).Y());
886 Herm(2)=3*(BS2->Pole(BS2->NbPoles()).Y()-BS2->Pole(BS2->NbPoles()-1).Y());
887 Herm(3)=BS2->Pole(BS2->NbPoles()).Y();
890 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Uint2,0.0);
894 PolyTest(Herm,BS,Utol1,Utol2,boucle,TolPoles,TolKnots,Uint1,0.0);
896 InsertKnots(BS2,Utol1,Utol2);
898 if ((BS2->Knot(2)<TolKnots)||(BS2->Knot(BS2->NbKnots()-1)>(1-TolKnots))) //checking of the knots tolerance
899 throw Standard_DimensionError("Hermit Impossible Tolerance");
901 if ((Upos2==1.0)&&(Utol2==1.0)&&(Uint2==1.0)) //test on the final inserted knots
902 Knotmin=BS2->Knot(2);
904 if ((Upos1==0.0)&&(Utol1==0.0)&&(Uint1==0.0))
905 Knotmax=BS2->Knot(BS2->NbKnots()-1);
907 Knotmin=BS2->Knot(2);
908 Knotmax=BS2->Knot(BS2->NbKnots()-1);