00001 #ifndef __INSTANTIO_MATRIX3_H
00002 #define __INSTANTIO_MATRIX3_H
00003
00004 #ifdef _MSC_VER
00005 # pragma once
00006 #endif
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include "InstantIODef.h"
00027 #include "TypeName.h"
00028 #include <iostream>
00029 #ifdef _MSC_VER
00030 # pragma warning (push)
00031 # pragma warning (disable: 4351)
00032 #endif
00033
00034
00035 namespace InstantIO
00036 {
00037
00038
00061 template <class T>
00062 class Matrix3
00063 {
00064 public:
00065
00067 enum MatrixElementIndex
00068 {
00069 M_00 = 0, M_01 = 1, M_02 = 2,
00070 M_10 = 3, M_11 = 4, M_12 = 5,
00071 M_20 = 6, M_21 = 7, M_22 = 8
00072 };
00073
00078 inline Matrix3(): matrix_()
00079 { setIdentity(); }
00080
00086 inline Matrix3(const Matrix3 &obj): matrix_()
00087 {
00088 matrix_[M_00] = obj.matrix_[M_00];
00089 matrix_[M_01] = obj.matrix_[M_01];
00090 matrix_[M_02] = obj.matrix_[M_02];
00091 matrix_[M_10] = obj.matrix_[M_10];
00092 matrix_[M_11] = obj.matrix_[M_11];
00093 matrix_[M_12] = obj.matrix_[M_12];
00094 matrix_[M_20] = obj.matrix_[M_20];
00095 matrix_[M_21] = obj.matrix_[M_21];
00096 matrix_[M_22] = obj.matrix_[M_22];
00097 }
00098
00106 inline Matrix3(const T matrix[9], bool transposed = false): matrix_()
00107 {
00108 if (transposed == true)
00109 {
00110 matrix_[M_00] = matrix[M_00];
00111 matrix_[M_01] = matrix[M_10];
00112 matrix_[M_02] = matrix[M_20];
00113 matrix_[M_10] = matrix[M_01];
00114 matrix_[M_11] = matrix[M_11];
00115 matrix_[M_12] = matrix[M_21];
00116 matrix_[M_20] = matrix[M_02];
00117 matrix_[M_21] = matrix[M_12];
00118 matrix_[M_22] = matrix[M_22];
00119 }
00120 else
00121 {
00122 matrix_[M_00] = matrix[M_00];
00123 matrix_[M_01] = matrix[M_01];
00124 matrix_[M_02] = matrix[M_02];
00125 matrix_[M_10] = matrix[M_10];
00126 matrix_[M_11] = matrix[M_11];
00127 matrix_[M_12] = matrix[M_12];
00128 matrix_[M_20] = matrix[M_20];
00129 matrix_[M_21] = matrix[M_21];
00130 matrix_[M_22] = matrix[M_22];
00131 }
00132 }
00133
00139 inline const Matrix3 &operator=(const Matrix3 &obj)
00140 {
00141 matrix_[M_00] = obj.matrix_[M_00];
00142 matrix_[M_01] = obj.matrix_[M_01];
00143 matrix_[M_02] = obj.matrix_[M_02];
00144 matrix_[M_10] = obj.matrix_[M_10];
00145 matrix_[M_11] = obj.matrix_[M_11];
00146 matrix_[M_12] = obj.matrix_[M_12];
00147 matrix_[M_20] = obj.matrix_[M_20];
00148 matrix_[M_21] = obj.matrix_[M_21];
00149 matrix_[M_22] = obj.matrix_[M_22];
00150 return obj;
00151 }
00152
00159 inline const T *operator=(const T matrix[9])
00160 {
00161 matrix_[M_00] = matrix[M_00];
00162 matrix_[M_01] = matrix[M_01];
00163 matrix_[M_02] = matrix[M_02];
00164 matrix_[M_10] = matrix[M_10];
00165 matrix_[M_11] = matrix[M_11];
00166 matrix_[M_12] = matrix[M_12];
00167 matrix_[M_20] = matrix[M_20];
00168 matrix_[M_21] = matrix[M_21];
00169 matrix_[M_22] = matrix[M_22];
00170 return matrix;
00171 }
00172
00174 void setIdentity();
00175
00181 inline T operator[](MatrixElementIndex i) const { return matrix_[i]; }
00182
00188 inline T &operator[](MatrixElementIndex i) { return matrix_[i]; }
00189
00195 inline const T *getValue() const { return matrix_; }
00196
00202 inline T *getValue() { return matrix_; }
00203
00208 inline operator T *() { return &matrix_[0]; }
00209
00214 inline operator const T *() const { return &matrix_[0]; }
00215
00216 private:
00217
00219 T matrix_[9];
00220 };
00221
00222
00223 template <class T>
00224 void Matrix3<T>::setIdentity()
00225 {
00226 matrix_[M_01] = matrix_[M_02] = 0.f;
00227 matrix_[M_10] = matrix_[M_12] = 0.f;
00228 matrix_[M_20] = matrix_[M_21] = 0.f;
00229 matrix_[M_00] = matrix_[M_11] = matrix_[M_22] = 1.f;
00230 }
00231
00232
00233 typedef Matrix3<double> Matrix3d;
00234
00235
00236 typedef Matrix3<float> Matrix3f;
00237
00238
00245 template <>
00246 class INSTANTIO_DLLMAPPING TypeName<Matrix3d>
00247 {
00248 public:
00249
00254 static const char *getName();
00255
00256 private:
00257
00259 TypeName();
00260
00262 TypeName(const TypeName &);
00263
00265 const TypeName &operator=(const TypeName &);
00266 };
00267
00268
00275 template <>
00276 class INSTANTIO_DLLMAPPING TypeName<Matrix3f>
00277 {
00278 public:
00279
00284 static const char *getName();
00285
00286 private:
00287
00289 TypeName();
00290
00292 TypeName(const TypeName &);
00293
00295 const TypeName &operator=(const TypeName &);
00296 };
00297
00298
00299 template <class T>
00300 std::ostream &operator <<(std::ostream &os, const Matrix3<T> &obj)
00301 {
00302 for (int i = 0; i < 3; ++i)
00303 {
00304 for (int j = 0; j < 3; ++j)
00305 os << obj[j * 3 + i] << ' ';
00306 os << std::endl;
00307 }
00308 return os;
00309 }
00310
00311
00312 template <class T>
00313 std::istream &operator >>(std::istream &is, Matrix3<T> &obj)
00314 {
00315 for (int i = 0; i < 3; ++i)
00316 for (int j = 0; j < 3; ++j)
00317 if (is.good())
00318 is >> obj[j * 3 + i];
00319 return is;
00320 }
00321
00322
00323 }
00324
00325
00326 #ifdef _MSC_VER
00327 # pragma warning (pop)
00328 #endif
00329
00330 #endif // __INSTANTIO_MATRIX3_H