ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/occ_surface.cpp
Revision: 906
Committed: Mon Nov 13 22:30:18 2017 UTC (7 years, 9 months ago) by couturad
File size: 30754 byte(s)
Log Message:
Nouveau opencascade commit 1

File Contents

# Content
1 //---------------------------------------------------------------------------
2 //------------------------------------------------------------
3 //------------------------------------------------------------
4 // MAGiC
5 // Jean Christophe Cuilli�re et Vincent FRANCOIS
6 // D�partement de G�nie M�canique - UQTR
7 //------------------------------------------------------------
8 // Le projet MAGIC est un projet de recherche du d�partement
9 // de g�nie m�canique de l'Universit� du Qu�bec �
10 // Trois Rivi�res
11 // Les librairies ne peuvent �tre utilis�es sans l'accord
12 // des auteurs (contact : francois@uqtr.ca)
13 //------------------------------------------------------------
14 //------------------------------------------------------------
15 //
16 // OCC_Surface.cpp
17 //
18 //------------------------------------------------------------
19 //------------------------------------------------------------
20 // COPYRIGHT 2000
21 // Version du 02/03/2006 � 11H22
22 //------------------------------------------------------------
23 //------------------------------------------------------------
24
25 #pragma hdrstop
26 #include "gestionversion.h"
27 #ifdef BREP_OCC
28
29 #include "occ_surface.h"
30 #include <gp_Pnt.hxx>
31 #include <gp_Vec.hxx>
32 #include "GeomAPI_ProjectPointOnSurf.hxx"
33 #include <ShapeAnalysis_Surface.hxx>
34 #include <BRep_Tool.hxx>
35 #include <BRepAdaptor_Surface.hxx>
36 //***********************************
37 #include <BRep_Tool.hxx>
38 #include <Poly_Triangulation.hxx>
39 #include <Geom_Plane.hxx>
40 #include <gp_Pln.hxx>
41 #include <Geom_CylindricalSurface.hxx>
42 #include <gp_Cylinder.hxx>
43 #include <Geom_ConicalSurface.hxx>
44 #include <gp_Cone.hxx>
45 #include <Geom_SphericalSurface.hxx>
46 #include <IGESSolid_SphericalSurface.hxx>
47 #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 #include "ot_mathematique.h"
58 #include <Geom_RectangularTrimmedSurface.hxx>
59 #include <BRepClass_FaceClassifier.hxx>
60 #include <gp_Pnt2d.hxx>
61 #include <Geom_SurfaceOfRevolution.hxx>
62
63 #pragma package(smart_init)
64
65
66
67 class NOEUDARETE
68 {
69 public:
70 MG_NOEUD* no;
71 MG_ARETE* are;
72 double t;
73 };
74
75
76
77 OCC_SURFACE::OCC_SURFACE(unsigned long num, TopoDS_Face srf, OCC_FONCTION* fonc):MG_SURFACE(num),face(srf), fonction1(fonc)
78 {
79
80 //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 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 // ShapeAnalysis::GetFaceUVBounds(face,u_min,u_max,v_min,v_max);
99 //**************************************************************
100
101 }
102
103 OCC_SURFACE::OCC_SURFACE(TopoDS_Face srf, OCC_FONCTION* fonc):MG_SURFACE(),face(srf), fonction1(fonc)
104 {
105 //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 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 //**************************************************************
123 // ShapeAnalysis::GetFaceUVBounds(face,u_min,u_max,v_min,v_max);
124 //**************************************************************
125
126
127 // 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 }
142
143 OCC_SURFACE::OCC_SURFACE(OCC_SURFACE& mdd):MG_SURFACE(mdd),face(mdd.face), fonction1(mdd.fonction1)
144 {
145 //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 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 //const Handle(Geom_Surface) &surface=BRep_Tool::Surface(face);
166 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 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
179 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 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
198 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 // Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
238 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 if (PPS.NbPoints() < 1)
247 {
248 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 return;
255 }
256 //PPS.Perform(P);
257 double UU, VV;
258 PPS.LowerDistanceParameters(UU,VV);
259 uv[0]=UU;
260 uv[1]=VV;
261 }
262
263 bool OCC_SURFACE::est_sur_surface(double* xyz, double precision)
264 {
265 GeomAPI_ProjectPointOnSurf projecteur;
266 double u0, u1;
267 double v0, v1;
268 ShapeAnalysis::GetFaceUVBounds(face,u0,u1,v0,v1);
269 gp_Pnt point(xyz[0],xyz[1],xyz[2]);
270 projecteur.Init(point,surface,u0,u1,v0,v1);
271 if(projecteur.NbPoints()==0) return false;
272 if(projecteur.LowerDistance()<precision) return true;
273 return false;
274 }
275
276 int OCC_SURFACE::est_periodique_u(void)
277 {
278 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
279 return surface->IsUClosed();
280 }
281
282 int OCC_SURFACE::est_periodique_v(void)
283 {
284 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
285 // return surface->IsVPeriodic();
286 return surface->IsVClosed();
287 }
288 double OCC_SURFACE::get_periode_u(void)
289 {
290 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
291 if (surface->IsUPeriodic()) return surface->UPeriod();
292 if (surface->IsUClosed()) return u_max-u_min;
293 return 0;
294 }
295
296 double OCC_SURFACE::get_periode_v(void)
297 {
298 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
299 if (surface->IsVPeriodic()) return surface->VPeriod();
300 if (surface->IsVClosed()) return v_max-v_min;
301 return 0;
302
303 }
304
305 void OCC_SURFACE::enregistrer(std::ostream& o,double version)
306 {
307 if(fonction1->get_version()=="OCCV2017")
308 {
309 o <<"%"<<get_id()<< "=SURFACE_OCC("<< get_idoriginal() << ");" << std::endl;
310 }
311 else
312 {
313 o <<"%"<<get_id()<< "=SURFACE_OCC("<< fonction1->GetID(face)<< ");" << std::endl;
314 }
315 }
316 int OCC_SURFACE::get_type_geometrique(TPL_LISTE_ENTITE<double> &param)
317 {
318 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
319 Handle(Standard_Type) type=surface->DynamicType();
320 //******plan
321 if (type==STANDARD_TYPE(Geom_Plane))
322 {
323 Handle(Geom_Plane) Pln=Handle(Geom_Plane)::DownCast(surface);
324 gp_Pln plan=Pln->Pln();
325
326 double origine[3];
327 gp_Pnt centre=plan.Location();
328
329 origine[0]=centre.X();
330 origine[1]=centre.Y();
331 origine[2]=centre.Z();
332
333 double normal[3];
334 gp_Ax1 axe=plan.Axis();
335 gp_Dir direction=axe.Direction();
336
337 normal[0]=direction.X();
338 normal[1]=direction.Y();
339 normal[2]=direction.Z();
340
341 param.ajouter(origine[0]);
342 param.ajouter(origine[1]);
343 param.ajouter(origine[2]);
344 param.ajouter(normal[0]);
345 param.ajouter(normal[1]);
346 param.ajouter(normal[2]);
347
348 return MGCo_PLAN;
349 }
350 //******cylindre
351 if (type==STANDARD_TYPE(Geom_CylindricalSurface))
352 {
353 Handle(Geom_CylindricalSurface) cylinder=Handle(Geom_CylindricalSurface)::DownCast(surface);
354 gp_Cylinder cylin=cylinder->Cylinder();
355
356 double origine[3];
357 gp_Pnt centre=cylin.Location();
358 origine[0]=centre.X();
359 origine[1]=centre.Y();
360 origine[2]=centre.Z();
361 double directionX[3];
362 double direction[3];
363 double rayon;
364 rayon=cylin.Radius();
365
366 gp_Ax3 repere=cylin.Position();
367 gp_Dir dirX=repere.XDirection();
368 gp_Dir dirZ=repere.Direction();
369 directionX[0]=dirX.X();
370 directionX[1]=dirX.Y();
371 directionX[2]=dirX.Z();
372 direction[0]=dirZ.X();
373 direction[1]=dirZ.Y();
374 direction[2]=dirZ.Z();
375
376
377
378 param.ajouter(origine[0]);
379 param.ajouter(origine[1]);
380 param.ajouter(origine[2]);
381 param.ajouter(directionX[0]);
382 param.ajouter(directionX[1]);
383 param.ajouter(directionX[2]);
384 param.ajouter(direction[0]);
385 param.ajouter(direction[1]);
386 param.ajouter(direction[2]);
387 param.ajouter(rayon);
388 param.ajouter(rayon);
389
390 return MGCo_CYLINDRE;
391 }
392 //******Cone
393 if (type==STANDARD_TYPE(Geom_ConicalSurface))
394 {
395 Handle(Geom_ConicalSurface) cone=Handle(Geom_ConicalSurface)::DownCast(surface);
396 gp_Cone con=cone->Cone();
397
398 double origine[3];
399 gp_Pnt centre=con.Location();
400 origine[0]=centre.X();
401 origine[1]=centre.Y();
402 origine[2]=centre.Z();
403 double direction[3];
404 double directionX[3];
405 double rayon;
406 rayon=con.RefRadius();
407 double angle;
408 angle=con.SemiAngle();
409
410 gp_Ax3 repere=con.Position();
411 gp_Dir dirX=repere.XDirection();
412 gp_Dir dirZ=repere.Direction();
413 directionX[0]=dirX.X();
414 directionX[1]=dirX.Y();
415 directionX[2]=dirX.Z();
416 direction[0]=dirZ.X();
417 direction[1]=dirZ.Y();
418 direction[2]=dirZ.Z();
419 param.ajouter(origine[0]);
420 param.ajouter(origine[1]);
421 param.ajouter(origine[2]);
422 param.ajouter(directionX[0]);
423 param.ajouter(directionX[1]);
424 param.ajouter(directionX[2]);
425 param.ajouter(direction[0]);
426 param.ajouter(direction[1]);
427 param.ajouter(direction[2]);
428 param.ajouter(rayon);
429 param.ajouter(rayon);
430 param.ajouter(cos(angle));
431 param.ajouter(sin(angle));
432
433 return MGCo_CONE;
434
435 }
436 //*****Sphere
437 if (type==STANDARD_TYPE(Geom_SphericalSurface))
438 {
439 Handle(Geom_SphericalSurface) sphere=Handle(Geom_SphericalSurface)::DownCast(surface);
440 gp_Sphere sph=sphere->Sphere();
441
442 double origine[3];
443 gp_Pnt centre=sph.Location();
444 origine[0]=centre.X();
445 origine[1]=centre.Y();
446 origine[2]=centre.Z();
447 double rayon;
448 rayon=sph.Radius();
449 param.ajouter(origine[0]);
450 param.ajouter(origine[1]);
451 param.ajouter(origine[2]);
452 param.ajouter(rayon);
453
454 return MGCo_SPHERE;
455
456 }
457 //****** Tore
458 if (type==STANDARD_TYPE(Geom_ToroidalSurface))
459 {
460 Handle(Geom_ToroidalSurface) tore=Handle(Geom_ToroidalSurface)::DownCast(surface);
461 gp_Torus tro=tore->Torus();
462 double origine[3];
463 gp_Pnt centre=tro.Location();
464 origine[0]=centre.X();
465 origine[1]=centre.Y();
466 origine[2]=centre.Z();
467 double direction[3];
468 double directionX[3];
469 double Grayon;
470 Grayon=tro.MajorRadius();
471 double Prayon;
472 Prayon=tro.MinorRadius();
473 gp_Ax3 repere=tro.Position();
474 gp_Dir dirX=repere.XDirection();
475 gp_Dir dirZ=repere.Direction();
476 directionX[0]=dirX.X();
477 directionX[1]=dirX.Y();
478 directionX[2]=dirX.Z();
479 direction[0]=dirZ.X();
480 direction[1]=dirZ.Y();
481 direction[2]=dirZ.Z();
482 param.ajouter(origine[0]);
483 param.ajouter(origine[1]);
484 param.ajouter(origine[2]);
485 param.ajouter(directionX[0]);
486 param.ajouter(directionX[1]);
487 param.ajouter(directionX[2]);
488 param.ajouter(direction[0]);
489 param.ajouter(direction[1]);
490 param.ajouter(direction[2]);
491 param.ajouter(Grayon);
492 param.ajouter(Prayon);
493
494 return MGCo_TORE;
495
496 }
497 //*******BSpline
498 if (type==STANDARD_TYPE(Geom_BSplineSurface))
499 {
500 Handle(Geom_BSplineSurface) bspline=Handle(Geom_BSplineSurface)::DownCast(surface);
501
502 //nombre des noeuds suivant Udirection
503 int nb_Uknot=bspline->NbUKnots();
504 //valeur de Unoeud
505 for (int i=1; i<=nb_Uknot; i++)
506 {
507 double Uvaleur=bspline->UKnot(i);
508 param.ajouter(Uvaleur);
509 }
510 //nombre des noeuds suivants Vdirection
511 int nb_Vknot=bspline->NbVKnots();
512 //valeur de Vnoeud
513 for (int j=1; j<=nb_Vknot; j++)
514 {
515 double Vvaleur=bspline->VKnot(j);
516 param.ajouter(Vvaleur);
517 }
518 //point de controle et poids
519 gp_Pnt pctr;
520 double poids;
521 for (int u=1; u<=bspline->NbUPoles(); u++)
522 for (int v=1; v<=bspline->NbVPoles(); v++)
523 {
524 pctr=bspline->Pole(u, v);
525
526 param.ajouter(pctr.X());
527 param.ajouter(pctr.Y());
528 param.ajouter(pctr.Z());
529
530 poids=bspline->Weight(u, v);
531 param.ajouter(poids);
532 }
533
534 double uDegree=bspline->UDegree();
535 param.ajouter(uDegree);
536 double vDegree=bspline->VDegree();
537 param.ajouter(vDegree);
538 return MGCo_BSPLINES;
539 }
540
541 }
542 void OCC_SURFACE::get_param_NURBS(int& indx_premier_ptctr,TPL_LISTE_ENTITE<double> &param)
543 {
544 //Conversion of the complete geometry of a shape into
545 //NURBS geometry
546 BRepBuilderAPI_NurbsConvert NURBS(face);
547 Handle(Geom_Surface) surface=BRepLib_FindSurface(NURBS).Surface();
548 Handle(Geom_BSplineSurface) bspline=GeomConvert::SurfaceToBSplineSurface(surface) ;
549
550 // The first parameter indicate the code access
551 param.ajouter(2);
552 //The follewing two parameters of the list indicate the orders of the net points
553 param.ajouter( bspline->UDegree()+1);
554 param.ajouter(bspline->VDegree()+1);
555
556 //The follewing two parameters indicate the number of rows and colons of the control points
557 //respectively to the two parameters directions
558 param.ajouter(bspline->NbUPoles());
559 param.ajouter(bspline->NbVPoles());
560
561 // this present the knot vector in the u-direction
562 for (unsigned int i=1;i<=bspline->NbUKnots();i++)
563 {
564 param.ajouter(bspline->UKnot(i));
565 }
566 //This present the knot vector in the v-direction
567 for (unsigned int j=1;j<=bspline->NbVKnots();j++)
568 {
569 param.ajouter(bspline->VKnot(j));
570 }
571 for (int v=1;v<=bspline->NbVPoles();v++)
572 {
573 for (int u=1;u<=bspline->NbUPoles();u++)
574 {
575 double w=bspline->Weight(u,v);
576 gp_Pnt point=bspline->Pole(u, v);
577 double x=point.X();
578 double y=point.Y();
579 double z=point.Z();
580 param.ajouter(x);
581 param.ajouter(y);
582 param.ajouter(z);
583 param.ajouter(w);
584 }
585
586 }
587 indx_premier_ptctr=5+bspline->NbUKnots()+bspline->NbVKnots();
588
589
590
591
592
593 }
594
595 void OCC_SURFACE::get_triangulation(MG_MAILLAGE* mai,MG_FACE* mgface,std::multimap<double,MG_NOEUD*,std::less<double> >& tabnoeudfus,double eps,int mode)
596 {
597 TPL_MAP_ENTITE<MG_SOMMET*> listsom;
598 TPL_MAP_ENTITE<MG_ARETE*> listare;
599 //std::map<unsigned long,bool> aretemaille;
600 std::map<unsigned long,std::map<double,NOEUDARETE,less<double> >,less<unsigned long> > areteamaille;
601 int nbboucle=mgface->get_nb_mg_boucle();
602 for (int i=0;i<nbboucle;i++)
603 {
604 MG_BOUCLE* bou=mgface->get_mg_boucle(i);
605 int nbarete=bou->get_nb_mg_coarete();
606 for (int j=0;j<nbarete;j++)
607 {
608 MG_ARETE* are=bou->get_mg_coarete(j)->get_arete();
609 listare.ajouter(are);
610 //bool amailler=true;
611 //if (are->get_lien_maillage()->get_nb()>0) amailler=false;
612 //aretemaille[are->get_id()]=amailler;
613 listsom.ajouter(bou->get_mg_coarete(j)->get_arete()->get_cosommet1()->get_sommet());
614 listsom.ajouter(bou->get_mg_coarete(j)->get_arete()->get_cosommet2()->get_sommet());
615 std::map<double,NOEUDARETE,less<double> > tmp;
616 std::pair<unsigned long,std::map<double,NOEUDARETE,less<double> > > maptmp(are->get_id(),tmp);
617 areteamaille.insert(maptmp);
618 }
619 }
620
621
622 TopLoc_Location L;
623 Handle (Poly_Triangulation) pt=BRep_Tool::Triangulation(face,L);
624 int nbnoeud=pt->NbNodes();
625 int nbmaille=pt->NbTriangles();
626 const TColgp_Array1OfPnt& nodes = pt->Nodes();
627 const Poly_Array1OfTriangle& triangles = pt->Triangles();
628 const TColgp_Array1OfPnt2d& uvNodes = pt->UVNodes();
629 std::vector<MG_NOEUD*> tabnoeud;
630 for ( Standard_Integer i = 0; i < nbnoeud; i++ )
631 {
632 gp_Pnt p1=nodes(i+1);
633 double xx=p1.X();
634 double yy=p1.Y();
635 double zz=p1.Z();
636 double key=fabs(xx)+fabs(yy)+fabs(zz);
637 MG_NOEUD* nvnoeud=NULL;
638 if (mode>1)
639 {
640 std::multimap<double,MG_NOEUD*,std::less<double> >::iterator it,itbas,ithaut;
641 itbas=tabnoeudfus.lower_bound(key*0.99);
642 ithaut=tabnoeudfus.upper_bound(key*1.1010101);
643 for ( it=itbas ; it != ithaut; it++ )
644 {
645 MG_NOEUD* ntmp=(*it).second;
646 double xtmp=ntmp->get_x();
647 double ytmp=ntmp->get_y();
648 double ztmp=ntmp->get_z();
649 OT_VECTEUR_3D vec(xtmp-xx,ytmp-yy,ztmp-zz);
650 if (vec.get_longueur()<1e-6*eps) {
651 nvnoeud=ntmp;
652 break;
653 }
654 }
655 }
656 if (nvnoeud==NULL)
657 {
658 MG_ELEMENT_TOPOLOGIQUE *topo=mgface;
659 TPL_MAP_ENTITE<MG_SOMMET*>::ITERATEUR it1;
660 for (MG_SOMMET* som=listsom.get_premier(it1);som!=NULL;som=listsom.get_suivant(it1))
661 {
662 double xyz[3];
663 som->get_point()->evaluer(xyz);
664 OT_VECTEUR_3D vec(xyz[0]-xx,xyz[1]-yy,xyz[2]-zz);
665 if (vec.get_longueur()<1e-6*eps)
666 {
667 topo=som;
668 break;
669
670 }
671 }
672 double param_t;
673 if (topo==mgface)
674 {
675 TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it2;
676 for (MG_ARETE* are=listare.get_premier(it2);are!=NULL;are=listare.get_suivant(it2))
677 {
678 double t;
679 double xyz[3]={xx,yy,zz};
680 are->inverser(t,xyz);
681 if (are->get_courbe()->est_periodique())
682 if (t< are->get_tmin()) t=t+are->get_courbe()->get_periode();
683 double xyztmp[3];
684 are->evaluer(t,xyztmp );
685 OT_VECTEUR_3D vec(xyz,xyztmp);
686 if (vec.get_longueur()<1e-6*eps)
687 if ((t>are->get_tmin()) && (t<are->get_tmax()))
688 {
689 topo=are;
690 param_t=t;
691 break;
692 }
693 }
694 }
695 nvnoeud=new MG_NOEUD(topo,xx,yy,zz,MAGIC::ORIGINE::TRIANGULATION);
696 mai->ajouter_mg_noeud(nvnoeud);
697 std::pair<double,MG_NOEUD*> tmp(key,nvnoeud);
698 tabnoeudfus.insert(tmp);
699 if (topo->get_dimension()==1)
700 {
701 NOEUDARETE na;
702 na.no=nvnoeud;
703 na.are=(MG_ARETE*)topo;
704 na.t=param_t;
705 std::pair<double,NOEUDARETE> tmp(na.t,na);
706 areteamaille[topo->get_id()].insert(tmp);
707 }
708 }
709
710
711 tabnoeud.insert(tabnoeud.end(),nvnoeud);
712 }
713 for ( Standard_Integer i = 0; i < nbmaille; i++ )
714 {
715 int n1,n2,n3;
716 Poly_Triangle triangle = triangles( i + 1 );
717 bool face_reversed = (face.Orientation() == TopAbs_REVERSED);
718 if ( face_reversed )
719 triangle.Get( n1, n3, n2 );
720 else
721 triangle.Get( n1, n2, n3 );
722 MG_NOEUD* noeud1=tabnoeud[n1-1];
723 MG_NOEUD* noeud2=tabnoeud[n2-1];
724 MG_NOEUD* noeud3=tabnoeud[n3-1];
725 if (noeud1==noeud2) continue;
726 if (noeud1==noeud3) continue;
727 if (noeud2==noeud3) continue;
728 mai->ajouter_mg_triangle(mgface,noeud1,noeud2,noeud3,MAGIC::ORIGINE::TRIANGULATION);
729 /*if (noeud1->get_lien_topologie()->get_dimension()==0)
730 {
731 MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
732 som->get_lien_maillage()->ajouter(noeud1);
733 }
734 if (noeud2->get_lien_topologie()->get_dimension()==0)
735 {
736 MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
737 som->get_lien_maillage()->ajouter(noeud2);
738 }
739 if (noeud3->get_lien_topologie()->get_dimension()==0)
740 {
741 MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
742 som->get_lien_maillage()->ajouter(noeud3);
743 }*/
744 /*if (noeud1->get_lien_topologie()==noeud2->get_lien_topologie())
745 if (noeud1->get_lien_topologie()->get_dimension()==1)
746 {
747 MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
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 if (noeud1->get_lien_topologie()==noeud3->get_lien_topologie())
755 if (noeud1->get_lien_topologie()->get_dimension()==1)
756 {
757 MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
758 if (aretemaille[are->get_id()]==true)
759 {
760 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud3,TRIANGULATION);
761 are->get_lien_maillage()->ajouter(seg);
762 }
763 }#include <../gmsh/tutorial/t8.geo>
764 if (noeud3->get_lien_topologie()==noeud2->get_lien_topologie())
765 if (noeud3->get_lien_topologie()->get_dimension()==1)
766 {
767 MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
768 if (aretemaille[are->get_id()]==true)
769 {
770 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud2,TRIANGULATION);
771 are->get_lien_maillage()->ajouter(seg);
772 }
773 }
774 if (noeud1->get_lien_topologie()->get_dimension()==1)
775 if (noeud2->get_lien_topologie()->get_dimension()==0)
776 {
777 MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
778 MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
779 if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
780 {
781 if (aretemaille[are->get_id()]==true)
782 {
783 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud2,TRIANGULATION);
784 are->get_lien_maillage()->ajouter(seg);
785 }
786 }
787 }
788 if (noeud1->get_lien_topologie()->get_dimension()==1)
789 if (noeud3->get_lien_topologie()->get_dimension()==0)
790 {
791 MG_ARETE* are=(MG_ARETE*)noeud1->get_lien_topologie();
792 MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
793 if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
794 {
795 if (aretemaille[are->get_id()]==true)
796 {
797 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud1,noeud3,TRIANGULATION);
798 are->get_lien_maillage()->ajouter(seg);
799 }
800 }
801 }
802 if (noeud2->get_lien_topologie()->get_dimension()==1)
803 if (noeud1->get_lien_topologie()->get_dimension()==0)
804 {
805 MG_ARETE* are=(MG_ARETE*)noeud2->get_lien_topologie();
806 MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
807 if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
808 {
809 if (aretemaille[are->get_id()]==true)
810 {
811 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud2,noeud1,TRIANGULATION);
812 are->get_lien_maillage()->ajouter(seg);
813 }
814 }
815 }
816 if (noeud2->get_lien_topologie()->get_dimension()==1)
817 if (noeud3->get_lien_topologie()->get_dimension()==0)
818 {
819 MG_ARETE* are=(MG_ARETE*)noeud2->get_lien_topologie();
820 MG_SOMMET* som=(MG_SOMMET*)noeud3->get_lien_topologie();
821 if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
822 {
823 if (aretemaille[are->get_id()]==true)
824 {
825 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud2,noeud3,TRIANGULATION);
826 are->get_lien_maillage()->ajouter(seg);
827 }
828 }
829 }
830 if (noeud3->get_lien_topologie()->get_dimension()==1)
831 if (noeud1->get_lien_topologie()->get_dimension()==0)
832 {
833 MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
834 MG_SOMMET* som=(MG_SOMMET*)noeud1->get_lien_topologie();
835 if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
836 {
837 if (aretemaille[are->get_id()]==true)
838 {
839 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud1,TRIANGULATION);
840 are->get_lien_maillage()->ajouter(seg);
841 }
842 }
843 }
844 if (noeud3->get_lien_topologie()->get_dimension()==1)
845 if (noeud2->get_lien_topologie()->get_dimension()==0)
846 {
847 MG_ARETE* are=(MG_ARETE*)noeud3->get_lien_topologie();
848 MG_SOMMET* som=(MG_SOMMET*)noeud2->get_lien_topologie();
849 if ((are->get_cosommet1()->get_sommet()==som)||(are->get_cosommet2()->get_sommet()==som))
850 {
851 if (aretemaille[are->get_id()]==true)
852 {
853 MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeud3,noeud2,TRIANGULATION);
854 are->get_lien_maillage()->ajouter(seg);
855 }
856 }
857 }*/
858 }
859 if (mode>1)
860 {
861 TPL_MAP_ENTITE<MG_ARETE*>::ITERATEUR it2;
862 for (MG_ARETE* are=listare.get_premier(it2);are!=NULL;are=listare.get_suivant(it2))
863 {
864 if (are->get_lien_maillage()->get_nb()==0)
865 {
866 unsigned long id=are->get_id();
867 MG_NOEUD* nodep=(MG_NOEUD*)are->get_cosommet1()->get_sommet()->get_lien_maillage()->get(0);
868 MG_NOEUD* noarr=(MG_NOEUD*)are->get_cosommet2()->get_sommet()->get_lien_maillage()->get(0);
869 std::map<double,NOEUDARETE,less<double> >::iterator it=areteamaille[id].begin();
870 MG_NOEUD* noeudcourant=nodep;
871 while (it!=areteamaille[id].end())
872 {
873 MG_NOEUD* noeud=(*it).second.no;
874 //MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeudcourant,noeud,TRIANGULATION);
875 MG_SEGMENT* seg=mai->get_mg_segment(noeudcourant->get_id(),noeud->get_id());
876 seg->change_lien_topologie(are);
877 noeudcourant=noeud;
878 it++;
879 }
880 //MG_SEGMENT* seg=mai->ajouter_mg_segment(are,noeudcourant,noarr,TRIANGULATION);
881 MG_SEGMENT* seg=mai->get_mg_segment(noeudcourant->get_id(),noarr->get_id());
882 seg->change_lien_topologie(are);
883 }
884 }
885
886 }
887 }
888
889 void OCC_SURFACE::get_liste_pole(std::vector< double> *liste_pole,double eps)
890 {
891 //Handle(Geom_Surface) surface=BRep_Tool::Surface(face);
892 Handle(Standard_Type) type=surface->DynamicType();
893 //std::cout << surface->DynamicType()->Name() <<std::endl;
894 if(type==STANDARD_TYPE(Geom_RectangularTrimmedSurface))
895 {
896 Handle(Geom_RectangularTrimmedSurface) RTSurface = Handle(Geom_RectangularTrimmedSurface)::DownCast(surface);
897 Handle(Geom_Surface) basissurface = RTSurface->BasisSurface();
898 Handle(Standard_Type) type_basissurface=basissurface->DynamicType();
899 if(type_basissurface==STANDARD_TYPE(Geom_SphericalSurface))
900 {
901 type=STANDARD_TYPE(Geom_SphericalSurface);
902 }
903 }
904 if(type==STANDARD_TYPE(Geom_SphericalSurface))
905 {
906 BRepClass_FaceClassifier faceclassifier;
907 gp_Pnt2d pnt2d_pole_sud(0.0,-M_PI/2.);
908 faceclassifier.Perform(face,pnt2d_pole_sud,eps);
909 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
910 {
911 liste_pole->push_back(0.0);
912 liste_pole->push_back(-M_PI/2.);
913 }
914 gp_Pnt2d pnt2d_pole_nord(0.0,M_PI/2.);
915 faceclassifier.Perform(face,pnt2d_pole_nord,eps);
916 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
917 {
918 liste_pole->push_back(0.0);
919 liste_pole->push_back(M_PI/2.);
920 }
921 }
922 if(type==STANDARD_TYPE(Geom_SurfaceOfRevolution))
923 {
924 BRepClass_FaceClassifier faceclassifier;
925 gp_Pnt2d pnt2d_pole_sud(0.0,v_min);
926 faceclassifier.Perform(face,pnt2d_pole_sud,eps);
927 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
928 {
929 liste_pole->push_back(0.0);
930 liste_pole->push_back(v_min);
931 }
932 gp_Pnt2d pnt2d_pole_nord(0.0,v_max);
933 faceclassifier.Perform(face,pnt2d_pole_nord,eps);
934 if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
935 {
936 liste_pole->push_back(0.0);
937 liste_pole->push_back(v_max);
938 }
939 }
940 // if(type==STANDARD_TYPE(Geom_ConicalSurface))
941 // {
942 // BRepClass_FaceClassifier faceclassifier;
943 // gp_Pnt2d pnt2d_pole(0.0,v_max);
944 // faceclassifier.Perform(face,pnt2d_pole,eps);
945 // if(faceclassifier.State()==TopAbs_IN || faceclassifier.State()==TopAbs_ON)
946 // {
947 // liste_pole->push_back(0.0);
948 // liste_pole->push_back(v_max);
949 // }
950 // }
951 }
952
953
954
955
956
957 #endif