Loading...
Searching...
No Matches
MatrixDenseBase.hpp
Go to the documentation of this file.
1// This code is based on Jet framework.
2// Copyright (c) 2018 Doyub Kim
3// CubbyFlow is voxel-based fluid simulation engine for computer games.
4// Copyright (c) 2020 CubbyFlow Team
5// Core Part: Chris Ohk, Junwoo Hwang, Jihong Sin, Seungwoo Yoo
6// AI Part: Dongheon Cho, Minseo Kim
7// We are making my contributions/submissions to this project solely in our
8// personal capacity and are not conveying any rights to any intellectual
9// property of any third parties.
10
11#ifndef CUBBYFLOW_MATRIX_DENSE_BASE_HPP
12#define CUBBYFLOW_MATRIX_DENSE_BASE_HPP
13
15
16namespace CubbyFlow
17{
18// Derived type should be constructible.
19template <typename T, size_t Rows, size_t Cols, typename Derived>
21{
22 public:
23 using ValueType = T;
24 using Reference = T&;
25 using ConstReference = const T&;
26
28 template <size_t R, size_t C, typename E>
30
33
36
38 template <size_t R, size_t C, typename E>
39 void SetRow(size_t i, const MatrixExpression<T, R, C, E>& row);
40
42 template <size_t R, size_t C, typename E>
43 void SetColumn(size_t j, const MatrixExpression<T, R, C, E>& col);
44
45 void Normalize();
46
48 void Transpose();
49
51 void Invert();
52
53 Reference operator()(size_t i, size_t j);
54
55 ConstReference operator()(size_t i, size_t j) const;
56
58 template <size_t R, size_t C, typename E>
60
62 template <typename D = Derived>
63 static std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(), D> MakeZero();
64
66 template <typename D = Derived>
67 static std::enable_if_t<IsMatrixSizeDynamic<Rows, Cols>(), D> MakeZero(
68 size_t rows, size_t cols);
69
71 template <typename D = Derived>
72 static std::enable_if_t<IsMatrixSizeStatic<Rows, Cols>(), D> MakeConstant(
74
76 template <typename D = Derived>
77 static std::enable_if_t<IsMatrixSizeDynamic<Rows, Cols>(), D> MakeConstant(
78 size_t rows, size_t cols, ValueType val);
79
81 template <typename D = Derived>
82 static std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>(), D>
84
86 template <typename D = Derived>
87 static std::enable_if_t<IsMatrixSizeDynamic<Rows, Cols>(), D> MakeIdentity(
88 size_t rows);
89
91 template <typename... Args, typename D = Derived>
92 static std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>(), D>
94
96 template <size_t R, size_t C, typename E, typename D = Derived>
97 static std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>(), D>
99
102 template <typename D = Derived>
103 static std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>() && (Rows == 2),
104 D>
106
109 template <size_t R, size_t C, typename E, typename D = Derived>
110 static std::enable_if_t<
111 IsMatrixStaticSquare<Rows, Cols>() && (Rows == 3 || Rows == 4), D>
113
115 template <size_t R, size_t C, typename E, typename D = Derived>
116 static std::enable_if_t<IsMatrixStaticSquare<Rows, Cols>() && (Rows == 4),
117 D>
119
120 protected:
121 MatrixDenseBase() = default;
122
123 private:
124 [[nodiscard]] constexpr size_t GetRows() const;
125
126 [[nodiscard]] constexpr size_t GetCols() const;
127
128 [[nodiscard]] auto begin();
129
130 [[nodiscard]] constexpr auto begin() const;
131
132 [[nodiscard]] auto end();
133
134 [[nodiscard]] constexpr auto end() const;
135
136 Reference operator[](size_t i);
137
138 ConstReference operator[](size_t i) const;
139
140 [[nodiscard]] Derived& GetDerived();
141
142 [[nodiscard]] const Derived& GetDerived() const;
143};
144} // namespace CubbyFlow
145
147
148#endif
Definition MatrixDenseBase.hpp:21
void Transpose()
Transposes this matrix.
Definition MatrixDenseBase-Impl.hpp:92
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >() &&(Rows==4), D > MakeTranslationMatrix(const MatrixExpression< T, R, C, E > &t)
Makes translation matrix.
Definition MatrixDenseBase-Impl.hpp:272
void Normalize()
Definition MatrixDenseBase-Impl.hpp:86
void SetOffDiagonal(ConstReference val)
Sets off-diagonal elements with input scalar.
Definition MatrixDenseBase-Impl.hpp:45
Reference operator()(size_t i, size_t j)
Definition MatrixDenseBase-Impl.hpp:107
T ValueType
Definition MatrixDenseBase.hpp:23
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >(), D > MakeZero()
Makes a static matrix with zero entries.
Definition MatrixDenseBase-Impl.hpp:136
MatrixDenseBase & operator=(const MatrixExpression< T, R, C, E > &expression)
Copies from generic expression.
void SetColumn(size_t j, const MatrixExpression< T, R, C, E > &col)
Sets j-th column with input vector.
Definition MatrixDenseBase-Impl.hpp:74
const T & ConstReference
Definition MatrixDenseBase.hpp:25
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >(), D > MakeIdentity()
Makes a static identity matrix.
Definition MatrixDenseBase-Impl.hpp:169
void CopyFrom(const MatrixExpression< T, R, C, E > &expression)
Copies from generic expression.
Definition MatrixDenseBase-Impl.hpp:21
static std::enable_if_t< IsMatrixSizeStatic< Rows, Cols >(), D > MakeConstant(ValueType val)
Makes a static matrix with constant entries.
Definition MatrixDenseBase-Impl.hpp:152
void Invert()
Inverts this matrix.
Definition MatrixDenseBase-Impl.hpp:100
void SetRow(size_t i, const MatrixExpression< T, R, C, E > &row)
Sets i-th row with input column vector.
Definition MatrixDenseBase-Impl.hpp:61
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >(), D > MakeScaleMatrix(ValueType first, Args... rest)
Makes scale matrix.
Definition MatrixDenseBase-Impl.hpp:191
static std::enable_if_t< IsMatrixStaticSquare< Rows, Cols >() &&(Rows==2), D > MakeRotationMatrix(T rad)
Definition MatrixDenseBase-Impl.hpp:229
void SetDiagonal(ConstReference val)
Sets diagonal elements with input scalar.
Definition MatrixDenseBase-Impl.hpp:34
Definition Matrix.hpp:30
Definition pybind11Utils.hpp:21
Matrix< T, Rows, 1 > Vector
Definition Matrix.hpp:738