1 // Created on: 1995-10-04
2 // Created by: Jacques GOUSSARD
3 // Copyright (c) 1995-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 // 09/09/1996 PMN Ajout des methodes GetCircle et GetTolerance.
18 // 30/12/1996 PMN Ajout de GetMinimalWeight
19 // 23/09/1997 PMN Supprimme GetCircle et GetTol (passe dans GeomFill)
21 #include <Adaptor3d_HSurface.hxx>
22 #include <BlendFunc.hxx>
24 #include <CSLib_NormalStatus.hxx>
25 #include <Geom_BSplineCurve.hxx>
26 #include <Geom_Circle.hxx>
27 #include <Geom_TrimmedCurve.hxx>
28 #include <GeomConvert.hxx>
30 #include <gp_Circ.hxx>
33 #include <gp_Pnt2d.hxx>
35 #include <Precision.hxx>
36 #include <Standard_ConstructionError.hxx>
37 #include <TColgp_Array2OfVec.hxx>
39 //=======================================================================
42 //=======================================================================
43 void BlendFunc::GetShape (const BlendFunc_SectionShape SShape,
44 const Standard_Real MaxAng,
45 Standard_Integer& NbPoles,
46 Standard_Integer& NbKnots,
47 Standard_Integer& Degree,
48 Convert_ParameterisationType& TConv)
51 case BlendFunc_Rational:
53 Standard_Integer NbSpan =
54 (Standard_Integer)(Ceiling(3.*Abs(MaxAng)/2./M_PI));
59 TConv = Convert_TgtThetaOver2_1;
61 else { // QuasiAngular affin d'etre C1 (et meme beaucoup plus)
65 TConv = Convert_QuasiAngular;
69 case BlendFunc_QuasiAngular:
74 TConv = Convert_QuasiAngular;
77 case BlendFunc_Polynomial:
82 TConv = Convert_Polynomial;
85 case BlendFunc_Linear:
96 //=======================================================================
97 //function : GetMinimalWeights
98 //purpose : On suppose les extremum de poids sont obtenus pour les
99 // extremums d'angles (A verifier eventuelement pour Quasi-Angular)
100 //=======================================================================
102 void BlendFunc::GetMinimalWeights(const BlendFunc_SectionShape SShape,
103 const Convert_ParameterisationType TConv,
104 const Standard_Real MinAng,
105 const Standard_Real MaxAng,
106 TColStd_Array1OfReal& Weights)
110 case BlendFunc_Polynomial:
111 case BlendFunc_Linear:
116 case BlendFunc_Rational:
117 case BlendFunc_QuasiAngular:
119 gp_Ax2 popAx2(gp_Pnt(0, 0, 0), gp_Dir(0,0,1));
120 gp_Circ C (popAx2, 1);
121 Handle(Geom_TrimmedCurve) Sect1 =
122 new Geom_TrimmedCurve(new Geom_Circle(C), 0., MaxAng);
123 Handle(Geom_BSplineCurve) CtoBspl =
124 GeomConvert::CurveToBSplineCurve(Sect1, TConv);
125 CtoBspl->Weights(Weights);
127 TColStd_Array1OfReal poids (Weights.Lower(), Weights.Upper());
128 Standard_Real angle_min = Max(Precision::PConfusion(), MinAng);
130 Handle(Geom_TrimmedCurve) Sect2 =
131 new Geom_TrimmedCurve(new Geom_Circle(C), 0., angle_min);
132 CtoBspl = GeomConvert::CurveToBSplineCurve(Sect2, TConv);
133 CtoBspl->Weights(poids);
135 for (Standard_Integer ii=Weights.Lower(); ii<=Weights.Upper(); ii++) {
136 if (poids(ii) < Weights(ii)) {
137 Weights(ii) = poids(ii);
146 //=======================================================================
147 //function : IncrementeShape
149 //=======================================================================
151 GeomAbs_Shape BlendFunc::NextShape (const GeomAbs_Shape S)
155 case GeomAbs_C0 : return GeomAbs_C1;
156 case GeomAbs_C1 : return GeomAbs_C2;
157 case GeomAbs_C2 : return GeomAbs_C3;
164 //=======================================================================
165 //function : ComputeNormal
167 //=======================================================================
169 Standard_Boolean BlendFunc::ComputeNormal (const Handle(Adaptor3d_HSurface)& Surf,
170 const gp_Pnt2d& p2d, gp_Vec& Normal)
172 const Standard_Integer MaxOrder=3;
173 const Standard_Real U = p2d.X();
174 const Standard_Real V = p2d.Y();
176 Standard_Integer i,j;
178 TColgp_Array2OfVec DerSurf(0,MaxOrder+1,0,MaxOrder+1);
179 for(i=1;i<=MaxOrder+1;i++)
180 DerSurf.SetValue(i,0,Surf->DN(U,V,i,0));
181 for(i=0;i<=MaxOrder+1;i++)
182 for(j=1;j<=MaxOrder+1;j++)
183 DerSurf.SetValue(i,j,Surf->DN(U,V,i,j));
185 TColgp_Array2OfVec DerNUV(0,MaxOrder,0,MaxOrder);
186 for(i=0;i<=MaxOrder;i++)
187 for(j=0;j<=MaxOrder;j++)
188 DerNUV.SetValue(i,j,CSLib::DNNUV(i,j,DerSurf));
191 CSLib_NormalStatus stat;
192 Standard_Integer OrderU,OrderV;
193 const Standard_Real Umin = Surf->FirstUParameter();
194 const Standard_Real Umax = Surf->LastUParameter();
195 const Standard_Real Vmin = Surf->FirstVParameter();
196 const Standard_Real Vmax = Surf->LastVParameter(); //szv: was FirstVParameter!
197 CSLib::Normal(MaxOrder,DerNUV,Standard_Real(1.e-9),U,V,Umin,Umax,Vmin,Vmax,
198 stat,thenormal,OrderU,OrderV);
199 if (stat == CSLib_Defined)
201 Normal.SetXYZ(thenormal.XYZ());
202 return Standard_True;
204 return Standard_False;
208 //=======================================================================
209 //function : ComputeDNormal
211 //=======================================================================
213 Standard_Boolean BlendFunc::ComputeDNormal (const Handle(Adaptor3d_HSurface)& Surf,
214 const gp_Pnt2d& p2d, gp_Vec& Normal,
215 gp_Vec& DNu, gp_Vec& DNv)
217 const Standard_Integer MaxOrder=3;
218 const Standard_Real U = p2d.X();
219 const Standard_Real V = p2d.Y();
221 Standard_Integer i,j;
223 TColgp_Array2OfVec DerSurf(0,MaxOrder+1,0,MaxOrder+1);
224 for(i=1;i<=MaxOrder+1;i++)
225 DerSurf.SetValue(i,0,Surf->DN(U,V,i,0));
226 for(i=0;i<=MaxOrder+1;i++)
227 for(j=1;j<=MaxOrder+1;j++)
228 DerSurf.SetValue(i,j,Surf->DN(U,V,i,j));
230 TColgp_Array2OfVec DerNUV(0,MaxOrder,0,MaxOrder);
231 for(i=0;i<=MaxOrder;i++)
232 for(j=0;j<=MaxOrder;j++)
233 DerNUV.SetValue(i,j,CSLib::DNNUV(i,j,DerSurf));
236 CSLib_NormalStatus stat;
237 Standard_Integer OrderU,OrderV;
238 const Standard_Real Umin = Surf->FirstUParameter();
239 const Standard_Real Umax = Surf->LastUParameter();
240 const Standard_Real Vmin = Surf->FirstVParameter();
241 const Standard_Real Vmax = Surf->LastVParameter(); //szv: was FirstVParameter!
242 CSLib::Normal(MaxOrder,DerNUV,Standard_Real(1.e-9),U,V,Umin,Umax,Vmin,Vmax,
243 stat,thenormal,OrderU,OrderV);
244 if (stat == CSLib_Defined)
246 Normal.SetXYZ(thenormal.XYZ());
247 DNu = CSLib::DNNormal(1, 0, DerNUV, OrderU, OrderV);
248 DNv = CSLib::DNNormal(0, 1, DerNUV, OrderU, OrderV);
249 return Standard_True;
251 return Standard_False;