1 // Created by: Stephanie HUMEAU
2 // Copyright (c) 1998-1999 Matra Datavision
3 // Copyright (c) 1999-2012 OPEN CASCADE SAS
5 // The content of this file is subject to the Open CASCADE Technology Public
6 // License Version 6.5 (the "License"). You may not use the content of this file
7 // except in compliance with the License. Please obtain a copy of the License
8 // at http://www.opencascade.org and read it completely before using this file.
10 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 // The Original Code and all software distributed under the License is
14 // distributed on an "AS IS" basis, without warranty of any kind, and the
15 // Initial Developer hereby disclaims all such warranties, including without
16 // limitation, any warranties of merchantability, fitness for a particular
17 // purpose or non-infringement. Please see the License for the specific terms
18 // and conditions governing the rights and limitations under the License.
20 // Creted: Tue Jun 23 15:39:24 1998
23 #include <GeomFill_GuideTrihedronAC.ixx>
28 #include <Precision.hxx>
29 #include <TColStd_SequenceOfReal.hxx>
31 #include <Approx_CurvlinFunc.hxx>
32 #include <Adaptor3d_Curve.hxx>
33 #include <GeomAdaptor.hxx>
34 #include <GeomAdaptor_HCurve.hxx>
36 #include <GeomFill_Frenet.hxx>
37 #include <GeomLib.hxx>
40 //=======================================================================
41 //function : GuideTrihedron
42 //purpose : Constructor
43 //=======================================================================
44 GeomFill_GuideTrihedronAC::GeomFill_GuideTrihedronAC(const Handle(Adaptor3d_HCurve) & guide)
49 myGuideAC = new (Approx_CurvlinFunc) (myGuide,1.e-7);
50 Lguide = myGuideAC->GetLength();
51 UTol = STol = Precision::PConfusion();
52 Orig1 = 0; // origines pour le cas path multi-edges
56 //=======================================================================
58 //purpose : calculation of trihedron
59 //=======================================================================
61 Handle(Adaptor3d_HCurve) GeomFill_GuideTrihedronAC::Guide()const
66 //=======================================================================
68 //purpose : calculation of trihedron
69 //=======================================================================
70 Standard_Boolean GeomFill_GuideTrihedronAC::D0(const Standard_Real Param,
75 Standard_Real s = myCurveAC->GetSParameter(Param); // abscisse curviligne <=> Param
76 Standard_Real OrigG = Orig1 + s*(Orig2-Orig1); // abscisse curv sur le guide (cas multi-edges)
77 Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1); // param <=> s sur theGuide
81 myTrimmed->D1(Param, P, To);//point et derivee au parametre Param sur myCurve
82 myTrimG->D0(tG, PG);// point au parametre tG sur myGuide
84 gp_Vec n (P, PG); // vecteur definissant la normale
86 Normal = n.Normalized();
87 B = To.Crossed(Normal);
88 BiNormal = B/B.Magnitude();
89 Tangent = Normal.Crossed(BiNormal);
95 //=======================================================================
97 //purpose : calculation of trihedron and first derivative
98 //=======================================================================
99 Standard_Boolean GeomFill_GuideTrihedronAC::D1(const Standard_Real Param,
108 Standard_Real s, OrigG, tG, dtg;
109 // abscisse curviligne <=> Param
110 s = myCurveAC->GetSParameter(Param);
111 // parametre <=> s sur theGuide
112 OrigG = Orig1 + s*(Orig2-Orig1);
113 // parametre <=> s sur theGuide
114 tG = myGuideAC->GetUParameter(myGuide->GetCurve(), OrigG, 1);
117 gp_Vec To, DTo, TG, B, BPrim;
119 myTrimmed->D2(Param, P, To, DTo);
120 myTrimG->D1(tG, PG, TG);
122 gp_Vec n (P, PG), dn;
123 Standard_Real Norm = n.Magnitude();
127 cout << "GuideTrihedronAC : Normal indefinie" << endl;
132 //derivee de n par rapport a Param
133 dtg = (Orig2-Orig1)*(To.Magnitude()/TG.Magnitude())*(Lguide/L);
134 dn.SetLinearForm(dtg, TG, -1, To);
139 B = To.Crossed(Normal);
140 Standard_Real NormB = B.Magnitude();
145 Tangent = Normal.Crossed(BiNormal);
149 DNormal.SetLinearForm(-(n.Dot(dn)), n, dn);
151 BPrim.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal));
153 DBiNormal.SetLinearForm(-(B.Dot(BPrim)), B, BPrim);
156 DTangent.SetLinearForm(Normal.Crossed(DBiNormal), DNormal.Crossed(BiNormal));
158 return Standard_True;
162 //=======================================================================
164 //purpose : calculation of trihedron and derivatives
165 //=======================================================================
166 Standard_Boolean GeomFill_GuideTrihedronAC::D2(const Standard_Real Param,
177 // abscisse curviligne <=> Param
178 Standard_Real s = myCurveAC->GetSParameter(Param);
179 // parametre <=> s sur theGuide
180 Standard_Real OrigG = Orig1 + s*(Orig2-Orig1);
181 Standard_Real tG = myGuideAC->GetUParameter(myGuide->GetCurve(),
186 // gp_Vec To,DTo,D2To,B;
189 myTrimmed->D3(Param, P, To, DTo, D2To);
190 myTrimG->D2(tG, PG, TG, DTG);
192 Standard_Real NTo = To.Magnitude();
193 Standard_Real N2To = To.SquareMagnitude();
194 Standard_Real NTG = TG.Magnitude();
195 Standard_Real N2Tp = TG.SquareMagnitude();
196 Standard_Real d2tp_dt2, dtg_dt;
197 dtg_dt = (Orig2-Orig1)*(NTo/NTG)*(Lguide/L);
199 gp_Vec n(P, PG); // vecteur definissant la normale
200 Standard_Real Norm = n.Magnitude(), ndn;
201 //derivee de n par rapport a Param
203 dn.SetLinearForm(dtg_dt, TG, -1, To);
205 //derivee seconde de tG par rapport a Param
206 d2tp_dt2 = (Orig2-Orig1)*(Lguide/L) *
207 ( DTo.Dot(To) / (NTo*NTG) - N2To*TG*DTG*(Lguide/L) / (N2Tp*N2Tp));
208 //derivee seconde de n par rapport a Param
209 d2n.SetLinearForm(dtg_dt*dtg_dt,DTG, d2tp_dt2, TG, -1, DTo);
219 gp_Vec TN, DTN, D2TN;
220 TN = To.Crossed(Normal);
223 Standard_Real Norma = TN.Magnitude();
224 if (Norma > 1.e-9) TN /= Norma;
228 Tangent = Normal.Crossed(BiNormal);
229 // Tangent.Normalize();
231 // derivee premiere du triedre
232 // gp_Vec DTN = DTo.Crossed(Normal);
233 // gp_Vec TDN = To.Crossed(DNormal);
234 // gp_Vec DT = DTN + TDN;
237 DNormal.SetLinearForm(-ndn, n, dn);
239 DTN.SetLinearForm(DTo.Crossed(Normal), To.Crossed(DNormal));
241 Standard_Real TNDTN = TN.Dot(DTN);
243 DBiNormal.SetLinearForm(-TNDTN, TN, DTN);
245 DTangent.SetLinearForm(Normal.Crossed(DBiNormal),
246 DNormal.Crossed(BiNormal));
249 //derivee seconde du triedre
251 gp_Vec DTDN = DTo.Crossed(DNormal);
253 DTo.Crossed(DNormal);
255 Standard_Real TN2 = TN.SquareMagnitude();
257 D2Normal.SetLinearForm(-2*ndn, dn,
258 3*ndn*ndn - (dn.SquareMagnitude() + n.Dot(d2n)),n,
262 D2TN.SetLinearForm(1, D2To.Crossed(Normal),
263 2, DTo.Crossed(DNormal),
264 To.Crossed(D2Normal));
267 D2BiNormal.SetLinearForm(-2*TNDTN, DTN,
268 3*TNDTN*TNDTN - (TN2 + TN.Dot(D2TN)), TN,
271 D2Tangent.SetLinearForm(1, D2Normal.Crossed(BiNormal),
272 2, DNormal.Crossed(DBiNormal),
273 Normal.Crossed(D2BiNormal) );
275 // return Standard_True;
276 return Standard_False;
281 //=======================================================================
284 //=======================================================================
285 Handle(GeomFill_TrihedronLaw) GeomFill_GuideTrihedronAC::Copy() const
287 Handle(GeomFill_GuideTrihedronAC) copy =
288 new (GeomFill_GuideTrihedronAC) (myGuide);
289 copy->SetCurve(myCurve);
290 copy->Origine(Orig1,Orig2);
294 //=======================================================================
295 //function : SetCurve
297 //=======================================================================
298 void GeomFill_GuideTrihedronAC::SetCurve(const Handle(Adaptor3d_HCurve)& C)
302 if (!myCurve.IsNull()) {
303 myCurveAC = new (Approx_CurvlinFunc) (C,1.e-7);
304 L = myCurveAC->GetLength();
305 // CorrectOrient(myGuide);
310 //=======================================================================
311 //function : NbIntervals
313 //=======================================================================
314 Standard_Integer GeomFill_GuideTrihedronAC::NbIntervals(const GeomAbs_Shape S) const
317 Nb = myCurveAC->NbIntervals(S);
318 TColStd_Array1OfReal DiscC(1, Nb+1);
319 myCurveAC->Intervals(DiscC, S);
320 Nb = myGuideAC->NbIntervals(S);
321 TColStd_Array1OfReal DiscG(1, Nb+1);
322 myGuideAC->Intervals(DiscG, S);
324 TColStd_SequenceOfReal Seq;
325 GeomLib::FuseIntervals(DiscC, DiscG, Seq);
327 return Seq.Length()-1;
331 //======================================================================
332 //function :Intervals
334 //=======================================================================
335 void GeomFill_GuideTrihedronAC::Intervals(TColStd_Array1OfReal& TT,
336 const GeomAbs_Shape S) const
338 Standard_Integer Nb, ii;
339 Nb = myCurveAC->NbIntervals(S);
340 TColStd_Array1OfReal DiscC(1, Nb+1);
341 myCurveAC->Intervals(DiscC, S);
342 Nb = myGuideAC->NbIntervals(S);
343 TColStd_Array1OfReal DiscG(1, Nb+1);
344 myGuideAC->Intervals(DiscG, S);
346 TColStd_SequenceOfReal Seq;
347 GeomLib::FuseIntervals(DiscC, DiscG, Seq);
350 for (ii=1; ii<=Nb; ii++) {
351 TT(ii) = myCurveAC->GetUParameter(myCurve->GetCurve(), Seq(ii), 1);
356 //======================================================================
357 //function :SetInterval
359 //=======================================================================
360 void GeomFill_GuideTrihedronAC::SetInterval(const Standard_Real First,
361 const Standard_Real Last)
363 myTrimmed = myCurve->Trim(First, Last, UTol);
364 Standard_Real Sf, Sl, U;
366 Sf = myCurveAC->GetSParameter(First);
367 Sl = myCurveAC->GetSParameter(Last);
369 // myCurveAC->Trim(Sf, Sl, UTol);
371 U = Orig1 + Sf*(Orig2-Orig1);
372 Sf = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1);
373 U = Orig1 + Sl*(Orig2-Orig1);
374 Sl = myGuideAC->GetUParameter(myGuide->GetCurve(), U, 1);
375 myTrimG = myGuide->Trim(Sf, Sl, UTol);
380 //=======================================================================
381 //function : GetAverageLaw
383 //=======================================================================
384 void GeomFill_GuideTrihedronAC::GetAverageLaw(gp_Vec& ATangent,
389 Standard_Real t, Delta = (myCurve->LastParameter() -
390 myCurve->FirstParameter())/20.001;
392 ATangent.SetCoord(0.,0.,0.);
393 ANormal.SetCoord(0.,0.,0.);
394 ABiNormal.SetCoord(0.,0.,0.);
397 for (ii=1; ii<=20; ii++) {
398 t = myCurve->FirstParameter() +(ii-1)*Delta;
409 //=======================================================================
410 //function : IsConstant
412 //=======================================================================
413 Standard_Boolean GeomFill_GuideTrihedronAC::IsConstant() const
415 return Standard_False;
418 //=======================================================================
419 //function : IsOnlyBy3dCurve
421 //=======================================================================
422 Standard_Boolean GeomFill_GuideTrihedronAC::IsOnlyBy3dCurve() const
424 return Standard_False;
427 //=======================================================================
430 //=======================================================================
431 void GeomFill_GuideTrihedronAC::Origine(const Standard_Real OrACR1,
432 const Standard_Real OrACR2)