From 32a1104769bd4400f2b3e0f2cc3ebd23ccec815f Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Sun, 8 Mar 2026 08:46:21 +0000 Subject: [PATCH] detector chamber in vtk --- src/Vtk/HEP/Detectors/CMakeLists.txt | 2 + src/Vtk/HEP/Detectors/testing/CMakeLists.txt | 1 + .../testing/vtkDetectorChamberTest.cpp | 52 +++++++ src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx | 50 ++++++ src/Vtk/HEP/Detectors/vtkDetectorChamber.h | 73 +++++++++ src/Vtk/vtkContainerBox.cpp | 144 ++++++++---------- src/Vtk/vtkContainerBox.h | 31 ++-- 7 files changed, 258 insertions(+), 95 deletions(-) create mode 100644 src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.cpp create mode 100644 src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx create mode 100644 src/Vtk/HEP/Detectors/vtkDetectorChamber.h diff --git a/src/Vtk/HEP/Detectors/CMakeLists.txt b/src/Vtk/HEP/Detectors/CMakeLists.txt index 1937a8f..d851818 100644 --- a/src/Vtk/HEP/Detectors/CMakeLists.txt +++ b/src/Vtk/HEP/Detectors/CMakeLists.txt @@ -9,11 +9,13 @@ set(HEP_DETECTORS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.cxx ${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.cxx + ${CMAKE_CURRENT_SOURCE_DIR}/vtkDetectorChamber.cxx PARENT_SCOPE) set(HEP_DETECTORS_HEADERS ${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.h ${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.h + ${CMAKE_CURRENT_SOURCE_DIR}/vtkDetectorChamber.h PARENT_SCOPE) if(BUILD_TESTING) diff --git a/src/Vtk/HEP/Detectors/testing/CMakeLists.txt b/src/Vtk/HEP/Detectors/testing/CMakeLists.txt index 2e36c4b..6e49e62 100644 --- a/src/Vtk/HEP/Detectors/testing/CMakeLists.txt +++ b/src/Vtk/HEP/Detectors/testing/CMakeLists.txt @@ -1,6 +1,7 @@ # TESTS set(TESTS vtkMuonScatterTest + vtkDetectorChamberTest ) set(LIBRARIES diff --git a/src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.cpp b/src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.cpp new file mode 100644 index 0000000..6a8d0ee --- /dev/null +++ b/src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.cpp @@ -0,0 +1,52 @@ +/*////////////////////////////////////////////////////////////////////////////// +// 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_AUTO_TEST_CASE(vtkDetectorChamberTest) { + uLib::DetectorChamber content; + content.SetSize(uLib::Vector3f(10, 10, 10)); + content.SetPosition(uLib::Vector3f(0, 0, 0)); + + uLib::Vtk::vtkDetectorChamber vtkDetectorChamber(&content); + + if (!vtkDetectorChamber.GetProp()) { + BOOST_FAIL("vtkDetectorChamber::GetProp() returned NULL"); + } + + if (std::getenv("CTEST_PROJECT_NAME") == nullptr) { + uLib::Vtk::Viewer viewer; + viewer.AddPuppet(vtkDetectorChamber); + viewer.Start(); + } + + BOOST_CHECK(true); // reached here without crash +} \ No newline at end of file diff --git a/src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx b/src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx new file mode 100644 index 0000000..d3196df --- /dev/null +++ b/src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx @@ -0,0 +1,50 @@ +/*////////////////////////////////////////////////////////////////////////////// +// 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 "Vtk/vtkContainerBox.h" + +namespace uLib { +namespace Vtk { + +vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content) + : vtkContainerBox(content) { + InstallPipe(); +} + +vtkDetectorChamber::~vtkDetectorChamber() {} + +DetectorChamber *vtkDetectorChamber::GetContent() { + return static_cast(m_Content); +} + +void vtkDetectorChamber::PrintSelf(std::ostream &o) const { + vtkContainerBox::PrintSelf(o); +} + +void vtkDetectorChamber::InstallPipe() { vtkContainerBox::InstallPipe(); } + +} // namespace Vtk +} // namespace uLib \ No newline at end of file diff --git a/src/Vtk/HEP/Detectors/vtkDetectorChamber.h b/src/Vtk/HEP/Detectors/vtkDetectorChamber.h new file mode 100644 index 0000000..3c7b3b9 --- /dev/null +++ b/src/Vtk/HEP/Detectors/vtkDetectorChamber.h @@ -0,0 +1,73 @@ +/*////////////////////////////////////////////////////////////////////////////// +// 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 +#include +#include +#include +#include +#include + +#include +#include + +#include + +#include +#include + +#include "Math/Dense.h" + +#include "HEP/Detectors/DetectorChamber.h" +#include "Vtk/uLibVtkInterface.h" +#include "Vtk/vtkContainerBox.h" + +namespace uLib { +namespace Vtk { + +class vtkDetectorChamber : public vtkContainerBox { + typedef DetectorChamber Content; + +public: + vtkDetectorChamber(DetectorChamber *content); + ~vtkDetectorChamber(); + + Content *GetContent(); + + void PrintSelf(std::ostream &o) const; + +private: + void InstallPipe(); + + vtkDetectorChamber::Content *content; +}; + +} // namespace Vtk +} // namespace uLib + +#endif // VTK_DETECTOR_CHAMBER_H diff --git a/src/Vtk/vtkContainerBox.cpp b/src/Vtk/vtkContainerBox.cpp index f403cfe..6d11239 100644 --- a/src/Vtk/vtkContainerBox.cpp +++ b/src/Vtk/vtkContainerBox.cpp @@ -23,107 +23,95 @@ //////////////////////////////////////////////////////////////////////////////*/ - - - #ifdef HAVE_CONFIG_H #include "config.h" #endif - -#include -#include #include -#include #include +#include +#include +#include #include #include -#include +#include #include "vtkContainerBox.h" namespace uLib { namespace Vtk { - -vtkContainerBox::vtkContainerBox(vtkContainerBox::Content &content) : - m_Cube(vtkActor::New()), - m_Axes(vtkActor::New()), - m_Pivot(vtkActor::New()), - m_Content(&content) -{ - this->InstallPipe(); +vtkContainerBox::vtkContainerBox(vtkContainerBox::Content *content) + : m_Cube(vtkActor::New()), m_Axes(vtkActor::New()), + m_Pivot(vtkActor::New()), m_Content(content) { + this->InstallPipe(); } -vtkContainerBox::~vtkContainerBox() -{ - m_Cube->Delete(); - m_Axes->Delete(); - m_Pivot->Delete(); +vtkContainerBox::~vtkContainerBox() { + m_Cube->Delete(); + m_Axes->Delete(); + m_Pivot->Delete(); } -vtkPolyData *vtkContainerBox::GetPolyData() const -{ - // TODO - return NULL; +vtkPolyData *vtkContainerBox::GetPolyData() const { + // TODO + return NULL; } -void vtkContainerBox::InstallPipe() -{ - if(!m_Content) return; - Content *c = m_Content; +void vtkContainerBox::InstallPipe() { + if (!m_Content) + return; + Content *c = m_Content; - // CUBE - vtkSmartPointer cube = vtkSmartPointer::New(); - Vector3f p = c->GetPosition(); - cube->SetCenter(p(0),p(1),p(2)); - Vector4f p1 = c->GetWorldPoint(HPoint3f(0,0,0)); - Vector4f p2 = c->GetWorldPoint(HPoint3f(1,1,1)); - vtkSmartPointer line = vtkSmartPointer::New(); - line->SetPoint1(p1(0),p1(1),p1(2)); - line->SetPoint2(p2(0),p2(1),p2(2)); - line->Update(); - cube->SetBounds(line->GetOutput()->GetBounds()); - vtkSmartPointer mapper = - vtkSmartPointer::New(); - mapper->SetInputConnection(cube->GetOutputPort()); - mapper->Update(); - m_Cube->SetMapper(mapper); - m_Cube->GetProperty()->SetRepresentationToWireframe(); - m_Cube->GetProperty()->SetAmbient(0.7); + // CUBE + vtkSmartPointer cube = vtkSmartPointer::New(); + Vector3f p = c->GetPosition(); + cube->SetCenter(p(0), p(1), p(2)); + Vector4f p1 = c->GetWorldPoint(HPoint3f(0, 0, 0)); + Vector4f p2 = c->GetWorldPoint(HPoint3f(1, 1, 1)); + vtkSmartPointer line = vtkSmartPointer::New(); + line->SetPoint1(p1(0), p1(1), p1(2)); + line->SetPoint2(p2(0), p2(1), p2(2)); + line->Update(); + cube->SetBounds(line->GetOutput()->GetBounds()); + vtkSmartPointer mapper = + vtkSmartPointer::New(); + mapper->SetInputConnection(cube->GetOutputPort()); + mapper->Update(); + m_Cube->SetMapper(mapper); + m_Cube->GetProperty()->SetRepresentationToWireframe(); + m_Cube->GetProperty()->SetAmbient(0.7); - // AXES // - vtkSmartPointer axes = vtkSmartPointer::New(); - axes->SetOrigin(p1(0),p1(1),p1(2)); - mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(axes->GetOutputPort()); - mapper->Update(); - m_Axes->SetMapper(mapper); - Vector3f s = c->GetSize(); - // m_Axes->SetScale(s(0),s(1),s(2)); - m_Axes->GetProperty()->SetLineWidth(3); - m_Axes->GetProperty()->SetAmbient(0.4); - m_Axes->GetProperty()->SetSpecular(0); + // AXES // + vtkSmartPointer axes = vtkSmartPointer::New(); + axes->SetOrigin(p1(0), p1(1), p1(2)); + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(axes->GetOutputPort()); + mapper->Update(); + m_Axes->SetMapper(mapper); + Vector3f s = c->GetSize(); + // m_Axes->SetScale(s(0),s(1),s(2)); + m_Axes->GetProperty()->SetLineWidth(3); + m_Axes->GetProperty()->SetAmbient(0.4); + m_Axes->GetProperty()->SetSpecular(0); - // PIVOT // - axes = vtkSmartPointer::New(); - axes->SetOrigin(p(0),p(1),p(2)); - mapper = vtkSmartPointer::New(); - mapper->SetInputConnection(axes->GetOutputPort()); - mapper->Update(); - m_Pivot->SetMapper(mapper); - s = c->GetScale(); - // m_Pivot->SetScale(s(0),s(1),s(2)); - m_Pivot->GetProperty()->SetLineWidth(3); - m_Pivot->GetProperty()->SetAmbient(0.4); - m_Pivot->GetProperty()->SetSpecular(0); + // PIVOT // + axes = vtkSmartPointer::New(); + axes->SetOrigin(p(0), p(1), p(2)); + mapper = vtkSmartPointer::New(); + mapper->SetInputConnection(axes->GetOutputPort()); + mapper->Update(); + m_Pivot->SetMapper(mapper); + s = c->GetScale(); + // m_Pivot->SetScale(s(0),s(1),s(2)); + m_Pivot->GetProperty()->SetLineWidth(3); + m_Pivot->GetProperty()->SetAmbient(0.4); + m_Pivot->GetProperty()->SetSpecular(0); - this->SetProp(m_Cube); - this->SetProp(m_Axes); - this->SetProp(m_Pivot); + this->SetProp(m_Cube); + this->SetProp(m_Axes); + this->SetProp(m_Pivot); } - - -} // vtk -} // uLib +} // namespace Vtk +} // namespace uLib diff --git a/src/Vtk/vtkContainerBox.h b/src/Vtk/vtkContainerBox.h index 951f2be..92611bf 100644 --- a/src/Vtk/vtkContainerBox.h +++ b/src/Vtk/vtkContainerBox.h @@ -23,37 +23,34 @@ //////////////////////////////////////////////////////////////////////////////*/ - - #ifndef U_VTKCONTAINERBOX_H #define U_VTKCONTAINERBOX_H - -#include "uLibVtkInterface.h" #include "Math/ContainerBox.h" - +#include "uLibVtkInterface.h" namespace uLib { namespace Vtk { class vtkContainerBox : public Puppet, public Polydata { - typedef ContainerBox Content; + typedef ContainerBox Content; + public: - vtkContainerBox(Content &content); - ~vtkContainerBox(); + vtkContainerBox(Content *content); + ~vtkContainerBox(); - virtual class vtkPolyData *GetPolyData() const; + virtual class vtkPolyData *GetPolyData() const; -private: - void InstallPipe(); +protected: + void InstallPipe(); - vtkActor *m_Cube; - vtkActor *m_Axes; - vtkActor *m_Pivot; - vtkContainerBox::Content *m_Content; + vtkActor *m_Cube; + vtkActor *m_Axes; + vtkActor *m_Pivot; + vtkContainerBox::Content *m_Content; }; -} // vtk -} // uLib +} // namespace Vtk +} // namespace uLib #endif // VTKCONTAINERBOX_H