ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_face.cpp
Revision: 253
Committed: Tue Jul 13 19:40:46 2010 UTC (14 years, 10 months ago) by francois
File size: 9505 byte(s)
Log Message:
changement de hiearchie et utilisation de ccmake + mise a jour

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
2     //------------------------------------------------------------
3     // MAGiC
4 francois 195 // Jean Christophe Cuilli�re et Vincent FRANCOIS
5     // D�partement de G�nie M�canique - UQTR
6 5 //------------------------------------------------------------
7 francois 195 // 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 5 // des auteurs (contact : francois@uqtr.ca)
12     //------------------------------------------------------------
13     //------------------------------------------------------------
14     //
15     // mg_face.cpp
16     //
17     //------------------------------------------------------------
18     //------------------------------------------------------------
19     // COPYRIGHT 2000
20 francois 195 // Version du 02/03/2006 � 11H22
21 5 //------------------------------------------------------------
22     //------------------------------------------------------------
23    
24    
25     #include "gestionversion.h"
26     #include <math.h>
27     #include "mg_face.h"
28 souaissa 71 #include "vct_face.h"
29 5 #include "geom.h"
30     //#include "message.h"
31     //#include "affiche.h"
32     #include "ot_mathematique.h"
33    
34 souaissa 71 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 5 {
36     }
37    
38 souaissa 71 MG_FACE::MG_FACE(std::string idori,MG_SURFACE* srf,int sens):MG_ELEMENT_TOPOLOGIQUE(idori),surface(srf),orientation(sens),vect(NULL)
39 5 {
40     }
41    
42 souaissa 71 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 5 {
44     }
45    
46     MG_FACE::~MG_FACE()
47     {
48     //if (lst_coface.size()!=0) afficheur << WARCOFACE << this->get_id()<< enderr;
49 souaissa 71 if (vect!=NULL) delete vect;
50 5 }
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 francois 195 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 5
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     int MG_FACE::valide_parametre_u(double& u)
145     {
146     if (surface->est_periodique_u()) return 1;
147     double param=u;
148     if (orientation!=MEME_SENS) param=surface->get_umin()+surface->get_umax()-param;
149     double param_min,param_max;
150     param_min=surface->get_umin();
151     param_max=surface->get_umax();
152     if (param<param_min)
153     {
154     u=param_min;
155     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
156     return 0;
157     }
158     if (param>param_max)
159     {
160     u=param_max;
161     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
162     return 0;
163     }
164     return 1;
165     }
166    
167     int MG_FACE::valide_parametre_v(double& v)
168     {
169     if (surface->est_periodique_v()) return 1;
170     double param=v;
171     double param_min,param_max;
172     param_min=surface->get_vmin();
173     param_max=surface->get_vmax();
174     if (param<param_min)
175     {
176     v=param_min;
177     return 0;
178     }
179     if (param>param_max)
180     {
181     v=param_max;
182     return 0;
183     }
184     return 1;
185     }
186    
187     void MG_FACE::evaluer(double *uv,double *xyz)
188     {
189     double param[2]={uv[0],uv[1]};
190     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
191     surface->evaluer(param,xyz);
192     }
193    
194     void MG_FACE::deriver(double *uv,double *xyzdu, double *xyzdv)
195     {
196     double param[2]={uv[0],uv[1]};
197     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
198     surface->deriver(param,xyzdu,xyzdv);
199     if (orientation!=MEME_SENS)
200     {
201     xyzdu[0]=-xyzdu[0];
202     xyzdu[1]=-xyzdu[1];
203     xyzdu[2]=-xyzdu[2];
204     }
205     }
206    
207     void MG_FACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu, double *xyzdv)
208     {
209     double param[2]={uv[0],uv[1]};
210     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
211     surface->deriver_seconde(param,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
212     if (orientation!=MEME_SENS)
213     {
214     xyzdu[0]=-xyzdu[0];
215     xyzdu[1]=-xyzdu[1];
216     xyzdu[2]=-xyzdu[2];
217     xyzduv[0]=-xyzduv[0];
218     xyzduv[1]=-xyzduv[1];
219     xyzduv[2]=-xyzduv[2];
220     }
221     }
222    
223     void MG_FACE::inverser(double *uv,double *xyz,double precision)
224     {
225     surface->inverser(uv,xyz,precision);
226     if (orientation!=MEME_SENS) uv[0]=surface->get_umin()+surface->get_umax()-uv[0];
227     }
228    
229     void MG_FACE::calcul_normale(double *uv,double *normale)
230     {
231     double xyzdu[3];
232     double xyzdv[3];
233    
234     deriver(uv,xyzdu,xyzdv);
235     OT_VECTEUR_3D xu(xyzdu);
236     OT_VECTEUR_3D xv(xyzdv);
237     OT_VECTEUR_3D n=xu&xv;
238     normale[0]=n.get_x();
239     normale[1]=n.get_y();
240     normale[2]=n.get_z();
241     }
242    
243     void MG_FACE::calcul_normale_unitaire(double *uv,double *normale)
244     {
245     double xyzdu[3];
246     double xyzdv[3];
247    
248     deriver(uv,xyzdu,xyzdv);
249     OT_VECTEUR_3D xu(xyzdu);
250     OT_VECTEUR_3D xv(xyzdv);
251     OT_VECTEUR_3D n=xu&xv;
252     n.norme();
253     normale[0]=n.get_x();
254     normale[1]=n.get_y();
255     normale[2]=n.get_z();
256     }
257    
258    
259     void MG_FACE::get_EFG(double *uv,double& E,double& F,double& G)
260     {
261     double xyzdu[3];
262     double xyzdv[3];
263     deriver(uv,xyzdu,xyzdv);
264     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
265     F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
266     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
267     }
268    
269     void MG_FACE::get_M(double *uv,double& M1,double& M2,double& M3)
270     {
271     double E,F,G;
272     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3];
273    
274     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
275     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
276     //F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
277     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
278     double Edu=2.*(xyzdu[0]*xyzduu[0]+xyzdu[1]*xyzduu[1]+xyzdu[2]*xyzduu[2]);
279     double Gdv=2.*(xyzdv[0]*xyzdvv[0]+xyzdv[1]*xyzdvv[1]+xyzdv[2]*xyzdvv[2]);
280     double Edv=2.*(xyzdu[0]*xyzduv[0]+xyzdu[1]*xyzduv[1]+xyzdu[2]*xyzduv[2]);
281     double Gdu=2.*(xyzdv[0]*xyzduv[0]+xyzdv[1]*xyzduv[1]+xyzdv[2]*xyzduv[2]);
282     double m1[3],m2[3],m3[3];
283     m1[0]=xyzduu[0]/E-0.5*Edu*xyzdu[0]/E/E;
284     m1[1]=xyzduu[1]/E-0.5*Edu*xyzdu[1]/E/E;
285     m1[2]=xyzduu[2]/E-0.5*Edu*xyzdu[2]/E/E;
286     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);
287     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);
288     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);
289     m3[0]=xyzdvv[0]/G-0.5*Gdv*xyzdv[0]/G/G;
290     m3[1]=xyzdvv[1]/G-0.5*Gdv*xyzdv[1]/G/G;
291     m3[2]=xyzdvv[2]/G-0.5*Gdv*xyzdv[2]/G/G;
292     M1=sqrt(m1[0]*m1[0]+m1[1]*m1[1]+m1[2]*m1[2]);
293     M2=sqrt(m2[0]*m2[0]+m2[1]*m2[1]+m2[2]*m2[2]);
294     M3=sqrt(m3[0]*m3[0]+m3[1]*m3[1]+m3[2]*m3[2]);
295     }
296    
297     void MG_FACE::get_LMN(double *uv,double& L,double& M,double &N)
298     {
299    
300     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3],normal[3];
301     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
302     calcul_normale_unitaire(uv,normal);
303     L=xyzduu[0]*normal[0]+xyzduu[1]*normal[1]+xyzduu[2]*normal[2];
304     M=xyzduv[0]*normal[0]+xyzduv[1]*normal[1]+xyzduv[2]*normal[2];
305     N=xyzdvv[0]*normal[0]+xyzdvv[1]*normal[1]+xyzdvv[2]*normal[2];
306     }
307    
308    
309     void MG_FACE::get_courbure(double *uv,double& cmax,double& cmin)
310     {
311     double E,F,G,L,M,N;
312     get_EFG(uv,E,F,G);
313     get_LMN(uv,L,M,N);
314     double a=E*G-F*F;
315     double b=-E*N-G*L+2*F*M;
316     double c=L*N-M*M;
317     double delta=b*b-4*a*c;
318     if (delta<0.00000001) delta=0.;
319     double x1=(-b+sqrt(delta))/2./a;
320     double x2=(-b-sqrt(delta))/2./a;
321     if (fabs(x1)>fabs(x2)) {cmax=x1;cmin=x2;} else {cmax=x2;cmin=x1;}
322     }
323    
324 souaissa 71 VCT& MG_FACE::get_vectorisation(void)
325     {
326     if (vect==NULL) vect=new VCT_FACE(this);
327     return *vect;
328     }
329    
330 5 void MG_FACE::enregistrer(std::ostream& o)
331     {
332     o << "%" << get_id() << "=FACE("<< get_idoriginal() << ",$" << surface->get_id() << ",(";
333     for (unsigned int i=0;i<lst_boucle.size();i++)
334     {
335     o << "$" << lst_boucle[i]->get_id();
336     if (i!=lst_boucle.size()-1) o << ","; else o << ")";
337     }
338     int nb=get_nb_ccf();
339     o << "," << orientation << "," << nb;
340     if (nb!=0)
341     {
342     o << ",(";
343     for (int i=0;i<nb;i++)
344     {
345     char nom[3];
346     get_type_ccf(i,nom);
347     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
348     if (i!=nb-1) o << "," ;
349     }
350     o << ")";
351     }
352     o << ");" << std::endl;
353     }
354    
355