1 // Created on: 1998-04-15
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_DraftTrihedron.ixx>
19 #include <Precision.hxx>
20 #include <GeomAbs_CurveType.hxx>
21 #include <Adaptor3d_HCurve.hxx>
23 //=======================================================================
25 //purpose : computes (F/|F|)''
26 //=======================================================================
27 static gp_Vec DDeriv(const gp_Vec& F, const gp_Vec& DF, const gp_Vec& D2F)
29 Standard_Real Norma = F.Magnitude();
31 gp_Vec Result = (D2F - 2*DF*(F*DF)/(Norma*Norma))/Norma -
32 F*((DF.SquareMagnitude() + F*D2F
33 - 3*(F*DF)*(F*DF)/(Norma*Norma))/(Norma*Norma*Norma));
37 //=======================================================================
38 //function : DraftTrihedron
39 //purpose : Constructor
40 //=======================================================================
41 GeomFill_DraftTrihedron::GeomFill_DraftTrihedron(const gp_Vec& BiNormal,
42 const Standard_Real Angle)
50 //=======================================================================
53 //=======================================================================
54 void GeomFill_DraftTrihedron::SetAngle(const Standard_Real Angle)
56 myAngle = M_PI/2 + Angle;
61 //=======================================================================
63 //purpose : calculation of trihedron
64 //=======================================================================
65 Standard_Boolean GeomFill_DraftTrihedron::D0(const Standard_Real Param,
72 myTrimmed->D1(Param,P,T);
75 gp_Vec b = T.Crossed(B);
76 Standard_Real normb = b.Magnitude();
80 return Standard_False;
82 gp_Vec v = b.Crossed(T);
84 Standard_Real mu = myCos ;
87 //La Normal est portee par la regle
88 Normal.SetLinearForm(Sqrt(1-mu*mu), b, mu, v);
91 // La tangente est perpendiculaire a la normale et a la direction de depouille
92 Tangent = Normal.Crossed(B);
96 BiNormal.Cross(Normal);
101 //=======================================================================
103 //purpose : calculation of trihedron and first derivative
104 //=======================================================================
105 Standard_Boolean GeomFill_DraftTrihedron::D1(const Standard_Real Param,
116 myTrimmed->D2(Param, P, T, aux);
118 Standard_Real normT, normb;
119 normT = T.Magnitude();
121 DT.SetLinearForm(-(T.Dot(aux)), T, aux);
124 gp_Vec db, b = T.Crossed(B);
125 normb = b.Magnitude();
127 return Standard_False;
130 db.SetLinearForm( -(b.Dot(aux)), b, aux);
133 gp_Vec v = b.Crossed(T);
134 gp_Vec dv = db.Crossed(T) + b.Crossed(DT);
136 Standard_Real mu = myCos;
138 Normal.SetLinearForm(Sqrt(1-mu*mu), b, mu, v);
139 DNormal.SetLinearForm(Sqrt(1-mu*mu), db, mu, dv);
141 Tangent = Normal.Crossed(B);
142 normT = Tangent.Magnitude();
144 aux = DNormal.Crossed(B);
145 DTangent.SetLinearForm( -(Tangent.Dot(aux)), Tangent, aux);
149 BiNormal.Cross(Normal);
150 DBiNormal.SetLinearForm(DTangent.Crossed(Normal),Tangent.Crossed(DNormal));
152 return Standard_True;
155 //=======================================================================
157 //purpose : calculation of trihedron and derivatives 1 et 2
158 //=======================================================================
159 Standard_Boolean GeomFill_DraftTrihedron::D2(const Standard_Real Param,
171 gp_Vec T, DT, D2T, aux, aux2;
174 myTrimmed->D3(Param, P, T, aux, aux2);
176 Standard_Real normT, normb;
178 D2T = DDeriv(T, aux, aux2);
179 normT = T.Magnitude();
182 DT.SetLinearForm(-dot, T, aux);
185 gp_Vec db, d2b, b = T.Crossed(B);
186 normb = b.Magnitude();
188 return Standard_False;
190 aux = DT.Crossed(B); aux2 = D2T.Crossed(B);
191 d2b = DDeriv(b, aux, aux2);
194 db.SetLinearForm( -dot, b, aux);
197 gp_Vec v = b.Crossed(T);
198 gp_Vec dv = db.Crossed(T) + b.Crossed(DT);
199 gp_Vec d2v = d2b.Crossed(T) + 2*db.Crossed(DT) + b.Crossed(D2T);
202 Standard_Real mu = myCos, rac;
205 Normal .SetLinearForm( rac, b , mu, v);
206 DNormal .SetLinearForm( rac, db , mu, dv);
207 D2Normal.SetLinearForm( rac, d2b, mu, d2v);
209 Tangent = Normal.Crossed(B);
210 normT = Tangent.Magnitude();
212 aux = DNormal.Crossed(B);
213 aux2 = D2Normal.Crossed(B);
214 D2Tangent = DDeriv(Tangent, aux, aux2);
216 dot = Tangent.Dot(aux);
217 DTangent.SetLinearForm( -dot, Tangent, aux);
221 BiNormal.Cross(Normal);
222 DBiNormal.SetLinearForm(DTangent.Crossed(Normal),Tangent.Crossed(DNormal));
223 D2BiNormal.SetLinearForm(1, D2Tangent.Crossed(Normal),
224 2, DTangent.Crossed(DNormal),
225 Tangent.Crossed(D2Normal));
227 return Standard_True;
231 //=======================================================================
234 //=======================================================================
235 Handle(GeomFill_TrihedronLaw) GeomFill_DraftTrihedron::Copy() const
237 Handle(GeomFill_DraftTrihedron) copy =
238 new (GeomFill_DraftTrihedron) (B,myAngle-M_PI/2);
239 copy->SetCurve(myCurve);
243 //=======================================================================
244 //function : NbIntervals
246 //=======================================================================
247 Standard_Integer GeomFill_DraftTrihedron::NbIntervals(const GeomAbs_Shape S) const
249 GeomAbs_Shape tmpS=GeomAbs_C0;
251 case GeomAbs_C0: tmpS = GeomAbs_C2; break;
252 case GeomAbs_C1: tmpS = GeomAbs_C3; break;
255 case GeomAbs_CN: tmpS = GeomAbs_CN; break;
256 default: Standard_OutOfRange::Raise();
259 return myCurve->NbIntervals(tmpS);
262 //======================================================================
263 //function :Intervals
265 //=======================================================================
266 void GeomFill_DraftTrihedron::Intervals(TColStd_Array1OfReal& TT,
267 const GeomAbs_Shape S) const
269 GeomAbs_Shape tmpS=GeomAbs_C0;
271 case GeomAbs_C0: tmpS = GeomAbs_C2; break;
272 case GeomAbs_C1: tmpS = GeomAbs_C3; break;
275 case GeomAbs_CN: tmpS = GeomAbs_CN; break;
276 default: Standard_OutOfRange::Raise();
279 myCurve->Intervals(TT, tmpS);
282 //=======================================================================
283 //function : GetAverageLaw
285 //=======================================================================
286 void GeomFill_DraftTrihedron::GetAverageLaw(gp_Vec& ATangent,
290 Standard_Integer Num = 20; //order of digitalization
292 ATangent = gp_Vec(0, 0, 0);
293 ANormal = gp_Vec(0, 0, 0);
294 ABiNormal = gp_Vec(0, 0, 0);
296 Standard_Real Step = (myTrimmed->LastParameter() -
297 myTrimmed->FirstParameter()) / Num;
299 for (Standard_Integer i = 0; i <= Num; i++) {
300 Param = myTrimmed->FirstParameter() + i*Step;
301 if (Param > myTrimmed->LastParameter()) Param = myTrimmed->LastParameter();
309 ABiNormal /= Num + 1;
313 //=======================================================================
314 //function : IsConstant
316 //=======================================================================
317 Standard_Boolean GeomFill_DraftTrihedron::IsConstant() const
319 return (myCurve->GetType() == GeomAbs_Line);
322 //=======================================================================
323 //function : IsOnlyBy3dCurve
325 //=======================================================================
326 Standard_Boolean GeomFill_DraftTrihedron::IsOnlyBy3dCurve() const
328 GeomAbs_CurveType TheType = myCurve->GetType();
334 TheAxe = myCurve->Circle().Axis();
337 case GeomAbs_Ellipse:
339 TheAxe = myCurve->Ellipse().Axis();
342 case GeomAbs_Hyperbola:
344 TheAxe = myCurve->Hyperbola().Axis();
347 case GeomAbs_Parabola:
349 TheAxe = myCurve->Parabola().Axis();
353 { //La normale du plan de la courbe est il perpendiculaire a la BiNormale ?
355 V.SetXYZ(myCurve->Line().Direction().XYZ());
356 return V.IsParallel(B, Precision::Angular());
359 return Standard_False; // pas de risques
362 // La normale du plan de la courbe est il // a la BiNormale ?
364 V.SetXYZ(TheAxe.Direction().XYZ());
365 return V.IsParallel(B, Precision::Angular());