54 lines
1.2 KiB
C++
54 lines
1.2 KiB
C++
#ifndef U_VTK_DENSE_H
|
|
#define U_VTK_DENSE_H
|
|
|
|
#include "Math/Dense.h"
|
|
#include <vtkMatrix4x4.h>
|
|
|
|
namespace uLib {
|
|
namespace Vtk {
|
|
|
|
/**
|
|
* @brief Converts a uLib::Matrix4f to an existing vtkMatrix4x4.
|
|
* @param src The source Eigen matrix.
|
|
* @param dst The destination vtkMatrix4x4.
|
|
*/
|
|
inline void Matrix4fToVtk(const Matrix4f& src, vtkMatrix4x4* dst) {
|
|
if (!dst)
|
|
return;
|
|
for (int i = 0; i < 4; ++i)
|
|
for (int j = 0; j < 4; ++j)
|
|
dst->SetElement(i, j, src(i, j));
|
|
}
|
|
|
|
/**
|
|
* @brief Converts a uLib::Matrix4f to a new vtkMatrix4x4.
|
|
* @param src The source Eigen matrix.
|
|
* @return A new vtkMatrix4x4 (caller is responsible for management/deletion).
|
|
*/
|
|
inline vtkMatrix4x4* Matrix4fToVtk(const Matrix4f& src) {
|
|
vtkMatrix4x4* dst = vtkMatrix4x4::New();
|
|
Matrix4fToVtk(src, dst);
|
|
return dst;
|
|
}
|
|
|
|
/**
|
|
* @brief Converts a vtkMatrix4x4 to a uLib::Matrix4f.
|
|
* @param src The source vtkMatrix4x4.
|
|
* @return The converted uLib::Matrix4f matrix.
|
|
*/
|
|
inline Matrix4f VtkToMatrix4f(vtkMatrix4x4* src) {
|
|
Matrix4f dst;
|
|
if (!src) {
|
|
dst.setIdentity();
|
|
return dst;
|
|
}
|
|
for (int i = 0; i < 4; ++i)
|
|
for (int j = 0; j < 4; ++j)
|
|
dst(i, j) = src->GetElement(i, j);
|
|
return dst;
|
|
}
|
|
|
|
} // namespace Vtk
|
|
} // namespace uLib
|
|
|
|
#endif // U_VTK_DENSE_H
|