ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/vct.cpp
Revision: 363
Committed: Thu Oct 18 22:12:03 2012 UTC (12 years, 6 months ago) by francois
File size: 9166 byte(s)
Log Message:
Mise a jour pour publi sur la comparaison

File Contents

# User Rev Content
1 francois 283 //---------------------------------------------------------------------------
2    
3     #pragma hdrstop
4    
5     #include "vct.h"
6     //---------------------------------------------------------------------------
7     #pragma package(smart_init)
8    
9    
10    
11    
12     VCT::VCT():tnsmetrique(NULL),tnsinertie4d(NULL),tnsinertielocal4d(NULL),axeslocaux4d(NULL),barycentre4d(NULL),tnsinertie3d(NULL),tnsinertielocal3d(NULL),axeslocaux3d(NULL),barycentre3d(NULL)
13     {
14     }
15    
16     VCT::VCT(VCT& mdd)
17     {
18     tnsmetrique=new OT_TENSEUR((*mdd.tnsmetrique));
19     tnsinertie4d=new OT_TENSEUR((*mdd.tnsinertie4d));
20     tnsinertielocal4d=new OT_TENSEUR((*mdd.tnsinertielocal4d));
21     axeslocaux4d=new OT_TENSEUR((*mdd.axeslocaux4d));
22     barycentre4d=new OT_VECTEUR_4DD((*mdd.barycentre4d));
23     tnsinertie3d=new OT_TENSEUR((*mdd.tnsinertie3d));
24     tnsinertielocal3d=new OT_TENSEUR((*mdd.tnsinertielocal3d));
25     axeslocaux3d=new OT_TENSEUR((*mdd.axeslocaux3d));
26     barycentre3d=new OT_VECTEUR_3DD((*mdd.barycentre3d));
27     }
28    
29     VCT::~VCT()
30     {
31     if (tnsmetrique!=NULL) delete tnsmetrique;
32     if (tnsinertie4d!=NULL) delete tnsinertie4d;
33     if (tnsinertielocal4d!=NULL) delete tnsinertielocal4d;
34     if (axeslocaux4d!=NULL) delete axeslocaux4d;
35     if (barycentre4d!=NULL) delete barycentre4d;
36     if (tnsinertie3d!=NULL) delete tnsinertie3d;
37     if (tnsinertielocal3d!=NULL) delete tnsinertielocal3d;
38     if (axeslocaux3d!=NULL) delete axeslocaux3d;
39     if (barycentre3d!=NULL) delete barycentre3d;
40     }
41    
42    
43     void VCT::construire_forme_tensorielle(void)
44     {
45 francois 363 //
46     double2 max=0.;
47     for (int i=0;i<lst_points.size();i++)
48     if (f2abs(lst_points[i].get_w())>max) max=f2abs(lst_points[i].get_w());
49     for (int i=0;i<lst_vecteurs.size();i++)
50     lst_vecteurs[i].change_w(lst_vecteurs[i].get_w()/max);
51    
52 francois 283 double2 zero=0.0;
53     // tenseur metrique
54     tnsmetrique=new OT_TENSEUR(lst_vecteurs);
55     // barycentre
56     barycentre4d=new OT_VECTEUR_4DD(zero,zero,zero,zero);
57     barycentre3d=new OT_VECTEUR_3DD(zero,zero,zero);
58     int nb_points=lst_points.size();
59     for (int i=0;i<nb_points;i++)
60     {
61     *barycentre4d=*barycentre4d+lst_points[i];
62     OT_VECTEUR_3DD tmp(lst_points[i].get_x(),lst_points[i].get_y(),lst_points[i].get_z());
63     *barycentre3d=*barycentre3d+tmp;
64     }
65     *barycentre4d=*barycentre4d/nb_points;
66     *barycentre3d=*barycentre3d/nb_points;
67     // tenseur d'inertie
68     OT_TENSEUR a(nb_points,4);
69     OT_TENSEUR b(nb_points,3);
70     for ( int i=0;i<nb_points;i++)
71     {
72     OT_VECTEUR_4DD pt=lst_points[i];
73     OT_VECTEUR_4DD ptcent=pt-(*barycentre4d);
74     for (int j=0;j<4;j++)
75     a(i,j)= ptcent[j];
76     OT_VECTEUR_3DD tmp(lst_points[i].get_x(),lst_points[i].get_y(),lst_points[i].get_z());
77     OT_VECTEUR_3DD ptcent2=tmp-(*barycentre3d);
78     for (int j=0;j<3;j++)
79     b(i,j)= ptcent2[j];
80     }
81     OT_TENSEUR at=a.transpose();
82     OT_TENSEUR bt=b.transpose();
83     OT_TENSEUR covariance(4,4);
84     OT_TENSEUR covariance2(3,3);
85     covariance=at*a;
86     covariance2=bt*b;
87     double2 unsurnb_points2(1./nb_points);
88     double2 nb_points2(nb_points);
89     covariance=covariance*unsurnb_points2;
90     covariance2=covariance2*unsurnb_points2;
91     tnsinertie4d=new OT_TENSEUR(4,4);
92     tnsinertie3d=new OT_TENSEUR(3,3);
93     *tnsinertie4d=covariance;
94     *tnsinertie3d=covariance2;
95     double2 un(-1.);
96     *tnsinertie4d=un*(*tnsinertie4d);
97     *tnsinertie4d=nb_points2*(*tnsinertie4d);
98     (*tnsinertie4d)(0,0)=((covariance)(1,1)+(covariance)(2,2)+(covariance)(3,3))*nb_points2;
99     (*tnsinertie4d)(1,1)=((covariance)(0,0)+(covariance)(2,2)+(covariance)(3,3))*nb_points2;
100     (*tnsinertie4d)(2,2)=((covariance)(0,0)+(covariance)(1,1)+(covariance)(3,3))*nb_points2;
101     (*tnsinertie4d)(3,3)=((covariance)(0,0)+(covariance)(1,1)+(covariance)(2,2))*nb_points2;
102     *tnsinertie3d=un*(*tnsinertie3d);
103     *tnsinertie3d=nb_points2*(*tnsinertie3d);
104     (*tnsinertie3d)(0,0)=((covariance)(1,1)+(covariance)(2,2))*nb_points2;
105     (*tnsinertie3d)(1,1)=((covariance)(0,0)+(covariance)(2,2))*nb_points2;
106     (*tnsinertie3d)(2,2)=((covariance)(0,0)+(covariance)(1,1))*nb_points2;
107     //axe d'inertie
108     if ((covariance)(0,0)==zero && (covariance)(1,0)==zero && (covariance)(2,0)==zero && (covariance)(3,0)==zero)
109     {
110     (covariance)(0,0)=1.0;
111     (covariance)(1,0)=zero;
112     (covariance)(2,0)=zero;
113     (covariance)(3,0)=zero;
114     }
115     if ((covariance)(0,1)==zero && (covariance)(1,1)==zero && (covariance)(2,1)==zero && (covariance)(3,1)==zero)
116     {
117     (covariance)(0,1)=zero;
118     (covariance)(1,1)=1.0;
119     (covariance)(2,1)=zero;
120     (covariance)(3,1)=zero;
121     }
122     if ((covariance)(0,2)==zero && (covariance)(1,2)==zero && (covariance)(2,2)==zero && (covariance)(3,2)==zero)
123     {
124     (covariance)(0,2)=zero;
125     (covariance)(1,2)=zero;
126     (covariance)(2,2)=1.0;
127     (covariance)(3,2)=zero;
128     }
129     if ((covariance)(0,3)==zero && (covariance)(1,3)==zero && (covariance)(2,3)==zero && (covariance)(3,3)==zero)
130     {
131     (covariance)(0,3)=zero;
132     (covariance)(1,3)=zero;
133     (covariance)(2,3)=zero;
134     (covariance)(3,3)=1.0;
135     }
136     if ((covariance2)(0,0)==zero && (covariance2)(1,0)==zero && (covariance2)(2,0)==zero )
137     {
138     (covariance2)(0,0)=1.0;
139     (covariance2)(1,0)=zero;
140     (covariance2)(2,0)=zero;
141     }
142     if ((covariance2)(0,1)==zero && (covariance2)(1,1)==zero && (covariance2)(2,1)==zero )
143     {
144     (covariance2)(0,1)=zero;
145     (covariance2)(1,1)=1.0;
146     (covariance2)(2,1)=zero;
147     }
148     if ((covariance2)(0,2)==zero && (covariance2)(1,2)==zero && (covariance2)(2,2)==zero )
149     {
150     (covariance2)(0,2)=zero;
151     (covariance2)(1,2)=zero;
152     (covariance2)(2,2)=1.0;
153     }
154     int nrot;
155     OT_VECTEUR_4DD D;
156     axeslocaux4d=new OT_TENSEUR(4,4);
157     axeslocaux3d=new OT_TENSEUR(3,3);
158     covariance.get_orthogonalisation(covariance,D,*axeslocaux4d,4,nrot);
159     covariance.get_orthogonalisation(covariance2,D,*axeslocaux3d,3,nrot);
160     OT_TENSEUR axest=axeslocaux4d->transpose();
161     OT_TENSEUR axest2=axeslocaux3d->transpose();
162     tnsinertielocal4d=new OT_TENSEUR(4,4);
163     *tnsinertielocal4d=axest*(*tnsinertie4d);
164     *tnsinertielocal4d=(*tnsinertielocal4d)*(*axeslocaux4d);
165     tnsinertielocal3d=new OT_TENSEUR(3,3);
166     *tnsinertielocal3d=axest2*(*tnsinertie3d);
167     *tnsinertielocal3d=(*tnsinertielocal3d)*(*axeslocaux3d);
168     }
169    
170    
171     int VCT::get_nb_points(void)
172     {
173     return lst_points.size();
174     }
175    
176    
177    
178     std::vector<OT_VECTEUR_4DD>& VCT::get_points_controle(void)
179     {
180     return lst_points;
181     }
182    
183    
184     std::vector<OT_VECTEUR_4DD> & VCT::get_vecteurs()
185     {
186     return lst_vecteurs;
187     }
188    
189     OT_TENSEUR* VCT::get_tenseur_metrique(void)
190     {
191     return tnsmetrique;
192     }
193    
194     OT_TENSEUR* VCT::get_tenseur_inertie_4d(void)
195     {
196     return tnsinertie4d;
197     }
198    
199     OT_TENSEUR* VCT::get_tenseur_inertie_base_locale_4d(void)
200     {
201     return tnsinertielocal4d;
202     }
203    
204     OT_TENSEUR* VCT::get_base_locale_4d(void)
205     {
206     return axeslocaux4d;
207     }
208    
209     OT_VECTEUR_4DD* VCT::get_barycentre_4d(void)
210     {
211     return barycentre4d;
212     }
213     OT_TENSEUR* VCT::get_tenseur_inertie_3d(void)
214     {
215     return tnsinertie3d;
216     }
217    
218     OT_TENSEUR* VCT::get_tenseur_inertie_base_locale_3d(void)
219     {
220     return tnsinertielocal3d;
221     }
222    
223     OT_TENSEUR* VCT::get_base_locale_3d(void)
224     {
225     return axeslocaux3d;
226     }
227    
228     OT_VECTEUR_3DD* VCT::get_barycentre_3d(void)
229     {
230     return barycentre3d;
231     }
232    
233    
234     void VCT::enregistrer(std::ostream& ost)
235     {
236     ost<<"========================================"<<endl;
237     ost<<"POINTS_DE_CONTROLS: "<<endl;
238     ost<<"========================================"<<endl;
239    
240     for (unsigned int i=0;i< lst_points.size();i++)
241     {
242     OT_VECTEUR_4DD v= lst_points[i]; // Rmq: la precision n�est pas affocher, il faut rajouter l'affichage
243     ost<< v<<endl; // de la precision dans la classe doubleprecision
244     }
245     ost<<endl;
246    
247     ost<<"VECTEUR: "<<endl;
248     ost<<"========================================"<<endl;
249     for (unsigned int i=0;i< lst_vecteurs.size();i++)
250     {
251     OT_VECTEUR_4DD v= lst_vecteurs[i];
252     ost<< v<<endl;
253     }
254     ost<<endl;
255     ost<<endl<<endl;
256     ost<<"BARYCENTRE: "<<endl;
257     ost<<"========================================"<<endl;
258     ost<< "---4D :" << *barycentre4d <<endl;
259     ost<< "---3D :" << *barycentre3d <<endl;
260     ost<<endl<<endl;
261     ost<<"TENSEUR_METRIQUE: "<<endl;
262     ost<<"========================================"<<endl;
263     ost<< *tnsmetrique<<endl;
264     ost<<endl<<endl;
265     ost<<"AXES_D'INERTIE: "<<endl;
266     ost<<"========================================"<<endl;
267     ost<< "-----4D-----" << endl;
268     ost<< *axeslocaux4d <<endl;
269     ost<< "-----3D-----" << endl;
270     ost<< *axeslocaux3d <<endl;
271     ost<<endl<<endl;
272     ost<<"INERTIE_CALCULEE_AU_BARYCENTRE: "<<endl;
273     ost<<"========================================"<<endl;
274     ost<< "-----4D-----" << endl;
275     ost<< *tnsinertie4d <<endl;
276     ost<< "-----3D-----" << endl;
277     ost<< *tnsinertie3d <<endl;
278     ost<<endl<<endl;
279     ost<<"INERTIE_CALCULE_DANS_LA_BASE_LOCALE: "<<endl;
280     ost<<"========================================"<<endl;
281     ost<< "-----4D-----" << endl;
282     ost<< *tnsinertielocal4d <<endl;
283     ost<< "-----3D-----" << endl;
284     ost<< *tnsinertielocal3d <<endl;
285    
286    
287     }