Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

ShMatrix.hpp

00001 // Sh: A GPU metaprogramming language.
00002 //
00003 // Copyright (c) 2003 University of Waterloo Computer Graphics Laboratory
00004 // Project administrator: Michael D. McCool
00005 // Authors: Zheng Qin, Stefanus Du Toit, Kevin Moule, Tiberiu S. Popa,
00006 //          Michael D. McCool
00007 // 
00008 // This software is provided 'as-is', without any express or implied
00009 // warranty. In no event will the authors be held liable for any damages
00010 // arising from the use of this software.
00011 // 
00012 // Permission is granted to anyone to use this software for any purpose,
00013 // including commercial applications, and to alter it and redistribute it
00014 // freely, subject to the following restrictions:
00015 // 
00016 // 1. The origin of this software must not be misrepresented; you must
00017 // not claim that you wrote the original software. If you use this
00018 // software in a product, an acknowledgment in the product documentation
00019 // would be appreciated but is not required.
00020 // 
00021 // 2. Altered source versions must be plainly marked as such, and must
00022 // not be misrepresented as being the original software.
00023 // 
00024 // 3. This notice may not be removed or altered from any source
00025 // distribution.
00027 #ifndef SH_SHMATRIX_HPP
00028 #define SH_SHMATRIX_HPP
00029 
00030 #include "ShMeta.hpp"
00031 #include "ShVariable.hpp"
00032 #include "ShAttrib.hpp"
00033 #include "ShRefCount.hpp"
00034 
00035 namespace SH {
00036 
00037 template<int Rows, int Cols, ShBindingType Binding, typename T>
00038 class ShMatrix;
00039 
00040 template<int Rows, int Cols, typename T>
00041 class ShMatrixRows;
00042 
00049 template<int Rows, int Cols, ShBindingType Binding, typename T>
00050 class ShMatrix: public virtual ShMeta {
00051 public:
00052   typedef typename ShHostType<T>::type H; 
00053   typedef H HostType; 
00054     
00062   ShMatrix();
00063 
00068   ShMatrix(const ShMatrix<Rows, Cols, Binding, T>& other);
00069 
00070 
00075   template<ShBindingType Binding2>
00076   ShMatrix(const ShMatrix<Rows, Cols, Binding2, T>& other);
00077   
00078   ~ShMatrix();
00079 
00085   ShMatrix& operator=(const ShMatrix<Rows, Cols, Binding, T>& other);
00086 
00092   template<ShBindingType Binding2>
00093   ShMatrix& operator=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00094 
00099   ShAttrib<Cols, Binding, T>& operator[](int i);
00100 
00105   const ShAttrib<Cols, Binding, T>& operator[](int i) const;
00106 
00112   template<ShBindingType Binding2>
00113   ShMatrix& operator+=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00114 
00120   template<ShBindingType Binding2>
00121   ShMatrix& operator-=(const ShMatrix<Rows, Cols, Binding2, T>& other);
00122 
00123 
00130   template<ShBindingType Binding2>
00131   ShMatrix& operator/=(const ShMatrix<Rows, Cols, Binding2, T>& other);    
00132    
00133 
00138   ShMatrix<Rows - 1, Cols -1, SH_TEMP, T> subMatrix(int,int) const;
00139 
00140   void setTranslation(const ShGeneric<Rows-1, T>& trans);
00141   
00142   void setScaling(const ShGeneric<Rows-1, T>& scale);
00143 
00144 
00150   ShMatrix& operator*=(const ShGeneric<1, T>& a);
00151     
00156   ShMatrix& operator/=(const ShGeneric<1, T>& a);
00157 
00163   ShMatrixRows<Rows, Cols, T> operator()() const; 
00164   ShMatrixRows<1, Cols, T> operator()(int) const;
00165   ShMatrixRows<2, Cols, T> operator()(int, int) const;
00166   ShMatrixRows<3, Cols, T> operator()(int, int, int) const;
00167   ShMatrixRows<4, Cols, T> operator()(int, int, int, int) const;
00169   
00175 
00177   void range(H low, H high);
00178 
00180   
00181   virtual std::string name() const;
00182   virtual void name(const std::string& n);
00183   virtual bool has_name() const;
00184   
00185   virtual bool internal() const;
00186   virtual void internal(bool);
00187 
00188   virtual std::string title() const;
00189   virtual void title(const std::string& t);
00190 
00191   virtual std::string description() const;
00192   virtual void description(const std::string& d);
00193 
00194   virtual std::string meta(const std::string& key) const;
00195   virtual void meta(const std::string& key, const std::string& value);
00196 
00197 private:
00202   ShAttrib<Cols, Binding, T> m_data[Rows];
00203   
00204 };
00211 template<int R, int C, ShBindingType B, typename Ty>
00212 std::ostream& operator<<(std::ostream& out,
00213                          const ShMatrix<R, C, B, Ty>& m);
00214 
00221 template<int Rows, int Cols, typename T>
00222 class ShMatrixRows {
00223 public:
00224   template<ShBindingType Binding>
00225   ShMatrixRows(const ShMatrix<Rows, Cols, Binding, T>& source);
00226   
00227   template<int OR, ShBindingType Binding>
00228   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00229                int idx0);
00230   template<int OR, ShBindingType Binding>
00231   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00232                int idx0, int idx1);
00233   template<int OR, ShBindingType Binding>
00234   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00235                int idx0, int idx1, int idx2);
00236   template<int OR, ShBindingType Binding>
00237   ShMatrixRows(const ShMatrix<OR, Cols, Binding, T>& source,
00238                int idx0, int idx1, int idx2, int idx3);
00239 
00240   ShMatrixRows(const ShMatrixRows<Rows, Cols, T>& other);
00241   
00242   ShMatrixRows& operator=(const ShMatrixRows<Rows, Cols, T>& other);
00243 
00248   ShMatrix<Rows, Cols, SH_TEMP, T> operator()() const; 
00249   ShMatrix<Rows, 1, SH_TEMP, T> operator()(int) const;
00250   ShMatrix<Rows, 2, SH_TEMP, T> operator()(int, int) const;
00251   ShMatrix<Rows, 3, SH_TEMP, T> operator()(int, int, int) const;
00252   ShMatrix<Rows, 4, SH_TEMP, T> operator()(int, int, int, int) const;
00254 private:
00255   ShAttrib<Cols, SH_TEMP, T> m_data[Rows];
00256 };
00257 
00258 
00259 typedef ShMatrix<1, 1, SH_INPUT, float> ShInputMatrix1x1f;
00260 typedef ShMatrix<1, 1, SH_OUTPUT, float> ShOutputMatrix1x1f;
00261 typedef ShMatrix<1, 1, SH_INOUT, float> ShInOutMatrix1x1f;
00262 typedef ShMatrix<1, 1, SH_TEMP, float> ShMatrix1x1f;
00263 typedef ShMatrix<1, 2, SH_INPUT, float> ShInputMatrix1x2f;
00264 typedef ShMatrix<1, 2, SH_OUTPUT, float> ShOutputMatrix1x2f;
00265 typedef ShMatrix<1, 2, SH_INOUT, float> ShInOutMatrix1x2f;
00266 typedef ShMatrix<1, 2, SH_TEMP, float> ShMatrix1x2f;
00267 typedef ShMatrix<1, 3, SH_INPUT, float> ShInputMatrix1x3f;
00268 typedef ShMatrix<1, 3, SH_OUTPUT, float> ShOutputMatrix1x3f;
00269 typedef ShMatrix<1, 3, SH_INOUT, float> ShInOutMatrix1x3f;
00270 typedef ShMatrix<1, 3, SH_TEMP, float> ShMatrix1x3f;
00271 typedef ShMatrix<1, 4, SH_INPUT, float> ShInputMatrix1x4f;
00272 typedef ShMatrix<1, 4, SH_OUTPUT, float> ShOutputMatrix1x4f;
00273 typedef ShMatrix<1, 4, SH_INOUT, float> ShInOutMatrix1x4f;
00274 typedef ShMatrix<1, 4, SH_TEMP, float> ShMatrix1x4f;
00275 
00276 typedef ShMatrix<2, 1, SH_INPUT, float> ShInputMatrix2x1f;
00277 typedef ShMatrix<2, 1, SH_OUTPUT, float> ShOutputMatrix2x1f;
00278 typedef ShMatrix<2, 1, SH_INOUT, float> ShInOutMatrix2x1f;
00279 typedef ShMatrix<2, 1, SH_TEMP, float> ShMatrix2x1f;
00280 typedef ShMatrix<2, 2, SH_INPUT, float> ShInputMatrix2x2f;
00281 typedef ShMatrix<2, 2, SH_OUTPUT, float> ShOutputMatrix2x2f;
00282 typedef ShMatrix<2, 2, SH_INOUT, float> ShInOutMatrix2x2f;
00283 typedef ShMatrix<2, 2, SH_TEMP, float> ShMatrix2x2f;
00284 typedef ShMatrix<2, 3, SH_INPUT, float> ShInputMatrix2x3f;
00285 typedef ShMatrix<2, 3, SH_OUTPUT, float> ShOutputMatrix2x3f;
00286 typedef ShMatrix<2, 3, SH_INOUT, float> ShInOutMatrix2x3f;
00287 typedef ShMatrix<2, 3, SH_TEMP, float> ShMatrix2x3f;
00288 typedef ShMatrix<2, 4, SH_INPUT, float> ShInputMatrix2x4f;
00289 typedef ShMatrix<2, 4, SH_OUTPUT, float> ShOutputMatrix2x4f;
00290 typedef ShMatrix<2, 4, SH_INOUT, float> ShInOutMatrix2x4f;
00291 typedef ShMatrix<2, 4, SH_TEMP, float> ShMatrix2x4f;
00292 
00293 typedef ShMatrix<3, 1, SH_INPUT, float> ShInputMatrix3x1f;
00294 typedef ShMatrix<3, 1, SH_OUTPUT, float> ShOutputMatrix3x1f;
00295 typedef ShMatrix<3, 1, SH_INOUT, float> ShInOutMatrix3x1f;
00296 typedef ShMatrix<3, 1, SH_TEMP, float> ShMatrix3x1f;
00297 typedef ShMatrix<3, 2, SH_INPUT, float> ShInputMatrix3x2f;
00298 typedef ShMatrix<3, 2, SH_OUTPUT, float> ShOutputMatrix3x2f;
00299 typedef ShMatrix<3, 2, SH_INOUT, float> ShInOutMatrix3x2f;
00300 typedef ShMatrix<3, 2, SH_TEMP, float> ShMatrix3x2f;
00301 typedef ShMatrix<3, 3, SH_INPUT, float> ShInputMatrix3x3f;
00302 typedef ShMatrix<3, 3, SH_OUTPUT, float> ShOutputMatrix3x3f;
00303 typedef ShMatrix<3, 3, SH_INOUT, float> ShInOutMatrix3x3f;
00304 typedef ShMatrix<3, 3, SH_TEMP, float> ShMatrix3x3f;
00305 typedef ShMatrix<3, 4, SH_INPUT, float> ShInputMatrix3x4f;
00306 typedef ShMatrix<3, 4, SH_OUTPUT, float> ShOutputMatrix3x4f;
00307 typedef ShMatrix<3, 4, SH_INOUT, float> ShInOutMatrix3x4f;
00308 typedef ShMatrix<3, 4, SH_TEMP, float> ShMatrix3x4f;
00309 
00310 typedef ShMatrix<4, 1, SH_INPUT, float> ShInputMatrix4x1f;
00311 typedef ShMatrix<4, 1, SH_OUTPUT, float> ShOutputMatrix4x1f;
00312 typedef ShMatrix<4, 1, SH_INOUT, float> ShInOutMatrix4x1f;
00313 typedef ShMatrix<4, 1, SH_TEMP, float> ShMatrix4x1f;
00314 typedef ShMatrix<4, 2, SH_INPUT, float> ShInputMatrix4x2f;
00315 typedef ShMatrix<4, 2, SH_OUTPUT, float> ShOutputMatrix4x2f;
00316 typedef ShMatrix<4, 2, SH_INOUT, float> ShInOutMatrix4x2f;
00317 typedef ShMatrix<4, 2, SH_TEMP, float> ShMatrix4x2f;
00318 typedef ShMatrix<4, 3, SH_INPUT, float> ShInputMatrix4x3f;
00319 typedef ShMatrix<4, 3, SH_OUTPUT, float> ShOutputMatrix4x3f;
00320 typedef ShMatrix<4, 3, SH_INOUT, float> ShInOutMatrix4x3f;
00321 typedef ShMatrix<4, 3, SH_TEMP, float> ShMatrix4x3f;
00322 typedef ShMatrix<4, 4, SH_INPUT, float> ShInputMatrix4x4f;
00323 typedef ShMatrix<4, 4, SH_OUTPUT, float> ShOutputMatrix4x4f;
00324 typedef ShMatrix<4, 4, SH_INOUT, float> ShInOutMatrix4x4f;
00325 typedef ShMatrix<4, 4, SH_TEMP, float> ShMatrix4x4f;
00326 
00327 }
00328 
00329 #include "ShMatrixImpl.hpp"
00330 
00331 #endif
00332 

Generated on Mon Jan 24 18:36:33 2005 for Sh by  doxygen 1.4.1