ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
File size: 11922 byte(s)
Log Message:
changement de hiearchie et utilisation de ccmake + mise a jour

File Contents

# User Rev Content
1 francois 139 //---------------------------------------------------------------------------
2     //------------------------------------------------------------
3     //------------------------------------------------------------
4     // MAGiC
5     // Jean Christophe Cuillière et Vincent FRANCOIS
6     // Département de Génie Mécanique - UQTR
7     //------------------------------------------------------------
8     // Le projet MAGIC est un projet de recherche du département
9     // de génie mécanique de l'Université du Québec à
10     // Trois Rivières
11     // Les librairies ne peuvent être utilisées sans l'accord
12     // des auteurs (contact : francois@uqtr.ca)
13     //------------------------------------------------------------
14     //------------------------------------------------------------
15     //
16     // OCC_Surface.cpp
17     //
18     //------------------------------------------------------------
19     //------------------------------------------------------------
20     // COPYRIGHT 2000
21     // Version du 02/03/2006 à 11H22
22     //------------------------------------------------------------
23     //------------------------------------------------------------
24    
25     #pragma hdrstop
26     #include "gestionversion.h"
27     #ifdef BREP_OCC
28    
29     #include "occ_surface.h"
30     #include <gp_Pnt.hxx>
31     #include <gp_Vec.hxx>
32     #include "GeomAPI_ProjectPointOnSurf.hxx"
33     #include <ShapeAnalysis_Surface.hxx>
34     #include <BRep_Tool.hxx>
35     #include <BRepAdaptor_Surface.hxx>
36     //***********************************
37     #include <Geom_Plane.hxx>
38     #include <gp_Pln.hxx>
39     #include <Geom_CylindricalSurface.hxx>
40     #include <gp_Cylinder.hxx>
41     #include <Geom_ConicalSurface.hxx>
42     #include <gp_Cone.hxx>
43     #include <Geom_SphericalSurface.hxx>
44     #include <gp_Sphere.hxx>
45     #include "Geom_ToroidalSurface.hxx"
46     #include <gp_Torus.hxx>
47     #include <Geom_BSplineSurface.hxx>
48     #include <Geom_BezierSurface.hxx>
49     #include <GeomConvert.hxx>
50     #include <BRepBuilderAPI_NurbsConvert.hxx>
51     #include <BRepLib_FindSurface.hxx>
52     #include "constantegeo.h"
53    
54     #pragma package(smart_init)
55     OCC_SURFACE::OCC_SURFACE(unsigned long num, TopoDS_Face srf, OCC_FONCTION1& fonc):MG_SURFACE(num),face(srf), fonction1(fonc)
56     {
57    
58     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
59     double u1; double u2; double v1; double v2;
60     surface->Bounds(u1,u2,v1, v2);
61     u_min=u1;
62     u_max=u2;
63     v_min=v1;
64     v_max=v2;
65    
66     }
67    
68     OCC_SURFACE::OCC_SURFACE(TopoDS_Face srf, OCC_FONCTION1& fonc):MG_SURFACE(),face(srf), fonction1(fonc)
69     {
70     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
71     double u1; double u2; double v1; double v2;
72     surface->Bounds(u1,u2,v1, v2);
73     u_min=u1;
74     u_max=u2;
75     v_min=v1;
76     v_max=v2;
77     }
78    
79     OCC_SURFACE::OCC_SURFACE(OCC_SURFACE& mdd):MG_SURFACE(mdd),face(mdd.face), fonction1(mdd.fonction1)
80     {
81     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
82     u_min=mdd.get_umin();
83     u_max=mdd.get_umax();
84     v_min=mdd.get_vmin();
85     v_max=mdd.get_vmax();
86    
87     }
88     OCC_SURFACE::~OCC_SURFACE()
89     {
90     }
91     void OCC_SURFACE::evaluer(double *uv,double *xyz)
92     {
93    
94     const Handle(Geom_Surface) &surface=BRep_Tool::Surface(face);
95     gp_Pnt P;
96     double u=uv[0];
97     double v=uv[1];
98    
99     surface->D0(u,v,P);
100    
101     xyz[0]=P.X();
102     xyz[1]=P.Y();
103     xyz[2]=P.Z();
104     }
105     void OCC_SURFACE::deriver(double *uv,double *xyzdu, double *xyzdv)
106     {
107     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
108     double u=uv[0];
109     double v=uv[1];
110     gp_Vec D1U;
111     gp_Vec D1V;
112     gp_Pnt P;
113    
114     surface->D1(u,v,P,D1U,D1V);
115     xyzdu[0]=D1U.X();
116     xyzdu[1]=D1U.Y();
117     xyzdu[2]=D1U.Z();
118    
119     xyzdv[0]=D1V.X();
120     xyzdv[1]=D1V.Y();
121     xyzdv[2]=D1V.Z();
122    
123     }
124     void OCC_SURFACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz, double *xyzdu, double *xyzdv)
125     {
126     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
127     double u=uv[0];
128     double v=uv[1];
129     gp_Pnt P;
130     gp_Vec D1U;
131     gp_Vec D1V;
132     gp_Vec D2U;
133     gp_Vec D2V;
134     gp_Vec D2UV;
135    
136     surface->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
137    
138     xyz[0]=P.X();
139     xyz[1]=P.Y();
140     xyz[2]=P.Z();
141    
142     xyzdu[0]=D1U.X();
143     xyzdu[1]=D1U.Y();
144     xyzdu[2]=D1U.Z();
145    
146     xyzdv[0]=D1V.X();
147     xyzdv[1]=D1V.Y();
148     xyzdv[2]=D1V.Z();
149    
150     xyzduu[0]=D2U.X();
151     xyzduu[1]=D2U.Y();
152     xyzduu[2]=D2U.Z();
153    
154     xyzdvv[0]=D2V.X();
155     xyzdvv[1]=D2V.Y();
156     xyzdvv[2]=D2V.Z();
157    
158     xyzduv[0]=D2UV.X();
159     xyzduv[1]=D2UV.Y();
160     xyzduv[2]=D2UV.Z();
161    
162     }
163    
164     void OCC_SURFACE::inverser(double *uv,double *xyz,double precision)
165     {
166     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
167     double u=xyz[0];
168     double v=xyz[1];
169     double w=xyz[2];
170     gp_Pnt P(u,v,w);
171    
172     //ShapeAnalysis_Surface SAS(surface);
173     //gp_Pnt2d pnt2d=SAS.ValueOfUV(P, precision);
174    
175     GeomAPI_ProjectPointOnSurf PPS(P,surface, precision);
176     //PPS.Perform(P);
177     double UU, VV;
178     PPS.LowerDistanceParameters(UU,VV);
179    
180     uv[0]=UU;
181     uv[1]=VV;
182     }
183     int OCC_SURFACE::est_periodique_u(void)
184     {
185     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
186     return surface->IsUClosed();
187     }
188    
189     int OCC_SURFACE::est_periodique_v(void)
190     {
191     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
192     return surface->IsVPeriodic();
193     }
194     double OCC_SURFACE::get_periode_u(void)
195     {
196     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
197     if(surface->IsUPeriodic()==0) return 0.;
198     return surface->UPeriod();
199     }
200    
201     double OCC_SURFACE::get_periode_v(void)
202     {
203     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
204     if(surface->IsVPeriodic()==0) return 0.;
205     return surface->VPeriod();
206     }
207     void OCC_SURFACE::enregistrer(std::ostream& o)
208     {
209     o <<"%"<<get_id()<< "=SURFACE_OCC("<< fonction1.GetID(face)<< ");" << std::endl;
210     }
211     int OCC_SURFACE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
212     {
213     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
214     Handle(Standard_Type) type=surface->DynamicType();
215     //******plan
216     if(type==STANDARD_TYPE(Geom_Plane))
217     {
218     Handle(Geom_Plane) Pln=Handle(Geom_Plane)::DownCast(surface);
219     gp_Pln plan=Pln->Pln();
220    
221     double origine[3];
222     gp_Pnt centre=plan.Location();
223    
224     origine[0]=centre.X();
225     origine[1]=centre.Y();
226     origine[2]=centre.Z();
227    
228     double normal[3];
229     gp_Ax1 axe=plan.Axis();
230     gp_Dir direction=axe.Direction();
231    
232     normal[0]=direction.X();
233     normal[1]=direction.Y();
234     normal[2]=direction.Z();
235    
236     param.ajouter(origine[0]);
237     param.ajouter(origine[1]);
238     param.ajouter(origine[2]);
239     param.ajouter(normal[0]);
240     param.ajouter(normal[1]);
241     param.ajouter(normal[2]);
242    
243     return MGCo_PLAN;
244     }
245     //******cylindre
246     if(type==STANDARD_TYPE(Geom_CylindricalSurface))
247     {
248     Handle(Geom_CylindricalSurface) cylinder=Handle(Geom_CylindricalSurface)::DownCast(surface);
249     gp_Cylinder cylin=cylinder->Cylinder();
250    
251     double origine[3];
252     gp_Pnt centre=cylin.Location();
253     origine[0]=centre.X();
254     origine[1]=centre.Y();
255     origine[2]=centre.Z();
256     double direction[3];
257     gp_Ax1 axe=cylin.Axis();
258     gp_Dir dir=axe.Direction();
259     direction[0]=dir.X();
260     direction[1]=dir.Y();
261     direction[2]=dir.Z();
262     double rayon;
263     rayon=cylin.Radius();
264    
265     param.ajouter(origine[0]);
266     param.ajouter(origine[1]);
267     param.ajouter(origine[2]);
268     param.ajouter(direction[0]);
269     param.ajouter(direction[1]);
270     param.ajouter(direction[2]);
271     param.ajouter(rayon);
272    
273     return MGCo_CYLINDRE;
274     }
275     //******Cone
276     if(type==STANDARD_TYPE(Geom_ConicalSurface))
277     {
278     Handle(Geom_ConicalSurface) cone=Handle(Geom_ConicalSurface)::DownCast(surface);
279     gp_Cone con=cone->Cone();
280    
281     double origine[3];
282     gp_Pnt centre=con.Location();
283     origine[0]=centre.X();
284     origine[1]=centre.Y();
285     origine[2]=centre.Z();
286     double direction[3];
287     gp_Ax1 axe=con.Axis();
288     gp_Dir dir=axe.Direction();
289     direction[0]=dir.X();
290     direction[1]=dir.Y();
291     direction[2]=dir.Z();
292     double rayon;
293     rayon=con.RefRadius();
294     double angle;
295     angle=con.SemiAngle();
296    
297     param.ajouter(origine[0]);
298     param.ajouter(origine[1]);
299     param.ajouter(origine[2]);
300     param.ajouter(direction[0]);
301     param.ajouter(direction[1]);
302     param.ajouter(direction[2]);
303     param.ajouter(rayon);
304     param.ajouter(angle);
305    
306     return MGCo_CONE;
307    
308     }
309     //*****Sphere
310     if(type==STANDARD_TYPE(Geom_SphericalSurface))
311     {
312     Handle(Geom_SphericalSurface) sphere=Handle(Geom_SphericalSurface)::DownCast(surface);
313     gp_Sphere sph=sphere->Sphere();
314    
315     double origine[3];
316     gp_Pnt centre=sph.Location();
317     origine[0]=centre.X();
318     origine[1]=centre.Y();
319     origine[2]=centre.Z();
320     double rayon;
321     rayon=sph.Radius();
322     param.ajouter(origine[0]);
323     param.ajouter(origine[1]);
324     param.ajouter(origine[2]);
325     param.ajouter(rayon);
326    
327     return MGCo_SPHERE;
328    
329     }
330     //****** Tore
331     if(type==STANDARD_TYPE(Geom_ToroidalSurface))
332     {
333     Handle(Geom_ToroidalSurface) tore=Handle(Geom_ToroidalSurface)::DownCast(surface);
334     gp_Torus tro=tore->Torus();
335     double origine[3];
336     gp_Pnt centre=tro.Location();
337     origine[0]=centre.X();
338     origine[1]=centre.Y();
339     origine[2]=centre.Z();
340     double direction[3];
341     gp_Ax1 axe=tro.Axis();
342     gp_Dir dir=axe.Direction();
343     direction[0]=dir.X();
344     direction[1]=dir.Y();
345     direction[2]=dir.Z();
346     double Grayon;
347     Grayon=tro.MajorRadius();
348     double Prayon;
349     Prayon=tro.MinorRadius();
350    
351     param.ajouter(origine[0]);
352     param.ajouter(origine[1]);
353     param.ajouter(origine[2]);
354     param.ajouter(direction[0]);
355     param.ajouter(direction[1]);
356     param.ajouter(direction[2]);
357     param.ajouter(Grayon);
358     param.ajouter(Prayon);
359    
360     return MGCo_TORE;
361    
362     }
363     //*******BSpline
364     if(type==STANDARD_TYPE(Geom_BSplineSurface))
365     {
366     Handle(Geom_BSplineSurface) bspline=Handle(Geom_BSplineSurface)::DownCast(surface);
367    
368     //nombre des noeuds suivant Udirection
369     int nb_Uknot=bspline->NbUKnots();
370     //valeur de Unoeud
371     for(int i=1; i<=nb_Uknot; i++)
372     {
373     double Uvaleur=bspline->UKnot(i);
374     param.ajouter(Uvaleur);
375     }
376     //nombre des noeuds suivants Vdirection
377     int nb_Vknot=bspline->NbVKnots();
378     //valeur de Vnoeud
379     for(int j=1; j<=nb_Vknot; j++)
380     {
381     double Vvaleur=bspline->VKnot(j);
382     param.ajouter(Vvaleur);
383     }
384     //point de controle et poids
385     gp_Pnt pctr;
386     double poids;
387     for(int u=1; u<=bspline->NbUPoles(); u++)
388     for(int v=1; v<=bspline->NbVPoles(); v++)
389     {
390     pctr=bspline->Pole(u, v);
391    
392     param.ajouter(pctr.X());
393     param.ajouter(pctr.Y());
394     param.ajouter(pctr.Z());
395    
396     poids=bspline->Weight(u, v);
397     param.ajouter(poids);
398     }
399    
400     double uDegree=bspline->UDegree();
401     param.ajouter(uDegree);
402     double vDegree=bspline->VDegree();
403     param.ajouter(vDegree);
404     return MGCo_BSPLINES;
405     }
406    
407     }
408     void OCC_SURFACE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
409     {
410     //Conversion of the complete geometry of a shape into
411     //NURBS geometry
412     BRepBuilderAPI_NurbsConvert NURBS(face);
413     Handle(Geom_Surface) surface=BRepLib_FindSurface(NURBS).Surface();
414     Handle(Geom_BSplineSurface) bspline=GeomConvert::SurfaceToBSplineSurface(surface) ;
415    
416     // The first parameter indicate the code access
417     param.ajouter(2);
418     //The follewing two parameters of the list indicate the orders of the net points
419     param.ajouter( bspline->UDegree()+1);
420     param.ajouter(bspline->VDegree()+1);
421    
422     //The follewing two parameters indicate the number of rows and colons of the control points
423     //respectively to the two parameters directions
424     param.ajouter(bspline->NbUPoles());
425     param.ajouter(bspline->NbVPoles());
426    
427     // this present the knot vector in the u-direction
428     for(unsigned int i=1;i<=bspline->NbUKnots();i++)
429     {
430     param.ajouter(bspline->UKnot(i));
431     }
432     //This present the knot vector in the v-direction
433     for(unsigned int j=1;j<=bspline->NbVKnots();j++)
434     {
435     param.ajouter(bspline->VKnot(j));
436     }
437    
438     for(int u=1;u<=bspline->NbUPoles();u++)
439     {
440     for(int v=1;v<=bspline->NbVPoles();v++)
441     {
442     double w=bspline->Weight(u,v);
443     gp_Pnt point=bspline->Pole(u, v);
444     double x=point.X();
445     double y=point.Y();
446     double z=point.Z();
447     param.ajouter(x);
448     param.ajouter(y);
449     param.ajouter(z);
450     param.ajouter(w);
451     }
452    
453     }
454     indx_premier_ptctr=5+bspline->NbUKnots()+bspline->NbVKnots();
455    
456    
457    
458     }
459     #endif