3 #include <Core/Containers/AlignedStdVector.hpp>
4 #include <Core/RaCore.hpp>
5 #include <Core/Utils/ContainerIntrospectionInterface.hpp>
15 template <
typename V,
bool isArithmetic,
bool isEigen>
25 std::is_arithmetic<V>::value || std::is_enum<V>::value,
26 std::is_base_of<typename Eigen::MatrixBase<V>, V>::value> {};
40 static constexpr
int NumberOfComponents = TypeHelper::NumberOfComponents;
47 using Matrix = Eigen::Matrix<component_type, TypeHelper::NumberOfComponents, Eigen::Dynamic>;
48 using MatrixMap = Eigen::Map<Matrix>;
49 using ConstMatrixMap = Eigen::Map<const Matrix>;
52 using AlignedStdVector<V>::AlignedStdVector;
56 size_t getSize()
const override {
return this->size(); }
59 int getStride()
const override {
return sizeof( V ); }
60 const void*
dataPtr()
const override {
return this->data(); }
69 template <
int N = NumberOfComponents>
70 std::enable_if_t<( N > 0 ), MatrixMap>
getMap() {
71 CORE_ASSERT( !this->empty(),
"Cannot map an empty vector " );
72 return MatrixMap( TypeHelper::getData(
this ),
73 TypeHelper::NumberOfComponents,
74 Eigen::Index( this->size() ) );
78 template <
int N = NumberOfComponents>
79 std::enable_if_t<( N > 0 ), ConstMatrixMap>
getMap()
const {
80 CORE_ASSERT( !this->empty(),
"Cannot map an empty vector " );
81 return ConstMatrixMap( TypeHelper::getConstData(
this ),
82 TypeHelper::NumberOfComponents,
83 Eigen::Index( this->size() ) );
90 using component_type = V;
91 static constexpr
int NumberOfComponents = 1;
92 static inline component_type* getData(
VectorArray<V>* v ) {
return v->data(); }
93 static inline const component_type* getConstData(
const VectorArray<V>* v ) {
99 struct VectorArrayTypeHelperInternal<V, false, true> {
100 using component_type =
typename V::Scalar;
101 static constexpr
int NumberOfComponents = V::RowsAtCompileTime;
102 static inline component_type* getData( VectorArray<V>* v ) {
return v->data()->data(); }
103 static inline const component_type* getConstData(
const VectorArray<V>* v ) {
104 return v->data()->data();
108 template <
typename V>
109 struct VectorArrayTypeHelperInternal<V, false, false> {
110 using component_type = V;
111 static constexpr
int NumberOfComponents = 0;
112 static inline component_type* getData( VectorArray<V>* v ) {
return v->data(); }
113 static inline const component_type* getConstData(
const VectorArray<V>* v ) {
119 using Vector1Array = VectorArray<Scalar>;
120 #define DEFINE_CONVENIENCE_MATRIX_ALIAS( NAME, TYPE, DIM ) \
121 using NAME = VectorArray<Eigen::Matrix<TYPE, DIM, 1>>;
122 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector2Array, Scalar, 2 )
123 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector3Array, Scalar, 3 )
124 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector4Array, Scalar, 4 )
125 DEFINE_CONVENIENCE_MATRIX_ALIAS( VectorNArray, Scalar, Eigen::Dynamic )
126 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector1iArray,
int, 1 )
127 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector2iArray,
int, 2 )
128 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector3iArray,
int, 3 )
129 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector4iArray,
int, 4 )
130 DEFINE_CONVENIENCE_MATRIX_ALIAS( VectorNiArray,
int, Eigen::Dynamic )
131 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector1uArray, uint, 1 )
132 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector2uArray, uint, 2 )
133 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector3uArray, uint, 3 )
134 DEFINE_CONVENIENCE_MATRIX_ALIAS( Vector4uArray, uint, 4 )
135 DEFINE_CONVENIENCE_MATRIX_ALIAS( VectorNuArray, uint, Eigen::Dynamic )
136 #undef DEFINE_CONVENIENCE_MATRIX_ALIAS
This class defines the introspection interface a container need to implement.
This class implements ContainerIntrospectionInterface for AlignedStdVector.
std::enable_if_t<(N > 0), ConstMatrixMap > getMap() const
const void * dataPtr() const override
std::enable_if_t<(N > 0), MatrixMap > getMap()
typename TypeHelper::component_type component_type
size_t getNumberOfComponents() const override
int getStride() const override
size_t getSize() const override
size_t getBufferSize() const override