00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef MC_MATRIX_N_H_
00020 # define MC_MATRIX_N_H_
00021
00022
00023 #include <MC_double_vector.hpp>
00024
00025 #include <iostream>
00026
00027
00028
00029 namespace mesh_conv
00030 {
00031
00032 class MC_int_vector;
00033 class MC_v3d;
00034 class MC_v4d;
00035 class MC_v3d_vector;
00036
00037
00044
00045
00048 class MC_matrix
00049 {
00050 public:
00051
00052
00053
00054
00055
00056
00057
00058
00060 MC_matrix();
00062 MC_matrix(const int& size_col,const int& size_row);
00064 MC_matrix(const int& size_col);
00066 MC_matrix(const MC_matrix& size_row);
00068 MC_matrix(const MC_v3d& v);
00070 MC_matrix(const MC_v3d& v1,const MC_v3d& v2);
00072 MC_matrix(const MC_v3d& v1,const MC_v3d& v2,const MC_v3d& v3);
00074 MC_matrix(const MC_v3d_vector& v);
00076 MC_matrix(const MC_double_vector& column);
00077
00078
00080 ~MC_matrix();
00081
00082
00083
00084
00085
00086
00087
00088
00089
00092 void check_integrity() const;
00093
00095 MC_matrix& clear();
00096
00098 int size_1() const;
00100 int size_2() const;
00102 MC_int_vector size() const;
00104 int size_vec() const;
00105
00106
00108 MC_matrix& resize(const MC_int_vector& new_size) ;
00110 MC_matrix& resize(const int& size_1,const int& size_2=-1) ;
00112 MC_matrix& resize_1(const int& size_1) ;
00114 MC_matrix& resize_2(const int& size_2) ;
00115
00116
00118 MC_matrix reshaped_1(const int& size_1) const;
00120 MC_matrix reshaped_2(const int& size_2) const;
00122 MC_matrix reshaped(const MC_int_vector& new_size) const;
00124 MC_matrix reshaped(const int& new_size_1,const int& new_size_2) const;
00125
00129 MC_matrix repmat(const int& k_repeat) const ;
00131 MC_matrix repmat(const int& k_repeat_1,const int& k_repeat_2) const ;
00133 MC_matrix repmat(const MC_int_vector& k_repeat) const ;
00135 MC_matrix repmat_1(const int& k_repeat_1) const ;
00137 MC_matrix repmat_2(const int& k_repeat_2) const ;
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00151 MC_matrix& set_block(const MC_int_vector& index_1,const MC_int_vector& index_2,const MC_matrix& block);
00155 MC_matrix& set_block(const int& start_x,const int& end_x,const int& start_y,const int& end_y,const MC_matrix& block);
00156
00158 const double& to_double() const;
00160 const MC_double_vector& to_vec () const;
00161
00163 MC_matrix& add_row(const MC_v3d& x0) ;
00165 MC_matrix& add_row(const MC_v3d& x0,const MC_v3d& x1) ;
00167 MC_matrix& add_row(const MC_v3d& x0,const MC_v3d& x1,const MC_v3d& x2);
00169 MC_matrix& add_row(const MC_double_vector& col);
00173 MC_matrix& set_row(const int& id_row,const MC_double_vector& row);
00175 MC_double_vector get_row(const int& k_index) const;
00176
00177
00178
00180 MC_matrix& add_col(const MC_v3d& x0);
00182 MC_matrix& add_col(const MC_v3d& x0,const MC_v3d& x1);
00184 MC_matrix& add_col(const MC_v3d& x0,const MC_v3d& x1,const MC_v3d& x2);
00186 MC_matrix& add_col(const MC_double_vector& col);
00187
00192 MC_matrix& set_col(const int& id_col,const MC_double_vector& col);
00194 MC_double_vector get_col(const int& k_index) const;
00195
00197 MC_matrix to_matrix4() const;
00200 std::pair <MC_matrix,MC_v3d> to_matrix3() const;
00201
00202
00203
00204
00205
00206
00207
00208
00210 static MC_matrix zeros(const int& size_1,const int& size_2);
00212 static MC_matrix zeros(const int& size);
00213
00215 static MC_matrix identity(const int& size);
00216
00222 static MC_matrix rotation_axis_to_axis(const MC_v3d& a1,const MC_v3d& a2);
00223
00230 static MC_matrix rotation_registration(const MC_matrix& X,const MC_matrix& X0);
00231
00236 static MC_matrix rotation(const MC_v3d& axis,const double& angle);
00242 static std::pair <MC_matrix,std::vector<MC_matrix> > rotation_axis_to_axis_with_gradient(const MC_v3d& a0,const MC_v3d& a1);
00243
00245 static MC_matrix translation(const MC_v3d& tr);
00246
00248 static MC_matrix scaling(const double& s);
00250 static MC_matrix scaling(const double& sx,const double& sy,const double& sz);
00251
00252
00253
00254
00255
00256
00257
00259 MC_matrix transposed() const;
00260
00263 MC_matrix inverted() const;
00264
00265
00266
00269 double norm_2() const;
00270
00271
00272
00273
00274
00277 MC_matrix log_m(int *error_bit=0) const;
00278
00279
00280
00281
00283 MC_matrix pow_m(const int& k_pow) const;
00284
00288 MC_matrix exp_m() const;
00289
00290
00296 MC_matrix lsqr_invert() const;
00297
00302 std::pair<MC_matrix,MC_matrix> polar_decomposition() const;
00303
00308 static std::pair<std::vector <MC_matrix>,std::vector <MC_matrix> > polar_decomposition(const std::vector <MC_matrix>& v_m);
00309
00310
00312 double trace() const;
00313
00314
00316 static MC_matrix kronecker(const MC_double_vector& v1,const MC_double_vector& v2);
00317
00318
00319
00322 MC_matrix componentwise(const MC_matrix& M1) const;
00323
00324
00325
00326
00328 MC_matrix& operator+=(const double& a);
00330 MC_matrix& operator+=(const MC_matrix& M);
00332 MC_matrix& operator*=(const double& a);
00334 MC_matrix& operator/=(const double& a);
00335
00336
00337
00339 friend MC_matrix operator+(const MC_matrix& M1,const double& alpha);
00341 friend MC_matrix operator+(const double& alpha,const MC_matrix& M1);
00343 friend MC_matrix operator+(const MC_matrix& M1,const MC_matrix& M2);
00344
00345
00347 friend MC_matrix operator-(const MC_matrix& M1,const double& alpha);
00349 friend MC_matrix operator-(const double& alpha,const MC_matrix& M1);
00351 friend MC_matrix operator-(const MC_matrix& M1,const MC_matrix& M2);
00352
00354 friend MC_matrix operator*(const MC_matrix& M1,const double& alpha);
00356 friend MC_matrix operator*(const double& alpha,const MC_matrix& M1);
00358 friend MC_matrix operator*(const MC_matrix& M1,const MC_matrix& M2);
00360 friend MC_matrix operator*(const MC_matrix& M1,const MC_v3d& V);
00362 friend MC_double_vector operator*(const MC_matrix& M1,const MC_double_vector& v);
00363
00367 MC_matrix& operator*=(const MC_matrix& M1);
00368
00369
00370
00372 friend MC_matrix operator/(const MC_matrix& M1,const double& alpha);
00374 friend MC_matrix operator/(const double& alpha,const MC_matrix& M1);
00375
00381 void internal_product(MC_v3d* to_multiply) const;
00387 void internal_product(MC_v4d* to_multiply) const;
00388
00390 MC_matrix& add_translation(const MC_v3d& tr);
00391
00392
00393
00394
00395
00396
00397
00399 double& operator()(const int& k1,const int& k2);
00401 const double& operator()(const int& k1,const int& k2) const;
00405 double& operator()(const int& k_index);
00409 const double& operator()(const int& k_index) const;
00413 MC_matrix operator()(const MC_int_vector& k_index);
00414
00418 MC_matrix operator()(const MC_int_vector& index_1,const MC_int_vector& index_2) const;
00422 MC_matrix operator()(const std::string& string_index_1,const std::string& string_index_2);
00425 MC_matrix operator()(const std::string& string_index);
00426
00429 MC_v3d translation_part() const;
00430
00432 MC_matrix& set_translation(const MC_v3d& tr);
00433
00435 MC_matrix& set_rotation(const MC_matrix& m);
00436
00439 const double* pointer() const;
00440
00441
00442
00443
00444
00445
00446
00447
00449 friend std::ostream& operator << (std::ostream& stream,const MC_matrix& _M);
00450
00452 std::string to_string() const;
00453
00455 static MC_matrix transformation(const std::string& input);
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465 static std::pair<MC_v3d,MC_v3d> tensor_to_axes(const MC_matrix& T);
00466
00467 static MC_matrix axes_to_tensor(const MC_v3d& e0,const MC_v3d& e1);
00468
00469
00470 private:
00471
00475 void analyse_string(const std::string& to_analyse,int dim,int *start,double *increment,int *end) const;
00477 void analyse_string(const char* to_analyse,int dim,int *start,double *increment,int *end) const;
00478
00479
00480 protected:
00481
00483 MC_double_vector M;
00484
00487 int current_size[2];
00488
00489 };
00490
00491 }
00492
00493
00494 #endif