Compare commits
5 Commits
3be7ec2274
...
andrea-dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f2133c31d5 | ||
|
|
00275ac56d | ||
|
|
1374821344 | ||
|
|
2548582036 | ||
|
|
32a1104769 |
@@ -29,62 +29,146 @@
|
|||||||
#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;
|
||||||
|
|
||||||
|
/** Rotate using transformation chain */
|
||||||
|
using BaseClass::Rotate;
|
||||||
|
|
||||||
|
/** Scale using transformation chain */
|
||||||
|
using BaseClass::Scale;
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
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;
|
||||||
|
Cnt.SetOrigin(Vector3f(0,0,0));
|
||||||
// // Local transform:
|
Cnt.SetSize(Vector3f(2,2,2));
|
||||||
Cnt.SetOrigin(Vector3f(-1,-1,-1));
|
TEST0( Vector4f0(Cnt.GetOrigin().homogeneous() - HVector3f(0,0,0)) );
|
||||||
Cnt.SetSize(Vector3f(2,2,2)); // scaling //
|
|
||||||
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
|
|
||||||
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
|
|
||||||
TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) );
|
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)) );
|
||||||
|
|
||||||
|
HPoint3f pt2 = Cnt.GetLocalPoint(HPoint3f(2,2,2));
|
||||||
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(2,2,2)) );
|
||||||
|
|
||||||
|
HPoint3f pt3 = Cnt.GetLocalPoint(HPoint3f(1,1,1));
|
||||||
|
HPoint3f wp3 = Cnt.GetWorldPoint(pt3);
|
||||||
|
TEST0( Vector4f0(wp3 - HPoint3f(1,1,1)) );
|
||||||
|
|
||||||
|
HPoint3f pt4 = Cnt.GetLocalPoint(HPoint3f(1,2,3));
|
||||||
|
HPoint3f wp4 = Cnt.GetWorldPoint(pt4);
|
||||||
|
TEST0( Vector4f0(wp4 - HPoint3f(1,2,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)) );
|
||||||
|
|
||||||
|
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.SetPosition(Vector3f(1,1,1));
|
||||||
Box.SetSize(Vector3f(2,2,2));
|
Box.SetSize(Vector3f(2,2,2));
|
||||||
Box.EulerYZYRotate(Vector3f(0,0,0));
|
Box.EulerYZYRotate(Vector3f(0,0,0));
|
||||||
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
|
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
|
||||||
HPoint3f wp = Box.GetWorldPoint(pt);
|
HPoint3f wp = Box.GetWorldPoint(pt);
|
||||||
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
|
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
|
||||||
|
}
|
||||||
|
|
||||||
//// // Global
|
|
||||||
// Cnt.SetPosition(Vector3f(1,1,1));
|
|
||||||
// Cnt.EulerYZYRotate(Vector3f(M_PI_2,M_PI_2,0));
|
|
||||||
// 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)) );
|
|
||||||
|
|
||||||
|
|
||||||
// // scaling //
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
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)
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
set(HEADERS uLibVtkInterface.h
|
set(HEADERS uLibVtkInterface.h
|
||||||
uLibVtkViewer.h
|
uLibVtkViewer.h
|
||||||
vtkContainerBox.h)
|
vtkContainerBox.h
|
||||||
|
vtkHandlerWidget.h
|
||||||
|
)
|
||||||
|
|
||||||
set(SOURCES uLibVtkInterface.cxx
|
set(SOURCES uLibVtkInterface.cxx
|
||||||
uLibVtkViewer.cpp
|
uLibVtkViewer.cpp
|
||||||
vtkContainerBox.cpp)
|
vtkContainerBox.cpp
|
||||||
|
vtkHandlerWidget.cpp
|
||||||
|
)
|
||||||
|
|
||||||
## Pull in Math VTK wrappers (sets MATH_SOURCES / MATH_HEADERS)
|
## Pull in Math VTK wrappers (sets MATH_SOURCES / MATH_HEADERS)
|
||||||
add_subdirectory(Math)
|
add_subdirectory(Math)
|
||||||
|
|||||||
@@ -9,11 +9,13 @@
|
|||||||
set(HEP_DETECTORS_SOURCES
|
set(HEP_DETECTORS_SOURCES
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.cxx
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.cxx
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.cxx
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.cxx
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkDetectorChamber.cxx
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
|
|
||||||
set(HEP_DETECTORS_HEADERS
|
set(HEP_DETECTORS_HEADERS
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.h
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.h
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.h
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkDetectorChamber.h
|
||||||
PARENT_SCOPE)
|
PARENT_SCOPE)
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
# TESTS
|
# TESTS
|
||||||
set(TESTS
|
set(TESTS
|
||||||
vtkMuonScatterTest
|
vtkMuonScatterTest
|
||||||
|
vtkDetectorChamberTest
|
||||||
)
|
)
|
||||||
|
|
||||||
set(LIBRARIES
|
set(LIBRARIES
|
||||||
@@ -12,3 +13,4 @@ set(LIBRARIES
|
|||||||
)
|
)
|
||||||
|
|
||||||
uLib_add_tests(VtkDetectors)
|
uLib_add_tests(VtkDetectors)
|
||||||
|
|
||||||
|
|||||||
62
src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.cpp
Normal file
62
src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.cpp
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||||
|
#include "HEP/Detectors/DetectorChamber.h"
|
||||||
|
|
||||||
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE vtkDetectorChamberTest
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(vtkDetectorChamberTest) {
|
||||||
|
uLib::DetectorChamber d1, d2;
|
||||||
|
d1.SetSize(uLib::Vector3f(1, 1, 1));
|
||||||
|
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));
|
||||||
|
|
||||||
|
|
||||||
|
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber(&d1);
|
||||||
|
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber2(&d2);
|
||||||
|
|
||||||
|
if (!vtkDetectorChamber.GetProp()) {
|
||||||
|
BOOST_FAIL("vtkDetectorChamber::GetProp() returned NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
uLib::Vtk::Viewer viewer;
|
||||||
|
viewer.AddPuppet(vtkDetectorChamber);
|
||||||
|
viewer.AddPuppet(vtkDetectorChamber2);
|
||||||
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK(true); // reached here without crash
|
||||||
|
}
|
||||||
198
src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx
Normal file
198
src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx
Normal file
@@ -0,0 +1,198 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include <vtkAbstractTransform.h>
|
||||||
|
#include <vtkAxes.h>
|
||||||
|
#include <vtkCubeSource.h>
|
||||||
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkPropPicker.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkRenderWindow.h>
|
||||||
|
#include <vtkRenderWindowInteractor.h>
|
||||||
|
#include <vtkRenderer.h>
|
||||||
|
#include <vtkRendererCollection.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
|
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||||
|
#include <vtkBoxWidget.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content)
|
||||||
|
: vtkContainerBox(content), m_Actor(vtkActor::New()),
|
||||||
|
m_Widget(vtkBoxWidget::New()) {
|
||||||
|
m_Callback = vtkWidgetCallback::New();
|
||||||
|
m_PickerCallback = vtkSelectionCallback::New();
|
||||||
|
|
||||||
|
m_Callback->SetChamber(this);
|
||||||
|
m_PickerCallback->SetChamber(this);
|
||||||
|
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() {
|
||||||
|
m_Actor->Delete();
|
||||||
|
m_Widget->Delete();
|
||||||
|
m_Callback->Delete();
|
||||||
|
m_PickerCallback->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
DetectorChamber *vtkDetectorChamber::GetContent() {
|
||||||
|
return static_cast<DetectorChamber *>(m_Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::PrintSelf(std::ostream &o) const {
|
||||||
|
vtkContainerBox::PrintSelf(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect the interactor to the widget
|
||||||
|
*/
|
||||||
|
void vtkDetectorChamber::ConnectInteractor(
|
||||||
|
vtkRenderWindowInteractor *interactor) {
|
||||||
|
if (!interactor)
|
||||||
|
return;
|
||||||
|
m_Widget->SetInteractor(interactor);
|
||||||
|
m_Widget->SetProp3D(m_Actor);
|
||||||
|
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, m_PickerCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::SetTransform(vtkTransform *t) {
|
||||||
|
|
||||||
|
|
||||||
|
m_RelativeTransform->SetMatrix(t->GetMatrix());
|
||||||
|
m_RelativeTransform->Update();
|
||||||
|
|
||||||
|
// Set content global transform (BaseClass of ContainerBox) //
|
||||||
|
vtkMatrix4x4 *vmat = m_TotalTransform->GetMatrix();
|
||||||
|
Matrix4f transform;
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
transform(i, j) = vmat->GetElement(i, j);
|
||||||
|
this->GetContent()->SetMatrix(transform);
|
||||||
|
|
||||||
|
this->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkBoxWidget *vtkDetectorChamber::GetWidget() { return m_Widget; }
|
||||||
|
|
||||||
|
void vtkDetectorChamber::Update() {
|
||||||
|
if (m_Actor->GetMapper())
|
||||||
|
m_Actor->GetMapper()->Update();
|
||||||
|
BaseClass::Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::InstallPipe() {
|
||||||
|
if (!m_Content)
|
||||||
|
return;
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||||
|
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>::New();
|
||||||
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
|
m_Actor->SetMapper(mapper);
|
||||||
|
|
||||||
|
m_Actor->GetProperty()->SetRepresentationToSurface();
|
||||||
|
m_Actor->GetProperty()->SetEdgeVisibility(true);
|
||||||
|
m_Actor->GetProperty()->SetOpacity(0.4);
|
||||||
|
m_Actor->GetProperty()->SetAmbient(0.7);
|
||||||
|
|
||||||
|
// Temporarily disable UserTransform to place widget on local base
|
||||||
|
m_Widget->SetProp3D(m_Actor);
|
||||||
|
|
||||||
|
m_TotalTransform->SetInput(m_RelativeTransform);
|
||||||
|
m_TotalTransform->Concatenate(m_InitialTransform);
|
||||||
|
m_Actor->SetUserTransform(m_TotalTransform);
|
||||||
|
m_TotalTransform->Update();
|
||||||
|
|
||||||
|
m_Widget->PlaceWidget();
|
||||||
|
m_Widget->SetPlaceFactor(2);
|
||||||
|
|
||||||
|
this->SetProp(m_Actor);
|
||||||
|
this->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::vtkWidgetCallback::Execute(vtkObject *caller,
|
||||||
|
unsigned long, void *) {
|
||||||
|
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget *>(caller);
|
||||||
|
|
||||||
|
// Get the Relative transform from the widget //
|
||||||
|
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
widget->GetTransform(t);
|
||||||
|
chamber->SetTransform(t);
|
||||||
|
|
||||||
|
// Apply to both the content and the actor state //
|
||||||
|
chamber->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::vtkSelectionCallback::Execute(vtkObject *caller,
|
||||||
|
unsigned long, void *) {
|
||||||
|
vtkRenderWindowInteractor *interactor =
|
||||||
|
reinterpret_cast<vtkRenderWindowInteractor *>(caller);
|
||||||
|
vtkSmartPointer<vtkPropPicker> picker = vtkSmartPointer<vtkPropPicker>::New();
|
||||||
|
int *pos = interactor->GetEventPosition();
|
||||||
|
picker->Pick(
|
||||||
|
pos[0], pos[1], 0,
|
||||||
|
interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
|
||||||
|
|
||||||
|
vtkProp *picked = picker->GetViewProp();
|
||||||
|
if (picked == chamber->m_Actor) {
|
||||||
|
if (!chamber->m_Widget->GetEnabled()) {
|
||||||
|
chamber->m_Widget->SetInteractor(interactor);
|
||||||
|
chamber->m_Widget->On();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (chamber->m_Widget->GetEnabled()) {
|
||||||
|
chamber->m_Widget->Off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
104
src/Vtk/HEP/Detectors/vtkDetectorChamber.h
Normal file
104
src/Vtk/HEP/Detectors/vtkDetectorChamber.h
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#ifndef VTK_DETECTOR_CHAMBER_H
|
||||||
|
#define VTK_DETECTOR_CHAMBER_H
|
||||||
|
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkCommand.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
|
#include "HEP/Detectors/DetectorChamber.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
#include "Vtk/vtkContainerBox.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkBoxWidget.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
// class vtkHandlerWidget; // Removed as we use vtkBoxWidget now
|
||||||
|
|
||||||
|
class vtkDetectorChamber : public vtkContainerBox {
|
||||||
|
typedef DetectorChamber Content;
|
||||||
|
typedef vtkContainerBox BaseClass;
|
||||||
|
|
||||||
|
public:
|
||||||
|
vtkDetectorChamber(DetectorChamber *content);
|
||||||
|
~vtkDetectorChamber();
|
||||||
|
|
||||||
|
Content *GetContent();
|
||||||
|
|
||||||
|
void SetTransform(class vtkTransform *t);
|
||||||
|
|
||||||
|
class vtkBoxWidget *GetWidget();
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
|
||||||
|
void ConnectInteractor(vtkRenderWindowInteractor *interactor) override;
|
||||||
|
|
||||||
|
void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void InstallPipe() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
class vtkWidgetCallback : public vtkCommand {
|
||||||
|
public:
|
||||||
|
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
||||||
|
void SetChamber(uLib::Vtk::vtkDetectorChamber *ch) { this->chamber = ch; }
|
||||||
|
virtual void Execute(vtkObject *caller, unsigned long, void *) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uLib::Vtk::vtkDetectorChamber *chamber;
|
||||||
|
};
|
||||||
|
|
||||||
|
class vtkSelectionCallback : public vtkCommand {
|
||||||
|
public:
|
||||||
|
static vtkSelectionCallback *New() { return new vtkSelectionCallback; }
|
||||||
|
void SetChamber(uLib::Vtk::vtkDetectorChamber *ch) { this->chamber = ch; }
|
||||||
|
virtual void Execute(vtkObject *caller, unsigned long, void *) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uLib::Vtk::vtkDetectorChamber *chamber;
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkActor *m_Actor;
|
||||||
|
vtkBoxWidget *m_Widget;
|
||||||
|
vtkWidgetCallback *m_Callback;
|
||||||
|
vtkSelectionCallback *m_PickerCallback;
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkTransform> m_InitialTransform;
|
||||||
|
vtkSmartPointer<vtkTransform> m_RelativeTransform;
|
||||||
|
vtkSmartPointer<vtkTransform> m_TotalTransform;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
#endif // VTK_DETECTOR_CHAMBER_H
|
||||||
@@ -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,8 +23,6 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "Vtk/uLibVtkViewer.h"
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
@@ -37,17 +35,16 @@ using namespace uLib;
|
|||||||
int main() {
|
int main() {
|
||||||
BEGIN_TESTING(vtk ContainerBox Test);
|
BEGIN_TESTING(vtk ContainerBox Test);
|
||||||
|
|
||||||
Vtk::Viewer v_viewer;
|
|
||||||
|
|
||||||
ContainerBox box;
|
ContainerBox box;
|
||||||
box.SetSize(Vector3f(2,3,4));
|
box.SetSize(Vector3f(2, 3, 4));
|
||||||
box.SetPosition(Vector3f(1,2,3));
|
box.SetPosition(Vector3f(1, 2, 3));
|
||||||
|
Vtk::vtkContainerBox v_box(&box);
|
||||||
Vtk::vtkContainerBox v_box(box);
|
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
Vtk::Viewer v_viewer;
|
||||||
v_viewer.AddPuppet(v_box);
|
v_viewer.AddPuppet(v_box);
|
||||||
v_viewer.Start();
|
v_viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
END_TESTING;
|
END_TESTING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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,19 +36,17 @@ 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);
|
||||||
|
|
||||||
@@ -64,15 +56,15 @@ public:
|
|||||||
|
|
||||||
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);
|
||||||
@@ -82,13 +74,9 @@ private:
|
|||||||
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);
|
||||||
|
|
||||||
@@ -98,10 +86,7 @@ protected:
|
|||||||
virtual ~Polydata() {}
|
virtual ~Polydata() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // ULIBVTKINTERFACE_H
|
#endif // ULIBVTKINTERFACE_H
|
||||||
|
|||||||
@@ -23,37 +23,33 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <vtkSmartPointer.h>
|
|
||||||
#include <vtkRendererCollection.h>
|
|
||||||
#include <vtkRenderWindowInteractor.h>
|
#include <vtkRenderWindowInteractor.h>
|
||||||
|
#include <vtkRendererCollection.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
#include <vtkTextProperty.h>
|
|
||||||
#include <vtkAxesActor.h>
|
#include <vtkAxesActor.h>
|
||||||
#include <vtkCamera.h>
|
#include <vtkCamera.h>
|
||||||
|
#include <vtkCameraOrientationWidget.h>
|
||||||
#include <vtkInteractorStyleTrackballCamera.h>
|
#include <vtkInteractorStyleTrackballCamera.h>
|
||||||
#include <vtkObjectFactory.h>
|
#include <vtkObjectFactory.h>
|
||||||
|
#include <vtkTextProperty.h>
|
||||||
|
|
||||||
#include "uLibVtkViewer.h"
|
#include "uLibVtkViewer.h"
|
||||||
|
|
||||||
// Custom interactor style: disables spin/inertia so the scene only
|
// Custom interactor style: disables spin/inertia so the scene only
|
||||||
// rotates while the mouse is actively being moved with the button held.
|
// rotates while the mouse is actively being moved with the button held.
|
||||||
class vtkInteractorStyleNoSpin : public vtkInteractorStyleTrackballCamera
|
class vtkInteractorStyleNoSpin : public vtkInteractorStyleTrackballCamera {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static vtkInteractorStyleNoSpin *New();
|
static vtkInteractorStyleNoSpin *New();
|
||||||
vtkTypeMacro(vtkInteractorStyleNoSpin, vtkInteractorStyleTrackballCamera);
|
vtkTypeMacro(vtkInteractorStyleNoSpin, vtkInteractorStyleTrackballCamera);
|
||||||
|
|
||||||
// Override: when the left button is released, immediately stop any
|
// Override: when the left button is released, immediately stop any
|
||||||
// ongoing motion (rotation/spin) so no momentum is carried over.
|
// ongoing motion (rotation/spin) so no momentum is carried over.
|
||||||
void OnLeftButtonUp() override
|
void OnLeftButtonUp() override {
|
||||||
{
|
|
||||||
this->StopState();
|
this->StopState();
|
||||||
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
|
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
|
||||||
}
|
}
|
||||||
@@ -63,34 +59,34 @@ vtkStandardNewMacro(vtkInteractorStyleNoSpin);
|
|||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
///// VTK VIEWER //////////////////////////////////////////////////////////////
|
///// VTK VIEWER //////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Viewer::Viewer()
|
||||||
|
: m_RenderWindow(vtkRenderWindow::New()), m_Renderer(vtkRenderer::New()),
|
||||||
Viewer::Viewer() :
|
|
||||||
m_RenderWindow(vtkRenderWindow::New()),
|
|
||||||
m_Renderer(vtkRenderer::New()),
|
|
||||||
m_Annotation(vtkCornerAnnotation::New()),
|
m_Annotation(vtkCornerAnnotation::New()),
|
||||||
m_Marker(vtkOrientationMarkerWidget::New())
|
m_Marker(vtkOrientationMarkerWidget::New()), m_CameraWidget(nullptr) {
|
||||||
{
|
#if VTK_MAJOR_VERSION >= 9 || \
|
||||||
|
(VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 90)
|
||||||
|
m_CameraWidget = vtkCameraOrientationWidget::New();
|
||||||
|
#endif
|
||||||
InstallPipe();
|
InstallPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewer::~Viewer()
|
Viewer::~Viewer() {
|
||||||
{
|
|
||||||
UninstallPipe();
|
UninstallPipe();
|
||||||
|
|
||||||
m_Annotation->Delete();
|
m_Annotation->Delete();
|
||||||
m_Marker->Delete();
|
m_Marker->Delete();
|
||||||
|
if (m_CameraWidget)
|
||||||
|
m_CameraWidget->Delete();
|
||||||
m_Renderer->Delete();
|
m_Renderer->Delete();
|
||||||
m_RenderWindow->Delete();
|
m_RenderWindow->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
@@ -101,84 +97,90 @@ void Viewer::InstallPipe()
|
|||||||
renderWindowInteractor->SetInteractorStyle(style);
|
renderWindowInteractor->SetInteractorStyle(style);
|
||||||
|
|
||||||
// annotation //
|
// annotation //
|
||||||
m_Annotation->GetTextProperty()->SetColor(1,1,1);
|
m_Annotation->GetTextProperty()->SetColor(1, 1, 1);
|
||||||
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
||||||
m_Annotation->GetTextProperty()->SetOpacity(0.5);
|
m_Annotation->GetTextProperty()->SetOpacity(0.5);
|
||||||
m_Annotation->SetMaximumFontSize(10);
|
m_Annotation->SetMaximumFontSize(10);
|
||||||
m_Annotation->SetText(0,"uLib VTK Viewer - OpenCMT all right reserved.");
|
m_Annotation->SetText(0, "uLib VTK Viewer - OpenCMT all right reserved.");
|
||||||
m_Renderer->AddViewProp(m_Annotation);
|
m_Renderer->AddViewProp(m_Annotation);
|
||||||
|
|
||||||
// orientation marker //
|
// orientation marker //
|
||||||
vtkSmartPointer<vtkAxesActor> axes =
|
vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
|
||||||
vtkSmartPointer<vtkAxesActor>::New();
|
|
||||||
m_Marker->SetInteractor(renderWindowInteractor);
|
m_Marker->SetInteractor(renderWindowInteractor);
|
||||||
m_Marker->SetOrientationMarker(axes);
|
m_Marker->SetOrientationMarker(axes);
|
||||||
m_Marker->SetViewport(0.0,0.0,0.2,0.2);
|
m_Marker->SetViewport(0.0, 0.0, 0.2, 0.2);
|
||||||
m_Marker->SetEnabled(true);
|
m_Marker->SetEnabled(true);
|
||||||
m_Marker->InteractiveOff();
|
m_Marker->InteractiveOff();
|
||||||
|
|
||||||
|
// camera orientation widget //
|
||||||
|
if (m_CameraWidget) {
|
||||||
|
m_CameraWidget->SetParentRenderer(m_Renderer);
|
||||||
|
m_CameraWidget->SetInteractor(renderWindowInteractor);
|
||||||
|
m_CameraWidget->On();
|
||||||
|
}
|
||||||
|
|
||||||
// Must be rendered here in Vtk-6.0 or seg-fault //
|
// Must be rendered here in Vtk-6.0 or seg-fault //
|
||||||
m_RenderWindow->Render();
|
m_RenderWindow->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::UninstallPipe()
|
void Viewer::UninstallPipe() {
|
||||||
{
|
|
||||||
m_Renderer->RemoveAllViewProps();
|
m_Renderer->RemoveAllViewProps();
|
||||||
m_Renderer->Clear();
|
m_Renderer->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::addProp(vtkProp *prop)
|
void Viewer::addProp(vtkProp *prop) {
|
||||||
{
|
|
||||||
m_Renderer->AddActor(prop);
|
m_Renderer->AddActor(prop);
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::RemoveProp(vtkProp *prop)
|
void Viewer::RemoveProp(vtkProp *prop) {
|
||||||
{
|
|
||||||
m_Renderer->RemoveViewProp(prop);
|
m_Renderer->RemoveViewProp(prop);
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::AddPuppet(Puppet &prop)
|
void Viewer::AddPuppet(Puppet &prop) {
|
||||||
{
|
|
||||||
prop.ConnectRenderer(m_Renderer);
|
prop.ConnectRenderer(m_Renderer);
|
||||||
|
prop.ConnectInteractor(this->GetInteractor());
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::RemovePuppet(Puppet &prop)
|
void Viewer::RemovePuppet(Puppet &prop) {
|
||||||
{
|
|
||||||
prop.DisconnectRenderer(m_Renderer);
|
prop.DisconnectRenderer(m_Renderer);
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::Start()
|
vtkSmartPointer<vtkCameraOrientationWidget>
|
||||||
{
|
Viewer::MakeCameraOrientationWidget(vtkRenderWindowInteractor *interactor,
|
||||||
m_RenderWindow->GetInteractor()->Start();
|
vtkRenderer *renderer) {
|
||||||
|
vtkSmartPointer<vtkCameraOrientationWidget> widget =
|
||||||
|
vtkSmartPointer<vtkCameraOrientationWidget>::New();
|
||||||
|
widget->SetParentRenderer(renderer);
|
||||||
|
widget->SetInteractor(interactor);
|
||||||
|
widget->On();
|
||||||
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkCornerAnnotation *Viewer::GetAnnotation()
|
void Viewer::Start() { m_RenderWindow->GetInteractor()->Start(); }
|
||||||
{
|
|
||||||
return m_Annotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkRenderer *Viewer::GetRenderer()
|
vtkCornerAnnotation *Viewer::GetAnnotation() { return m_Annotation; }
|
||||||
{
|
|
||||||
return m_Renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkRenderWindowInteractor *Viewer::GetInteractor()
|
vtkRenderer *Viewer::GetRenderer() { return m_Renderer; }
|
||||||
{
|
|
||||||
|
vtkRenderWindowInteractor *Viewer::GetInteractor() {
|
||||||
return m_RenderWindow->GetInteractor();
|
return m_RenderWindow->GetInteractor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::Reset()
|
vtkCameraOrientationWidget *Viewer::GetCameraWidget() { return m_CameraWidget; }
|
||||||
{
|
|
||||||
m_Renderer->ResetCameraClippingRange();
|
void Viewer::Reset() {
|
||||||
m_Renderer->ResetCamera();
|
this->ZoomAuto();
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewer::ZoomAuto() {
|
||||||
|
m_Renderer->ResetCameraClippingRange();
|
||||||
|
m_Renderer->ResetCamera();
|
||||||
|
}
|
||||||
|
|
||||||
} // vtk
|
} // namespace Vtk
|
||||||
} // uLib
|
} // namespace uLib
|
||||||
|
|
||||||
|
|||||||
@@ -23,60 +23,63 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ULIBVTKVIEWER_H
|
#ifndef ULIBVTKVIEWER_H
|
||||||
#define ULIBVTKVIEWER_H
|
#define ULIBVTKVIEWER_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "uLibVtkInterface.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <vtkRenderer.h>
|
|
||||||
#include <vtkRenderWindow.h>
|
|
||||||
#include <vtkCornerAnnotation.h>
|
#include <vtkCornerAnnotation.h>
|
||||||
#include <vtkOrientationMarkerWidget.h>
|
#include <vtkOrientationMarkerWidget.h>
|
||||||
|
#include <vtkRenderWindow.h>
|
||||||
|
#include <vtkRenderer.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
class vtkProp;
|
class vtkProp;
|
||||||
class vtk3DWidget;
|
class vtk3DWidget;
|
||||||
class vtkCornerAnnotation;
|
class vtkCornerAnnotation;
|
||||||
class vtkRenderWindowInteractor;
|
class vtkRenderWindowInteractor;
|
||||||
class vtkRenderer;
|
class vtkRenderer;
|
||||||
|
class vtkCameraOrientationWidget;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
|
template <class T> class Tie {
|
||||||
template <class T>
|
|
||||||
class Tie {
|
|
||||||
public:
|
public:
|
||||||
void DoAction() {
|
void DoAction() {
|
||||||
std::cout << "Tie::DoAction -> generic Tie does nothing\n";
|
std::cout << "Tie::DoAction -> generic Tie does nothing\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Viewer {
|
class Viewer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Viewer();
|
Viewer();
|
||||||
~Viewer();
|
~Viewer();
|
||||||
|
|
||||||
|
|
||||||
void AddPuppet(Puppet &prop);
|
void AddPuppet(Puppet &prop);
|
||||||
|
|
||||||
void RemovePuppet(Puppet &prop);
|
void RemovePuppet(Puppet &prop);
|
||||||
|
|
||||||
void AddWidget(vtk3DWidget *widget);
|
void AddWidget(vtk3DWidget *widget);
|
||||||
|
|
||||||
|
static vtkSmartPointer<vtkCameraOrientationWidget>
|
||||||
|
MakeCameraOrientationWidget(vtkRenderWindowInteractor *interactor,
|
||||||
|
vtkRenderer *renderer);
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
void ZoomAuto();
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
vtkCornerAnnotation *GetAnnotation();
|
vtkCornerAnnotation *GetAnnotation();
|
||||||
|
|
||||||
vtkRenderer * GetRenderer();
|
vtkRenderer *GetRenderer();
|
||||||
|
|
||||||
vtkRenderWindowInteractor * GetInteractor();
|
vtkRenderWindowInteractor *GetInteractor();
|
||||||
|
|
||||||
|
vtkCameraOrientationWidget *GetCameraWidget();
|
||||||
|
|
||||||
void addProp(vtkProp *prop);
|
void addProp(vtkProp *prop);
|
||||||
|
|
||||||
@@ -90,18 +93,15 @@ private:
|
|||||||
vtkRenderWindow *m_RenderWindow;
|
vtkRenderWindow *m_RenderWindow;
|
||||||
vtkCornerAnnotation *m_Annotation;
|
vtkCornerAnnotation *m_Annotation;
|
||||||
vtkOrientationMarkerWidget *m_Marker;
|
vtkOrientationMarkerWidget *m_Marker;
|
||||||
|
vtkCameraOrientationWidget *m_CameraWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <> class Tie<Viewer> {
|
||||||
class Tie<Viewer> {
|
|
||||||
public:
|
public:
|
||||||
void DoAction() {
|
void DoAction() { std::cout << " VIEWER TIE !!! \n"; }
|
||||||
std::cout << " VIEWER TIE !!! \n";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
#endif // ULIBVTKVIEWER_H
|
#endif // ULIBVTKVIEWER_H
|
||||||
|
|||||||
@@ -23,69 +23,96 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <vtkSmartPointer.h>
|
|
||||||
#include <vtkCubeSource.h>
|
|
||||||
#include <vtkActor.h>
|
|
||||||
#include <vtkAxes.h>
|
|
||||||
#include <vtkAssembly.h>
|
|
||||||
#include <vtkPolyDataMapper.h>
|
|
||||||
#include <vtkProperty.h>
|
|
||||||
#include <vtkLineSource.h>
|
|
||||||
|
|
||||||
#include "vtkContainerBox.h"
|
#include "vtkContainerBox.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkAssembly.h>
|
||||||
|
#include <vtkAxes.h>
|
||||||
|
#include <vtkCubeSource.h>
|
||||||
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.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_Pivot(vtkActor::New()),
|
||||||
m_Content(&content)
|
m_Content(content) {
|
||||||
{
|
|
||||||
this->InstallPipe();
|
this->InstallPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkContainerBox::~vtkContainerBox()
|
vtkContainerBox::~vtkContainerBox() {
|
||||||
{
|
|
||||||
m_Cube->Delete();
|
m_Cube->Delete();
|
||||||
m_Axes->Delete();
|
m_Axes->Delete();
|
||||||
m_Pivot->Delete();
|
m_Pivot->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkPolyData *vtkContainerBox::GetPolyData() const
|
vtkPolyData *vtkContainerBox::GetPolyData() const {
|
||||||
{
|
|
||||||
// TODO
|
// TODO
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkContainerBox::InstallPipe()
|
void vtkContainerBox::Update() {
|
||||||
{
|
if (!m_Content)
|
||||||
if(!m_Content) return;
|
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() {
|
||||||
|
if (!m_Content)
|
||||||
|
return;
|
||||||
Content *c = m_Content;
|
Content *c = m_Content;
|
||||||
|
|
||||||
// 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);
|
||||||
@@ -94,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);
|
||||||
@@ -107,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);
|
||||||
@@ -123,7 +159,5 @@ void vtkContainerBox::InstallPipe()
|
|||||||
this->SetProp(m_Pivot);
|
this->SetProp(m_Pivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
} // vtk
|
|
||||||
} // uLib
|
|
||||||
|
|||||||
@@ -23,37 +23,39 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef U_VTKCONTAINERBOX_H
|
#ifndef U_VTKCONTAINERBOX_H
|
||||||
#define U_VTKCONTAINERBOX_H
|
#define U_VTKCONTAINERBOX_H
|
||||||
|
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
|
#include "uLibVtkInterface.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
class vtkContainerBox : public Puppet, public Polydata {
|
class vtkContainerBox : public Puppet, public Polydata {
|
||||||
typedef ContainerBox Content;
|
typedef ContainerBox Content;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vtkContainerBox(Content &content);
|
vtkContainerBox(Content *content);
|
||||||
~vtkContainerBox();
|
~vtkContainerBox();
|
||||||
|
|
||||||
virtual class vtkPolyData *GetPolyData() const;
|
virtual class vtkPolyData *GetPolyData() const;
|
||||||
|
|
||||||
private:
|
virtual void Update();
|
||||||
void InstallPipe();
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void InstallPipe();
|
||||||
|
|
||||||
vtkActor *m_Cube;
|
vtkActor *m_Cube;
|
||||||
vtkActor *m_Axes;
|
vtkActor *m_Axes;
|
||||||
vtkActor *m_Pivot;
|
vtkActor *m_Pivot;
|
||||||
vtkContainerBox::Content *m_Content;
|
|
||||||
|
Content *m_Content;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // vtk
|
} // namespace Vtk
|
||||||
} // uLib
|
} // namespace uLib
|
||||||
|
|
||||||
#endif // VTKCONTAINERBOX_H
|
#endif // VTKCONTAINERBOX_H
|
||||||
|
|||||||
367
src/Vtk/vtkHandlerWidget.cpp
Normal file
367
src/Vtk/vtkHandlerWidget.cpp
Normal file
@@ -0,0 +1,367 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include "vtkHandlerWidget.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <vtkArcSource.h>
|
||||||
|
#include <vtkArrowSource.h>
|
||||||
|
#include <vtkCallbackCommand.h>
|
||||||
|
#include <vtkCamera.h>
|
||||||
|
#include <vtkConeSource.h>
|
||||||
|
#include <vtkCubeSource.h>
|
||||||
|
#include <vtkInteractorObserver.h>
|
||||||
|
#include <vtkMath.h>
|
||||||
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include <vtkObjectFactory.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkProp3D.h>
|
||||||
|
#include <vtkPropPicker.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkRenderWindow.h>
|
||||||
|
#include <vtkRenderWindowInteractor.h>
|
||||||
|
#include <vtkRenderer.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
vtkStandardNewMacro(vtkHandlerWidget);
|
||||||
|
|
||||||
|
vtkHandlerWidget::vtkHandlerWidget() {
|
||||||
|
this->Interaction = IDLE;
|
||||||
|
this->m_Picker = vtkSmartPointer<::vtkPropPicker>::New();
|
||||||
|
this->m_InitialTransform = vtkSmartPointer<::vtkTransform>::New();
|
||||||
|
this->EventCallbackCommand->SetCallback(vtkHandlerWidget::ProcessEvents);
|
||||||
|
this->EventCallbackCommand->SetClientData(this);
|
||||||
|
this->CreateGizmos();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkHandlerWidget::~vtkHandlerWidget() {}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::SetEnabled(int enabling) {
|
||||||
|
if (enabling) {
|
||||||
|
if (this->Enabled)
|
||||||
|
return;
|
||||||
|
if (!this->Interactor) {
|
||||||
|
vtkErrorMacro(
|
||||||
|
<< "The interactor must be set prior to enabling the widget");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->CurrentRenderer) {
|
||||||
|
this->CurrentRenderer = this->Interactor->FindPokedRenderer(
|
||||||
|
this->Interactor->GetLastEventPosition()[0],
|
||||||
|
this->Interactor->GetLastEventPosition()[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this->CurrentRenderer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Enabled = 1;
|
||||||
|
|
||||||
|
// Add observers
|
||||||
|
::vtkRenderWindowInteractor *i = this->Interactor;
|
||||||
|
i->AddObserver(::vtkCommand::LeftButtonPressEvent,
|
||||||
|
this->EventCallbackCommand, this->Priority);
|
||||||
|
i->AddObserver(::vtkCommand::LeftButtonReleaseEvent,
|
||||||
|
this->EventCallbackCommand, this->Priority);
|
||||||
|
i->AddObserver(::vtkCommand::MouseMoveEvent, this->EventCallbackCommand,
|
||||||
|
this->Priority);
|
||||||
|
|
||||||
|
this->UpdateGizmoPosition();
|
||||||
|
this->CurrentRenderer->AddActor(m_AxesX);
|
||||||
|
this->CurrentRenderer->AddActor(m_AxesY);
|
||||||
|
this->CurrentRenderer->AddActor(m_AxesZ);
|
||||||
|
this->CurrentRenderer->AddActor(m_RotX);
|
||||||
|
this->CurrentRenderer->AddActor(m_RotY);
|
||||||
|
this->CurrentRenderer->AddActor(m_RotZ);
|
||||||
|
this->CurrentRenderer->AddActor(m_ScaleX);
|
||||||
|
this->CurrentRenderer->AddActor(m_ScaleY);
|
||||||
|
this->CurrentRenderer->AddActor(m_ScaleZ);
|
||||||
|
|
||||||
|
this->InvokeEvent(::vtkCommand::EnableEvent, nullptr);
|
||||||
|
} else {
|
||||||
|
if (!this->Enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->Enabled = 0;
|
||||||
|
this->Interactor->RemoveObserver(this->EventCallbackCommand);
|
||||||
|
if (this->CurrentRenderer) {
|
||||||
|
this->CurrentRenderer->RemoveActor(m_AxesX);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_AxesY);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_AxesZ);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_RotX);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_RotY);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_RotZ);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_ScaleX);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_ScaleY);
|
||||||
|
this->CurrentRenderer->RemoveActor(m_ScaleZ);
|
||||||
|
}
|
||||||
|
this->InvokeEvent(::vtkCommand::DisableEvent, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this->Interactor) {
|
||||||
|
this->Interactor->Render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::ProcessEvents(::vtkObject *caller, unsigned long event,
|
||||||
|
void *clientdata, void *calldata) {
|
||||||
|
(void)caller;
|
||||||
|
(void)calldata;
|
||||||
|
vtkHandlerWidget *self = reinterpret_cast<vtkHandlerWidget *>(clientdata);
|
||||||
|
switch (event) {
|
||||||
|
case ::vtkCommand::LeftButtonPressEvent:
|
||||||
|
self->OnLeftButtonDown();
|
||||||
|
break;
|
||||||
|
case ::vtkCommand::LeftButtonReleaseEvent:
|
||||||
|
self->OnLeftButtonUp();
|
||||||
|
break;
|
||||||
|
case ::vtkCommand::MouseMoveEvent:
|
||||||
|
self->OnMouseMove();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::OnLeftButtonDown() {
|
||||||
|
int X = this->Interactor->GetEventPosition()[0];
|
||||||
|
int Y = this->Interactor->GetEventPosition()[1];
|
||||||
|
|
||||||
|
if (!this->CurrentRenderer) {
|
||||||
|
this->CurrentRenderer = this->Interactor->FindPokedRenderer(X, Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
this->m_Picker->Pick(X, Y, 0.0, this->CurrentRenderer);
|
||||||
|
::vtkProp *prop = this->m_Picker->GetViewProp();
|
||||||
|
|
||||||
|
if (!prop)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->Interaction = IDLE;
|
||||||
|
if (prop == m_AxesX)
|
||||||
|
this->Interaction = TRANS_X;
|
||||||
|
else if (prop == m_AxesY)
|
||||||
|
this->Interaction = TRANS_Y;
|
||||||
|
else if (prop == m_AxesZ)
|
||||||
|
this->Interaction = TRANS_Z;
|
||||||
|
else if (prop == m_RotX)
|
||||||
|
this->Interaction = ROT_X;
|
||||||
|
else if (prop == m_RotY)
|
||||||
|
this->Interaction = ROT_Y;
|
||||||
|
else if (prop == m_RotZ)
|
||||||
|
this->Interaction = ROT_Z;
|
||||||
|
else if (prop == m_ScaleX)
|
||||||
|
this->Interaction = SCALE_X;
|
||||||
|
else if (prop == m_ScaleY)
|
||||||
|
this->Interaction = SCALE_Y;
|
||||||
|
else if (prop == m_ScaleZ)
|
||||||
|
this->Interaction = SCALE_Z;
|
||||||
|
|
||||||
|
if (this->Interaction != IDLE) {
|
||||||
|
this->StartEventPosition[0] = X;
|
||||||
|
this->StartEventPosition[1] = Y;
|
||||||
|
if (this->Prop3D) {
|
||||||
|
this->m_InitialTransform->SetMatrix(this->Prop3D->GetMatrix());
|
||||||
|
}
|
||||||
|
this->EventCallbackCommand->SetAbortFlag(1);
|
||||||
|
this->InvokeEvent(::vtkCommand::StartInteractionEvent, nullptr);
|
||||||
|
this->Interactor->Render();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::OnLeftButtonUp() {
|
||||||
|
if (this->Interaction == IDLE)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this->Interaction = IDLE;
|
||||||
|
this->InvokeEvent(::vtkCommand::EndInteractionEvent, nullptr);
|
||||||
|
this->Interactor->Render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::OnMouseMove() {
|
||||||
|
if (this->Interaction == IDLE || !this->Prop3D)
|
||||||
|
return;
|
||||||
|
|
||||||
|
int X = this->Interactor->GetEventPosition()[0];
|
||||||
|
int Y = this->Interactor->GetEventPosition()[1];
|
||||||
|
|
||||||
|
double dx = X - this->StartEventPosition[0];
|
||||||
|
double dy = Y - this->StartEventPosition[1];
|
||||||
|
|
||||||
|
vtkSmartPointer<::vtkTransform> t = vtkSmartPointer<::vtkTransform>::New();
|
||||||
|
t->PostMultiply();
|
||||||
|
t->SetMatrix(this->m_InitialTransform->GetMatrix());
|
||||||
|
|
||||||
|
double factor = 0.01;
|
||||||
|
switch (this->Interaction) {
|
||||||
|
case TRANS_X:
|
||||||
|
t->Translate(dx * factor, 0, 0);
|
||||||
|
break;
|
||||||
|
case TRANS_Y:
|
||||||
|
t->Translate(0, dy * factor, 0);
|
||||||
|
break;
|
||||||
|
case TRANS_Z:
|
||||||
|
t->Translate(0, 0, dy * factor);
|
||||||
|
break;
|
||||||
|
case ROT_X:
|
||||||
|
t->RotateX(dy);
|
||||||
|
break;
|
||||||
|
case ROT_Y:
|
||||||
|
t->RotateY(dx);
|
||||||
|
break;
|
||||||
|
case ROT_Z:
|
||||||
|
t->RotateZ(dx);
|
||||||
|
break;
|
||||||
|
case SCALE_X:
|
||||||
|
t->Scale(std::max(0.1, 1.0 + dx * factor), 1.0, 1.0);
|
||||||
|
break;
|
||||||
|
case SCALE_Y:
|
||||||
|
t->Scale(1.0, std::max(0.1, 1.0 + dy * factor), 1.0);
|
||||||
|
break;
|
||||||
|
case SCALE_Z:
|
||||||
|
t->Scale(1.0, 1.0, std::max(0.1, 1.0 + dy * factor));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this->Prop3D->SetUserMatrix(t->GetMatrix());
|
||||||
|
this->UpdateGizmoPosition();
|
||||||
|
|
||||||
|
this->InvokeEvent(::vtkCommand::InteractionEvent, nullptr);
|
||||||
|
this->Interactor->Render();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::PlaceWidget(double bounds[6]) {
|
||||||
|
(void)bounds;
|
||||||
|
this->UpdateGizmoPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::PlaceWidget() { this->UpdateGizmoPosition(); }
|
||||||
|
|
||||||
|
void vtkHandlerWidget::SetTransform(::vtkTransform *t) {
|
||||||
|
if (!t || !this->Prop3D)
|
||||||
|
return;
|
||||||
|
this->Prop3D->SetUserMatrix(t->GetMatrix());
|
||||||
|
this->UpdateGizmoPosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::GetTransform(::vtkTransform *t) {
|
||||||
|
if (!t || !this->Prop3D)
|
||||||
|
return;
|
||||||
|
t->SetMatrix(this->Prop3D->GetUserMatrix());
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::CreateGizmos() {
|
||||||
|
auto create_arrow = [](double dir[3], double color[3]) {
|
||||||
|
auto arrow = vtkSmartPointer<::vtkArrowSource>::New();
|
||||||
|
auto mapper = vtkSmartPointer<::vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputConnection(arrow->GetOutputPort());
|
||||||
|
auto actor = vtkSmartPointer<::vtkActor>::New();
|
||||||
|
actor->SetMapper(mapper);
|
||||||
|
actor->GetProperty()->SetColor(color);
|
||||||
|
|
||||||
|
auto t = vtkSmartPointer<::vtkTransform>::New();
|
||||||
|
if (dir[1] > 0)
|
||||||
|
t->RotateZ(90);
|
||||||
|
else if (dir[2] > 0)
|
||||||
|
t->RotateY(-90);
|
||||||
|
actor->SetUserTransform(t);
|
||||||
|
return actor;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto create_ring = [](int axis, double color[3]) {
|
||||||
|
auto arc = vtkSmartPointer<::vtkArcSource>::New();
|
||||||
|
arc->SetCenter(0, 0, 0);
|
||||||
|
arc->SetResolution(64);
|
||||||
|
if (axis == 0) {
|
||||||
|
arc->SetPoint1(0, 1, 0);
|
||||||
|
arc->SetPoint2(0, -1, 0);
|
||||||
|
} else if (axis == 1) {
|
||||||
|
arc->SetPoint1(1, 0, 0);
|
||||||
|
arc->SetPoint2(-1, 0, 0);
|
||||||
|
} else if (axis == 2) {
|
||||||
|
arc->SetPoint1(1, 0, 0);
|
||||||
|
arc->SetPoint2(-1, 0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
auto mapper = vtkSmartPointer<::vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputConnection(arc->GetOutputPort());
|
||||||
|
auto actor = vtkSmartPointer<::vtkActor>::New();
|
||||||
|
actor->SetMapper(mapper);
|
||||||
|
actor->GetProperty()->SetColor(color);
|
||||||
|
actor->GetProperty()->SetLineWidth(3);
|
||||||
|
return actor;
|
||||||
|
};
|
||||||
|
|
||||||
|
double red[] = {0.8, 0.1, 0.1}, green[] = {0.1, 0.8, 0.1},
|
||||||
|
blue[] = {0.1, 0.1, 0.8};
|
||||||
|
|
||||||
|
double x[] = {1, 0, 0}, y[] = {0, 1, 0}, z[] = {0, 0, 1};
|
||||||
|
m_AxesX = create_arrow(x, red);
|
||||||
|
m_AxesY = create_arrow(y, green);
|
||||||
|
m_AxesZ = create_arrow(z, blue);
|
||||||
|
|
||||||
|
m_RotX = create_ring(0, red);
|
||||||
|
m_RotY = create_ring(1, green);
|
||||||
|
m_RotZ = create_ring(2, blue);
|
||||||
|
|
||||||
|
auto create_cube = [](double pos[3], double color[3]) {
|
||||||
|
auto cube = vtkSmartPointer<::vtkCubeSource>::New();
|
||||||
|
cube->SetCenter(pos[0], pos[1], pos[2]);
|
||||||
|
cube->SetXLength(0.12);
|
||||||
|
cube->SetYLength(0.12);
|
||||||
|
cube->SetZLength(0.12);
|
||||||
|
auto mapper = vtkSmartPointer<::vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
|
auto actor = vtkSmartPointer<::vtkActor>::New();
|
||||||
|
actor->SetMapper(mapper);
|
||||||
|
actor->GetProperty()->SetColor(color);
|
||||||
|
return actor;
|
||||||
|
};
|
||||||
|
|
||||||
|
double px[] = {1.2, 0, 0}, py[] = {0, 1.2, 0}, pz[] = {0, 0, 1.2};
|
||||||
|
m_ScaleX = create_cube(px, red);
|
||||||
|
m_ScaleY = create_cube(py, green);
|
||||||
|
m_ScaleZ = create_cube(pz, blue);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkHandlerWidget::UpdateGizmoPosition() {
|
||||||
|
if (!this->Prop3D)
|
||||||
|
return;
|
||||||
|
::vtkMatrix4x4 *mat = this->Prop3D->GetMatrix();
|
||||||
|
m_AxesX->SetUserMatrix(mat);
|
||||||
|
m_AxesY->SetUserMatrix(mat);
|
||||||
|
m_AxesZ->SetUserMatrix(mat);
|
||||||
|
m_RotX->SetUserMatrix(mat);
|
||||||
|
m_RotY->SetUserMatrix(mat);
|
||||||
|
m_RotZ->SetUserMatrix(mat);
|
||||||
|
m_ScaleX->SetUserMatrix(mat);
|
||||||
|
m_ScaleY->SetUserMatrix(mat);
|
||||||
|
m_ScaleZ->SetUserMatrix(mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
111
src/Vtk/vtkHandlerWidget.h
Normal file
111
src/Vtk/vtkHandlerWidget.h
Normal file
@@ -0,0 +1,111 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||||
|
All rights reserved
|
||||||
|
|
||||||
|
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||||
|
|
||||||
|
------------------------------------------------------------------
|
||||||
|
This library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 3.0 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
This library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with this library.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#ifndef U_VTKHANDLERWIDGET_H
|
||||||
|
#define U_VTKHANDLERWIDGET_H
|
||||||
|
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "uLibVtkInterface.h"
|
||||||
|
|
||||||
|
#include <vtk3DWidget.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
|
// Forward declarations of VTK classes in global namespace
|
||||||
|
class vtkActor;
|
||||||
|
class vtkCallbackCommand;
|
||||||
|
class vtkPropPicker;
|
||||||
|
class vtkTransform;
|
||||||
|
class vtkObject;
|
||||||
|
class vtkRenderWindowInteractor;
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @class vtkHandlerWidget
|
||||||
|
* @brief A Blender-like transform gizmo for move, rotate, and scale.
|
||||||
|
*/
|
||||||
|
class vtkHandlerWidget : public ::vtk3DWidget {
|
||||||
|
public:
|
||||||
|
static vtkHandlerWidget *New();
|
||||||
|
vtkTypeMacro(vtkHandlerWidget, ::vtk3DWidget);
|
||||||
|
|
||||||
|
vtkHandlerWidget();
|
||||||
|
virtual ~vtkHandlerWidget();
|
||||||
|
|
||||||
|
virtual void SetEnabled(int enabling) override;
|
||||||
|
static void ProcessEvents(::vtkObject *caller, unsigned long event,
|
||||||
|
void *clientdata, void *calldata);
|
||||||
|
|
||||||
|
void OnLeftButtonDown();
|
||||||
|
void OnLeftButtonUp();
|
||||||
|
void OnMouseMove();
|
||||||
|
|
||||||
|
enum InteractionState {
|
||||||
|
IDLE = 0,
|
||||||
|
TRANS_X,
|
||||||
|
TRANS_Y,
|
||||||
|
TRANS_Z,
|
||||||
|
ROT_X,
|
||||||
|
ROT_Y,
|
||||||
|
ROT_Z,
|
||||||
|
SCALE_X,
|
||||||
|
SCALE_Y,
|
||||||
|
SCALE_Z
|
||||||
|
};
|
||||||
|
|
||||||
|
using ::vtk3DWidget::PlaceWidget;
|
||||||
|
virtual void PlaceWidget(double bounds[6]) override;
|
||||||
|
virtual void PlaceWidget() override;
|
||||||
|
|
||||||
|
// Transform handling //
|
||||||
|
void SetTransform(::vtkTransform *t);
|
||||||
|
void GetTransform(::vtkTransform *t);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void CreateGizmos();
|
||||||
|
void UpdateGizmoPosition();
|
||||||
|
|
||||||
|
int Interaction;
|
||||||
|
|
||||||
|
// Visual components //
|
||||||
|
vtkSmartPointer<::vtkActor> m_AxesX, m_AxesY, m_AxesZ; // Arrows
|
||||||
|
vtkSmartPointer<::vtkActor> m_RotX, m_RotY, m_RotZ; // Rings
|
||||||
|
vtkSmartPointer<::vtkActor> m_ScaleX, m_ScaleY, m_ScaleZ; // Cubes
|
||||||
|
|
||||||
|
vtkSmartPointer<::vtkPropPicker> m_Picker;
|
||||||
|
|
||||||
|
double StartEventPosition[2];
|
||||||
|
vtkSmartPointer<::vtkTransform> m_InitialTransform;
|
||||||
|
|
||||||
|
private:
|
||||||
|
vtkHandlerWidget(const vtkHandlerWidget &) = delete;
|
||||||
|
void operator=(const vtkHandlerWidget &) = delete;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
#endif // U_VTKHANDLERWIDGET_H
|
||||||
Reference in New Issue
Block a user