ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/vct_arete.cpp
Revision: 67
Committed: Tue Mar 25 15:59:01 2008 UTC (17 years, 1 month ago) by souaissa
Original Path: magic/lib/geometrie/geometrie/src/vct_arete.cpp
File size: 10903 byte(s)
Log Message:
mise en conformité des noms de topologies dans la vectorisation

File Contents

# User Rev Content
1 souaissa 66 //---------------------------------------------------------------------------
2     #include "gestionversion.h"
3     //---------------------------------------------------------------------------
4    
5    
6     #pragma hdrstop
7     #include "vct_arete.h"
8     #include "vct_courbe.h"
9     #include "mg_courbe.h"
10     #include "mg_arete.h"
11     #include <iomanip.h>
12     #include "ot_mathematique.h"
13     //---------------------------------------------------------------------------
14    
15     #pragma package(smart_init)
16    
17    
18    
19     VCT_ARETE::VCT_ARETE(MG_ARETE* arete):VCT_ELEMENT_TOPOLOGIQUE(arete)
20     {
21     double2 ZERO=0.;
22    
23 souaissa 67
24 souaissa 66 MG_COURBE* courbe=arete->get_courbe();
25     VCT_COURBE vct_crb(courbe);
26     arete->get_param_NURBS(indx_premier_ptctr,nurbs_params);
27     nb_topo_points=1/4.*(nurbs_params.get_nb()-indx_premier_ptctr);
28 souaissa 67 //nb_geo_points= vct_crb.get_nb_points();
29 souaissa 66
30 souaissa 67
31 souaissa 66 double2 X1,Y1,Z1,w1,X2,Y2,Z2,w2,vx,vy,vz,w;
32    
33    
34    
35     for(int s=0;s<nb_topo_points-1;s++)
36     {
37     X1=nurbs_params.get(indx_premier_ptctr+ 4 * s);
38     Y1=nurbs_params.get(indx_premier_ptctr+ 4 * s + 1);
39     Z1=nurbs_params.get(indx_premier_ptctr+ 4 * s + 2);
40     w1=nurbs_params.get(indx_premier_ptctr+ 4 * s + 3);
41    
42     X2=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1));
43     Y2=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1) + 1);
44     Z2=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1) + 2);
45     w2=nurbs_params.get(indx_premier_ptctr+ 4 * (s + 1) + 3);
46    
47     vx=X2-X1;
48     vy=Y2-Y1;
49     vz=Z2-Z1;
50     w=w2-w1;
51    
52     double2 norm_au_carre=vx*vx+vy*vy+vz*vz+w*w;
53     double2 norm=norm_au_carre^0.5;
54    
55 souaissa 67
56 souaissa 66 if(norm!=ZERO){
57     vx=vx/norm;
58     vy=vy/norm;
59     vz=vz/norm;
60     w=w/norm;
61     double2 eps=1e-6;
62     if(fabs(vx)<eps) vx=0;
63     if(fabs(vy)<eps) vy=0;
64     if(fabs(vz)<eps) vz=0;
65     if(fabs(w)<eps) w=0;
66     LISTE_TOPO_VECTEUR_ARETE.insert(LISTE_TOPO_VECTEUR_ARETE.end(),vx);
67     LISTE_TOPO_VECTEUR_ARETE.insert(LISTE_TOPO_VECTEUR_ARETE.end(),vy);
68     LISTE_TOPO_VECTEUR_ARETE.insert(LISTE_TOPO_VECTEUR_ARETE.end(),vz);
69     LISTE_TOPO_VECTEUR_ARETE.insert(LISTE_TOPO_VECTEUR_ARETE.end(),w);
70     }
71    
72     }
73    
74    
75 souaissa 67 //vct_crb.get_vectorisation(LISTE_GEO_VECTEUR_ARETE);
76 souaissa 66
77     }
78    
79     VCT_ARETE::VCT_ARETE(VCT_ARETE& mdd):VCT_ELEMENT_TOPOLOGIQUE(mdd.elem_topo)
80     {
81     LISTE_TOPO_VECTEUR_ARETE= mdd.LISTE_TOPO_VECTEUR_ARETE;
82 souaissa 67 //LISTE_GEO_VECTEUR_ARETE=mdd.LISTE_GEO_VECTEUR_ARETE;
83 souaissa 66 nurbs_params=mdd.nurbs_params;
84 souaissa 67 //nb_geo_points=mdd.nb_geo_points;
85     nb_topo_points=mdd.nb_topo_points;
86 souaissa 66 }
87    
88    
89     VCT_ARETE::~ VCT_ARETE()
90     {
91 souaissa 67
92 souaissa 66 }
93 souaissa 67 /*
94 souaissa 66 void VCT_ARETE::get_geo_vectorisation(vector<double2>& lst)
95     {
96     lst=LISTE_GEO_VECTEUR_ARETE;
97 souaissa 67 } */
98 souaissa 66
99     void VCT_ARETE::get_topo_vectorisation(vector<double2>& lst)
100     {
101     lst=LISTE_TOPO_VECTEUR_ARETE;
102     }
103    
104    
105 souaissa 67 /*
106 souaissa 66 void VCT_ARETE:: get_geo_barycentre(double2* xyz)
107     {
108     MG_COURBE* courbe=((MG_ARETE*)elem_topo)->get_courbe();
109     VCT_COURBE vct_crb(courbe);
110     vct_crb.get_geo_barycentre(xyz);
111     }
112 souaissa 67 */
113 souaissa 66
114    
115     void VCT_ARETE::get_topo_barycentre(double2* xyz)
116     {
117     xyz[0]=0.;
118     xyz[1]=0.;
119     xyz[2]=0.;
120     xyz[3]=0.;
121    
122    
123     for(int i=0;i<nb_topo_points;i++)
124     {
125     xyz[0]=xyz[0]+nurbs_params.get(4*i+indx_premier_ptctr);
126     xyz[1]=xyz[1]+nurbs_params.get(4*i+indx_premier_ptctr+1);
127     xyz[2]=xyz[2]+nurbs_params.get(4*i+indx_premier_ptctr+2);
128     xyz[3]=xyz[3]+nurbs_params.get(4*i+indx_premier_ptctr+3);
129     }
130    
131     xyz[0]=1./nb_topo_points*xyz[0];
132     xyz[1]=1./nb_topo_points*xyz[1];
133     xyz[2]=1./nb_topo_points*xyz[2];
134 souaissa 67 xyz[3]=1./nb_topo_points*xyz[3];
135 souaissa 66 }
136    
137    
138     double2 VCT_ARETE::get_inertie_au_centre_de_masse()
139     {
140     double2 xyz_g[4];
141     double2 xyzi[4];
142     this->get_topo_barycentre(xyz_g);
143    
144     xyzi[0]=0.;
145     xyzi[1]=0.;
146     xyzi[2]=0.;
147     xyzi[3]=0.;
148    
149    
150     double2 moment_inertie=0.;
151     for(int i=0;i<nb_topo_points;i++)
152     {
153     xyzi[0]=xyz_g[0]-nurbs_params.get(4*i+indx_premier_ptctr);
154     xyzi[1]=xyz_g[1]-nurbs_params.get(4*i+indx_premier_ptctr+1);
155     xyzi[2]=xyz_g[2]-nurbs_params.get(4*i+indx_premier_ptctr+2);
156     xyzi[3]=xyz_g[3]-nurbs_params.get(4*i+indx_premier_ptctr+3);
157     moment_inertie=moment_inertie+xyzi[0]*xyzi[0]+xyzi[1]*xyzi[1]+xyzi[2]*xyzi[2]+xyzi[3]*xyzi[3];
158     }
159     return moment_inertie;
160     }
161    
162    
163    
164    
165     double2 VCT_ARETE:: get_inertie_au_point(double2* xyz)
166     {
167     double2 centre_de_masse[4];
168     double2 inertie_au_point_xyz;
169    
170    
171     double2 inertie_au_centre_de_masse=get_inertie_au_centre_de_masse();
172    
173     this->get_topo_barycentre(centre_de_masse);
174    
175     double2 d_x=xyz[0]-centre_de_masse[0] ;
176     double2 d_y=xyz[1]-centre_de_masse[1] ;
177     double2 d_z=xyz[2]-centre_de_masse[2] ;
178     double2 d_w=xyz[3]-centre_de_masse[3] ;
179    
180     double2 dis_GXYZ=d_x*d_x+d_y*d_y+d_z*d_z+d_w*d_w;
181    
182     inertie_au_point_xyz=inertie_au_centre_de_masse+nb_topo_points*dis_GXYZ;
183    
184     return inertie_au_point_xyz;
185     }
186    
187    
188    
189     void VCT_ARETE::get_covariance(double2* cov)
190     {
191    
192     double2 baryc[4];
193     get_topo_barycentre(baryc);
194     double2 *pt_au_centre_masse=new double2[nb_topo_points*3] ;
195    
196     for(int k=0;k<nb_topo_points;k++)
197     {
198     for(int j=0;j<3;j++){
199     double2 xjk= nurbs_params.get(4*k+indx_premier_ptctr+j); //arete
200     pt_au_centre_masse[k*3+j]=xjk- baryc[j];
201     }
202     }
203     // la cov= 1/nb* transpose(pt_au_centre_masse)*(pt_au_centre_masse);
204     for(int i=0;i<9;i++)cov[i]=0.;
205    
206     for(int k=0;k<nb_topo_points;k++)
207     {
208     cov[0*3+0]= cov[0*3+0]+pt_au_centre_masse[k*3+0]*pt_au_centre_masse[k*3+0];
209     cov[0*3+1]= cov[0*3+1]+pt_au_centre_masse[k*3+0]*pt_au_centre_masse[k*3+1];
210     cov[0*3+2]= cov[0*3+2]+pt_au_centre_masse[k*3+0]*pt_au_centre_masse[k*3+2];
211     cov[1*3+1]= cov[1*3+1]+pt_au_centre_masse[k*3+1]*pt_au_centre_masse[k*3+1];
212     cov[1*3+2]= cov[1*3+2]+pt_au_centre_masse[k*3+1]*pt_au_centre_masse[k*3+2];
213     cov[2*3+2]= cov[2*3+2]+pt_au_centre_masse[k*3+2]*pt_au_centre_masse[k*3+2];
214     }
215    
216     cov[1*3+0]=cov[0*3+1] ;
217     cov[2*3+0]=cov[0*3+2] ;
218     cov[2*3+1]=cov[1*3+2] ;
219    
220     for(int i=0;i<9;i++) cov[i]=1./nb_topo_points*cov[i];
221     delete [] pt_au_centre_masse;
222    
223    
224     }
225    
226    
227    
228    
229    
230     void VCT_ARETE:: get_tenseur_inertie_au_cm(double2* tens)
231     {
232     double2 cov[9] ;
233     get_covariance(cov) ;
234     for(int i=0;i<9;i++) tens[i]=cov[i]*nb_topo_points;
235    
236     tens[0]=cov[4]+cov[8];
237     tens[4]=cov[0]+cov[8];
238     tens[8]=cov[0]+cov[4];
239    
240     for(int i=0;i<3;i++) {
241     for(int j=0;j<3;j++) {
242     if(i!=j)
243     tens[i*3+j]=-1*tens[i*3+j]; }
244     }
245     }
246    
247     void VCT_ARETE::get_tenseur_inertie_au_pt(double2* xyz, double2* tens)
248     {
249     double2 tens1[9];
250     double2 centre_de_masse[4] ;
251     get_tenseur_inertie_au_cm(tens1);
252    
253     double2 a=xyz[0]-centre_de_masse[0] ;
254     double2 b=xyz[1]-centre_de_masse[1] ;
255     double2 c=xyz[2]-centre_de_masse[2] ;
256    
257     tens[0]=tens1[0]+b*b+c*c;
258     tens[4]=tens1[0]+a*a+c*c;
259     tens[8]=tens1[0]+a*a+b*b;
260    
261     tens[1]=tens1[0]-a*b;
262     tens[2]=tens1[0]-a*c;
263     tens[3]=tens1[1];
264     tens[5]=tens1[0]-b*c;
265     tens[6]=tens1[2];
266     tens[7]=tens1[5];
267    
268     }
269    
270    
271     void VCT_ARETE::get_tenseur_inertie_base_locale(double2* tens_loc)
272     {
273     // inertie calculé dans le repere globale
274     double2 cov[9] ;
275     double2 tens_glo[9] ;
276     get_covariance(cov) ;
277     get_tenseur_inertie_au_cm(tens_glo);
278    
279     for(int i=0;i<3;i++) {
280     for(int j=0;j<3;j++) {
281     tens_loc[i*3+j]=0.;
282     for(int k=0;k<3;k++){
283     for(int h=0;h<3;h++) {
284     tens_loc[i*3+j]=tens_loc[i*3+j]+cov[k*3+i]*tens_glo[k*3+h]*cov[h*3+j];
285     }}}
286     }
287     }
288    
289     ostream& operator <<(ostream& os,const VCT_ARETE& vct_art)
290     {
291     VCT_ARETE& vct=(VCT_ARETE&)vct_art;
292     vct.enregistrer(os) ;
293     return os;
294     }
295    
296     void VCT_ARETE::get_axes_dinertie(OT_VECTEUR_3D& vp1,OT_VECTEUR_3D& vp2,OT_VECTEUR_3D& vp3)
297     {
298    
299     }
300    
301    
302     int VCT_ARETE::get_nb_topo_points()
303     {
304     return nb_topo_points;
305     }
306    
307 souaissa 67 /*
308 souaissa 66 int VCT_ARETE::get_nb_geo_points()
309     {
310     return nb_geo_points;
311 souaissa 67 } */
312 souaissa 66
313     /*
314     void VCT_ARETE::enregistrer(ostream& o)
315     {
316     int compt=0;
317    
318     // o<<"%%"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"POINTS_CONTROL_COURBE,"<< endl;
319     // MG_COURBE* courbe=((MG_ARETE*)elem_topo)->get_courbe();
320     // VCT_COURBE vct_crb(courbe);
321     // vct_crb.enregistrer(o) ;
322    
323     o<<setfill('=')<<setw(99)<<'='<<endl;
324     o<<"(*)"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"POINTS_CONTROL_ARETE,"<< endl;
325     o<<setfill('=')<<setw(99)<<'='<<endl;
326    
327    
328     for(int i=indx_premier_ptctr;i<nurbs_params.get_nb();i++)
329     {
330     o<<setfill(' ')<<setw(15)<<nurbs_params.get(i);
331     compt++;
332     if(compt==4) {
333     o<<endl;
334     compt=0;}
335     }
336     o<<setfill('=')<<setw(99)<<'='<<endl;
337    
338     /*
339     o<<"(*)"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"POLYGONE_DE_CONTROL_ARETE,"<<endl;
340     o<<setfill('=')<<setw(99)<<'='<<endl;
341     compt=0;
342    
343     for(unsigned int i=0;i<LISTE_TOPO_VECTEUR_ARETE.size();i++)
344     {
345     o<<setfill(' ')<<setw(15)<<LISTE_TOPO_VECTEUR_ARETE[i];
346     compt++;
347     if(compt==4) {
348     o<<endl;
349     compt=0;}
350     }
351     o<<setfill('=')<<setw(99)<<'='<<endl; /
352    
353     double2 cmasse[4];
354     get_topo_barycentre(cmasse) ;
355     o<<"(*)"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"CENTRE DE MASSE: "<<endl;
356     o<<setfill('=')<<setw(99)<<'='<<endl;
357    
358     for(unsigned int i=0;i<4;i++)
359     {
360     o<<setfill(' ')<<setw(15)<<cmasse[i]<<endl;
361     }
362     o<<setfill('=')<<setw(99)<<'='<<endl; /*
363     double2 inert_cm=get_inertie_au_centre_de_masse();
364     o<<"(*)"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"INERTIE AU CM: "<<endl;
365     o<<setfill('=')<<setw(99)<<'='<<endl;
366     o<< inert_cm<<endl;
367     o<<setfill('=')<<setw(99)<<'='<<endl;
368     double2 cov[9];
369    
370     get_covariance(cov) ;
371     o<<"%%"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"MATRICE DE COV: "<<endl;
372     o<<setfill('=')<<setw(99)<<'='<<endl;
373     for(unsigned int i=0;i<3;i++)
374     {
375     for(unsigned int j=0;j<3;j++)
376     o<<setfill(' ')<<setw(15)<<cov[3*i+j] ;
377     o<<endl;
378     }
379     o<<setfill('=')<<setw(99)<<'='<<endl;
380     OT_VECTEUR_3D v1,v2,v3;
381     o<<"(*)"<<((MG_ARETE*)elem_topo)->get_id()<<"="<<"AXES D INERTIE: "<<endl;
382     get_axes_dinertie(v1,v2,v3) ;
383     o<<setfill('=')<<setw(99)<<'='<<endl;
384     for(unsigned int j=0;j<3;j++)
385    
386     o<<setfill(' ')<<setw(15)<<v1[j]<<setfill(' ')<<setw(15)<<v2[j]<<setfill(' ')<<setw(15)<<v3[j]<<endl;
387    
388     o<<setfill('=')<<setw(99)<<'='<<endl; /
389     } */
390    
391    
392    
393     void VCT_ARETE::enregistrer(ostream& o)
394     {
395     // o<<"ARETE__"<<((MG_ARETE*)elem_topo)->get_id()<<" : ";
396     // o<<"__CTRS_PTS"<<endl;
397     // int cmpt=0;
398     /*
399     for(int i=indx_premier_ptctr;i<nurbs_params.get_nb();i++)
400     {
401     //if(cmpt!=3)
402     o<<setprecision(9)<<nurbs_params.get(i)<<" ; ";
403     //cmpt++;
404     //if(cmpt==4) cmpt=0;
405    
406     }
407     */
408     o<<endl; /*
409     o<<"__VECTORISATION"<<endl;
410     cmpt=0 ;
411     for(unsigned int i=0;i<LISTE_TOPO_VECTEUR_ARETE.size();i++)
412     {
413     o<<setfill(' ')<<setw(15)<<LISTE_TOPO_VECTEUR_ARETE[i];
414     cmpt++;
415     if(cmpt==4) {
416     o<<endl;
417     cmpt=0;}
418     } */
419     }
420