1 // Created by: Stephanie HUMEAU
2 // Copyright (c) 1998-1999 Matra Datavision
3 // Copyright (c) 1999-2014 OPEN CASCADE SAS
5 // This file is part of Open CASCADE Technology software library.
7 // This library is free software; you can redistribute it and/or modify it under
8 // the terms of the GNU Lesser General Public License version 2.1 as published
9 // by the Free Software Foundation, with special exception defined in the file
10 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
11 // distribution for complete text of the license and disclaimer of any warranty.
13 // Alternatively, this file may be used under the terms of Open CASCADE
14 // commercial license or contractual agreement.
16 // Creted: Tue Jun 23 15:39:24 1998
19 #include <GeomFill_GuideTrihedronAC.ixx>
24 #include <Precision.hxx>
25 #include <TColStd_SequenceOfReal.hxx>
27 #include <Approx_CurvlinFunc.hxx>
28 #include <Adaptor3d_Curve.hxx>
29 #include <GeomAdaptor.hxx>
30 #include <GeomAdaptor_HCurve.hxx>
32 #include <GeomFill_Frenet.hxx>
33 #include <GeomLib.hxx>
36 //=======================================================================
37 //function : GuideTrihedron
38 //purpose : Constructor
39 //=======================================================================
40 GeomFill_GuideTrihedronAC::GeomFill_GuideTrihedronAC(const Handle(Adaptor3d_HCurve) & guide)
45 myGuideAC = new (Approx_CurvlinFunc) (myGuide,1.e-7);
46 Lguide = myGuideAC->GetLength();
47 UTol = STol = Precision::PConfusion();
48 Orig1 = 0; // origines pour le cas path multi-edges
52 //=======================================================================
54 //purpose : calculation of trihedron
55 //=======================================================================
57 Handle(Adaptor3d_HCurve) GeomFill_GuideTrihedronAC::Guide()const
62 //=======================================================================
64 //purpose : calculation of trihedron
65 //=======================================================================
66 Standard_Boolean GeomFill_GuideTrihedronAC::D0(const Standard_Real Param,
71 Standard_Real s = myCurveAC->GetSParameter(Param); // abscisse curviligne <=> Param
72 Standard_Real OrigG = Orig1 + s*(Orig2-Orig1); // abscisse curv sur le guide (cas multi-edges)
73 Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1); // param <=> s sur theGuide
77 myTrimmed->D1(Param, P, To);//point et derivee au parametre Param sur myCurve
78 myTrimG->D0(tG, PG);// point au parametre tG sur myGuide
79 myCurPointOnGuide = PG;
81 gp_Vec n (P, PG); // vecteur definissant la normale
83 Normal = n.Normalized();
84 B = To.Crossed(Normal);
85 BiNormal = B/B.Magnitude();
86 Tangent = Normal.Crossed(BiNormal);
92 //=======================================================================
94 //purpose : calculation of trihedron and first derivative
95 //=======================================================================
96 Standard_Boolean GeomFill_GuideTrihedronAC::D1(const Standard_Real Param,
105 Standard_Real s, OrigG, tG, dtg;
106 // abscisse curviligne <=> Param
107 s = myCurveAC->GetSParameter(Param);
108 // parametre <=> s sur theGuide
109 OrigG = Orig1 + s*(Orig2-Orig1);
110 // parametre <=> s sur theGuide
111 tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1);
114 gp_Vec To, DTo, TG, B, BPrim;
116 myTrimmed->D2(Param, P, To, DTo);
117 myTrimG->D1(tG, PG, TG);
118 myCurPointOnGuide = PG;
120 gp_Vec n (P, PG), dn;
121 Standard_Real Norm = n.Magnitude();
125 cout << "GuideTrihedronAC : Normal indefinie" << endl;
130 //derivee de n par rapport a Param
131 dtg = (Orig2-Orig1)*(To.Magnitude()/TG.Magnitude())*(Lguide/L);
132 dn.SetLinearForm(dtg, TG, -1, To);
137 B = To.Crossed(Normal);
138 Standard_Real NormB = B.Magnitude();
143 Tangent = Normal.Crossed(BiNormal);
147 DNormal.SetLinearForm(-(n.Dot(dn)), n, dn);
149 BPrim.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal));
151 DBiNormal.SetLinearForm(-(B.Dot(BPrim)), B, BPrim);
154 DTangent.SetLinearForm(Normal.Crossed(DBiNormal), DNormal.Crossed(BiNormal));
156 return Standard_True;
160 //=======================================================================
162 //purpose : calculation of trihedron and derivatives
163 //=======================================================================
164 Standard_Boolean GeomFill_GuideTrihedronAC::D2(const Standard_Real Param,
175 // abscisse curviligne <=> Param
176 Standard_Real s = myCurveAC->GetSParameter(Param);
177 // parametre <=> s sur theGuide
178 Standard_Real OrigG = Orig1 + s*(Orig2-Orig1);
179 Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(),
184 // gp_Vec To,DTo,D2To,B;
187 myTrimmed->D3(Param, P, To, DTo, D2To);
188 myTrimG->D2(tG, PG, TG, DTG);
189 myCurPointOnGuide = PG;
191 Standard_Real NTo = To.Magnitude();
192 Standard_Real N2To = To.SquareMagnitude();
193 Standard_Real NTG = TG.Magnitude();
194 Standard_Real N2Tp = TG.SquareMagnitude();
195 Standard_Real d2tp_dt2, dtg_dt;
196 dtg_dt = (Orig2-Orig1)*(NTo/NTG)*(Lguide/L);
198 gp_Vec n(P, PG); // vecteur definissant la normale
199 Standard_Real Norm = n.Magnitude(), ndn;
200 //derivee de n par rapport a Param
202 dn.SetLinearForm(dtg_dt, TG, -1, To);
204 //derivee seconde de tG par rapport a Param
205 d2tp_dt2 = (Orig2-Orig1)*(Lguide/L) *
206 ( DTo.Dot(To) / (NTo*NTG) - N2To*TG*DTG*(Lguide/L) / (N2Tp*N2Tp));
207 //derivee seconde de n par rapport a Param
208 d2n.SetLinearForm(dtg_dt*dtg_dt,DTG, d2tp_dt2, TG, -1, DTo);
218 gp_Vec TN, DTN, D2TN;
219 TN = To.Crossed(Normal);
222 Standard_Real Norma = TN.Magnitude();
223 if (Norma > 1.e-9) TN /= Norma;
227 Tangent = Normal.Crossed(BiNormal);
228 // Tangent.Normalize();
230 // derivee premiere du triedre
231 // gp_Vec DTN = DTo.Crossed(Normal);
232 // gp_Vec TDN = To.Crossed(DNormal);
233 // gp_Vec DT = DTN + TDN;
236 DNormal.SetLinearForm(-ndn, n, dn);
238 DTN.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal));
240 Standard_Real TNDTN = TN.Dot(DTN);
242 DBiNormal.SetLinearForm(-TNDTN, TN, DTN);
244 DTangent.SetLinearForm(Normal.Crossed(DBiNormal),
245 DNormal.Crossed(BiNormal));
248 //derivee seconde du triedre
250 gp_Vec DTDN = DTo.Crossed(DNormal);
252 DTo.Crossed(DNormal);
254 Standard_Real TN2 = TN.SquareMagnitude();
256 D2Normal.SetLinearForm(-2*ndn, dn,
257 3*ndn*ndn - (dn.SquareMagnitude() + n.Dot(d2n)),n,
261 D2TN.SetLinearForm(1, D2To.Crossed(Normal),
262 2, DTo.Crossed(DNormal),
263 To.Crossed(D2Normal));
266 D2BiNormal.SetLinearForm(-2*TNDTN, DTN,
267 3*TNDTN*TNDTN - (TN2 + TN.Dot(D2TN)), TN,
270 D2Tangent.SetLinearForm(1, D2Normal.Crossed(BiNormal),
271 2, DNormal.Crossed(DBiNormal),
272 Normal.Crossed(D2BiNormal) );
274 // return Standard_True;
275 return Standard_False;
280 //=======================================================================
283 //=======================================================================
284 Handle(GeomFill_TrihedronLaw) GeomFill_GuideTrihedronAC::Copy() const
286 Handle(GeomFill_GuideTrihedronAC) copy =
287 new (GeomFill_GuideTrihedronAC) (myGuide);
288 copy->SetCurve(myCurve);
289 copy->Origine(Orig1,Orig2);
293 //=======================================================================
294 //function : SetCurve
296 //=======================================================================
297 void GeomFill_GuideTrihedronAC::SetCurve(const Handle(Adaptor3d_HCurve)& C)
301 if (!myCurve.IsNull()) {
302 myCurveAC = new (Approx_CurvlinFunc) (C,1.e-7);
303 L = myCurveAC->GetLength();
304 // CorrectOrient(myGuide);
309 //=======================================================================
310 //function : NbIntervals
312 //=======================================================================
313 Standard_Integer GeomFill_GuideTrihedronAC::NbIntervals(const GeomAbs_Shape S) const
316 Nb = myCurveAC->NbIntervals(S);
317 TColStd_Array1OfReal DiscC(1, Nb+1);
318 myCurveAC->Intervals(DiscC, S);
319 Nb = myGuideAC->NbIntervals(S);
320 TColStd_Array1OfReal DiscG(1, Nb+1);
321 myGuideAC->Intervals(DiscG, S);
323 TColStd_SequenceOfReal Seq;
324 GeomLib::FuseIntervals(DiscC, DiscG, Seq);
326 return Seq.Length()-1;
330 //======================================================================
331 //function :Intervals
333 //=======================================================================
334 void GeomFill_GuideTrihedronAC::Intervals(TColStd_Array1OfReal& TT,
335 const GeomAbs_Shape S) const
337 Standard_Integer Nb, ii;
338 Nb = myCurveAC->NbIntervals(S);
339 TColStd_Array1OfReal DiscC(1, Nb+1);
340 myCurveAC->Intervals(DiscC, S);
341 Nb = myGuideAC->NbIntervals(S);
342 TColStd_Array1OfReal DiscG(1, Nb+1);
343 myGuideAC->Intervals(DiscG, S);
345 TColStd_SequenceOfReal Seq;
346 GeomLib::FuseIntervals(DiscC, DiscG, Seq);
349 for (ii=1; ii<=Nb; ii++) {
350 TT(ii) = myCurveAC->GetUParameter(myCurve->GetCurve(), Seq(ii), 1);
355 //======================================================================
356 //function :SetInterval
358 //=======================================================================
359 void GeomFill_GuideTrihedronAC::SetInterval(const Standard_Real First,
360 const Standard_Real Last)
362 myTrimmed = myCurve->Trim(First, Last, UTol);
363 Standard_Real Sf, Sl, U;
365 Sf = myCurveAC->GetSParameter(First);
366 Sl = myCurveAC->GetSParameter(Last);
368 // myCurveAC->Trim(Sf, Sl, UTol);
370 U = Orig1 + Sf*(Orig2-Orig1);
371 Sf = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1);
372 U = Orig1 + Sl*(Orig2-Orig1);
373 Sl = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1);
374 myTrimG = myGuide->Trim(Sf, Sl, UTol);
379 //=======================================================================
380 //function : GetAverageLaw
382 //=======================================================================
383 void GeomFill_GuideTrihedronAC::GetAverageLaw(gp_Vec& ATangent,
388 Standard_Real t, Delta = (myCurve->LastParameter() -
389 myCurve->FirstParameter())/20.001;
391 ATangent.SetCoord(0.,0.,0.);
392 ANormal.SetCoord(0.,0.,0.);
393 ABiNormal.SetCoord(0.,0.,0.);
396 for (ii=1; ii<=20; ii++) {
397 t = myCurve->FirstParameter() +(ii-1)*Delta;
408 //=======================================================================
409 //function : IsConstant
411 //=======================================================================
412 Standard_Boolean GeomFill_GuideTrihedronAC::IsConstant() const
414 return Standard_False;
417 //=======================================================================
418 //function : IsOnlyBy3dCurve
420 //=======================================================================
421 Standard_Boolean GeomFill_GuideTrihedronAC::IsOnlyBy3dCurve() const
423 return Standard_False;
426 //=======================================================================
429 //=======================================================================
430 void GeomFill_GuideTrihedronAC::Origine(const Standard_Real OrACR1,
431 const Standard_Real OrACR2)