ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mtu/src/occ_surface.cpp
Revision: 1149
Committed: Fri May 24 20:23:11 2024 UTC (11 months, 4 weeks ago) by francois
File size: 37405 byte(s)
Log Message:
mise de constante en namespace

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