ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/mg_face.cpp
Revision: 906
Committed: Mon Nov 13 22:30:18 2017 UTC (7 years, 9 months ago) by couturad
File size: 12740 byte(s)
Log Message:
Nouveau opencascade commit 1

File Contents

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