1 #include <GeomConvert_ApproxSurface.ixx>
3 #include <GeomAdaptor_HSurface.hxx>
4 #include <Precision.hxx>
5 #include <AdvApp2Var_ApproxAFunc2Var.hxx>
6 #include <Standard_Real.hxx>
7 #include <TColStd_HArray2OfReal.hxx>
8 #include <TColStd_HArray1OfReal.hxx>
9 #include <AdvApprox_PrefAndRec.hxx>
11 class GeomConvert_ApproxSurface_Eval : public AdvApp2Var_EvaluatorFunc2Var
16 GeomConvert_ApproxSurface_Eval (const Handle(Adaptor3d_HSurface)& theAdaptor)
17 : myAdaptor (theAdaptor) {}
19 virtual void Evaluate (Standard_Integer* theDimension,
20 Standard_Real* theUStartEnd,
21 Standard_Real* theVStartEnd,
22 Standard_Integer* theFavorIso,
23 Standard_Real* theConstParam,
24 Standard_Integer* theNbParams,
25 Standard_Real* theParameters,
26 Standard_Integer* theUOrder,
27 Standard_Integer* theVOrder,
28 Standard_Real* theResult,
29 Standard_Integer* theErrorCode) const;
33 mutable Handle(Adaptor3d_HSurface) myAdaptor;
38 void GeomConvert_ApproxSurface_Eval::Evaluate (Standard_Integer * Dimension,
40 Standard_Real * UStartEnd,
42 Standard_Real * VStartEnd,
44 Standard_Integer * FavorIso,
45 // Choice of constante, 1 for U, 2 for V
46 Standard_Real * ConstParam,
47 // Value of constant parameter
48 Standard_Integer * NbParams,
49 // Number of parameters N
50 Standard_Real * Parameters,
51 // Values of parameters,
52 Standard_Integer * UOrder,
53 // Derivative Request in U
54 Standard_Integer * VOrder,
55 // Derivative Request in V
56 Standard_Real * Result,
57 // Result[Dimension,N]
58 Standard_Integer * ErrorCode) const
62 // Standard_Integer idim;
63 Standard_Integer jpar;
64 Standard_Real Upar,Vpar;
66 // Dimension incorrecte
71 // Parametres incorrects
72 /* if (*FavorIso==1) {
74 if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
77 for (jpar=1;jpar<=*NbParams;jpar++) {
78 Vpar = Parameters[jpar-1];
79 if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
86 if (( Vpar < VStartEnd[0] ) || ( Vpar > VStartEnd[1] )) {
89 for (jpar=1;jpar<=*NbParams;jpar++) {
90 Upar = Parameters[jpar-1];
91 if (( Upar < UStartEnd[0] ) || ( Upar > UStartEnd[1] )) {
99 myAdaptor = myAdaptor->UTrim (UStartEnd[0], UStartEnd[1], Precision::PConfusion());
100 myAdaptor = myAdaptor->VTrim (VStartEnd[0], VStartEnd[1], Precision::PConfusion());
102 for (idim=1;idim<=*Dimension;idim++) {
103 for (jpar=1;jpar<=*NbParams;jpar++) {
104 Result[idim-1+(jpar-1)*(*Dimension)] = 0.;
109 Standard_Integer Order = *UOrder + *VOrder;
111 gp_Vec vect, v1, v2, v3, v4, v5, v6, v7, v8, v9;
117 for (jpar=1;jpar<=*NbParams;jpar++) {
118 Vpar = Parameters[jpar-1];
119 pnt = myAdaptor->Value (Upar, Vpar);
120 Result[(jpar-1)*(*Dimension)] = pnt.X();
121 Result[1+(jpar-1)*(*Dimension)] = pnt.Y();
122 Result[2+(jpar-1)*(*Dimension)] = pnt.Z();
126 for (jpar=1;jpar<=*NbParams;jpar++) {
127 Vpar = Parameters[jpar-1];
128 myAdaptor->D1 (Upar, Vpar, pnt, v1, v2);
130 Result[(jpar-1)*(*Dimension)] = v1.X();
131 Result[1+(jpar-1)*(*Dimension)] = v1.Y();
132 Result[2+(jpar-1)*(*Dimension)] = v1.Z();
135 Result[(jpar-1)*(*Dimension)] = v2.X();
136 Result[1+(jpar-1)*(*Dimension)] = v2.Y();
137 Result[2+(jpar-1)*(*Dimension)] = v2.Z();
142 for (jpar=1;jpar<=*NbParams;jpar++) {
143 Vpar = Parameters[jpar-1];
144 myAdaptor->D2 (Upar, Vpar, pnt, v1, v2, v3, v4, v5);
146 Result[(jpar-1)*(*Dimension)] = v3.X();
147 Result[1+(jpar-1)*(*Dimension)] = v3.Y();
148 Result[2+(jpar-1)*(*Dimension)] = v3.Z();
150 else if (*UOrder==1) {
151 Result[(jpar-1)*(*Dimension)] = v5.X();
152 Result[1+(jpar-1)*(*Dimension)] = v5.Y();
153 Result[2+(jpar-1)*(*Dimension)] = v5.Z();
155 else if (*UOrder==0) {
156 Result[(jpar-1)*(*Dimension)] = v4.X();
157 Result[1+(jpar-1)*(*Dimension)] = v4.Y();
158 Result[2+(jpar-1)*(*Dimension)] = v4.Z();
163 for (jpar=1;jpar<=*NbParams;jpar++) {
164 Vpar = Parameters[jpar-1];
165 myAdaptor->D3 (Upar, Vpar, pnt, v1, v2, v3, v4, v5, v6, v7, v8, v9);
167 Result[(jpar-1)*(*Dimension)] = v8.X();
168 Result[1+(jpar-1)*(*Dimension)] = v8.Y();
169 Result[2+(jpar-1)*(*Dimension)] = v8.Z();
171 else if (*UOrder==1) {
172 Result[(jpar-1)*(*Dimension)] = v9.X();
173 Result[1+(jpar-1)*(*Dimension)] = v9.Y();
174 Result[2+(jpar-1)*(*Dimension)] = v9.Z();
179 for (jpar=1;jpar<=*NbParams;jpar++) {
180 Vpar = Parameters[jpar-1];
181 vect = myAdaptor->DN (Upar, Vpar, *UOrder, *VOrder);
182 Result[(jpar-1)*(*Dimension)] = vect.X();
183 Result[1+(jpar-1)*(*Dimension)] = vect.Y();
184 Result[2+(jpar-1)*(*Dimension)] = vect.Z();
193 for (jpar=1;jpar<=*NbParams;jpar++) {
194 Upar = Parameters[jpar-1];
195 pnt = myAdaptor->Value (Upar, Vpar);
196 Result[(jpar-1)*(*Dimension)] = pnt.X();
197 Result[1+(jpar-1)*(*Dimension)] = pnt.Y();
198 Result[2+(jpar-1)*(*Dimension)] = pnt.Z();
202 for (jpar=1;jpar<=*NbParams;jpar++) {
203 Upar = Parameters[jpar-1];
204 myAdaptor->D1 (Upar, Vpar, pnt, v1, v2);
206 Result[(jpar-1)*(*Dimension)] = v1.X();
207 Result[1+(jpar-1)*(*Dimension)] = v1.Y();
208 Result[2+(jpar-1)*(*Dimension)] = v1.Z();
211 Result[(jpar-1)*(*Dimension)] = v2.X();
212 Result[1+(jpar-1)*(*Dimension)] = v2.Y();
213 Result[2+(jpar-1)*(*Dimension)] = v2.Z();
218 for (jpar=1;jpar<=*NbParams;jpar++) {
219 Upar = Parameters[jpar-1];
220 myAdaptor->D2 (Upar, Vpar, pnt, v1, v2, v3, v4, v5);
222 Result[(jpar-1)*(*Dimension)] = v3.X();
223 Result[1+(jpar-1)*(*Dimension)] = v3.Y();
224 Result[2+(jpar-1)*(*Dimension)] = v3.Z();
226 else if (*UOrder==1) {
227 Result[(jpar-1)*(*Dimension)] = v5.X();
228 Result[1+(jpar-1)*(*Dimension)] = v5.Y();
229 Result[2+(jpar-1)*(*Dimension)] = v5.Z();
231 else if (*UOrder==0) {
232 Result[(jpar-1)*(*Dimension)] = v4.X();
233 Result[1+(jpar-1)*(*Dimension)] = v4.Y();
234 Result[2+(jpar-1)*(*Dimension)] = v4.Z();
239 for (jpar=1;jpar<=*NbParams;jpar++) {
240 Upar = Parameters[jpar-1];
241 myAdaptor->D3 (Upar, Vpar, pnt, v1, v2, v3, v4, v5, v6, v7, v8, v9);
243 Result[(jpar-1)*(*Dimension)] = v8.X();
244 Result[1+(jpar-1)*(*Dimension)] = v8.Y();
245 Result[2+(jpar-1)*(*Dimension)] = v8.Z();
247 else if (*UOrder==1) {
248 Result[(jpar-1)*(*Dimension)] = v9.X();
249 Result[1+(jpar-1)*(*Dimension)] = v9.Y();
250 Result[2+(jpar-1)*(*Dimension)] = v9.Z();
255 for (jpar=1;jpar<=*NbParams;jpar++) {
256 Upar = Parameters[jpar-1];
257 vect = myAdaptor->DN (Upar, Vpar, *UOrder, *VOrder);
258 Result[(jpar-1)*(*Dimension)] = vect.X();
259 Result[1+(jpar-1)*(*Dimension)] = vect.Y();
260 Result[2+(jpar-1)*(*Dimension)] = vect.Z();
269 //=======================================================================
270 //function : GeomConvert_ApproxSurface
272 //=======================================================================
274 GeomConvert_ApproxSurface::GeomConvert_ApproxSurface(const Handle(Geom_Surface)& Surf,
275 const Standard_Real Tol3d,
276 const GeomAbs_Shape UContinuity,
277 const GeomAbs_Shape VContinuity,
278 const Standard_Integer MaxDegU,
279 const Standard_Integer MaxDegV,
280 const Standard_Integer MaxSegments,
281 const Standard_Integer PrecisCode)
283 Standard_Real U0, U1, V0, V1;
285 Handle(Adaptor3d_HSurface) aSurfAdaptor = new GeomAdaptor_HSurface (Surf);
286 Surf->Bounds(U0, U1, V0, V1);
288 // " Init des nombres de sous-espaces et des tolerances"
289 Standard_Integer nb1 = 0, nb2 = 0, nb3 = 1;
290 Handle(TColStd_HArray1OfReal) nul1 =
291 new TColStd_HArray1OfReal(1,1);
292 nul1->SetValue(1,0.);
293 Handle(TColStd_HArray2OfReal) nul2 =
294 new TColStd_HArray2OfReal(1,1,1,4);
295 nul2->SetValue(1,1,0.);
296 nul2->SetValue(1,2,0.);
297 nul2->SetValue(1,3,0.);
298 nul2->SetValue(1,4,0.);
299 Handle(TColStd_HArray1OfReal) eps3D =
300 new TColStd_HArray1OfReal(1,1);
301 eps3D->SetValue(1,Tol3d);
302 Handle(TColStd_HArray2OfReal) epsfr =
303 new TColStd_HArray2OfReal(1,1,1,4);
304 epsfr->SetValue(1,1,Tol3d);
305 epsfr->SetValue(1,2,Tol3d);
306 epsfr->SetValue(1,3,Tol3d);
307 epsfr->SetValue(1,4,Tol3d);
309 // " Init du type d'iso"
310 GeomAbs_IsoType IsoType = GeomAbs_IsoV;
311 Standard_Integer NbDec;
313 NbDec = aSurfAdaptor->NbUIntervals(GeomAbs_C2);
314 TColStd_Array1OfReal UDec_C2(1, NbDec+1);
315 aSurfAdaptor->UIntervals(UDec_C2, GeomAbs_C2);
316 NbDec = aSurfAdaptor->NbVIntervals(GeomAbs_C2);
317 TColStd_Array1OfReal VDec_C2(1, NbDec+1);
318 aSurfAdaptor->VIntervals(VDec_C2, GeomAbs_C2);
320 NbDec = aSurfAdaptor->NbUIntervals(GeomAbs_C3);
321 TColStd_Array1OfReal UDec_C3(1, NbDec+1);
322 aSurfAdaptor->UIntervals(UDec_C3, GeomAbs_C3);
324 NbDec = aSurfAdaptor->NbVIntervals(GeomAbs_C3);
325 TColStd_Array1OfReal VDec_C3(1, NbDec+1);
326 aSurfAdaptor->VIntervals(VDec_C3, GeomAbs_C3);
327 // Approximation avec decoupe preferentiel
328 // aux lieux de discontinuitees C2
329 AdvApprox_PrefAndRec pUDec(UDec_C2,UDec_C3);
330 AdvApprox_PrefAndRec pVDec(VDec_C2,VDec_C3);
333 GeomConvert_ApproxSurface_Eval ev (aSurfAdaptor);
334 AdvApp2Var_ApproxAFunc2Var approx(nb1, nb2, nb3,
338 IsoType,UContinuity,VContinuity,PrecisCode,
339 // MaxDegU,MaxDegV,MaxSegments,mySurfEval1,
340 MaxDegU,MaxDegV,MaxSegments,ev,
343 myMaxError = approx.MaxError(3,1);
344 myBSplSurf = approx.Surface(1);
345 myIsDone = approx.IsDone();
346 myHasResult = approx.HasResult();
350 //=======================================================================
353 //=======================================================================
355 Handle(Geom_BSplineSurface) GeomConvert_ApproxSurface::Surface() const
360 //=======================================================================
363 //=======================================================================
365 Standard_Boolean GeomConvert_ApproxSurface::IsDone() const
370 //=======================================================================
371 //function : HasResult
373 //=======================================================================
375 Standard_Boolean GeomConvert_ApproxSurface::HasResult() const
380 //=======================================================================
381 //function : MaxError
383 //=======================================================================
385 Standard_Real GeomConvert_ApproxSurface::MaxError() const
389 //=======================================================================
392 //=======================================================================
394 void GeomConvert_ApproxSurface::Dump(Standard_OStream& o) const
397 if (!myHasResult) { o<<"No result"<<endl; }
399 o<<"Result max error :"<< myMaxError <<endl;