ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_face.cpp
Revision: 5
Committed: Tue Jun 12 20:26:34 2007 UTC (17 years, 11 months ago)
Original Path: magic/lib/geometrie/geometrie/src/mg_face.cpp
File size: 8915 byte(s)
Log Message:

File Contents

# User Rev Content
1 5 //------------------------------------------------------------
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 "geom.h"
29     //#include "message.h"
30     //#include "affiche.h"
31     #include "ot_mathematique.h"
32    
33     MG_FACE::MG_FACE(std::string idori,unsigned long num,MG_SURFACE* srf,int sens):MG_ELEMENT_TOPOLOGIQUE(num,idori),surface(srf),orientation(sens)
34     {
35     }
36    
37     MG_FACE::MG_FACE(std::string idori,MG_SURFACE* srf,int sens):MG_ELEMENT_TOPOLOGIQUE(idori),surface(srf),orientation(sens)
38     {
39     }
40    
41     MG_FACE::MG_FACE(MG_FACE& mdd):MG_ELEMENT_TOPOLOGIQUE(mdd),lst_boucle(mdd.lst_boucle),surface(mdd.surface),orientation(mdd.orientation)
42     {
43     }
44    
45     MG_FACE::~MG_FACE()
46     {
47     //if (lst_coface.size()!=0) afficheur << WARCOFACE << this->get_id()<< enderr;
48     }
49    
50     void MG_FACE::ajouter_mg_boucle(class MG_BOUCLE* mgbou)
51     {
52     lst_boucle.insert(lst_boucle.end(),mgbou);
53     }
54    
55     void MG_FACE::supprimer_mg_boucle(class MG_BOUCLE* mgbou)
56     {
57     std::vector<MG_BOUCLE*>::iterator i;
58     for (i=lst_boucle.begin();i!=lst_boucle.end();i++)
59     {
60     if ((*i)==mgbou)
61     {
62     lst_boucle.erase(i);
63     return;
64     }
65     }
66     }
67    
68    
69     int MG_FACE::get_nb_mg_boucle(void)
70     {
71     return lst_boucle.size();
72     }
73    
74     MG_BOUCLE* MG_FACE::get_mg_boucle(int num)
75     {
76     return lst_boucle[num];
77     }
78    
79    
80     void MG_FACE::ajouter_mg_coface(class MG_COFACE* coface)
81     {
82     lst_coface.insert(lst_coface.end(),coface);
83     }
84    
85     int MG_FACE::get_nb_mg_coface(void)
86     {
87     return lst_coface.size();
88     }
89    
90    
91     void MG_FACE::supprimer_mg_coface(class MG_COFACE* coface)
92     {
93     std::vector<MG_COFACE*>::iterator i;
94     for (i=lst_coface.begin();i!=lst_coface.end();i++)
95     {
96     if ((*i)==coface)
97     {
98     lst_coface.erase(i);
99     return;
100     }
101     }
102     }
103    
104    
105    
106     MG_COFACE* MG_FACE::get_mg_coface(int num)
107     {
108     return lst_coface[num];
109     }
110    
111     MG_SURFACE* MG_FACE::get_surface(void)
112     {
113     return surface;
114     }
115    
116    
117     int MG_FACE::get_dimension(void)
118     {
119     return 2;
120     }
121    
122     int MG_FACE::get_orientation(void)
123     {
124     return orientation;
125     }
126    
127     int MG_FACE::valide_parametre_u(double& u)
128     {
129     if (surface->est_periodique_u()) return 1;
130     double param=u;
131     if (orientation!=MEME_SENS) param=surface->get_umin()+surface->get_umax()-param;
132     double param_min,param_max;
133     param_min=surface->get_umin();
134     param_max=surface->get_umax();
135     if (param<param_min)
136     {
137     u=param_min;
138     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
139     return 0;
140     }
141     if (param>param_max)
142     {
143     u=param_max;
144     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
145     return 0;
146     }
147     return 1;
148     }
149    
150     int MG_FACE::valide_parametre_v(double& v)
151     {
152     if (surface->est_periodique_v()) return 1;
153     double param=v;
154     double param_min,param_max;
155     param_min=surface->get_vmin();
156     param_max=surface->get_vmax();
157     if (param<param_min)
158     {
159     v=param_min;
160     return 0;
161     }
162     if (param>param_max)
163     {
164     v=param_max;
165     return 0;
166     }
167     return 1;
168     }
169    
170     void MG_FACE::evaluer(double *uv,double *xyz)
171     {
172     double param[2]={uv[0],uv[1]};
173     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
174     surface->evaluer(param,xyz);
175     }
176    
177     void MG_FACE::deriver(double *uv,double *xyzdu, double *xyzdv)
178     {
179     double param[2]={uv[0],uv[1]};
180     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
181     surface->deriver(param,xyzdu,xyzdv);
182     if (orientation!=MEME_SENS)
183     {
184     xyzdu[0]=-xyzdu[0];
185     xyzdu[1]=-xyzdu[1];
186     xyzdu[2]=-xyzdu[2];
187     }
188     }
189    
190     void MG_FACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu, double *xyzdv)
191     {
192     double param[2]={uv[0],uv[1]};
193     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
194     surface->deriver_seconde(param,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
195     if (orientation!=MEME_SENS)
196     {
197     xyzdu[0]=-xyzdu[0];
198     xyzdu[1]=-xyzdu[1];
199     xyzdu[2]=-xyzdu[2];
200     xyzduv[0]=-xyzduv[0];
201     xyzduv[1]=-xyzduv[1];
202     xyzduv[2]=-xyzduv[2];
203     }
204     }
205    
206     void MG_FACE::inverser(double *uv,double *xyz,double precision)
207     {
208     surface->inverser(uv,xyz,precision);
209     if (orientation!=MEME_SENS) uv[0]=surface->get_umin()+surface->get_umax()-uv[0];
210     }
211    
212     void MG_FACE::calcul_normale(double *uv,double *normale)
213     {
214     double xyzdu[3];
215     double xyzdv[3];
216    
217     deriver(uv,xyzdu,xyzdv);
218     OT_VECTEUR_3D xu(xyzdu);
219     OT_VECTEUR_3D xv(xyzdv);
220     OT_VECTEUR_3D n=xu&xv;
221     normale[0]=n.get_x();
222     normale[1]=n.get_y();
223     normale[2]=n.get_z();
224     }
225    
226     void MG_FACE::calcul_normale_unitaire(double *uv,double *normale)
227     {
228     double xyzdu[3];
229     double xyzdv[3];
230    
231     deriver(uv,xyzdu,xyzdv);
232     OT_VECTEUR_3D xu(xyzdu);
233     OT_VECTEUR_3D xv(xyzdv);
234     OT_VECTEUR_3D n=xu&xv;
235     n.norme();
236     normale[0]=n.get_x();
237     normale[1]=n.get_y();
238     normale[2]=n.get_z();
239     }
240    
241    
242     void MG_FACE::get_EFG(double *uv,double& E,double& F,double& G)
243     {
244     double xyzdu[3];
245     double xyzdv[3];
246     deriver(uv,xyzdu,xyzdv);
247     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
248     F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
249     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
250     }
251    
252     void MG_FACE::get_M(double *uv,double& M1,double& M2,double& M3)
253     {
254     double E,F,G;
255     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3];
256    
257     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
258     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
259     //F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
260     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
261     double Edu=2.*(xyzdu[0]*xyzduu[0]+xyzdu[1]*xyzduu[1]+xyzdu[2]*xyzduu[2]);
262     double Gdv=2.*(xyzdv[0]*xyzdvv[0]+xyzdv[1]*xyzdvv[1]+xyzdv[2]*xyzdvv[2]);
263     double Edv=2.*(xyzdu[0]*xyzduv[0]+xyzdu[1]*xyzduv[1]+xyzdu[2]*xyzduv[2]);
264     double Gdu=2.*(xyzdv[0]*xyzduv[0]+xyzdv[1]*xyzduv[1]+xyzdv[2]*xyzduv[2]);
265     double m1[3],m2[3],m3[3];
266     m1[0]=xyzduu[0]/E-0.5*Edu*xyzdu[0]/E/E;
267     m1[1]=xyzduu[1]/E-0.5*Edu*xyzdu[1]/E/E;
268     m1[2]=xyzduu[2]/E-0.5*Edu*xyzdu[2]/E/E;
269     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);
270     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);
271     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);
272     m3[0]=xyzdvv[0]/G-0.5*Gdv*xyzdv[0]/G/G;
273     m3[1]=xyzdvv[1]/G-0.5*Gdv*xyzdv[1]/G/G;
274     m3[2]=xyzdvv[2]/G-0.5*Gdv*xyzdv[2]/G/G;
275     M1=sqrt(m1[0]*m1[0]+m1[1]*m1[1]+m1[2]*m1[2]);
276     M2=sqrt(m2[0]*m2[0]+m2[1]*m2[1]+m2[2]*m2[2]);
277     M3=sqrt(m3[0]*m3[0]+m3[1]*m3[1]+m3[2]*m3[2]);
278     }
279    
280     void MG_FACE::get_LMN(double *uv,double& L,double& M,double &N)
281     {
282    
283     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3],normal[3];
284     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
285     calcul_normale_unitaire(uv,normal);
286     L=xyzduu[0]*normal[0]+xyzduu[1]*normal[1]+xyzduu[2]*normal[2];
287     M=xyzduv[0]*normal[0]+xyzduv[1]*normal[1]+xyzduv[2]*normal[2];
288     N=xyzdvv[0]*normal[0]+xyzdvv[1]*normal[1]+xyzdvv[2]*normal[2];
289     }
290    
291    
292     void MG_FACE::get_courbure(double *uv,double& cmax,double& cmin)
293     {
294     double E,F,G,L,M,N;
295     get_EFG(uv,E,F,G);
296     get_LMN(uv,L,M,N);
297     double a=E*G-F*F;
298     double b=-E*N-G*L+2*F*M;
299     double c=L*N-M*M;
300     double delta=b*b-4*a*c;
301     if (delta<0.00000001) delta=0.;
302     double x1=(-b+sqrt(delta))/2./a;
303     double x2=(-b-sqrt(delta))/2./a;
304     if (fabs(x1)>fabs(x2)) {cmax=x1;cmin=x2;} else {cmax=x2;cmin=x1;}
305     }
306    
307     void MG_FACE::enregistrer(std::ostream& o)
308     {
309     o << "%" << get_id() << "=FACE("<< get_idoriginal() << ",$" << surface->get_id() << ",(";
310     for (unsigned int i=0;i<lst_boucle.size();i++)
311     {
312     o << "$" << lst_boucle[i]->get_id();
313     if (i!=lst_boucle.size()-1) o << ","; else o << ")";
314     }
315     int nb=get_nb_ccf();
316     o << "," << orientation << "," << nb;
317     if (nb!=0)
318     {
319     o << ",(";
320     for (int i=0;i<nb;i++)
321     {
322     char nom[3];
323     get_type_ccf(i,nom);
324     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
325     if (i!=nb-1) o << "," ;
326     }
327     o << ")";
328     }
329     o << ");" << std::endl;
330     }
331    
332