ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 825
Committed: Wed Sep 7 11:36:26 2016 UTC (8 years, 8 months ago) by couturad
File size: 28277 byte(s)
Log Message:
Gestion des pôles de l'ellipsoide

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 couturad 818 #include <IGESSolid_SphericalSurface.hxx>
47 francois 283 #include <gp_Sphere.hxx>
48     #include "Geom_ToroidalSurface.hxx"
49     #include <gp_Torus.hxx>
50     #include <Geom_BSplineSurface.hxx>
51     #include <Geom_BezierSurface.hxx>
52     #include <GeomConvert.hxx>
53     #include <BRepBuilderAPI_NurbsConvert.hxx>
54     #include <BRepLib_FindSurface.hxx>
55     #include "mg_gestionnaire.h"
56     #include "constantegeo.h"
57 francois 295 #include "ot_mathematique.h"
58 couturad 818 #include <Geom_RectangularTrimmedSurface.hxx>
59     #include <BRepClass_FaceClassifier.hxx>
60     #include <gp_Pnt2d.hxx>
61 couturad 825 #include <Geom_SurfaceOfRevolution.hxx>
62 francois 283
63     #pragma package(smart_init)
64 francois 371
65    
66    
67     class NOEUDARETE
68     {
69     public:
70     MG_NOEUD* no;
71     MG_ARETE* are;
72     double t;
73     };
74    
75    
76    
77 couturad 740 OCC_SURFACE::OCC_SURFACE(unsigned long num, TopoDS_Face srf, OCC_FONCTION& fonc):MG_SURFACE(num),face(srf), fonction1(fonc)
78 francois 283 {
79    
80 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
81     surface=BRep_Tool::Surface(face);
82     Handle(Standard_Type) type=surface->DynamicType();
83     if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
84     {
85     Handle(Geom_RectangularTrimmedSurface) RTSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
86     surface = RTSurface->BasisSurface();
87     }
88 francois 283 double u1;
89     double u2;
90     double v1;
91     double v2;
92     surface->Bounds(u1,u2,v1, v2);
93     u_min=u1;
94     u_max=u2;
95     v_min=v1;
96     v_max=v2;
97    
98     }
99    
100 couturad 740 OCC_SURFACE::OCC_SURFACE(TopoDS_Face srf, OCC_FONCTION& fonc):MG_SURFACE(),face(srf), fonction1(fonc)
101 francois 283 {
102 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
103     surface=BRep_Tool::Surface(face);
104     Handle(Standard_Type) type=surface->DynamicType();
105     if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
106     {
107     Handle(Geom_RectangularTrimmedSurface) RTSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
108     surface = RTSurface->BasisSurface();
109     }
110 francois 283 double u1;
111     double u2;
112     double v1;
113     double v2;
114     surface->Bounds(u1,u2,v1, v2);
115     u_min=u1;
116     u_max=u2;
117     v_min=v1;
118     v_max=v2;
119 couturad 825 // std::cout << " " <<std::endl;
120     // Handle(Standard_Type) type=surface->DynamicType();
121     // if (type==STANDARD_TYPE(Geom_Plane)) std::cout << "plan" << std::endl;
122     // else if (type==STANDARD_TYPE(Geom_CylindricalSurface)) std::cout << "Cylindre" << std::endl;
123     // else if (type==STANDARD_TYPE(Geom_ConicalSurface)) std::cout << "Cone" << std::endl;
124     // else if (type==STANDARD_TYPE(Geom_SphericalSurface)) std::cout << "Sphere" << std::endl;
125     // else if (type==STANDARD_TYPE(Geom_ToroidalSurface)) std::cout << "Tore" << std::endl;
126     // else if (type==STANDARD_TYPE(Geom_BSplineSurface)) std::cout << "Bspline surf" << std::endl;
127     // else std::cout << type->Name() << std::endl;
128     //
129     // std::cout << surface->IsUClosed()<< " " <<surface->IsVClosed() <<std::endl;;
130     // std::cout << surface->IsUPeriodic() <<" " <<surface->IsVPeriodic() << std::endl;;
131     // if (surface->IsUPeriodic()) std::cout << "Pu=" << surface->UPeriod() << std::endl;;
132     // if (surface->IsVPeriodic()) std::cout << "Pv=" << surface->VPeriod() << std::endl;;
133 francois 283 }
134    
135     OCC_SURFACE::OCC_SURFACE(OCC_SURFACE& mdd):MG_SURFACE(mdd),face(mdd.face), fonction1(mdd.fonction1)
136     {
137 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
138     surface=BRep_Tool::Surface(face);
139     Handle(Standard_Type) type=surface->DynamicType();
140     if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
141     {
142     Handle(Geom_RectangularTrimmedSurface) RTSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
143     surface = RTSurface->BasisSurface();
144     }
145 francois 283 u_min=mdd.get_umin();
146     u_max=mdd.get_umax();
147     v_min=mdd.get_vmin();
148     v_max=mdd.get_vmax();
149    
150     }
151     OCC_SURFACE::~OCC_SURFACE()
152     {
153     }
154     void OCC_SURFACE::evaluer(double *uv,double *xyz)
155     {
156    
157 francois 820 //const Handle(Geom_Surface) &surface=BRep_Tool::Surface(face);
158 francois 283 gp_Pnt P;
159     double u=uv[0];
160     double v=uv[1];
161    
162     surface->D0(u,v,P);
163    
164     xyz[0]=P.X();
165     xyz[1]=P.Y();
166     xyz[2]=P.Z();
167     }
168     void OCC_SURFACE::deriver(double *uv,double *xyzdu, double *xyzdv)
169     {
170 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
171 francois 283 double u=uv[0];
172     double v=uv[1];
173     gp_Vec D1U;
174     gp_Vec D1V;
175     gp_Pnt P;
176    
177     surface->D1(u,v,P,D1U,D1V);
178     xyzdu[0]=D1U.X();
179     xyzdu[1]=D1U.Y();
180     xyzdu[2]=D1U.Z();
181    
182     xyzdv[0]=D1V.X();
183     xyzdv[1]=D1V.Y();
184     xyzdv[2]=D1V.Z();
185    
186     }
187     void OCC_SURFACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz, double *xyzdu, double *xyzdv)
188     {
189 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
190 francois 283 double u=uv[0];
191     double v=uv[1];
192     gp_Pnt P;
193     gp_Vec D1U;
194     gp_Vec D1V;
195     gp_Vec D2U;
196     gp_Vec D2V;
197     gp_Vec D2UV;
198    
199     surface->D2(u,v,P,D1U,D1V,D2U,D2V,D2UV);
200    
201     xyz[0]=P.X();
202     xyz[1]=P.Y();
203     xyz[2]=P.Z();
204    
205     xyzdu[0]=D1U.X();
206     xyzdu[1]=D1U.Y();
207     xyzdu[2]=D1U.Z();
208    
209     xyzdv[0]=D1V.X();
210     xyzdv[1]=D1V.Y();
211     xyzdv[2]=D1V.Z();
212    
213     xyzduu[0]=D2U.X();
214     xyzduu[1]=D2U.Y();
215     xyzduu[2]=D2U.Z();
216    
217     xyzdvv[0]=D2V.X();
218     xyzdvv[1]=D2V.Y();
219     xyzdvv[2]=D2V.Z();
220    
221     xyzduv[0]=D2UV.X();
222     xyzduv[1]=D2UV.Y();
223     xyzduv[2]=D2UV.Z();
224    
225     }
226    
227     void OCC_SURFACE::inverser(double *uv,double *xyz,double precision)
228     {
229 francois 820 // Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
230 francois 283 double u=xyz[0];
231     double v=xyz[1];
232     double w=xyz[2];
233     gp_Pnt P(u,v,w);
234    
235     //ShapeAnalysis_Surface SAS(surface);
236     //gp_Pnt2d pnt2d=SAS.ValueOfUV(P, precision);
237     GeomAPI_ProjectPointOnSurf PPS(P,surface, precision);
238 francois 339 if (PPS.NbPoints() < 1)
239     {
240     uv[0]=1e308;
241     uv[1]=1e308;
242     return;
243     }
244 francois 283 //PPS.Perform(P);
245     double UU, VV;
246     PPS.LowerDistanceParameters(UU,VV);
247     uv[0]=UU;
248     uv[1]=VV;
249     }
250     int OCC_SURFACE::est_periodique_u(void)
251     {
252 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
253 francois 283 return surface->IsUClosed();
254     }
255    
256     int OCC_SURFACE::est_periodique_v(void)
257     {
258 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
259 francois 731 // return surface->IsVPeriodic();
260 francois 733 return surface->IsVClosed();
261 francois 283 }
262     double OCC_SURFACE::get_periode_u(void)
263     {
264 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
265 francois 731 if (surface->IsUPeriodic()) return surface->UPeriod();
266     if (surface->IsUClosed()) return u_max-u_min;
267     return 0;
268 francois 283 }
269    
270     double OCC_SURFACE::get_periode_v(void)
271     {
272 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
273 francois 731 if (surface->IsVPeriodic()) surface->VPeriod();
274     if (surface->IsVClosed()) v_max-v_min;
275     return 0;
276    
277 francois 283 }
278 couturad 814
279 francois 763 void OCC_SURFACE::enregistrer(std::ostream& o,double version)
280 francois 283 {
281     o <<"%"<<get_id()<< "=SURFACE_OCC("<< fonction1.GetID(face)<< ");" << std::endl;
282     }
283     int OCC_SURFACE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
284     {
285 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
286 francois 283 Handle(Standard_Type) type=surface->DynamicType();
287     //******plan
288     if (type==STANDARD_TYPE(Geom_Plane))
289     {
290     Handle(Geom_Plane) Pln=Handle(Geom_Plane)::DownCast(surface);
291     gp_Pln plan=Pln->Pln();
292    
293     double origine[3];
294     gp_Pnt centre=plan.Location();
295    
296     origine[0]=centre.X();
297     origine[1]=centre.Y();
298     origine[2]=centre.Z();
299    
300     double normal[3];
301     gp_Ax1 axe=plan.Axis();
302     gp_Dir direction=axe.Direction();
303    
304     normal[0]=direction.X();
305     normal[1]=direction.Y();
306     normal[2]=direction.Z();
307    
308     param.ajouter(origine[0]);
309     param.ajouter(origine[1]);
310     param.ajouter(origine[2]);
311     param.ajouter(normal[0]);
312     param.ajouter(normal[1]);
313     param.ajouter(normal[2]);
314    
315     return MGCo_PLAN;
316     }
317     //******cylindre
318     if (type==STANDARD_TYPE(Geom_CylindricalSurface))
319     {
320     Handle(Geom_CylindricalSurface) cylinder=Handle(Geom_CylindricalSurface)::DownCast(surface);
321     gp_Cylinder cylin=cylinder->Cylinder();
322    
323     double origine[3];
324     gp_Pnt centre=cylin.Location();
325     origine[0]=centre.X();
326     origine[1]=centre.Y();
327     origine[2]=centre.Z();
328     double direction[3];
329     gp_Ax1 axe=cylin.Axis();
330     gp_Dir dir=axe.Direction();
331     direction[0]=dir.X();
332     direction[1]=dir.Y();
333     direction[2]=dir.Z();
334     double rayon;
335     rayon=cylin.Radius();
336    
337     param.ajouter(origine[0]);
338     param.ajouter(origine[1]);
339     param.ajouter(origine[2]);
340     param.ajouter(direction[0]);
341     param.ajouter(direction[1]);
342     param.ajouter(direction[2]);
343     param.ajouter(rayon);
344    
345     return MGCo_CYLINDRE;
346     }
347     //******Cone
348     if (type==STANDARD_TYPE(Geom_ConicalSurface))
349     {
350     Handle(Geom_ConicalSurface) cone=Handle(Geom_ConicalSurface)::DownCast(surface);
351     gp_Cone con=cone->Cone();
352    
353     double origine[3];
354     gp_Pnt centre=con.Location();
355     origine[0]=centre.X();
356     origine[1]=centre.Y();
357     origine[2]=centre.Z();
358     double direction[3];
359     gp_Ax1 axe=con.Axis();
360     gp_Dir dir=axe.Direction();
361     direction[0]=dir.X();
362     direction[1]=dir.Y();
363     direction[2]=dir.Z();
364     double rayon;
365     rayon=con.RefRadius();
366     double angle;
367     angle=con.SemiAngle();
368    
369     param.ajouter(origine[0]);
370     param.ajouter(origine[1]);
371     param.ajouter(origine[2]);
372     param.ajouter(direction[0]);
373     param.ajouter(direction[1]);
374     param.ajouter(direction[2]);
375     param.ajouter(rayon);
376     param.ajouter(angle);
377    
378     return MGCo_CONE;
379    
380     }
381     //*****Sphere
382     if (type==STANDARD_TYPE(Geom_SphericalSurface))
383     {
384     Handle(Geom_SphericalSurface) sphere=Handle(Geom_SphericalSurface)::DownCast(surface);
385     gp_Sphere sph=sphere->Sphere();
386    
387     double origine[3];
388     gp_Pnt centre=sph.Location();
389     origine[0]=centre.X();
390     origine[1]=centre.Y();
391     origine[2]=centre.Z();
392     double rayon;
393     rayon=sph.Radius();
394     param.ajouter(origine[0]);
395     param.ajouter(origine[1]);
396     param.ajouter(origine[2]);
397     param.ajouter(rayon);
398    
399     return MGCo_SPHERE;
400    
401     }
402     //****** Tore
403     if (type==STANDARD_TYPE(Geom_ToroidalSurface))
404     {
405     Handle(Geom_ToroidalSurface) tore=Handle(Geom_ToroidalSurface)::DownCast(surface);
406     gp_Torus tro=tore->Torus();
407     double origine[3];
408     gp_Pnt centre=tro.Location();
409     origine[0]=centre.X();
410     origine[1]=centre.Y();
411     origine[2]=centre.Z();
412     double direction[3];
413     gp_Ax1 axe=tro.Axis();
414     gp_Dir dir=axe.Direction();
415     direction[0]=dir.X();
416     direction[1]=dir.Y();
417     direction[2]=dir.Z();
418     double Grayon;
419     Grayon=tro.MajorRadius();
420     double Prayon;
421     Prayon=tro.MinorRadius();
422    
423     param.ajouter(origine[0]);
424     param.ajouter(origine[1]);
425     param.ajouter(origine[2]);
426     param.ajouter(direction[0]);
427     param.ajouter(direction[1]);
428     param.ajouter(direction[2]);
429     param.ajouter(Grayon);
430     param.ajouter(Prayon);
431    
432     return MGCo_TORE;
433    
434     }
435     //*******BSpline
436     if (type==STANDARD_TYPE(Geom_BSplineSurface))
437     {
438     Handle(Geom_BSplineSurface) bspline=Handle(Geom_BSplineSurface)::DownCast(surface);
439    
440     //nombre des noeuds suivant Udirection
441     int nb_Uknot=bspline->NbUKnots();
442     //valeur de Unoeud
443     for (int i=1; i<=nb_Uknot; i++)
444     {
445     double Uvaleur=bspline->UKnot(i);
446     param.ajouter(Uvaleur);
447     }
448     //nombre des noeuds suivants Vdirection
449     int nb_Vknot=bspline->NbVKnots();
450     //valeur de Vnoeud
451     for (int j=1; j<=nb_Vknot; j++)
452     {
453     double Vvaleur=bspline->VKnot(j);
454     param.ajouter(Vvaleur);
455     }
456     //point de controle et poids
457     gp_Pnt pctr;
458     double poids;
459     for (int u=1; u<=bspline->NbUPoles(); u++)
460     for (int v=1; v<=bspline->NbVPoles(); v++)
461     {
462     pctr=bspline->Pole(u, v);
463    
464     param.ajouter(pctr.X());
465     param.ajouter(pctr.Y());
466     param.ajouter(pctr.Z());
467    
468     poids=bspline->Weight(u, v);
469     param.ajouter(poids);
470     }
471    
472     double uDegree=bspline->UDegree();
473     param.ajouter(uDegree);
474     double vDegree=bspline->VDegree();
475     param.ajouter(vDegree);
476     return MGCo_BSPLINES;
477     }
478    
479     }
480     void OCC_SURFACE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
481     {
482     //Conversion of the complete geometry of a shape into
483     //NURBS geometry
484     BRepBuilderAPI_NurbsConvert NURBS(face);
485     Handle(Geom_Surface) surface=BRepLib_FindSurface(NURBS).Surface();
486     Handle(Geom_BSplineSurface) bspline=GeomConvert::SurfaceToBSplineSurface(surface) ;
487    
488     // The first parameter indicate the code access
489     param.ajouter(2);
490     //The follewing two parameters of the list indicate the orders of the net points
491     param.ajouter( bspline->UDegree()+1);
492     param.ajouter(bspline->VDegree()+1);
493    
494     //The follewing two parameters indicate the number of rows and colons of the control points
495     //respectively to the two parameters directions
496     param.ajouter(bspline->NbUPoles());
497     param.ajouter(bspline->NbVPoles());
498    
499     // this present the knot vector in the u-direction
500     for (unsigned int i=1;i<=bspline->NbUKnots();i++)
501     {
502     param.ajouter(bspline->UKnot(i));
503     }
504     //This present the knot vector in the v-direction
505     for (unsigned int j=1;j<=bspline->NbVKnots();j++)
506     {
507     param.ajouter(bspline->VKnot(j));
508     }
509 francois 363 for (int v=1;v<=bspline->NbVPoles();v++)
510 francois 283 {
511 francois 363 for (int u=1;u<=bspline->NbUPoles();u++)
512 francois 283 {
513     double w=bspline->Weight(u,v);
514     gp_Pnt point=bspline->Pole(u, v);
515     double x=point.X();
516     double y=point.Y();
517     double z=point.Z();
518     param.ajouter(x);
519     param.ajouter(y);
520     param.ajouter(z);
521     param.ajouter(w);
522     }
523    
524     }
525     indx_premier_ptctr=5+bspline->NbUKnots()+bspline->NbVKnots();
526    
527    
528    
529    
530    
531     }
532    
533 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)
534 francois 283 {
535 francois 353 TPL_MAP_ENTITE<MG_SOMMET*> listsom;
536     TPL_MAP_ENTITE<MG_ARETE*> listare;
537 francois 371 //std::map<unsigned long,bool> aretemaille;
538     std::map<unsigned long,std::map<double,NOEUDARETE,less<double> >,less<unsigned long> > areteamaille;
539 francois 353 int nbboucle=mgface->get_nb_mg_boucle();
540     for (int i=0;i<nbboucle;i++)
541     {
542     MG_BOUCLE* bou=mgface->get_mg_boucle(i);
543     int nbarete=bou->get_nb_mg_coarete();
544     for (int j=0;j<nbarete;j++)
545     {
546     MG_ARETE* are=bou->get_mg_coarete(j)->get_arete();
547     listare.ajouter(are);
548 francois 371 //bool amailler=true;
549     //if (are->get_lien_maillage()->get_nb()>0) amailler=false;
550     //aretemaille[are->get_id()]=amailler;
551 francois 353 listsom.ajouter(bou->get_mg_coarete(j)->get_arete()->get_cosommet1()->get_sommet());
552 francois 371 listsom.ajouter(bou->get_mg_coarete(j)->get_arete()->get_cosommet2()->get_sommet());
553     std::map<double,NOEUDARETE,less<double> > tmp;
554     std::pair<unsigned long,std::map<double,NOEUDARETE,less<double> > > maptmp(are->get_id(),tmp);
555     areteamaille.insert(maptmp);
556 francois 353 }
557     }
558 foucault 569
559    
560 francois 283 TopLoc_Location L;
561     Handle (Poly_Triangulation) pt=BRep_Tool::Triangulation(face,L);
562     int nbnoeud=pt->NbNodes();
563     int nbmaille=pt->NbTriangles();
564     const TColgp_Array1OfPnt& nodes = pt->Nodes();
565     const Poly_Array1OfTriangle& triangles = pt->Triangles();
566     const TColgp_Array1OfPnt2d& uvNodes = pt->UVNodes();
567 francois 295 std::vector<MG_NOEUD*> tabnoeud;
568 francois 283 for ( Standard_Integer i = 0; i < nbnoeud; i++ )
569     {
570 foucault 569 gp_Pnt p1=nodes(i+1);
571     double xx=p1.X();
572     double yy=p1.Y();
573     double zz=p1.Z();
574     double key=fabs(xx)+fabs(yy)+fabs(zz);
575     MG_NOEUD* nvnoeud=NULL;
576     if (mode>1)
577     {
578     std::multimap<double,MG_NOEUD*,std::less<double> >::iterator it,itbas,ithaut;
579     itbas=tabnoeudfus.lower_bound(key*0.99);
580     ithaut=tabnoeudfus.upper_bound(key*1.1010101);
581     for ( it=itbas ; it != ithaut; it++ )
582     {
583     MG_NOEUD* ntmp=(*it).second;
584     double xtmp=ntmp->get_x();
585     double ytmp=ntmp->get_y();
586     double ztmp=ntmp->get_z();
587     OT_VECTEUR_3D vec(xtmp-xx,ytmp-yy,ztmp-zz);
588     if (vec.get_longueur()<1e-6*eps) {
589     nvnoeud=ntmp;
590     break;
591     }
592     }
593     }
594     if (nvnoeud==NULL)
595     {
596     MG_ELEMENT_TOPOLOGIQUE *topo=mgface;
597     TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it1;
598     for (MG_SOMMET* som=listsom.get_premier(it1);som!=NULL;som=listsom.get_suivant(it1))
599     {
600     double xyz[3];
601     som->get_point()->evaluer(xyz);
602     OT_VECTEUR_3D vec(xyz[0]-xx,xyz[1]-yy,xyz[2]-zz);
603     if (vec.get_longueur()<1e-6*eps)
604     {
605     topo=som;
606     break;
607 francois 283
608 foucault 569 }
609     }
610     double param_t;
611     if (topo==mgface)
612     {
613     TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it2;
614     for (MG_ARETE* are=listare.get_premier(it2);are!=NULL;are=listare.get_suivant(it2))
615     {
616     double t;
617     double xyz[3]={xx,yy,zz};
618     are->inverser(t,xyz);
619     if (are->get_courbe()->est_periodique())
620     if (t< are->get_tmin()) t=t+are->get_courbe()->get_periode();
621     double xyztmp[3];
622     are->evaluer(t,xyztmp );
623     OT_VECTEUR_3D vec(xyz,xyztmp);
624     if (vec.get_longueur()<1e-6*eps)
625     if ((t>are->get_tmin()) && (t<are->get_tmax()))
626     {
627     topo=are;
628     param_t=t;
629     break;
630     }
631     }
632     }
633 francois 791 nvnoeud=new MG_NOEUD(topo,xx,yy,zz,MAGIC::ORIGINE::TRIANGULATION);
634 foucault 569 mai->ajouter_mg_noeud(nvnoeud);
635     std::pair<double,MG_NOEUD*> tmp(key,nvnoeud);
636     tabnoeudfus.insert(tmp);
637     if (topo->get_dimension()==1)
638     {
639     NOEUDARETE na;
640     na.no=nvnoeud;
641     na.are=(MG_ARETE*)topo;
642     na.t=param_t;
643     std::pair<double,NOEUDARETE> tmp(na.t,na);
644     areteamaille[topo->get_id()].insert(tmp);
645     }
646     }
647 francois 283
648 foucault 569
649 francois 283 tabnoeud.insert(tabnoeud.end(),nvnoeud);
650     }
651     for ( Standard_Integer i = 0; i < nbmaille; i++ )
652     {
653     int n1,n2,n3;
654     Poly_Triangle triangle = triangles( i + 1 );
655     bool face_reversed = (face.Orientation() == TopAbs_REVERSED);
656     if ( face_reversed )
657     triangle.Get( n1, n3, n2 );
658     else
659     triangle.Get( n1, n2, n3 );
660 francois 525 MG_NOEUD* noeud1=tabnoeud[n1-1];
661 francois 283 MG_NOEUD* noeud2=tabnoeud[n2-1];
662     MG_NOEUD* noeud3=tabnoeud[n3-1];
663 francois 525 if (noeud1==noeud2) continue;
664     if (noeud1==noeud3) continue;
665     if (noeud2==noeud3) continue;
666 francois 791 mai->ajouter_mg_triangle(mgface,noeud1,noeud2,noeud3,MAGIC::ORIGINE::TRIANGULATION);
667 francois 525 /*if (noeud1->get_lien_topologie()->get_dimension()==0)
668 francois 353 {
669     MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
670     som->get_lien_maillage()->ajouter(noeud1);
671     }
672     if (noeud2->get_lien_topologie()->get_dimension()==0)
673     {
674     MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
675     som->get_lien_maillage()->ajouter(noeud2);
676     }
677     if (noeud3->get_lien_topologie()->get_dimension()==0)
678     {
679     MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
680     som->get_lien_maillage()->ajouter(noeud3);
681 francois 525 }*/
682 francois 371 /*if (noeud1->get_lien_topologie()==noeud2->get_lien_topologie())
683 francois 353 if (noeud1->get_lien_topologie()->get_dimension()==1)
684     {
685     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
686     if (aretemaille[are->get_id()]==true)
687     {
688     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud2,TRIANGULATION);
689     are->get_lien_maillage()->ajouter(seg);
690     }
691     }
692     if (noeud1->get_lien_topologie()==noeud3->get_lien_topologie())
693     if (noeud1->get_lien_topologie()->get_dimension()==1)
694     {
695     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
696     if (aretemaille[are->get_id()]==true)
697     {
698     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud3,TRIANGULATION);
699     are->get_lien_maillage()->ajouter(seg);
700     }
701 francois 371 }#include <../gmsh/tutorial/t8.geo>
702 francois 353 if (noeud3->get_lien_topologie()==noeud2->get_lien_topologie())
703     if (noeud3->get_lien_topologie()->get_dimension()==1)
704     {
705     MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
706     if (aretemaille[are->get_id()]==true)
707     {
708     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud2,TRIANGULATION);
709     are->get_lien_maillage()->ajouter(seg);
710     }
711     }
712     if (noeud1->get_lien_topologie()->get_dimension()==1)
713     if (noeud2->get_lien_topologie()->get_dimension()==0)
714     {
715     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
716     MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
717     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
718     {
719     if (aretemaille[are->get_id()]==true)
720     {
721     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud2,TRIANGULATION);
722     are->get_lien_maillage()->ajouter(seg);
723     }
724     }
725     }
726     if (noeud1->get_lien_topologie()->get_dimension()==1)
727     if (noeud3->get_lien_topologie()->get_dimension()==0)
728     {
729     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
730     MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
731     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
732     {
733     if (aretemaille[are->get_id()]==true)
734     {
735     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud3,TRIANGULATION);
736     are->get_lien_maillage()->ajouter(seg);
737     }
738     }
739     }
740     if (noeud2->get_lien_topologie()->get_dimension()==1)
741     if (noeud1->get_lien_topologie()->get_dimension()==0)
742     {
743     MG_ARETE* are=(MG_ARETE*)noeud2->get_lien_topologie();
744     MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
745     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
746     {
747     if (aretemaille[are->get_id()]==true)
748     {
749     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud2,noeud1,TRIANGULATION);
750     are->get_lien_maillage()->ajouter(seg);
751     }
752     }
753     }
754     if (noeud2->get_lien_topologie()->get_dimension()==1)
755     if (noeud3->get_lien_topologie()->get_dimension()==0)
756     {
757     MG_ARETE* are=(MG_ARETE*)noeud2->get_lien_topologie();
758     MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
759     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
760     {
761     if (aretemaille[are->get_id()]==true)
762     {
763     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud2,noeud3,TRIANGULATION);
764     are->get_lien_maillage()->ajouter(seg);
765     }
766     }
767     }
768     if (noeud3->get_lien_topologie()->get_dimension()==1)
769     if (noeud1->get_lien_topologie()->get_dimension()==0)
770     {
771     MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
772     MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
773     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
774     {
775     if (aretemaille[are->get_id()]==true)
776     {
777     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud1,TRIANGULATION);
778     are->get_lien_maillage()->ajouter(seg);
779     }
780     }
781     }
782     if (noeud3->get_lien_topologie()->get_dimension()==1)
783     if (noeud2->get_lien_topologie()->get_dimension()==0)
784     {
785     MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
786     MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
787     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
788     {
789     if (aretemaille[are->get_id()]==true)
790     {
791     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud2,TRIANGULATION);
792     are->get_lien_maillage()->ajouter(seg);
793     }
794     }
795 francois 371 }*/
796 francois 283 }
797 francois 525 if (mode>1)
798     {
799 francois 353 TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it2;
800     for (MG_ARETE* are=listare.get_premier(it2);are!=NULL;are=listare.get_suivant(it2))
801     {
802     if (are->get_lien_maillage()->get_nb()==0)
803     {
804 francois 371 unsigned long id=are->get_id();
805     MG_NOEUD* nodep=(MG_NOEUD*)are->get_cosommet1()->get_sommet()->get_lien_maillage()->get(0);
806     MG_NOEUD* noarr=(MG_NOEUD*)are->get_cosommet2()->get_sommet()->get_lien_maillage()->get(0);
807     std::map<double,NOEUDARETE,less<double> >::iterator it=areteamaille[id].begin();
808     MG_NOEUD* noeudcourant=nodep;
809     while (it!=areteamaille[id].end())
810     {
811     MG_NOEUD* noeud=(*it).second.no;
812 francois 525 //MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeudcourant,noeud,TRIANGULATION);
813     MG_SEGMENT* seg=mai->get_mg_segment(noeudcourant->get_id(),noeud->get_id());
814     seg->change_lien_topologie(are);
815 francois 371 noeudcourant=noeud;
816     it++;
817     }
818 francois 525 //MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeudcourant,noarr,TRIANGULATION);
819     MG_SEGMENT* seg=mai->get_mg_segment(noeudcourant->get_id(),noarr->get_id());
820     seg->change_lien_topologie(are);
821 francois 353 }
822     }
823 francois 525
824     }
825 francois 283 }
826    
827 francois 820 void OCC_SURFACE::get_liste_pole(std::vector< double> *liste_pole,double eps)
828 couturad 814 {
829 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
830 couturad 818 Handle(Standard_Type) type=surface->DynamicType();
831 francois 820 //std::cout << surface->DynamicType()->Name() <<std::endl;
832 couturad 818 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
833     {
834     Handle(Geom_RectangularTrimmedSurface) RTSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
835     Handle(Geom_Surface) basissurface = RTSurface->BasisSurface();
836     Handle(Standard_Type) type_basissurface=basissurface->DynamicType();
837     if(type_basissurface==STANDARD_TYPE(Geom_SphericalSurface))
838     {
839     type=STANDARD_TYPE(Geom_SphericalSurface);
840     }
841     }
842 couturad 814 if(type==STANDARD_TYPE(Geom_SphericalSurface))
843 couturad 818 {
844     BRepClass_FaceClassifier faceclassifier;
845     gp_Pnt2d pnt2d_pole_sud(0.0,-M_PI/2.);
846 francois 820 faceclassifier.Perform(face,pnt2d_pole_sud,eps);
847 couturad 818 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
848     {
849 francois 820 liste_pole->push_back(0.0);
850     liste_pole->push_back(-M_PI/2.);
851 couturad 818 }
852     gp_Pnt2d pnt2d_pole_nord(0.0,M_PI/2.);
853 francois 820 faceclassifier.Perform(face,pnt2d_pole_nord,eps);
854 couturad 818 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
855     {
856 francois 820 liste_pole->push_back(0.0);
857     liste_pole->push_back(M_PI/2.);
858 couturad 818 }
859 couturad 825 }
860     if(type==STANDARD_TYPE(Geom_SurfaceOfRevolution))
861     {
862     BRepClass_FaceClassifier faceclassifier;
863     gp_Pnt2d pnt2d_pole_sud(0.0,v_min);
864     faceclassifier.Perform(face,pnt2d_pole_sud,eps);
865     if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
866     {
867     liste_pole->push_back(0.0);
868     liste_pole->push_back(v_min);
869     }
870     gp_Pnt2d pnt2d_pole_nord(0.0,v_max);
871     faceclassifier.Perform(face,pnt2d_pole_nord,eps);
872     if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
873     {
874     liste_pole->push_back(0.0);
875     liste_pole->push_back(v_max);
876     }
877     }
878 couturad 814 }
879    
880    
881    
882    
883    
884 francois 283 #endif