/*////////////////////////////////////////////////////////////////////////////// // 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 > //////////////////////////////////////////////////////////////////////////////*/ #include "Vtk/HEP/Geant/vtkBoxSolid.h" #include "Vtk/HEP/Geant/vtkTessellatedSolid.h" #include "Vtk/uLibVtkViewer.h" #include "HEP/Geant/Solid.h" #include "Math/ContainerBox.h" #include "Math/TriangleMesh.h" #include "Math/Units.h" #include #include using namespace uLib; int main(int argc, char** argv) { bool interactive = (argc > 1 && std::string(argv[1]) == "-i"); // 1. Create a BoxSolid ContainerBox box; box.Scale(Vector3f(1_m, 2_m, 3_m)); Geant::BoxSolid gBox("MyBox", &box); gBox.Update(); Vtk::vtkBoxSolid vtkBox(&gBox); // 2. Create a TessellatedSolid Geant::TessellatedSolid gTess("MyTess"); TriangleMesh mesh; // Create a simple pyramid mesh.Points().push_back(Vector3f(0, 0, 1_m)); // apex mesh.Points().push_back(Vector3f(-1_m, -1_m, 0)); mesh.Points().push_back(Vector3f( 1_m, -1_m, 0)); mesh.Points().push_back(Vector3f( 1_m, 1_m, 0)); mesh.Points().push_back(Vector3f(-1_m, 1_m, 0)); mesh.Triangles().push_back(Vector3i(1, 2, 0)); mesh.Triangles().push_back(Vector3i(2, 3, 0)); mesh.Triangles().push_back(Vector3i(3, 4, 0)); mesh.Triangles().push_back(Vector3i(4, 1, 0)); mesh.Triangles().push_back(Vector3i(1, 3, 2)); // base mesh.Triangles().push_back(Vector3i(1, 4, 3)); // base gTess.SetMesh(mesh); gTess.Update(); Vtk::vtkTessellatedSolid vtkTess(&gTess); // 3. Visualization setup Vtk::Viewer viewer; vtkBox.AddToViewer(viewer); vtkTess.AddToViewer(viewer); // Color them differently vtkActor::SafeDownCast(vtkBox.GetProp())->GetProperty()->SetColor(0.8, 0.2, 0.2); // Redish box vtkActor::SafeDownCast(vtkTess.GetProp())->GetProperty()->SetColor(0.2, 0.8, 0.2); // Greenish tess // Position tessellated solid away from box Matrix4f trans = Matrix4f::Identity(); trans.block<3,1>(0,3) = Vector3f(5_m, 0, 0); gTess.SetTransform(trans); vtkTess.Update(); std::cout << "..:: Testing vtkSolidsTest ::.." << std::endl; std::cout << "Box and Tessellated solids initialized." << std::endl; if (interactive) { viewer.ZoomAuto(); viewer.Start(); } else { std::cout << "Non-interactive test passed." << std::endl; } return 0; }