00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00020 #ifndef SH_SHMATRIX_HPP
00021 #define SH_SHMATRIX_HPP
00022
00023 #include "ShMeta.hpp"
00024 #include "ShVariable.hpp"
00025 #include "ShAttrib.hpp"
00026 #include "ShRefCount.hpp"
00027
00028 namespace SH {
00029
00030 template<int Rows, int Cols, ShBindingType Binding, typename T>
00031 class ShMatrix;
00032
00033 template<int Rows, int Cols, typename T>
00034 class ShMatrixRows;
00035
00042 template<int Rows, int Cols, ShBindingType Binding, typename T>
00043 class ShMatrix: public virtual ShMeta {
00044 public:
00045 typedef T storage_type;
00046 typedef typename ShHostType<T>::type host_type;
00047 typedef typename ShMemType<T>::type mem_type;
00048 static const ShValueType value_type = ShStorageTypeInfo<T>::value_type;
00049 static const ShBindingType binding_type = Binding;
00050 static const int rows = Rows;
00051 static const int cols = Cols;
00052 static const int typesize = Rows * Cols;
00053
00054 typedef ShMatrix<Rows, Cols, SH_INPUT, T> InputType;
00055 typedef ShMatrix<Rows, Cols, SH_OUTPUT, T> OutputType;
00056 typedef ShMatrix<Rows, Cols, SH_INOUT, T> InOutType;
00057 typedef ShMatrix<Rows, Cols, SH_TEMP, T> TempType;
00058 typedef ShMatrix<Rows, Cols, SH_CONST, T> ConstType;
00059
00067 ShMatrix();
00068
00073 template<ShBindingType Binding2>
00074 ShMatrix(const ShMatrix<Rows, Cols, Binding2, T>& other);
00075
00076 ~ShMatrix();
00077
00083 ShMatrix& operator=(const ShMatrix<Rows, Cols, Binding, T>& other);
00084
00090 template<ShBindingType Binding2>
00091 ShMatrix& operator=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00092
00097 ShMatrix& operator=(const T& scalar);
00098
00103 ShMatrix& operator=(const ShGeneric<1, T>& scalar);
00104
00109 ShAttrib<Cols, Binding, T>& operator[](int i);
00110
00115 const ShAttrib<Cols, Binding, T>& operator[](int i) const;
00116
00122 template<ShBindingType Binding2>
00123 ShMatrix& operator+=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00124
00130 template<ShBindingType Binding2>
00131 ShMatrix& operator-=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00132
00133
00140 template<ShBindingType Binding2>
00141 ShMatrix& operator/=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00142
00148 template<ShBindingType Binding2>
00149 ShMatrix& operator*=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00150
00155 ShMatrix& operator-();
00156
00161 ShMatrix<Rows - 1, Cols -1, SH_TEMP, T> subMatrix(int,int) const;
00162
00163 void setTranslation(const ShGeneric<Rows-1, T>& trans);
00164
00165 void setScaling(const ShGeneric<Rows-1, T>& scale);
00166
00167
00173 ShMatrix& operator*=(const ShGeneric<1, T>& a);
00174
00179 ShMatrix& operator/=(const ShGeneric<1, T>& a);
00180
00186 ShMatrixRows<Rows, Cols, T> operator()() const;
00187 ShMatrixRows<1, Cols, T> operator()(int) const;
00188 ShMatrixRows<2, Cols, T> operator()(int, int) const;
00189 ShMatrixRows<3, Cols, T> operator()(int, int, int) const;
00190 ShMatrixRows<4, Cols, T> operator()(int, int, int, int) const;
00192
00198
00200 void range(host_type low, host_type high);
00201
00203
00204 virtual std::string name() const;
00205 virtual void name(const std::string& n);
00206 virtual bool has_name() const;
00207
00208 virtual bool internal() const;
00209 virtual void internal(bool);
00210
00211 virtual std::string title() const;
00212 virtual void title(const std::string& t);
00213
00214 virtual std::string description() const;
00215 virtual void description(const std::string& d);
00216
00217 virtual std::string meta(const std::string& key) const;
00218 virtual void meta(const std::string& key, const std::string& value);
00219
00220 int size() const { return Rows * Cols; }
00221
00222 virtual void getValues(host_type dest[]) const;
00223
00224 private:
00229 ShAttrib<Cols, Binding, T> m_data[Rows];
00230
00231 };
00238 template<int R, int C, ShBindingType B, typename Ty>
00239 std::ostream& operator<<(std::ostream& out,
00240 const ShMatrix<R, C, B, Ty>& m);
00241
00248 template<int Rows, int Cols, typename T>
00249 class ShMatrixRows {
00250 public:
00251 template<ShBindingType Binding>
00252 ShMatrixRows(const ShMatrix<Rows, Cols, Binding, T>& source);
00253
00254 template<int OR, ShBindingType Binding>
00255 ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00256 int idx0);
00257 template<int OR, ShBindingType Binding>
00258 ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00259 int idx0, int idx1);
00260 template<int OR, ShBindingType Binding>
00261 ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00262 int idx0, int idx1, int idx2);
00263 template<int OR, ShBindingType Binding>
00264 ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00265 int idx0, int idx1, int idx2, int idx3);
00266
00267 ShMatrixRows(const ShMatrixRows<Rows, Cols, T>& other);
00268
00269 ShMatrixRows& operator=(const ShMatrixRows<Rows, Cols, T>& other);
00270
00275 ShMatrix<Rows, Cols, SH_TEMP, T> operator()() const;
00276 ShMatrix<Rows, 1, SH_TEMP, T> operator()(int) const;
00277 ShMatrix<Rows, 2, SH_TEMP, T> operator()(int, int) const;
00278 ShMatrix<Rows, 3, SH_TEMP, T> operator()(int, int, int) const;
00279 ShMatrix<Rows, 4, SH_TEMP, T> operator()(int, int, int, int) const;
00281 private:
00282 ShAttrib<Cols, SH_TEMP, T> m_data[Rows];
00283 };
00284
00285
00286 typedef ShMatrix<1, 1, SH_INPUT, float> ShInputMatrix1x1f;
00287 typedef ShMatrix<1, 1, SH_OUTPUT, float> ShOutputMatrix1x1f;
00288 typedef ShMatrix<1, 1, SH_INOUT, float> ShInOutMatrix1x1f;
00289 typedef ShMatrix<1, 1, SH_TEMP, float> ShMatrix1x1f;
00290 typedef ShMatrix<1, 2, SH_INPUT, float> ShInputMatrix1x2f;
00291 typedef ShMatrix<1, 2, SH_OUTPUT, float> ShOutputMatrix1x2f;
00292 typedef ShMatrix<1, 2, SH_INOUT, float> ShInOutMatrix1x2f;
00293 typedef ShMatrix<1, 2, SH_TEMP, float> ShMatrix1x2f;
00294 typedef ShMatrix<1, 3, SH_INPUT, float> ShInputMatrix1x3f;
00295 typedef ShMatrix<1, 3, SH_OUTPUT, float> ShOutputMatrix1x3f;
00296 typedef ShMatrix<1, 3, SH_INOUT, float> ShInOutMatrix1x3f;
00297 typedef ShMatrix<1, 3, SH_TEMP, float> ShMatrix1x3f;
00298 typedef ShMatrix<1, 4, SH_INPUT, float> ShInputMatrix1x4f;
00299 typedef ShMatrix<1, 4, SH_OUTPUT, float> ShOutputMatrix1x4f;
00300 typedef ShMatrix<1, 4, SH_INOUT, float> ShInOutMatrix1x4f;
00301 typedef ShMatrix<1, 4, SH_TEMP, float> ShMatrix1x4f;
00302
00303 typedef ShMatrix<2, 1, SH_INPUT, float> ShInputMatrix2x1f;
00304 typedef ShMatrix<2, 1, SH_OUTPUT, float> ShOutputMatrix2x1f;
00305 typedef ShMatrix<2, 1, SH_INOUT, float> ShInOutMatrix2x1f;
00306 typedef ShMatrix<2, 1, SH_TEMP, float> ShMatrix2x1f;
00307 typedef ShMatrix<2, 2, SH_INPUT, float> ShInputMatrix2x2f;
00308 typedef ShMatrix<2, 2, SH_OUTPUT, float> ShOutputMatrix2x2f;
00309 typedef ShMatrix<2, 2, SH_INOUT, float> ShInOutMatrix2x2f;
00310 typedef ShMatrix<2, 2, SH_TEMP, float> ShMatrix2x2f;
00311 typedef ShMatrix<2, 3, SH_INPUT, float> ShInputMatrix2x3f;
00312 typedef ShMatrix<2, 3, SH_OUTPUT, float> ShOutputMatrix2x3f;
00313 typedef ShMatrix<2, 3, SH_INOUT, float> ShInOutMatrix2x3f;
00314 typedef ShMatrix<2, 3, SH_TEMP, float> ShMatrix2x3f;
00315 typedef ShMatrix<2, 4, SH_INPUT, float> ShInputMatrix2x4f;
00316 typedef ShMatrix<2, 4, SH_OUTPUT, float> ShOutputMatrix2x4f;
00317 typedef ShMatrix<2, 4, SH_INOUT, float> ShInOutMatrix2x4f;
00318 typedef ShMatrix<2, 4, SH_TEMP, float> ShMatrix2x4f;
00319
00320 typedef ShMatrix<3, 1, SH_INPUT, float> ShInputMatrix3x1f;
00321 typedef ShMatrix<3, 1, SH_OUTPUT, float> ShOutputMatrix3x1f;
00322 typedef ShMatrix<3, 1, SH_INOUT, float> ShInOutMatrix3x1f;
00323 typedef ShMatrix<3, 1, SH_TEMP, float> ShMatrix3x1f;
00324 typedef ShMatrix<3, 2, SH_INPUT, float> ShInputMatrix3x2f;
00325 typedef ShMatrix<3, 2, SH_OUTPUT, float> ShOutputMatrix3x2f;
00326 typedef ShMatrix<3, 2, SH_INOUT, float> ShInOutMatrix3x2f;
00327 typedef ShMatrix<3, 2, SH_TEMP, float> ShMatrix3x2f;
00328 typedef ShMatrix<3, 3, SH_INPUT, float> ShInputMatrix3x3f;
00329 typedef ShMatrix<3, 3, SH_OUTPUT, float> ShOutputMatrix3x3f;
00330 typedef ShMatrix<3, 3, SH_INOUT, float> ShInOutMatrix3x3f;
00331 typedef ShMatrix<3, 3, SH_TEMP, float> ShMatrix3x3f;
00332 typedef ShMatrix<3, 4, SH_INPUT, float> ShInputMatrix3x4f;
00333 typedef ShMatrix<3, 4, SH_OUTPUT, float> ShOutputMatrix3x4f;
00334 typedef ShMatrix<3, 4, SH_INOUT, float> ShInOutMatrix3x4f;
00335 typedef ShMatrix<3, 4, SH_TEMP, float> ShMatrix3x4f;
00336
00337 typedef ShMatrix<4, 1, SH_INPUT, float> ShInputMatrix4x1f;
00338 typedef ShMatrix<4, 1, SH_OUTPUT, float> ShOutputMatrix4x1f;
00339 typedef ShMatrix<4, 1, SH_INOUT, float> ShInOutMatrix4x1f;
00340 typedef ShMatrix<4, 1, SH_TEMP, float> ShMatrix4x1f;
00341 typedef ShMatrix<4, 2, SH_INPUT, float> ShInputMatrix4x2f;
00342 typedef ShMatrix<4, 2, SH_OUTPUT, float> ShOutputMatrix4x2f;
00343 typedef ShMatrix<4, 2, SH_INOUT, float> ShInOutMatrix4x2f;
00344 typedef ShMatrix<4, 2, SH_TEMP, float> ShMatrix4x2f;
00345 typedef ShMatrix<4, 3, SH_INPUT, float> ShInputMatrix4x3f;
00346 typedef ShMatrix<4, 3, SH_OUTPUT, float> ShOutputMatrix4x3f;
00347 typedef ShMatrix<4, 3, SH_INOUT, float> ShInOutMatrix4x3f;
00348 typedef ShMatrix<4, 3, SH_TEMP, float> ShMatrix4x3f;
00349 typedef ShMatrix<4, 4, SH_INPUT, float> ShInputMatrix4x4f;
00350 typedef ShMatrix<4, 4, SH_OUTPUT, float> ShOutputMatrix4x4f;
00351 typedef ShMatrix<4, 4, SH_INOUT, float> ShInOutMatrix4x4f;
00352 typedef ShMatrix<4, 4, SH_TEMP, float> ShMatrix4x4f;
00353
00354 }
00355
00356 #include "ShMatrixImpl.hpp"
00357
00358 #endif
00359