1 // Created on: 1998-07-08
2 // Created by: Stephanie HUMEAU
3 // Copyright (c) 1998-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.
17 #include <GeomFill_LocationGuide.ixx>
22 #include <gp_Trsf.hxx>
23 #include <gp_GTrsf.hxx>
26 #include <gp_Pnt2d.hxx>
28 #include <math_Vector.hxx>
29 #include <math_Gauss.hxx>
30 #include <math_FunctionSetRoot.hxx>
31 #include <Precision.hxx>
33 #include <Geom_SurfaceOfRevolution.hxx>
34 #include <Geom_BSplineCurve.hxx>
35 #include <Geom_Curve.hxx>
37 #include <Adaptor3d_SurfaceOfRevolution.hxx>
38 #include <Adaptor3d_HSurface.hxx>
40 #include <IntCurveSurface_IntersectionPoint.hxx>
41 #include <Adaptor3d_Surface.hxx>
42 #include <GeomAdaptor.hxx>
43 #include <GeomAdaptor_HSurface.hxx>
44 #include <GeomAdaptor_HCurve.hxx>
47 #include <GeomFill_FunctionGuide.ixx>
48 #include <GeomFill_UniformSection.hxx>
49 #include <GeomFill_SectionPlacement.hxx>
50 #include <Geom_TrimmedCurve.hxx>
51 #include <GeomLib.hxx>
54 #include <TColStd_HArray1OfInteger.hxx>
55 #include <TColStd_HArray1OfReal.hxx>
56 #include <TColgp_HArray1OfPnt.hxx>
58 #include <Extrema_ExtCS.hxx>
59 #include <Extrema_POnSurf.hxx>
62 static Standard_Integer Affich = 0;
63 #include <Approx_Curve3d.hxx>
64 #include <DrawTrSurf.hxx>
67 //=======================================================================
68 //function : TraceRevol
69 //purpose : Trace la surface de revolution (Debug)
70 //=======================================================================
72 static void TraceRevol(const Standard_Real t,
73 const Standard_Real s,
74 const Handle(GeomFill_TrihedronWithGuide)& Law,
75 const Handle(GeomFill_SectionLaw)& Section,
76 const Handle(Adaptor3d_HCurve)& Curve,
82 gp_Ax3 Rep(gp::Origin(), gp::DZ(), gp::DX());
87 gp_Mat M(N.XYZ(), B.XYZ(), T.XYZ());
90 gp_Dir D = M.Column(3);
91 gp_Ax1 Ax(P,D); // axe pour la surface de revoltuion
93 // calculer transfo entre triedre et Oxyz
97 Transfo.SetTransformation(N3, Rep);
99 // transformer la section
100 Standard_Real f, l,e=1.e-7;
101 Handle (Geom_Curve) S, C;
103 if (Section->IsConstant(e)) {
104 C = Section->ConstantSection();
107 Standard_Integer NbPoles, NbKnots, Deg;
108 Section->SectionShape(NbPoles, NbKnots, Deg);
109 TColStd_Array1OfInteger Mult(1,NbKnots);
110 Section->Mults( Mult);
111 TColStd_Array1OfReal Knots(1,NbKnots);
112 Section->Knots(Knots);
113 TColgp_Array1OfPnt Poles(1, NbPoles);
114 TColStd_Array1OfReal Weights(1, NbPoles);
115 Section->D0(s, Poles, Weights);
116 if (Section->IsRational())
117 C = new (Geom_BSplineCurve)
118 (Poles, Weights, Knots, Mult ,
119 Deg, Section->IsUPeriodic());
121 C = new (Geom_BSplineCurve)
123 Deg, Section->IsUPeriodic());
127 f = C->FirstParameter();
128 l = C->LastParameter();
129 S = new (Geom_TrimmedCurve) (C, f, l);
130 S->Transform(Transfo);
132 // Surface de revolution
133 Handle (Geom_Surface) Revol = new(Geom_SurfaceOfRevolution) (S, Ax);
134 cout << "Surf Revol at parameter t = " << t << endl;
137 Standard_CString aName = "TheRevol" ;
138 DrawTrSurf::Set(aName,Revol);
143 //==================================================================
144 //Function: InGoodPeriod
145 //Purpose : Recadre un paramtere
146 //==================================================================
147 static void InGoodPeriod(const Standard_Real Prec,
148 const Standard_Real Period,
149 Standard_Real& Current)
151 Standard_Real Diff=Current-Prec;
152 Standard_Integer nb = (Standard_Integer ) IntegerPart(Diff/Period);
153 Current -= nb*Period;
155 if (Diff > Period/2) Current -= Period;
156 else if (Diff < -Period/2) Current += Period;
159 //==================================================================
160 //Function: GeomFill_LocationGuide
161 //Purpose : constructor
162 //==================================================================
163 GeomFill_LocationGuide::
164 GeomFill_LocationGuide (const Handle(GeomFill_TrihedronWithGuide)& Triedre)
165 : TolRes(1,3), Inf(1,3,0.), Sup(1,3,0.),
166 X(1,3), R(1,3), myStatus(GeomFill_PipeOk)
169 myLaw = Triedre; // loi de triedre
170 mySec.Nullify(); // loi de section
172 myFirstS = myLastS = -505e77;
174 myNbPts = 21; // nb points pour les calculs
175 myGuide = myLaw->Guide(); // courbe guide
176 if (!myGuide->IsPeriodic()) {
177 Standard_Real f, l, delta;
178 f = myGuide->FirstParameter();
179 l = myGuide->LastParameter();
183 myGuide = myGuide->Trim(f,l,delta*1.e-7); // courbe guide
186 myPoles2d = new (TColgp_HArray2OfPnt2d)(1, 2, 1, myNbPts);
187 rotation = Standard_False; // contact ou non
188 OrigParam1 = 0; // param pour ACR quand trajectoire
189 OrigParam2 = 1; // et guide pas meme sens de parcourt
191 WithTrans = Standard_False;
195 Approx_Curve3d approx(myGuide, 1.e-4,
197 15+myGuide->NbIntervals(GeomAbs_CN),
199 if (approx.HasResult()) {
200 Standard_CString aName = "TheGuide" ;
201 DrawTrSurf::Set(aName, approx.Curve());
207 //==================================================================
208 //Function: SetRotation
209 //Purpose : init et force la Rotation
210 //==================================================================
211 void GeomFill_LocationGuide::SetRotation(const Standard_Real PrecAngle,
212 Standard_Real& LastAngle)
214 if (myCurve.IsNull())
215 Standard_ConstructionError::Raise(
216 "GeomFill_LocationGuide::The path is not setted !!");
219 gp_Ax3 Rep(gp::Origin(), gp::DZ(), gp::DX());
223 Standard_Integer ii, Deg;
224 Standard_Boolean isconst, israt=Standard_False;
225 Standard_Real t, v,w, OldAngle=0, Angle, DeltaG, Diff;
226 Standard_Real CurAngle = PrecAngle, a1/*, a2*/;
228 Handle(Geom_SurfaceOfRevolution) Revol; // surface de revolution
229 Handle(GeomAdaptor_HSurface) Pl; // = Revol
230 Handle(Geom_TrimmedCurve) S;
231 IntCurveSurface_IntersectionPoint PInt; // intersection guide/Revol
232 Handle(TColStd_HArray1OfInteger) Mult;
233 Handle(TColStd_HArray1OfReal) Knots, Weights;
234 Handle(TColgp_HArray1OfPnt) Poles;
237 Standard_Real U=0, UPeriod=0;
238 Standard_Real f = myCurve->FirstParameter();
239 Standard_Real l = myCurve->LastParameter();
240 Standard_Boolean Ok, uperiodic = mySec->IsUPeriodic();
242 DeltaG = (myGuide->LastParameter() - myGuide->FirstParameter())/5;
243 Handle(Geom_Curve) mySection;
244 Standard_Real Tol =1.e-9;
246 Standard_Integer NbPoles, NbKnots;
247 mySec->SectionShape(NbPoles, NbKnots, Deg);
250 if (mySec->IsConstant(Tol)) {
251 mySection = mySec->ConstantSection();
252 Uf = mySection->FirstParameter();
253 Ul = mySection->LastParameter();
255 isconst = Standard_True;
258 isconst = Standard_False;
259 israt = mySec->IsRational();
260 Mult = new (TColStd_HArray1OfInteger) (1, NbKnots);
261 mySec->Mults( Mult->ChangeArray1());
262 Knots = new (TColStd_HArray1OfReal) (1, NbKnots);
263 mySec->Knots(Knots->ChangeArray1());
264 Poles = new (TColgp_HArray1OfPnt) (1, NbPoles);
265 Weights = new (TColStd_HArray1OfReal) (1, NbPoles);
266 Uf = Knots->Value(1);
267 Ul = Knots->Value(NbKnots);
272 // Standard_Integer bid1, bid2, NbK;
273 Delta = myGuide->LastParameter() - myGuide->FirstParameter();
274 Inf(1) = myGuide->FirstParameter() - Delta/10;
275 Sup(1) = myGuide->LastParameter() + Delta/10;
281 Inf(3) = Uf - Delta/10;
282 Sup(3) = Ul + Delta/10;
285 if (uperiodic) UPeriod = Ul-Uf;
287 for (ii=1; ii<=myNbPts; ii++) {
288 t = Standard_Real(myNbPts - ii)*f + Standard_Real(ii - 1)*l;
291 Ok = myLaw->D0(t, T, N, B);
293 myStatus = myLaw->ErrorStatus();
294 return; //Y a rien a faire.
298 gp_Mat M(N.XYZ(), B.XYZ(), T.XYZ());
302 gp_Ax1 Ax(P,D); // axe pour la surface de revoltuion
304 // calculer transfo entre triedre et Oxyz
308 Transfo.SetTransformation(N3, Rep);
310 // transformer la section
312 U = myFirstS + (t-myCurve->FirstParameter())*ratio;
313 mySec->D0(U, Poles->ChangeArray1(), Weights->ChangeArray1());
315 mySection = new (Geom_BSplineCurve)
320 Deg, mySec->IsUPeriodic());
322 mySection = new (Geom_BSplineCurve)
326 Deg, mySec->IsUPeriodic());
327 S = new (Geom_TrimmedCurve) (mySection, Uf, Ul);
330 S = new (Geom_TrimmedCurve)
331 (Handle(Geom_Curve)::DownCast(mySection->Copy()), Uf, Ul);
333 S->Transform(Transfo);
335 // Surface de revolution
336 Revol = new(Geom_SurfaceOfRevolution) (S, Ax);
338 GeomAdaptor_Surface GArevol(Revol);
339 Extrema_ExtCS DistMini(myGuide->Curve(), GArevol,
340 Precision::Confusion(), Precision::Confusion());
343 Standard_Real theU = 0., theV = 0.;
345 if (!DistMini.IsDone() || DistMini.NbExt() == 0) {
347 cout <<"LocationGuide : Pas d'intersection"<<endl;
348 TraceRevol(t, U, myLaw, mySec, myCurve, Trans);
350 Standard_Boolean SOS=Standard_False;
352 // Intersection de secour entre surf revol et guide
354 X(1) = myPoles2d->Value(1,ii-1).Y();
355 X(2) = myPoles2d->Value(2,ii-1).X();
356 X(3) = myPoles2d->Value(2,ii-1).Y();
357 GeomFill_FunctionGuide E (mySec, myGuide, U);
358 E.SetParam(U, P, T.XYZ(), N.XYZ());
359 // resolution => angle
360 math_FunctionSetRoot Result(E, X, TolRes,
363 if (Result.IsDone() &&
364 (Result.FunctionSetErrors().Norm() < TolRes(1)*TolRes(1)) ) {
366 cout << "Ratrappage Reussi !" << endl;
371 PInt.SetValues(P, RR(2), RR(3), RR(1), IntCurveSurface_Out);
377 cout << "Echec du Ratrappage !" << endl;
382 myStatus = GeomFill_ImpossibleContact;
386 else { // on prend le point d'intersection
387 // d'angle le plus proche de P
389 Standard_Real MinDist = RealLast();
390 Standard_Integer jref = 0;
391 for (Standard_Integer j = 1; j <= DistMini.NbExt(); j++)
393 Standard_Real aDist = DistMini.SquareDistance(j);
400 MinDist = Sqrt(MinDist);
401 DistMini.Points(jref, Pc, Ps);
403 Ps.Parameter(theU, theV);
406 InGoodPeriod (CurAngle, 2*M_PI, a1);
413 Diff = w - myPoles2d->Value(1, ii-1).Y();
414 if (Abs(Diff) > DeltaG) {
415 if (myGuide->IsPeriodic()) {
416 InGoodPeriod (myPoles2d->Value(1, ii-1).Y(),
417 myGuide->Period(), w);
418 Diff = w - myPoles2d->Value(1, ii-1).Y();
423 if (Abs(Diff) > DeltaG) {
424 cout << "Location :: Diff on Guide : " <<
429 //Recadrage de l'angle.
433 Diff = Angle - OldAngle;
434 if (Abs(Diff) > M_PI) {
435 InGoodPeriod (OldAngle, 2*M_PI, Angle);
436 Diff = Angle - OldAngle;
439 if (Abs(Diff) > M_PI/4) {
440 cout << "Diff d'angle trop grand !!" << endl;
451 InGoodPeriod (myPoles2d->Value(2, ii-1).Y(), UPeriod, v);
453 Diff = v - myPoles2d->Value(2, ii-1).Y();
455 if (Abs(Diff) > (Ul-Uf)/(2+NbKnots)) {
456 cout << "Diff sur section trop grand !!" << endl;
461 p1.SetCoord(t, w); // on stocke les parametres
462 p2.SetCoord(Angle , v);
464 myPoles2d->SetValue(1, ii, p1);
465 myPoles2d->SetValue(2, ii, p2);
469 LastAngle = CurAngle;
470 rotation = Standard_True; //C'est pret !
474 //==================================================================
476 //Purpose : init loi de section et force la Rotation
477 //==================================================================
478 void GeomFill_LocationGuide::Set(const Handle(GeomFill_SectionLaw)& Section,
479 const Standard_Boolean rotat,
480 const Standard_Real SFirst,
481 const Standard_Real SLast,
482 const Standard_Real PrecAngle,
483 Standard_Real& LastAngle)
485 myStatus = GeomFill_PipeOk;
488 LastAngle = PrecAngle;
489 if (myCurve.IsNull())
492 ratio = (SLast-SFirst) / (myCurve->LastParameter() -
493 myCurve->FirstParameter());
496 if (rotat) SetRotation(PrecAngle, LastAngle);
497 else rotation = Standard_False;
500 //==================================================================
501 //Function: EraseRotation
502 //Purpose : Supprime la Rotation
503 //==================================================================
504 void GeomFill_LocationGuide:: EraseRotation()
506 rotation = Standard_False;
507 if (myStatus == GeomFill_ImpossibleContact) myStatus = GeomFill_PipeOk;
510 //==================================================================
513 //==================================================================
514 Handle(GeomFill_LocationLaw) GeomFill_LocationGuide::Copy() const
517 Handle(GeomFill_TrihedronWithGuide) L;
518 L = Handle(GeomFill_TrihedronWithGuide)::DownCast(myLaw->Copy());
519 Handle(GeomFill_LocationGuide) copy = new
520 (GeomFill_LocationGuide) (L);
521 copy->SetOrigine(OrigParam1, OrigParam2);
522 copy->Set(mySec, rotation, myFirstS, myLastS,
523 myPoles2d->Value(1,1).X(), la);
524 copy->SetTrsf(Trans);
530 //==================================================================
532 //Purpose : Calcul des poles sur la surface d'arret (intersection
533 // courbe guide / surface de revolution en myNbPts points)
534 //==================================================================
535 void GeomFill_LocationGuide::SetCurve(const Handle(Adaptor3d_HCurve)& C)
537 Standard_Real LastAngle;
541 if (!myCurve.IsNull()){
543 myLaw->Origine(OrigParam1, OrigParam2);
544 myStatus = myLaw->ErrorStatus();
546 if (rotation) SetRotation(myPoles2d->Value(1,1).X(), LastAngle);
550 //==================================================================
552 //Purpose : return the trajectoire
553 //==================================================================
554 const Handle(Adaptor3d_HCurve)& GeomFill_LocationGuide::GetCurve() const
559 //==================================================================
562 //==================================================================
563 void GeomFill_LocationGuide::SetTrsf(const gp_Mat& Transfo)
569 WithTrans = Standard_False; // Au cas ou Trans = I
570 for (Standard_Integer ii=1; ii<=3 && !WithTrans ; ii++)
571 for (Standard_Integer jj=1; jj<=3 && !WithTrans; jj++)
572 if (Abs(Aux.Value(ii, jj)) > 1.e-14) WithTrans = Standard_True;
575 //==================================================================
578 //==================================================================
579 Standard_Boolean GeomFill_LocationGuide::D0(const Standard_Real Param,
587 myCurve->D0(Param, P);
589 Ok = myLaw->D0(Param, T, N, B);
591 myStatus = myLaw->ErrorStatus();
594 M.SetCols(N.XYZ(), B.XYZ(), T.XYZ());
601 Standard_Real U = myFirstS +
602 (Param-myCurve->FirstParameter())*ratio;
603 // initialisations germe
606 Standard_Integer Iter = 100;
612 // Intersection entre surf revol et guide
614 GeomFill_FunctionGuide E (mySec, myGuide, U);
615 E.SetParam(Param, P, t, n);
616 // resolution => angle
617 math_FunctionSetRoot Result(E, X, TolRes,
620 if (Result.IsDone()) {
626 Rot.SetRotation(t, R(2));
634 cout << "LocationGuide::D0 : No Result !"<<endl;
635 TraceRevol(Param, U, myLaw, mySec, myCurve, Trans);
637 myStatus = GeomFill_ImpossibleContact;
638 return Standard_False;
642 return Standard_True;
645 //==================================================================
647 //Purpose : calcul de l'intersection (C0) surface revol / guide
648 //==================================================================
649 Standard_Boolean GeomFill_LocationGuide::D0(const Standard_Real Param,
652 // TColgp_Array1OfPnt2d& Poles2d)
653 TColgp_Array1OfPnt2d& )
659 myCurve->D0(Param, P);
661 Ok = myLaw->D0(Param, T, N, B);
663 myStatus = myLaw->ErrorStatus();
666 M.SetCols(N.XYZ(), B.XYZ(), T.XYZ());
673 //initialisation du germe
675 Standard_Integer Iter = 100;
681 // equation d'intersection entre surf revol et guide => angle
682 GeomFill_FunctionGuide E (mySec, myGuide, myFirstS +
683 (Param-myCurve->FirstParameter())*ratio);
684 E.SetParam(Param, P, t, n);
687 math_FunctionSetRoot Result(E, X, TolRes,
690 if (Result.IsDone()) {
696 Rot.SetRotation(t, R(2));
706 Standard_Real U = myFirstS + ratio*(Param-myCurve->FirstParameter());
707 cout << "LocationGuide::D0 : No Result !"<<endl;
708 TraceRevol(Param, U, myLaw, mySec, myCurve, Trans);
710 myStatus = GeomFill_ImpossibleContact;
711 return Standard_False;
715 return Standard_True;
719 //==================================================================
721 //Purpose : calcul de l'intersection (C1) surface revol / guide
722 //==================================================================
723 Standard_Boolean GeomFill_LocationGuide::D1(const Standard_Real Param,
728 // TColgp_Array1OfPnt2d& Poles2d,
729 TColgp_Array1OfPnt2d& ,
730 // TColgp_Array1OfVec2d& DPoles2d)
731 TColgp_Array1OfVec2d& )
733 // gp_Vec T, N, B, DT, DN, DB, T0, N0, B0;
734 gp_Vec T, N, B, DT, DN, DB;
739 myCurve->D1(Param, P, DV);
741 Ok = myLaw->D1(Param, T, DT, N, DN, B, DB);
743 myStatus = myLaw->ErrorStatus();
746 M.SetCols(N.XYZ(), B.XYZ(), T.XYZ());
747 DM.SetCols(DN.XYZ() , DB.XYZ(), DT.XYZ());
755 return Standard_False;
758 Standard_Real U = myFirstS + ratio*(Param-myCurve->FirstParameter());
760 myCurve->FirstParameter() ;
763 // initialisation du germe
766 Standard_Integer Iter = 100;
767 gp_XYZ t,b,n, dt, db, dn;
775 // equation d'intersection surf revol / guide => angle
776 GeomFill_FunctionGuide E (mySec, myGuide, myFirstS +
777 (Param-myCurve->FirstParameter())*ratio);
778 E.SetParam(Param, P, t, n);
781 math_FunctionSetRoot Result(E, X, TolRes,
786 // solution de la fonction
789 // derivee de la fonction
790 math_Vector DEDT(1,3);
791 E.DerivT(R, DV.XYZ(), dt, DEDT); // dE/dt => DEDT
793 math_Vector DSDT (1,3,0);
794 math_Matrix DEDX (1,3,1,3,0);
795 E.Derivatives(R, DEDX); // dE/dx au point R => DEDX
797 // resolution du syst. : DEDX*DSDT = -DEDT
801 Ga.Solve (DEDT.Opposite(), DSDT);// resolution du syst.
805 cout << "DEDX = " << DEDX << endl;
806 cout << "DEDT = " << DEDT << endl;
808 Standard_ConstructionError::Raise(
809 "LocationGuide::D1 : No Result dans la derivee");
812 // transformation = rotation
814 Rot.SetRotation(t, R(2));
818 M.SetCols(n*Rot, b*Rot, t);
820 // transfo entre triedre (en Q) et Oxyz
821 gp_Ax3 Rep(gp::Origin(),gp::DZ(), gp::DX());
822 gp_Ax3 RepTriedre(gp::Origin(),t,n);
824 Transfo3.SetTransformation(Rep,RepTriedre);
825 // on se place dans Oxyz
826 Transfo3.Transforms(n);
827 Transfo3.Transforms(b);
828 Transfo3.Transforms(dn);
829 Transfo3.Transforms(db);
831 // matrices de rotation et derivees
832 Standard_Real A = R(2);
833 Standard_Real Aprim = DSDT(2);
836 gp_Mat M2 (Cos(A), -Sin(A),0, // rotation autour de T
841 gp_Mat M2prim (-Sin(A), -Cos(A), 0, // derivee rotation autour de T
844 M2prim.Multiply(Aprim);
858 // on repasse dans repere triedre
860 InvTrsf = Transfo3.Inverted();
861 InvTrsf.Transforms(dn);
862 InvTrsf.Transforms(db);
864 DM.SetCols(dn , db , dt);
869 cout << "LocationGuide::D1 : No Result !!"<<endl;
870 TraceRevol(Param, U, myLaw, mySec, myCurve, Trans);
872 myStatus = GeomFill_ImpossibleContact;
873 return Standard_False;
879 return Standard_True;
883 //==================================================================
885 //Purpose : calcul de l'intersection (C2) surface revol / guide
886 //==================================================================
887 Standard_Boolean GeomFill_LocationGuide::D2(const Standard_Real Param,
894 // TColgp_Array1OfPnt2d& Poles2d,
895 TColgp_Array1OfPnt2d& ,
896 // TColgp_Array1OfVec2d& DPoles2d,
897 TColgp_Array1OfVec2d& ,
898 // TColgp_Array1OfVec2d& D2Poles2d)
899 TColgp_Array1OfVec2d& )
901 gp_Vec T, N, B, DT, DN, DB, D2T, D2N, D2B;
902 // gp_Vec T0, N0, B0, T1, N1, B1;
907 myCurve->D2(Param, P, DV, D2V);
909 Ok = myLaw->D2(Param, T, DT, D2T, N, DN, D2N, B, DB, D2B);
911 myStatus = myLaw->ErrorStatus();
923 return Standard_False;
925 Standard_Real U = myFirstS +
926 (Param-myCurve->FirstParameter())*ratio;
928 math_Vector X(1,3,0);
934 // Standard_Real ETol = 1.e-6;
935 Standard_Integer Iter = 100;
938 // resoudre equation d'intersection entre surf revol et guide => angle
939 GeomFill_FunctionGuide E (mySec, myGuide, myFirstS +
940 (Param-myCurve->FirstParameter())*ratio);
941 E.SetParam(Param, P, T, N);
944 math_FunctionSetRoot Result(E, X, TolRes,
949 Result.Root(R); // solution
951 //gp_Pnt2d p (R(2), R(3)); // point sur la surface (angle, v)
952 //Poles2d.SetValue(1,p);
954 // derivee de la fonction
955 math_Vector DEDT(1,3,0);
956 E.DerivT(Param, Param0, R, R0, DEDT); // dE/dt => DEDT
957 math_Vector DSDT (1,3,0);
958 math_Matrix DEDX (1,3,1,3,0);
959 E.Derivatives(R, DEDX); // dE/dx au point R => DEDX
961 // resolution du syst. lin. : DEDX*DSDT = -DEDT
965 Ga.Solve (DEDT.Opposite(), DSDT); // resolution du syst. lin.
966 //gp_Vec2d dp (DSDT(2), DSDT(3)); // surface
967 //DPoles2d.SetValue(1, dp);
969 else cout <<"LocationGuide::D2 : No Result dans la derivee premiere"<<endl;
972 GeomFill_Tensor D2EDX2(3,3,3);
973 E.Deriv2X(R, D2EDX2); // d2E/dx2
975 math_Vector D2EDT2(1,3,0);
977 // if(Param1 < Param && Param < Param0)
978 E.Deriv2T(Param1, Param, Param0, R1, R, R0, D2EDT2); // d2E/dt2
979 // else if (Param < Param0 && Param0 < Param1)
980 // E.Deriv2T(Param, Param0, Param1, R, R0, R1, D2EDT2); // d2E/dt2
982 // E.Deriv2T(Param0, Param1, Param, R0, R1, R, D2EDT2); // d2E/dt2
984 math_Matrix D2EDTDX(1,3,1,3,0);
985 E.DerivTX(Param, Param0, R, R0, D2EDTDX); // d2E/dtdx
987 math_Vector D2SDT2(1,3,0); // d2s/dt2
988 math_Matrix M1(1,3,1,3,0);
989 D2EDX2.Multiply(DSDT,M1);
991 // resolution du syst. lin.
992 math_Gauss Ga1 (DEDX);
995 Ga1.Solve ( - M1*DSDT - 2*D2EDTDX*DSDT - D2EDT2 , D2SDT2);
996 //gp_Vec2d d2p (D2SDT2(2), D2SDT2(3)); // surface
997 //D2Poles2d.SetValue(1, d2p);
1000 cout <<"LocationGuide::D2 : No Result dans la derivee seconde"<<endl;
1001 myStatus = GeomFill_ImpossibleContact;
1004 //------------------------------------------
1006 //------------------------------------------
1011 Tr.SetRotation(Axe, R(2));
1021 M.SetCols(N.XYZ(), B.XYZ(), T.XYZ());
1023 //------------------------------------------
1024 // derivees de la rotation
1026 //-----------------------------------------
1027 gp_Vec db,dn,db3,dn3;
1031 gp_Vec db1,dn1,db2,dn2;
1033 //transfo entre triedre et Oxyz
1034 gp_Ax3 RepTriedre4(Q,D,B2);
1036 Transfo3.SetTransformation(Rep,RepTriedre4);
1038 //on passe dans le repere du triedre
1039 n.Transform(Transfo3);
1040 b.Transform(Transfo3);
1041 n2.Transform(Transfo3);
1042 b2.Transform(Transfo3);
1043 dn.Transform(Transfo3);
1044 db.Transform(Transfo3);
1045 dn3.Transform(Transfo3);
1046 db3.Transform(Transfo3);
1047 D2N.Transform(Transfo3);
1048 D2B.Transform(Transfo3);
1050 //matrices de rotation et derivees
1051 Standard_Real A = R(2);
1052 Standard_Real Aprim = DSDT(2);
1053 Standard_Real Asec = D2SDT2(2);
1055 gp_Mat M2 (Cos(A),-Sin(A),0, // rotation autour de T
1059 gp_Mat M2prim (-Sin(A),-Cos(A),0, // derivee 1ere rotation autour de T
1063 gp_Mat M2sec (-Cos(A), Sin(A), 0, // derivee 2nde rotation autour de T
1064 -Sin(A), -Cos(A), 0,
1066 M2sec.Multiply(Aprim*Aprim);
1067 gp_Mat M2p = M2prim.Multiplied(Asec);
1070 M2prim.Multiply(Aprim);
1074 Rot.SetValues(M2(1,1),M2(1,2),M2(1,3),0,
1075 M2(2,1),M2(2,2),M2(2,3),0,
1076 M2(3,1),M2(3,2),M2(3,3),0,
1079 DRot.SetValues(M2prim(1,1),M2prim(1,2),M2prim(1,3),0,
1080 M2prim(2,1),M2prim(2,2),M2prim(2,3),0,
1081 M2prim(3,1),M2prim(3,2),M2prim(3,3),0,
1085 D2Rot.SetValues(M2sec(1,1),M2sec(1,2),M2sec(1,3),0,
1086 M2sec(2,1),M2sec(2,2),M2sec(2,3),0,
1087 M2sec(3,1),M2sec(3,2),M2sec(3,3),0,
1098 dn1.Transform(Transfo3.Inverted());
1099 db1.Transform(Transfo3.Inverted());
1101 DM.SetCols(dn1.XYZ(), db1.XYZ(), DT.XYZ());
1106 dn3.Transform(DRot);
1107 db3.Transform(DRot);
1108 n2.Transform(D2Rot);
1109 b2.Transform(D2Rot);
1110 dn2 = n2 + 2*dn3 + D2N;
1111 db2 = b2 + 2*db3 + D2B;
1112 dn2.Transform(Transfo3.Inverted());
1113 db2.Transform(Transfo3.Inverted());
1115 D2M.SetCols(dn2.XYZ(), db2.XYZ(), D2T.XYZ());
1120 cout << "LocationGuide::D2 : No Result !!" <<endl;
1121 TraceRevol(Param, U, myLaw, mySec, myCurve, Trans);
1123 return Standard_False;
1129 M.SetCols(N.XYZ(), B.XYZ(), T.XYZ());
1130 DM.SetCols(DN.XYZ(), DB.XYZ(), DT.XYZ());
1131 D2M.SetCols(D2N.XYZ(), D2B.XYZ(), D2T.XYZ());
1134 return Standard_True;
1135 // return Standard_False;
1138 //==================================================================
1139 //Function : HasFirstRestriction
1141 //==================================================================
1142 Standard_Boolean GeomFill_LocationGuide::HasFirstRestriction() const
1144 return Standard_False;
1147 //==================================================================
1148 //Function : HasLastRestriction
1150 //==================================================================
1151 Standard_Boolean GeomFill_LocationGuide::HasLastRestriction() const
1153 return Standard_False;
1156 //==================================================================
1157 //Function : TraceNumber
1159 //==================================================================
1160 Standard_Integer GeomFill_LocationGuide::TraceNumber() const
1165 //==================================================================
1166 //Function : ErrorStatus
1168 //==================================================================
1169 GeomFill_PipeError GeomFill_LocationGuide::ErrorStatus() const
1174 //==================================================================
1175 //Function:NbIntervals
1177 //==================================================================
1178 Standard_Integer GeomFill_LocationGuide::NbIntervals
1179 (const GeomAbs_Shape S) const
1181 Standard_Integer Nb_Sec, Nb_Law;
1182 Nb_Sec = myTrimmed->NbIntervals(S);
1183 Nb_Law = myLaw->NbIntervals(S);
1188 else if (Nb_Law==1) {
1192 TColStd_Array1OfReal IntC(1, Nb_Sec+1);
1193 TColStd_Array1OfReal IntL(1, Nb_Law+1);
1194 TColStd_SequenceOfReal Inter;
1195 myTrimmed->Intervals(IntC, S);
1196 myLaw->Intervals(IntL, S);
1198 GeomLib::FuseIntervals( IntC, IntL, Inter, Precision::PConfusion()*0.99);
1199 return Inter.Length()-1;
1203 //==================================================================
1204 //Function:Intervals
1206 //==================================================================
1207 void GeomFill_LocationGuide::Intervals(TColStd_Array1OfReal& T,
1208 const GeomAbs_Shape S) const
1210 Standard_Integer Nb_Sec, Nb_Law;
1211 Nb_Sec = myTrimmed->NbIntervals(S);
1212 Nb_Law = myLaw->NbIntervals(S);
1215 myLaw->Intervals(T, S);
1218 else if (Nb_Law==1) {
1219 myTrimmed->Intervals(T, S);
1223 TColStd_Array1OfReal IntC(1, Nb_Sec+1);
1224 TColStd_Array1OfReal IntL(1, Nb_Law+1);
1225 TColStd_SequenceOfReal Inter;
1226 myTrimmed->Intervals(IntC, S);
1227 myLaw->Intervals(IntL, S);
1229 GeomLib::FuseIntervals(IntC, IntL, Inter, Precision::PConfusion()*0.99);
1230 for (Standard_Integer ii=1; ii<=Inter.Length(); ii++)
1234 //==================================================================
1235 //Function:SetInterval
1237 //==================================================================
1238 void GeomFill_LocationGuide::SetInterval(const Standard_Real First,
1239 const Standard_Real Last)
1241 myLaw->SetInterval(First, Last);
1242 myTrimmed = myCurve->Trim(First, Last, 0);
1244 //==================================================================
1245 //Function: GetInterval
1247 //==================================================================
1248 void GeomFill_LocationGuide::GetInterval(Standard_Real& First,
1249 Standard_Real& Last) const
1251 First = myTrimmed->FirstParameter();
1252 Last = myTrimmed->LastParameter();
1255 //==================================================================
1256 //Function: GetDomain
1258 //==================================================================
1259 void GeomFill_LocationGuide::GetDomain(Standard_Real& First,
1260 Standard_Real& Last) const
1262 First = myCurve->FirstParameter();
1263 Last = myCurve->LastParameter();
1266 //==================================================================
1267 //function : SetTolerance
1269 //==================================================================
1270 void GeomFill_LocationGuide::SetTolerance(const Standard_Real Tol3d,
1271 const Standard_Real )
1273 TolRes(1) = myGuide->Resolution(Tol3d);
1274 Resolution(1, Tol3d, TolRes(2), TolRes(3));
1278 //==================================================================
1279 //function : Resolution
1280 //purpose : A definir
1281 //==================================================================
1282 //void GeomFill_LocationGuide::Resolution (const Standard_Integer Index,
1283 void GeomFill_LocationGuide::Resolution (const Standard_Integer ,
1284 const Standard_Real Tol,
1285 Standard_Real& TolU,
1286 Standard_Real& TolV) const
1292 //==================================================================
1293 //Function:GetMaximalNorm
1294 //Purpose : On suppose les triedres normes => return 1
1295 //==================================================================
1296 Standard_Real GeomFill_LocationGuide::GetMaximalNorm()
1301 //==================================================================
1302 //Function:GetAverageLaw
1304 //==================================================================
1305 void GeomFill_LocationGuide::GetAverageLaw(gp_Mat& AM,
1308 Standard_Integer ii;
1309 Standard_Real U, delta;
1310 gp_Vec V, V1, V2, V3;
1312 myLaw->GetAverageLaw(V1, V2, V3);
1313 AM.SetCols(V1.XYZ(), V2.XYZ(), V3.XYZ());
1315 AV.SetCoord(0., 0., 0.);
1316 delta = (myTrimmed->LastParameter() - myTrimmed->FirstParameter())/10;
1317 U = myTrimmed->FirstParameter();
1318 for (ii=0; ii<=myNbPts; ii++, U+=delta) {
1319 V.SetXYZ( myTrimmed->Value(U).XYZ() );
1322 AV = AV/(myNbPts+1);
1326 //==================================================================
1327 //Function : Section
1329 //==================================================================
1330 Handle(Geom_Curve) GeomFill_LocationGuide::Section() const
1332 return mySec->ConstantSection();
1335 //==================================================================
1338 //==================================================================
1339 Handle(Adaptor3d_HCurve) GeomFill_LocationGuide::Guide() const
1344 //==================================================================
1345 //Function : IsRotation
1347 //==================================================================
1348 // Standard_Boolean GeomFill_LocationGuide::IsRotation(Standard_Real& Error) const
1349 Standard_Boolean GeomFill_LocationGuide::IsRotation(Standard_Real& ) const
1351 return Standard_False;
1354 //==================================================================
1355 //Function : Rotation
1357 //==================================================================
1358 // void GeomFill_LocationGuide::Rotation(gp_Pnt& Centre) const
1359 void GeomFill_LocationGuide::Rotation(gp_Pnt& ) const
1361 Standard_NotImplemented::Raise("GeomFill_LocationGuide::Rotation");
1364 //==================================================================
1365 //Function : IsTranslation
1367 //==================================================================
1368 // Standard_Boolean GeomFill_LocationGuide::IsTranslation(Standard_Real& Error) const
1369 Standard_Boolean GeomFill_LocationGuide::IsTranslation(Standard_Real& ) const
1371 return Standard_False;
1374 //==================================================================
1376 //Purpose : recherche par interpolation d'une valeur initiale
1377 //==================================================================
1378 void GeomFill_LocationGuide::InitX(const Standard_Real Param) const
1381 Standard_Integer Ideb = 1, Ifin = myPoles2d->RowLength(), Idemi;
1382 Standard_Real Valeur, t1, t2;
1385 Valeur = myPoles2d->Value(1, Ideb).X();
1386 if (Param == Valeur) {
1390 Valeur = myPoles2d->Value(1, Ifin).X();
1391 if (Param == Valeur) {
1395 while ( Ideb+1 != Ifin) {
1396 Idemi = (Ideb+Ifin)/2;
1397 Valeur = myPoles2d->Value(1, Idemi).X();
1398 if (Valeur < Param) {
1402 if ( Valeur > Param) { Ifin = Idemi;}
1410 t1 = myPoles2d->Value(1,Ideb).X();
1411 t2 = myPoles2d->Value(1,Ifin).X();
1412 Standard_Real diff = t2-t1;
1414 Standard_Real W1, W2;
1415 W1 = myPoles2d->Value(1,Ideb).Coord(2);
1416 W2 = myPoles2d->Value(1,Ifin).Coord(2);
1417 const gp_Pnt2d& P1 = myPoles2d->Value(2, Ideb);
1418 const gp_Pnt2d& P2 = myPoles2d->Value(2, Ifin);
1421 Standard_Real b = (Param-t1) / diff,
1422 a = (t2-Param) / diff;
1423 X(1) = a * W1 + b * W2;
1424 X(2) = a * P1.Coord(1) + b * P2.Coord(1); // angle
1425 X(3) = a * P1.Coord(2) + b * P2.Coord(2); // param isov
1429 X(2) = (P1.Coord(1) + P2.Coord(1)) /2;
1430 X(3) = (P1.Coord(2) + P2.Coord(2)) /2;
1433 if (myGuide->IsPeriodic()) {
1434 X(1) = ElCLib::InPeriod(X(1), myGuide->FirstParameter(),
1435 myGuide->LastParameter());
1437 X(2) = ElCLib::InPeriod(X(2), 0, 2*M_PI);
1438 if (mySec->IsUPeriodic()) {
1439 X(3) = ElCLib::InPeriod(X(3), Uf, Ul);
1444 //==================================================================
1445 //Function : SetOrigine
1446 //Purpose : utilise pour ACR dans le cas ou la trajectoire est multi-edges
1447 //==================================================================
1448 void GeomFill_LocationGuide::SetOrigine(const Standard_Real Param1,
1449 const Standard_Real Param2)
1451 OrigParam1 = Param1;
1452 OrigParam2 = Param2;
1455 //==================================================================
1456 //Function : ComputeAutomaticLaw
1458 //==================================================================
1459 GeomFill_PipeError GeomFill_LocationGuide::ComputeAutomaticLaw(Handle(TColgp_HArray1OfPnt2d)& ParAndRad) const
1463 Standard_Integer ii;
1466 GeomFill_PipeError theStatus = GeomFill_PipeOk;
1468 Standard_Real f = myCurve->FirstParameter();
1469 Standard_Real l = myCurve->LastParameter();
1471 ParAndRad = new TColgp_HArray1OfPnt2d(1, myNbPts);
1472 for (ii = 1; ii <= myNbPts; ii++)
1474 t = Standard_Real(myNbPts - ii)*f + Standard_Real(ii - 1)*l;
1477 Standard_Boolean Ok = myLaw->D0(t, T, N, B);
1480 theStatus = myLaw->ErrorStatus();
1483 gp_Pnt PointOnGuide = myLaw->CurrentPointOnGuide();
1484 Standard_Real CurWidth = P.Distance(PointOnGuide);
1486 gp_Pnt2d aParamWithRadius(t, CurWidth);
1487 ParAndRad->SetValue(ii, aParamWithRadius);