ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/vct_arete.cpp
Revision: 66
Committed: Wed Mar 19 16:45:26 2008 UTC (17 years, 1 month ago) by souaissa
Original Path: magic/lib/geometrie/geometrie/src/vct_arete.cpp
File size: 11441 byte(s)
Log Message:
reorganisation des classes de vectorisation. Situation normalement final pour le doc de khaled

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