ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_face.cpp
Revision: 763
Committed: Wed Dec 2 19:55:53 2015 UTC (9 years, 5 months ago) by francois
File size: 12167 byte(s)
Log Message:
Le fichier MAGiC est maintenant versionné. LA version actuelle est 2.0. L'ancienne version est 1.0.
Tout est transparent pour l'utilisateur. Les vieilles versions sont lisibles mais les nouveaux enregistrements sont dans la version la plus récente.
Changement des conditions aux limites : ajout d'un parametre pour dire si la condition numerique est une valeur ou une formule ou un lien vers une autre entité magic.
Les parametres pour saisir sont maintenant -ccf -ccfi -ccff -ccft -ccfit -ccfft

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     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)
35     {
36     }
37    
38     MG_FACE::MG_FACE(std::string idori,MG_SURFACE* srf,int sens):MG_ELEMENT_TOPOLOGIQUE(idori),surface(srf),orientation(sens),vect(NULL)
39     {
40     }
41    
42     MG_FACE::MG_FACE(MG_FACE& mdd):MG_ELEMENT_TOPOLOGIQUE(mdd),lst_boucle(mdd.lst_boucle),surface(mdd.surface),orientation(mdd.orientation),vect(NULL)
43     {
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    
397    
398    
399    
400    
401    
402 francois 283 VCT& MG_FACE::get_vectorisation(void)
403     {
404     if (vect==NULL) vect=new VCT_FACE(this);
405     return *vect;
406     }
407    
408 francois 763 void MG_FACE::enregistrer(std::ostream& o,double version)
409 francois 283 {
410     o << "%" << get_id() << "=FACE("<< get_idoriginal() << ",$" << surface->get_id() << ",(";
411     for (unsigned int i=0;i<lst_boucle.size();i++)
412     {
413     o << "$" << lst_boucle[i]->get_id();
414     if (i!=lst_boucle.size()-1) o << ",";
415     else o << ")";
416     }
417     int nb=get_nb_ccf();
418 francois 763 o << "," << orientation << ",";
419     if (version<2)
420 francois 283 {
421 francois 763 o << nb;
422     if (nb!=0)
423     {
424 francois 283 o << ",(";
425     for (int i=0;i<nb;i++)
426     {
427     char nom[3];
428     get_type_ccf(i,nom);
429     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
430     if (i!=nb-1) o << "," ;
431     }
432     o << ")";
433 francois 763
434     }
435 francois 283 }
436 francois 763 else
437     enregistrer_ccf(o,version);
438 francois 283 o << ");" << std::endl;
439     }
440    
441