move vtk containerbox in math
This commit is contained in:
@@ -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;
|
||||
}
|
||||
58
src/Vtk/Math/testing/vtkContainerBoxTest.cpp
Normal file
58
src/Vtk/Math/testing/vtkContainerBoxTest.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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/uLibVtkViewer.h"
|
||||
|
||||
#include "Math/ContainerBox.h"
|
||||
#include "Math/Units.h"
|
||||
#include "Vtk/Math/vtkContainerBox.h"
|
||||
|
||||
#include "testing-prototype.h"
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
int main() {
|
||||
BEGIN_TESTING(vtk ContainerBox Test);
|
||||
|
||||
ContainerBox box;
|
||||
box.Scale(Vector3f(1_m,5_m,1_m));
|
||||
box.SetPosition(Vector3f(0,1_m,0));
|
||||
Vtk::vtkContainerBox v_box(&box);
|
||||
v_box.SetRepresentation(Vtk::Puppet::Surface);
|
||||
v_box.SetOpacity(0.5);
|
||||
v_box.SetSelectable(true);
|
||||
|
||||
box.findOrAddSignal(&ContainerBox::Updated)->connect([&box](){
|
||||
std::cout << "box updated: " << box.GetWorldPoint(HPoint3f(1,1,1)) << std::endl;
|
||||
});
|
||||
|
||||
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||
Vtk::Viewer v_viewer;
|
||||
v_viewer.AddPuppet(v_box);
|
||||
v_viewer.Start();
|
||||
}
|
||||
|
||||
END_TESTING;
|
||||
}
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user