ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 283
Committed: Tue Sep 13 21:11:20 2011 UTC (13 years, 8 months ago) by francois
File size: 15258 byte(s)
Log Message:
structure de l'écriture

File Contents

# User Rev Content
1 francois 283 //---------------------------------------------------------------------------
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 <BRep_Tool.hxx>
38     #include <Poly_Triangulation.hxx>
39     #include <Geom_Plane.hxx>
40     #include <gp_Pln.hxx>
41     #include <Geom_CylindricalSurface.hxx>
42     #include <gp_Cylinder.hxx>
43     #include <Geom_ConicalSurface.hxx>
44     #include <gp_Cone.hxx>
45     #include <Geom_SphericalSurface.hxx>
46     #include <gp_Sphere.hxx>
47     #include "Geom_ToroidalSurface.hxx"
48     #include <gp_Torus.hxx>
49     #include <Geom_BSplineSurface.hxx>
50     #include <Geom_BezierSurface.hxx>
51     #include <GeomConvert.hxx>
52     #include <BRepBuilderAPI_NurbsConvert.hxx>
53     #include <BRepLib_FindSurface.hxx>
54     #include "mg_gestionnaire.h"
55     #include "constantegeo.h"
56    
57     #pragma package(smart_init)
58     OCC_SURFACE::OCC_SURFACE(unsigned long num, TopoDS_Face srf, OCC_FONCTION1& fonc):MG_SURFACE(num),face(srf), fonction1(fonc)
59     {
60    
61     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
62     double u1;
63     double u2;
64     double v1;
65     double v2;
66     surface->Bounds(u1,u2,v1, v2);
67     u_min=u1;
68     u_max=u2;
69     v_min=v1;
70     v_max=v2;
71    
72     }
73    
74     OCC_SURFACE::OCC_SURFACE(TopoDS_Face srf, OCC_FONCTION1& fonc):MG_SURFACE(),face(srf), fonction1(fonc)
75     {
76     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
77     double u1;
78     double u2;
79     double v1;
80     double v2;
81     surface->Bounds(u1,u2,v1, v2);
82     u_min=u1;
83     u_max=u2;
84     v_min=v1;
85     v_max=v2;
86     }
87    
88     OCC_SURFACE::OCC_SURFACE(OCC_SURFACE& mdd):MG_SURFACE(mdd),face(mdd.face), fonction1(mdd.fonction1)
89     {
90     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
91     u_min=mdd.get_umin();
92     u_max=mdd.get_umax();
93     v_min=mdd.get_vmin();
94     v_max=mdd.get_vmax();
95    
96     }
97     OCC_SURFACE::~OCC_SURFACE()
98     {
99     }
100     void OCC_SURFACE::evaluer(double *uv,double *xyz)
101     {
102    
103     const Handle(Geom_Surface) &surface=BRep_Tool::Surface(face);
104     gp_Pnt P;
105     double u=uv[0];
106     double v=uv[1];
107    
108     surface->D0(u,v,P);
109    
110     xyz[0]=P.X();
111     xyz[1]=P.Y();
112     xyz[2]=P.Z();
113     }
114     void OCC_SURFACE::deriver(double *uv,double *xyzdu, double *xyzdv)
115     {
116     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
117     double u=uv[0];
118     double v=uv[1];
119     gp_Vec D1U;
120     gp_Vec D1V;
121     gp_Pnt P;
122    
123     surface->D1(u,v,P,D1U,D1V);
124     xyzdu[0]=D1U.X();
125     xyzdu[1]=D1U.Y();
126     xyzdu[2]=D1U.Z();
127    
128     xyzdv[0]=D1V.X();
129     xyzdv[1]=D1V.Y();
130     xyzdv[2]=D1V.Z();
131    
132     }
133     void OCC_SURFACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz, double *xyzdu, double *xyzdv)
134     {
135     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
136     double u=uv[0];
137     double v=uv[1];
138     gp_Pnt P;
139     gp_Vec D1U;
140     gp_Vec D1V;
141     gp_Vec D2U;
142     gp_Vec D2V;
143     gp_Vec D2UV;
144    
145     surface->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
146    
147     xyz[0]=P.X();
148     xyz[1]=P.Y();
149     xyz[2]=P.Z();
150    
151     xyzdu[0]=D1U.X();
152     xyzdu[1]=D1U.Y();
153     xyzdu[2]=D1U.Z();
154    
155     xyzdv[0]=D1V.X();
156     xyzdv[1]=D1V.Y();
157     xyzdv[2]=D1V.Z();
158    
159     xyzduu[0]=D2U.X();
160     xyzduu[1]=D2U.Y();
161     xyzduu[2]=D2U.Z();
162    
163     xyzdvv[0]=D2V.X();
164     xyzdvv[1]=D2V.Y();
165     xyzdvv[2]=D2V.Z();
166    
167     xyzduv[0]=D2UV.X();
168     xyzduv[1]=D2UV.Y();
169     xyzduv[2]=D2UV.Z();
170    
171     }
172    
173     void OCC_SURFACE::inverser(double *uv,double *xyz,double precision)
174     {
175     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
176     double u=xyz[0];
177     double v=xyz[1];
178     double w=xyz[2];
179     gp_Pnt P(u,v,w);
180    
181     //ShapeAnalysis_Surface SAS(surface);
182     //gp_Pnt2d pnt2d=SAS.ValueOfUV(P, precision);
183    
184     GeomAPI_ProjectPointOnSurf PPS(P,surface, precision);
185     //PPS.Perform(P);
186     double UU, VV;
187     PPS.LowerDistanceParameters(UU,VV);
188    
189     uv[0]=UU;
190     uv[1]=VV;
191     }
192     int OCC_SURFACE::est_periodique_u(void)
193     {
194     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
195     return surface->IsUClosed();
196     }
197    
198     int OCC_SURFACE::est_periodique_v(void)
199     {
200     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
201     return surface->IsVPeriodic();
202     }
203     double OCC_SURFACE::get_periode_u(void)
204     {
205     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
206     if (surface->IsUPeriodic()==0) return 0.;
207     return surface->UPeriod();
208     }
209    
210     double OCC_SURFACE::get_periode_v(void)
211     {
212     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
213     if (surface->IsVPeriodic()==0) return 0.;
214     return surface->VPeriod();
215     }
216     void OCC_SURFACE::enregistrer(std::ostream& o)
217     {
218     o <<"%"<<get_id()<< "=SURFACE_OCC("<< fonction1.GetID(face)<< ");" << std::endl;
219     }
220     int OCC_SURFACE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
221     {
222     Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
223     Handle(Standard_Type) type=surface->DynamicType();
224     //******plan
225     if (type==STANDARD_TYPE(Geom_Plane))
226     {
227     Handle(Geom_Plane) Pln=Handle(Geom_Plane)::DownCast(surface);
228     gp_Pln plan=Pln->Pln();
229    
230     double origine[3];
231     gp_Pnt centre=plan.Location();
232    
233     origine[0]=centre.X();
234     origine[1]=centre.Y();
235     origine[2]=centre.Z();
236    
237     double normal[3];
238     gp_Ax1 axe=plan.Axis();
239     gp_Dir direction=axe.Direction();
240    
241     normal[0]=direction.X();
242     normal[1]=direction.Y();
243     normal[2]=direction.Z();
244    
245     param.ajouter(origine[0]);
246     param.ajouter(origine[1]);
247     param.ajouter(origine[2]);
248     param.ajouter(normal[0]);
249     param.ajouter(normal[1]);
250     param.ajouter(normal[2]);
251    
252     return MGCo_PLAN;
253     }
254     //******cylindre
255     if (type==STANDARD_TYPE(Geom_CylindricalSurface))
256     {
257     Handle(Geom_CylindricalSurface) cylinder=Handle(Geom_CylindricalSurface)::DownCast(surface);
258     gp_Cylinder cylin=cylinder->Cylinder();
259    
260     double origine[3];
261     gp_Pnt centre=cylin.Location();
262     origine[0]=centre.X();
263     origine[1]=centre.Y();
264     origine[2]=centre.Z();
265     double direction[3];
266     gp_Ax1 axe=cylin.Axis();
267     gp_Dir dir=axe.Direction();
268     direction[0]=dir.X();
269     direction[1]=dir.Y();
270     direction[2]=dir.Z();
271     double rayon;
272     rayon=cylin.Radius();
273    
274     param.ajouter(origine[0]);
275     param.ajouter(origine[1]);
276     param.ajouter(origine[2]);
277     param.ajouter(direction[0]);
278     param.ajouter(direction[1]);
279     param.ajouter(direction[2]);
280     param.ajouter(rayon);
281    
282     return MGCo_CYLINDRE;
283     }
284     //******Cone
285     if (type==STANDARD_TYPE(Geom_ConicalSurface))
286     {
287     Handle(Geom_ConicalSurface) cone=Handle(Geom_ConicalSurface)::DownCast(surface);
288     gp_Cone con=cone->Cone();
289    
290     double origine[3];
291     gp_Pnt centre=con.Location();
292     origine[0]=centre.X();
293     origine[1]=centre.Y();
294     origine[2]=centre.Z();
295     double direction[3];
296     gp_Ax1 axe=con.Axis();
297     gp_Dir dir=axe.Direction();
298     direction[0]=dir.X();
299     direction[1]=dir.Y();
300     direction[2]=dir.Z();
301     double rayon;
302     rayon=con.RefRadius();
303     double angle;
304     angle=con.SemiAngle();
305    
306     param.ajouter(origine[0]);
307     param.ajouter(origine[1]);
308     param.ajouter(origine[2]);
309     param.ajouter(direction[0]);
310     param.ajouter(direction[1]);
311     param.ajouter(direction[2]);
312     param.ajouter(rayon);
313     param.ajouter(angle);
314    
315     return MGCo_CONE;
316    
317     }
318     //*****Sphere
319     if (type==STANDARD_TYPE(Geom_SphericalSurface))
320     {
321     Handle(Geom_SphericalSurface) sphere=Handle(Geom_SphericalSurface)::DownCast(surface);
322     gp_Sphere sph=sphere->Sphere();
323    
324     double origine[3];
325     gp_Pnt centre=sph.Location();
326     origine[0]=centre.X();
327     origine[1]=centre.Y();
328     origine[2]=centre.Z();
329     double rayon;
330     rayon=sph.Radius();
331     param.ajouter(origine[0]);
332     param.ajouter(origine[1]);
333     param.ajouter(origine[2]);
334     param.ajouter(rayon);
335    
336     return MGCo_SPHERE;
337    
338     }
339     //****** Tore
340     if (type==STANDARD_TYPE(Geom_ToroidalSurface))
341     {
342     Handle(Geom_ToroidalSurface) tore=Handle(Geom_ToroidalSurface)::DownCast(surface);
343     gp_Torus tro=tore->Torus();
344     double origine[3];
345     gp_Pnt centre=tro.Location();
346     origine[0]=centre.X();
347     origine[1]=centre.Y();
348     origine[2]=centre.Z();
349     double direction[3];
350     gp_Ax1 axe=tro.Axis();
351     gp_Dir dir=axe.Direction();
352     direction[0]=dir.X();
353     direction[1]=dir.Y();
354     direction[2]=dir.Z();
355     double Grayon;
356     Grayon=tro.MajorRadius();
357     double Prayon;
358     Prayon=tro.MinorRadius();
359    
360     param.ajouter(origine[0]);
361     param.ajouter(origine[1]);
362     param.ajouter(origine[2]);
363     param.ajouter(direction[0]);
364     param.ajouter(direction[1]);
365     param.ajouter(direction[2]);
366     param.ajouter(Grayon);
367     param.ajouter(Prayon);
368    
369     return MGCo_TORE;
370    
371     }
372     //*******BSpline
373     if (type==STANDARD_TYPE(Geom_BSplineSurface))
374     {
375     Handle(Geom_BSplineSurface) bspline=Handle(Geom_BSplineSurface)::DownCast(surface);
376    
377     //nombre des noeuds suivant Udirection
378     int nb_Uknot=bspline->NbUKnots();
379     //valeur de Unoeud
380     for (int i=1; i<=nb_Uknot; i++)
381     {
382     double Uvaleur=bspline->UKnot(i);
383     param.ajouter(Uvaleur);
384     }
385     //nombre des noeuds suivants Vdirection
386     int nb_Vknot=bspline->NbVKnots();
387     //valeur de Vnoeud
388     for (int j=1; j<=nb_Vknot; j++)
389     {
390     double Vvaleur=bspline->VKnot(j);
391     param.ajouter(Vvaleur);
392     }
393     //point de controle et poids
394     gp_Pnt pctr;
395     double poids;
396     for (int u=1; u<=bspline->NbUPoles(); u++)
397     for (int v=1; v<=bspline->NbVPoles(); v++)
398     {
399     pctr=bspline->Pole(u, v);
400    
401     param.ajouter(pctr.X());
402     param.ajouter(pctr.Y());
403     param.ajouter(pctr.Z());
404    
405     poids=bspline->Weight(u, v);
406     param.ajouter(poids);
407     }
408    
409     double uDegree=bspline->UDegree();
410     param.ajouter(uDegree);
411     double vDegree=bspline->VDegree();
412     param.ajouter(vDegree);
413     return MGCo_BSPLINES;
414     }
415    
416     }
417     void OCC_SURFACE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
418     {
419     //Conversion of the complete geometry of a shape into
420     //NURBS geometry
421     BRepBuilderAPI_NurbsConvert NURBS(face);
422     Handle(Geom_Surface) surface=BRepLib_FindSurface(NURBS).Surface();
423     Handle(Geom_BSplineSurface) bspline=GeomConvert::SurfaceToBSplineSurface(surface) ;
424    
425     // The first parameter indicate the code access
426     param.ajouter(2);
427     //The follewing two parameters of the list indicate the orders of the net points
428     param.ajouter( bspline->UDegree()+1);
429     param.ajouter(bspline->VDegree()+1);
430    
431     //The follewing two parameters indicate the number of rows and colons of the control points
432     //respectively to the two parameters directions
433     param.ajouter(bspline->NbUPoles());
434     param.ajouter(bspline->NbVPoles());
435    
436     // this present the knot vector in the u-direction
437     for (unsigned int i=1;i<=bspline->NbUKnots();i++)
438     {
439     param.ajouter(bspline->UKnot(i));
440     }
441     //This present the knot vector in the v-direction
442     for (unsigned int j=1;j<=bspline->NbVKnots();j++)
443     {
444     param.ajouter(bspline->VKnot(j));
445     }
446    
447     for (int u=1;u<=bspline->NbUPoles();u++)
448     {
449     for (int v=1;v<=bspline->NbVPoles();v++)
450     {
451     double w=bspline->Weight(u,v);
452     gp_Pnt point=bspline->Pole(u, v);
453     double x=point.X();
454     double y=point.Y();
455     double z=point.Z();
456     param.ajouter(x);
457     param.ajouter(y);
458     param.ajouter(z);
459     param.ajouter(w);
460     }
461    
462     }
463     indx_premier_ptctr=5+bspline->NbUKnots()+bspline->NbVKnots();
464    
465    
466    
467    
468    
469     }
470    
471     void OCC_SURFACE::get_triangulation(MG_MAILLAGE* mai,MG_FACE* mgface,multimap<double,MG_NOEUD*,less<double> >& tabnoeudfus,double eps,int mode)
472     {
473     TopLoc_Location L;
474     Handle (Poly_Triangulation) pt=BRep_Tool::Triangulation(face,L);
475     int nbnoeud=pt->NbNodes();
476     int nbmaille=pt->NbTriangles();
477     const TColgp_Array1OfPnt& nodes = pt->Nodes();
478     const Poly_Array1OfTriangle& triangles = pt->Triangles();
479     const TColgp_Array1OfPnt2d& uvNodes = pt->UVNodes();
480     vector<MG_NOEUD*> tabnoeud;
481     for ( Standard_Integer i = 0; i < nbnoeud; i++ )
482     {
483     gp_Pnt p1=nodes(i+1);
484     double xx=p1.X();
485     double yy=p1.Y();
486     double zz=p1.Z();
487     double key=fabs(xx)+fabs(yy)+fabs(zz);
488     MG_NOEUD* nvnoeud=NULL;
489     if (mode>1)
490     {
491     multimap<double,MG_NOEUD*,less<double> >::iterator it,itbas,ithaut;
492     itbas=tabnoeudfus.lower_bound(key*0.99);
493     ithaut=tabnoeudfus.upper_bound(key*1.1010101);
494     for ( it=itbas ; it != ithaut; it++ )
495     {
496     MG_NOEUD* ntmp=(*it).second;
497     double xtmp=ntmp->get_x();
498     double ytmp=ntmp->get_y();
499     double ztmp=ntmp->get_z();
500     OT_VECTEUR_3D vec(xtmp-xx,ytmp-yy,ztmp-zz);
501     if (vec.get_longueur()<1e-6*eps) {
502     nvnoeud=ntmp;
503     break;
504     }
505     }
506     }
507     if (nvnoeud==NULL)
508     {
509     nvnoeud=new MG_NOEUD(mgface,xx,yy,zz,TRIANGULATION);
510     mai->ajouter_mg_noeud(nvnoeud);
511     std::pair<double,MG_NOEUD*> tmp(key,nvnoeud);
512     tabnoeudfus.insert(tmp);
513     }
514    
515    
516     tabnoeud.insert(tabnoeud.end(),nvnoeud);
517     }
518     for ( Standard_Integer i = 0; i < nbmaille; i++ )
519     {
520     int n1,n2,n3;
521     Poly_Triangle triangle = triangles( i + 1 );
522     bool face_reversed = (face.Orientation() == TopAbs_REVERSED);
523     if ( face_reversed )
524     triangle.Get( n1, n3, n2 );
525     else
526     triangle.Get( n1, n2, n3 );
527     MG_NOEUD* noeud1=tabnoeud[n1-1];
528     MG_NOEUD* noeud2=tabnoeud[n2-1];
529     MG_NOEUD* noeud3=tabnoeud[n3-1];
530     mai->ajouter_mg_triangle(mgface,noeud1,noeud2,noeud3,TRIANGULATION);
531    
532    
533     }
534     }
535    
536     #endif