ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/geometrie/src/vct.cpp
Revision: 283
Committed: Tue Sep 13 21:11:20 2011 UTC (13 years, 8 months ago) by francois
File size: 8916 byte(s)
Log Message:
structure de l'écriture

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