move vtk containerbox in math
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
set(HEADERS uLibVtkInterface.h
|
||||
uLibVtkViewer.h
|
||||
vtkContainerBox.h
|
||||
vtkHandlerWidget.h
|
||||
vtkQViewport.h
|
||||
vtkViewport.h
|
||||
@@ -10,7 +9,6 @@ set(HEADERS uLibVtkInterface.h
|
||||
|
||||
set(SOURCES uLibVtkInterface.cxx
|
||||
uLibVtkViewer.cpp
|
||||
vtkContainerBox.cpp
|
||||
vtkHandlerWidget.cpp
|
||||
vtkQViewport.cpp
|
||||
vtkViewport.cpp
|
||||
|
||||
@@ -34,7 +34,7 @@
|
||||
#include "HEP/Detectors/DetectorChamber.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include <vtkActor.h>
|
||||
#include <vtkBoxWidget.h>
|
||||
#include <vtkTransformPolyDataFilter.h>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Vtk/HEP/Geant/vtkGeantEvent.h"
|
||||
#include "Vtk/HEP/Geant/vtkEmitterPrimary.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkCallbackCommand.h>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Vtk/HEP/Geant/vtkGeantEvent.h"
|
||||
#include "Vtk/HEP/Geant/vtkEmitterPrimary.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include "HEP/Detectors/DetectorChamber.h"
|
||||
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#include "Math/Units.h"
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Vtk/HEP/Geant/vtkGeantEvent.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkCallbackCommand.h>
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Vtk/HEP/Geant/vtkGeantEvent.h"
|
||||
#include "Vtk/HEP/Geant/vtkEmitterPrimary.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include "HEP/Detectors/DetectorChamber.h"
|
||||
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||
|
||||
|
||||
@@ -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}/vtkContainerBox.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkCylinder.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
@@ -17,6 +18,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}/vtkContainerBox.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkCylinder.h
|
||||
PARENT_SCOPE)
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ set(TESTS
|
||||
vtkQuadMeshTest
|
||||
vtkVoxImageTest
|
||||
vtkVoxImageInteractiveTest
|
||||
vtkContainerBoxTest
|
||||
vtkContainerBoxTest2
|
||||
)
|
||||
|
||||
|
||||
41
src/Vtk/Math/testing/testing-prototype.h
Normal file
41
src/Vtk/Math/testing/testing-prototype.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <stdio.h>
|
||||
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
|
||||
|
||||
#define BEGIN_TESTING(name) \
|
||||
static int _fail = 0; \
|
||||
printf("..:: Testing " #name " ::..\n");
|
||||
|
||||
#define TEST1(val) _fail += (val)==0
|
||||
#define TEST0(val) _fail += (val)!=0
|
||||
#define END_TESTING return _fail;
|
||||
|
||||
|
||||
109
src/Vtk/Math/testing/vtkAssemblyTest.cpp
Normal file
109
src/Vtk/Math/testing/vtkAssemblyTest.cpp
Normal file
@@ -0,0 +1,109 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
|
||||
// All rights reserved
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Vtk/Math/vtkAssembly.h"
|
||||
#include "Vtk/Math/vtkCylinder.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include "Math/Assembly.h"
|
||||
#include "Math/Cylinder.h"
|
||||
#include "Math/ContainerBox.h"
|
||||
#include "Math/Units.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
/**
|
||||
* @brief This test verifies that uLib::Vtk::Assembly correctly visualizes a collection
|
||||
* of objects and that transformations applied to the assembly are propagated to its children.
|
||||
* It also checks that the assembly appears as a bounding box of its contents.
|
||||
*/
|
||||
int main() {
|
||||
std::cout << "Starting vtkAssemblyTest..." << std::endl;
|
||||
|
||||
// 1. Setup Core Geometry
|
||||
std::cout << " - Creating core Assembly..." << std::endl;
|
||||
uLib::Assembly* core_assembly = new uLib::Assembly();
|
||||
core_assembly->SetInstanceName("MainAssembly");
|
||||
|
||||
// Add a box
|
||||
std::cout << " - Adding ChildBox (Red)..." << std::endl;
|
||||
ContainerBox* box = new ContainerBox();
|
||||
box->SetInstanceName("ChildBox");
|
||||
box->Translate(Vector3f(1.0, 0, 0));
|
||||
core_assembly->AddObject(box);
|
||||
|
||||
// Add a cylinder
|
||||
// std::cout << " - Adding ChildCylinder (Blue)..." << std::endl;
|
||||
// Cylinder* cyl = new Cylinder(0.5, 2.0);
|
||||
// cyl->SetInstanceName("ChildCylinder");
|
||||
// cyl->Translate(Vector3f(-2.0, 0, 0));
|
||||
// core_assembly->AddObject(cyl);
|
||||
|
||||
std::cout << " - Adding another box (Green)..." << std::endl;
|
||||
ContainerBox* box2 = new ContainerBox();
|
||||
box2->Scale(Vector3f(1.0, 1.0, 2.0));
|
||||
box2->SetInstanceName("ChildBox2");
|
||||
box2->Translate(Vector3f(0, 0, 1.0));
|
||||
core_assembly->AddObject(box2);
|
||||
|
||||
// 2. Setup VTK Representation
|
||||
std::cout << " - Creating VTK Assembly representation..." << std::endl;
|
||||
Vtk::Assembly vtk_assembly(core_assembly);
|
||||
|
||||
// Find and colorized the children puppets
|
||||
Vtk::Puppet* p_box = vtk_assembly.GetPuppet(box);
|
||||
if (p_box) {
|
||||
p_box->SetColor(1.0, 0.0, 0.0); // Red
|
||||
} else {
|
||||
std::cerr << "Warning: Could not find puppet for box!" << std::endl;
|
||||
}
|
||||
|
||||
// Vtk::Puppet* p_cyl = vtk_assembly.GetPuppet(cyl);
|
||||
// if (p_cyl) {
|
||||
// p_cyl->SetColor(0.0, 0.0, 1.0); // Blue
|
||||
// } else {
|
||||
// std::cerr << "Warning: Could not find puppet for cylinder!" << std::endl;
|
||||
// }
|
||||
|
||||
Vtk::Puppet* p_box2 = vtk_assembly.GetPuppet(box2);
|
||||
if (p_box2) {
|
||||
p_box2->SetColor(0.0, 1.0, 0.0); // Green
|
||||
} else {
|
||||
std::cerr << "Warning: Could not find puppet for box2!" << std::endl;
|
||||
}
|
||||
|
||||
// 3. Test Transformation Propagation
|
||||
std::cout << " - Rotating Assembly 45 degrees around Z..." << std::endl;
|
||||
core_assembly->Rotate(45.0_deg, Vector3f::UnitZ());
|
||||
|
||||
std::cout << " - Translating Assembly up (+Y)..." << std::endl;
|
||||
core_assembly->Translate(Vector3f(0, 2.0, 0));
|
||||
|
||||
// Notify all puppets of the change
|
||||
core_assembly->Updated();
|
||||
|
||||
// 4. Run Visualization
|
||||
std::cout << "Starting viewer (close to exit)..." << std::endl;
|
||||
std::cout << "Expected: A white bounding box containing a red box and a blue cylinder, "
|
||||
<< "all rotated and translated as a group." << std::endl;
|
||||
|
||||
Vtk::Viewer viewer;
|
||||
viewer.AddPuppet(*p_box);
|
||||
viewer.AddPuppet(*p_box2);
|
||||
viewer.AddPuppet(vtk_assembly);
|
||||
viewer.Start();
|
||||
|
||||
// Clean up
|
||||
delete core_assembly;
|
||||
delete box;
|
||||
delete box2;
|
||||
// delete cyl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -27,7 +27,7 @@
|
||||
|
||||
#include "Math/ContainerBox.h"
|
||||
#include "Math/Units.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Math/ContainerBox.h"
|
||||
#include "Math/Units.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
@@ -86,33 +86,40 @@ void vtkContainerBox::contentUpdate() {
|
||||
m_Axes->SetUserMatrix(nullptr);
|
||||
|
||||
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));
|
||||
}
|
||||
Matrix4fToVtk(transform, vmat);
|
||||
|
||||
root->Modified();
|
||||
m_BlockUpdate = true;
|
||||
Puppet::Update();
|
||||
}
|
||||
|
||||
|
||||
void vtkContainerBox::Update() {
|
||||
if (!m_Content) return;
|
||||
|
||||
if (m_BlockUpdate) {
|
||||
m_BlockUpdate = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// Use Targeted Blocking: only block the feedback connection to this puppet
|
||||
// boost::signals2::shared_connection_block block(m_Connection);
|
||||
|
||||
vtkProp3D* assembly = vtkProp3D::SafeDownCast(this->GetProp());
|
||||
if (!assembly) return;
|
||||
|
||||
vtkMatrix4x4* vmat = assembly->GetUserMatrix();
|
||||
if (!vmat) return;
|
||||
|
||||
Matrix4f transform = VtkToMatrix4f(vmat);
|
||||
|
||||
// Update uLib model's affine transform
|
||||
if (m_Content->GetParent()) {
|
||||
Matrix4f localT = m_Content->GetParent()->GetWorldMatrix().inverse() * transform;
|
||||
m_Content->SetMatrix(localT);
|
||||
} else {
|
||||
m_Content->SetMatrix(transform);
|
||||
}
|
||||
// if (m_Content->GetParent()) {
|
||||
// Matrix4f localT = m_Content->GetParent()->GetWorldMatrix().inverse() * transform;
|
||||
// m_Content->SetMatrix(localT);
|
||||
// } else {
|
||||
m_Content->SetMatrix(transform);
|
||||
// }
|
||||
|
||||
m_Content->Updated(); // Notify change
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkPolydata.h"
|
||||
#include <vtkActor.h>
|
||||
#include <boost/signals2/connection.hpp>
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
@@ -55,6 +56,8 @@ protected:
|
||||
// vtkActor *m_Pivot;
|
||||
|
||||
Content *m_Content;
|
||||
bool m_BlockUpdate = false;
|
||||
// boost::signals2::connection m_Connection;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
@@ -1,7 +1,6 @@
|
||||
# TESTS
|
||||
set( TESTS
|
||||
set(TESTS
|
||||
vtkViewerTest
|
||||
vtkContainerBoxTest
|
||||
vtkHandlerWidget
|
||||
PuppetPropertyTest
|
||||
# vtkVoxImageTest
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
#include "Math/ContainerBox.h"
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include "Vtk/vtkHandlerWidget.h"
|
||||
#include "testing-prototype.h"
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include "vtkObjectsContext.h"
|
||||
#include "Vtk/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
#include "Vtk/Math/vtkCylinder.h"
|
||||
#include "HEP/Detectors/vtkDetectorChamber.h"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user