add cylinder
This commit is contained in:
@@ -8,6 +8,7 @@ set(MATH_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkTriangleMesh.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkQuadMesh.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkVoxImage.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkCylinder.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
set(MATH_HEADERS
|
||||
@@ -16,6 +17,7 @@ set(MATH_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkTriangleMesh.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkQuadMesh.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkVoxImage.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkCylinder.h
|
||||
PARENT_SCOPE)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
|
||||
144
src/Vtk/Math/vtkCylinder.cpp
Normal file
144
src/Vtk/Math/vtkCylinder.cpp
Normal file
@@ -0,0 +1,144 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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/Math/vtkCylinder.h"
|
||||
#include <vtkActor.h>
|
||||
#include <vtkCylinderSource.h>
|
||||
#include <vtkMatrix4x4.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkProperty.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkTransform.h>
|
||||
#include "Math/vtkDense.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
vtkCylinder::vtkCylinder(vtkCylinder::Content *content)
|
||||
: m_Actor(vtkActor::New()), m_Content(content) {
|
||||
this->InstallPipe();
|
||||
Object::connect(m_Content, &Content::Updated, this, &vtkCylinder::contentUpdate);
|
||||
}
|
||||
|
||||
vtkCylinder::~vtkCylinder() {
|
||||
m_Actor->Delete();
|
||||
}
|
||||
|
||||
void vtkCylinder::contentUpdate() {
|
||||
if (!m_Content)
|
||||
return;
|
||||
|
||||
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (!root) return;
|
||||
|
||||
vtkMatrix4x4* vmat = root->GetUserMatrix();
|
||||
if (!vmat) {
|
||||
vtkNew<vtkMatrix4x4> mat;
|
||||
root->SetUserMatrix(mat);
|
||||
vmat = mat;
|
||||
}
|
||||
|
||||
// Multiply the placement matrix by the volume scaling (Radius, Radius, Height)
|
||||
Matrix4f transform = m_Content->GetMatrix() * m_Content->GetLocalMatrix();
|
||||
Matrix4fToVtk(transform, vmat);
|
||||
|
||||
// Update internal alignment based on active axis
|
||||
vtkTransform* alignment = vtkTransform::SafeDownCast(m_Actor->GetUserTransform());
|
||||
if (alignment) {
|
||||
alignment->Identity();
|
||||
int axis = m_Content->GetAxis();
|
||||
if (axis == 0) alignment->RotateZ(-90); // Y -> X
|
||||
else if (axis == 1) ; // Y -> Y (identity)
|
||||
else if (axis == 2) alignment->RotateX(90); // Y -> Z
|
||||
|
||||
// We keep it centered as per latest user preference in Step 677
|
||||
// alignment->Translate(0, 0, 0); // Implicit
|
||||
}
|
||||
|
||||
root->Modified();
|
||||
Puppet::Update();
|
||||
}
|
||||
|
||||
void vtkCylinder::Update() {
|
||||
if (!m_Content) return;
|
||||
|
||||
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (!root) return;
|
||||
|
||||
vtkMatrix4x4* vmat = root->GetUserMatrix();
|
||||
if (!vmat) return;
|
||||
|
||||
Matrix4f fullTransform = VtkToMatrix4f(vmat);
|
||||
Matrix4f placementScale = m_Content->GetLocalMatrix().inverse();
|
||||
Matrix4f transform = fullTransform * placementScale;
|
||||
|
||||
if (m_Content->GetParent()) {
|
||||
Matrix4f localT = m_Content->GetParent()->GetWorldMatrix().inverse() * transform;
|
||||
m_Content->SetMatrix(localT);
|
||||
} else {
|
||||
m_Content->SetMatrix(transform);
|
||||
}
|
||||
|
||||
m_Content->Updated();
|
||||
}
|
||||
|
||||
void vtkCylinder::InstallPipe() {
|
||||
if (!m_Content)
|
||||
return;
|
||||
|
||||
vtkNew<vtkCylinderSource> cylinder;
|
||||
cylinder->SetRadius(1.0);
|
||||
cylinder->SetHeight(1.0);
|
||||
cylinder->SetResolution(32);
|
||||
|
||||
vtkNew<vtkTransform> alignment;
|
||||
alignment->Identity();
|
||||
alignment->Translate(0, 0, -0.5);
|
||||
|
||||
// Default to Y alignment (Identity) as per latest request
|
||||
int axis = m_Content->GetAxis();
|
||||
if (axis == 0) alignment->RotateZ(-90);
|
||||
else if (axis == 2) alignment->RotateX(90);
|
||||
|
||||
vtkNew<vtkPolyDataMapper> mapper;
|
||||
mapper->SetInputConnection(cylinder->GetOutputPort());
|
||||
|
||||
m_Actor->SetMapper(mapper);
|
||||
m_Actor->SetUserTransform(alignment);
|
||||
m_Actor->GetProperty()->SetRepresentationToWireframe();
|
||||
m_Actor->GetProperty()->SetAmbient(0.6);
|
||||
|
||||
this->SetProp(m_Actor);
|
||||
|
||||
vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (root) {
|
||||
vtkNew<vtkMatrix4x4> vmat;
|
||||
Matrix4fToVtk(m_Content->GetMatrix() * m_Content->GetLocalMatrix(), vmat);
|
||||
root->SetUserMatrix(vmat);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
67
src/Vtk/Math/vtkCylinder.h
Normal file
67
src/Vtk/Math/vtkCylinder.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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_VTKCYLINDER_H
|
||||
#define U_VTKCYLINDER_H
|
||||
|
||||
#include "Math/Cylinder.h"
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
#include <vtkActor.h>
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
/**
|
||||
* @brief VTK representation of the uLib::Cylinder object.
|
||||
*
|
||||
* This class wraps a vtkCylinderSource and synchronizes it with the
|
||||
* mathematical state of a Cylinder object. It manages the alignment
|
||||
* between VTK's Y-centered cylinder and uLib's Z-based coordinate system.
|
||||
*/
|
||||
class vtkCylinder : public Puppet {
|
||||
typedef Cylinder Content;
|
||||
|
||||
public:
|
||||
vtkCylinder(Content *content);
|
||||
virtual ~vtkCylinder();
|
||||
|
||||
/** Synchronizes the VTK actor with the uLib model matrix */
|
||||
virtual void contentUpdate();
|
||||
|
||||
/** Synchronizes the uLib model matrix with the VTK actor (e.g., after UI manipulation) */
|
||||
virtual void Update();
|
||||
|
||||
protected:
|
||||
/** Sets up the VTK visualization pipeline */
|
||||
virtual void InstallPipe();
|
||||
|
||||
vtkActor *m_Actor;
|
||||
Content *m_Content;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
#endif // U_VTKCYLINDER_H
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "vtkObjectsContext.h"
|
||||
#include "vtkContainerBox.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkCylinder.h"
|
||||
#include "HEP/Detectors/vtkDetectorChamber.h"
|
||||
|
||||
#include <vtkAssembly.h>
|
||||
@@ -128,6 +129,8 @@ Puppet* vtkObjectsContext::CreatePuppet(uLib::Object* obj) {
|
||||
return new vtkContainerBox(static_cast<uLib::ContainerBox*>(obj));
|
||||
} else if (std::strcmp(className, "DetectorChamber") == 0) {
|
||||
return new vtkDetectorChamber(static_cast<uLib::DetectorChamber*>(obj));
|
||||
} else if (std::strcmp(className, "Cylinder") == 0) {
|
||||
return new vtkCylinder(static_cast<uLib::Cylinder*>(obj));
|
||||
}
|
||||
|
||||
// Fallback if we don't know the exact class but it might be a context itself
|
||||
|
||||
Reference in New Issue
Block a user