ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mtu/src/mg_face.cpp
Revision: 1095
Committed: Mon Jul 25 19:04:45 2022 UTC (2 years, 9 months ago) by francois
Original Path: magic/lib/geometrie/src/mg_face.cpp
File size: 14995 byte(s)
Log Message:
Correction des tores dans l'homogeinisation. Problème de la boite englobante dans le parametrique.

File Contents

# User Rev Content
1 francois 283 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4     // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6     //------------------------------------------------------------
7     // Le projet MAGIC est un projet de recherche du d�partement
8     // de g�nie m�canique de l'Universit� du Qu�bec �
9     // Trois Rivi�res
10     // Les librairies ne peuvent �tre utilis�es sans l'accord
11     // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // mg_face.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20     // Version du 02/03/2006 � 11H22
21     //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #include <math.h>
27     #include "mg_face.h"
28     #include "vct_face.h"
29 francois 375 #include "mg_definition.h"
30 francois 283 //#include "message.h"
31     //#include "affiche.h"
32     #include "ot_mathematique.h"
33    
34 couturad 814 MG_FACE::MG_FACE(std::string idori,unsigned long num,MG_SURFACE* srf,int sens):MG_ELEMENT_TOPOLOGIQUE(num,idori),surface(srf),orientation(sens),vect(NULL),nb_pole(-1)
35 francois 283 {
36     }
37    
38 couturad 814 MG_FACE::MG_FACE(std::string idori,MG_SURFACE* srf,int sens):MG_ELEMENT_TOPOLOGIQUE(idori),surface(srf),orientation(sens),vect(NULL),nb_pole(-1)
39 francois 283 {
40     }
41    
42 couturad 814 MG_FACE::MG_FACE(MG_FACE& mdd):MG_ELEMENT_TOPOLOGIQUE(mdd),lst_boucle(mdd.lst_boucle),surface(mdd.surface),orientation(mdd.orientation),vect(NULL),nb_pole(mdd.nb_pole)
43 francois 283 {
44     }
45    
46     MG_FACE::~MG_FACE()
47     {
48     //if (lst_coface.size()!=0) afficheur << WARCOFACE << this->get_id()<< enderr;
49     if (vect!=NULL) delete vect;
50     }
51    
52     void MG_FACE::ajouter_mg_boucle(class MG_BOUCLE* mgbou)
53     {
54     lst_boucle.insert(lst_boucle.end(),mgbou);
55     }
56    
57     void MG_FACE::supprimer_mg_boucle(class MG_BOUCLE* mgbou)
58     {
59     std::vector<MG_BOUCLE*>::iterator i;
60     for (i=lst_boucle.begin();i!=lst_boucle.end();i++)
61     {
62     if ((*i)==mgbou)
63     {
64     lst_boucle.erase(i);
65     return;
66     }
67     }
68     }
69    
70    
71     int MG_FACE::get_nb_mg_boucle(void)
72     {
73     return lst_boucle.size();
74     }
75    
76     MG_BOUCLE* MG_FACE::get_mg_boucle(int num)
77     {
78     return lst_boucle[num];
79     }
80    
81    
82     void MG_FACE::ajouter_mg_coface(class MG_COFACE* coface)
83     {
84     lst_coface.insert(lst_coface.end(),coface);
85     }
86    
87     int MG_FACE::get_nb_mg_coface(void)
88     {
89     return lst_coface.size();
90     }
91    
92    
93     void MG_FACE::supprimer_mg_coface(class MG_COFACE* coface)
94     {
95     std::vector<MG_COFACE*>::iterator i;
96     for (i=lst_coface.begin();i!=lst_coface.end();i++)
97     {
98     if ((*i)==coface)
99     {
100     lst_coface.erase(i);
101     return;
102     }
103     }
104     }
105    
106    
107    
108     MG_COFACE* MG_FACE::get_mg_coface(int num)
109     {
110     return lst_coface[num];
111     }
112    
113     MG_SURFACE* MG_FACE::get_surface(void)
114     {
115     return surface;
116     }
117    
118     void MG_FACE::get_topologie_sousjacente(TPL_MAP_ENTITE<MG_ELEMENT_TOPOLOGIQUE*> *lst)
119     {
120     int nb=lst_boucle.size();
121     for (int i=0;i<nb;i++)
122     {
123     MG_BOUCLE* bou=lst_boucle[i];
124     int nb2=bou->get_nb_mg_coarete();
125     for (int j=0;j<nb2;j++)
126     {
127     MG_ARETE* are=bou->get_mg_coarete(j)->get_arete();
128     lst->ajouter(are);
129     are->get_topologie_sousjacente(lst);
130     }
131     }
132     }
133    
134     int MG_FACE::get_dimension(void)
135     {
136     return 2;
137     }
138    
139 couturad 906 int MG_FACE::get_type(void)
140     {
141     return TYPE_ELEMENT_TOPOLOGIQUE::FACE;
142     }
143    
144 francois 283 int MG_FACE::get_orientation(void)
145     {
146     return orientation;
147     }
148    
149 francois 576 bool MG_FACE::est_une_face_element(void)
150     {
151     return false;
152     }
153    
154 francois 283 int MG_FACE::valide_parametre_u(double& u)
155     {
156     if (surface->est_periodique_u()) return 1;
157     double param=u;
158     if (orientation!=MEME_SENS) param=surface->get_umin()+surface->get_umax()-param;
159     double param_min,param_max;
160     param_min=surface->get_umin();
161     param_max=surface->get_umax();
162     if (param<param_min)
163     {
164     u=param_min;
165     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
166     return 0;
167     }
168     if (param>param_max)
169     {
170     u=param_max;
171     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
172     return 0;
173     }
174     return 1;
175     }
176     int MG_FACE::valide_parametre_v(double& v)
177     {
178     if (surface->est_periodique_v()) return 1;
179     double param=v;
180     double param_min,param_max;
181     param_min=surface->get_vmin();
182     param_max=surface->get_vmax();
183     if (param<param_min)
184     {
185     v=param_min;
186     return 0;
187     }
188     if (param>param_max)
189     {
190     v=param_max;
191     return 0;
192     }
193     return 1;
194     }
195    
196     void MG_FACE::evaluer(double *uv,double *xyz)
197     {
198     double param[2]={uv[0],uv[1]};
199     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
200     surface->evaluer(param,xyz);
201     }
202    
203     void MG_FACE::deriver(double *uv,double *xyzdu, double *xyzdv)
204     {
205     double param[2]={uv[0],uv[1]};
206     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
207     surface->deriver(param,xyzdu,xyzdv);
208     if (orientation!=MEME_SENS)
209     {
210     xyzdu[0]=-xyzdu[0];
211     xyzdu[1]=-xyzdu[1];
212     xyzdu[2]=-xyzdu[2];
213     }
214     }
215    
216     void MG_FACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu, double *xyzdv)
217     {
218     double param[2]={uv[0],uv[1]};
219     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
220     surface->deriver_seconde(param,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
221     if (orientation!=MEME_SENS)
222     {
223     xyzdu[0]=-xyzdu[0];
224     xyzdu[1]=-xyzdu[1];
225     xyzdu[2]=-xyzdu[2];
226     xyzduv[0]=-xyzduv[0];
227     xyzduv[1]=-xyzduv[1];
228     xyzduv[2]=-xyzduv[2];
229     }
230     }
231    
232     void MG_FACE::inverser(double *uv,double *xyz,double precision)
233     {
234     surface->inverser(uv,xyz,precision);
235     if (orientation!=MEME_SENS) uv[0]=surface->get_umin()+surface->get_umax()-uv[0];
236     }
237    
238     void MG_FACE::calcul_normale(double *uv,double *normale)
239     {
240     double xyzdu[3];
241     double xyzdv[3];
242    
243     deriver(uv,xyzdu,xyzdv);
244     OT_VECTEUR_3D xu(xyzdu);
245     OT_VECTEUR_3D xv(xyzdv);
246     OT_VECTEUR_3D n=xu&xv;
247     normale[0]=n.get_x();
248     normale[1]=n.get_y();
249     normale[2]=n.get_z();
250     }
251    
252     void MG_FACE::calcul_normale_unitaire(double *uv,double *normale)
253     {
254     double xyzdu[3];
255     double xyzdv[3];
256    
257     deriver(uv,xyzdu,xyzdv);
258     OT_VECTEUR_3D xu(xyzdu);
259     OT_VECTEUR_3D xv(xyzdv);
260     OT_VECTEUR_3D n=xu&xv;
261     n.norme();
262     normale[0]=n.get_x();
263     normale[1]=n.get_y();
264     normale[2]=n.get_z();
265     }
266    
267    
268     void MG_FACE::get_EFG(double *uv,double& E,double& F,double& G)
269     {
270     double xyzdu[3];
271     double xyzdv[3];
272     deriver(uv,xyzdu,xyzdv);
273     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
274     F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
275     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
276     }
277    
278     void MG_FACE::get_M(double *uv,double& M1,double& M2,double& M3)
279     {
280     double E,F,G;
281     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3];
282    
283     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
284     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
285     //F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
286     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
287     double Edu=2.*(xyzdu[0]*xyzduu[0]+xyzdu[1]*xyzduu[1]+xyzdu[2]*xyzduu[2]);
288     double Gdv=2.*(xyzdv[0]*xyzdvv[0]+xyzdv[1]*xyzdvv[1]+xyzdv[2]*xyzdvv[2]);
289     double Edv=2.*(xyzdu[0]*xyzduv[0]+xyzdu[1]*xyzduv[1]+xyzdu[2]*xyzduv[2]);
290     double Gdu=2.*(xyzdv[0]*xyzduv[0]+xyzdv[1]*xyzduv[1]+xyzdv[2]*xyzduv[2]);
291     double m1[3],m2[3],m3[3];
292     m1[0]=xyzduu[0]/E-0.5*Edu*xyzdu[0]/E/E;
293     m1[1]=xyzduu[1]/E-0.5*Edu*xyzdu[1]/E/E;
294     m1[2]=xyzduu[2]/E-0.5*Edu*xyzdu[2]/E/E;
295     m2[0]=xyzduv[0]/sqrt(E*G)-0.5*xyzdu[0]*Edv/E/sqrt(E*G)-0.5*xyzdv[0]*Gdu/G/sqrt(E*G);
296     m2[1]=xyzduv[1]/sqrt(E*G)-0.5*xyzdu[1]*Edv/E/sqrt(E*G)-0.5*xyzdv[1]*Gdu/G/sqrt(E*G);
297     m2[2]=xyzduv[2]/sqrt(E*G)-0.5*xyzdu[2]*Edv/E/sqrt(E*G)-0.5*xyzdv[2]*Gdu/G/sqrt(E*G);
298     m3[0]=xyzdvv[0]/G-0.5*Gdv*xyzdv[0]/G/G;
299     m3[1]=xyzdvv[1]/G-0.5*Gdv*xyzdv[1]/G/G;
300     m3[2]=xyzdvv[2]/G-0.5*Gdv*xyzdv[2]/G/G;
301     M1=sqrt(m1[0]*m1[0]+m1[1]*m1[1]+m1[2]*m1[2]);
302     M2=sqrt(m2[0]*m2[0]+m2[1]*m2[1]+m2[2]*m2[2]);
303     M3=sqrt(m3[0]*m3[0]+m3[1]*m3[1]+m3[2]*m3[2]);
304     }
305    
306     void MG_FACE::get_LMN(double *uv,double& L,double& M,double &N)
307     {
308    
309     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3],normal[3];
310     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
311     calcul_normale_unitaire(uv,normal);
312     L=xyzduu[0]*normal[0]+xyzduu[1]*normal[1]+xyzduu[2]*normal[2];
313     M=xyzduv[0]*normal[0]+xyzduv[1]*normal[1]+xyzduv[2]*normal[2];
314     N=xyzdvv[0]*normal[0]+xyzdvv[1]*normal[1]+xyzdvv[2]*normal[2];
315     }
316    
317    
318     void MG_FACE::get_courbure(double *uv,double& cmax,double& cmin)
319     {
320     double E,F,G,L,M,N;
321     get_EFG(uv,E,F,G);
322     get_LMN(uv,L,M,N);
323     double a=E*G-F*F;
324     double b=-E*N-G*L+2*F*M;
325     double c=L*N-M*M;
326     double delta=b*b-4*a*c;
327     if (delta<0.00000001) delta=0.;
328     double x1=(-b+sqrt(delta))/2./a;
329     double x2=(-b-sqrt(delta))/2./a;
330     if (fabs(x1)>fabs(x2)) {
331     cmax=x1;
332     cmin=x2;
333     } else {
334     cmax=x2;
335     cmin=x1;
336     }
337     }
338    
339 francois 632
340    
341 francois 1095 BOITE_3D MG_FACE::get_boite_3D(void)
342 francois 632 {
343     double xmin=1e308,ymin=1e308,zmin=1e308;
344     double xmax=-1e308,ymax=-1e308,zmax=-1e308;
345     double umin=1e308,vmin=1e308;
346     double umax=-1e308,vmax=-1e308;
347     int nb_boucle=get_nb_mg_boucle();
348 francois 824 if (surface->est_periodique_u())
349     {
350     umin=0.;
351     umax=surface->get_periode_u();
352     }
353     if (surface->est_periodique_v())
354     {
355     vmin=0.;
356     vmax=surface->get_periode_v();
357     }
358 francois 632 for (int i=0;i<nb_boucle;i++)
359     {
360     MG_BOUCLE* bou=get_mg_boucle(i);
361     int nb_arete=bou->get_nb_mg_coarete();
362     for (int j=0;j<nb_arete;j++)
363     {
364     MG_ARETE* arete=bou->get_mg_coarete(j)->get_arete();
365     double tmin=arete->get_tmin();
366     double tmax=arete->get_tmax();
367     double tdemi=0.5*(tmax+tmin);
368     double xyz1[3],xyz2[3];
369     for (int k=0;k<pas_echantillon+1;k++)
370     {
371     double t=tmin+1.0*k/pas_echantillon*(tmax-tmin);
372     double xyz[3];
373     arete->evaluer(t,xyz);
374     if (xyz[0]<xmin) xmin=xyz[0];
375     if (xyz[0]>xmax) xmax=xyz[0];
376     if (xyz[1]<ymin) ymin=xyz[1];
377     if (xyz[1]>ymax) ymax=xyz[1];
378     if (xyz[2]<zmin) zmin=xyz[2];
379     if (xyz[2]>zmax) zmax=xyz[2];
380     double uv[2];
381 francois 1095 inverser(uv,xyz);
382 francois 632 if (uv[0]>umax) umax=uv[0];
383     if (uv[0]<umin) umin=uv[0];
384     if (uv[1]>vmax) vmax=uv[1];
385     if (uv[1]<vmin) vmin=uv[1];
386     }
387     }
388 francois 1095 std::vector<double> lstpoint;
389     get_echantillonnage(pas_echantillon*pas_echantillon,lstpoint);
390     if (lstpoint.size()<1)
391     {
392     for (int k=0;k<pas_echantillon+1;k++)
393     for (int l=0;l<pas_echantillon+1;l++)
394 francois 632 {
395     double uv[2];
396     uv[0]=umin+1.0*k/pas_echantillon*(umax-umin);
397     uv[1]=vmin+1.0*l/pas_echantillon*(vmax-vmin);
398     double xyz[3];
399     evaluer(uv,xyz);
400     if (xyz[0]<xmin) xmin=xyz[0];
401     if (xyz[1]<ymin) ymin=xyz[1];
402     if (xyz[2]<zmin) zmin=xyz[2];
403     if (xyz[0]>xmax) xmax=xyz[0];
404     if (xyz[1]>ymax) ymax=xyz[1];
405     if (xyz[2]>zmax) zmax=xyz[2];
406     }
407 francois 1095 }
408     else
409     for (int k=0;k<lstpoint.size()/5;k++)
410     {
411     double xyz[3]={lstpoint[5*k],lstpoint[5*k+1],lstpoint[5*k+2]};
412     if (xyz[0]<xmin) xmin=xyz[0];
413     if (xyz[1]<ymin) ymin=xyz[1];
414     if (xyz[2]<zmin) zmin=xyz[2];
415     if (xyz[0]>xmax) xmax=xyz[0];
416     if (xyz[1]>ymax) ymax=xyz[1];
417     if (xyz[2]>zmax) zmax=xyz[2];
418     }
419 francois 632 }
420     BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
421     return boite;
422    
423     }
424    
425    
426 couturad 814 int MG_FACE::get_nb_pole(void)
427     {
428     return nb_pole;
429     }
430 francois 632
431    
432 francois 820 void MG_FACE::get_liste_pole_uv(std::vector<double> *liste_pole_uv,double eps)
433 couturad 814 {
434 francois 820 surface->get_liste_pole(liste_pole_uv,eps);
435     nb_pole = liste_pole_uv->size()/2;
436 couturad 814 }
437 francois 632
438 francois 1095 void MG_FACE::get_xyz_min_max(double* xyzmin, double* xyzmax)
439 couturad 919 {
440 francois 984 /*xyzmin[0] = std::numeric_limits<double>::max();
441 couturad 951 xyzmin[1] = std::numeric_limits<double>::max();
442     xyzmin[2] = std::numeric_limits<double>::max();
443     xyzmax[0] = std::numeric_limits<double>::min();
444     xyzmax[1] = std::numeric_limits<double>::min();
445     xyzmax[2] = std::numeric_limits<double>::min();
446 couturad 919 double umin = get_surface()->get_umin();
447     double umax = get_surface()->get_umax();
448     if(get_surface()->est_periodique_u())
449     {
450     umin=0.0;
451     umax=get_surface()->get_periode_u();
452     }
453     double pas_u = (umax-umin)/(double)nb_pas;
454     double vmin = get_surface()->get_vmin();
455     double vmax = get_surface()->get_vmax();
456     if(get_surface()->est_periodique_v())
457     {
458     vmin=0.0;
459     vmax=get_surface()->get_periode_v();
460     }
461 francois 984 double pas_v = (vmax-vmin)/(double)nb_pas;
462 couturad 919 double uv[2];
463     for(int i=0;i<nb_pas;i++)
464     {
465     uv[0] = umin+pas_u*i;
466     for(int j=0;j<nb_pas;j++)
467     {
468     uv[1] = vmin+j*pas_v;
469     double xyz[3];
470     evaluer(uv,xyz);
471     if(xyz[0]>xyzmax[0]) xyzmax[0]=xyz[0];
472     else if(xyz[0]<xyzmin[0]) xyzmin[0]=xyz[0];
473     if(xyz[1]>xyzmax[1]) xyzmax[1]=xyz[1];
474     else if(xyz[1]<xyzmin[1]) xyzmin[1]=xyz[1];
475     if(xyz[2]>xyzmax[2]) xyzmax[2]=xyz[2];
476     else if(xyz[2]<xyzmin[2]) xyzmin[2]=xyz[2];
477     }
478 francois 984 }*/
479 francois 1095 BOITE_3D boite=get_boite_3D();
480 francois 984 xyzmin[0] = boite.get_xmin();
481     xyzmin[1] = boite.get_ymin();
482     xyzmin[2] = boite.get_zmin();
483     xyzmax[0] = boite.get_xmax();
484     xyzmax[1] = boite.get_ymax();
485     xyzmax[2] = boite.get_zmax();
486    
487 couturad 919 }
488    
489 francois 1095 void MG_FACE::get_echantillonnage(int numechantillon, std::vector<double> &tab)
490     {
491     surface->get_echantillonnage(numechantillon,tab,epsilon_echantillon,angle_dev_echantillon);
492    
493     }
494 couturad 919
495 francois 1095
496 couturad 814 void MG_FACE::change_nb_pole(int val)
497     {
498     nb_pole=val;
499     }
500 francois 632
501 francois 283 VCT& MG_FACE::get_vectorisation(void)
502     {
503     if (vect==NULL) vect=new VCT_FACE(this);
504     return *vect;
505     }
506    
507 francois 763 void MG_FACE::enregistrer(std::ostream& o,double version)
508 francois 283 {
509     o << "%" << get_id() << "=FACE("<< get_idoriginal() << ",$" << surface->get_id() << ",(";
510     for (unsigned int i=0;i<lst_boucle.size();i++)
511     {
512     o << "$" << lst_boucle[i]->get_id();
513     if (i!=lst_boucle.size()-1) o << ",";
514     else o << ")";
515     }
516     int nb=get_nb_ccf();
517 couturad 814 o << "," << orientation << "," << nb_pole << ",";
518 francois 763 if (version<2)
519 francois 283 {
520 francois 763 o << nb;
521     if (nb!=0)
522     {
523 francois 283 o << ",(";
524     for (int i=0;i<nb;i++)
525     {
526     char nom[3];
527     get_type_ccf(i,nom);
528     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
529     if (i!=nb-1) o << "," ;
530     }
531     o << ")";
532 francois 763
533     }
534 francois 283 }
535 francois 763 else
536     enregistrer_ccf(o,version);
537 francois 283 o << ");" << std::endl;
538     }
539    
540