ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 908
Committed: Tue Nov 21 15:33:21 2017 UTC (7 years, 5 months ago) by couturad
File size: 30895 byte(s)
Log Message:
Ajout des "#ifdef ALL_OCC" manquant

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