VR-Vantage API Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DtMatrix.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2014 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 #pragma once
10 
11 #include <vector>
12 
13 #include "Matrix3.h"
14 #include "Matrix4.h"
15 
16 namespace makVrv {
17 
20  template<class T>
21  class Matrix
22  {
23  public:
24  Matrix(size_t numRows, size_t numCols);
25  virtual ~Matrix();
26 
27  std::vector<T>& operator [](size_t row);
28 
29  const std::vector<T>& operator [](size_t row) const;
30 
31  Matrix operator * (const Matrix& rhsMatrix) const;
32 
33  size_t getNumRows(void) const;
34  size_t getNumCols(void) const;
35 
36  size_t getNumElements(void) const {return getNumRows()*getNumCols();}
37  private:
38  std::vector< std::vector<T> > myElements;
39  };
40 
41  template <class T>
42  Matrix<T>::Matrix(size_t numRows, size_t numCols)
43  {
44  Assert(numRows>=1 && numCols >= 1);
45  myElements.resize(numRows);
46  for(size_t i = 0; i < myElements.size(); ++i)
47  {
48  myElements[i].resize(numCols);
49  }
50  }
51 
52  template <class T>
54  {
55 
56  }
57 
58  template <class T>
59  std::vector<T>& Matrix<T>::operator [](size_t row)
60  {
61  return myElements[row];
62  }
63 
64  template <class T>
65  const std::vector<T>& Matrix<T>::operator [](size_t row) const
66  {
67  return myElements[row];
68  }
69 
70  template <class T>
71  size_t Matrix<T>::getNumRows(void) const
72  {
73  return myElements.size();
74  }
75  template <class T>
76  size_t Matrix<T>::getNumCols(void) const
77  {
78  if (myElements.empty())
79  return 0;
80  return myElements[0].size();
81  }
82 
83  template <class T>
84  Matrix<T> Matrix<T>::operator * (const Matrix& rhsMatrix) const
85  {
86  const Matrix& lhsMatrix = *this;
87  Assert(getNumCols()==rhsMatrix.getNumRows());
88  Matrix<T> result(getNumRows(), rhsMatrix.getNumCols());
89 
90  for(size_t i = 0; i < result.getNumRows(); ++i)
91  {
92  for (size_t j = 0; j < result.getNumCols(); ++j)
93  {
94  result[i][j] = 0;
95  for(size_t k = 0; k < result.getNumCols(); ++k)
96  {
97  result[i][j] += lhsMatrix[i][k]*rhsMatrix[k][j];
98  }
99  }
100  }
101  return result;
102  }
103 
104 } //namespace makVrv


Copyright © 2005-2013 VT MÄK. All Rights Reserved (www.mak.com)