reorganization of sources, moving cmt pertaining structures into HEP folder
This commit is contained in:
22
src/Vtk/HEP/Detectors/CMakeLists.txt
Normal file
22
src/Vtk/HEP/Detectors/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
################################################################################
|
||||
##### Vtk/HEP/Detectors - VTK wrappers for HEP Detectors objects ##############
|
||||
################################################################################
|
||||
|
||||
## Sources and headers are exported to parent scope so they get compiled
|
||||
## into the single mutomVtk shared library.
|
||||
|
||||
set(HEP_DETECTORS_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.cxx
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.cxx
|
||||
PARENT_SCOPE)
|
||||
|
||||
set(HEP_DETECTORS_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonScatter.h
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkMuonEvent.h
|
||||
PARENT_SCOPE)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
include(uLibTargetMacros)
|
||||
add_subdirectory(testing)
|
||||
endif()
|
||||
14
src/Vtk/HEP/Detectors/testing/CMakeLists.txt
Normal file
14
src/Vtk/HEP/Detectors/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
||||
# TESTS
|
||||
set(TESTS
|
||||
vtkMuonScatterTest
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
${PACKAGE_LIBPREFIX}Core
|
||||
${PACKAGE_LIBPREFIX}Detectors
|
||||
${PACKAGE_LIBPREFIX}Vtk
|
||||
${VTK_LIBRARIES}
|
||||
Boost::unit_test_framework
|
||||
)
|
||||
|
||||
uLib_add_tests(VtkDetectors)
|
||||
62
src/Vtk/HEP/Detectors/testing/vtkMuonScatterTest.cpp
Normal file
62
src/Vtk/HEP/Detectors/testing/vtkMuonScatterTest.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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/vtkMuonScatter.h"
|
||||
#include "HEP/Detectors/MuonScatter.h"
|
||||
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
|
||||
#define BOOST_TEST_MODULE VtkMuonScatterTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vtkMuonScatterTest) {
|
||||
MuonScatter event;
|
||||
event.LineIn().direction << 0, -1, 1, 0;
|
||||
event.LineIn().origin << 0, 1, -1, 1;
|
||||
|
||||
event.LineOut().direction << 0, -1, 0, 0;
|
||||
event.LineOut().origin << 0, -1, 0, 1;
|
||||
|
||||
Vtk::vtkMuonScatter v_event(event);
|
||||
v_event.AddPocaPoint(HPoint3f(0, 0, 0));
|
||||
|
||||
v_event.SaveToXMLFile("vtk_testing_muonevent.vtp");
|
||||
|
||||
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||
Vtk::Viewer viewer;
|
||||
|
||||
// Vtk::Tie<Vtk::vtkMuonScatter> tms;
|
||||
// tms.DoAction();
|
||||
// Vtk::Tie<Vtk::Viewer> vms;
|
||||
// vms.DoAction();
|
||||
|
||||
viewer.AddPuppet(v_event);
|
||||
viewer.Start();
|
||||
}
|
||||
|
||||
BOOST_CHECK(true); // reached here without crash
|
||||
}
|
||||
145
src/Vtk/HEP/Detectors/vtkMuonEvent.cxx
Normal file
145
src/Vtk/HEP/Detectors/vtkMuonEvent.cxx
Normal file
@@ -0,0 +1,145 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "Math/Dense.h"
|
||||
#include "Vtk/HEP/Detectors/vtkMuonEvent.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
///// CALLBACK /////////////////////////////////////////////////////////////////
|
||||
|
||||
class vtkWidgetCallback : public vtkCommand {
|
||||
public:
|
||||
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
||||
void SetParent(uLib::Vtk::vtkMuonEvent *parent) { this->parent = parent; }
|
||||
virtual void Execute(vtkObject *caller, unsigned long, void *) {
|
||||
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
||||
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget *>(caller);
|
||||
widget->GetTransform(t);
|
||||
// parent->SetTransform(t);
|
||||
// std::cout << "event\n";
|
||||
}
|
||||
|
||||
private:
|
||||
uLib::Vtk::vtkMuonEvent *parent;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///// VTK MUON EVENT /////////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vtkMuonEvent::vtkMuonEvent(MuonEventData &content)
|
||||
: m_PolyData(NULL), m_Appender(vtkAppendPolyData::New()),
|
||||
content(&content) {
|
||||
InstallPipe();
|
||||
}
|
||||
|
||||
vtkMuonEvent::vtkMuonEvent(const MuonEventData &content)
|
||||
: m_PolyData(NULL), m_Appender(vtkAppendPolyData::New()),
|
||||
content(const_cast<MuonEventData *>(&content)) {
|
||||
InstallPipe();
|
||||
}
|
||||
|
||||
vtkMuonEvent::~vtkMuonEvent() {}
|
||||
|
||||
vtkMuonEvent::Content &vtkMuonEvent::GetContent() { return *content; }
|
||||
|
||||
void vtkMuonEvent::PrintSelf(std::ostream &o) const {
|
||||
o << "..:: MuonEvent ::..\n"
|
||||
"\t[in] Origin > "
|
||||
<< content->LineIn().origin.transpose() << "\n"
|
||||
<< "\t[in] Direction > " << content->LineIn().direction.transpose() << "\n"
|
||||
<< "\t[out] Origin > " << content->LineOut().origin.transpose() << "\n"
|
||||
<< "\t[out] Direction > " << content->LineOut().direction.transpose()
|
||||
<< "\n"
|
||||
<< "\tMomentum > " << content->GetMomentum() << "\n"
|
||||
<< "...................\n";
|
||||
}
|
||||
|
||||
void vtkMuonEvent::InstallPipe() {
|
||||
|
||||
vtkAppendPolyData *appender = m_Appender;
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
if (content) {
|
||||
vtkSmartPointer<vtkLineSource> line_in =
|
||||
vtkSmartPointer<vtkLineSource>::New();
|
||||
vtkSmartPointer<vtkLineSource> line_out =
|
||||
vtkSmartPointer<vtkLineSource>::New();
|
||||
|
||||
float distance =
|
||||
(content->LineIn().origin - content->LineOut().origin).norm() / 10;
|
||||
|
||||
HPoint3f pt;
|
||||
pt = content->LineIn().origin;
|
||||
line_in->SetPoint1(pt(0), pt(1), pt(2));
|
||||
pt = content->LineIn().origin + content->LineIn().direction * distance;
|
||||
line_in->SetPoint2(pt(0), pt(1), pt(2));
|
||||
pt = content->LineOut().origin;
|
||||
line_out->SetPoint1(pt(0), pt(1), pt(2));
|
||||
pt = content->LineOut().origin + content->LineOut().direction * distance;
|
||||
line_out->SetPoint2(pt(0), pt(1), pt(2));
|
||||
|
||||
appender->AddInputConnection(line_in->GetOutputPort());
|
||||
appender->AddInputConnection(line_out->GetOutputPort());
|
||||
}
|
||||
|
||||
appender->Update();
|
||||
mapper->SetInputConnection(appender->GetOutputPort());
|
||||
mapper->Update();
|
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||
actor->SetMapper(mapper);
|
||||
this->SetProp(actor);
|
||||
}
|
||||
|
||||
vtkPolyData *vtkMuonEvent::GetPolyData() const {
|
||||
return m_Appender->GetOutput();
|
||||
}
|
||||
|
||||
void vtkMuonEvent::AddPocaPoint(HPoint3f poca) {
|
||||
m_Poca = poca;
|
||||
vtkSmartPointer<vtkSphereSource> sphere =
|
||||
vtkSmartPointer<vtkSphereSource>::New();
|
||||
float size =
|
||||
(content->LineIn().origin - content->LineOut().origin).head(3).norm();
|
||||
size /= 100;
|
||||
sphere->SetRadius(size);
|
||||
sphere->SetCenter(poca(0), poca(1), poca(2));
|
||||
sphere->Update();
|
||||
m_Appender->AddInputConnection(sphere->GetOutputPort());
|
||||
m_Appender->Update();
|
||||
}
|
||||
|
||||
HPoint3f vtkMuonEvent::GetPocaPoint() { return m_Poca; }
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
87
src/Vtk/HEP/Detectors/vtkMuonEvent.h
Normal file
87
src/Vtk/HEP/Detectors/vtkMuonEvent.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 VTKMUONEVENT_H
|
||||
#define VTKMUONEVENT_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/MuonEvent.h"
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
class vtkMuonEvent : public Puppet, public Polydata {
|
||||
typedef MuonEventData Content;
|
||||
|
||||
public:
|
||||
vtkMuonEvent(const MuonEventData &content);
|
||||
vtkMuonEvent(MuonEventData &content);
|
||||
~vtkMuonEvent();
|
||||
|
||||
Content &GetContent();
|
||||
|
||||
void PrintSelf(std::ostream &o) const;
|
||||
|
||||
virtual vtkPolyData *GetPolyData() const;
|
||||
|
||||
void AddPocaPoint(HPoint3f poca);
|
||||
|
||||
HPoint3f GetPocaPoint();
|
||||
|
||||
void vtkStartInteractive();
|
||||
|
||||
private:
|
||||
void InstallPipe();
|
||||
|
||||
vtkMuonEvent::Content *content;
|
||||
vtkPolyData *m_PolyData;
|
||||
|
||||
vtkAppendPolyData *m_Appender;
|
||||
vtkBoxWidget *m_WidgetIN;
|
||||
vtkBoxWidget *m_WidgetOUT;
|
||||
HPoint3f m_Poca;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
#endif // VTKMUONEVENT_H
|
||||
144
src/Vtk/HEP/Detectors/vtkMuonScatter.cxx
Normal file
144
src/Vtk/HEP/Detectors/vtkMuonScatter.cxx
Normal file
@@ -0,0 +1,144 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "Math/Dense.h"
|
||||
#include "Vtk/HEP/Detectors/vtkMuonScatter.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
///// VTK MUON Scatter ///////////////////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vtkMuonScatter::vtkMuonScatter(MuonScatter &content)
|
||||
: m_Content(&content), m_LineIn(vtkLineSource::New()),
|
||||
m_LineOut(vtkLineSource::New()), m_PolyData(vtkPolyData::New()),
|
||||
m_SpherePoca(NULL) {
|
||||
InstallPipe();
|
||||
}
|
||||
|
||||
vtkMuonScatter::vtkMuonScatter(const MuonScatter &content)
|
||||
: m_Content(const_cast<MuonScatter *>(&content)),
|
||||
m_LineIn(vtkLineSource::New()), m_LineOut(vtkLineSource::New()),
|
||||
m_PolyData(vtkPolyData::New()), m_SpherePoca(NULL) {
|
||||
InstallPipe();
|
||||
}
|
||||
|
||||
vtkMuonScatter::~vtkMuonScatter() {
|
||||
m_LineIn->Delete();
|
||||
m_LineOut->Delete();
|
||||
if (m_SpherePoca)
|
||||
m_SpherePoca->Delete();
|
||||
}
|
||||
|
||||
vtkMuonScatter::Content &vtkMuonScatter::GetContent() { return *m_Content; }
|
||||
|
||||
void vtkMuonScatter::PrintSelf(std::ostream &o) const {}
|
||||
|
||||
void vtkMuonScatter::InstallPipe() {
|
||||
if (m_Content) {
|
||||
vtkLineSource *line_in = m_LineIn;
|
||||
vtkLineSource *line_out = m_LineOut;
|
||||
|
||||
float distance =
|
||||
(m_Content->LineIn().origin - m_Content->LineOut().origin).norm() / 10;
|
||||
|
||||
HPoint3f pt;
|
||||
pt = m_Content->LineIn().origin;
|
||||
line_in->SetPoint1(pt(0), pt(1), pt(2));
|
||||
pt = m_Content->LineIn().origin + m_Content->LineIn().direction * distance;
|
||||
line_in->SetPoint2(pt(0), pt(1), pt(2));
|
||||
pt = m_Content->LineOut().origin;
|
||||
line_out->SetPoint1(pt(0), pt(1), pt(2));
|
||||
pt =
|
||||
m_Content->LineOut().origin + m_Content->LineOut().direction * distance;
|
||||
line_out->SetPoint2(pt(0), pt(1), pt(2));
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(m_LineIn->GetOutputPort());
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||
actor->SetMapper(mapper);
|
||||
this->SetProp(actor);
|
||||
|
||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(m_LineOut->GetOutputPort());
|
||||
actor = vtkSmartPointer<vtkActor>::New();
|
||||
actor->SetMapper(mapper);
|
||||
this->SetProp(actor);
|
||||
}
|
||||
|
||||
vtkPolyData *vtkMuonScatter::GetPolyData() const {
|
||||
vtkSmartPointer<vtkAppendPolyData> append =
|
||||
vtkSmartPointer<vtkAppendPolyData>::New();
|
||||
append->AddInputConnection(m_LineIn->GetOutputPort());
|
||||
append->AddInputConnection(m_LineOut->GetOutputPort());
|
||||
if (m_SpherePoca)
|
||||
append->AddInputConnection(m_SpherePoca->GetOutputPort());
|
||||
append->Update();
|
||||
m_PolyData->DeepCopy(append->GetOutput());
|
||||
return m_PolyData;
|
||||
}
|
||||
|
||||
void vtkMuonScatter::AddPocaPoint(HPoint3f poca) {
|
||||
vtkSphereSource *sphere = vtkSphereSource::New();
|
||||
float size =
|
||||
(m_Content->LineIn().origin - m_Content->LineOut().origin).head(3).norm();
|
||||
size /= 100;
|
||||
sphere->SetRadius(size);
|
||||
sphere->SetCenter(poca(0), poca(1), poca(2));
|
||||
sphere->Update();
|
||||
m_SpherePoca = sphere;
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(m_SpherePoca->GetOutputPort());
|
||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||
actor->SetMapper(mapper);
|
||||
this->SetProp(actor);
|
||||
}
|
||||
|
||||
HPoint3f vtkMuonScatter::GetPocaPoint() {
|
||||
double center[3];
|
||||
if (m_SpherePoca) {
|
||||
m_SpherePoca->GetCenter(center);
|
||||
return HPoint3f(center[0], center[1], center[2]);
|
||||
} else {
|
||||
return HPoint3f(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void vtkMuonScatter::ConnectInteractor(vtkRenderWindowInteractor *interactor) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
92
src/Vtk/HEP/Detectors/vtkMuonScatter.h
Normal file
92
src/Vtk/HEP/Detectors/vtkMuonScatter.h
Normal file
@@ -0,0 +1,92 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 VTKMUONSCATTER_H
|
||||
#define VTKMUONSCATTER_H
|
||||
|
||||
#include <vtkActor.h>
|
||||
#include <vtkAppendPolyData.h>
|
||||
#include <vtkLineSource.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkSphereSource.h>
|
||||
#include <vtkVersion.h>
|
||||
|
||||
#include <vtk3DWidget.h>
|
||||
#include <vtkBoxWidget.h>
|
||||
|
||||
#include <vtkRenderWindowInteractor.h>
|
||||
|
||||
#include <vtkCommand.h>
|
||||
#include <vtkTransform.h>
|
||||
|
||||
#include "Math/Dense.h"
|
||||
|
||||
#include "HEP/Detectors/MuonScatter.h"
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
|
||||
class vtkRenderWindowInteractor;
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
class vtkMuonScatter : public Puppet, public Polydata {
|
||||
typedef MuonScatter Content;
|
||||
|
||||
public:
|
||||
vtkMuonScatter(const MuonScatter &content);
|
||||
vtkMuonScatter(MuonScatter &content);
|
||||
|
||||
~vtkMuonScatter();
|
||||
|
||||
Content &GetContent();
|
||||
|
||||
void PrintSelf(std::ostream &o) const;
|
||||
|
||||
virtual vtkPolyData *GetPolyData() const;
|
||||
|
||||
void AddPocaPoint(HPoint3f poca);
|
||||
|
||||
HPoint3f GetPocaPoint();
|
||||
|
||||
void vtkStartInteractive();
|
||||
|
||||
protected:
|
||||
void ConnectInteractor(vtkRenderWindowInteractor *interactor);
|
||||
|
||||
private:
|
||||
void InstallPipe();
|
||||
|
||||
vtkMuonScatter::Content *m_Content;
|
||||
vtkLineSource *m_LineIn;
|
||||
vtkLineSource *m_LineOut;
|
||||
vtkSphereSource *m_SpherePoca;
|
||||
vtkPolyData *m_PolyData;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
#endif // VTKMUONSCATTER_H
|
||||
17
src/Vtk/HEP/MuonTomography/CMakeLists.txt
Normal file
17
src/Vtk/HEP/MuonTomography/CMakeLists.txt
Normal file
@@ -0,0 +1,17 @@
|
||||
|
||||
################################################################################
|
||||
##### Vtk/HEP/MuonTomography - VTK wrappers for MuonTomography objects ########
|
||||
################################################################################
|
||||
|
||||
set(HEP_MUONTOMOGRAPHY_SOURCES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkVoxRaytracerRepresentation.cpp
|
||||
PARENT_SCOPE)
|
||||
|
||||
set(HEP_MUONTOMOGRAPHY_HEADERS
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/vtkVoxRaytracerRepresentation.h
|
||||
PARENT_SCOPE)
|
||||
|
||||
if(BUILD_TESTING)
|
||||
include(uLibTargetMacros)
|
||||
add_subdirectory(testing)
|
||||
endif()
|
||||
15
src/Vtk/HEP/MuonTomography/testing/CMakeLists.txt
Normal file
15
src/Vtk/HEP/MuonTomography/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
# TESTS
|
||||
set(TESTS
|
||||
vtkVoxRaytracerTest
|
||||
)
|
||||
|
||||
set(LIBRARIES
|
||||
${PACKAGE_LIBPREFIX}Core
|
||||
${PACKAGE_LIBPREFIX}Math
|
||||
${PACKAGE_LIBPREFIX}Detectors
|
||||
${PACKAGE_LIBPREFIX}Vtk
|
||||
${VTK_LIBRARIES}
|
||||
Boost::unit_test_framework
|
||||
)
|
||||
|
||||
uLib_add_tests(VtkMuonTomography)
|
||||
132
src/Vtk/HEP/MuonTomography/testing/vtkVoxRaytracerTest.cpp
Normal file
132
src/Vtk/HEP/MuonTomography/testing/vtkVoxRaytracerTest.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 <vtkBoxWidget.h>
|
||||
#include <vtkCommand.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
|
||||
#include <vtkCornerAnnotation.h>
|
||||
|
||||
#include <HEP/Detectors/MuonScatter.h>
|
||||
#include <Math/VoxRaytracer.h>
|
||||
|
||||
#include "Vtk/HEP/Detectors/vtkMuonScatter.h"
|
||||
#include "Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.h"
|
||||
#include "Vtk/Math/vtkStructuredGrid.h"
|
||||
#include "Vtk/uLibVtkViewer.h"
|
||||
|
||||
#define BOOST_TEST_MODULE VtkVoxRaytracerTest
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
using namespace uLib;
|
||||
|
||||
class vtkWidgetCallback : public vtkCommand {
|
||||
public:
|
||||
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
||||
|
||||
void SetTracer(Vtk::vtkVoxRaytracerRepresentation *parent) {
|
||||
this->vtk_raytr = parent;
|
||||
}
|
||||
|
||||
void SetMuon(uLib::MuonScatter *muon) { this->muon = muon; }
|
||||
|
||||
void SetAnnotation(vtkCornerAnnotation *annotation) {
|
||||
this->annotation = annotation;
|
||||
}
|
||||
|
||||
virtual void Execute(vtkObject *caller, unsigned long, void *) {
|
||||
char str[40];
|
||||
vtk_raytr->SetMuon(*muon);
|
||||
if (annotation) {
|
||||
sprintf(str, "total length = %f", vtk_raytr->GetRay().TotalLength());
|
||||
annotation->SetText(1, str);
|
||||
for (int i = 0; i < vtk_raytr->GetRay().Data().size(); ++i) {
|
||||
std::cout << "L[" << i << "] = " << vtk_raytr->GetRay().Data().at(i).L
|
||||
<< "\n";
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
vtkWidgetCallback() : vtk_raytr(NULL), muon(NULL), annotation(NULL) {}
|
||||
|
||||
uLib::VoxRaytracer *raytracer;
|
||||
Vtk::vtkVoxRaytracerRepresentation *vtk_raytr;
|
||||
uLib::MuonScatter *muon;
|
||||
vtkCornerAnnotation *annotation;
|
||||
};
|
||||
|
||||
BOOST_AUTO_TEST_CASE(vtkVoxRaytracerRepresentationTest) {
|
||||
// muon scatter //
|
||||
MuonScatter muon;
|
||||
muon.LineIn().origin << -6, 12, -6, 1;
|
||||
muon.LineIn().direction << 1, -1, 1, 0;
|
||||
muon.LineOut().origin << 6, -4, 6, 1;
|
||||
muon.LineOut().direction << 1, -1, 1, 0;
|
||||
|
||||
Vtk::vtkMuonScatter v_muon(muon);
|
||||
|
||||
// structured grid //
|
||||
StructuredGrid grid(Vector3i(12, 10, 12));
|
||||
grid.SetSpacing(Vector3f(1, 1, 1));
|
||||
grid.SetPosition(Vector3f(0, 0, 0));
|
||||
|
||||
Vtk::vtkStructuredGrid v_grid(grid);
|
||||
|
||||
// voxraytracer //
|
||||
VoxRaytracer rt(grid);
|
||||
HPoint3f pt;
|
||||
rt.GetEntryPoint(muon.LineIn(), pt);
|
||||
std::cout << pt.transpose() << "\n";
|
||||
|
||||
Vtk::vtkVoxRaytracerRepresentation v_rt(rt);
|
||||
v_rt.SetMuon(muon);
|
||||
v_rt.SetRayColor(Vector4f(1, 0, 0, 1));
|
||||
|
||||
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||
// renderer //
|
||||
Vtk::Viewer viewer;
|
||||
|
||||
// widget //
|
||||
vtkBoxWidget *widget = v_grid.GetWidget();
|
||||
|
||||
vtkWidgetCallback *cbk = vtkWidgetCallback::New();
|
||||
cbk->SetTracer(&v_rt);
|
||||
cbk->SetMuon(&muon);
|
||||
cbk->SetAnnotation(viewer.GetAnnotation());
|
||||
widget->AddObserver(vtkCommand::InteractionEvent, cbk);
|
||||
widget->SetInteractor(viewer.GetInteractor());
|
||||
widget->PlaceWidget();
|
||||
widget->On();
|
||||
|
||||
viewer.AddPuppet(v_grid);
|
||||
viewer.AddPuppet(v_rt);
|
||||
viewer.AddPuppet(v_muon);
|
||||
viewer.Start();
|
||||
}
|
||||
|
||||
BOOST_CHECK(v_rt.GetRay().Count() > 0);
|
||||
}
|
||||
323
src/Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.cpp
Normal file
323
src/Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.cpp
Normal file
@@ -0,0 +1,323 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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.
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#include "Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.h"
|
||||
|
||||
#include "Math/VoxRaytracer.h"
|
||||
|
||||
// #include "Vtk/HEP/Detectors/vtkMuonEvent.h"
|
||||
#include "Vtk/HEP/Detectors/vtkMuonScatter.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
////// VOX RAYTRACER REPRESENTATION ///////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
vtkVoxRaytracerRepresentation::vtkVoxRaytracerRepresentation(Content &content)
|
||||
: m_Content(&content), m_Assembly(vtkAssembly::New()),
|
||||
m_Sphere1(vtkSphereSource::New()), m_Sphere2(vtkSphereSource::New()),
|
||||
m_Line1(vtkLineSource::New()), m_Line2(vtkLineSource::New()),
|
||||
m_Line3(vtkLineSource::New()), m_RayLine(vtkAppendPolyData::New()),
|
||||
m_RayLineActor(vtkActor::New()),
|
||||
m_RayRepresentation(vtkAppendPolyData::New()),
|
||||
m_RayRepresentationActor(vtkActor::New()),
|
||||
m_Transform(vtkTransform::New()) {
|
||||
default_radius = content.GetImage()->GetSpacing()(0) / 4;
|
||||
m_Sphere1->SetRadius(default_radius);
|
||||
m_Sphere2->SetRadius(default_radius);
|
||||
m_SelectedElement = m_RayLine;
|
||||
|
||||
InstallPipe();
|
||||
}
|
||||
|
||||
vtkVoxRaytracerRepresentation::~vtkVoxRaytracerRepresentation() {
|
||||
m_Assembly->Delete();
|
||||
m_RayLine->Delete();
|
||||
m_RayLineActor->Delete();
|
||||
m_RayRepresentationActor->Delete();
|
||||
m_Transform->Delete();
|
||||
}
|
||||
|
||||
VoxRaytracer *vtkVoxRaytracerRepresentation::GetRaytracerAlgorithm() {
|
||||
return m_Content;
|
||||
}
|
||||
|
||||
vtkProp *vtkVoxRaytracerRepresentation::GetProp() { return m_Assembly; }
|
||||
|
||||
vtkPolyData *vtkVoxRaytracerRepresentation::GetPolyData() const {
|
||||
std::cout << "get Raytracer polydata\n";
|
||||
m_SelectedElement->Update();
|
||||
return m_SelectedElement->GetOutput();
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetRepresentationElements(
|
||||
vtkVoxRaytracerRepresentation::RepresentationElements el) {
|
||||
switch (el) {
|
||||
case Vtk::vtkVoxRaytracerRepresentation::RayElements:
|
||||
m_SelectedElement = m_RayLine;
|
||||
break;
|
||||
case Vtk::vtkVoxRaytracerRepresentation::VoxelsElements:
|
||||
m_SelectedElement = m_RayRepresentation;
|
||||
break;
|
||||
default:
|
||||
m_SelectedElement = m_RayLine;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon) {
|
||||
HPoint3f pt1, pt2, src;
|
||||
src = muon.LineIn().origin;
|
||||
m_Content->GetEntryPoint(muon.LineIn(), pt1);
|
||||
m_Sphere1->SetCenter(pt1(0), pt1(1), pt1(2));
|
||||
m_Line1->SetPoint1(src(0), src(1), src(2));
|
||||
m_Line1->SetPoint2(pt1(0), pt1(1), pt1(2));
|
||||
|
||||
HLine3f line_out = muon.LineOut();
|
||||
src = line_out.origin;
|
||||
float *direction = line_out.direction.data();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
direction[i] *= -1;
|
||||
m_Content->GetEntryPoint(line_out, pt2);
|
||||
m_Sphere2->SetCenter(pt2(0), pt2(1), pt2(2));
|
||||
m_Line2->SetPoint1(src(0), src(1), src(2));
|
||||
m_Line2->SetPoint2(pt2(0), pt2(1), pt2(2));
|
||||
|
||||
m_Line3->SetPoint1(pt1(0), pt1(1), pt1(2));
|
||||
m_Line3->SetPoint2(pt2(0), pt2(1), pt2(2));
|
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
points->InsertNextPoint(pt1(0), pt1(1), pt1(2));
|
||||
points->InsertNextPoint(pt2(0), pt2(1), pt2(2));
|
||||
|
||||
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
||||
|
||||
vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
|
||||
line->GetPointIds()->SetId(0, 0);
|
||||
line->GetPointIds()->SetId(1, 1);
|
||||
lines->InsertNextCell(line);
|
||||
|
||||
vtkSmartPointer<vtkPolyData> linesPolyData =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
linesPolyData->SetPoints(points);
|
||||
linesPolyData->SetLines(lines);
|
||||
|
||||
m_RayLine->RemoveAllInputs();
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
|
||||
#else
|
||||
m_RayLine->AddInputData(linesPolyData);
|
||||
#endif
|
||||
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
|
||||
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
|
||||
m_RayLine->AddInputConnection(m_Line2->GetOutputPort());
|
||||
m_RayLine->AddInputConnection(m_Sphere2->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||
Matrix4f mat = m_Content->GetImage()->GetWorldMatrix();
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j)
|
||||
vmat->SetElement(i, j, mat(i, j));
|
||||
m_Transform->SetMatrix(vmat);
|
||||
|
||||
this->SetRay(pt1, pt2);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca) {
|
||||
HPoint3f pt1, pt2, src;
|
||||
src = muon.LineIn().origin;
|
||||
m_Content->GetEntryPoint(muon.LineIn(), pt1);
|
||||
m_Sphere1->SetCenter(pt1(0), pt1(1), pt1(2));
|
||||
m_Line1->SetPoint1(src(0), src(1), src(2));
|
||||
m_Line1->SetPoint2(pt1(0), pt1(1), pt1(2));
|
||||
|
||||
HLine3f line_out = muon.LineOut();
|
||||
src = line_out.origin;
|
||||
float *direction = line_out.direction.data();
|
||||
for (int i = 0; i < 3; ++i)
|
||||
direction[i] *= -1;
|
||||
m_Content->GetEntryPoint(line_out, pt2);
|
||||
m_Sphere2->SetCenter(pt2(0), pt2(1), pt2(2));
|
||||
m_Line2->SetPoint1(src(0), src(1), src(2));
|
||||
m_Line2->SetPoint2(pt2(0), pt2(1), pt2(2));
|
||||
|
||||
m_Line3->SetPoint1(pt1(0), pt1(1), pt1(2));
|
||||
m_Line3->SetPoint2(pt2(0), pt2(1), pt2(2));
|
||||
|
||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||
points->InsertNextPoint(pt1(0), pt1(1), pt1(2));
|
||||
points->InsertNextPoint(poca(0), poca(1), poca(2));
|
||||
points->InsertNextPoint(pt2(0), pt2(1), pt2(2));
|
||||
|
||||
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
||||
for (unsigned int i = 0; i < 2; i++) {
|
||||
vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
|
||||
line->GetPointIds()->SetId(0, i);
|
||||
line->GetPointIds()->SetId(1, i + 1);
|
||||
lines->InsertNextCell(line);
|
||||
}
|
||||
|
||||
vtkSmartPointer<vtkPolyData> linesPolyData =
|
||||
vtkSmartPointer<vtkPolyData>::New();
|
||||
linesPolyData->SetPoints(points);
|
||||
linesPolyData->SetLines(lines);
|
||||
|
||||
m_RayLine->RemoveAllInputs();
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
|
||||
#else
|
||||
m_RayLine->AddInputData(linesPolyData);
|
||||
#endif
|
||||
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
|
||||
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
|
||||
m_RayLine->AddInputConnection(m_Line2->GetOutputPort());
|
||||
m_RayLine->AddInputConnection(m_Sphere2->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkSphereSource> poca_sphere =
|
||||
vtkSmartPointer<vtkSphereSource>::New();
|
||||
poca_sphere->SetRadius(default_radius);
|
||||
poca_sphere->SetCenter(poca(0), poca(1), poca(2));
|
||||
m_RayLine->AddInputConnection(poca_sphere->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||
Matrix4f mat = m_Content->GetImage()->GetWorldMatrix();
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j)
|
||||
vmat->SetElement(i, j, mat(i, j));
|
||||
m_Transform->SetMatrix(vmat);
|
||||
|
||||
if (m_Content->GetImage()->IsInsideBounds(poca))
|
||||
this->SetRay(pt1, poca, pt2);
|
||||
else
|
||||
this->SetRay(pt1, pt2);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetMuon(vtkMuonScatter &muon) {
|
||||
HPoint3f poca = muon.GetPocaPoint();
|
||||
MuonScatter &mu = muon.GetContent();
|
||||
this->SetMuon(mu, poca);
|
||||
}
|
||||
|
||||
VoxRaytracer::RayData vtkVoxRaytracerRepresentation::GetRay() { return m_Ray; }
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetRay(HPoint3f in, HPoint3f out) {
|
||||
m_Ray = m_Content->TraceBetweenPoints(in, out);
|
||||
this->SetRay(&m_Ray);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetRay(HPoint3f in, HPoint3f mid,
|
||||
HPoint3f out) {
|
||||
m_Ray = m_Content->TraceBetweenPoints(in, mid);
|
||||
m_Ray.AppendRay(m_Content->TraceBetweenPoints(mid, out));
|
||||
this->SetRay(&m_Ray);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetRay(VoxRaytracer::RayData *ray) {
|
||||
vtkAppendPolyData *appender = m_RayRepresentation;
|
||||
appender->RemoveAllInputs();
|
||||
|
||||
for (size_t i = 0; i < ray->Count(); ++i) {
|
||||
int id = ray->Data().at(i).vox_id;
|
||||
Vector3i idv = m_Content->GetImage()->UnMap(id);
|
||||
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||
cube->SetBounds(idv(0), idv(0) + 1, idv(1), idv(1) + 1, idv(2), idv(2) + 1);
|
||||
#if VTK_MAJOR_VERSION <= 5
|
||||
cube->Update();
|
||||
appender->AddInput(cube->GetOutput());
|
||||
#else
|
||||
appender->AddInputData(cube->GetOutput());
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetVoxelsColor(Vector4f rgba) {
|
||||
this->SetColor(m_RayRepresentationActor, rgba);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetRayColor(Vector4f rgba) {
|
||||
this->SetColor(m_RayLineActor, rgba);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::SetColor(vtkActor *actor, Vector4f rgba) {
|
||||
if (!actor)
|
||||
return;
|
||||
vtkProperty *pr = actor->GetProperty();
|
||||
pr->SetDiffuseColor(rgba(0), rgba(1), rgba(2));
|
||||
pr->SetOpacity(rgba(3));
|
||||
pr->SetDiffuse(1);
|
||||
}
|
||||
|
||||
void vtkVoxRaytracerRepresentation::InstallPipe() {
|
||||
|
||||
vtkSmartPointer<vtkAppendPolyData> append =
|
||||
vtkSmartPointer<vtkAppendPolyData>::New();
|
||||
append->AddInputConnection(m_Sphere1->GetOutputPort());
|
||||
append->AddInputConnection(m_Sphere2->GetOutputPort());
|
||||
append->AddInputConnection(m_Line1->GetOutputPort());
|
||||
append->AddInputConnection(m_Line2->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
|
||||
mapper->SetInputConnection(append->GetOutputPort());
|
||||
|
||||
vtkSmartPointer<vtkActor> actor = vtkActor::New();
|
||||
actor->SetMapper(mapper);
|
||||
actor->GetProperty()->SetColor(0.6, 0.6, 1);
|
||||
this->SetProp(actor);
|
||||
|
||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(m_RayLine->GetOutputPort());
|
||||
|
||||
m_RayLineActor->SetMapper(mapper);
|
||||
m_RayLineActor->GetProperty()->SetColor(1, 0, 0);
|
||||
this->SetProp(m_RayLineActor);
|
||||
|
||||
vtkSmartPointer<vtkTransformPolyDataFilter> polyfilter =
|
||||
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
|
||||
|
||||
polyfilter->SetInputConnection(m_RayRepresentation->GetOutputPort());
|
||||
polyfilter->SetTransform(m_Transform);
|
||||
|
||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||
mapper->SetInputConnection(polyfilter->GetOutputPort());
|
||||
|
||||
vtkActor *vra = m_RayRepresentationActor;
|
||||
vra->SetMapper(mapper);
|
||||
vra->GetProperty()->SetOpacity(0.2);
|
||||
vra->GetProperty()->SetEdgeVisibility(true);
|
||||
vra->GetProperty()->SetColor(0.5, 0.5, 0.5);
|
||||
|
||||
this->SetProp(vra);
|
||||
}
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
123
src/Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.h
Normal file
123
src/Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 U_VTKVOXRAYTRACERREPRESENTATION_H
|
||||
#define U_VTKVOXRAYTRACERREPRESENTATION_H
|
||||
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkLine.h>
|
||||
|
||||
#include <vtkActor.h>
|
||||
#include <vtkAppendPolyData.h>
|
||||
#include <vtkAssembly.h>
|
||||
#include <vtkBoundingBox.h>
|
||||
#include <vtkCubeSource.h>
|
||||
#include <vtkLineSource.h>
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkPolyDataMapper.h>
|
||||
#include <vtkProp3DCollection.h>
|
||||
#include <vtkProperty.h>
|
||||
#include <vtkSmartPointer.h>
|
||||
#include <vtkSphereSource.h>
|
||||
#include <vtkTransform.h>
|
||||
#include <vtkTransformPolyDataFilter.h>
|
||||
|
||||
#include "Math/Dense.h"
|
||||
|
||||
#include "Vtk/uLibVtkInterface.h"
|
||||
|
||||
#include "HEP/Detectors/MuonScatter.h"
|
||||
|
||||
#include "Math/StructuredGrid.h"
|
||||
#include "Math/VoxRaytracer.h"
|
||||
|
||||
class vtkActor;
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
class vtkVoxRaytracerRepresentation : public Puppet {
|
||||
typedef VoxRaytracer Content;
|
||||
|
||||
public:
|
||||
vtkVoxRaytracerRepresentation(Content &content);
|
||||
~vtkVoxRaytracerRepresentation();
|
||||
|
||||
uLib::VoxRaytracer *GetRaytracerAlgorithm();
|
||||
|
||||
vtkProp *GetProp();
|
||||
|
||||
vtkPolyData *GetPolyData() const;
|
||||
|
||||
enum RepresentationElements { RayElements, VoxelsElements };
|
||||
void SetRepresentationElements(enum RepresentationElements el);
|
||||
|
||||
void SetMuon(MuonScatter &muon);
|
||||
|
||||
void SetMuon(MuonScatter &muon, HPoint3f poca);
|
||||
|
||||
void SetMuon(class vtkMuonEvent &muon);
|
||||
|
||||
void SetMuon(class vtkMuonScatter &muon);
|
||||
|
||||
VoxRaytracer::RayData GetRay();
|
||||
|
||||
void SetRay(HPoint3f in, HPoint3f out);
|
||||
|
||||
void SetRay(HPoint3f in, HPoint3f mid, HPoint3f out);
|
||||
|
||||
void SetRay(VoxRaytracer::RayData *ray);
|
||||
|
||||
void SetVoxelsColor(Vector4f rgba);
|
||||
void SetRayColor(Vector4f rgba);
|
||||
|
||||
private:
|
||||
void InstallPipe();
|
||||
|
||||
void SetColor(vtkActor *actor, Vector4f rgba);
|
||||
|
||||
VoxRaytracer *m_Content;
|
||||
|
||||
Scalarf default_radius;
|
||||
vtkAssembly *m_Assembly;
|
||||
vtkAppendPolyData *m_RayLine;
|
||||
vtkActor *m_RayLineActor;
|
||||
vtkActor *m_RayRepresentationActor;
|
||||
vtkSmartPointer<vtkTransform> m_Transform;
|
||||
VoxRaytracer::RayData m_Ray;
|
||||
vtkSmartPointer<vtkSphereSource> m_Sphere1;
|
||||
vtkSmartPointer<vtkSphereSource> m_Sphere2;
|
||||
vtkSmartPointer<vtkLineSource> m_Line1;
|
||||
vtkSmartPointer<vtkLineSource> m_Line2;
|
||||
vtkSmartPointer<vtkLineSource> m_Line3;
|
||||
vtkSmartPointer<vtkAppendPolyData> m_RayRepresentation;
|
||||
|
||||
vtkAppendPolyData *m_SelectedElement;
|
||||
};
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
|
||||
#endif // VTKVOXRAYTRACERREPRESENTATION_H
|
||||
Reference in New Issue
Block a user