ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/REPOS_ERICCA/magic/lib/mtu/src/vct.cpp
Revision: 1158
Committed: Thu Jun 13 22:18:49 2024 UTC (11 months, 1 week ago) by francois
File size: 10227 byte(s)
Log Message:
compatibilité Ubuntu 22.04
Suppression des refeences à Windows
Ajout d'une banière

File Contents

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