ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 295
Committed: Tue Nov 8 21:46:30 2011 UTC (13 years, 6 months ago) by francois
File size: 15312 byte(s)
Log Message:
Mise a jour des CMakeListe pour rendre les choix possible

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