ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_face.cpp
Revision: 814
Committed: Fri Aug 12 14:58:19 2016 UTC (8 years, 9 months ago) by couturad
File size: 12779 byte(s)
Log Message:
-> Mise à jour de la version du fichier MAGiC (version 2.2)
-> Ajout de la fonctionnalité get_liste_pole permettant d'obtenir les pôles d'une face
-> Ajout d'une méthode de génération d'un VES aléatoire selon la méthode RSA

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     int MG_FACE::get_orientation(void)
140     {
141     return orientation;
142     }
143    
144 francois 576 bool MG_FACE::est_une_face_element(void)
145     {
146     return false;
147     }
148    
149 francois 283 int MG_FACE::valide_parametre_u(double& u)
150     {
151     if (surface->est_periodique_u()) return 1;
152     double param=u;
153     if (orientation!=MEME_SENS) param=surface->get_umin()+surface->get_umax()-param;
154     double param_min,param_max;
155     param_min=surface->get_umin();
156     param_max=surface->get_umax();
157     if (param<param_min)
158     {
159     u=param_min;
160     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
161     return 0;
162     }
163     if (param>param_max)
164     {
165     u=param_max;
166     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
167     return 0;
168     }
169     return 1;
170     }
171     int MG_FACE::valide_parametre_v(double& v)
172     {
173     if (surface->est_periodique_v()) return 1;
174     double param=v;
175     double param_min,param_max;
176     param_min=surface->get_vmin();
177     param_max=surface->get_vmax();
178     if (param<param_min)
179     {
180     v=param_min;
181     return 0;
182     }
183     if (param>param_max)
184     {
185     v=param_max;
186     return 0;
187     }
188     return 1;
189     }
190    
191     void MG_FACE::evaluer(double *uv,double *xyz)
192     {
193     double param[2]={uv[0],uv[1]};
194     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
195     surface->evaluer(param,xyz);
196     }
197    
198     void MG_FACE::deriver(double *uv,double *xyzdu, double *xyzdv)
199     {
200     double param[2]={uv[0],uv[1]};
201     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
202     surface->deriver(param,xyzdu,xyzdv);
203     if (orientation!=MEME_SENS)
204     {
205     xyzdu[0]=-xyzdu[0];
206     xyzdu[1]=-xyzdu[1];
207     xyzdu[2]=-xyzdu[2];
208     }
209     }
210    
211     void MG_FACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu, double *xyzdv)
212     {
213     double param[2]={uv[0],uv[1]};
214     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
215     surface->deriver_seconde(param,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
216     if (orientation!=MEME_SENS)
217     {
218     xyzdu[0]=-xyzdu[0];
219     xyzdu[1]=-xyzdu[1];
220     xyzdu[2]=-xyzdu[2];
221     xyzduv[0]=-xyzduv[0];
222     xyzduv[1]=-xyzduv[1];
223     xyzduv[2]=-xyzduv[2];
224     }
225     }
226    
227     void MG_FACE::inverser(double *uv,double *xyz,double precision)
228     {
229     surface->inverser(uv,xyz,precision);
230     if (orientation!=MEME_SENS) uv[0]=surface->get_umin()+surface->get_umax()-uv[0];
231     }
232    
233     void MG_FACE::calcul_normale(double *uv,double *normale)
234     {
235     double xyzdu[3];
236     double xyzdv[3];
237    
238     deriver(uv,xyzdu,xyzdv);
239     OT_VECTEUR_3D xu(xyzdu);
240     OT_VECTEUR_3D xv(xyzdv);
241     OT_VECTEUR_3D n=xu&xv;
242     normale[0]=n.get_x();
243     normale[1]=n.get_y();
244     normale[2]=n.get_z();
245     }
246    
247     void MG_FACE::calcul_normale_unitaire(double *uv,double *normale)
248     {
249     double xyzdu[3];
250     double xyzdv[3];
251    
252     deriver(uv,xyzdu,xyzdv);
253     OT_VECTEUR_3D xu(xyzdu);
254     OT_VECTEUR_3D xv(xyzdv);
255     OT_VECTEUR_3D n=xu&xv;
256     n.norme();
257     normale[0]=n.get_x();
258     normale[1]=n.get_y();
259     normale[2]=n.get_z();
260     }
261    
262    
263     void MG_FACE::get_EFG(double *uv,double& E,double& F,double& G)
264     {
265     double xyzdu[3];
266     double xyzdv[3];
267     deriver(uv,xyzdu,xyzdv);
268     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
269     F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
270     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
271     }
272    
273     void MG_FACE::get_M(double *uv,double& M1,double& M2,double& M3)
274     {
275     double E,F,G;
276     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3];
277    
278     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
279     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
280     //F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
281     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
282     double Edu=2.*(xyzdu[0]*xyzduu[0]+xyzdu[1]*xyzduu[1]+xyzdu[2]*xyzduu[2]);
283     double Gdv=2.*(xyzdv[0]*xyzdvv[0]+xyzdv[1]*xyzdvv[1]+xyzdv[2]*xyzdvv[2]);
284     double Edv=2.*(xyzdu[0]*xyzduv[0]+xyzdu[1]*xyzduv[1]+xyzdu[2]*xyzduv[2]);
285     double Gdu=2.*(xyzdv[0]*xyzduv[0]+xyzdv[1]*xyzduv[1]+xyzdv[2]*xyzduv[2]);
286     double m1[3],m2[3],m3[3];
287     m1[0]=xyzduu[0]/E-0.5*Edu*xyzdu[0]/E/E;
288     m1[1]=xyzduu[1]/E-0.5*Edu*xyzdu[1]/E/E;
289     m1[2]=xyzduu[2]/E-0.5*Edu*xyzdu[2]/E/E;
290     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);
291     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);
292     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);
293     m3[0]=xyzdvv[0]/G-0.5*Gdv*xyzdv[0]/G/G;
294     m3[1]=xyzdvv[1]/G-0.5*Gdv*xyzdv[1]/G/G;
295     m3[2]=xyzdvv[2]/G-0.5*Gdv*xyzdv[2]/G/G;
296     M1=sqrt(m1[0]*m1[0]+m1[1]*m1[1]+m1[2]*m1[2]);
297     M2=sqrt(m2[0]*m2[0]+m2[1]*m2[1]+m2[2]*m2[2]);
298     M3=sqrt(m3[0]*m3[0]+m3[1]*m3[1]+m3[2]*m3[2]);
299     }
300    
301     void MG_FACE::get_LMN(double *uv,double& L,double& M,double &N)
302     {
303    
304     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3],normal[3];
305     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
306     calcul_normale_unitaire(uv,normal);
307     L=xyzduu[0]*normal[0]+xyzduu[1]*normal[1]+xyzduu[2]*normal[2];
308     M=xyzduv[0]*normal[0]+xyzduv[1]*normal[1]+xyzduv[2]*normal[2];
309     N=xyzdvv[0]*normal[0]+xyzdvv[1]*normal[1]+xyzdvv[2]*normal[2];
310     }
311    
312    
313     void MG_FACE::get_courbure(double *uv,double& cmax,double& cmin)
314     {
315     double E,F,G,L,M,N;
316     get_EFG(uv,E,F,G);
317     get_LMN(uv,L,M,N);
318     double a=E*G-F*F;
319     double b=-E*N-G*L+2*F*M;
320     double c=L*N-M*M;
321     double delta=b*b-4*a*c;
322     if (delta<0.00000001) delta=0.;
323     double x1=(-b+sqrt(delta))/2./a;
324     double x2=(-b-sqrt(delta))/2./a;
325     if (fabs(x1)>fabs(x2)) {
326     cmax=x1;
327     cmin=x2;
328     } else {
329     cmax=x2;
330     cmin=x1;
331     }
332     }
333    
334 francois 632
335    
336     BOITE_3D MG_FACE::get_boite_3D(int pas_echantillon)
337     {
338     double xmin=1e308,ymin=1e308,zmin=1e308;
339     double xmax=-1e308,ymax=-1e308,zmax=-1e308;
340     double umin=1e308,vmin=1e308;
341     double umax=-1e308,vmax=-1e308;
342     int nb_boucle=get_nb_mg_boucle();
343     for (int i=0;i<nb_boucle;i++)
344     {
345     MG_BOUCLE* bou=get_mg_boucle(i);
346     int nb_arete=bou->get_nb_mg_coarete();
347     for (int j=0;j<nb_arete;j++)
348     {
349     MG_ARETE* arete=bou->get_mg_coarete(j)->get_arete();
350     double tmin=arete->get_tmin();
351     double tmax=arete->get_tmax();
352     double tdemi=0.5*(tmax+tmin);
353     double xyz1[3],xyz2[3];
354     for (int k=0;k<pas_echantillon+1;k++)
355     {
356     double t=tmin+1.0*k/pas_echantillon*(tmax-tmin);
357     double xyz[3];
358     arete->evaluer(t,xyz);
359     if (xyz[0]<xmin) xmin=xyz[0];
360     if (xyz[0]>xmax) xmax=xyz[0];
361     if (xyz[1]<ymin) ymin=xyz[1];
362     if (xyz[1]>ymax) ymax=xyz[1];
363     if (xyz[2]<zmin) zmin=xyz[2];
364     if (xyz[2]>zmax) zmax=xyz[2];
365     double uv[2];
366     inverser(uv,xyz);
367     if (uv[0]>umax) umax=uv[0];
368     if (uv[0]<umin) umin=uv[0];
369     if (uv[1]>vmax) vmax=uv[1];
370     if (uv[1]<vmin) vmin=uv[1];
371     }
372     }
373     for (int k=0;k<pas_echantillon+1;k++)
374     for (int l=0;l<pas_echantillon+1;l++)
375     {
376     double uv[2];
377     uv[0]=umin+1.0*k/pas_echantillon*(umax-umin);
378     uv[1]=vmin+1.0*l/pas_echantillon*(vmax-vmin);
379     double xyz[3];
380     evaluer(uv,xyz);
381     if (xyz[0]<xmin) xmin=xyz[0];
382     if (xyz[1]<ymin) ymin=xyz[1];
383     if (xyz[2]<zmin) zmin=xyz[2];
384     if (xyz[0]>xmax) xmax=xyz[0];
385     if (xyz[1]>ymax) ymax=xyz[1];
386     if (xyz[2]>zmax) zmax=xyz[2];
387     }
388    
389     }
390     BOITE_3D boite(xmin,ymin,zmin,xmax,ymax,zmax);
391     return boite;
392    
393     }
394    
395    
396 couturad 814 int MG_FACE::get_nb_pole(void)
397     {
398     return nb_pole;
399     }
400 francois 632
401    
402 couturad 814 void MG_FACE::get_liste_pole_uv(TPL_LISTE_ENTITE< double* > *liste_pole_uv)
403     {
404     TPL_LISTE_ENTITE<double*> liste_pole_surface;
405     surface->get_liste_pole(&liste_pole_surface);
406     for(int i=0;i<liste_pole_surface.get_nb();i++)
407     {
408     double *uv = liste_pole_surface.get(i);
409     if(valide_parametre_u(uv[0]) && valide_parametre_v(uv[1])) liste_pole_uv->ajouter(uv);
410     else delete uv;
411     }
412     if(nb_pole==-1) nb_pole = liste_pole_uv->get_nb();
413     }
414 francois 632
415 couturad 814 void MG_FACE::change_nb_pole(int val)
416     {
417     nb_pole=val;
418     }
419 francois 632
420 francois 283 VCT& MG_FACE::get_vectorisation(void)
421     {
422     if (vect==NULL) vect=new VCT_FACE(this);
423     return *vect;
424     }
425    
426 francois 763 void MG_FACE::enregistrer(std::ostream& o,double version)
427 francois 283 {
428     o << "%" << get_id() << "=FACE("<< get_idoriginal() << ",$" << surface->get_id() << ",(";
429     for (unsigned int i=0;i<lst_boucle.size();i++)
430     {
431     o << "$" << lst_boucle[i]->get_id();
432     if (i!=lst_boucle.size()-1) o << ",";
433     else o << ")";
434     }
435     int nb=get_nb_ccf();
436 couturad 814 o << "," << orientation << "," << nb_pole << ",";
437 francois 763 if (version<2)
438 francois 283 {
439 francois 763 o << nb;
440     if (nb!=0)
441     {
442 francois 283 o << ",(";
443     for (int i=0;i<nb;i++)
444     {
445     char nom[3];
446     get_type_ccf(i,nom);
447     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
448     if (i!=nb-1) o << "," ;
449     }
450     o << ")";
451 francois 763
452     }
453 francois 283 }
454 francois 763 else
455     enregistrer_ccf(o,version);
456 francois 283 o << ");" << std::endl;
457     }
458    
459