Polyhedral-net Splines
Loading...
Searching...
No Matches
Matrix.hpp
1/* copyright(c)Jorg Peters [jorg.peters@gmail.com] */
2
3#pragma once
4
5#include <iostream>
6#include <vector>
7
8typedef std::vector<std::vector<double>> MatNxNd;
9
10class Matrix
11{
12public:
13 Matrix(){}
14
15 Matrix(const MatNxNd a_Mat)
16 : m_Mat(a_Mat), m_Rows(a_Mat.size()), m_Cols(a_Mat[0].size()){}
17
18 Matrix(const int a_Rows, const int a_Cols)
19 : m_Rows(a_Rows), m_Cols(a_Cols)
20 {
21 initMatrix(m_Mat, m_Rows, m_Cols);
22 }
23
24 int getRows() const { return m_Rows; }
25 int getCols() const { return m_Cols; }
26
27 std::vector<double>& operator()(int a_Row)
28 {
29 return m_Mat[a_Row];
30 }
31
32 const std::vector<double>& operator()(int a_Row) const
33 {
34 return m_Mat[a_Row];
35 }
36
37 double& operator()(int a_Row, int a_Col)
38 {
39 return m_Mat[a_Row][a_Col];
40 }
41
42 const double& operator()(int a_Row, int a_Col) const
43 {
44 return m_Mat[a_Row][a_Col];
45 }
46
47 Matrix operator*(Matrix a_Input) const
48 {
49 // check dimensions
50 if(m_Cols!=a_Input.getRows())
51 {
52 std::cout << "Can't multiply two matrices!" << std::endl;
53 }
54
55 Matrix t_Output = Matrix(m_Rows, a_Input.getCols());
56
57 for(int i=0; i < m_Rows; i++)
58 {
59 for(int j=0; j < a_Input.getCols(); j++)
60 {
61 for (int k=0; k < m_Cols; k++)
62 {
63 t_Output(i, j) += m_Mat[i][k] * a_Input(k, j);
64 }
65 }
66 }
67 return t_Output;
68 }
69
70 Matrix& operator=(const Matrix& a_Input)
71 {
72 if(this != &a_Input)
73 {
74 m_Rows = a_Input.getRows();
75 m_Cols = a_Input.getCols();
76 m_Mat = a_Input.m_Mat;
77 }
78 return *this;
79 }
80
81private:
82 int m_Rows, m_Cols;
83 MatNxNd m_Mat;
84
85 void initMatrix(MatNxNd& a_Mat, const int a_Rows, const int a_Cols)
86 {
87 for(int i=0; i<a_Rows; i++)
88 {
89 std::vector<double> t_RowVec;
90 for(int j=0; j<a_Cols; j++)
91 {
92 t_RowVec.push_back(0);
93 }
94 a_Mat.push_back(t_RowVec);
95 }
96 }
97
98};