detector chamber in vtk

This commit is contained in:
AndreaRigoni
2026-03-08 08:46:21 +00:00
parent 3be7ec2274
commit 32a1104769
7 changed files with 258 additions and 95 deletions

View File

@@ -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)

View File

@@ -1,6 +1,7 @@
# TESTS
set(TESTS
vtkMuonScatterTest
vtkDetectorChamberTest
)
set(LIBRARIES

View File

@@ -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/test/unit_test.hpp>
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
}

View File

@@ -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<DetectorChamber *>(m_Content);
}
void vtkDetectorChamber::PrintSelf(std::ostream &o) const {
vtkContainerBox::PrintSelf(o);
}
void vtkDetectorChamber::InstallPipe() { vtkContainerBox::InstallPipe(); }
} // namespace Vtk
} // namespace uLib

View File

@@ -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 <vtkActor.h>
#include <vtkAppendPolyData.h>
#include <vtkLineSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtk3DWidget.h>
#include <vtkBoxWidget.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkCommand.h>
#include <vtkTransform.h>
#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

View File

@@ -23,65 +23,55 @@
//////////////////////////////////////////////////////////////////////////////*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <vtkSmartPointer.h>
#include <vtkCubeSource.h>
#include <vtkActor.h>
#include <vtkAxes.h>
#include <vtkAssembly.h>
#include <vtkAxes.h>
#include <vtkCubeSource.h>
#include <vtkLineSource.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
#include <vtkLineSource.h>
#include <vtkSmartPointer.h>
#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)
{
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::~vtkContainerBox() {
m_Cube->Delete();
m_Axes->Delete();
m_Pivot->Delete();
}
vtkPolyData *vtkContainerBox::GetPolyData() const
{
vtkPolyData *vtkContainerBox::GetPolyData() const {
// TODO
return NULL;
}
void vtkContainerBox::InstallPipe()
{
if(!m_Content) return;
void vtkContainerBox::InstallPipe() {
if (!m_Content)
return;
Content *c = m_Content;
// CUBE
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::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));
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<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
line->SetPoint1(p1(0),p1(1),p1(2));
line->SetPoint2(p2(0),p2(1),p2(2));
line->SetPoint1(p1(0), p1(1), p1(2));
line->SetPoint2(p2(0), p2(1), p2(2));
line->Update();
cube->SetBounds(line->GetOutput()->GetBounds());
vtkSmartPointer<vtkPolyDataMapper> mapper =
@@ -94,7 +84,7 @@ void vtkContainerBox::InstallPipe()
// AXES //
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
axes->SetOrigin(p1(0),p1(1),p1(2));
axes->SetOrigin(p1(0), p1(1), p1(2));
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(axes->GetOutputPort());
mapper->Update();
@@ -107,7 +97,7 @@ void vtkContainerBox::InstallPipe()
// PIVOT //
axes = vtkSmartPointer<vtkAxes>::New();
axes->SetOrigin(p(0),p(1),p(2));
axes->SetOrigin(p(0), p(1), p(2));
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputConnection(axes->GetOutputPort());
mapper->Update();
@@ -123,7 +113,5 @@ void vtkContainerBox::InstallPipe()
this->SetProp(m_Pivot);
}
} // vtk
} // uLib
} // namespace Vtk
} // namespace uLib

View File

@@ -23,28 +23,25 @@
//////////////////////////////////////////////////////////////////////////////*/
#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;
public:
vtkContainerBox(Content &content);
vtkContainerBox(Content *content);
~vtkContainerBox();
virtual class vtkPolyData *GetPolyData() const;
private:
protected:
void InstallPipe();
vtkActor *m_Cube;
@@ -53,7 +50,7 @@ private:
vtkContainerBox::Content *m_Content;
};
} // vtk
} // uLib
} // namespace Vtk
} // namespace uLib
#endif // VTKCONTAINERBOX_H