ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/vct_surface.cpp
Revision: 79
Committed: Thu Apr 10 15:14:15 2008 UTC (17 years, 1 month ago) by souaissa
Original Path: magic/lib/geometrie/geometrie/src/vct_surface.cpp
File size: 12057 byte(s)
Log Message:

File Contents

# User Rev Content
1 souaissa 66 #include "gestionversion.h"
2    
3     //---------------------------------------------------------------------------
4    
5    
6     #pragma hdrstop
7    
8     #include "vct_surface.h"
9     #include "mg_surface.h"
10     #include <iomanip.h>
11     //---------------------------------------------------------------------------
12    
13     #pragma package(smart_init)
14    
15    
16     VCT_SURFACE::VCT_SURFACE(MG_SURFACE* elemgeo):VCT_ELEMENT_GEOMETRIQUE(elemgeo)
17     {
18 souaissa 69 int indx_premier_ptctr;
19     TPL_LISTE_ENTITE<double> nurbs_params;
20 souaissa 66 elem_geo->get_param_NURBS(indx_premier_ptctr,nurbs_params);
21     nb_points=1/4.*(nurbs_params.get_nb()-indx_premier_ptctr);
22 souaissa 69 int nb_u=nurbs_params.get(3);
23     int nb_v=nurbs_params.get(4);
24 souaissa 66 double2 ZERO=0.;
25 souaissa 69 OT_VECTEUR_4DD VCT_NUL(0.,0.,0.,0.);
26 souaissa 66
27 souaissa 69 OT_VECTEUR_4DD V1,V2,V;
28 souaissa 66
29 souaissa 79 for(int pt=0;pt< nb_points;pt++)
30     {
31     V1[0]=nurbs_params.get( indx_premier_ptctr+ 4 * pt);
32     V1[1]=nurbs_params.get( indx_premier_ptctr+ 4 * pt + 1);
33     V1[2]=nurbs_params.get( indx_premier_ptctr+ 4 * pt + 2);
34     V1[3]=nurbs_params.get( indx_premier_ptctr+ 4 * pt + 3);
35 souaissa 66
36 souaissa 79 lst_points.insert(lst_points.end(),V1);
37     }
38    
39    
40    
41    
42 souaissa 66 for(int r=0;r<nb_v;r++)
43     {
44     for(int s=0;s<nb_u-1;s++)
45     {
46 souaissa 69
47     V1[0]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * s);
48     V1[1]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * s + 1);
49     V1[2]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * s + 2);
50     V1[3]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * s + 3);
51 souaissa 71
52    
53 souaissa 79
54 souaissa 69 V2[0]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * (s + 1));
55     V2[1]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * (s + 1) + 1);
56     V2[2]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * (s + 1) + 2);
57     V2[3]=nurbs_params.get( indx_premier_ptctr+ r *4 * nb_u + 4 * (s + 1) + 3);
58 souaissa 71
59 souaissa 66
60 souaissa 79
61 souaissa 69 V=V2-V1;
62 souaissa 66
63 souaissa 69 double2 norm_au_carre=(V[0]*V[0])+(V[1]*V[1])+(V[2]*V[2])+(V[3]*V[3]);
64     double2 norm=norm_au_carre^0.5;
65 souaissa 66
66 souaissa 69 if(V==VCT_NUL)
67     lst_vecteurs.insert(lst_vecteurs.end(),VCT_NUL);
68    
69 souaissa 66 if(norm!=ZERO){
70 souaissa 69 V=1./norm*V;
71     lst_vecteurs.insert(lst_vecteurs.end(),V);
72 souaissa 66 }
73    
74     }
75     }
76    
77     for(int r=0;r<nb_v-1;r++)
78     {
79     for(int s=0;s<nb_u;s++)
80     {
81 souaissa 69 V1[0]=nurbs_params.get(indx_premier_ptctr+ r * 4 * nb_u + 4 * s);
82     V1[1]=nurbs_params.get(indx_premier_ptctr+ r * 4 * nb_u + 4 * s + 1);
83     V1[2]=nurbs_params.get(indx_premier_ptctr+ r * 4 * nb_u + 4 * s + 2);
84     V1[3]=nurbs_params.get(indx_premier_ptctr+ r * 4 * nb_u + 4 * s + 3);
85 souaissa 71
86    
87 souaissa 79
88 souaissa 69 V2[0]=nurbs_params.get(indx_premier_ptctr+ (r+1) *4 * nb_u + 4 * s);
89     V2[1]=nurbs_params.get(indx_premier_ptctr+ (r+1) *4 * nb_u + 4 * s + 1);
90     V2[2]=nurbs_params.get(indx_premier_ptctr+ (r+1) *4 * nb_u + 4 * s + 2);
91     V2[3]=nurbs_params.get(indx_premier_ptctr+ (r+1) *4 * nb_u + 4 * s + 3);
92 souaissa 71
93 souaissa 79
94 souaissa 69 V=V2-V1;
95 souaissa 66
96 souaissa 69 double2 norm_au_carre=(V[0]*V[0])+(V[1]*V[1])+(V[2]*V[2])+(V[3]*V[3]);
97     double2 norm=norm_au_carre^0.5;
98 souaissa 66
99 souaissa 69 if(V==VCT_NUL)
100     lst_vecteurs.insert(lst_vecteurs.end(),VCT_NUL);
101 souaissa 66
102 souaissa 69 if (norm!=ZERO){
103     V=1./norm*V;
104     lst_vecteurs.insert(lst_vecteurs.end(),V);
105 souaissa 66
106     }
107     }
108     }
109    
110 souaissa 69
111    
112 souaissa 66 }
113    
114    
115    
116 souaissa 69
117    
118    
119     VCT_SURFACE::VCT_SURFACE(VCT_SURFACE& mdd):VCT_ELEMENT_GEOMETRIQUE(mdd.elem_geo)
120 souaissa 66 {
121 souaissa 69 lst_vecteurs=mdd.lst_vecteurs;
122     lst_points=mdd.lst_points;
123     nb_points=mdd.nb_points ;
124     }
125 souaissa 66
126    
127 souaissa 69 VCT_SURFACE::~VCT_SURFACE()
128     {
129     }
130    
131     std::vector<OT_VECTEUR_4DD> &VCT_SURFACE::get_vecteurs()
132     {
133     return lst_vecteurs;
134     }
135    
136 francois 72 std::vector<OT_VECTEUR_4DD>& VCT_SURFACE::get_points_controle(void)
137 souaissa 71 {
138     return lst_points;
139     }
140 souaissa 69
141 souaissa 71
142 souaissa 69 OT_TENSEUR VCT_SURFACE:: calcule_tenseur_metrique()
143     {
144     OT_TENSEUR tns(lst_vecteurs);
145     return tns;
146     }
147    
148     OT_VECTEUR_4DD VCT_SURFACE::calcule_barycentre()
149     {
150     OT_VECTEUR_4DD barycentre(0,0,0,0);
151    
152 souaissa 66 for(int i=0;i<nb_points;i++)
153     {
154 souaissa 71 barycentre+=lst_points[i];
155 souaissa 66 }
156    
157 souaissa 69 barycentre*=1./nb_points;
158     return barycentre;
159 souaissa 66 }
160    
161    
162    
163 souaissa 69 int VCT_SURFACE::get_nb_points()
164     {
165     return nb_points ;
166     }
167    
168    
169     OT_TENSEUR VCT_SURFACE::calcule_covariance(void)
170 souaissa 66 {
171 souaissa 71 OT_TENSEUR COVARIANCE(4);
172 souaissa 69 std::vector<OT_VECTEUR_4DD> Points_Centre_au_barycentre(nb_points);
173     OT_VECTEUR_4DD barycentre=calcule_barycentre();
174 souaissa 66
175 souaissa 69 for( int i=0;i<nb_points;i++)
176     {
177     Points_Centre_au_barycentre[i]=lst_points[i]-barycentre;
178     }
179    
180 souaissa 71 OT_TENSEUR PT_CENTRE(nb_points,4),PT_CENTRE_TRANSPOSE;
181 souaissa 69
182 souaissa 71 for( int i=0;i<nb_points;i++)
183     {
184     OT_VECTEUR_4DD pt=Points_Centre_au_barycentre[i];
185     PT_CENTRE(i,0)= pt[0] ;
186     PT_CENTRE(i,1)= pt[1] ;
187     PT_CENTRE(i,2)= pt[2] ;
188     PT_CENTRE(i,3)= pt[3] ;
189     }
190     PT_CENTRE_TRANSPOSE =PT_CENTRE.transpose();
191    
192     COVARIANCE=PT_CENTRE_TRANSPOSE*PT_CENTRE;
193     double2 COEF= 1./nb_points;
194     COVARIANCE=COVARIANCE*COEF;
195    
196 souaissa 69 return COVARIANCE;
197 souaissa 66 }
198    
199 souaissa 69
200 souaissa 71 void VCT_SURFACE::calcule_axes_dinertie(OT_VECTEUR_4DD& D,OT_TENSEUR& V)
201 souaissa 66 {
202 souaissa 69 int n=4;
203     int nrot;
204    
205 souaissa 71 OT_TENSEUR COV=calcule_covariance();
206    
207    
208 souaissa 69 double2 zro=0.0;
209    
210 souaissa 71 if(COV(0,0)==zro&&COV(1,0)==zro&&COV(2,0)==zro&&COV(3,0)==zro)
211 souaissa 69 {
212 souaissa 71 COV(0,0)=1.0;
213     COV(1,0)=zro;
214     COV(2,0)=zro;
215     COV(3,0)=zro;
216 souaissa 69 }
217 souaissa 71 if(COV(0,1)==zro&&COV(1,1)==zro&&COV(2,1)==zro&&COV(3,1)==zro)
218 souaissa 69 {
219 souaissa 71 COV(0,1)=zro;
220     COV(1,1)=1.0;
221     COV(2,1)=zro;
222     COV(3,1)=zro;
223 souaissa 69 }
224 souaissa 71 if(COV(0,2)==zro&&COV(1,2)==zro&&COV(2,2)==zro&&COV(3,2)==zro)
225 souaissa 69 {
226 souaissa 71 COV(0,2)=zro;
227     COV(1,2)=zro;
228     COV(2,2)=1.0;
229     COV(3,2)=zro;
230 souaissa 69 }
231 souaissa 71 if(COV(0,3)==zro&&COV(1,3)==zro&&COV(2,3)==zro&&COV(3,3)==zro)
232 souaissa 69 {
233 souaissa 71 COV(0,3)=zro;
234     COV(1,3)=zro;
235     COV(2,3)=zro;
236     COV(3,3)=1.0;
237 souaissa 69 }
238    
239    
240 souaissa 71 COV.get_orthogonalisation(COV,D,V,n,nrot);
241 souaissa 69
242 souaissa 66 }
243    
244    
245 souaissa 69 OT_TENSEUR VCT_SURFACE:: calcule_tenseur_inertie_au_barycentre() //repere globale
246     {
247 souaissa 71 OT_TENSEUR INERTIE(4);
248 souaissa 69 OT_TENSEUR cov=calcule_covariance();
249     double2 nb_pts=nb_points;
250     double2 MOINS_UN=-1.0;
251 souaissa 71 INERTIE=cov*MOINS_UN;
252     INERTIE=INERTIE*nb_pts;
253 souaissa 69
254 souaissa 71 INERTIE(0,0)=(cov(1,1)+cov(2,2)+cov(3,3))*nb_pts;
255     INERTIE(1,1)=(cov(0,0)+cov(2,2)+cov(3,3))*nb_pts;
256     INERTIE(2,2)=(cov(1,1)+cov(0,0)+cov(3,3))*nb_pts;
257     INERTIE(3,3)=(cov(1,1)+cov(2,2)+cov(0,0))*nb_pts;
258    
259     return INERTIE;
260 souaissa 69 }
261    
262    
263     OT_TENSEUR VCT_SURFACE:: calcule_tenseur_inertie_au_pt(OT_VECTEUR_4DD& POINT)
264     {
265    
266 souaissa 71 OT_VECTEUR_4DD BARYCENTRE=calcule_barycentre();
267     OT_TENSEUR TENS=calcule_tenseur_inertie_au_barycentre();
268 souaissa 69
269     OT_VECTEUR_4DD ABC=POINT-BARYCENTRE;
270    
271     double2 a=ABC[0] ;
272     double2 b=ABC[1] ;
273     double2 c=ABC[2] ;
274     double2 d=ABC[3] ;
275    
276     TENS(0,0)=TENS(0,0)+b*b+c*c+d*d;
277     TENS(1,1)=TENS(1,1)+a*a+c*c+d*d;
278     TENS(2,2)=TENS(2,2)+a*a+b*b+d*d;
279 souaissa 71 TENS(3,3)=TENS(3,3)+a*a+b*b+c*c;
280 souaissa 69
281     TENS(0,1)=TENS(0,1)-nb_points*a*b;
282     TENS(0,2)=TENS(0,2)-nb_points*a*c;
283     TENS(0,3)=TENS(0,3)-nb_points*a*d;
284    
285     TENS(1,0)=TENS(1,0)-nb_points*b*a;
286     TENS(1,2)=TENS(1,2)-nb_points*b*c;
287     TENS(1,3)=TENS(1,3)-nb_points*b*d;
288    
289     TENS(2,0)=TENS(2,0)-nb_points*c*a;
290     TENS(2,1)=TENS(2,1)-nb_points*c*b;
291     TENS(2,3)=TENS(2,3)-nb_points*c*d;
292    
293     TENS(3,0)=TENS(3,0)-nb_points*d*a;
294     TENS(3,1)=TENS(3,1)-nb_points*d*b;
295     TENS(3,2)=TENS(3,2)-nb_points*d*c;
296    
297     return TENS;
298     }
299    
300    
301     OT_TENSEUR VCT_SURFACE::calcule_tenseur_inertie_base_locale()
302     {
303 souaissa 71
304 souaissa 69 OT_VECTEUR_4DD v1,v2,v3,v4;
305     OT_TENSEUR INERTIE;
306     OT_TENSEUR I_GLOBALE;
307 souaissa 71 OT_VECTEUR_4DD D;
308     OT_TENSEUR V(4);
309     this->calcule_axes_dinertie(D,V);
310 souaissa 69 INERTIE=this->calcule_tenseur_inertie_au_barycentre();
311    
312     I_GLOBALE= INERTIE;
313    
314     OT_TENSEUR P(4);
315     OT_TENSEUR I=I_GLOBALE;
316     OT_TENSEUR P_TRSPOSE;
317     OT_TENSEUR I_LOCALE;
318 souaissa 71 P=V;
319 souaissa 69 P_TRSPOSE=P.transpose();
320    
321     I_LOCALE=P_TRSPOSE*I;
322     I_LOCALE=I_LOCALE*P;
323    
324 souaissa 71 return I_LOCALE;
325 souaissa 69 }
326    
327    
328    
329    
330 souaissa 79 OT_TENSEUR VCT_SURFACE::calcule_tenseur_inertie_base_entite( VCT& vct_f)
331 souaissa 69 {
332 souaissa 71 OT_VECTEUR_4DD Dv,Dw,G1,G2,G1G2;
333 souaissa 69 OT_TENSEUR P(4);
334     OT_TENSEUR pt;
335     OT_TENSEUR IV;
336 souaissa 71 OT_TENSEUR Q(4);
337 souaissa 69 OT_TENSEUR qt;
338     OT_TENSEUR R;
339     OT_TENSEUR Rt;
340     OT_TENSEUR IW;
341 souaissa 71 OT_TENSEUR MASSE_CONCENTRE(4);
342     OT_TENSEUR V(4),W(4);
343     this->calcule_axes_dinertie(Dv,V);
344     vct_f.calcule_axes_dinertie(Dw,W);
345 souaissa 69
346 souaissa 71 P=V;
347     Q=W;
348 souaissa 69
349 souaissa 71 IW=vct_f.calcule_tenseur_inertie_base_locale();
350 souaissa 69
351     pt=P.transpose();
352     qt=Q.transpose();
353     R=pt*Q;
354     Rt=qt*P;
355     IV=R*IW;
356     IV=IV*Rt;
357 souaissa 66
358    
359 souaissa 69 G1=this->calcule_barycentre();
360     G2=vct_f.calcule_barycentre();
361    
362     G1G2=G2-G1;
363    
364     OT_VECTEUR_4DD G1G2_LOC; //Calcul du vecteur G1G2 dans la base locale;
365     for(int i=0;i<4;i++)
366     {
367     for(int j=0;j<4;j++)
368     {
369     G1G2_LOC[i]= G1G2_LOC[i]+pt(i,j)*G1G2[j];
370 souaissa 66 }
371 souaissa 69 }
372 souaissa 66
373 souaissa 69 MASSE_CONCENTRE(0,0)=nb_points*(G1G2_LOC[1]*G1G2_LOC[1]+G1G2_LOC[2]*G1G2_LOC[2]+G1G2_LOC[3]*G1G2_LOC[3]);
374     MASSE_CONCENTRE(0,1)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[1]);
375     MASSE_CONCENTRE(0,2)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[2]);
376     MASSE_CONCENTRE(0,3)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[3]);
377    
378     MASSE_CONCENTRE(1,0)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[0]);
379     MASSE_CONCENTRE(1,1)= nb_points*(G1G2_LOC[0]*G1G2_LOC[0]+G1G2_LOC[2]*G1G2_LOC[2]+G1G2_LOC[3]*G1G2_LOC[3]);
380     MASSE_CONCENTRE(1,2)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[2]);
381     MASSE_CONCENTRE(1,3)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[3]);
382    
383     MASSE_CONCENTRE(2,0)=-1*nb_points*(G1G2_LOC[2]*G1G2_LOC[0]);
384     MASSE_CONCENTRE(2,1)=-1*nb_points*(G1G2_LOC[2]*G1G2_LOC[1]);
385     MASSE_CONCENTRE(2,2)=nb_points*(G1G2_LOC[0]*G1G2_LOC[0]+G1G2_LOC[1]*G1G2_LOC[1]+G1G2_LOC[3]*G1G2_LOC[3]);
386 souaissa 79 MASSE_CONCENTRE(2,3)=-1*nb_points*(G1G2_LOC[3]*G1G2_LOC[2]);
387 souaissa 69
388     MASSE_CONCENTRE(3,0)=-1*nb_points*(G1G2_LOC[0]*G1G2_LOC[3]);
389     MASSE_CONCENTRE(3,1)=-1*nb_points*(G1G2_LOC[1]*G1G2_LOC[3]);
390     MASSE_CONCENTRE(3,2)=-1*nb_points*(G1G2_LOC[2]*G1G2_LOC[3]);
391     MASSE_CONCENTRE(3,3)=nb_points*(G1G2_LOC[0]*G1G2_LOC[0]+G1G2_LOC[1]*G1G2_LOC[1]+G1G2_LOC[2]*G1G2_LOC[2]);
392    
393     IV=IV+MASSE_CONCENTRE;
394 souaissa 79 return IV;
395 souaissa 66 }
396    
397 souaissa 69
398     ostream& operator <<(ostream& os, VCT_SURFACE& vct_f)
399     {
400     vct_f.enregistrer(os) ;
401     return os;
402     }
403    
404 souaissa 71
405    
406    
407     void VCT_SURFACE::enregistrer(std::ostream& ost)
408     {
409    
410     ost<<"========================================"<<endl;
411     ost<<"% SURFACE: "<<endl;
412     ost<<"========================================"<<endl;
413     ost<<"POINTS_DE_CONTROLS: "<<endl;
414     ost<<"========================================"<<endl;
415    
416     for (unsigned int i=0;i< lst_points.size();i++)
417     {
418     OT_VECTEUR_4DD v= lst_points[i]; // Rmq: la precision nèest pas affocher, il faut rajouter l'affichage
419     ost<< v<<endl; // de la precision dans la classe doubleprecision
420     }
421    
422     ost<<endl;
423     ost<<"VECTORISATION: "<<endl;
424     ost<<"========================================"<<endl;
425     for (unsigned int i=0;i< lst_vecteurs.size();i++)
426     {
427     OT_VECTEUR_4DD v= lst_vecteurs[i];
428     ost<< v<<endl;
429     }
430    
431     ost<<endl<<endl;
432     ost<<"BARYCENTRE: "<<endl;
433     ost<<"========================================"<<endl;
434     OT_VECTEUR_4DD BARY= calcule_barycentre();
435     ost<<BARY<<endl;
436     ost<<endl<<endl;
437     ost<<"TENSEUR_METRIQUE: "<<endl;
438     ost<<"========================================"<<endl;
439     OT_TENSEUR TNS_MT= calcule_tenseur_metrique() ;
440     ost<< TNS_MT<<endl;
441     ost<<endl<<endl;
442     ost<<"TENSEUR_DE_COVARIANCE: "<<endl;
443     ost<<"========================================"<<endl;
444     OT_TENSEUR TNS_CV= calcule_covariance();
445     ost<< TNS_CV<<endl;
446     ost<<endl<<endl;
447     ost<<"AXES_D'INERTIE: "<<endl;
448     ost<<"========================================"<<endl;
449     OT_VECTEUR_4DD D;
450     OT_TENSEUR V(4);
451     calcule_axes_dinertie(D,V);
452     ost<< V<<endl;
453     ost<<endl<<endl;
454     ost<<"INERTIE_CALCULÉE_AU_BARYCENTRE: "<<endl;
455     ost<<"========================================"<<endl;
456     OT_TENSEUR I_BARY=calcule_tenseur_inertie_au_barycentre();
457     ost<<I_BARY<<endl;
458    
459     ost<<endl<<endl;
460     ost<<"INERTIE_TRANSPORTÉE_EN_UN_POINT: "<<endl;
461     ost<<"========================================"<<endl;
462     OT_TENSEUR I_TRANSP=calcule_tenseur_inertie_au_pt(BARY);
463     ost<<I_TRANSP<<endl;
464     ost<<endl<<endl;
465    
466     ost<<"INERTIE_CALCULÉ_DANS_LA_BASE_LOCALE: "<<endl;
467     ost<<"========================================"<<endl;
468     OT_TENSEUR I_BASE=calcule_tenseur_inertie_base_locale();
469     ost<<I_BASE<<endl;
470     ost<<endl<<endl;
471     }
472    
473