MAGiC  V5.0
Mailleurs Automatiques de Géometries intégrés à la Cao
vct.cpp
Aller à la documentation de ce fichier.
1 //####//------------------------------------------------------------
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 
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 
36 {
46 }
47 
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 
63 {
64  //
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  double2 zero=0.0;
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  {
79  OT_VECTEUR_3DD tmp(lst_points[i].get_x(),lst_points[i].get_y(),lst_points[i].get_z());
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  {
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);
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 
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 
205 {
206  return tnsmetrique;
207 }
208 
210 {
211  return tnsinertie4d;
212 }
213 
215 {
216  return tnsinertielocal4d;
217 }
218 
220 {
221  return axeslocaux4d;
222 }
223 
225 {
226  return barycentre4d;
227 }
229 {
230  return tnsinertie3d;
231 }
232 
234 {
235  return tnsinertielocal3d;
236 }
237 
239 {
240  return axeslocaux3d;
241 }
242 
244 {
245  return barycentre3d;
246 }
247 
248 
249 void VCT::enregistrer(std::ostream& ost)
250 {
251  ost<<"========================================"<<std::endl;
252  ost<<"POINTS_DE_CONTROLS: "<<std::endl;
253  ost<<"========================================"<<std::endl;
254 
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  ost<< v<<std::endl; // de la precision dans la classe doubleprecision
259  }
260  ost<<std::endl;
261 
262  ost<<"VECTEUR: "<<std::endl;
263  ost<<"========================================"<<std::endl;
264  for (unsigned int i=0;i< lst_vecteurs.size();i++)
265  {
267  ost<< v<<std::endl;
268  }
269  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 
301 
302 }
VCT::get_tenseur_metrique
virtual OT_TENSEUR * get_tenseur_metrique(void)
Definition: vct.cpp:204
VCT::get_points_controle
virtual std::vector< OT_VECTEUR_4DD > & get_points_controle(void)
Definition: vct.cpp:193
VCT::lst_points
std::vector< OT_VECTEUR_4DD > lst_points
Definition: vct.h:61
vct.h
VCT::tnsinertie4d
OT_TENSEUR * tnsinertie4d
Definition: vct.h:64
VCT::~VCT
~VCT()
Definition: vct.cpp:48
VCT::axeslocaux3d
OT_TENSEUR * axeslocaux3d
Definition: vct.h:70
OT_TENSEUR::get_orthogonalisation
virtual void get_orthogonalisation(OT_TENSEUR &a, OT_VECTEUR_4DD &d, OT_TENSEUR &v, int n, int &nrot)
Definition: ot_tenseur.cpp:612
OT_TENSEUR::transpose
virtual OT_TENSEUR transpose()
Definition: ot_tenseur.cpp:525
f2abs
double2 f2abs(double2 &val)
Definition: ot_doubleprecision.cpp:267
a
#define a(i, j)
VCT::construire_forme_tensorielle
void construire_forme_tensorielle(void)
Definition: vct.cpp:62
VCT::get_tenseur_inertie_base_locale_3d
virtual OT_TENSEUR * get_tenseur_inertie_base_locale_3d(void)
Definition: vct.cpp:233
VCT::VCT
VCT()
Definition: vct.cpp:31
VCT::get_barycentre_3d
virtual OT_VECTEUR_3DD * get_barycentre_3d(void)
Definition: vct.cpp:243
VCT::tnsinertielocal4d
OT_TENSEUR * tnsinertielocal4d
Definition: vct.h:65
VCT::get_nb_points
virtual int get_nb_points(void)
Definition: vct.cpp:186
double2
Definition: ot_doubleprecision.h:29
VCT::axeslocaux4d
OT_TENSEUR * axeslocaux4d
Definition: vct.h:66
VCT::get_vecteurs
virtual std::vector< OT_VECTEUR_4DD > & get_vecteurs(void)
Definition: vct.cpp:199
OT_TENSEUR
Definition: ot_tenseur.h:41
OT_VECTEUR_3DD
Definition: ot_mathematique.h:350
VCT::get_base_locale_4d
virtual OT_TENSEUR * get_base_locale_4d(void)
Definition: vct.cpp:219
VCT::get_tenseur_inertie_4d
virtual OT_TENSEUR * get_tenseur_inertie_4d(void)
Definition: vct.cpp:209
VCT::tnsmetrique
OT_TENSEUR * tnsmetrique
Definition: vct.h:63
VCT::lst_vecteurs
std::vector< OT_VECTEUR_4DD > lst_vecteurs
Definition: vct.h:62
VCT::tnsinertielocal3d
OT_TENSEUR * tnsinertielocal3d
Definition: vct.h:69
VCT::get_barycentre_4d
virtual OT_VECTEUR_4DD * get_barycentre_4d(void)
Definition: vct.cpp:224
VCT::enregistrer
virtual void enregistrer(std::ostream &ost)
Definition: vct.cpp:249
VCT::get_tenseur_inertie_base_locale_4d
virtual OT_TENSEUR * get_tenseur_inertie_base_locale_4d(void)
Definition: vct.cpp:214
VCT::get_base_locale_3d
virtual OT_TENSEUR * get_base_locale_3d(void)
Definition: vct.cpp:238
OT_VECTEUR_4DD
Definition: ot_mathematique.h:284
VCT::barycentre3d
OT_VECTEUR_3DD * barycentre3d
Definition: vct.h:71
VCT
Definition: vct.h:33
VCT::barycentre4d
OT_VECTEUR_4DD * barycentre4d
Definition: vct.h:67
VCT::get_tenseur_inertie_3d
virtual OT_TENSEUR * get_tenseur_inertie_3d(void)
Definition: vct.cpp:228
VCT::tnsinertie3d
OT_TENSEUR * tnsinertie3d
Definition: vct.h:68