8#ifndef META_OCEAN_CV_EIGEN_UTILITIES_H
9#define META_OCEAN_CV_EIGEN_UTILITIES_H
19 #pragma warning(disable: 4244)
20#elif defined(__clang__)
21 #pragma clang diagnostic push
22 #pragma clang diagnostic ignored "-Wconversion"
29#elif defined(__clang__)
30 #pragma clang diagnostic pop
54 static bool frame2matrix(
const Frame& frame, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>& matrix);
63 static bool frame2matrix(
const Frame& frame, Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>& matrix);
71 template <
typename TType>
80 template <
typename TType>
89 template <
typename TType>
98 template <
typename TType>
107 template <
typename TType>
116 template <
typename TType>
125 template <
typename TType>
134 template <
typename TType>
148 ocean_assert((matrix.Flags & Eigen::RowMajorBit) == 0);
150 Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> rowMajorMatrix(frame.
height(), frame.
width());
152 constexpr unsigned int matrixPaddingElements = 0u;
156 CV::FrameConverter::cast<uint8_t, T>(frame.
constdata<uint8_t>(), rowMajorMatrix.data(), frame.
width(), frame.
height(), 1u, frame.
paddingElements(), matrixPaddingElements);
164 ocean_assert(
false &&
"Data type not supported!");
168 matrix = rowMajorMatrix;
170 ocean_assert((matrix.Flags & Eigen::RowMajorBit) == 0);
185 ocean_assert((matrix.Flags & Eigen::RowMajorBit) != 0);
189 constexpr unsigned int matrixPaddingElements = 0u;
202 ocean_assert(
false &&
"Data type not supported!");
206template <
typename TType>
209 return Eigen::Matrix<TType, 2, 1>(ocnVector.
data());
212template <
typename TType>
215 return Eigen::Matrix<TType, 3, 1>(ocnVector.
data());
218template <
typename TType>
221 return Eigen::Matrix<TType, 4, 1>(ocnVector.
data());
224template <
typename TType>
230template <
typename TType>
236template <
typename TType>
242template <
typename TType>
245 static_assert(std::is_same<TType, float>::value || std::is_same<TType, double>::value,
"Invalid value for type TType");
247 return Eigen::Quaternion<TType>(ocnQuaternion.
w(), ocnQuaternion.
x(), ocnQuaternion.
y(), ocnQuaternion.
z());
250template <
typename TType>
253 static_assert(std::is_same<TType, float>::value || std::is_same<TType, double>::value,
"Invalid value for type TType");
255 return QuaternionT<TType>(eigenQuaternion.w(), eigenQuaternion.x(), eigenQuaternion.y(), eigenQuaternion.z());
This class provides several helper classes allowing to convert between Ocean data structures and Eige...
Definition EigenUtilities.h:44
static VectorT2< TType > toOceanVector(const Eigen::Matrix< TType, 2, 1 > &eigenVector)
Converts an Eigen 2D vector to a corresponding Ocean vector.
Definition EigenUtilities.h:225
static Eigen::Matrix< TType, 2, 1 > toEigenVector(const VectorT2< TType > &ocnVector)
Converts an Ocean 2D vector to a corresponding Eigen vector.
Definition EigenUtilities.h:207
static Eigen::Quaternion< TType > toEigenQuaternion(const QuaternionT< TType > &ocnQuaternion)
Converts an Ocean quaternion to an Eigen quaternion.
Definition EigenUtilities.h:243
static bool frame2matrix(const Frame &frame, Eigen::Matrix< T, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor > &matrix)
Converts a frame to an Eigen matrix with column major memory layout (default in Eigen).
Definition EigenUtilities.h:139
static QuaternionT< TType > toOceanQuaternion(const Eigen::Quaternion< TType > &eigenQuaternion)
Converts an Eigen quaternion to an Ocean quaternion.
Definition EigenUtilities.h:251
This class implements Ocean's image class.
Definition Frame.h:1808
const T * constdata(const unsigned int planeIndex=0u) const
Returns a pointer to the read-only pixel data of a specific plane.
Definition Frame.h:4248
bool isValid() const
Returns whether this frame is valid.
Definition Frame.h:4528
unsigned int paddingElements(const unsigned int planeIndex=0u) const
Returns the optional number of padding elements at the end of each row for a specific plane.
Definition Frame.h:4122
unsigned int width() const
Returns the width of the frame format in pixel.
Definition Frame.h:3170
uint32_t numberPlanes() const
Returns the number of planes of the pixel format of this frame.
Definition Frame.h:3210
PixelFormat pixelFormat() const
Returns the pixel format of the frame.
Definition Frame.h:3180
@ DT_UNSIGNED_INTEGER_8
Unsigned 8 bit integer data type (uint8_t).
Definition Frame.h:41
@ DT_SIGNED_FLOAT_32
Signed 32 bit float data type (float).
Definition Frame.h:59
unsigned int height() const
Returns the height of the frame in pixel.
Definition Frame.h:3175
unsigned int channels() const
Returns the number of individual channels the frame has.
Definition Frame.h:3200
static bool formatIsGeneric(const PixelFormat pixelFormat, const DataType dataType, const uint32_t channels, const uint32_t planes=1u, const uint32_t widthMultiple=1u, const uint32_t heightMultiple=1u)
Checks whether a given pixel format is a specific layout regarding data channels and data type.
Definition Frame.h:3435
This class implements a unit quaternion rotation.
Definition Quaternion.h:100
const T & x() const
Returns the x value of the quaternion.
Definition Quaternion.h:917
const T & w() const
Returns the w value of the quaternion.
Definition Quaternion.h:905
const T & y() const
Returns the y value of the quaternion.
Definition Quaternion.h:929
const T & z() const
Returns the z value of the quaternion.
Definition Quaternion.h:941
This class implements a vector with two elements.
Definition Vector2.h:96
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector2.h:734
This class implements a vector with three elements.
Definition Vector3.h:97
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector3.h:854
This class implements a vector with four elements.
Definition Vector4.h:97
const T * data() const noexcept
Returns an pointer to the vector elements.
Definition Vector4.h:732
The namespace covering the entire Ocean framework.
Definition Accessor.h:15