15#ifndef vtkMatrixUtilities_h
16#define vtkMatrixUtilities_h
18#include "vtkABINamespace.h"
24VTK_ABI_NAMESPACE_BEGIN
51template <
int ContainerTypeT,
class ContainerT>
55 static_assert(std::is_integral<value_type>::value || std::is_floating_point<value_type>::value,
56 "value_type is not a numeric type");
60template <
class ContainerT>
63 typedef typename std::remove_pointer<
64 typename std::remove_all_extents<typename std::remove_pointer<ContainerT>::type>::type>::type
66 static_assert(std::is_integral<value_type>::value || std::is_floating_point<value_type>::value,
67 "value_type is not a numeric type");
80template <
class ContainerT>
84 typedef typename std::remove_reference<ContainerT>::type DerefContainer;
89 std::is_array<DerefContainer>::value || std::is_pointer<DerefContainer>::value,
91 static_assert(std::is_integral<value_type>::value || std::is_floating_point<value_type>::value,
92 "value_type is not a numeric type");
100template <
class MatrixT>
103 typedef typename std::remove_extent<MatrixT>::type Row;
104 typedef typename std::remove_extent<Row>::type Value;
105 return std::is_array<MatrixT>::value && std::is_array<Row>::value && !std::is_array<Value>::value;
113template <
class MatrixT>
116 typedef typename std::remove_pointer<MatrixT>::type Row;
117 typedef typename std::remove_pointer<Row>::type Value;
118 return std::is_pointer<MatrixT>::value && std::is_pointer<Row>::value &&
119 !std::is_pointer<Value>::value;
127template <
class MatrixT>
130 typedef typename std::remove_pointer<MatrixT>::type RowPointer;
131 typedef typename std::remove_extent<MatrixT>::type RowArray;
132 typedef typename std::remove_pointer<MatrixT>::type ValuePointerPointer;
133 typedef typename std::remove_extent<MatrixT>::type ValuePointerArray;
134 typedef typename std::remove_pointer<MatrixT>::type ValueArrayPointer;
135 typedef typename std::remove_extent<MatrixT>::type ValueArrayArray;
136 return ((std::is_array<RowPointer>::value && !std::is_same<RowPointer, MatrixT>::value) ||
137 std::is_pointer<RowPointer>::value || std::is_array<RowArray>::value ||
138 (std::is_pointer<RowArray>::value && !std::is_same<RowArray, MatrixT>::value)) &&
139 (!std::is_array<ValuePointerPointer>::value || !std::is_pointer<ValuePointerPointer>::value) &&
140 (!std::is_array<ValueArrayPointer>::value || !std::is_pointer<ValueArrayPointer>::value) &&
141 (!std::is_array<ValuePointerArray>::value || !std::is_pointer<ValuePointerArray>::value) &&
142 (!std::is_array<ValueArrayArray>::value || !std::is_pointer<ValueArrayArray>::value);
148template <
int RowsT,
int ColsT,
class LayoutT>
152template <
int RowsT,
int ColsT>
155 template <
int RowT,
int ColT>
158 static_assert(RowT >= 0 && RowT < RowsT,
"RowT out of bounds");
159 static_assert(ColT >= 0 && ColT < ColsT,
"ColT out of bounds");
160 return ColsT * RowT + ColT;
164template <
int RowsT,
int ColsT>
167 template <
int RowT,
int ColT>
170 static_assert(RowT >= 0 && RowT < RowsT,
"RowT out of bounds");
171 static_assert(ColT >= 0 && ColT < ColsT,
"ColT out of bounds");
172 return RowsT * ColT + RowT;
189template <
int RowsT,
int ColsT,
class LayoutT = Layout::Identity>
192 template <
int RowT,
int ColT>
202template <
int RowsT,
int ColsT,
class MatrixT,
class LayoutT,
bool MatrixLayoutIs2DT>
207template <
int RowsT,
int ColsT,
class MatrixT,
class LayoutT>
208class Wrapper<RowsT, ColsT, MatrixT, LayoutT, false>
214 template <
int RowT,
int ColT>
215 static const Scalar&
Get(
const MatrixT& M)
220 template <
int RowT,
int ColT>
221 static Scalar&
Get(MatrixT& M)
228template <
int RowsT,
int ColsT,
class MatrixT>
235 template <
int RowT,
int ColT>
236 static const Scalar&
Get(
const MatrixT& M)
238 return M[RowT][ColT];
241 template <
int RowT,
int ColT>
242 static Scalar&
Get(MatrixT& M)
244 return M[RowT][ColT];
249template <
int RowsT,
int ColsT,
class MatrixT>
256 template <
int RowT,
int ColT>
257 static const Scalar&
Get(
const MatrixT& M)
259 return M[ColT][RowT];
262 template <
int RowT,
int ColT>
263 static Scalar&
Get(MatrixT& M)
265 return M[ColT][RowT];
271template <
int RowsT,
int ColsT,
class MatrixT>
277 template <
int RowT,
int ColT>
280 static constexpr Scalar ZERO = Scalar(0);
282 static Scalar& Get(
const MatrixT&) {
return ZERO; }
286 struct Helper<RowT, RowT>
288 static Scalar& Get(MatrixT& M) {
return M[RowT]; }
290 static const Scalar& Get(
const MatrixT& M) {
return M[RowT]; }
294 template <
int RowT,
int ColT>
295 const Scalar&
Get(
const MatrixT& M)
297 return Helper<RowT, ColT>::Get(M);
300 template <
int RowT,
int ColT>
303 return Helper<RowT, ColT>::Get(M);
323template <
int RowsT,
int ColsT,
class MatrixT,
class LayoutT = Layout::Identity>
329 static_assert(!MatrixLayoutIs2D<MatrixT>() || !std::is_same<LayoutT, Layout::Diag>::value,
330 "A diagonal matrix cannot be a 2D array");
333 template <
int RowT,
int ColT>
334 static const Scalar&
Get(
const MatrixT& M)
337 MatrixLayoutIs2D<MatrixT>()>::template Get<RowT, ColT>(M);
340 template <
int RowT,
int ColT>
341 static Scalar&
Get(MatrixT& M)
344 MatrixLayoutIs2D<MatrixT>()>::template Get<RowT, ColT>(M);
static const Scalar & Get(const MatrixT &M)
static Scalar & Get(MatrixT &M)
static const Scalar & Get(const MatrixT &M)
static Scalar & Get(MatrixT &M)
const Scalar & Get(const MatrixT &M)
static Scalar & Get(MatrixT &M)
static const Scalar & Get(const MatrixT &M)
static Scalar & Get(MatrixT &M)
static const Scalar & Get(const MatrixT &M)
static constexpr bool MatrixIsPointerToPointer()
At compile time, returns true if the templated parameter is a pointer to pointer (double** for instan...
static constexpr bool MatrixIs2DArray()
At compile time, returns true if the templated parameter is a 2D array (double[3][3] for instance),...
static constexpr bool MatrixLayoutIs2D()
At compile time, returns true if the templated parameter layout is 2D, i.e.
This struct determines a prior transform to input matrices, changing the way they are indexed.
This class is a helper class to compute at compile time the index of a matrix stored as a 1D array fr...
static constexpr int GetIndex()
static constexpr int GetIndex()
static constexpr int GetIndex()