ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_face.cpp
Revision: 71
Committed: Mon Mar 31 21:10:47 2008 UTC (17 years, 1 month ago) by souaissa
Original Path: magic/lib/geometrie/geometrie/src/mg_face.cpp
File size: 9105 byte(s)
Log Message:
vectorisation est une propriete des entites

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 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    
119     int MG_FACE::get_dimension(void)
120     {
121     return 2;
122     }
123    
124     int MG_FACE::get_orientation(void)
125     {
126     return orientation;
127     }
128    
129     int MG_FACE::valide_parametre_u(double& u)
130     {
131     if (surface->est_periodique_u()) return 1;
132     double param=u;
133     if (orientation!=MEME_SENS) param=surface->get_umin()+surface->get_umax()-param;
134     double param_min,param_max;
135     param_min=surface->get_umin();
136     param_max=surface->get_umax();
137     if (param<param_min)
138     {
139     u=param_min;
140     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
141     return 0;
142     }
143     if (param>param_max)
144     {
145     u=param_max;
146     if (orientation!=MEME_SENS) u=surface->get_umin()+surface->get_umax()-u;
147     return 0;
148     }
149     return 1;
150     }
151    
152     int MG_FACE::valide_parametre_v(double& v)
153     {
154     if (surface->est_periodique_v()) return 1;
155     double param=v;
156     double param_min,param_max;
157     param_min=surface->get_vmin();
158     param_max=surface->get_vmax();
159     if (param<param_min)
160     {
161     v=param_min;
162     return 0;
163     }
164     if (param>param_max)
165     {
166     v=param_max;
167     return 0;
168     }
169     return 1;
170     }
171    
172     void MG_FACE::evaluer(double *uv,double *xyz)
173     {
174     double param[2]={uv[0],uv[1]};
175     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
176     surface->evaluer(param,xyz);
177     }
178    
179     void MG_FACE::deriver(double *uv,double *xyzdu, double *xyzdv)
180     {
181     double param[2]={uv[0],uv[1]};
182     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
183     surface->deriver(param,xyzdu,xyzdv);
184     if (orientation!=MEME_SENS)
185     {
186     xyzdu[0]=-xyzdu[0];
187     xyzdu[1]=-xyzdu[1];
188     xyzdu[2]=-xyzdu[2];
189     }
190     }
191    
192     void MG_FACE::deriver_seconde(double *uv,double* xyzduu,double* xyzduv,double* xyzdvv,double *xyz , double *xyzdu, double *xyzdv)
193     {
194     double param[2]={uv[0],uv[1]};
195     if (orientation!=MEME_SENS) param[0]=surface->get_umin()+surface->get_umax()-param[0];
196     surface->deriver_seconde(param,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
197     if (orientation!=MEME_SENS)
198     {
199     xyzdu[0]=-xyzdu[0];
200     xyzdu[1]=-xyzdu[1];
201     xyzdu[2]=-xyzdu[2];
202     xyzduv[0]=-xyzduv[0];
203     xyzduv[1]=-xyzduv[1];
204     xyzduv[2]=-xyzduv[2];
205     }
206     }
207    
208     void MG_FACE::inverser(double *uv,double *xyz,double precision)
209     {
210     surface->inverser(uv,xyz,precision);
211     if (orientation!=MEME_SENS) uv[0]=surface->get_umin()+surface->get_umax()-uv[0];
212     }
213    
214     void MG_FACE::calcul_normale(double *uv,double *normale)
215     {
216     double xyzdu[3];
217     double xyzdv[3];
218    
219     deriver(uv,xyzdu,xyzdv);
220     OT_VECTEUR_3D xu(xyzdu);
221     OT_VECTEUR_3D xv(xyzdv);
222     OT_VECTEUR_3D n=xu&xv;
223     normale[0]=n.get_x();
224     normale[1]=n.get_y();
225     normale[2]=n.get_z();
226     }
227    
228     void MG_FACE::calcul_normale_unitaire(double *uv,double *normale)
229     {
230     double xyzdu[3];
231     double xyzdv[3];
232    
233     deriver(uv,xyzdu,xyzdv);
234     OT_VECTEUR_3D xu(xyzdu);
235     OT_VECTEUR_3D xv(xyzdv);
236     OT_VECTEUR_3D n=xu&xv;
237     n.norme();
238     normale[0]=n.get_x();
239     normale[1]=n.get_y();
240     normale[2]=n.get_z();
241     }
242    
243    
244     void MG_FACE::get_EFG(double *uv,double& E,double& F,double& G)
245     {
246     double xyzdu[3];
247     double xyzdv[3];
248     deriver(uv,xyzdu,xyzdv);
249     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
250     F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
251     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
252     }
253    
254     void MG_FACE::get_M(double *uv,double& M1,double& M2,double& M3)
255     {
256     double E,F,G;
257     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3];
258    
259     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
260     E=xyzdu[0]*xyzdu[0]+xyzdu[1]*xyzdu[1]+xyzdu[2]*xyzdu[2];
261     //F=xyzdu[0]*xyzdv[0]+xyzdu[1]*xyzdv[1]+xyzdu[2]*xyzdv[2];
262     G=xyzdv[0]*xyzdv[0]+xyzdv[1]*xyzdv[1]+xyzdv[2]*xyzdv[2];
263     double Edu=2.*(xyzdu[0]*xyzduu[0]+xyzdu[1]*xyzduu[1]+xyzdu[2]*xyzduu[2]);
264     double Gdv=2.*(xyzdv[0]*xyzdvv[0]+xyzdv[1]*xyzdvv[1]+xyzdv[2]*xyzdvv[2]);
265     double Edv=2.*(xyzdu[0]*xyzduv[0]+xyzdu[1]*xyzduv[1]+xyzdu[2]*xyzduv[2]);
266     double Gdu=2.*(xyzdv[0]*xyzduv[0]+xyzdv[1]*xyzduv[1]+xyzdv[2]*xyzduv[2]);
267     double m1[3],m2[3],m3[3];
268     m1[0]=xyzduu[0]/E-0.5*Edu*xyzdu[0]/E/E;
269     m1[1]=xyzduu[1]/E-0.5*Edu*xyzdu[1]/E/E;
270     m1[2]=xyzduu[2]/E-0.5*Edu*xyzdu[2]/E/E;
271     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);
272     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);
273     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);
274     m3[0]=xyzdvv[0]/G-0.5*Gdv*xyzdv[0]/G/G;
275     m3[1]=xyzdvv[1]/G-0.5*Gdv*xyzdv[1]/G/G;
276     m3[2]=xyzdvv[2]/G-0.5*Gdv*xyzdv[2]/G/G;
277     M1=sqrt(m1[0]*m1[0]+m1[1]*m1[1]+m1[2]*m1[2]);
278     M2=sqrt(m2[0]*m2[0]+m2[1]*m2[1]+m2[2]*m2[2]);
279     M3=sqrt(m3[0]*m3[0]+m3[1]*m3[1]+m3[2]*m3[2]);
280     }
281    
282     void MG_FACE::get_LMN(double *uv,double& L,double& M,double &N)
283     {
284    
285     double xyz[3],xyzdu[3],xyzdv[3],xyzduu[3],xyzduv[3],xyzdvv[3],normal[3];
286     deriver_seconde(uv,xyzduu,xyzduv,xyzdvv,xyz,xyzdu,xyzdv);
287     calcul_normale_unitaire(uv,normal);
288     L=xyzduu[0]*normal[0]+xyzduu[1]*normal[1]+xyzduu[2]*normal[2];
289     M=xyzduv[0]*normal[0]+xyzduv[1]*normal[1]+xyzduv[2]*normal[2];
290     N=xyzdvv[0]*normal[0]+xyzdvv[1]*normal[1]+xyzdvv[2]*normal[2];
291     }
292    
293    
294     void MG_FACE::get_courbure(double *uv,double& cmax,double& cmin)
295     {
296     double E,F,G,L,M,N;
297     get_EFG(uv,E,F,G);
298     get_LMN(uv,L,M,N);
299     double a=E*G-F*F;
300     double b=-E*N-G*L+2*F*M;
301     double c=L*N-M*M;
302     double delta=b*b-4*a*c;
303     if (delta<0.00000001) delta=0.;
304     double x1=(-b+sqrt(delta))/2./a;
305     double x2=(-b-sqrt(delta))/2./a;
306     if (fabs(x1)>fabs(x2)) {cmax=x1;cmin=x2;} else {cmax=x2;cmin=x1;}
307     }
308    
309 souaissa 71 VCT& MG_FACE::get_vectorisation(void)
310     {
311     if (vect==NULL) vect=new VCT_FACE(this);
312     return *vect;
313     }
314    
315 5 void MG_FACE::enregistrer(std::ostream& o)
316     {
317     o << "%" << get_id() << "=FACE("<< get_idoriginal() << ",$" << surface->get_id() << ",(";
318     for (unsigned int i=0;i<lst_boucle.size();i++)
319     {
320     o << "$" << lst_boucle[i]->get_id();
321     if (i!=lst_boucle.size()-1) o << ","; else o << ")";
322     }
323     int nb=get_nb_ccf();
324     o << "," << orientation << "," << nb;
325     if (nb!=0)
326     {
327     o << ",(";
328     for (int i=0;i<nb;i++)
329     {
330     char nom[3];
331     get_type_ccf(i,nom);
332     o << "(" << nom << "," << get_valeur_ccf(i) << ")";
333     if (i!=nb-1) o << "," ;
334     }
335     o << ")";
336     }
337     o << ");" << std::endl;
338     }
339    
340