ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 886
Committed: Fri May 26 23:30:57 2017 UTC (7 years, 11 months ago) by francois
File size: 29205 byte(s)
Log Message:
Divers bug rencontré 
* cylindre cone et tore mal defini dans occ_surface
*parenthese de trop dans les fichiers magic pour les entitées topologiques

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 francois 886 double directionX[3];
329 francois 283 double direction[3];
330     double rayon;
331     rayon=cylin.Radius();
332    
333 francois 886 gp_Ax3 repere=cylin.Position();
334     gp_Dir dirX=repere.XDirection();
335     gp_Dir dirZ=repere.Direction();
336     directionX[0]=dirX.X();
337     directionX[1]=dirX.Y();
338     directionX[2]=dirX.Z();
339     direction[0]=dirZ.X();
340     direction[1]=dirZ.Y();
341     direction[2]=dirZ.Z();
342    
343    
344    
345 francois 283 param.ajouter(origine[0]);
346     param.ajouter(origine[1]);
347     param.ajouter(origine[2]);
348 francois 886 param.ajouter(directionX[0]);
349     param.ajouter(directionX[1]);
350     param.ajouter(directionX[2]);
351 francois 283 param.ajouter(direction[0]);
352     param.ajouter(direction[1]);
353     param.ajouter(direction[2]);
354     param.ajouter(rayon);
355 francois 886 param.ajouter(rayon);
356 francois 283
357     return MGCo_CYLINDRE;
358     }
359     //******Cone
360     if (type==STANDARD_TYPE(Geom_ConicalSurface))
361     {
362     Handle(Geom_ConicalSurface) cone=Handle(Geom_ConicalSurface)::DownCast(surface);
363     gp_Cone con=cone->Cone();
364    
365     double origine[3];
366     gp_Pnt centre=con.Location();
367     origine[0]=centre.X();
368     origine[1]=centre.Y();
369     origine[2]=centre.Z();
370     double direction[3];
371 francois 886 double directionX[3];
372 francois 283 double rayon;
373     rayon=con.RefRadius();
374     double angle;
375     angle=con.SemiAngle();
376 francois 886
377     gp_Ax3 repere=con.Position();
378     gp_Dir dirX=repere.XDirection();
379     gp_Dir dirZ=repere.Direction();
380     directionX[0]=dirX.X();
381     directionX[1]=dirX.Y();
382     directionX[2]=dirX.Z();
383     direction[0]=dirZ.X();
384     direction[1]=dirZ.Y();
385     direction[2]=dirZ.Z();
386 francois 283 param.ajouter(origine[0]);
387     param.ajouter(origine[1]);
388     param.ajouter(origine[2]);
389 francois 886 param.ajouter(directionX[0]);
390     param.ajouter(directionX[1]);
391     param.ajouter(directionX[2]);
392     param.ajouter(direction[0]);
393 francois 283 param.ajouter(direction[1]);
394     param.ajouter(direction[2]);
395     param.ajouter(rayon);
396 francois 886 param.ajouter(rayon);
397     param.ajouter(cos(angle));
398     param.ajouter(sin(angle));
399 francois 283
400     return MGCo_CONE;
401    
402     }
403     //*****Sphere
404     if (type==STANDARD_TYPE(Geom_SphericalSurface))
405     {
406     Handle(Geom_SphericalSurface) sphere=Handle(Geom_SphericalSurface)::DownCast(surface);
407     gp_Sphere sph=sphere->Sphere();
408    
409     double origine[3];
410     gp_Pnt centre=sph.Location();
411     origine[0]=centre.X();
412     origine[1]=centre.Y();
413     origine[2]=centre.Z();
414     double rayon;
415     rayon=sph.Radius();
416     param.ajouter(origine[0]);
417     param.ajouter(origine[1]);
418     param.ajouter(origine[2]);
419     param.ajouter(rayon);
420    
421     return MGCo_SPHERE;
422    
423     }
424     //****** Tore
425     if (type==STANDARD_TYPE(Geom_ToroidalSurface))
426     {
427     Handle(Geom_ToroidalSurface) tore=Handle(Geom_ToroidalSurface)::DownCast(surface);
428     gp_Torus tro=tore->Torus();
429     double origine[3];
430     gp_Pnt centre=tro.Location();
431     origine[0]=centre.X();
432     origine[1]=centre.Y();
433     origine[2]=centre.Z();
434     double direction[3];
435 francois 886 double directionX[3];
436 francois 283 double Grayon;
437     Grayon=tro.MajorRadius();
438     double Prayon;
439     Prayon=tro.MinorRadius();
440 francois 886 gp_Ax3 repere=tro.Position();
441     gp_Dir dirX=repere.XDirection();
442     gp_Dir dirZ=repere.Direction();
443     directionX[0]=dirX.X();
444     directionX[1]=dirX.Y();
445     directionX[2]=dirX.Z();
446     direction[0]=dirZ.X();
447     direction[1]=dirZ.Y();
448     direction[2]=dirZ.Z();
449 francois 283 param.ajouter(origine[0]);
450     param.ajouter(origine[1]);
451     param.ajouter(origine[2]);
452 francois 886 param.ajouter(directionX[0]);
453     param.ajouter(directionX[1]);
454     param.ajouter(directionX[2]);
455     param.ajouter(direction[0]);
456 francois 283 param.ajouter(direction[1]);
457     param.ajouter(direction[2]);
458     param.ajouter(Grayon);
459     param.ajouter(Prayon);
460    
461     return MGCo_TORE;
462    
463     }
464     //*******BSpline
465     if (type==STANDARD_TYPE(Geom_BSplineSurface))
466     {
467     Handle(Geom_BSplineSurface) bspline=Handle(Geom_BSplineSurface)::DownCast(surface);
468    
469     //nombre des noeuds suivant Udirection
470     int nb_Uknot=bspline->NbUKnots();
471     //valeur de Unoeud
472     for (int i=1; i<=nb_Uknot; i++)
473     {
474     double Uvaleur=bspline->UKnot(i);
475     param.ajouter(Uvaleur);
476     }
477     //nombre des noeuds suivants Vdirection
478     int nb_Vknot=bspline->NbVKnots();
479     //valeur de Vnoeud
480     for (int j=1; j<=nb_Vknot; j++)
481     {
482     double Vvaleur=bspline->VKnot(j);
483     param.ajouter(Vvaleur);
484     }
485     //point de controle et poids
486     gp_Pnt pctr;
487     double poids;
488     for (int u=1; u<=bspline->NbUPoles(); u++)
489     for (int v=1; v<=bspline->NbVPoles(); v++)
490     {
491     pctr=bspline->Pole(u, v);
492    
493     param.ajouter(pctr.X());
494     param.ajouter(pctr.Y());
495     param.ajouter(pctr.Z());
496    
497     poids=bspline->Weight(u, v);
498     param.ajouter(poids);
499     }
500    
501     double uDegree=bspline->UDegree();
502     param.ajouter(uDegree);
503     double vDegree=bspline->VDegree();
504     param.ajouter(vDegree);
505     return MGCo_BSPLINES;
506     }
507    
508     }
509     void OCC_SURFACE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
510     {
511     //Conversion of the complete geometry of a shape into
512     //NURBS geometry
513     BRepBuilderAPI_NurbsConvert NURBS(face);
514     Handle(Geom_Surface) surface=BRepLib_FindSurface(NURBS).Surface();
515     Handle(Geom_BSplineSurface) bspline=GeomConvert::SurfaceToBSplineSurface(surface) ;
516    
517     // The first parameter indicate the code access
518     param.ajouter(2);
519     //The follewing two parameters of the list indicate the orders of the net points
520     param.ajouter( bspline->UDegree()+1);
521     param.ajouter(bspline->VDegree()+1);
522    
523     //The follewing two parameters indicate the number of rows and colons of the control points
524     //respectively to the two parameters directions
525     param.ajouter(bspline->NbUPoles());
526     param.ajouter(bspline->NbVPoles());
527    
528     // this present the knot vector in the u-direction
529     for (unsigned int i=1;i<=bspline->NbUKnots();i++)
530     {
531     param.ajouter(bspline->UKnot(i));
532     }
533     //This present the knot vector in the v-direction
534     for (unsigned int j=1;j<=bspline->NbVKnots();j++)
535     {
536     param.ajouter(bspline->VKnot(j));
537     }
538 francois 363 for (int v=1;v<=bspline->NbVPoles();v++)
539 francois 283 {
540 francois 363 for (int u=1;u<=bspline->NbUPoles();u++)
541 francois 283 {
542     double w=bspline->Weight(u,v);
543     gp_Pnt point=bspline->Pole(u, v);
544     double x=point.X();
545     double y=point.Y();
546     double z=point.Z();
547     param.ajouter(x);
548     param.ajouter(y);
549     param.ajouter(z);
550     param.ajouter(w);
551     }
552    
553     }
554     indx_premier_ptctr=5+bspline->NbUKnots()+bspline->NbVKnots();
555    
556    
557    
558    
559    
560     }
561    
562 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)
563 francois 283 {
564 francois 353 TPL_MAP_ENTITE<MG_SOMMET*> listsom;
565     TPL_MAP_ENTITE<MG_ARETE*> listare;
566 francois 371 //std::map<unsigned long,bool> aretemaille;
567     std::map<unsigned long,std::map<double,NOEUDARETE,less<double> >,less<unsigned long> > areteamaille;
568 francois 353 int nbboucle=mgface->get_nb_mg_boucle();
569     for (int i=0;i<nbboucle;i++)
570     {
571     MG_BOUCLE* bou=mgface->get_mg_boucle(i);
572     int nbarete=bou->get_nb_mg_coarete();
573     for (int j=0;j<nbarete;j++)
574     {
575     MG_ARETE* are=bou->get_mg_coarete(j)->get_arete();
576     listare.ajouter(are);
577 francois 371 //bool amailler=true;
578     //if (are->get_lien_maillage()->get_nb()>0) amailler=false;
579     //aretemaille[are->get_id()]=amailler;
580 francois 353 listsom.ajouter(bou->get_mg_coarete(j)->get_arete()->get_cosommet1()->get_sommet());
581 francois 371 listsom.ajouter(bou->get_mg_coarete(j)->get_arete()->get_cosommet2()->get_sommet());
582     std::map<double,NOEUDARETE,less<double> > tmp;
583     std::pair<unsigned long,std::map<double,NOEUDARETE,less<double> > > maptmp(are->get_id(),tmp);
584     areteamaille.insert(maptmp);
585 francois 353 }
586     }
587 foucault 569
588    
589 francois 283 TopLoc_Location L;
590     Handle (Poly_Triangulation) pt=BRep_Tool::Triangulation(face,L);
591     int nbnoeud=pt->NbNodes();
592     int nbmaille=pt->NbTriangles();
593     const TColgp_Array1OfPnt& nodes = pt->Nodes();
594     const Poly_Array1OfTriangle& triangles = pt->Triangles();
595     const TColgp_Array1OfPnt2d& uvNodes = pt->UVNodes();
596 francois 295 std::vector<MG_NOEUD*> tabnoeud;
597 francois 283 for ( Standard_Integer i = 0; i < nbnoeud; i++ )
598     {
599 foucault 569 gp_Pnt p1=nodes(i+1);
600     double xx=p1.X();
601     double yy=p1.Y();
602     double zz=p1.Z();
603     double key=fabs(xx)+fabs(yy)+fabs(zz);
604     MG_NOEUD* nvnoeud=NULL;
605     if (mode>1)
606     {
607     std::multimap<double,MG_NOEUD*,std::less<double> >::iterator it,itbas,ithaut;
608     itbas=tabnoeudfus.lower_bound(key*0.99);
609     ithaut=tabnoeudfus.upper_bound(key*1.1010101);
610     for ( it=itbas ; it != ithaut; it++ )
611     {
612     MG_NOEUD* ntmp=(*it).second;
613     double xtmp=ntmp->get_x();
614     double ytmp=ntmp->get_y();
615     double ztmp=ntmp->get_z();
616     OT_VECTEUR_3D vec(xtmp-xx,ytmp-yy,ztmp-zz);
617     if (vec.get_longueur()<1e-6*eps) {
618     nvnoeud=ntmp;
619     break;
620     }
621     }
622     }
623     if (nvnoeud==NULL)
624     {
625     MG_ELEMENT_TOPOLOGIQUE *topo=mgface;
626     TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it1;
627     for (MG_SOMMET* som=listsom.get_premier(it1);som!=NULL;som=listsom.get_suivant(it1))
628     {
629     double xyz[3];
630     som->get_point()->evaluer(xyz);
631     OT_VECTEUR_3D vec(xyz[0]-xx,xyz[1]-yy,xyz[2]-zz);
632     if (vec.get_longueur()<1e-6*eps)
633     {
634     topo=som;
635     break;
636 francois 283
637 foucault 569 }
638     }
639     double param_t;
640     if (topo==mgface)
641     {
642     TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it2;
643     for (MG_ARETE* are=listare.get_premier(it2);are!=NULL;are=listare.get_suivant(it2))
644     {
645     double t;
646     double xyz[3]={xx,yy,zz};
647     are->inverser(t,xyz);
648     if (are->get_courbe()->est_periodique())
649     if (t< are->get_tmin()) t=t+are->get_courbe()->get_periode();
650     double xyztmp[3];
651     are->evaluer(t,xyztmp );
652     OT_VECTEUR_3D vec(xyz,xyztmp);
653     if (vec.get_longueur()<1e-6*eps)
654     if ((t>are->get_tmin()) && (t<are->get_tmax()))
655     {
656     topo=are;
657     param_t=t;
658     break;
659     }
660     }
661     }
662 francois 791 nvnoeud=new MG_NOEUD(topo,xx,yy,zz,MAGIC::ORIGINE::TRIANGULATION);
663 foucault 569 mai->ajouter_mg_noeud(nvnoeud);
664     std::pair<double,MG_NOEUD*> tmp(key,nvnoeud);
665     tabnoeudfus.insert(tmp);
666     if (topo->get_dimension()==1)
667     {
668     NOEUDARETE na;
669     na.no=nvnoeud;
670     na.are=(MG_ARETE*)topo;
671     na.t=param_t;
672     std::pair<double,NOEUDARETE> tmp(na.t,na);
673     areteamaille[topo->get_id()].insert(tmp);
674     }
675     }
676 francois 283
677 foucault 569
678 francois 283 tabnoeud.insert(tabnoeud.end(),nvnoeud);
679     }
680     for ( Standard_Integer i = 0; i < nbmaille; i++ )
681     {
682     int n1,n2,n3;
683     Poly_Triangle triangle = triangles( i + 1 );
684     bool face_reversed = (face.Orientation() == TopAbs_REVERSED);
685     if ( face_reversed )
686     triangle.Get( n1, n3, n2 );
687     else
688     triangle.Get( n1, n2, n3 );
689 francois 525 MG_NOEUD* noeud1=tabnoeud[n1-1];
690 francois 283 MG_NOEUD* noeud2=tabnoeud[n2-1];
691     MG_NOEUD* noeud3=tabnoeud[n3-1];
692 francois 525 if (noeud1==noeud2) continue;
693     if (noeud1==noeud3) continue;
694     if (noeud2==noeud3) continue;
695 francois 791 mai->ajouter_mg_triangle(mgface,noeud1,noeud2,noeud3,MAGIC::ORIGINE::TRIANGULATION);
696 francois 525 /*if (noeud1->get_lien_topologie()->get_dimension()==0)
697 francois 353 {
698     MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
699     som->get_lien_maillage()->ajouter(noeud1);
700     }
701     if (noeud2->get_lien_topologie()->get_dimension()==0)
702     {
703     MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
704     som->get_lien_maillage()->ajouter(noeud2);
705     }
706     if (noeud3->get_lien_topologie()->get_dimension()==0)
707     {
708     MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
709     som->get_lien_maillage()->ajouter(noeud3);
710 francois 525 }*/
711 francois 371 /*if (noeud1->get_lien_topologie()==noeud2->get_lien_topologie())
712 francois 353 if (noeud1->get_lien_topologie()->get_dimension()==1)
713     {
714     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
715     if (aretemaille[are->get_id()]==true)
716     {
717     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud2,TRIANGULATION);
718     are->get_lien_maillage()->ajouter(seg);
719     }
720     }
721     if (noeud1->get_lien_topologie()==noeud3->get_lien_topologie())
722     if (noeud1->get_lien_topologie()->get_dimension()==1)
723     {
724     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
725     if (aretemaille[are->get_id()]==true)
726     {
727     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud3,TRIANGULATION);
728     are->get_lien_maillage()->ajouter(seg);
729     }
730 francois 371 }#include <../gmsh/tutorial/t8.geo>
731 francois 353 if (noeud3->get_lien_topologie()==noeud2->get_lien_topologie())
732     if (noeud3->get_lien_topologie()->get_dimension()==1)
733     {
734     MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
735     if (aretemaille[are->get_id()]==true)
736     {
737     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud2,TRIANGULATION);
738     are->get_lien_maillage()->ajouter(seg);
739     }
740     }
741     if (noeud1->get_lien_topologie()->get_dimension()==1)
742     if (noeud2->get_lien_topologie()->get_dimension()==0)
743     {
744     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
745     MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
746     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
747     {
748     if (aretemaille[are->get_id()]==true)
749     {
750     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud2,TRIANGULATION);
751     are->get_lien_maillage()->ajouter(seg);
752     }
753     }
754     }
755     if (noeud1->get_lien_topologie()->get_dimension()==1)
756     if (noeud3->get_lien_topologie()->get_dimension()==0)
757     {
758     MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
759     MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
760     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
761     {
762     if (aretemaille[are->get_id()]==true)
763     {
764     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud3,TRIANGULATION);
765     are->get_lien_maillage()->ajouter(seg);
766     }
767     }
768     }
769     if (noeud2->get_lien_topologie()->get_dimension()==1)
770     if (noeud1->get_lien_topologie()->get_dimension()==0)
771     {
772     MG_ARETE* are=(MG_ARETE*)noeud2->get_lien_topologie();
773     MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
774     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
775     {
776     if (aretemaille[are->get_id()]==true)
777     {
778     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud2,noeud1,TRIANGULATION);
779     are->get_lien_maillage()->ajouter(seg);
780     }
781     }
782     }
783     if (noeud2->get_lien_topologie()->get_dimension()==1)
784     if (noeud3->get_lien_topologie()->get_dimension()==0)
785     {
786     MG_ARETE* are=(MG_ARETE*)noeud2->get_lien_topologie();
787     MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
788     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
789     {
790     if (aretemaille[are->get_id()]==true)
791     {
792     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud2,noeud3,TRIANGULATION);
793     are->get_lien_maillage()->ajouter(seg);
794     }
795     }
796     }
797     if (noeud3->get_lien_topologie()->get_dimension()==1)
798     if (noeud1->get_lien_topologie()->get_dimension()==0)
799     {
800     MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
801     MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
802     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
803     {
804     if (aretemaille[are->get_id()]==true)
805     {
806     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud1,TRIANGULATION);
807     are->get_lien_maillage()->ajouter(seg);
808     }
809     }
810     }
811     if (noeud3->get_lien_topologie()->get_dimension()==1)
812     if (noeud2->get_lien_topologie()->get_dimension()==0)
813     {
814     MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
815     MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
816     if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
817     {
818     if (aretemaille[are->get_id()]==true)
819     {
820     MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud2,TRIANGULATION);
821     are->get_lien_maillage()->ajouter(seg);
822     }
823     }
824 francois 371 }*/
825 francois 283 }
826 francois 525 if (mode>1)
827     {
828 francois 353 TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it2;
829     for (MG_ARETE* are=listare.get_premier(it2);are!=NULL;are=listare.get_suivant(it2))
830     {
831     if (are->get_lien_maillage()->get_nb()==0)
832     {
833 francois 371 unsigned long id=are->get_id();
834     MG_NOEUD* nodep=(MG_NOEUD*)are->get_cosommet1()->get_sommet()->get_lien_maillage()->get(0);
835     MG_NOEUD* noarr=(MG_NOEUD*)are->get_cosommet2()->get_sommet()->get_lien_maillage()->get(0);
836     std::map<double,NOEUDARETE,less<double> >::iterator it=areteamaille[id].begin();
837     MG_NOEUD* noeudcourant=nodep;
838     while (it!=areteamaille[id].end())
839     {
840     MG_NOEUD* noeud=(*it).second.no;
841 francois 525 //MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeudcourant,noeud,TRIANGULATION);
842     MG_SEGMENT* seg=mai->get_mg_segment(noeudcourant->get_id(),noeud->get_id());
843     seg->change_lien_topologie(are);
844 francois 371 noeudcourant=noeud;
845     it++;
846     }
847 francois 525 //MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeudcourant,noarr,TRIANGULATION);
848     MG_SEGMENT* seg=mai->get_mg_segment(noeudcourant->get_id(),noarr->get_id());
849     seg->change_lien_topologie(are);
850 francois 353 }
851     }
852 francois 525
853     }
854 francois 283 }
855    
856 francois 820 void OCC_SURFACE::get_liste_pole(std::vector< double> *liste_pole,double eps)
857 couturad 814 {
858 francois 820 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
859 couturad 818 Handle(Standard_Type) type=surface->DynamicType();
860 francois 820 //std::cout << surface->DynamicType()->Name() <<std::endl;
861 couturad 818 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
862     {
863     Handle(Geom_RectangularTrimmedSurface) RTSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
864     Handle(Geom_Surface) basissurface = RTSurface->BasisSurface();
865     Handle(Standard_Type) type_basissurface=basissurface->DynamicType();
866     if(type_basissurface==STANDARD_TYPE(Geom_SphericalSurface))
867     {
868     type=STANDARD_TYPE(Geom_SphericalSurface);
869     }
870     }
871 couturad 814 if(type==STANDARD_TYPE(Geom_SphericalSurface))
872 couturad 818 {
873     BRepClass_FaceClassifier faceclassifier;
874     gp_Pnt2d pnt2d_pole_sud(0.0,-M_PI/2.);
875 francois 820 faceclassifier.Perform(face,pnt2d_pole_sud,eps);
876 couturad 818 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
877     {
878 francois 820 liste_pole->push_back(0.0);
879     liste_pole->push_back(-M_PI/2.);
880 couturad 818 }
881     gp_Pnt2d pnt2d_pole_nord(0.0,M_PI/2.);
882 francois 820 faceclassifier.Perform(face,pnt2d_pole_nord,eps);
883 couturad 818 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
884     {
885 francois 820 liste_pole->push_back(0.0);
886     liste_pole->push_back(M_PI/2.);
887 couturad 818 }
888 couturad 825 }
889     if(type==STANDARD_TYPE(Geom_SurfaceOfRevolution))
890     {
891     BRepClass_FaceClassifier faceclassifier;
892     gp_Pnt2d pnt2d_pole_sud(0.0,v_min);
893     faceclassifier.Perform(face,pnt2d_pole_sud,eps);
894     if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
895     {
896     liste_pole->push_back(0.0);
897     liste_pole->push_back(v_min);
898     }
899     gp_Pnt2d pnt2d_pole_nord(0.0,v_max);
900     faceclassifier.Perform(face,pnt2d_pole_nord,eps);
901     if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
902     {
903     liste_pole->push_back(0.0);
904     liste_pole->push_back(v_max);
905     }
906     }
907 couturad 814 }
908    
909    
910    
911    
912    
913 francois 283 #endif