DetectorChamber vtk handler
This commit is contained in:
@@ -29,63 +29,147 @@
|
|||||||
#define U_CONTAINERBOX_H
|
#define U_CONTAINERBOX_H
|
||||||
|
|
||||||
#include "Geometry.h"
|
#include "Geometry.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Math/Transform.h"
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Represents an oriented bounding box (OBB) within a hierarchical transformation system.
|
||||||
|
*
|
||||||
|
* ContainerBox inherits from AffineTransform, which defines its parent coordinate system.
|
||||||
|
* It contains an internal local transformation (m_LocalT) that defines the box's
|
||||||
|
* specific origin and size relative to its own coordinate system.
|
||||||
|
*/
|
||||||
class ContainerBox : public AffineTransform {
|
class ContainerBox : public AffineTransform {
|
||||||
public:
|
|
||||||
ContainerBox() : m_LocalT(this) {}
|
|
||||||
|
|
||||||
|
typedef AffineTransform BaseClass;
|
||||||
|
|
||||||
|
public:
|
||||||
|
/**
|
||||||
|
* @brief Default constructor.
|
||||||
|
* Initializes the local transformation with this instance as its parent.
|
||||||
|
*/
|
||||||
|
ContainerBox() :
|
||||||
|
m_LocalT(this) // BaseClass is Parent of m_LocalTransform
|
||||||
|
{}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy constructor.
|
||||||
|
* @param copy The ContainerBox instance to copy from.
|
||||||
|
*/
|
||||||
ContainerBox(const ContainerBox ©) :
|
ContainerBox(const ContainerBox ©) :
|
||||||
m_LocalT(this),
|
m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||||
AffineTransform(copy)
|
AffineTransform(copy)
|
||||||
{
|
{
|
||||||
// FIX for performance //
|
|
||||||
this->SetOrigin(copy.GetOrigin());
|
this->SetOrigin(copy.GetOrigin());
|
||||||
this->SetSize(copy.GetSize());
|
this->SetSize(copy.GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the box origin relative to its coordinate system.
|
||||||
|
* @param v The origin position vector.
|
||||||
|
*/
|
||||||
inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
|
inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the box origin relative to its coordinate system.
|
||||||
|
* @return The origin position vector.
|
||||||
|
*/
|
||||||
inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
|
inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the size of the box.
|
||||||
|
* Re-initializes the local transformation and applies the new scale.
|
||||||
|
* @param v The size vector (width, height, depth).
|
||||||
|
*/
|
||||||
void SetSize(const Vector3f &v) {
|
void SetSize(const Vector3f &v) {
|
||||||
Vector3f pos = this->GetOrigin();
|
Vector3f pos = this->GetOrigin();
|
||||||
m_LocalT = AffineTransform(this);
|
m_LocalT = AffineTransform(this); // regenerate local transform
|
||||||
m_LocalT.Scale(v);
|
m_LocalT.Scale(v);
|
||||||
m_LocalT.SetPosition(pos);
|
m_LocalT.SetPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the current size (scale) of the box.
|
||||||
|
* @return The size vector.
|
||||||
|
*/
|
||||||
inline Vector3f GetSize() const { return m_LocalT.GetScale(); }
|
inline Vector3f GetSize() const { return m_LocalT.GetScale(); }
|
||||||
|
|
||||||
// FIX... //
|
/**
|
||||||
|
* @brief Swaps two local axes of the box.
|
||||||
|
* @param first Index of the first axis (0=X, 1=Y, 2=Z).
|
||||||
|
* @param second Index of the second axis (0=X, 1=Y, 2=Z).
|
||||||
|
*/
|
||||||
inline void FlipLocalAxes(int first, int second)
|
inline void FlipLocalAxes(int first, int second)
|
||||||
{ m_LocalT.FlipAxes(first,second); }
|
{ m_LocalT.FlipAxes(first,second); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the world transformation matrix of the box's volume.
|
||||||
|
* @return A 4x4 transformation matrix.
|
||||||
|
*/
|
||||||
Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); }
|
Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the local transformation matrix of the box's volume.
|
||||||
|
* @return A 4x4 transformation matrix.
|
||||||
|
*/
|
||||||
|
Matrix4f GetLocalMatrix() const { return m_LocalT.GetMatrix(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from box-local space to world space.
|
||||||
|
* @param v The local point (4D homogeneous vector).
|
||||||
|
* @return The transformed point in world space.
|
||||||
|
*/
|
||||||
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
||||||
return m_LocalT.GetWorldMatrix() * v;
|
return m_LocalT.GetWorldMatrix() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from box-local space coordinates to world space.
|
||||||
|
* @param x X coordinate in local space.
|
||||||
|
* @param y Y coordinate in local space.
|
||||||
|
* @param z Z coordinate in local space.
|
||||||
|
* @return The transformed point in world space.
|
||||||
|
*/
|
||||||
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
|
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
|
||||||
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from world space to box-local space.
|
||||||
|
* @param v The world point (4D homogeneous vector).
|
||||||
|
* @return The transformed point in box-local space.
|
||||||
|
*/
|
||||||
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
||||||
return m_LocalT.GetWorldMatrix().inverse() * v;
|
return m_LocalT.GetWorldMatrix().inverse() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from world space coordinates to box-local space.
|
||||||
|
* @param x X coordinate in world space.
|
||||||
|
* @param y Y coordinate in world space.
|
||||||
|
* @param z Z coordinate in world space.
|
||||||
|
* @return The transformed point in box-local space.
|
||||||
|
*/
|
||||||
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
|
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
|
||||||
return this->GetLocalPoint(Vector4f(x,y,z,1));
|
return this->GetLocalPoint(Vector4f(x,y,z,1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Translate using transformation chain */
|
||||||
|
using BaseClass::Translate;
|
||||||
|
|
||||||
protected:
|
/** Rotate using transformation chain */
|
||||||
|
using BaseClass::Rotate;
|
||||||
|
|
||||||
|
/** Scale using transformation chain */
|
||||||
|
using BaseClass::Scale;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AffineTransform m_LocalT;
|
AffineTransform m_LocalT;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace uLib {
|
|||||||
class Geometry : public AffineTransform {
|
class Geometry : public AffineTransform {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
inline Vector4f GetWorldPoint(const Vector4f v) const {
|
||||||
return this->GetWorldMatrix() * v;
|
return this->GetWorldMatrix() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
inline Vector4f GetLocalPoint(const Vector4f v) const {
|
||||||
return this->GetWorldMatrix().inverse() * v;
|
return this->GetWorldMatrix().inverse() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ public:
|
|||||||
|
|
||||||
inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
|
inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
|
||||||
|
|
||||||
inline void SetMatrix (Matrix4f &mat) { m_T.matrix() = mat; }
|
inline void SetMatrix (Matrix4f mat) { m_T.matrix() = mat; }
|
||||||
inline Matrix4f& GetMatrix () { return m_T.matrix(); }
|
inline Matrix4f GetMatrix() const { return m_T.matrix(); }
|
||||||
|
|
||||||
Matrix4f GetWorldMatrix() const
|
Matrix4f GetWorldMatrix() const
|
||||||
{
|
{
|
||||||
@@ -93,22 +93,22 @@ public:
|
|||||||
else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
|
else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetPosition(const Vector3f &v) { this->m_T.translation() = v; }
|
inline void SetPosition(const Vector3f v) { this->m_T.translation() = v; }
|
||||||
|
|
||||||
inline Vector3f GetPosition() const { return this->m_T.translation(); }
|
inline Vector3f GetPosition() const { return this->m_T.translation(); }
|
||||||
|
|
||||||
inline void SetRotation(const Matrix3f &m) { this->m_T.linear() = m; }
|
inline void SetRotation(const Matrix3f m) { this->m_T.linear() = m; }
|
||||||
|
|
||||||
inline Matrix3f GetRotation() const { return this->m_T.rotation(); }
|
inline Matrix3f GetRotation() const { return this->m_T.rotation(); }
|
||||||
|
|
||||||
inline void Translate(const Vector3f &v) { this->m_T.translate(v); }
|
inline void Translate(const Vector3f v) { this->m_T.translate(v); }
|
||||||
|
|
||||||
inline void Scale(const Vector3f &v) { this->m_T.scale(v); }
|
inline void Scale(const Vector3f v) { this->m_T.scale(v); }
|
||||||
|
|
||||||
inline Vector3f GetScale() const { return this->m_T.linear() * Vector3f(1,1,1); } // FIXXXXXXX
|
inline Vector3f GetScale() const { return this->m_T.linear() * Vector3f(1,1,1); } // FIXXXXXXX
|
||||||
|
|
||||||
|
|
||||||
inline void Rotate(const Matrix3f &m) { this->m_T.rotate(m); }
|
inline void Rotate(const Matrix3f m) { this->m_T.rotate(m); }
|
||||||
|
|
||||||
inline void Rotate(const float angle, Vector3f axis)
|
inline void Rotate(const float angle, Vector3f axis)
|
||||||
{
|
{
|
||||||
@@ -122,12 +122,12 @@ public:
|
|||||||
Rotate(angle,euler_axis);
|
Rotate(angle,euler_axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); }
|
inline void PreRotate(const Matrix3f m) { this->m_T.prerotate(m); }
|
||||||
|
|
||||||
inline void QuaternionRotate(const Vector4f &q)
|
inline void QuaternionRotate(const Vector4f q)
|
||||||
{ this->m_T.rotate(Eigen::Quaternion<float>(q)); }
|
{ this->m_T.rotate(Eigen::Quaternion<float>(q)); }
|
||||||
|
|
||||||
inline void EulerYZYRotate(const Vector3f &e) {
|
inline void EulerYZYRotate(const Vector3f e) {
|
||||||
Matrix3f mat;
|
Matrix3f mat;
|
||||||
mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY())
|
mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY())
|
||||||
* Eigen::AngleAxisf(e.y(), Vector3f::UnitZ())
|
* Eigen::AngleAxisf(e.y(), Vector3f::UnitZ())
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -52,41 +53,82 @@ int main()
|
|||||||
|
|
||||||
BEGIN_TESTING(Math ContainerBox);
|
BEGIN_TESTING(Math ContainerBox);
|
||||||
|
|
||||||
ContainerBox Cnt;
|
{
|
||||||
|
ContainerBox Cnt;
|
||||||
// // Local transform:
|
Cnt.SetOrigin(Vector3f(0,0,0));
|
||||||
Cnt.SetOrigin(Vector3f(-1,-1,-1));
|
Cnt.SetSize(Vector3f(2,2,2));
|
||||||
Cnt.SetSize(Vector3f(2,2,2)); // scaling //
|
TEST0( Vector4f0(Cnt.GetOrigin().homogeneous() - HVector3f(0,0,0)) );
|
||||||
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
|
TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) );
|
||||||
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
|
|
||||||
TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) );
|
|
||||||
|
|
||||||
|
|
||||||
ContainerBox Box;
|
HPoint3f pt = Cnt.GetLocalPoint(HPoint3f(0,0,0));
|
||||||
|
HPoint3f wp = Cnt.GetWorldPoint(pt);
|
||||||
|
TEST0( Vector4f0(wp - HPoint3f(0,0,0)) );
|
||||||
|
|
||||||
Box.SetPosition(Vector3f(1,1,1));
|
HPoint3f pt2 = Cnt.GetLocalPoint(HPoint3f(2,2,2));
|
||||||
Box.SetSize(Vector3f(2,2,2));
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
Box.EulerYZYRotate(Vector3f(0,0,0));
|
TEST0( Vector4f0(wp2 - HPoint3f(2,2,2)) );
|
||||||
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
|
|
||||||
HPoint3f wp = Box.GetWorldPoint(pt);
|
|
||||||
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
|
|
||||||
|
|
||||||
|
HPoint3f pt3 = Cnt.GetLocalPoint(HPoint3f(1,1,1));
|
||||||
|
HPoint3f wp3 = Cnt.GetWorldPoint(pt3);
|
||||||
|
TEST0( Vector4f0(wp3 - HPoint3f(1,1,1)) );
|
||||||
|
|
||||||
//// // Global
|
HPoint3f pt4 = Cnt.GetLocalPoint(HPoint3f(1,2,3));
|
||||||
// Cnt.SetPosition(Vector3f(1,1,1));
|
HPoint3f wp4 = Cnt.GetWorldPoint(pt4);
|
||||||
// Cnt.EulerYZYRotate(Vector3f(M_PI_2,M_PI_2,0));
|
TEST0( Vector4f0(wp4 - HPoint3f(1,2,3)) );
|
||||||
// HPoint3f p = Cnt.GetWorldPoint(1,1,1);
|
}
|
||||||
// //std::cout << p.transpose() << "\n";
|
|
||||||
// TEST0( Vector4f0(p - HVector3f(2,1,2)) );
|
|
||||||
// p = Cnt.GetWorldPoint(1,2,3);
|
|
||||||
// //std::cout << p.transpose() << "\n";
|
|
||||||
// TEST0( Vector4f0(p - HVector3f(4,1,3)) );
|
|
||||||
|
|
||||||
|
{
|
||||||
|
ContainerBox Cnt;
|
||||||
|
Cnt.SetOrigin(Vector3f(0,0,0));
|
||||||
|
Cnt.SetSize(Vector3f(2,2,2));
|
||||||
|
Cnt.EulerYZYRotate(Vector3f(M_PI,0,0));
|
||||||
|
|
||||||
|
HPoint3f pt = Cnt.GetLocalPoint(HPoint3f(0,0,0));
|
||||||
|
HPoint3f wp = Cnt.GetWorldPoint(pt);
|
||||||
|
TEST0( Vector4f0(wp - HPoint3f(0,0,0)) );
|
||||||
|
|
||||||
// // scaling //
|
HPoint3f pt2 = Cnt.GetLocalPoint(HPoint3f(2,2,2));
|
||||||
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(2,2,2)) );
|
||||||
|
|
||||||
|
pt2 = HPoint3f(1,1,1);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(-2,2,-2)) );
|
||||||
|
|
||||||
|
pt2 = HPoint3f(1,2,3);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(-2,4,-6)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ContainerBox Cnt;
|
||||||
|
Cnt.SetOrigin(Vector3f(-1,-1,-1));
|
||||||
|
Cnt.SetSize(Vector3f(2,2,2)); // scaling //
|
||||||
|
|
||||||
|
HPoint3f pt2 = HPoint3f(.5,.5,.5);
|
||||||
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(0,0,0)) );
|
||||||
|
|
||||||
|
pt2 = HPoint3f(0,0,0);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(-1,-1,-1)) );
|
||||||
|
|
||||||
|
Cnt.EulerYZYRotate(Vector3f(M_PI,0,0));
|
||||||
|
pt2 = HPoint3f(0,0,0);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(1,-1,1)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ContainerBox Box;
|
||||||
|
Box.SetPosition(Vector3f(1,1,1));
|
||||||
|
Box.SetSize(Vector3f(2,2,2));
|
||||||
|
Box.EulerYZYRotate(Vector3f(0,0,0));
|
||||||
|
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
|
||||||
|
HPoint3f wp = Box.GetWorldPoint(pt);
|
||||||
|
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
|
||||||
|
}
|
||||||
|
|
||||||
END_TESTING;
|
END_TESTING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -243,15 +243,14 @@ void init_math(py::module_ &m) {
|
|||||||
.def("Scale", &AffineTransform::Scale)
|
.def("Scale", &AffineTransform::Scale)
|
||||||
.def("SetRotation", &AffineTransform::SetRotation)
|
.def("SetRotation", &AffineTransform::SetRotation)
|
||||||
.def("GetRotation", &AffineTransform::GetRotation)
|
.def("GetRotation", &AffineTransform::GetRotation)
|
||||||
.def("Rotate", py::overload_cast<const Matrix3f &>(&AffineTransform::Rotate))
|
.def("Rotate", &AffineTransform::Rotate)
|
||||||
.def("Rotate", py::overload_cast<const Vector3f>(&AffineTransform::Rotate))
|
|
||||||
.def("EulerYZYRotate", &AffineTransform::EulerYZYRotate)
|
.def("EulerYZYRotate", &AffineTransform::EulerYZYRotate)
|
||||||
.def("FlipAxes", &AffineTransform::FlipAxes);
|
.def("FlipAxes", &AffineTransform::FlipAxes);
|
||||||
|
|
||||||
py::class_<Geometry, AffineTransform>(m, "Geometry")
|
py::class_<Geometry, AffineTransform>(m, "Geometry")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(&Geometry::GetWorldPoint, py::const_))
|
.def("GetWorldPoint", &Geometry::GetWorldPoint)
|
||||||
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(&Geometry::GetLocalPoint, py::const_));
|
.def("GetLocalPoint", &Geometry::GetLocalPoint);
|
||||||
|
|
||||||
py::class_<ContainerBox, AffineTransform>(m, "ContainerBox")
|
py::class_<ContainerBox, AffineTransform>(m, "ContainerBox")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
@@ -260,8 +259,8 @@ void init_math(py::module_ &m) {
|
|||||||
.def("SetSize", &ContainerBox::SetSize)
|
.def("SetSize", &ContainerBox::SetSize)
|
||||||
.def("GetSize", &ContainerBox::GetSize)
|
.def("GetSize", &ContainerBox::GetSize)
|
||||||
.def("GetWorldMatrix", &ContainerBox::GetWorldMatrix)
|
.def("GetWorldMatrix", &ContainerBox::GetWorldMatrix)
|
||||||
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(&ContainerBox::GetWorldPoint, py::const_))
|
.def("GetWorldPoint", &ContainerBox::GetWorldPoint)
|
||||||
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(&ContainerBox::GetLocalPoint, py::const_));
|
.def("GetLocalPoint", &ContainerBox::GetLocalPoint);
|
||||||
|
|
||||||
py::enum_<StructuredData::_Order>(m, "StructuredDataOrder")
|
py::enum_<StructuredData::_Order>(m, "StructuredDataOrder")
|
||||||
.value("CustomOrder", StructuredData::CustomOrder)
|
.value("CustomOrder", StructuredData::CustomOrder)
|
||||||
|
|||||||
@@ -13,3 +13,4 @@ set(LIBRARIES
|
|||||||
)
|
)
|
||||||
|
|
||||||
uLib_add_tests(VtkDetectors)
|
uLib_add_tests(VtkDetectors)
|
||||||
|
|
||||||
|
|||||||
@@ -33,11 +33,16 @@
|
|||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(vtkDetectorChamberTest) {
|
BOOST_AUTO_TEST_CASE(vtkDetectorChamberTest) {
|
||||||
uLib::DetectorChamber d1, d2;
|
uLib::DetectorChamber d1, d2;
|
||||||
d1.SetSize(uLib::Vector3f(10, 20, 2));
|
d1.SetSize(uLib::Vector3f(1, 1, 1));
|
||||||
d1.SetPosition(uLib::Vector3f(0, 0, 0));
|
d1.SetPosition(uLib::Vector3f(0, 0, 0));
|
||||||
|
d1.Scale(uLib::Vector3f(5, 10, 2));
|
||||||
|
d1.Translate(uLib::Vector3f(0, 0, 0));
|
||||||
|
|
||||||
|
d2.SetSize(uLib::Vector3f(1, 1, 1));
|
||||||
|
d2.SetPosition(uLib::Vector3f(0, 0, 0));
|
||||||
|
d2.Scale(uLib::Vector3f(5, 10, 2));
|
||||||
|
d2.Translate(uLib::Vector3f(0, 0, 10));
|
||||||
|
|
||||||
d2.SetSize(uLib::Vector3f(10, 20, 2));
|
|
||||||
d2.SetPosition(uLib::Vector3f(0, 0, 20));
|
|
||||||
|
|
||||||
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber(&d1);
|
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber(&d1);
|
||||||
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber2(&d2);
|
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber2(&d2);
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include <vtkAbstractTransform.h>
|
||||||
#include <vtkAxes.h>
|
#include <vtkAxes.h>
|
||||||
#include <vtkCubeSource.h>
|
#include <vtkCubeSource.h>
|
||||||
#include <vtkLineSource.h>
|
#include <vtkLineSource.h>
|
||||||
@@ -38,23 +39,31 @@
|
|||||||
#include <vtkTransform.h>
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||||
#include "Vtk/vtkHandlerWidget.h"
|
#include <vtkBoxWidget.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content)
|
vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content)
|
||||||
: vtkContainerBox(content) {
|
: vtkContainerBox(content), m_Actor(vtkActor::New()),
|
||||||
m_Widget = vtkHandlerWidget::New();
|
m_Widget(vtkBoxWidget::New()) {
|
||||||
m_Callback = vtkWidgetCallback::New();
|
m_Callback = vtkWidgetCallback::New();
|
||||||
m_PickerCallback = vtkSelectionCallback::New();
|
m_PickerCallback = vtkSelectionCallback::New();
|
||||||
|
|
||||||
m_Callback->SetChamber(this);
|
m_Callback->SetChamber(this);
|
||||||
m_PickerCallback->SetChamber(this);
|
m_PickerCallback->SetChamber(this);
|
||||||
m_Widget->AddObserver(vtkCommand::InteractionEvent, m_Callback);
|
m_Widget->AddObserver(vtkCommand::InteractionEvent, m_Callback);
|
||||||
|
|
||||||
|
m_InitialTransform = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
m_RelativeTransform = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
m_TotalTransform = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
|
||||||
|
this->InstallPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkDetectorChamber::~vtkDetectorChamber() {
|
vtkDetectorChamber::~vtkDetectorChamber() {
|
||||||
|
m_Actor->Delete();
|
||||||
m_Widget->Delete();
|
m_Widget->Delete();
|
||||||
m_Callback->Delete();
|
m_Callback->Delete();
|
||||||
m_PickerCallback->Delete();
|
m_PickerCallback->Delete();
|
||||||
@@ -68,94 +77,97 @@ void vtkDetectorChamber::PrintSelf(std::ostream &o) const {
|
|||||||
vtkContainerBox::PrintSelf(o);
|
vtkContainerBox::PrintSelf(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect the interactor to the widget
|
||||||
|
*/
|
||||||
void vtkDetectorChamber::ConnectInteractor(
|
void vtkDetectorChamber::ConnectInteractor(
|
||||||
vtkRenderWindowInteractor *interactor) {
|
vtkRenderWindowInteractor *interactor) {
|
||||||
if (!interactor)
|
if (!interactor)
|
||||||
return;
|
return;
|
||||||
m_Widget->SetInteractor(interactor);
|
m_Widget->SetInteractor(interactor);
|
||||||
m_Widget->SetProp3D(m_Cube);
|
m_Widget->SetProp3D(m_Actor);
|
||||||
m_Widget->PlaceWidget();
|
|
||||||
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, m_PickerCallback);
|
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, m_PickerCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkDetectorChamber::Update() {
|
void vtkDetectorChamber::SetTransform(vtkTransform *t) {
|
||||||
if (!m_Content)
|
|
||||||
return;
|
|
||||||
|
m_RelativeTransform->SetMatrix(t->GetMatrix());
|
||||||
Matrix4f mat = static_cast<Content *>(m_Content)->GetWorldMatrix();
|
m_RelativeTransform->Update();
|
||||||
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
|
||||||
|
// Set content global transform (BaseClass of ContainerBox) //
|
||||||
|
vtkMatrix4x4 *vmat = m_TotalTransform->GetMatrix();
|
||||||
|
Matrix4f transform;
|
||||||
for (int i = 0; i < 4; ++i)
|
for (int i = 0; i < 4; ++i)
|
||||||
for (int j = 0; j < 4; ++j)
|
for (int j = 0; j < 4; ++j)
|
||||||
vmat->SetElement(i, j, mat(i, j));
|
transform(i, j) = vmat->GetElement(i, j);
|
||||||
|
this->GetContent()->SetMatrix(transform);
|
||||||
|
|
||||||
m_Cube->SetUserMatrix(vmat);
|
this->Update();
|
||||||
m_Axes->SetUserMatrix(vmat);
|
}
|
||||||
m_Pivot->SetUserMatrix(vmat);
|
|
||||||
|
vtkBoxWidget *vtkDetectorChamber::GetWidget() { return m_Widget; }
|
||||||
|
|
||||||
|
void vtkDetectorChamber::Update() {
|
||||||
|
if (m_Actor->GetMapper())
|
||||||
|
m_Actor->GetMapper()->Update();
|
||||||
|
BaseClass::Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkDetectorChamber::InstallPipe() {
|
void vtkDetectorChamber::InstallPipe() {
|
||||||
if (!m_Content)
|
if (!m_Content)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Cube: unit box (0,0,0) -> (1,1,1)
|
|
||||||
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||||
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
||||||
|
|
||||||
|
// 1. Initialize Global Transform (m_Transform) from Content's matrix (Base
|
||||||
|
// class AffineTransform)
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmatGlobal =
|
||||||
|
vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f matGlobal = this->GetContent()->GetMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmatGlobal->SetElement(i, j, matGlobal(i, j));
|
||||||
|
|
||||||
|
m_InitialTransform->SetMatrix(vmatGlobal);
|
||||||
|
m_InitialTransform->Update();
|
||||||
|
|
||||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(cube->GetOutputPort());
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
m_Cube->SetMapper(mapper);
|
m_Actor->SetMapper(mapper);
|
||||||
m_Cube->GetProperty()->SetRepresentationToWireframe();
|
|
||||||
m_Cube->GetProperty()->SetAmbient(0.7);
|
|
||||||
|
|
||||||
// Axes: corner origin
|
m_Actor->GetProperty()->SetRepresentationToSurface();
|
||||||
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
m_Actor->GetProperty()->SetEdgeVisibility(true);
|
||||||
axes->SetOrigin(0, 0, 0);
|
m_Actor->GetProperty()->SetOpacity(0.4);
|
||||||
axes->SetScaleFactor(0.2);
|
m_Actor->GetProperty()->SetAmbient(0.7);
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
|
||||||
mapper->SetInputConnection(axes->GetOutputPort());
|
|
||||||
m_Axes->SetMapper(mapper);
|
|
||||||
m_Axes->GetProperty()->SetLineWidth(3);
|
|
||||||
m_Axes->GetProperty()->SetAmbient(0.4);
|
|
||||||
|
|
||||||
// Pivot: center of unit box
|
// Temporarily disable UserTransform to place widget on local base
|
||||||
vtkSmartPointer<vtkAxes> pivot = vtkSmartPointer<vtkAxes>::New();
|
m_Widget->SetProp3D(m_Actor);
|
||||||
pivot->SetOrigin(0.5, 0.5, 0.5);
|
|
||||||
pivot->SetScaleFactor(0.1);
|
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
|
||||||
mapper->SetInputConnection(pivot->GetOutputPort());
|
|
||||||
m_Pivot->SetMapper(mapper);
|
|
||||||
m_Pivot->GetProperty()->SetLineWidth(3);
|
|
||||||
m_Pivot->GetProperty()->SetAmbient(0.4);
|
|
||||||
|
|
||||||
this->SetProp(m_Cube);
|
m_TotalTransform->SetInput(m_RelativeTransform);
|
||||||
this->SetProp(m_Axes);
|
m_TotalTransform->Concatenate(m_InitialTransform);
|
||||||
this->SetProp(m_Pivot);
|
m_Actor->SetUserTransform(m_TotalTransform);
|
||||||
|
m_TotalTransform->Update();
|
||||||
|
|
||||||
|
m_Widget->PlaceWidget();
|
||||||
|
m_Widget->SetPlaceFactor(2);
|
||||||
|
|
||||||
|
this->SetProp(m_Actor);
|
||||||
this->Update();
|
this->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkDetectorChamber::vtkWidgetCallback::Execute(vtkObject *caller,
|
void vtkDetectorChamber::vtkWidgetCallback::Execute(vtkObject *caller,
|
||||||
unsigned long, void *) {
|
unsigned long, void *) {
|
||||||
vtkHandlerWidget *widget = reinterpret_cast<vtkHandlerWidget *>(caller);
|
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget *>(caller);
|
||||||
|
|
||||||
|
// Get the Relative transform from the widget //
|
||||||
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
||||||
widget->GetTransform(t);
|
widget->GetTransform(t);
|
||||||
|
chamber->SetTransform(t);
|
||||||
|
|
||||||
vtkMatrix4x4 *vmat = t->GetMatrix();
|
// Apply to both the content and the actor state //
|
||||||
Matrix4f mat;
|
|
||||||
for (int i = 0; i < 4; ++i)
|
|
||||||
for (int j = 0; j < 4; ++j)
|
|
||||||
mat(i, j) = vmat->GetElement(i, j);
|
|
||||||
|
|
||||||
chamber->GetContent()->SetMatrix(mat);
|
|
||||||
|
|
||||||
// Reset internal matrix to identity to avoid double-transformation
|
|
||||||
vtkProp3D *prop = widget->GetProp3D();
|
|
||||||
if (prop) {
|
|
||||||
prop->SetPosition(0, 0, 0);
|
|
||||||
prop->SetOrientation(0, 0, 0);
|
|
||||||
prop->SetScale(1, 1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
chamber->Update();
|
chamber->Update();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,22 +182,9 @@ void vtkDetectorChamber::vtkSelectionCallback::Execute(vtkObject *caller,
|
|||||||
interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
|
interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
|
||||||
|
|
||||||
vtkProp *picked = picker->GetViewProp();
|
vtkProp *picked = picker->GetViewProp();
|
||||||
if (picked == chamber->m_Cube || picked == chamber->m_Axes ||
|
if (picked == chamber->m_Actor) {
|
||||||
picked == chamber->m_Pivot) {
|
|
||||||
if (!chamber->m_Widget->GetEnabled()) {
|
if (!chamber->m_Widget->GetEnabled()) {
|
||||||
// Register current position/rotation/scale from content //
|
chamber->m_Widget->SetInteractor(interactor);
|
||||||
Matrix4f mat = chamber->GetContent()->GetWorldMatrix();
|
|
||||||
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
|
||||||
for (int i = 0; i < 4; ++i)
|
|
||||||
for (int j = 0; j < 4; ++j)
|
|
||||||
vmat->SetElement(i, j, mat(i, j));
|
|
||||||
|
|
||||||
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
|
||||||
t->SetMatrix(vmat);
|
|
||||||
chamber->m_Widget->SetCurrentRenderer(
|
|
||||||
interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
|
|
||||||
chamber->m_Widget->SetTransform(t);
|
|
||||||
chamber->m_Widget->PlaceWidget();
|
|
||||||
chamber->m_Widget->On();
|
chamber->m_Widget->On();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -35,14 +35,18 @@
|
|||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
#include "Vtk/uLibVtkInterface.h"
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
#include "Vtk/vtkContainerBox.h"
|
#include "Vtk/vtkContainerBox.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkBoxWidget.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
class vtkHandlerWidget;
|
// class vtkHandlerWidget; // Removed as we use vtkBoxWidget now
|
||||||
|
|
||||||
class vtkDetectorChamber : public vtkContainerBox {
|
class vtkDetectorChamber : public vtkContainerBox {
|
||||||
typedef DetectorChamber Content;
|
typedef DetectorChamber Content;
|
||||||
|
typedef vtkContainerBox BaseClass;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vtkDetectorChamber(DetectorChamber *content);
|
vtkDetectorChamber(DetectorChamber *content);
|
||||||
@@ -50,6 +54,10 @@ public:
|
|||||||
|
|
||||||
Content *GetContent();
|
Content *GetContent();
|
||||||
|
|
||||||
|
void SetTransform(class vtkTransform *t);
|
||||||
|
|
||||||
|
class vtkBoxWidget *GetWidget();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
void ConnectInteractor(vtkRenderWindowInteractor *interactor) override;
|
void ConnectInteractor(vtkRenderWindowInteractor *interactor) override;
|
||||||
@@ -80,9 +88,14 @@ private:
|
|||||||
uLib::Vtk::vtkDetectorChamber *chamber;
|
uLib::Vtk::vtkDetectorChamber *chamber;
|
||||||
};
|
};
|
||||||
|
|
||||||
vtkHandlerWidget *m_Widget;
|
vtkActor *m_Actor;
|
||||||
|
vtkBoxWidget *m_Widget;
|
||||||
vtkWidgetCallback *m_Callback;
|
vtkWidgetCallback *m_Callback;
|
||||||
vtkSelectionCallback *m_PickerCallback;
|
vtkSelectionCallback *m_PickerCallback;
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkTransform> m_InitialTransform;
|
||||||
|
vtkSmartPointer<vtkTransform> m_RelativeTransform;
|
||||||
|
vtkSmartPointer<vtkTransform> m_TotalTransform;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vtk
|
} // namespace Vtk
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#if VTK_5_x
|
|
||||||
_VTK_LIBS = -lQVTK \
|
|
||||||
-lLSDyna \
|
|
||||||
-lMapReduceMPI \
|
|
||||||
-lmpistubs \
|
|
||||||
-lvtkalglib \
|
|
||||||
-lvtkCharts \
|
|
||||||
-lvtkCommon \
|
|
||||||
-lvtkDICOMParser \
|
|
||||||
-lvtkexoIIc \
|
|
||||||
-lvtkFiltering \
|
|
||||||
-lvtkftgl \
|
|
||||||
-lvtkGenericFiltering \
|
|
||||||
-lvtkGraphics \
|
|
||||||
-lvtkHybrid \
|
|
||||||
-lvtkImaging \
|
|
||||||
-lvtkInfovis \
|
|
||||||
-lvtkmetaio \
|
|
||||||
-lvtkNetCDF_cxx \
|
|
||||||
-lvtkNetCDF \
|
|
||||||
-lvtkproj4 \
|
|
||||||
-lvtkRendering \
|
|
||||||
-lvtksqlite \
|
|
||||||
-lvtksys \
|
|
||||||
-lvtkverdict \
|
|
||||||
-lvtkViews \
|
|
||||||
-lvtkVolumeRendering \
|
|
||||||
-lvtkWidgets
|
|
||||||
|
|
||||||
AM_CFLAGS += $(VTK_CFLAGS)
|
|
||||||
AM_CXXFLAGS += $(VTK_CXXFLAGS)
|
|
||||||
AM_LDFLAGS += $(VTK_LDFLAGS) $(_VTK_LIBS)
|
|
||||||
|
|
||||||
#else
|
|
||||||
#_VTK_LIBS = \
|
|
||||||
# -lvtkRenderingOpenGL-6.0 \
|
|
||||||
# -lvtkImagingHybrid-6.0 \
|
|
||||||
# -lvtkIOImage-6.0 \
|
|
||||||
# -lvtkCommonDataModel-6.0 \
|
|
||||||
# -lvtkCommonMath-6.0 \
|
|
||||||
# -lvtkCommonCore-6.0 \
|
|
||||||
# -lvtksys-6.0 \
|
|
||||||
# -lvtkCommonMisc-6.0 \
|
|
||||||
# -lvtkCommonSystem-6.0 \
|
|
||||||
# -lvtkCommonTransforms-6.0 \
|
|
||||||
# -lvtkCommonExecutionModel-6.0 \
|
|
||||||
# -lvtkDICOMParser-6.0 \
|
|
||||||
# -lvtkIOCore-6.0 \
|
|
||||||
# -lvtkzlib-6.0 \
|
|
||||||
# -lvtkmetaio-6.0 \
|
|
||||||
# -lvtkjpeg-6.0 \
|
|
||||||
# -lvtkpng-6.0 \
|
|
||||||
# -lvtktiff-6.0 \
|
|
||||||
# -lvtkImagingCore-6.0 \
|
|
||||||
# -lvtkRenderingCore-6.0 \
|
|
||||||
# -lvtkFiltersExtraction-6.0 \
|
|
||||||
# -lvtkFiltersCore-6.0 \
|
|
||||||
# -lvtkFiltersGeneral-6.0 \
|
|
||||||
# -lvtkCommonComputationalGeometry-6.0 \
|
|
||||||
# -lvtkFiltersStatistics-6.0 \
|
|
||||||
# -lvtkImagingFourier-6.0 \
|
|
||||||
# -lvtkalglib-6.0 \
|
|
||||||
# -lvtkFiltersGeometry-6.0 \
|
|
||||||
# -lvtkFiltersSources-6.0 \
|
|
||||||
# -lvtkIOXMLParser-6.0 \
|
|
||||||
# -lvtkexpat-6.0 \
|
|
||||||
# -lvtkRenderingAnnotation-6.0 \
|
|
||||||
# -lvtkImagingColor-6.0 \
|
|
||||||
# -lvtkRenderingFreeType-6.0 \
|
|
||||||
# -lvtkfreetype-6.0 \
|
|
||||||
# -lvtkftgl-6.0 \
|
|
||||||
# -lvtkInteractionStyle-6.0 \
|
|
||||||
# -lvtkRenderingVolumeOpenGL-6.0 \
|
|
||||||
# -lvtkRenderingVolume-6.0 \
|
|
||||||
# -lvtkIOXML-6.0 \
|
|
||||||
# -lvtkIOGeometry-6.0 \
|
|
||||||
# -lvtkjsoncpp-6.0 \
|
|
||||||
# -lvtkInteractionWidgets-6.0 \
|
|
||||||
# -lvtkFiltersHybrid-6.0 \
|
|
||||||
# -lvtkImagingSources-6.0 \
|
|
||||||
# -lvtkFiltersModeling-6.0 \
|
|
||||||
# -lvtkImagingGeneral-6.0 \
|
|
||||||
# -lvtkIOLegacy-6.0 \
|
|
||||||
# -lvtkRenderingFreeTypeOpenGL-6.0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#AM_CFLAGS += $(VTK_CFLAGS)
|
|
||||||
#AM_CXXFLAGS += $(VTK_CXXFLAGS) -rdynamic
|
|
||||||
#AM_LDFLAGS += $(VTK_LDFLAGS) $(_VTK_LIBS) -lGLU -lSM -lICE -lX11 -lXext -lSM -lICE -lX11 -lXext -lXt -lm -ldl -lGL
|
|
||||||
#endif
|
|
||||||
@@ -23,17 +23,11 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ULIBVTKINTERFACE_H
|
#ifndef ULIBVTKINTERFACE_H
|
||||||
#define ULIBVTKINTERFACE_H
|
#define ULIBVTKINTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <ostream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
|
||||||
// vtk classes forward declaration //
|
// vtk classes forward declaration //
|
||||||
class vtkProp;
|
class vtkProp;
|
||||||
@@ -42,66 +36,57 @@ class vtkPropCollection;
|
|||||||
class vtkRenderer;
|
class vtkRenderer;
|
||||||
class vtkRendererCollection;
|
class vtkRendererCollection;
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
class Puppet
|
class Puppet {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Puppet();
|
Puppet();
|
||||||
~Puppet();
|
~Puppet();
|
||||||
|
|
||||||
virtual vtkProp * GetProp();
|
virtual vtkProp *GetProp();
|
||||||
|
|
||||||
virtual vtkPropCollection * GetProps();
|
virtual vtkPropCollection *GetProps();
|
||||||
|
|
||||||
void ConnectRenderer(vtkRenderer *renderer);
|
void ConnectRenderer(vtkRenderer *renderer);
|
||||||
|
|
||||||
void DisconnectRenderer(vtkRenderer *renderer);
|
void DisconnectRenderer(vtkRenderer *renderer);
|
||||||
|
|
||||||
void ConnectViewer(class Viewer *viewer);
|
void ConnectViewer(class Viewer *viewer);
|
||||||
|
|
||||||
void DisonnectViewer(class Viewer *viewer);
|
void DisonnectViewer(class Viewer *viewer);
|
||||||
|
|
||||||
vtkRendererCollection * GetRenderers() const;
|
vtkRendererCollection *GetRenderers() const;
|
||||||
|
|
||||||
|
virtual void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
virtual void PrintSelf(std::ostream &o) const;
|
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor) {
|
||||||
|
(void)interactor;
|
||||||
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor) { (void)interactor; }
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void SetProp(vtkProp *prop);
|
||||||
|
|
||||||
void SetProp(vtkProp *prop);
|
void RemoveProp(vtkProp *prop);
|
||||||
|
|
||||||
void RemoveProp(vtkProp *prop);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class PuppetData;
|
friend class PuppetData;
|
||||||
class PuppetData *d;
|
class PuppetData *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Polydata {
|
class Polydata {
|
||||||
public:
|
public:
|
||||||
|
virtual vtkPolyData *GetPolyData() const { return NULL; }
|
||||||
|
|
||||||
virtual vtkPolyData * GetPolyData() const { return NULL; }
|
virtual void SaveToFile(const char *vtk_file);
|
||||||
|
|
||||||
virtual void SaveToFile(const char *vtk_file);
|
virtual void SaveToXMLFile(const char *vtp_file);
|
||||||
|
|
||||||
virtual void SaveToXMLFile(const char *vtp_file);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~Polydata() {}
|
virtual ~Polydata() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // ULIBVTKINTERFACE_H
|
#endif // ULIBVTKINTERFACE_H
|
||||||
|
|||||||
@@ -86,6 +86,7 @@ Viewer::~Viewer() {
|
|||||||
|
|
||||||
void Viewer::InstallPipe() {
|
void Viewer::InstallPipe() {
|
||||||
m_RenderWindow->AddRenderer(m_Renderer);
|
m_RenderWindow->AddRenderer(m_Renderer);
|
||||||
|
m_RenderWindow->SetSize(600,600);
|
||||||
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
|
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
|
||||||
vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
||||||
renderWindowInteractor->SetRenderWindow(m_RenderWindow);
|
renderWindowInteractor->SetRenderWindow(m_RenderWindow);
|
||||||
|
|||||||
@@ -27,23 +27,28 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "vtkContainerBox.h"
|
||||||
#include <vtkActor.h>
|
#include <vtkActor.h>
|
||||||
#include <vtkAssembly.h>
|
#include <vtkAssembly.h>
|
||||||
#include <vtkAxes.h>
|
#include <vtkAxes.h>
|
||||||
#include <vtkCubeSource.h>
|
#include <vtkCubeSource.h>
|
||||||
#include <vtkLineSource.h>
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkMatrix4x4.h>
|
||||||
#include <vtkPolyDataMapper.h>
|
#include <vtkPolyDataMapper.h>
|
||||||
#include <vtkProperty.h>
|
#include <vtkProperty.h>
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
#include "vtkContainerBox.h"
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
vtkContainerBox::vtkContainerBox(vtkContainerBox::Content *content)
|
vtkContainerBox::vtkContainerBox(vtkContainerBox::Content *content)
|
||||||
: m_Cube(vtkActor::New()), m_Axes(vtkActor::New()),
|
: m_Cube(vtkActor::New()), m_Axes(vtkActor::New()),
|
||||||
m_Pivot(vtkActor::New()), m_Content(content) {
|
m_Pivot(vtkActor::New()),
|
||||||
|
m_Content(content) {
|
||||||
this->InstallPipe();
|
this->InstallPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +63,28 @@ vtkPolyData *vtkContainerBox::GetPolyData() const {
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vtkContainerBox::Update() {
|
||||||
|
if (!m_Content)
|
||||||
|
return;
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f transform = m_Content->GetMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmat->SetElement(i, j, transform(i, j));
|
||||||
|
|
||||||
|
std::cout << "transform: " << transform << std::endl;
|
||||||
|
|
||||||
|
// m_RelativeTransform->SetMatrix(vmat);
|
||||||
|
// m_RelativeTransform->Update();
|
||||||
|
|
||||||
|
m_Cube->SetUserMatrix(vmat);
|
||||||
|
m_Axes->SetUserMatrix(vmat);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void vtkContainerBox::InstallPipe() {
|
void vtkContainerBox::InstallPipe() {
|
||||||
if (!m_Content)
|
if (!m_Content)
|
||||||
return;
|
return;
|
||||||
@@ -65,17 +92,27 @@ void vtkContainerBox::InstallPipe() {
|
|||||||
|
|
||||||
// CUBE
|
// CUBE
|
||||||
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||||
|
|
||||||
Vector3f p = c->GetPosition();
|
Vector3f p = c->GetPosition();
|
||||||
cube->SetCenter(p(0), p(1), p(2));
|
// cube->SetCenter(p(0), p(1), p(2));
|
||||||
Vector4f p1 = c->GetWorldPoint(HPoint3f(0, 0, 0));
|
// Vector4f p1 = c->GetWorldPoint(HPoint3f(0, 0, 0));
|
||||||
Vector4f p2 = c->GetWorldPoint(HPoint3f(1, 1, 1));
|
// Vector4f p2 = c->GetWorldPoint(HPoint3f(1, 1, 1));
|
||||||
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
|
// vtkSmartPointer<vtkLineSource> line =
|
||||||
line->SetPoint1(p1(0), p1(1), p1(2));
|
// vtkSmartPointer<vtkLineSource>::New(); line->SetPoint1(p1(0), p1(1),
|
||||||
line->SetPoint2(p2(0), p2(1), p2(2));
|
// p1(2)); line->SetPoint2(p2(0), p2(1), p2(2)); line->Update();
|
||||||
line->Update();
|
// cube->SetBounds(line->GetOutput()->GetBounds());
|
||||||
cube->SetBounds(line->GetOutput()->GetBounds());
|
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f transform = c->GetMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmat->SetElement(i, j, transform(i, j));
|
||||||
|
|
||||||
|
m_Cube->SetUserMatrix(vmat);
|
||||||
|
|
||||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
||||||
mapper->SetInputConnection(cube->GetOutputPort());
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
mapper->Update();
|
mapper->Update();
|
||||||
m_Cube->SetMapper(mapper);
|
m_Cube->SetMapper(mapper);
|
||||||
@@ -84,11 +121,12 @@ void vtkContainerBox::InstallPipe() {
|
|||||||
|
|
||||||
// AXES //
|
// AXES //
|
||||||
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
||||||
axes->SetOrigin(p1(0), p1(1), p1(2));
|
axes->SetOrigin(0, 0, 0);
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(axes->GetOutputPort());
|
mapper->SetInputConnection(axes->GetOutputPort());
|
||||||
mapper->Update();
|
mapper->Update();
|
||||||
m_Axes->SetMapper(mapper);
|
m_Axes->SetMapper(mapper);
|
||||||
|
m_Axes->SetUserMatrix(vmat);
|
||||||
Vector3f s = c->GetSize();
|
Vector3f s = c->GetSize();
|
||||||
// m_Axes->SetScale(s(0),s(1),s(2));
|
// m_Axes->SetScale(s(0),s(1),s(2));
|
||||||
m_Axes->GetProperty()->SetLineWidth(3);
|
m_Axes->GetProperty()->SetLineWidth(3);
|
||||||
@@ -97,11 +135,19 @@ void vtkContainerBox::InstallPipe() {
|
|||||||
|
|
||||||
// PIVOT //
|
// PIVOT //
|
||||||
axes = vtkSmartPointer<vtkAxes>::New();
|
axes = vtkSmartPointer<vtkAxes>::New();
|
||||||
axes->SetOrigin(p(0), p(1), p(2));
|
axes->SetOrigin(0, 0, 0);
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(axes->GetOutputPort());
|
mapper->SetInputConnection(axes->GetOutputPort());
|
||||||
mapper->Update();
|
mapper->Update();
|
||||||
|
m_Pivot->SetUserMatrix(vmat);
|
||||||
m_Pivot->SetMapper(mapper);
|
m_Pivot->SetMapper(mapper);
|
||||||
|
|
||||||
|
Matrix4f pivotTransform = c->AffineTransform::GetWorldMatrix();
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> pmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
pmat->SetElement(i, j, pivotTransform(i, j));
|
||||||
|
m_Pivot->SetUserMatrix(pmat);
|
||||||
s = c->GetScale();
|
s = c->GetScale();
|
||||||
// m_Pivot->SetScale(s(0),s(1),s(2));
|
// m_Pivot->SetScale(s(0),s(1),s(2));
|
||||||
m_Pivot->GetProperty()->SetLineWidth(3);
|
m_Pivot->GetProperty()->SetLineWidth(3);
|
||||||
|
|||||||
@@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
#include "uLibVtkInterface.h"
|
#include "uLibVtkInterface.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
@@ -41,6 +42,9 @@ public:
|
|||||||
|
|
||||||
virtual class vtkPolyData *GetPolyData() const;
|
virtual class vtkPolyData *GetPolyData() const;
|
||||||
|
|
||||||
|
virtual void Update();
|
||||||
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void InstallPipe();
|
virtual void InstallPipe();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user