15#ifndef vtkMatrixUtilities_h
16#define vtkMatrixUtilities_h
18#include "vtkABINamespace.h"
25VTK_ABI_NAMESPACE_BEGIN
52template <
int ContainerTypeT,
class ContainerT>
55 typedef typename std::decay<typename std::decay<ContainerT>::type::value_type>::type
value_type;
56 static_assert(std::is_integral<value_type>::value || std::is_floating_point<value_type>::value,
57 "value_type is not a numeric type");
61template <
class ContainerT>
65 typedef typename std::remove_reference<ContainerT>::type DerefContainer;
68 typedef typename std::decay<
typename std::remove_pointer<
typename std::remove_all_extents<
69 typename std::remove_pointer<DerefContainer>::type>::type>::type>::type
value_type;
71 static_assert(std::is_integral<value_type>::value || std::is_floating_point<value_type>::value,
72 "value_type is not a numeric type");
76template <
class MatrixT,
int Depth = 0>
79 static constexpr int Value = Depth;
83template <
class MatrixT,
int Depth>
90template <
class MatrixT,
int N,
int Depth>
97template <
class MatrixT,
int Depth>
104template <
class MatrixT,
int Depth>
116template <
class MatrixT>
125template <
class MatrixT,
class =
void>
129template <
class MatrixT>
132 using Type =
decltype(std::declval<MatrixT>()[0][0]);
136template <
class MatrixT>
139 using Type =
decltype(std::declval<MatrixT>()[0]);
152template <
class ContainerT>
156 typedef typename std::remove_reference<ContainerT>::type DerefContainer;
164 std::is_array<DerefContainer>::value || std::is_pointer<DerefContainer>::value,
166 static_assert(std::is_integral<value_type>::value || std::is_floating_point<value_type>::value,
167 "value_type is not a numeric type");
178 using ComponentType =
typename std::conditional<std::is_rvalue_reference<RawComponentType>::value,
179 typename std::remove_reference<RawComponentType>::type,
RawComponentType>::type;
187template <
class MatrixT>
190 typedef typename std::remove_pointer<MatrixT>::type Row;
191 typedef typename std::remove_pointer<Row>::type Value;
192 return std::is_pointer<MatrixT>::value && std::is_pointer<Row>::value &&
193 !std::is_pointer<Value>::value;
201template <
class MatrixT>
210template <
int RowsT,
int ColsT,
class LayoutT>
214template <
int RowsT,
int ColsT>
217 template <
int RowT,
int ColT>
220 static_assert(RowT >= 0 && RowT < RowsT,
"RowT out of bounds");
221 static_assert(ColT >= 0 && ColT < ColsT,
"ColT out of bounds");
222 return ColsT * RowT + ColT;
226template <
int RowsT,
int ColsT>
229 template <
int RowT,
int ColT>
232 static_assert(RowT >= 0 && RowT < RowsT,
"RowT out of bounds");
233 static_assert(ColT >= 0 && ColT < ColsT,
"ColT out of bounds");
234 return RowsT * ColT + RowT;
251template <
int RowsT,
int ColsT,
class LayoutT = Layout::Identity>
254 template <
int RowT,
int ColT>
264template <
int RowsT,
int ColsT,
class MatrixT,
class LayoutT,
bool MatrixLayoutIs2DT>
269template <
int RowsT,
int ColsT,
class MatrixT,
class LayoutT>
270class Wrapper<RowsT, ColsT, MatrixT, LayoutT, false>
276 template <
int RowT,
int ColT,
class MatrixTT>
277 static ComponentType
Get(MatrixTT&& M)
284template <
int RowsT,
int ColsT,
class MatrixT>
291 template <
int RowT,
int ColT,
class MatrixTT>
292 static ComponentType
Get(MatrixTT&& M)
294 return M[RowT][ColT];
299template <
int RowsT,
int ColsT,
class MatrixT>
306 template <
int RowT,
int ColT,
class MatrixTT>
307 static ComponentType
Get(MatrixTT&& M)
309 return M[ColT][RowT];
315template <
int RowsT,
int ColsT,
class MatrixT>
322 template <
int RowT,
int ColT>
325 static constexpr Scalar
ZERO = Scalar(0);
327 template <
class MatrixTT>
328 static ComponentType
Get(MatrixTT&&)
335 struct Helper<RowT, RowT>
337 template <
class MatrixTT>
338 static ComponentType
Get(MatrixTT&& M)
345 template <
int RowT,
int ColT,
class MatrixTT>
346 ComponentType
Get(MatrixTT& M)
348 return Helper<RowT, ColT>::Get(std::forward<MatrixTT>(M));
368template <
int RowsT,
int ColsT,
class MatrixT,
class LayoutT = Layout::Identity>
376 "A diagonal matrix cannot be a 2D array");
379 template <
int RowT,
int ColT,
class MatrixTT>
380 static ComponentType
Get(MatrixTT&& M)
static ComponentType Get(MatrixTT &&M)
static ComponentType Get(MatrixTT &&M)
ComponentType Get(MatrixTT &M)
static ComponentType Get(MatrixTT &&M)
static ComponentType Get(MatrixTT &&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 Value
static constexpr int Value
static constexpr int Value
static constexpr int Value
static constexpr int Value
static constexpr int GetIndex()
static constexpr int GetIndex()