Compare commits
10 Commits
main
...
61052f80bc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
61052f80bc | ||
|
|
f2133c31d5 | ||
|
|
00275ac56d | ||
|
|
1374821344 | ||
|
|
2548582036 | ||
|
|
32a1104769 | ||
|
|
3be7ec2274 | ||
|
|
38dd416ced | ||
|
|
e8f8e96521 | ||
|
|
49cf0aeedd |
@@ -3,7 +3,12 @@
|
|||||||
##### CMAKE LISTS ##############################################################
|
##### CMAKE LISTS ##############################################################
|
||||||
################################################################################
|
################################################################################
|
||||||
|
|
||||||
|
if(EXISTS "${CMAKE_BINARY_DIR}/conan_toolchain.cmake")
|
||||||
|
include("${CMAKE_BINARY_DIR}/conan_toolchain.cmake")
|
||||||
|
endif()
|
||||||
|
|
||||||
cmake_minimum_required (VERSION 3.26)
|
cmake_minimum_required (VERSION 3.26)
|
||||||
|
|
||||||
if(POLICY CMP0167)
|
if(POLICY CMP0167)
|
||||||
cmake_policy(SET CMP0167 NEW)
|
cmake_policy(SET CMP0167 NEW)
|
||||||
endif()
|
endif()
|
||||||
@@ -107,6 +112,8 @@ set(Boost_USE_MULTITHREADED ON)
|
|||||||
set(Boost_USE_STATIC_RUNTIME OFF)
|
set(Boost_USE_STATIC_RUNTIME OFF)
|
||||||
message(STATUS "CMAKE_PREFIX_PATH is ${CMAKE_PREFIX_PATH}")
|
message(STATUS "CMAKE_PREFIX_PATH is ${CMAKE_PREFIX_PATH}")
|
||||||
|
|
||||||
|
find_package(HDF5 REQUIRED CONFIG)
|
||||||
|
|
||||||
find_package(Boost 1.45.0 COMPONENTS program_options serialization unit_test_framework REQUIRED)
|
find_package(Boost 1.45.0 COMPONENTS program_options serialization unit_test_framework REQUIRED)
|
||||||
include_directories(${Boost_INCLUDE_DIRS})
|
include_directories(${Boost_INCLUDE_DIRS})
|
||||||
|
|
||||||
@@ -120,6 +127,9 @@ include(${ROOT_USE_FILE})
|
|||||||
find_package(VTK REQUIRED)
|
find_package(VTK REQUIRED)
|
||||||
# include(${VTK_USE_FILE})
|
# include(${VTK_USE_FILE})
|
||||||
|
|
||||||
|
set(GEANT4_USE_HDF5 OFF CACHE BOOL "Use HDF5" FORCE)
|
||||||
|
find_package(Geant4 REQUIRED)
|
||||||
|
|
||||||
find_package(pybind11 REQUIRED)
|
find_package(pybind11 REQUIRED)
|
||||||
|
|
||||||
|
|
||||||
@@ -146,7 +156,8 @@ else()
|
|||||||
RenderingFreeType
|
RenderingFreeType
|
||||||
RenderingGL2PSOpenGL2
|
RenderingGL2PSOpenGL2
|
||||||
RenderingOpenGL2
|
RenderingOpenGL2
|
||||||
RenderingVolumeOpenGL2)
|
RenderingVolumeOpenGL2
|
||||||
|
IOGeometry)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h)
|
set(CMAKE_REQUIRED_INCLUDES CMAKE_REQUIRED_INCLUDES math.h)
|
||||||
@@ -204,8 +215,8 @@ add_subdirectory(${SRC_DIR}/Core)
|
|||||||
include_directories(${SRC_DIR}/Math)
|
include_directories(${SRC_DIR}/Math)
|
||||||
add_subdirectory(${SRC_DIR}/Math)
|
add_subdirectory(${SRC_DIR}/Math)
|
||||||
|
|
||||||
include_directories(${SRC_DIR}/Detectors)
|
include_directories(${SRC_DIR}/HEP)
|
||||||
add_subdirectory(${SRC_DIR}/Detectors)
|
add_subdirectory(${SRC_DIR}/HEP)
|
||||||
|
|
||||||
include_directories(${SRC_DIR}/Root)
|
include_directories(${SRC_DIR}/Root)
|
||||||
add_subdirectory(${SRC_DIR}/Root)
|
add_subdirectory(${SRC_DIR}/Root)
|
||||||
@@ -215,7 +226,7 @@ add_subdirectory(${SRC_DIR}/Vtk)
|
|||||||
|
|
||||||
add_subdirectory(${SRC_DIR}/Python)
|
add_subdirectory(${SRC_DIR}/Python)
|
||||||
|
|
||||||
#add_subdirectory("${SRC_DIR}/utils/make_recipe")
|
add_subdirectory(app)
|
||||||
|
|
||||||
## Documentation and packages
|
## Documentation and packages
|
||||||
|
|
||||||
|
|||||||
1
app/CMakeLists.txt
Normal file
1
app/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
|||||||
|
add_subdirectory(gcompose)
|
||||||
20
app/gcompose/CMakeLists.txt
Normal file
20
app/gcompose/CMakeLists.txt
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
|
||||||
|
add_executable(gcompose src/main.cpp)
|
||||||
|
|
||||||
|
target_include_directories(gcompose PRIVATE
|
||||||
|
${SRC_DIR}
|
||||||
|
${PROJECT_BINARY_DIR}
|
||||||
|
${Geant4_INCLUDE_DIRS}
|
||||||
|
${VTK_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(gcompose
|
||||||
|
mutomCore
|
||||||
|
mutomMath
|
||||||
|
mutomGeant
|
||||||
|
mutomVtk
|
||||||
|
${Geant4_LIBRARIES}
|
||||||
|
${VTK_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS gcompose RUNTIME DESTINATION bin)
|
||||||
45
app/gcompose/src/main.cpp
Normal file
45
app/gcompose/src/main.cpp
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
|
||||||
|
#include "Math/ContainerBox.h"
|
||||||
|
#include <HEP/Geant/Scene.h>
|
||||||
|
|
||||||
|
#include <Vtk/uLibVtkViewer.h>
|
||||||
|
#include <Vtk/vtkContainerBox.h>
|
||||||
|
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkCubeSource.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkRenderer.h>
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main(int argc, char** argv) {
|
||||||
|
std::cout << "Starting gcompose application..." << std::endl;
|
||||||
|
|
||||||
|
uLib::ContainerBox world_box(Vector3f(100, 100, 100));
|
||||||
|
|
||||||
|
uLib::Scene scene;
|
||||||
|
scene.ConstructWorldBox(&world_box, "G4_AIR");
|
||||||
|
scene.Initialize();
|
||||||
|
|
||||||
|
// 2. Initialize VTK Viewer
|
||||||
|
Vtk::Viewer viewer;
|
||||||
|
|
||||||
|
uLib::Vtk::vtkContainerBox vtk_box(&world_box);
|
||||||
|
viewer.AddPuppet(vtk_box);
|
||||||
|
|
||||||
|
viewer.GetRenderer()->Render();
|
||||||
|
|
||||||
|
std::cout << "Geant4 and VTK scenes are ready." << std::endl;
|
||||||
|
std::cout << "Starting VTK Interactor..." << std::endl;
|
||||||
|
|
||||||
|
// 3. Start VTK interactor (blocks until window is closed)
|
||||||
|
viewer.Start();
|
||||||
|
|
||||||
|
// 4. Clean up
|
||||||
|
std::cout << "Shutting down..." << std::endl;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -1,8 +1,13 @@
|
|||||||
[requires]
|
[requires]
|
||||||
eigen/3.4.0
|
eigen/3.4.0
|
||||||
boost/1.83.0
|
boost/1.83.0
|
||||||
pybind11/3.0.2
|
# pybind11/3.0.2
|
||||||
|
hdf5/1.14.3
|
||||||
|
|
||||||
[generators]
|
[generators]
|
||||||
CMakeDeps
|
CMakeDeps
|
||||||
CMakeToolchain
|
CMakeToolchain
|
||||||
|
|
||||||
|
[options]
|
||||||
|
hdf5/*:threadsafe=True
|
||||||
|
hdf5/*:enable_unsupported=True
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ endif()
|
|||||||
target_link_libraries(${libname} ${LIBRARIES})
|
target_link_libraries(${libname} ${LIBRARIES})
|
||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "uLibTargets"
|
||||||
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
set(HEADERS MuonScatter.h MuonError.h MuonEvent.h)
|
|
||||||
|
|
||||||
set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE)
|
|
||||||
|
|
||||||
|
|
||||||
install(FILES ${HEADERS}
|
|
||||||
DESTINATION ${INSTALL_INC_DIR}/Detectors)
|
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
|
||||||
include(uLibTargetMacros)
|
|
||||||
add_subdirectory(testing)
|
|
||||||
endif()
|
|
||||||
@@ -1,114 +0,0 @@
|
|||||||
/*//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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.
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// G4 Solid //
|
|
||||||
#include <Geant4/G4Material.hh>
|
|
||||||
#include <Geant4/G4NistManager.hh>
|
|
||||||
#include <Geant4/G4LogicalVolume.hh>
|
|
||||||
|
|
||||||
// Tessellated solid //
|
|
||||||
#include <Geant4/G4TessellatedSolid.hh>
|
|
||||||
#include <Geant4/G4TriangularFacet.hh>
|
|
||||||
#include <Geant4/G4ThreeVector.hh>
|
|
||||||
|
|
||||||
|
|
||||||
#include "Math/Dense.h"
|
|
||||||
|
|
||||||
#include "Solid.h"
|
|
||||||
|
|
||||||
namespace uLib {
|
|
||||||
|
|
||||||
class DetectorsSolidPimpl {
|
|
||||||
public:
|
|
||||||
static G4ThreeVector getG4Vector3f(const Vector3f &vector) {
|
|
||||||
return G4ThreeVector( vector(0), vector(1), vector(2) );
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Solid::Solid() :
|
|
||||||
m_Logical (new G4LogicalVolume(NULL,NULL,"unnamed_solid")),
|
|
||||||
m_Material(NULL)
|
|
||||||
{}
|
|
||||||
|
|
||||||
Solid::Solid(const char *name) :
|
|
||||||
m_Logical(new G4LogicalVolume(NULL,NULL,name)),
|
|
||||||
m_Material(NULL)
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void Solid::SetNistMaterial(const char *name)
|
|
||||||
{
|
|
||||||
G4NistManager *nist = G4NistManager::Instance();
|
|
||||||
if (m_Material) delete m_Material;
|
|
||||||
m_Material = nist->FindOrBuildMaterial(name);
|
|
||||||
m_Logical->SetMaterial(m_Material);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Solid::SetMaterial(G4Material *material)
|
|
||||||
{
|
|
||||||
if(material)
|
|
||||||
{
|
|
||||||
m_Material = material;
|
|
||||||
m_Logical->SetMaterial(material);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
TessellatedSolid::TessellatedSolid(const char *name) :
|
|
||||||
BaseClass(name),
|
|
||||||
m_Solid(new G4TessellatedSolid(name))
|
|
||||||
{}
|
|
||||||
|
|
||||||
|
|
||||||
void TessellatedSolid::SetMesh(TriangleMesh &mesh)
|
|
||||||
{
|
|
||||||
G4TessellatedSolid *ts = this->m_Solid;
|
|
||||||
for (int i=0; i<mesh.Triangles().size(); ++i) {
|
|
||||||
const Vector3i &trg = mesh.Triangles().at(i);
|
|
||||||
G4TriangularFacet *facet = new G4TriangularFacet(
|
|
||||||
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(0))),
|
|
||||||
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(1))),
|
|
||||||
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(2))),
|
|
||||||
ABSOLUTE);
|
|
||||||
ts->AddFacet((G4VFacet *)facet);
|
|
||||||
}
|
|
||||||
this->m_Logical->SetSolid(ts);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
13
src/HEP/CMakeLists.txt
Normal file
13
src/HEP/CMakeLists.txt
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
|
||||||
|
################################################################################
|
||||||
|
##### HEP - High Energy Physics modules ########################################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
include_directories(${SRC_DIR}/HEP)
|
||||||
|
|
||||||
|
add_subdirectory(Detectors)
|
||||||
|
add_subdirectory(Geant)
|
||||||
|
# add_subdirectory(MuonTomography)
|
||||||
|
|
||||||
|
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} PARENT_SCOPE)
|
||||||
|
set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} PARENT_SCOPE)
|
||||||
34
src/HEP/Detectors/CMakeLists.txt
Normal file
34
src/HEP/Detectors/CMakeLists.txt
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
set(HEADERS
|
||||||
|
ChamberHitEvent.h
|
||||||
|
DetectorChamber.h
|
||||||
|
ExperimentFitEvent.h
|
||||||
|
HierarchicalEncoding.h
|
||||||
|
Hit.h
|
||||||
|
HitMC.h
|
||||||
|
LinearFit.h
|
||||||
|
MuonError.h
|
||||||
|
MuonEvent.h
|
||||||
|
MuonScatter.h
|
||||||
|
)
|
||||||
|
|
||||||
|
set(libname ${PACKAGE_LIBPREFIX}Detectors)
|
||||||
|
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
|
||||||
|
set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Detectors PARENT_SCOPE)
|
||||||
|
|
||||||
|
## Headers-only INTERFACE library
|
||||||
|
add_library(${libname} INTERFACE)
|
||||||
|
target_include_directories(${libname} INTERFACE
|
||||||
|
$<BUILD_INTERFACE:${SRC_DIR}>
|
||||||
|
$<INSTALL_INTERFACE:${INSTALL_INC_DIR}>
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS ${libname}
|
||||||
|
EXPORT "uLibTargets")
|
||||||
|
|
||||||
|
install(FILES ${HEADERS}
|
||||||
|
DESTINATION ${INSTALL_INC_DIR}/HEP/Detectors)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
include(uLibTargetMacros)
|
||||||
|
add_subdirectory(testing)
|
||||||
|
endif()
|
||||||
@@ -29,8 +29,8 @@
|
|||||||
#define U_CHAMBERHITEVENT_H
|
#define U_CHAMBERHITEVENT_H
|
||||||
|
|
||||||
#include "Core/Vector.h"
|
#include "Core/Vector.h"
|
||||||
#include "Hit.h"
|
#include "Detectors/HitMC.h"
|
||||||
#include "ChamberDetector.h"
|
#include "Detectors/DetectorChamber.h"
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
@@ -38,17 +38,17 @@ class ChamberHitEventData
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
uLibConstRefMacro (Hits, Vector<HitData> )
|
uLibConstRefMacro (Hits, Vector<HitData> )
|
||||||
uLibGetMacro (Idv, ChamberDetector::ID)
|
uLibGetMacro (Idv, uint)
|
||||||
private:
|
private:
|
||||||
friend class ChamberHitEvent;
|
friend class ChamberHitEvent;
|
||||||
Vector<HitData> m_Hits;
|
Vector<HitData> m_Hits;
|
||||||
DetectorChamber::ID m_Idv; // -> chamber/view
|
uint m_Idv; // -> chamber/view
|
||||||
};
|
};
|
||||||
|
|
||||||
class ChamberHitEvent : public ChamberHitEventData {
|
class ChamberHitEvent : public ChamberHitEventData {
|
||||||
public:
|
public:
|
||||||
uLibRefMacro (Hits, Vector<HitData> )
|
uLibRefMacro (Hits, Vector<HitData> )
|
||||||
uLibSetMacro (Idv, ChamberDetector::ID)
|
uLibSetMacro (Idv, uint)
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -33,9 +33,6 @@
|
|||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class HitRawCode_CMSDrift :
|
class HitRawCode_CMSDrift :
|
||||||
public BitCode4<unsigned short,6,3,2,5>
|
public BitCode4<unsigned short,6,3,2,5>
|
||||||
{
|
{
|
||||||
@@ -59,8 +56,14 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class HitData {
|
||||||
|
public:
|
||||||
|
HitData() {}
|
||||||
|
~HitData() {}
|
||||||
|
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
25
src/HEP/Geant/ActionInitialization.cpp
Normal file
25
src/HEP/Geant/ActionInitialization.cpp
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
#include "ActionInitialization.hh"
|
||||||
|
#include "EmitterPrimary.hh"
|
||||||
|
|
||||||
|
ActionInitialization::ActionInitialization() : G4VUserActionInitialization() {}
|
||||||
|
|
||||||
|
ActionInitialization::~ActionInitialization() {}
|
||||||
|
|
||||||
|
void ActionInitialization::BuildForMaster() const {
|
||||||
|
// Questo metodo viene usato in modalità Multi-Threading.
|
||||||
|
// Serve per le azioni che devono esistere solo nel thread Master
|
||||||
|
// (tipicamente solo per inizializzare file di output o il RunAction globale).
|
||||||
|
|
||||||
|
// Esempio: SetUserAction(new RunAction());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ActionInitialization::Build() const {
|
||||||
|
// Questo è il cuore dell'inizializzazione per i thread di lavoro.
|
||||||
|
// Qui passiamo il nostro generatore di muoni a Geant4.
|
||||||
|
SetUserAction(new EmitterPrimary());
|
||||||
|
|
||||||
|
// In una simulazione completa, qui registreresti anche le altre classi:
|
||||||
|
// SetUserAction(new RunAction());
|
||||||
|
// SetUserAction(new EventAction());
|
||||||
|
// SetUserAction(new SteppingAction());
|
||||||
|
}
|
||||||
18
src/HEP/Geant/ActionInitialization.hh
Normal file
18
src/HEP/Geant/ActionInitialization.hh
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
#ifndef ActionInitialization_h
|
||||||
|
#define ActionInitialization_h
|
||||||
|
|
||||||
|
#include "G4VUserActionInitialization.hh"
|
||||||
|
|
||||||
|
class ActionInitialization : public G4VUserActionInitialization {
|
||||||
|
public:
|
||||||
|
ActionInitialization();
|
||||||
|
~ActionInitialization();
|
||||||
|
|
||||||
|
// Metodo chiamato solo dal thread principale (Master)
|
||||||
|
virtual void BuildForMaster() const;
|
||||||
|
|
||||||
|
// Metodo chiamato dai thread di lavoro (Worker) o in modalità sequenziale
|
||||||
|
virtual void Build() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
62
src/HEP/Geant/CMakeLists.txt
Normal file
62
src/HEP/Geant/CMakeLists.txt
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
|
||||||
|
################################################################################
|
||||||
|
##### HEP/Geant - Geant4 integration library ###################################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
if(NOT Geant4_FOUND)
|
||||||
|
message(STATUS "Geant4 not found - skipping mutomGeant library")
|
||||||
|
return()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
message(STATUS "Geant4 found: ${Geant4_VERSION}")
|
||||||
|
include(${Geant4_USE_FILE})
|
||||||
|
|
||||||
|
set(HEADERS
|
||||||
|
GeantEvent.h
|
||||||
|
Matter.h
|
||||||
|
Scene.h
|
||||||
|
Solid.h
|
||||||
|
DetectorConstruction.hh
|
||||||
|
PhysicsList.hh
|
||||||
|
ActionInitialization.hh
|
||||||
|
)
|
||||||
|
|
||||||
|
set(SOURCES
|
||||||
|
Scene.cpp
|
||||||
|
Solid.cpp
|
||||||
|
EmitterPrimary.cpp
|
||||||
|
DetectorConstruction.cpp
|
||||||
|
PhysicsList.cpp
|
||||||
|
ActionInitialization.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(libname ${PACKAGE_LIBPREFIX}Geant)
|
||||||
|
set(ULIB_SHARED_LIBRARIES ${ULIB_SHARED_LIBRARIES} ${libname} PARENT_SCOPE)
|
||||||
|
set(ULIB_SELECTED_MODULES ${ULIB_SELECTED_MODULES} Geant PARENT_SCOPE)
|
||||||
|
|
||||||
|
add_library(${libname} SHARED ${SOURCES})
|
||||||
|
set_target_properties(${libname} PROPERTIES
|
||||||
|
VERSION ${PROJECT_VERSION}
|
||||||
|
SOVERSION ${PROJECT_SOVERSION})
|
||||||
|
|
||||||
|
target_include_directories(${libname} PRIVATE ${Geant4_INCLUDE_DIRS})
|
||||||
|
|
||||||
|
target_link_libraries(${libname}
|
||||||
|
${PACKAGE_LIBPREFIX}Core
|
||||||
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
${PACKAGE_LIBPREFIX}Detectors
|
||||||
|
${Geant4_LIBRARIES}
|
||||||
|
)
|
||||||
|
|
||||||
|
install(TARGETS ${libname}
|
||||||
|
EXPORT "uLibTargets"
|
||||||
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
|
install(FILES ${HEADERS}
|
||||||
|
DESTINATION ${INSTALL_INC_DIR}/HEP/Geant)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
include(uLibTargetMacros)
|
||||||
|
add_subdirectory(testing)
|
||||||
|
endif()
|
||||||
29
src/HEP/Geant/DetectorConstruction.cpp
Normal file
29
src/HEP/Geant/DetectorConstruction.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
|
||||||
|
#include "DetectorConstruction.hh"
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Math/ContainerBox.h"
|
||||||
|
|
||||||
|
#include "G4Box.hh"
|
||||||
|
#include "G4LogicalVolume.hh"
|
||||||
|
#include "G4NistManager.hh"
|
||||||
|
#include "G4PVPlacement.hh"
|
||||||
|
#include "G4RunManager.hh"
|
||||||
|
#include "G4SystemOfUnits.hh"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
DetectorConstruction::DetectorConstruction(const char *name) : G4VUserDetectorConstruction() {}
|
||||||
|
|
||||||
|
DetectorConstruction::~DetectorConstruction() {}
|
||||||
|
|
||||||
|
G4VPhysicalVolume *DetectorConstruction::Construct() { return nullptr; }
|
||||||
|
|
||||||
|
void DetectorConstruction::ConstructSDandField() {}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
28
src/HEP/Geant/DetectorConstruction.hh
Normal file
28
src/HEP/Geant/DetectorConstruction.hh
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
#ifndef DetectorConstruction_h
|
||||||
|
#define DetectorConstruction_h
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "G4VUserDetectorConstruction.hh"
|
||||||
|
#include "globals.hh"
|
||||||
|
|
||||||
|
class G4VPhysicalVolume;
|
||||||
|
class G4LogicalVolume;
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class DetectorConstruction : public G4VUserDetectorConstruction {
|
||||||
|
public:
|
||||||
|
DetectorConstruction(const char *name);
|
||||||
|
virtual ~DetectorConstruction();
|
||||||
|
|
||||||
|
virtual G4VPhysicalVolume *Construct();
|
||||||
|
|
||||||
|
virtual void ConstructSDandField();
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
50
src/HEP/Geant/EmitterPrimary.cpp
Normal file
50
src/HEP/Geant/EmitterPrimary.cpp
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
#include "EmitterPrimary.hh"
|
||||||
|
|
||||||
|
#include "G4Box.hh"
|
||||||
|
#include "G4LogicalVolume.hh"
|
||||||
|
#include "G4LogicalVolumeStore.hh"
|
||||||
|
#include "G4ParticleDefinition.hh"
|
||||||
|
#include "G4ParticleGun.hh"
|
||||||
|
#include "G4ParticleTable.hh"
|
||||||
|
#include "G4RunManager.hh"
|
||||||
|
#include "G4SystemOfUnits.hh"
|
||||||
|
#include "Randomize.hh"
|
||||||
|
|
||||||
|
EmitterPrimary::EmitterPrimary()
|
||||||
|
: G4VUserPrimaryGeneratorAction(), fParticleGun(nullptr) {
|
||||||
|
// Creiamo il ParticleGun impostandolo per sparare 1 particella alla volta
|
||||||
|
G4int n_particle = 1;
|
||||||
|
fParticleGun = new G4ParticleGun(n_particle);
|
||||||
|
|
||||||
|
// Otteniamo la tabella delle particelle di Geant4
|
||||||
|
G4ParticleTable *particleTable = G4ParticleTable::GetParticleTable();
|
||||||
|
|
||||||
|
// Cerchiamo il muone negativo (usa "mu+" per l'antimuone)
|
||||||
|
G4String particleName = "mu-";
|
||||||
|
G4ParticleDefinition *particle = particleTable->FindParticle(particleName);
|
||||||
|
|
||||||
|
// Configuriamo le proprietà iniziali della particella
|
||||||
|
fParticleGun->SetParticleDefinition(particle);
|
||||||
|
|
||||||
|
// Impostiamo la direzione della quantità di moto (es. lungo l'asse Z)
|
||||||
|
fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., -1.));
|
||||||
|
|
||||||
|
// Impostiamo l'energia cinetica a 1 GeV
|
||||||
|
fParticleGun->SetParticleEnergy(1.0 * GeV);
|
||||||
|
|
||||||
|
// Impostiamo la posizione di partenza (origine)
|
||||||
|
fParticleGun->SetParticlePosition(G4ThreeVector(0., 0., 10. * m));
|
||||||
|
}
|
||||||
|
|
||||||
|
EmitterPrimary::~EmitterPrimary() {
|
||||||
|
// Importante: liberare la memoria
|
||||||
|
delete fParticleGun;
|
||||||
|
}
|
||||||
|
|
||||||
|
void EmitterPrimary::GeneratePrimaries(G4Event *anEvent) {
|
||||||
|
// Questo metodo viene invocato all'inizio di ogni evento.
|
||||||
|
// Qui potresti anche aggiungere una randomizzazione della posizione o
|
||||||
|
// dell'energia.
|
||||||
|
|
||||||
|
fParticleGun->GeneratePrimaryVertex(anEvent);
|
||||||
|
}
|
||||||
23
src/HEP/Geant/EmitterPrimary.hh
Normal file
23
src/HEP/Geant/EmitterPrimary.hh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#ifndef U_GEANT_EMITTERPRIMARY_HH
|
||||||
|
#define U_GEANT_EMITTERPRIMARY_HH 1
|
||||||
|
|
||||||
|
#include "G4VUserPrimaryGeneratorAction.hh"
|
||||||
|
#include "globals.hh"
|
||||||
|
|
||||||
|
class G4ParticleGun;
|
||||||
|
class G4Event;
|
||||||
|
|
||||||
|
class EmitterPrimary : public G4VUserPrimaryGeneratorAction
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
EmitterPrimary();
|
||||||
|
virtual ~EmitterPrimary();
|
||||||
|
|
||||||
|
// Metodo principale chiamato all'inizio di ogni evento
|
||||||
|
virtual void GeneratePrimaries(G4Event*);
|
||||||
|
|
||||||
|
private:
|
||||||
|
G4ParticleGun* fParticleGun; // Puntatore al cannone di particelle
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef U_GEANTEVENT_H
|
#ifndef U_GEANTEVENT_H
|
||||||
#define U_GEANTEVENT_H
|
#define U_GEANTEVENT_H
|
||||||
|
|
||||||
@@ -32,17 +30,15 @@
|
|||||||
#include "Core/Vector.h"
|
#include "Core/Vector.h"
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
#include "ChamberHitEvent.h"
|
#include "Detectors/ChamberHitEvent.h"
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
class GeantEventData {
|
class GeantEventData {
|
||||||
public:
|
public:
|
||||||
uLibGetMacro (EventID, Id_t )
|
uLibGetMacro(EventID, Id_t) uLibGetMacro(Momentum, Scalarf)
|
||||||
uLibGetMacro (Momentum,Scalarf )
|
uLibConstRefMacro(GenPos, Vector3f) uLibConstRefMacro(GenDir, Vector3f)
|
||||||
uLibConstRefMacro (GenPos, Vector3f)
|
uLibConstRefMacro(ChEvents, Vector<ChamberHitEventData>)
|
||||||
uLibConstRefMacro (GenDir, Vector3f)
|
|
||||||
uLibConstRefMacro (ChEvents,Vector<ChamberHitEventData>)
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class GeantEvent;
|
friend class GeantEvent;
|
||||||
@@ -53,17 +49,13 @@ private:
|
|||||||
Vector<ChamberHitEventData> m_ChEvents;
|
Vector<ChamberHitEventData> m_ChEvents;
|
||||||
};
|
};
|
||||||
|
|
||||||
class GeantEvent {
|
class GeantEvent : public GeantEventData {
|
||||||
public:
|
public:
|
||||||
uLibSetMacro (EventID, Id_t )
|
uLibSetMacro(EventID, Id_t) uLibSetMacro(Momentum, Scalarf)
|
||||||
uLibSetMacro (Momentum,Scalarf )
|
uLibRefMacro(GenPos, Vector3f) uLibRefMacro(GenDir, Vector3f)
|
||||||
uLibRefMacro (GenPos, Vector3f)
|
uLibRefMacro(ChEvents, Vector<ChamberHitEventData>)
|
||||||
uLibRefMacro (GenDir, Vector3f)
|
|
||||||
uLibRefMacro (ChEvents,Vector<ChamberHitEventData>)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
#endif // GEANTEVENT_H
|
#endif // GEANTEVENT_H
|
||||||
22
src/HEP/Geant/PhysicsList.cpp
Normal file
22
src/HEP/Geant/PhysicsList.cpp
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#include "PhysicsList.hh"
|
||||||
|
|
||||||
|
#include "G4DecayPhysics.hh"
|
||||||
|
#include "G4EmStandardPhysics.hh"
|
||||||
|
#include "G4RadioactiveDecayPhysics.hh"
|
||||||
|
|
||||||
|
PhysicsList::PhysicsList() : G4VModularPhysicsList() {
|
||||||
|
SetVerboseLevel(1);
|
||||||
|
|
||||||
|
// Default physics
|
||||||
|
RegisterPhysics(new G4DecayPhysics());
|
||||||
|
|
||||||
|
// EM physics
|
||||||
|
RegisterPhysics(new G4EmStandardPhysics());
|
||||||
|
|
||||||
|
// Radioactive decay
|
||||||
|
RegisterPhysics(new G4RadioactiveDecayPhysics());
|
||||||
|
}
|
||||||
|
|
||||||
|
PhysicsList::~PhysicsList() {}
|
||||||
|
|
||||||
|
void PhysicsList::SetCuts() { G4VModularPhysicsList::SetCuts(); }
|
||||||
14
src/HEP/Geant/PhysicsList.hh
Normal file
14
src/HEP/Geant/PhysicsList.hh
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
#ifndef PhysicsList_h
|
||||||
|
#define PhysicsList_h
|
||||||
|
|
||||||
|
#include "G4VModularPhysicsList.hh"
|
||||||
|
|
||||||
|
class PhysicsList : public G4VModularPhysicsList {
|
||||||
|
public:
|
||||||
|
PhysicsList();
|
||||||
|
virtual ~PhysicsList();
|
||||||
|
|
||||||
|
virtual void SetCuts();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
149
src/HEP/Geant/Scene.cpp
Normal file
149
src/HEP/Geant/Scene.cpp
Normal file
@@ -0,0 +1,149 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <Geant4/G4Box.hh>
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
#include <Geant4/G4PVPlacement.hh>
|
||||||
|
#include <Geant4/G4RunManager.hh>
|
||||||
|
#include <Geant4/G4RunManagerFactory.hh>
|
||||||
|
#include <Geant4/G4SystemOfUnits.hh>
|
||||||
|
#include <Geant4/G4VPhysicalVolume.hh>
|
||||||
|
|
||||||
|
#include "Core/Vector.h"
|
||||||
|
#include "HEP/Geant/DetectorConstruction.hh"
|
||||||
|
#include "Math/ContainerBox.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Solid.h"
|
||||||
|
|
||||||
|
#include "Scene.h"
|
||||||
|
#include "PhysicsList.hh"
|
||||||
|
#include "ActionInitialization.hh"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class SceneDetectorConstruction : public DetectorConstruction {
|
||||||
|
public:
|
||||||
|
SceneDetectorConstruction(class SceneImpl *owner);
|
||||||
|
G4VPhysicalVolume *Construct() override;
|
||||||
|
private:
|
||||||
|
class SceneImpl *m_Owner;
|
||||||
|
};
|
||||||
|
|
||||||
|
class SceneImpl {
|
||||||
|
public:
|
||||||
|
// constructor //
|
||||||
|
SceneImpl() : m_RunManager(G4RunManagerFactory::CreateRunManager()) {}
|
||||||
|
|
||||||
|
// destructor //
|
||||||
|
~SceneImpl() {
|
||||||
|
if (m_RunManager) delete m_RunManager;
|
||||||
|
if (m_World) delete m_World;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Initialize() {
|
||||||
|
// Set mandatory initialization classes for Geant4
|
||||||
|
m_RunManager->SetUserInitialization(new SceneDetectorConstruction(this));
|
||||||
|
m_RunManager->SetUserInitialization(new PhysicsList);
|
||||||
|
m_RunManager->SetUserInitialization(new ActionInitialization);
|
||||||
|
|
||||||
|
// Initialize Geant4
|
||||||
|
m_RunManager->Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
// members //
|
||||||
|
Vector<Solid *> m_Solids;
|
||||||
|
Solid *m_World = nullptr;
|
||||||
|
G4RunManager *m_RunManager;
|
||||||
|
};
|
||||||
|
|
||||||
|
SceneDetectorConstruction::SceneDetectorConstruction(SceneImpl *owner)
|
||||||
|
: DetectorConstruction("Scene"), m_Owner(owner) {}
|
||||||
|
|
||||||
|
G4VPhysicalVolume *SceneDetectorConstruction::Construct() {
|
||||||
|
return m_Owner->m_World->GetPhysical();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Scene::Scene() : d(new SceneImpl()) {}
|
||||||
|
Scene::~Scene() { delete d; }
|
||||||
|
|
||||||
|
void Scene::AddSolid(Solid *solid, Solid *parent) {
|
||||||
|
d->m_Solids.push_back(solid);
|
||||||
|
if (!d->m_World) {
|
||||||
|
d->m_World = solid;
|
||||||
|
} else {
|
||||||
|
solid->SetParent(parent ? parent : d->m_World);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scene::ConstructWorldBox(const ContainerBox *box, const char *material) {
|
||||||
|
// Get nist material manager
|
||||||
|
if (!d->m_World) {
|
||||||
|
d->m_World = new Solid("World");
|
||||||
|
d->m_World->SetNistMaterial(material);
|
||||||
|
AddSolid(d->m_World);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector3f size = box->GetSize();
|
||||||
|
|
||||||
|
G4Box *solidWorld = new G4Box("World",
|
||||||
|
0.5 * size(0),
|
||||||
|
0.5 * size(1),
|
||||||
|
0.5 * size(2));
|
||||||
|
|
||||||
|
G4LogicalVolume *logicWorld = new G4LogicalVolume(solidWorld,
|
||||||
|
d->m_World->GetMaterial(),
|
||||||
|
d->m_World->GetName());
|
||||||
|
|
||||||
|
d->m_World->SetLogical(logicWorld);
|
||||||
|
|
||||||
|
G4PVPlacement *physWorld = new G4PVPlacement(
|
||||||
|
nullptr,
|
||||||
|
G4ThreeVector(0, 0, 0),
|
||||||
|
logicWorld,
|
||||||
|
d->m_World->GetName(),
|
||||||
|
0,
|
||||||
|
false,
|
||||||
|
0,
|
||||||
|
true);
|
||||||
|
|
||||||
|
d->m_World->SetPhysical(physWorld);
|
||||||
|
|
||||||
|
Matrix4f transform = box->GetMatrix();
|
||||||
|
d->m_World->SetTransform(transform);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Scene::Initialize() {
|
||||||
|
d->Initialize();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
@@ -23,30 +23,33 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SCENE_H
|
#ifndef SCENE_H
|
||||||
#define SCENE_H
|
#define SCENE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "Core/Object.h"
|
#include "Core/Object.h"
|
||||||
#include "Core/Vector.h"
|
#include "Core/Vector.h"
|
||||||
#include "Solid.h"
|
#include "Solid.h"
|
||||||
|
|
||||||
|
class G4VPhysicalVolume;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
|
class Scene : public Object {
|
||||||
class DetectorsScene : public Object {
|
|
||||||
public:
|
public:
|
||||||
DetectorsScene();
|
Scene();
|
||||||
~DetectorsScene();
|
~Scene();
|
||||||
|
|
||||||
|
void AddSolid(Solid *solid, Solid *parent = nullptr);
|
||||||
|
|
||||||
void AddSolid(const Solid &solid);
|
void ConstructWorldBox(const ContainerBox *box, const char *material);
|
||||||
|
|
||||||
|
void Initialize();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
class DetectorsScenePimpl *d;
|
class SceneImpl *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
}
|
|
||||||
#endif // SCENE_H
|
#endif // SCENE_H
|
||||||
174
src/HEP/Geant/Solid.cpp
Normal file
174
src/HEP/Geant/Solid.cpp
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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.
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
// G4 Solid //
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
|
||||||
|
// Tessellated solid //
|
||||||
|
#include <Geant4/G4TessellatedSolid.hh>
|
||||||
|
#include <Geant4/G4ThreeVector.hh>
|
||||||
|
#include <Geant4/G4TriangularFacet.hh>
|
||||||
|
#include <Geant4/G4Box.hh>
|
||||||
|
#include <Geant4/G4PVPlacement.hh>
|
||||||
|
|
||||||
|
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Math/Transform.h"
|
||||||
|
|
||||||
|
#include "Solid.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class DetectorsSolidPimpl {
|
||||||
|
public:
|
||||||
|
static G4ThreeVector getG4Vector3f(const Vector3f &vector) {
|
||||||
|
return G4ThreeVector(vector(0), vector(1), vector(2));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
Solid::Solid()
|
||||||
|
: m_Logical(new G4LogicalVolume(NULL, NULL, "unnamed_solid")),
|
||||||
|
m_Material(NULL) {}
|
||||||
|
|
||||||
|
Solid::Solid(const char *name)
|
||||||
|
: m_Logical(new G4LogicalVolume(NULL, NULL, name)), m_Material(NULL) {}
|
||||||
|
|
||||||
|
void Solid::SetNistMaterial(const char *name) {
|
||||||
|
G4NistManager *nist = G4NistManager::Instance();
|
||||||
|
m_Material = nist->FindOrBuildMaterial(name);
|
||||||
|
m_Logical->SetMaterial(m_Material);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Solid::SetMaterial(G4Material *material) {
|
||||||
|
if (material) {
|
||||||
|
m_Material = material;
|
||||||
|
m_Logical->SetMaterial(material);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Solid::SetTransform(Matrix4f transform) {
|
||||||
|
uLib::AffineTransform t;
|
||||||
|
t.SetMatrix(transform);
|
||||||
|
|
||||||
|
// 2. Extracto position and rotation for Geant4
|
||||||
|
Vector3f pos = t.GetPosition();
|
||||||
|
G4ThreeVector g4pos(pos(0), pos(1), pos(2));
|
||||||
|
|
||||||
|
// Create a G4 rotation matrix from the 4x4 matrix
|
||||||
|
Matrix3f m = t.GetRotation();
|
||||||
|
G4RotationMatrix* rot = new G4RotationMatrix();
|
||||||
|
rot->set(G4ThreeVector(m(0,0), m(1,0), m(2,0)),
|
||||||
|
G4ThreeVector(m(0,1), m(1,1), m(2,1)),
|
||||||
|
G4ThreeVector(m(0,2), m(1,2), m(2,2)));
|
||||||
|
|
||||||
|
// 3. Se l'oggetto è già stato piazzato, aggiorniamo la sua trasformazione
|
||||||
|
if (m_Physical) {
|
||||||
|
m_Physical->SetTranslation(g4pos);
|
||||||
|
m_Physical->SetRotation(rot);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Solid::SetParent(Solid *parent) {
|
||||||
|
if (!m_Logical) {
|
||||||
|
std::cerr << "logical volume not created for solid " << GetName() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(m_Physical) {
|
||||||
|
std::cerr << "physical volume already created for solid " << GetName() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
G4LogicalVolume* parentLogical = nullptr;
|
||||||
|
if (parent) {
|
||||||
|
parentLogical = parent->GetLogical();
|
||||||
|
if (!parentLogical) {
|
||||||
|
std::cerr << "parent logical volume not created for solid " << parent->GetName() << std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// G4PVPlacement
|
||||||
|
m_Physical = new G4PVPlacement(
|
||||||
|
nullptr, // Rotation
|
||||||
|
G4ThreeVector(0,0,0), // Position (translation) inside the parent
|
||||||
|
m_Logical, // The logical volume of this solid (the child)
|
||||||
|
GetName(), // Name of the physical volume
|
||||||
|
parentLogical, // The logical volume of the parent (nullptr if it's the World volume)
|
||||||
|
false, // Boolean operations (usually false)
|
||||||
|
0, // Copy number
|
||||||
|
true // Check overlaps (useful to enable in debug phase)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
TessellatedSolid::TessellatedSolid(const char *name)
|
||||||
|
: BaseClass(name), m_Solid(new G4TessellatedSolid(name)) {}
|
||||||
|
|
||||||
|
void TessellatedSolid::SetMesh(TriangleMesh &mesh) {
|
||||||
|
G4TessellatedSolid *ts = this->m_Solid;
|
||||||
|
for (int i = 0; i < mesh.Triangles().size(); ++i) {
|
||||||
|
const Vector3i &trg = mesh.Triangles().at(i);
|
||||||
|
G4TriangularFacet *facet = new G4TriangularFacet(
|
||||||
|
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(0))),
|
||||||
|
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(1))),
|
||||||
|
DetectorsSolidPimpl::getG4Vector3f(mesh.Points().at(trg(2))), ABSOLUTE);
|
||||||
|
ts->AddFacet((G4VFacet *)facet);
|
||||||
|
}
|
||||||
|
this->m_Logical->SetSolid(ts);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
BoxSolid::BoxSolid(const char *name, ContainerBox *box) : BaseClass(name) {
|
||||||
|
m_Solid = new G4Box(name, 0.5, 0.5, 0.5);
|
||||||
|
m_Object = box;
|
||||||
|
Object::connect(box, &ContainerBox::Updated, this, &BoxSolid::Update);
|
||||||
|
this->m_Logical->SetSolid(m_Solid);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BoxSolid::Update() {
|
||||||
|
if (m_Object) {
|
||||||
|
Vector3f size = m_Object->GetSize();
|
||||||
|
m_Solid->SetXHalfLength(size(0) * 0.5);
|
||||||
|
m_Solid->SetYHalfLength(size(1) * 0.5);
|
||||||
|
m_Solid->SetZHalfLength(size(2) * 0.5);
|
||||||
|
|
||||||
|
this->SetTransform(m_Object->GetMatrix());
|
||||||
|
// this->m_Logical->SetSolid(m_Solid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
112
src/HEP/Geant/Solid.h
Normal file
112
src/HEP/Geant/Solid.h
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 SOLID_H
|
||||||
|
#define SOLID_H
|
||||||
|
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Geant/Matter.h"
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
#include "Math/ContainerBox.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Math/TriangleMesh.h"
|
||||||
|
|
||||||
|
class G4Material;
|
||||||
|
class G4LogicalVolume;
|
||||||
|
class G4TessellatedSolid;
|
||||||
|
class G4Box;
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
|
||||||
|
class Solid : public Object {
|
||||||
|
public:
|
||||||
|
Solid();
|
||||||
|
Solid(const char *name);
|
||||||
|
|
||||||
|
void SetNistMaterial(const char *name);
|
||||||
|
void SetMaterial(G4Material *material);
|
||||||
|
|
||||||
|
// Implementiamo SetParent qui, per tutti.
|
||||||
|
virtual void SetParent(Solid *parent);
|
||||||
|
|
||||||
|
// Setters per la posizione (necessari per il piazzamento)
|
||||||
|
void SetTransform(Matrix4f transform);
|
||||||
|
|
||||||
|
uLibGetMacro(Material, G4Material *)
|
||||||
|
uLibGetSetMacro(Logical, G4LogicalVolume *)
|
||||||
|
uLibGetSetMacro(Physical, G4VPhysicalVolume *)
|
||||||
|
|
||||||
|
inline const char *GetName() const { return m_Logical->GetName().c_str(); }
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
G4Material *m_Material;
|
||||||
|
G4LogicalVolume *m_Logical;
|
||||||
|
G4VPhysicalVolume *m_Physical; // <-- Memorizza l'oggetto posizionato
|
||||||
|
|
||||||
|
G4ThreeVector *m_Position; // <-- Offset rispetto al centro del padre
|
||||||
|
G4RotationMatrix* m_Rotation; // <-- Rotazione rispetto al padre
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class TessellatedSolid : public Solid {
|
||||||
|
typedef Solid BaseClass;
|
||||||
|
public:
|
||||||
|
TessellatedSolid(const char *name);
|
||||||
|
void SetMesh(TriangleMesh &mesh);
|
||||||
|
uLibGetMacro(Solid, G4TessellatedSolid *)
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void Update();
|
||||||
|
|
||||||
|
private :
|
||||||
|
G4TessellatedSolid *m_Solid;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class BoxSolid : public Solid {
|
||||||
|
typedef Solid BaseClass;
|
||||||
|
|
||||||
|
public:
|
||||||
|
BoxSolid(const char *name, ContainerBox *box);
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void Update();
|
||||||
|
|
||||||
|
private:
|
||||||
|
ContainerBox *m_Object;
|
||||||
|
G4Box *m_Solid;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
#endif // SOLID_H
|
||||||
23
src/HEP/Geant/testing/ActionInitialization.cpp
Normal file
23
src/HEP/Geant/testing/ActionInitialization.cpp
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#include "HEP/Geant/ActionInitialization.hh" // Il file appena creato
|
||||||
|
#include "G4RunManagerFactory.hh" // Per il RunManager moderno
|
||||||
|
// ... altri include (DetectorConstruction, PhysicsList, ecc.)
|
||||||
|
|
||||||
|
int main(int argc, char **argv) {
|
||||||
|
// Creazione del Run Manager
|
||||||
|
auto *runManager = G4RunManagerFactory::CreateRunManager();
|
||||||
|
|
||||||
|
// 1. Inizializzazione della Geometria
|
||||||
|
// runManager->SetUserInitialization(new DetectorConstruction());
|
||||||
|
|
||||||
|
// 2. Inizializzazione della Fisica
|
||||||
|
// runManager->SetUserInitialization(new PhysicsList());
|
||||||
|
|
||||||
|
// 3. INIZIALIZZAZIONE DELLE AZIONI (Il nostro generatore!)
|
||||||
|
runManager->SetUserInitialization(new ActionInitialization());
|
||||||
|
|
||||||
|
// ... Inizializzazione del kernel ( runManager->Initialize(); ), UI manager,
|
||||||
|
// vis manager, ecc.
|
||||||
|
|
||||||
|
delete runManager;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
14
src/HEP/Geant/testing/CMakeLists.txt
Normal file
14
src/HEP/Geant/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# TESTS
|
||||||
|
set(TESTS
|
||||||
|
SolidTest
|
||||||
|
EventTest
|
||||||
|
GeantApp
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBRARIES
|
||||||
|
${PACKAGE_LIBPREFIX}Core
|
||||||
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
${PACKAGE_LIBPREFIX}Geant
|
||||||
|
Eigen3::Eigen
|
||||||
|
)
|
||||||
|
uLib_add_tests(Geant)
|
||||||
72
src/HEP/Geant/testing/EventTest.cpp
Normal file
72
src/HEP/Geant/testing/EventTest.cpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#include "Geant/Solid.h"
|
||||||
|
#include "HEP/Geant/GeantEvent.h"
|
||||||
|
#include "Math/TriangleMesh.h"
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
#include <Geant4/G4TessellatedSolid.hh>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(Geant Event);
|
||||||
|
|
||||||
|
// Test Solid initialization and NIST material //
|
||||||
|
{
|
||||||
|
Solid solid("test_solid");
|
||||||
|
TEST1(solid.GetLogical() != nullptr);
|
||||||
|
|
||||||
|
solid.SetNistMaterial("G4_AIR");
|
||||||
|
TEST1(solid.GetMaterial() != nullptr);
|
||||||
|
TEST1(solid.GetMaterial()->GetName() == "G4_AIR");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test TessellatedSolid with a simple mesh //
|
||||||
|
{
|
||||||
|
TessellatedSolid tsolid("test_tessellated");
|
||||||
|
TEST1(tsolid.GetLogical() != nullptr);
|
||||||
|
TEST1(tsolid.GetSolid() != nullptr);
|
||||||
|
|
||||||
|
// cube mesh //
|
||||||
|
TriangleMesh mesh;
|
||||||
|
mesh.AddPoint(Vector3f(0,0,0));
|
||||||
|
mesh.AddPoint(Vector3f(1,0,0));
|
||||||
|
mesh.AddPoint(Vector3f(0,1,0));
|
||||||
|
mesh.AddPoint(Vector3f(1,1,0));
|
||||||
|
mesh.AddPoint(Vector3f(0,0,1));
|
||||||
|
mesh.AddPoint(Vector3f(1,0,1));
|
||||||
|
mesh.AddPoint(Vector3f(0,1,1));
|
||||||
|
mesh.AddPoint(Vector3f(1,1,1));
|
||||||
|
|
||||||
|
// create triangles (consistent outward winding) //
|
||||||
|
// bottom (z=0)
|
||||||
|
mesh.AddTriangle(Vector3i(0,2,3));
|
||||||
|
mesh.AddTriangle(Vector3i(0,3,1));
|
||||||
|
// top (z=1)
|
||||||
|
mesh.AddTriangle(Vector3i(4,5,7));
|
||||||
|
mesh.AddTriangle(Vector3i(4,7,6));
|
||||||
|
// left (x=0)
|
||||||
|
mesh.AddTriangle(Vector3i(0,4,6));
|
||||||
|
mesh.AddTriangle(Vector3i(0,6,2));
|
||||||
|
// right (x=1)
|
||||||
|
mesh.AddTriangle(Vector3i(1,3,7));
|
||||||
|
mesh.AddTriangle(Vector3i(1,7,5));
|
||||||
|
// front (y=0)
|
||||||
|
mesh.AddTriangle(Vector3i(0,1,5));
|
||||||
|
mesh.AddTriangle(Vector3i(0,5,4));
|
||||||
|
// back (y=1)
|
||||||
|
mesh.AddTriangle(Vector3i(2,6,7));
|
||||||
|
mesh.AddTriangle(Vector3i(2,7,3));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
tsolid.SetMesh(mesh);
|
||||||
|
// GeantEvent geant_event;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
END_TESTING
|
||||||
|
}
|
||||||
18
src/HEP/Geant/testing/GeantApp.cpp
Normal file
18
src/HEP/Geant/testing/GeantApp.cpp
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#include "Math/ContainerBox.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "HEP/Geant/Scene.h"
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
|
||||||
|
uLib::ContainerBox world_box(Vector3f(100, 100, 100));
|
||||||
|
uLib::Scene scene;
|
||||||
|
|
||||||
|
scene.ConstructWorldBox(&world_box, "G4_AIR");
|
||||||
|
scene.Initialize();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
69
src/HEP/Geant/testing/SolidTest.cpp
Normal file
69
src/HEP/Geant/testing/SolidTest.cpp
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
#include "Geant/Solid.h"
|
||||||
|
#include "Math/TriangleMesh.h"
|
||||||
|
#include "testing-prototype.h"
|
||||||
|
#include <Geant4/G4Material.hh>
|
||||||
|
#include <Geant4/G4NistManager.hh>
|
||||||
|
#include <Geant4/G4LogicalVolume.hh>
|
||||||
|
#include <Geant4/G4TessellatedSolid.hh>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
BEGIN_TESTING(Geant Solid);
|
||||||
|
|
||||||
|
// Test Solid initialization and NIST material //
|
||||||
|
{
|
||||||
|
Solid solid("test_solid");
|
||||||
|
TEST1(solid.GetLogical() != nullptr);
|
||||||
|
|
||||||
|
solid.SetNistMaterial("G4_AIR");
|
||||||
|
TEST1(solid.GetMaterial() != nullptr);
|
||||||
|
TEST1(solid.GetMaterial()->GetName() == "G4_AIR");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test TessellatedSolid with a simple mesh //
|
||||||
|
{
|
||||||
|
TessellatedSolid tsolid("test_tessellated");
|
||||||
|
TEST1(tsolid.GetLogical() != nullptr);
|
||||||
|
TEST1(tsolid.GetSolid() != nullptr);
|
||||||
|
|
||||||
|
// cube mesh //
|
||||||
|
TriangleMesh mesh;
|
||||||
|
mesh.AddPoint(Vector3f(0,0,0));
|
||||||
|
mesh.AddPoint(Vector3f(1,0,0));
|
||||||
|
mesh.AddPoint(Vector3f(0,1,0));
|
||||||
|
mesh.AddPoint(Vector3f(1,1,0));
|
||||||
|
mesh.AddPoint(Vector3f(0,0,1));
|
||||||
|
mesh.AddPoint(Vector3f(1,0,1));
|
||||||
|
mesh.AddPoint(Vector3f(0,1,1));
|
||||||
|
mesh.AddPoint(Vector3f(1,1,1));
|
||||||
|
|
||||||
|
// create triangles (consistent outward winding) //
|
||||||
|
// bottom (z=0)
|
||||||
|
mesh.AddTriangle(Vector3i(0,2,3));
|
||||||
|
mesh.AddTriangle(Vector3i(0,3,1));
|
||||||
|
// top (z=1)
|
||||||
|
mesh.AddTriangle(Vector3i(4,5,7));
|
||||||
|
mesh.AddTriangle(Vector3i(4,7,6));
|
||||||
|
// left (x=0)
|
||||||
|
mesh.AddTriangle(Vector3i(0,4,6));
|
||||||
|
mesh.AddTriangle(Vector3i(0,6,2));
|
||||||
|
// right (x=1)
|
||||||
|
mesh.AddTriangle(Vector3i(1,3,7));
|
||||||
|
mesh.AddTriangle(Vector3i(1,7,5));
|
||||||
|
// front (y=0)
|
||||||
|
mesh.AddTriangle(Vector3i(0,1,5));
|
||||||
|
mesh.AddTriangle(Vector3i(0,5,4));
|
||||||
|
// back (y=1)
|
||||||
|
mesh.AddTriangle(Vector3i(2,6,7));
|
||||||
|
mesh.AddTriangle(Vector3i(2,7,3));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
tsolid.SetMesh(mesh);
|
||||||
|
TEST1(tsolid.GetSolid()->GetNumberOfFacets() == 12);
|
||||||
|
}
|
||||||
|
|
||||||
|
END_TESTING
|
||||||
|
}
|
||||||
@@ -25,50 +25,13 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define BEGIN_TESTING(name) \
|
||||||
|
static int _fail = 0; \
|
||||||
|
printf("..:: Testing " #name " ::..\n");
|
||||||
|
|
||||||
#include <Geant4/G4Material.hh>
|
#define TEST1(val) _fail += (val)==0
|
||||||
#include <Geant4/G4NistManager.hh>
|
#define TEST0(val) _fail += (val)!=0
|
||||||
#include <Geant4/G4LogicalVolume.hh>
|
#define END_TESTING return _fail;
|
||||||
|
|
||||||
#include "Core/Vector.h"
|
|
||||||
#include "Matter.h"
|
|
||||||
#include "Solid.h"
|
|
||||||
|
|
||||||
#include "Scene.h"
|
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
|
||||||
|
|
||||||
|
|
||||||
class DetectorsScenePimpl {
|
|
||||||
|
|
||||||
public:
|
|
||||||
|
|
||||||
|
|
||||||
// members //
|
|
||||||
//Vector<Solid> m_Solids;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DetectorsScene::DetectorsScene() :
|
|
||||||
d(new DetectorsScenePimpl())
|
|
||||||
{}
|
|
||||||
|
|
||||||
DetectorsScene::~DetectorsScene()
|
|
||||||
{
|
|
||||||
delete d;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DetectorsScene::AddSolid(const Solid &solid)
|
|
||||||
{
|
|
||||||
// d->m_Solids.push_back(solid);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -39,12 +39,6 @@ class Hit {
|
|||||||
Type m_DriftTime;
|
Type m_DriftTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class HitMC {
|
class HitMC {
|
||||||
public:
|
public:
|
||||||
virtual Id_t GetChamber() = 0;
|
virtual Id_t GetChamber() = 0;
|
||||||
@@ -54,7 +54,7 @@ endif()
|
|||||||
|
|
||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "uLibTargets"
|
||||||
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
|
|||||||
@@ -23,76 +23,165 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef U_CONTAINERBOX_H
|
#ifndef U_CONTAINERBOX_H
|
||||||
#define U_CONTAINERBOX_H
|
#define U_CONTAINERBOX_H
|
||||||
|
|
||||||
#include "Geometry.h"
|
#include "Geometry.h"
|
||||||
|
#include "Core/Object.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Math/Transform.h"
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Represents an oriented bounding box (OBB) within a hierarchical
|
||||||
|
* transformation system.
|
||||||
|
*
|
||||||
|
* ContainerBox inherits from AffineTransform, which defines its parent
|
||||||
|
* coordinate system. It contains an internal local transformation (m_LocalT)
|
||||||
|
* that defines the box's specific origin and size relative to its own
|
||||||
|
* coordinate system.
|
||||||
|
*/
|
||||||
|
class ContainerBox : public AffineTransform, public Object {
|
||||||
|
|
||||||
|
typedef AffineTransform BaseClass;
|
||||||
|
|
||||||
class ContainerBox : public AffineTransform {
|
|
||||||
public:
|
public:
|
||||||
ContainerBox() : m_LocalT(this) {}
|
/**
|
||||||
|
* @brief Default constructor.
|
||||||
|
* Initializes the local transformation with this instance as its parent.
|
||||||
|
*/
|
||||||
|
ContainerBox()
|
||||||
|
: m_LocalT(this) // BaseClass is Parent of m_LocalTransform
|
||||||
|
{}
|
||||||
|
|
||||||
ContainerBox(const ContainerBox ©) :
|
/**
|
||||||
m_LocalT(this),
|
* @brief Constructor with size.
|
||||||
AffineTransform(copy)
|
* @param size The size vector.
|
||||||
{
|
*/
|
||||||
// FIX for performance //
|
ContainerBox(const Vector3f &size) : m_LocalT(this) { this->SetSize(size); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Copy constructor.
|
||||||
|
* @param copy The ContainerBox instance to copy from.
|
||||||
|
*/
|
||||||
|
ContainerBox(const ContainerBox ©)
|
||||||
|
: m_LocalT(this), // BaseClass is Parent of m_LocalTransform
|
||||||
|
AffineTransform(copy) {
|
||||||
this->SetOrigin(copy.GetOrigin());
|
this->SetOrigin(copy.GetOrigin());
|
||||||
this->SetSize(copy.GetSize());
|
this->SetSize(copy.GetSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the box origin relative to its coordinate system.
|
||||||
|
* @param v The origin position vector.
|
||||||
|
*/
|
||||||
inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
|
inline void SetOrigin(const Vector3f &v) { m_LocalT.SetPosition(v); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the box origin relative to its coordinate system.
|
||||||
|
* @return The origin position vector.
|
||||||
|
*/
|
||||||
inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
|
inline Vector3f GetOrigin() const { return m_LocalT.GetPosition(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Sets the size of the box.
|
||||||
|
* Re-initializes the local transformation and applies the new scale.
|
||||||
|
* @param v The size vector (width, height, depth).
|
||||||
|
*/
|
||||||
void SetSize(const Vector3f &v) {
|
void SetSize(const Vector3f &v) {
|
||||||
Vector3f pos = this->GetOrigin();
|
Vector3f pos = this->GetOrigin();
|
||||||
m_LocalT = AffineTransform(this);
|
m_LocalT = AffineTransform(this); // regenerate local transform
|
||||||
m_LocalT.Scale(v);
|
m_LocalT.Scale(v);
|
||||||
m_LocalT.SetPosition(pos);
|
m_LocalT.SetPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gets the current size (scale) of the box.
|
||||||
|
* @return The size vector.
|
||||||
|
*/
|
||||||
inline Vector3f GetSize() const { return m_LocalT.GetScale(); }
|
inline Vector3f GetSize() const { return m_LocalT.GetScale(); }
|
||||||
|
|
||||||
// FIX... //
|
/**
|
||||||
inline void FlipLocalAxes(int first, int second)
|
* @brief Swaps two local axes of the box.
|
||||||
{ m_LocalT.FlipAxes(first,second); }
|
* @param first Index of the first axis (0=X, 1=Y, 2=Z).
|
||||||
|
* @param second Index of the second axis (0=X, 1=Y, 2=Z).
|
||||||
|
*/
|
||||||
|
inline void FlipLocalAxes(int first, int second) {
|
||||||
|
m_LocalT.FlipAxes(first, second);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the world transformation matrix of the box's volume.
|
||||||
|
* @return A 4x4 transformation matrix.
|
||||||
|
*/
|
||||||
Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); }
|
Matrix4f GetWorldMatrix() const { return m_LocalT.GetWorldMatrix(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Returns the local transformation matrix of the box's volume.
|
||||||
|
* @return A 4x4 transformation matrix.
|
||||||
|
*/
|
||||||
|
Matrix4f GetLocalMatrix() const { return m_LocalT.GetMatrix(); }
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from box-local space to world space.
|
||||||
|
* @param v The local point (4D homogeneous vector).
|
||||||
|
* @return The transformed point in world space.
|
||||||
|
*/
|
||||||
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
||||||
return m_LocalT.GetWorldMatrix() * v;
|
return m_LocalT.GetWorldMatrix() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from box-local space coordinates to world space.
|
||||||
|
* @param x X coordinate in local space.
|
||||||
|
* @param y Y coordinate in local space.
|
||||||
|
* @param z Z coordinate in local space.
|
||||||
|
* @return The transformed point in world space.
|
||||||
|
*/
|
||||||
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
|
inline Vector4f GetWorldPoint(const float x, const float y, const float z) {
|
||||||
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
return this->GetWorldPoint(Vector4f(x, y, z, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from world space to box-local space.
|
||||||
|
* @param v The world point (4D homogeneous vector).
|
||||||
|
* @return The transformed point in box-local space.
|
||||||
|
*/
|
||||||
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
||||||
return m_LocalT.GetWorldMatrix().inverse() * v;
|
return m_LocalT.GetWorldMatrix().inverse() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Transforms a point from world space coordinates to box-local space.
|
||||||
|
* @param x X coordinate in world space.
|
||||||
|
* @param y Y coordinate in world space.
|
||||||
|
* @param z Z coordinate in world space.
|
||||||
|
* @return The transformed point in box-local space.
|
||||||
|
*/
|
||||||
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
|
inline Vector4f GetLocalPoint(const float x, const float y, const float z) {
|
||||||
return this->GetLocalPoint(Vector4f(x,y,z,1));
|
return this->GetLocalPoint(Vector4f(x, y, z, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Translate using transformation chain */
|
||||||
|
using BaseClass::Translate;
|
||||||
|
|
||||||
protected:
|
/** Rotate using transformation chain */
|
||||||
|
using BaseClass::Rotate;
|
||||||
|
|
||||||
|
/** Scale using transformation chain */
|
||||||
|
using BaseClass::Scale;
|
||||||
|
|
||||||
|
signals:
|
||||||
|
|
||||||
|
// signal to emit when the box is updated //
|
||||||
|
void Updated() { ULIB_SIGNAL_EMIT(ContainerBox::Updated); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AffineTransform m_LocalT;
|
AffineTransform m_LocalT;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // CONTAINERBOX_H
|
#endif // CONTAINERBOX_H
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ namespace uLib {
|
|||||||
class Geometry : public AffineTransform {
|
class Geometry : public AffineTransform {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
inline Vector4f GetWorldPoint(const Vector4f &v) const {
|
inline Vector4f GetWorldPoint(const Vector4f v) const {
|
||||||
return this->GetWorldMatrix() * v;
|
return this->GetWorldMatrix() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
return this->GetWorldPoint(Vector4f(x,y,z,1));
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Vector4f GetLocalPoint(const Vector4f &v) const {
|
inline Vector4f GetLocalPoint(const Vector4f v) const {
|
||||||
return this->GetWorldMatrix().inverse() * v;
|
return this->GetWorldMatrix().inverse() * v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,8 +84,8 @@ public:
|
|||||||
|
|
||||||
inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
|
inline void SetParent(AffineTransform *name) { this->m_Parent = name; }
|
||||||
|
|
||||||
inline void SetMatrix (Matrix4f &mat) { m_T.matrix() = mat; }
|
inline void SetMatrix (Matrix4f mat) { m_T.matrix() = mat; }
|
||||||
inline Matrix4f& GetMatrix () { return m_T.matrix(); }
|
inline Matrix4f GetMatrix() const { return m_T.matrix(); }
|
||||||
|
|
||||||
Matrix4f GetWorldMatrix() const
|
Matrix4f GetWorldMatrix() const
|
||||||
{
|
{
|
||||||
@@ -93,22 +93,22 @@ public:
|
|||||||
else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
|
else return m_Parent->GetWorldMatrix() * m_T.matrix(); // T = B * A //
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void SetPosition(const Vector3f &v) { this->m_T.translation() = v; }
|
inline void SetPosition(const Vector3f v) { this->m_T.translation() = v; }
|
||||||
|
|
||||||
inline Vector3f GetPosition() const { return this->m_T.translation(); }
|
inline Vector3f GetPosition() const { return this->m_T.translation(); }
|
||||||
|
|
||||||
inline void SetRotation(const Matrix3f &m) { this->m_T.linear() = m; }
|
inline void SetRotation(const Matrix3f m) { this->m_T.linear() = m; }
|
||||||
|
|
||||||
inline Matrix3f GetRotation() const { return this->m_T.rotation(); }
|
inline Matrix3f GetRotation() const { return this->m_T.rotation(); }
|
||||||
|
|
||||||
inline void Translate(const Vector3f &v) { this->m_T.translate(v); }
|
inline void Translate(const Vector3f v) { this->m_T.translate(v); }
|
||||||
|
|
||||||
inline void Scale(const Vector3f &v) { this->m_T.scale(v); }
|
inline void Scale(const Vector3f v) { this->m_T.scale(v); }
|
||||||
|
|
||||||
inline Vector3f GetScale() const { return this->m_T.linear() * Vector3f(1,1,1); } // FIXXXXXXX
|
inline Vector3f GetScale() const { return this->m_T.linear() * Vector3f(1,1,1); } // FIXXXXXXX
|
||||||
|
|
||||||
|
|
||||||
inline void Rotate(const Matrix3f &m) { this->m_T.rotate(m); }
|
inline void Rotate(const Matrix3f m) { this->m_T.rotate(m); }
|
||||||
|
|
||||||
inline void Rotate(const float angle, Vector3f axis)
|
inline void Rotate(const float angle, Vector3f axis)
|
||||||
{
|
{
|
||||||
@@ -122,12 +122,12 @@ public:
|
|||||||
Rotate(angle,euler_axis);
|
Rotate(angle,euler_axis);
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void PreRotate(const Matrix3f &m) { this->m_T.prerotate(m); }
|
inline void PreRotate(const Matrix3f m) { this->m_T.prerotate(m); }
|
||||||
|
|
||||||
inline void QuaternionRotate(const Vector4f &q)
|
inline void QuaternionRotate(const Vector4f q)
|
||||||
{ this->m_T.rotate(Eigen::Quaternion<float>(q)); }
|
{ this->m_T.rotate(Eigen::Quaternion<float>(q)); }
|
||||||
|
|
||||||
inline void EulerYZYRotate(const Vector3f &e) {
|
inline void EulerYZYRotate(const Vector3f e) {
|
||||||
Matrix3f mat;
|
Matrix3f mat;
|
||||||
mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY())
|
mat = Eigen::AngleAxisf(e.x(), Vector3f::UnitY())
|
||||||
* Eigen::AngleAxisf(e.y(), Vector3f::UnitZ())
|
* Eigen::AngleAxisf(e.y(), Vector3f::UnitZ())
|
||||||
|
|||||||
@@ -63,9 +63,16 @@ public:
|
|||||||
|
|
||||||
inline size_t Count() const { return this->m_Count; }
|
inline size_t Count() const { return this->m_Count; }
|
||||||
|
|
||||||
|
inline size_t size() const { return this->m_Count; }
|
||||||
|
|
||||||
inline const Scalarf &TotalLength() const { return this->m_TotalLength; }
|
inline const Scalarf &TotalLength() const { return this->m_TotalLength; }
|
||||||
|
|
||||||
inline void SetCount(size_t c) { this->m_Count = c; }
|
inline void SetCount(size_t c) {
|
||||||
|
this->m_Count = c;
|
||||||
|
if (this->m_Data.size() != c) {
|
||||||
|
this->m_Data.resize(c);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
inline void SetTotalLength(Scalarf tl) { this->m_TotalLength = tl; }
|
inline void SetTotalLength(Scalarf tl) { this->m_TotalLength = tl; }
|
||||||
|
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
@@ -52,41 +53,82 @@ int main()
|
|||||||
|
|
||||||
BEGIN_TESTING(Math ContainerBox);
|
BEGIN_TESTING(Math ContainerBox);
|
||||||
|
|
||||||
|
{
|
||||||
ContainerBox Cnt;
|
ContainerBox Cnt;
|
||||||
|
Cnt.SetOrigin(Vector3f(0,0,0));
|
||||||
// // Local transform:
|
Cnt.SetSize(Vector3f(2,2,2));
|
||||||
Cnt.SetOrigin(Vector3f(-1,-1,-1));
|
TEST0( Vector4f0(Cnt.GetOrigin().homogeneous() - HVector3f(0,0,0)) );
|
||||||
Cnt.SetSize(Vector3f(2,2,2)); // scaling //
|
|
||||||
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
|
|
||||||
std::cout << "Container scale is: " << Cnt.GetSize().transpose() << "\n";
|
|
||||||
TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) );
|
TEST0( Vector4f0(Cnt.GetSize().homogeneous() - HVector3f(2,2,2)) );
|
||||||
|
|
||||||
|
|
||||||
ContainerBox Box;
|
HPoint3f pt = Cnt.GetLocalPoint(HPoint3f(0,0,0));
|
||||||
|
HPoint3f wp = Cnt.GetWorldPoint(pt);
|
||||||
|
TEST0( Vector4f0(wp - HPoint3f(0,0,0)) );
|
||||||
|
|
||||||
|
HPoint3f pt2 = Cnt.GetLocalPoint(HPoint3f(2,2,2));
|
||||||
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(2,2,2)) );
|
||||||
|
|
||||||
|
HPoint3f pt3 = Cnt.GetLocalPoint(HPoint3f(1,1,1));
|
||||||
|
HPoint3f wp3 = Cnt.GetWorldPoint(pt3);
|
||||||
|
TEST0( Vector4f0(wp3 - HPoint3f(1,1,1)) );
|
||||||
|
|
||||||
|
HPoint3f pt4 = Cnt.GetLocalPoint(HPoint3f(1,2,3));
|
||||||
|
HPoint3f wp4 = Cnt.GetWorldPoint(pt4);
|
||||||
|
TEST0( Vector4f0(wp4 - HPoint3f(1,2,3)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ContainerBox Cnt;
|
||||||
|
Cnt.SetOrigin(Vector3f(0,0,0));
|
||||||
|
Cnt.SetSize(Vector3f(2,2,2));
|
||||||
|
Cnt.EulerYZYRotate(Vector3f(M_PI,0,0));
|
||||||
|
|
||||||
|
HPoint3f pt = Cnt.GetLocalPoint(HPoint3f(0,0,0));
|
||||||
|
HPoint3f wp = Cnt.GetWorldPoint(pt);
|
||||||
|
TEST0( Vector4f0(wp - HPoint3f(0,0,0)) );
|
||||||
|
|
||||||
|
HPoint3f pt2 = Cnt.GetLocalPoint(HPoint3f(2,2,2));
|
||||||
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(2,2,2)) );
|
||||||
|
|
||||||
|
pt2 = HPoint3f(1,1,1);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(-2,2,-2)) );
|
||||||
|
|
||||||
|
pt2 = HPoint3f(1,2,3);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(-2,4,-6)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ContainerBox Cnt;
|
||||||
|
Cnt.SetOrigin(Vector3f(-1,-1,-1));
|
||||||
|
Cnt.SetSize(Vector3f(2,2,2)); // scaling //
|
||||||
|
|
||||||
|
HPoint3f pt2 = HPoint3f(.5,.5,.5);
|
||||||
|
HPoint3f wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(0,0,0)) );
|
||||||
|
|
||||||
|
pt2 = HPoint3f(0,0,0);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(-1,-1,-1)) );
|
||||||
|
|
||||||
|
Cnt.EulerYZYRotate(Vector3f(M_PI,0,0));
|
||||||
|
pt2 = HPoint3f(0,0,0);
|
||||||
|
wp2 = Cnt.GetWorldPoint(pt2);
|
||||||
|
TEST0( Vector4f0(wp2 - HPoint3f(1,-1,1)) );
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ContainerBox Box;
|
||||||
Box.SetPosition(Vector3f(1,1,1));
|
Box.SetPosition(Vector3f(1,1,1));
|
||||||
Box.SetSize(Vector3f(2,2,2));
|
Box.SetSize(Vector3f(2,2,2));
|
||||||
Box.EulerYZYRotate(Vector3f(0,0,0));
|
Box.EulerYZYRotate(Vector3f(0,0,0));
|
||||||
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
|
HPoint3f pt = Box.GetLocalPoint(HPoint3f(2,3,2));
|
||||||
HPoint3f wp = Box.GetWorldPoint(pt);
|
HPoint3f wp = Box.GetWorldPoint(pt);
|
||||||
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
|
TEST0( Vector4f0(wp - HPoint3f(2,3,2)) );
|
||||||
|
}
|
||||||
|
|
||||||
//// // Global
|
|
||||||
// Cnt.SetPosition(Vector3f(1,1,1));
|
|
||||||
// Cnt.EulerYZYRotate(Vector3f(M_PI_2,M_PI_2,0));
|
|
||||||
// HPoint3f p = Cnt.GetWorldPoint(1,1,1);
|
|
||||||
// //std::cout << p.transpose() << "\n";
|
|
||||||
// TEST0( Vector4f0(p - HVector3f(2,1,2)) );
|
|
||||||
// p = Cnt.GetWorldPoint(1,2,3);
|
|
||||||
// //std::cout << p.transpose() << "\n";
|
|
||||||
// TEST0( Vector4f0(p - HVector3f(4,1,3)) );
|
|
||||||
|
|
||||||
|
|
||||||
// // scaling //
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
END_TESTING;
|
END_TESTING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ int main() {
|
|||||||
|
|
||||||
Raytracer rt(img);
|
Raytracer rt(img);
|
||||||
|
|
||||||
const size_t NUM_RAYS = 1000000;
|
const size_t NUM_RAYS = 100000;
|
||||||
std::cout << "Generating " << NUM_RAYS
|
std::cout << "Generating " << NUM_RAYS
|
||||||
<< " random ray pairs across a 100x100x100 grid...\n";
|
<< " random ray pairs across a 100x100x100 grid...\n";
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
include $(top_srcdir)/Common.am
|
|
||||||
|
|
||||||
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/ParticlePhysics/Geant
|
|
||||||
|
|
||||||
library_include_HEADERS =
|
|
||||||
|
|
||||||
_PPGEANT_SOURCES =
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
noinst_LTLIBRARIES = libmutomppgeant.la
|
|
||||||
libmutomppgeant_la_SOURCES = ${_PPGEANT_SOURCES}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
include $(top_srcdir)/Common.am
|
|
||||||
|
|
||||||
library_includedir = $(includedir)/libmutom-${PACKAGE_VERSION}/ParticlePhysics/MuonTomography
|
|
||||||
library_include_HEADERS =
|
|
||||||
|
|
||||||
_PPMUTOM_SOURCES =
|
|
||||||
|
|
||||||
noinst_LTLIBRARIES = libmutomppmutom.la
|
|
||||||
libmutomppmutom_la_SOURCES = ${_PPMUTOM_SOURCES}
|
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +25,7 @@ target_include_directories(uLib_python PRIVATE
|
|||||||
|
|
||||||
# Install uLib_python within the uLib install target
|
# Install uLib_python within the uLib install target
|
||||||
install(TARGETS uLib_python
|
install(TARGETS uLib_python
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "uLibTargets"
|
||||||
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
|
||||||
ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
|
ARCHIVE DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib
|
||||||
|
|||||||
@@ -1,22 +1,22 @@
|
|||||||
#include <pybind11/pybind11.h>
|
|
||||||
#include <pybind11/eigen.h>
|
#include <pybind11/eigen.h>
|
||||||
|
#include <pybind11/pybind11.h>
|
||||||
#include <pybind11/stl.h>
|
#include <pybind11/stl.h>
|
||||||
#include <pybind11/stl_bind.h>
|
#include <pybind11/stl_bind.h>
|
||||||
|
|
||||||
#include <pybind11/numpy.h>
|
#include <pybind11/numpy.h>
|
||||||
|
|
||||||
#include "Math/Dense.h"
|
#include "Math/Accumulator.h"
|
||||||
#include "Math/Transform.h"
|
|
||||||
#include "Math/Geometry.h"
|
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
#include "Math/StructuredData.h"
|
#include "Math/Dense.h"
|
||||||
#include "Math/StructuredGrid.h"
|
#include "Math/Geometry.h"
|
||||||
#include "Math/Structured2DGrid.h"
|
#include "Math/Structured2DGrid.h"
|
||||||
#include "Math/Structured4DGrid.h"
|
#include "Math/Structured4DGrid.h"
|
||||||
|
#include "Math/StructuredData.h"
|
||||||
|
#include "Math/StructuredGrid.h"
|
||||||
|
#include "Math/Transform.h"
|
||||||
#include "Math/TriangleMesh.h"
|
#include "Math/TriangleMesh.h"
|
||||||
#include "Math/VoxRaytracer.h"
|
|
||||||
#include "Math/Accumulator.h"
|
|
||||||
#include "Math/VoxImage.h"
|
#include "Math/VoxImage.h"
|
||||||
|
#include "Math/VoxRaytracer.h"
|
||||||
|
|
||||||
namespace py = pybind11;
|
namespace py = pybind11;
|
||||||
using namespace uLib;
|
using namespace uLib;
|
||||||
@@ -45,7 +45,8 @@ void bind_eigen_type(py::module_ &m, const char *name) {
|
|||||||
|
|
||||||
// Default constructor (zeros)
|
// Default constructor (zeros)
|
||||||
m.def(name, []() -> MatrixType {
|
m.def(name, []() -> MatrixType {
|
||||||
if constexpr (MatrixType::RowsAtCompileTime == Eigen::Dynamic || MatrixType::ColsAtCompileTime == Eigen::Dynamic) {
|
if constexpr (MatrixType::RowsAtCompileTime == Eigen::Dynamic ||
|
||||||
|
MatrixType::ColsAtCompileTime == Eigen::Dynamic) {
|
||||||
return MatrixType(); // Empty dynamic matrix
|
return MatrixType(); // Empty dynamic matrix
|
||||||
} else {
|
} else {
|
||||||
return MatrixType::Zero(); // Zero static matrix
|
return MatrixType::Zero(); // Zero static matrix
|
||||||
@@ -53,7 +54,8 @@ void bind_eigen_type(py::module_ &m, const char *name) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Specialized constructor for dynamic matrices
|
// Specialized constructor for dynamic matrices
|
||||||
if constexpr (MatrixType::RowsAtCompileTime == Eigen::Dynamic || MatrixType::ColsAtCompileTime == Eigen::Dynamic) {
|
if constexpr (MatrixType::RowsAtCompileTime == Eigen::Dynamic ||
|
||||||
|
MatrixType::ColsAtCompileTime == Eigen::Dynamic) {
|
||||||
m.def(name, [](int rows, int cols) -> MatrixType {
|
m.def(name, [](int rows, int cols) -> MatrixType {
|
||||||
MatrixType mat;
|
MatrixType mat;
|
||||||
mat.setZero(rows, cols);
|
mat.setZero(rows, cols);
|
||||||
@@ -70,8 +72,12 @@ void bind_eigen_type(py::module_ &m, const char *name) {
|
|||||||
mat(i) = l[i].cast<Scalar>();
|
mat(i) = l[i].cast<Scalar>();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
int rows = MatrixType::RowsAtCompileTime == Eigen::Dynamic ? (int)std::sqrt(l.size()) : MatrixType::RowsAtCompileTime;
|
int rows = MatrixType::RowsAtCompileTime == Eigen::Dynamic
|
||||||
int cols = MatrixType::ColsAtCompileTime == Eigen::Dynamic ? (int)std::sqrt(l.size()) : MatrixType::ColsAtCompileTime;
|
? (int)std::sqrt(l.size())
|
||||||
|
: MatrixType::RowsAtCompileTime;
|
||||||
|
int cols = MatrixType::ColsAtCompileTime == Eigen::Dynamic
|
||||||
|
? (int)std::sqrt(l.size())
|
||||||
|
: MatrixType::ColsAtCompileTime;
|
||||||
mat.setZero(rows, cols);
|
mat.setZero(rows, cols);
|
||||||
for (size_t i = 0; i < (size_t)l.size(); ++i) {
|
for (size_t i = 0; i < (size_t)l.size(); ++i) {
|
||||||
mat(i / cols, i % cols) = l[i].cast<Scalar>();
|
mat(i / cols, i % cols) = l[i].cast<Scalar>();
|
||||||
@@ -81,18 +87,21 @@ void bind_eigen_type(py::module_ &m, const char *name) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Initialize from py::array
|
// Initialize from py::array
|
||||||
m.def(name, [](py::array_t<Scalar, py::array::c_style | py::array::forcecast> arr) -> MatrixType {
|
m.def(name,
|
||||||
|
[](py::array_t<Scalar, py::array::c_style | py::array::forcecast> arr)
|
||||||
|
-> MatrixType {
|
||||||
auto buf = arr.request();
|
auto buf = arr.request();
|
||||||
MatrixType mat;
|
MatrixType mat;
|
||||||
if constexpr (is_vector) {
|
if constexpr (is_vector) {
|
||||||
mat.setZero(buf.size);
|
mat.setZero(buf.size);
|
||||||
Scalar* ptr = static_cast<Scalar*>(buf.ptr);
|
Scalar *ptr = static_cast<Scalar *>(buf.ptr);
|
||||||
for (ssize_t i = 0; i < buf.size; ++i) mat(i) = ptr[i];
|
for (ssize_t i = 0; i < buf.size; ++i)
|
||||||
|
mat(i) = ptr[i];
|
||||||
} else {
|
} else {
|
||||||
int rows = buf.shape.size() > 0 ? (int)buf.shape[0] : 1;
|
int rows = buf.shape.size() > 0 ? (int)buf.shape[0] : 1;
|
||||||
int cols = buf.shape.size() > 1 ? (int)buf.shape[1] : 1;
|
int cols = buf.shape.size() > 1 ? (int)buf.shape[1] : 1;
|
||||||
mat.setZero(rows, cols);
|
mat.setZero(rows, cols);
|
||||||
Scalar* ptr = static_cast<Scalar*>(buf.ptr);
|
Scalar *ptr = static_cast<Scalar *>(buf.ptr);
|
||||||
for (int i = 0; i < rows; ++i) {
|
for (int i = 0; i < rows; ++i) {
|
||||||
for (int j = 0; j < cols; ++j) {
|
for (int j = 0; j < cols; ++j) {
|
||||||
mat(i, j) = ptr[i * cols + j];
|
mat(i, j) = ptr[i * cols + j];
|
||||||
@@ -192,45 +201,68 @@ void init_math(py::module_ &m) {
|
|||||||
py::bind_vector<uLib::Vector<Voxel>>(m, "Vector_Voxel")
|
py::bind_vector<uLib::Vector<Voxel>>(m, "Vector_Voxel")
|
||||||
.def("MoveToVRAM", &uLib::Vector<Voxel>::MoveToVRAM)
|
.def("MoveToVRAM", &uLib::Vector<Voxel>::MoveToVRAM)
|
||||||
.def("MoveToRAM", &uLib::Vector<Voxel>::MoveToRAM);
|
.def("MoveToRAM", &uLib::Vector<Voxel>::MoveToRAM);
|
||||||
py::bind_vector<uLib::Vector<VoxRaytracer::RayData::Element>>(m, "Vector_VoxRaytracerRayDataElement")
|
py::bind_vector<uLib::Vector<VoxRaytracer::RayData::Element>>(
|
||||||
.def("MoveToVRAM", &uLib::Vector<VoxRaytracer::RayData::Element>::MoveToVRAM)
|
m, "Vector_VoxRaytracerRayDataElement")
|
||||||
.def("MoveToRAM", &uLib::Vector<VoxRaytracer::RayData::Element>::MoveToRAM);
|
.def("MoveToVRAM",
|
||||||
|
&uLib::Vector<VoxRaytracer::RayData::Element>::MoveToVRAM)
|
||||||
|
.def("MoveToRAM",
|
||||||
|
&uLib::Vector<VoxRaytracer::RayData::Element>::MoveToRAM);
|
||||||
|
|
||||||
// 4. Accumulators
|
// 4. Accumulators
|
||||||
py::class_<Accumulator_Mean<float>>(m, "Accumulator_Mean_f")
|
py::class_<Accumulator_Mean<float>>(m, "Accumulator_Mean_f")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("AddPass", &Accumulator_Mean<float>::AddPass)
|
.def("AddPass", &Accumulator_Mean<float>::AddPass)
|
||||||
.def("__call__", py::overload_cast<const float>(&Accumulator_Mean<float>::operator()))
|
.def("__call__",
|
||||||
.def("__call__", py::overload_cast<>(&Accumulator_Mean<float>::operator(), py::const_));
|
py::overload_cast<const float>(&Accumulator_Mean<float>::operator()))
|
||||||
|
.def("__call__", py::overload_cast<>(&Accumulator_Mean<float>::operator(),
|
||||||
|
py::const_));
|
||||||
|
|
||||||
py::class_<Accumulator_Mean<double>>(m, "Accumulator_Mean_d")
|
py::class_<Accumulator_Mean<double>>(m, "Accumulator_Mean_d")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("AddPass", &Accumulator_Mean<double>::AddPass)
|
.def("AddPass", &Accumulator_Mean<double>::AddPass)
|
||||||
.def("__call__", py::overload_cast<const double>(&Accumulator_Mean<double>::operator()))
|
.def("__call__", py::overload_cast<const double>(
|
||||||
.def("__call__", py::overload_cast<>(&Accumulator_Mean<double>::operator(), py::const_));
|
&Accumulator_Mean<double>::operator()))
|
||||||
|
.def("__call__", py::overload_cast<>(
|
||||||
|
&Accumulator_Mean<double>::operator(), py::const_));
|
||||||
|
|
||||||
py::class_<Accumulator_ABTrim<float>>(m, "Accumulator_ABTrim_f")
|
py::class_<Accumulator_ABTrim<float>>(m, "Accumulator_ABTrim_f")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("SetABTrim", &Accumulator_ABTrim<float>::SetABTrim)
|
.def("SetABTrim", &Accumulator_ABTrim<float>::SetABTrim)
|
||||||
.def("__iadd__", [](Accumulator_ABTrim<float> &self, float val) { self += val; return &self; })
|
.def("__iadd__",
|
||||||
|
[](Accumulator_ABTrim<float> &self, float val) {
|
||||||
|
self += val;
|
||||||
|
return &self;
|
||||||
|
})
|
||||||
.def("__call__", &Accumulator_ABTrim<float>::operator());
|
.def("__call__", &Accumulator_ABTrim<float>::operator());
|
||||||
|
|
||||||
py::class_<Accumulator_ABTrim<double>>(m, "Accumulator_ABTrim_d")
|
py::class_<Accumulator_ABTrim<double>>(m, "Accumulator_ABTrim_d")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("SetABTrim", &Accumulator_ABTrim<double>::SetABTrim)
|
.def("SetABTrim", &Accumulator_ABTrim<double>::SetABTrim)
|
||||||
.def("__iadd__", [](Accumulator_ABTrim<double> &self, double val) { self += val; return &self; })
|
.def("__iadd__",
|
||||||
|
[](Accumulator_ABTrim<double> &self, double val) {
|
||||||
|
self += val;
|
||||||
|
return &self;
|
||||||
|
})
|
||||||
.def("__call__", &Accumulator_ABTrim<double>::operator());
|
.def("__call__", &Accumulator_ABTrim<double>::operator());
|
||||||
|
|
||||||
py::class_<Accumulator_ABClip<float>>(m, "Accumulator_ABClip_f")
|
py::class_<Accumulator_ABClip<float>>(m, "Accumulator_ABClip_f")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("SetABTrim", &Accumulator_ABClip<float>::SetABTrim)
|
.def("SetABTrim", &Accumulator_ABClip<float>::SetABTrim)
|
||||||
.def("__iadd__", [](Accumulator_ABClip<float> &self, float val) { self += val; return &self; })
|
.def("__iadd__",
|
||||||
|
[](Accumulator_ABClip<float> &self, float val) {
|
||||||
|
self += val;
|
||||||
|
return &self;
|
||||||
|
})
|
||||||
.def("__call__", &Accumulator_ABClip<float>::operator());
|
.def("__call__", &Accumulator_ABClip<float>::operator());
|
||||||
|
|
||||||
py::class_<Accumulator_ABClip<double>>(m, "Accumulator_ABClip_d")
|
py::class_<Accumulator_ABClip<double>>(m, "Accumulator_ABClip_d")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("SetABTrim", &Accumulator_ABClip<double>::SetABTrim)
|
.def("SetABTrim", &Accumulator_ABClip<double>::SetABTrim)
|
||||||
.def("__iadd__", [](Accumulator_ABClip<double> &self, double val) { self += val; return &self; })
|
.def("__iadd__",
|
||||||
|
[](Accumulator_ABClip<double> &self, double val) {
|
||||||
|
self += val;
|
||||||
|
return &self;
|
||||||
|
})
|
||||||
.def("__call__", &Accumulator_ABClip<double>::operator());
|
.def("__call__", &Accumulator_ABClip<double>::operator());
|
||||||
|
|
||||||
// 5. Core Math Structures
|
// 5. Core Math Structures
|
||||||
@@ -243,25 +275,42 @@ void init_math(py::module_ &m) {
|
|||||||
.def("Scale", &AffineTransform::Scale)
|
.def("Scale", &AffineTransform::Scale)
|
||||||
.def("SetRotation", &AffineTransform::SetRotation)
|
.def("SetRotation", &AffineTransform::SetRotation)
|
||||||
.def("GetRotation", &AffineTransform::GetRotation)
|
.def("GetRotation", &AffineTransform::GetRotation)
|
||||||
.def("Rotate", py::overload_cast<const Matrix3f &>(&AffineTransform::Rotate))
|
.def("Rotate",
|
||||||
.def("Rotate", py::overload_cast<const Vector3f>(&AffineTransform::Rotate))
|
py::overload_cast<const Matrix3f>(&AffineTransform::Rotate))
|
||||||
|
.def("Rotate",
|
||||||
|
py::overload_cast<float, Vector3f>(&AffineTransform::Rotate))
|
||||||
|
.def("Rotate", py::overload_cast<Vector3f>(&AffineTransform::Rotate))
|
||||||
.def("EulerYZYRotate", &AffineTransform::EulerYZYRotate)
|
.def("EulerYZYRotate", &AffineTransform::EulerYZYRotate)
|
||||||
.def("FlipAxes", &AffineTransform::FlipAxes);
|
.def("FlipAxes", &AffineTransform::FlipAxes);
|
||||||
|
|
||||||
py::class_<Geometry, AffineTransform>(m, "Geometry")
|
py::class_<Geometry, AffineTransform>(m, "Geometry")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(&Geometry::GetWorldPoint, py::const_))
|
.def("GetWorldPoint", py::overload_cast<const Vector4f>(
|
||||||
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(&Geometry::GetLocalPoint, py::const_));
|
&Geometry::GetWorldPoint, py::const_))
|
||||||
|
.def("GetWorldPoint",
|
||||||
|
py::overload_cast<float, float, float>(&Geometry::GetWorldPoint))
|
||||||
|
.def("GetLocalPoint", py::overload_cast<const Vector4f>(
|
||||||
|
&Geometry::GetLocalPoint, py::const_))
|
||||||
|
.def("GetLocalPoint",
|
||||||
|
py::overload_cast<float, float, float>(&Geometry::GetLocalPoint));
|
||||||
|
|
||||||
py::class_<ContainerBox, AffineTransform>(m, "ContainerBox")
|
py::class_<ContainerBox, AffineTransform, Object>(m, "ContainerBox")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("SetOrigin", &ContainerBox::SetOrigin)
|
.def("SetOrigin", &ContainerBox::SetOrigin)
|
||||||
.def("GetOrigin", &ContainerBox::GetOrigin)
|
.def("GetOrigin", &ContainerBox::GetOrigin)
|
||||||
.def("SetSize", &ContainerBox::SetSize)
|
.def("SetSize", &ContainerBox::SetSize)
|
||||||
.def("GetSize", &ContainerBox::GetSize)
|
.def("GetSize", &ContainerBox::GetSize)
|
||||||
|
.def("GetLocalMatrix", &ContainerBox::GetLocalMatrix)
|
||||||
.def("GetWorldMatrix", &ContainerBox::GetWorldMatrix)
|
.def("GetWorldMatrix", &ContainerBox::GetWorldMatrix)
|
||||||
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(&ContainerBox::GetWorldPoint, py::const_))
|
.def("GetWorldPoint", py::overload_cast<const Vector4f &>(
|
||||||
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(&ContainerBox::GetLocalPoint, py::const_));
|
&ContainerBox::GetWorldPoint, py::const_))
|
||||||
|
.def("GetWorldPoint",
|
||||||
|
py::overload_cast<float, float, float>(&ContainerBox::GetWorldPoint))
|
||||||
|
.def("GetLocalPoint", py::overload_cast<const Vector4f &>(
|
||||||
|
&ContainerBox::GetLocalPoint, py::const_))
|
||||||
|
.def("GetLocalPoint",
|
||||||
|
py::overload_cast<float, float, float>(&ContainerBox::GetLocalPoint))
|
||||||
|
.def("FlipLocalAxes", &ContainerBox::FlipLocalAxes);
|
||||||
|
|
||||||
py::enum_<StructuredData::_Order>(m, "StructuredDataOrder")
|
py::enum_<StructuredData::_Order>(m, "StructuredDataOrder")
|
||||||
.value("CustomOrder", StructuredData::CustomOrder)
|
.value("CustomOrder", StructuredData::CustomOrder)
|
||||||
@@ -331,10 +380,14 @@ void init_math(py::module_ &m) {
|
|||||||
.def_readwrite("Count", &Voxel::Count);
|
.def_readwrite("Count", &Voxel::Count);
|
||||||
|
|
||||||
py::class_<Abstract::VoxImage, StructuredGrid>(m, "AbstractVoxImage")
|
py::class_<Abstract::VoxImage, StructuredGrid>(m, "AbstractVoxImage")
|
||||||
.def("GetValue", py::overload_cast<const Vector3i &>(&Abstract::VoxImage::GetValue, py::const_))
|
.def("GetValue", py::overload_cast<const Vector3i &>(
|
||||||
.def("GetValue", py::overload_cast<const int>(&Abstract::VoxImage::GetValue, py::const_))
|
&Abstract::VoxImage::GetValue, py::const_))
|
||||||
.def("SetValue", py::overload_cast<const Vector3i &, float>(&Abstract::VoxImage::SetValue))
|
.def("GetValue", py::overload_cast<const int>(
|
||||||
.def("SetValue", py::overload_cast<const int, float>(&Abstract::VoxImage::SetValue))
|
&Abstract::VoxImage::GetValue, py::const_))
|
||||||
|
.def("SetValue", py::overload_cast<const Vector3i &, float>(
|
||||||
|
&Abstract::VoxImage::SetValue))
|
||||||
|
.def("SetValue",
|
||||||
|
py::overload_cast<const int, float>(&Abstract::VoxImage::SetValue))
|
||||||
.def("ExportToVtk", &Abstract::VoxImage::ExportToVtk)
|
.def("ExportToVtk", &Abstract::VoxImage::ExportToVtk)
|
||||||
.def("ExportToVti", &Abstract::VoxImage::ExportToVti)
|
.def("ExportToVti", &Abstract::VoxImage::ExportToVti)
|
||||||
.def("ImportFromVtk", &Abstract::VoxImage::ImportFromVtk)
|
.def("ImportFromVtk", &Abstract::VoxImage::ImportFromVtk)
|
||||||
@@ -343,24 +396,40 @@ void init_math(py::module_ &m) {
|
|||||||
py::class_<VoxImage<Voxel>, Abstract::VoxImage>(m, "VoxImage")
|
py::class_<VoxImage<Voxel>, Abstract::VoxImage>(m, "VoxImage")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def(py::init<const Vector3i &>())
|
.def(py::init<const Vector3i &>())
|
||||||
.def("Data", &VoxImage<Voxel>::Data, py::return_value_policy::reference_internal)
|
.def("Data", &VoxImage<Voxel>::Data,
|
||||||
|
py::return_value_policy::reference_internal)
|
||||||
.def("InitVoxels", &VoxImage<Voxel>::InitVoxels)
|
.def("InitVoxels", &VoxImage<Voxel>::InitVoxels)
|
||||||
.def("Abs", &VoxImage<Voxel>::Abs)
|
.def("Abs", &VoxImage<Voxel>::Abs)
|
||||||
.def("clipImage", py::overload_cast<const Vector3i, const Vector3i>(&VoxImage<Voxel>::clipImage, py::const_))
|
.def("clipImage", py::overload_cast<const Vector3i, const Vector3i>(
|
||||||
.def("clipImage", py::overload_cast<const HPoint3f, const HPoint3f>(&VoxImage<Voxel>::clipImage, py::const_))
|
&VoxImage<Voxel>::clipImage, py::const_))
|
||||||
.def("clipImage", py::overload_cast<const float>(&VoxImage<Voxel>::clipImage, py::const_))
|
.def("clipImage", py::overload_cast<const HPoint3f, const HPoint3f>(
|
||||||
.def("maskImage", py::overload_cast<const HPoint3f, const HPoint3f, float>(&VoxImage<Voxel>::maskImage, py::const_))
|
&VoxImage<Voxel>::clipImage, py::const_))
|
||||||
.def("maskImage", py::overload_cast<const float, float, float>(&VoxImage<Voxel>::maskImage, py::const_), py::arg("threshold"), py::arg("belowValue") = 0, py::arg("aboveValue") = 0)
|
.def("clipImage", py::overload_cast<const float>(
|
||||||
.def("fixVoxels", py::overload_cast<const float, float>(&VoxImage<Voxel>::fixVoxels, py::const_))
|
&VoxImage<Voxel>::clipImage, py::const_))
|
||||||
.def("__getitem__", py::overload_cast<unsigned int>(&VoxImage<Voxel>::operator[]))
|
.def("maskImage",
|
||||||
.def("__getitem__", py::overload_cast<const Vector3i &>(&VoxImage<Voxel>::operator[]));
|
py::overload_cast<const HPoint3f, const HPoint3f, float>(
|
||||||
|
&VoxImage<Voxel>::maskImage, py::const_))
|
||||||
|
.def("maskImage",
|
||||||
|
py::overload_cast<const float, float, float>(
|
||||||
|
&VoxImage<Voxel>::maskImage, py::const_),
|
||||||
|
py::arg("threshold"), py::arg("belowValue") = 0,
|
||||||
|
py::arg("aboveValue") = 0)
|
||||||
|
.def("fixVoxels", py::overload_cast<const float, float>(
|
||||||
|
&VoxImage<Voxel>::fixVoxels, py::const_))
|
||||||
|
.def("__getitem__",
|
||||||
|
py::overload_cast<unsigned int>(&VoxImage<Voxel>::operator[]))
|
||||||
|
.def("__getitem__",
|
||||||
|
py::overload_cast<const Vector3i &>(&VoxImage<Voxel>::operator[]));
|
||||||
|
|
||||||
py::class_<TriangleMesh>(m, "TriangleMesh")
|
py::class_<TriangleMesh>(m, "TriangleMesh")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("AddPoint", &TriangleMesh::AddPoint)
|
.def("AddPoint", &TriangleMesh::AddPoint)
|
||||||
.def("AddTriangle", py::overload_cast<const Vector3i &>(&TriangleMesh::AddTriangle))
|
.def("AddTriangle",
|
||||||
.def("Points", &TriangleMesh::Points, py::return_value_policy::reference_internal)
|
py::overload_cast<const Vector3i &>(&TriangleMesh::AddTriangle))
|
||||||
.def("Triangles", &TriangleMesh::Triangles, py::return_value_policy::reference_internal);
|
.def("Points", &TriangleMesh::Points,
|
||||||
|
py::return_value_policy::reference_internal)
|
||||||
|
.def("Triangles", &TriangleMesh::Triangles,
|
||||||
|
py::return_value_policy::reference_internal);
|
||||||
|
|
||||||
py::class_<VoxRaytracer::RayData::Element>(m, "VoxRaytracerRayDataElement")
|
py::class_<VoxRaytracer::RayData::Element>(m, "VoxRaytracerRayDataElement")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
@@ -370,7 +439,8 @@ void init_math(py::module_ &m) {
|
|||||||
py::class_<VoxRaytracer::RayData>(m, "VoxRaytracerRayData")
|
py::class_<VoxRaytracer::RayData>(m, "VoxRaytracerRayData")
|
||||||
.def(py::init<>())
|
.def(py::init<>())
|
||||||
.def("AppendRay", &VoxRaytracer::RayData::AppendRay)
|
.def("AppendRay", &VoxRaytracer::RayData::AppendRay)
|
||||||
.def("Data", py::overload_cast<>(&VoxRaytracer::RayData::Data), py::return_value_policy::reference_internal)
|
.def("Data", py::overload_cast<>(&VoxRaytracer::RayData::Data),
|
||||||
|
py::return_value_policy::reference_internal)
|
||||||
.def("Count", &VoxRaytracer::RayData::Count)
|
.def("Count", &VoxRaytracer::RayData::Count)
|
||||||
.def("TotalLength", &VoxRaytracer::RayData::TotalLength)
|
.def("TotalLength", &VoxRaytracer::RayData::TotalLength)
|
||||||
.def("SetCount", &VoxRaytracer::RayData::SetCount)
|
.def("SetCount", &VoxRaytracer::RayData::SetCount)
|
||||||
@@ -378,8 +448,8 @@ void init_math(py::module_ &m) {
|
|||||||
|
|
||||||
py::class_<VoxRaytracer>(m, "VoxRaytracer")
|
py::class_<VoxRaytracer>(m, "VoxRaytracer")
|
||||||
.def(py::init<StructuredGrid &>(), py::keep_alive<1, 2>())
|
.def(py::init<StructuredGrid &>(), py::keep_alive<1, 2>())
|
||||||
.def("GetImage", &VoxRaytracer::GetImage, py::return_value_policy::reference_internal)
|
.def("GetImage", &VoxRaytracer::GetImage,
|
||||||
|
py::return_value_policy::reference_internal)
|
||||||
.def("TraceLine", &VoxRaytracer::TraceLine)
|
.def("TraceLine", &VoxRaytracer::TraceLine)
|
||||||
.def("TraceBetweenPoints", &VoxRaytracer::TraceBetweenPoints);
|
.def("TraceBetweenPoints", &VoxRaytracer::TraceBetweenPoints);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ set_target_properties(${libname} PROPERTIES
|
|||||||
target_link_libraries(${libname} ${LIBRARIES})
|
target_link_libraries(${libname} ${LIBRARIES})
|
||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "uLibTargets"
|
||||||
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
set(HEADERS uLibVtkInterface.h
|
set(HEADERS uLibVtkInterface.h
|
||||||
uLibVtkViewer.h
|
uLibVtkViewer.h
|
||||||
vtkContainerBox.h
|
vtkContainerBox.h
|
||||||
vtkMuonScatter.h
|
vtkHandlerWidget.h
|
||||||
vtkStructuredGrid.h
|
)
|
||||||
vtkVoxRaytracerRepresentation.h
|
|
||||||
vtkVoxImage.h)
|
|
||||||
|
|
||||||
set(SOURCES uLibVtkInterface.cxx
|
set(SOURCES uLibVtkInterface.cxx
|
||||||
uLibVtkViewer.cpp
|
uLibVtkViewer.cpp
|
||||||
vtkContainerBox.cpp
|
vtkContainerBox.cpp
|
||||||
vtkMuonScatter.cxx
|
vtkHandlerWidget.cpp
|
||||||
vtkStructuredGrid.cpp
|
)
|
||||||
vtkVoxRaytracerRepresentation.cpp
|
|
||||||
vtkVoxImage.cpp)
|
## Pull in Math VTK wrappers (sets MATH_SOURCES / MATH_HEADERS)
|
||||||
|
add_subdirectory(Math)
|
||||||
|
list(APPEND SOURCES ${MATH_SOURCES})
|
||||||
|
list(APPEND HEADERS ${MATH_HEADERS})
|
||||||
|
|
||||||
|
## Pull in HEP/Detectors VTK wrappers (sets HEP_DETECTORS_SOURCES / HEADERS)
|
||||||
|
add_subdirectory(HEP/Detectors)
|
||||||
|
list(APPEND SOURCES ${HEP_DETECTORS_SOURCES})
|
||||||
|
list(APPEND HEADERS ${HEP_DETECTORS_HEADERS})
|
||||||
|
|
||||||
|
## Pull in HEP/MuonTomography VTK wrappers (sets HEP_MUONTOMOGRAPHY_SOURCES / HEADERS)
|
||||||
|
add_subdirectory(HEP/MuonTomography)
|
||||||
|
list(APPEND SOURCES ${HEP_MUONTOMOGRAPHY_SOURCES})
|
||||||
|
list(APPEND HEADERS ${HEP_MUONTOMOGRAPHY_HEADERS})
|
||||||
|
|
||||||
set(LIBRARIES Eigen3::Eigen
|
set(LIBRARIES Eigen3::Eigen
|
||||||
${ROOT_LIBRARIES}
|
${ROOT_LIBRARIES}
|
||||||
${VTK_LIBRARIES}
|
${VTK_LIBRARIES}
|
||||||
${PACKAGE_LIBPREFIX}Math)
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
${PACKAGE_LIBPREFIX}Detectors)
|
||||||
|
|
||||||
if(USE_CUDA)
|
if(USE_CUDA)
|
||||||
find_package(CUDAToolkit REQUIRED)
|
find_package(CUDAToolkit REQUIRED)
|
||||||
@@ -35,11 +47,14 @@ set_target_properties(${libname} PROPERTIES
|
|||||||
target_link_libraries(${libname} ${LIBRARIES})
|
target_link_libraries(${libname} ${LIBRARIES})
|
||||||
|
|
||||||
install(TARGETS ${libname}
|
install(TARGETS ${libname}
|
||||||
EXPORT "${PROJECT_NAME}Targets"
|
EXPORT "uLibTargets"
|
||||||
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
RUNTIME DESTINATION ${INSTALL_BIN_DIR} COMPONENT bin
|
||||||
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
LIBRARY DESTINATION ${INSTALL_LIB_DIR} COMPONENT lib)
|
||||||
|
|
||||||
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk)
|
install(FILES ${HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk)
|
||||||
|
install(FILES ${MATH_HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk/Math)
|
||||||
|
install(FILES ${HEP_DETECTORS_HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk/HEP/Detectors)
|
||||||
|
install(FILES ${HEP_MUONTOMOGRAPHY_HEADERS} DESTINATION ${INSTALL_INC_DIR}/Vtk/HEP/MuonTomography)
|
||||||
|
|
||||||
if(BUILD_TESTING)
|
if(BUILD_TESTING)
|
||||||
include(uLibTargetMacros)
|
include(uLibTargetMacros)
|
||||||
|
|||||||
24
src/Vtk/HEP/Detectors/CMakeLists.txt
Normal file
24
src/Vtk/HEP/Detectors/CMakeLists.txt
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
|
||||||
|
################################################################################
|
||||||
|
##### 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
|
||||||
|
${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)
|
||||||
|
include(uLibTargetMacros)
|
||||||
|
add_subdirectory(testing)
|
||||||
|
endif()
|
||||||
16
src/Vtk/HEP/Detectors/testing/CMakeLists.txt
Normal file
16
src/Vtk/HEP/Detectors/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# TESTS
|
||||||
|
set(TESTS
|
||||||
|
vtkMuonScatterTest
|
||||||
|
vtkDetectorChamberTest
|
||||||
|
)
|
||||||
|
|
||||||
|
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/vtkDetectorChamberTest.cpp
Normal file
62
src/Vtk/HEP/Detectors/testing/vtkDetectorChamberTest.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/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 d1, d2;
|
||||||
|
d1.SetSize(uLib::Vector3f(1, 1, 1));
|
||||||
|
d1.SetPosition(uLib::Vector3f(0, 0, 0));
|
||||||
|
d1.Scale(uLib::Vector3f(5, 10, 2));
|
||||||
|
d1.Translate(uLib::Vector3f(0, 0, 0));
|
||||||
|
|
||||||
|
d2.SetSize(uLib::Vector3f(1, 1, 1));
|
||||||
|
d2.SetPosition(uLib::Vector3f(0, 0, 0));
|
||||||
|
d2.Scale(uLib::Vector3f(5, 10, 2));
|
||||||
|
d2.Translate(uLib::Vector3f(0, 0, 10));
|
||||||
|
|
||||||
|
|
||||||
|
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber(&d1);
|
||||||
|
uLib::Vtk::vtkDetectorChamber vtkDetectorChamber2(&d2);
|
||||||
|
|
||||||
|
if (!vtkDetectorChamber.GetProp()) {
|
||||||
|
BOOST_FAIL("vtkDetectorChamber::GetProp() returned NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
uLib::Vtk::Viewer viewer;
|
||||||
|
viewer.AddPuppet(vtkDetectorChamber);
|
||||||
|
viewer.AddPuppet(vtkDetectorChamber2);
|
||||||
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK(true); // reached here without crash
|
||||||
|
}
|
||||||
@@ -23,53 +23,40 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include "Vtk/HEP/Detectors/vtkMuonScatter.h"
|
||||||
|
#include "HEP/Detectors/MuonScatter.h"
|
||||||
|
|
||||||
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
|
#define BOOST_TEST_MODULE VtkMuonScatterTest
|
||||||
#include "Math/TriangleMesh.h"
|
#include <boost/test/unit_test.hpp>
|
||||||
#include "Vtk/vtkTriangleMesh.h"
|
|
||||||
#include "testing-prototype.h"
|
|
||||||
|
|
||||||
using namespace uLib;
|
using namespace uLib;
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(vtkMuonScatterTest) {
|
||||||
|
MuonScatter event;
|
||||||
|
event.LineIn().direction << 0, -1, 1, 0;
|
||||||
|
event.LineIn().origin << 0, 1, -1, 1;
|
||||||
|
|
||||||
int main()
|
event.LineOut().direction << 0, -1, 0, 0;
|
||||||
{
|
event.LineOut().origin << 0, -1, 0, 1;
|
||||||
BEGIN_TESTING(Vtk Triangle Mesh);
|
|
||||||
|
|
||||||
// { // SIMPLE TESTS //
|
Vtk::vtkMuonScatter v_event(event);
|
||||||
|
v_event.AddPocaPoint(HPoint3f(0, 0, 0));
|
||||||
|
|
||||||
|
v_event.SaveToXMLFile("vtk_testing_muonevent.vtp");
|
||||||
|
|
||||||
// TriangleMesh mesh;
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
Vtk::Viewer viewer;
|
||||||
|
|
||||||
// mesh.AddPoint(Vector3f(0,0,0));
|
// Vtk::Tie<Vtk::vtkMuonScatter> tms;
|
||||||
// mesh.AddPoint(Vector3f(0,1,0));
|
// tms.DoAction();
|
||||||
// mesh.AddPoint(Vector3f(1,0,0));
|
// Vtk::Tie<Vtk::Viewer> vms;
|
||||||
|
// vms.DoAction();
|
||||||
|
|
||||||
// mesh.AddTriangle(Vector3i(0,1,2));
|
viewer.AddPuppet(v_event);
|
||||||
|
viewer.Start();
|
||||||
// mesh.PrintSelf(std::cout);
|
|
||||||
|
|
||||||
|
|
||||||
// vtkTriangleMesh v_mesh(mesh);
|
|
||||||
// v_mesh.Update();
|
|
||||||
|
|
||||||
// TestingRenderWidow(&v_mesh);
|
|
||||||
// }
|
|
||||||
|
|
||||||
{ // SIMPLE TESTS //
|
|
||||||
|
|
||||||
TriangleMesh mesh;
|
|
||||||
|
|
||||||
vtkTriangleMesh v_mesh(mesh);
|
|
||||||
|
|
||||||
v_mesh.ReadFromStlFile("prova.stl");
|
|
||||||
|
|
||||||
mesh.PrintSelf(std::cout);
|
|
||||||
|
|
||||||
TestingRenderWidow(&v_mesh);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK(true); // reached here without crash
|
||||||
END_TESTING;
|
|
||||||
}
|
}
|
||||||
199
src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx
Normal file
199
src/Vtk/HEP/Detectors/vtkDetectorChamber.cxx
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <vtkAbstractTransform.h>
|
||||||
|
#include <vtkAxes.h>
|
||||||
|
#include <vtkCubeSource.h>
|
||||||
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkPropPicker.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkRenderWindow.h>
|
||||||
|
#include <vtkRenderWindowInteractor.h>
|
||||||
|
#include <vtkRenderer.h>
|
||||||
|
#include <vtkRendererCollection.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
|
#include "Vtk/HEP/Detectors/vtkDetectorChamber.h"
|
||||||
|
#include <vtkBoxWidget.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
vtkDetectorChamber::vtkDetectorChamber(DetectorChamber *content)
|
||||||
|
: vtkContainerBox(content), m_Actor(vtkActor::New()),
|
||||||
|
m_Widget(vtkBoxWidget::New()) {
|
||||||
|
m_Callback = vtkWidgetCallback::New();
|
||||||
|
m_PickerCallback = vtkSelectionCallback::New();
|
||||||
|
|
||||||
|
m_Callback->SetChamber(this);
|
||||||
|
m_PickerCallback->SetChamber(this);
|
||||||
|
m_Widget->AddObserver(vtkCommand::InteractionEvent, m_Callback);
|
||||||
|
|
||||||
|
m_InitialTransform = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
m_RelativeTransform = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
m_TotalTransform = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
|
||||||
|
this->InstallPipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkDetectorChamber::~vtkDetectorChamber() {
|
||||||
|
m_Actor->Delete();
|
||||||
|
m_Widget->Delete();
|
||||||
|
m_Callback->Delete();
|
||||||
|
m_PickerCallback->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
DetectorChamber *vtkDetectorChamber::GetContent() {
|
||||||
|
return static_cast<DetectorChamber *>(m_Content);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::PrintSelf(std::ostream &o) const {
|
||||||
|
vtkContainerBox::PrintSelf(o);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Connect the interactor to the widget
|
||||||
|
*/
|
||||||
|
void vtkDetectorChamber::ConnectInteractor(
|
||||||
|
vtkRenderWindowInteractor *interactor) {
|
||||||
|
if (!interactor)
|
||||||
|
return;
|
||||||
|
m_Widget->SetInteractor(interactor);
|
||||||
|
m_Widget->SetProp3D(m_Actor);
|
||||||
|
interactor->AddObserver(vtkCommand::LeftButtonPressEvent, m_PickerCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::SetTransform(vtkTransform *t) {
|
||||||
|
|
||||||
|
|
||||||
|
m_RelativeTransform->SetMatrix(t->GetMatrix());
|
||||||
|
m_RelativeTransform->Update();
|
||||||
|
|
||||||
|
// Set content global transform (BaseClass of ContainerBox) //
|
||||||
|
vtkMatrix4x4 *vmat = m_TotalTransform->GetMatrix();
|
||||||
|
Matrix4f transform;
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
transform(i, j) = vmat->GetElement(i, j);
|
||||||
|
this->GetContent()->SetMatrix(transform);
|
||||||
|
this->GetContent()->Updated(); // emit signal
|
||||||
|
|
||||||
|
this->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkBoxWidget *vtkDetectorChamber::GetWidget() { return m_Widget; }
|
||||||
|
|
||||||
|
void vtkDetectorChamber::Update() {
|
||||||
|
if (m_Actor->GetMapper())
|
||||||
|
m_Actor->GetMapper()->Update();
|
||||||
|
BaseClass::Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::InstallPipe() {
|
||||||
|
if (!m_Content)
|
||||||
|
return;
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||||
|
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
||||||
|
|
||||||
|
// 1. Initialize Global Transform (m_Transform) from Content's matrix (Base
|
||||||
|
// class AffineTransform)
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmatGlobal =
|
||||||
|
vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f matGlobal = this->GetContent()->GetMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmatGlobal->SetElement(i, j, matGlobal(i, j));
|
||||||
|
|
||||||
|
m_InitialTransform->SetMatrix(vmatGlobal);
|
||||||
|
m_InitialTransform->Update();
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
|
m_Actor->SetMapper(mapper);
|
||||||
|
|
||||||
|
m_Actor->GetProperty()->SetRepresentationToSurface();
|
||||||
|
m_Actor->GetProperty()->SetEdgeVisibility(true);
|
||||||
|
m_Actor->GetProperty()->SetOpacity(0.4);
|
||||||
|
m_Actor->GetProperty()->SetAmbient(0.7);
|
||||||
|
|
||||||
|
// Temporarily disable UserTransform to place widget on local base
|
||||||
|
m_Widget->SetProp3D(m_Actor);
|
||||||
|
|
||||||
|
m_TotalTransform->SetInput(m_RelativeTransform);
|
||||||
|
m_TotalTransform->Concatenate(m_InitialTransform);
|
||||||
|
m_Actor->SetUserTransform(m_TotalTransform);
|
||||||
|
m_TotalTransform->Update();
|
||||||
|
|
||||||
|
m_Widget->PlaceWidget();
|
||||||
|
m_Widget->SetPlaceFactor(2);
|
||||||
|
|
||||||
|
this->SetProp(m_Actor);
|
||||||
|
this->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::vtkWidgetCallback::Execute(vtkObject *caller,
|
||||||
|
unsigned long, void *) {
|
||||||
|
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget *>(caller);
|
||||||
|
|
||||||
|
// Get the Relative transform from the widget //
|
||||||
|
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
||||||
|
widget->GetTransform(t);
|
||||||
|
chamber->SetTransform(t);
|
||||||
|
|
||||||
|
// Apply to both the content and the actor state //
|
||||||
|
chamber->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkDetectorChamber::vtkSelectionCallback::Execute(vtkObject *caller,
|
||||||
|
unsigned long, void *) {
|
||||||
|
vtkRenderWindowInteractor *interactor =
|
||||||
|
reinterpret_cast<vtkRenderWindowInteractor *>(caller);
|
||||||
|
vtkSmartPointer<vtkPropPicker> picker = vtkSmartPointer<vtkPropPicker>::New();
|
||||||
|
int *pos = interactor->GetEventPosition();
|
||||||
|
picker->Pick(
|
||||||
|
pos[0], pos[1], 0,
|
||||||
|
interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer());
|
||||||
|
|
||||||
|
vtkProp *picked = picker->GetViewProp();
|
||||||
|
if (picked == chamber->m_Actor) {
|
||||||
|
if (!chamber->m_Widget->GetEnabled()) {
|
||||||
|
chamber->m_Widget->SetInteractor(interactor);
|
||||||
|
chamber->m_Widget->On();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (chamber->m_Widget->GetEnabled()) {
|
||||||
|
chamber->m_Widget->Off();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
104
src/Vtk/HEP/Detectors/vtkDetectorChamber.h
Normal file
104
src/Vtk/HEP/Detectors/vtkDetectorChamber.h
Normal file
@@ -0,0 +1,104 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <vtkCommand.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
|
#include "HEP/Detectors/DetectorChamber.h"
|
||||||
|
#include "Math/Dense.h"
|
||||||
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
#include "Vtk/vtkContainerBox.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkBoxWidget.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
// class vtkHandlerWidget; // Removed as we use vtkBoxWidget now
|
||||||
|
|
||||||
|
class vtkDetectorChamber : public vtkContainerBox {
|
||||||
|
typedef DetectorChamber Content;
|
||||||
|
typedef vtkContainerBox BaseClass;
|
||||||
|
|
||||||
|
public:
|
||||||
|
vtkDetectorChamber(DetectorChamber *content);
|
||||||
|
~vtkDetectorChamber();
|
||||||
|
|
||||||
|
Content *GetContent();
|
||||||
|
|
||||||
|
void SetTransform(class vtkTransform *t);
|
||||||
|
|
||||||
|
class vtkBoxWidget *GetWidget();
|
||||||
|
|
||||||
|
void Update();
|
||||||
|
|
||||||
|
void ConnectInteractor(vtkRenderWindowInteractor *interactor) override;
|
||||||
|
|
||||||
|
void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void InstallPipe() override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
class vtkWidgetCallback : public vtkCommand {
|
||||||
|
public:
|
||||||
|
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
||||||
|
void SetChamber(uLib::Vtk::vtkDetectorChamber *ch) { this->chamber = ch; }
|
||||||
|
virtual void Execute(vtkObject *caller, unsigned long, void *) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uLib::Vtk::vtkDetectorChamber *chamber;
|
||||||
|
};
|
||||||
|
|
||||||
|
class vtkSelectionCallback : public vtkCommand {
|
||||||
|
public:
|
||||||
|
static vtkSelectionCallback *New() { return new vtkSelectionCallback; }
|
||||||
|
void SetChamber(uLib::Vtk::vtkDetectorChamber *ch) { this->chamber = ch; }
|
||||||
|
virtual void Execute(vtkObject *caller, unsigned long, void *) override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
uLib::Vtk::vtkDetectorChamber *chamber;
|
||||||
|
};
|
||||||
|
|
||||||
|
vtkActor *m_Actor;
|
||||||
|
vtkBoxWidget *m_Widget;
|
||||||
|
vtkWidgetCallback *m_Callback;
|
||||||
|
vtkSelectionCallback *m_PickerCallback;
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkTransform> m_InitialTransform;
|
||||||
|
vtkSmartPointer<vtkTransform> m_RelativeTransform;
|
||||||
|
vtkSmartPointer<vtkTransform> m_TotalTransform;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
|
#endif // VTK_DETECTOR_CHAMBER_H
|
||||||
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
|
||||||
@@ -23,17 +23,15 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef VTKMUONEVENT_H
|
#ifndef VTKMUONEVENT_H
|
||||||
#define VTKMUONEVENT_H
|
#define VTKMUONEVENT_H
|
||||||
|
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkAppendPolyData.h>
|
||||||
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
#include <vtkSphereSource.h>
|
#include <vtkSphereSource.h>
|
||||||
#include <vtkAppendPolyData.h>
|
|
||||||
#include <vtkPolyDataMapper.h>
|
|
||||||
#include <vtkLineSource.h>
|
|
||||||
#include <vtkActor.h>
|
|
||||||
|
|
||||||
#include <vtk3DWidget.h>
|
#include <vtk3DWidget.h>
|
||||||
#include <vtkBoxWidget.h>
|
#include <vtkBoxWidget.h>
|
||||||
@@ -45,28 +43,25 @@
|
|||||||
|
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "HEP/Detectors/MuonEvent.h"
|
||||||
#include "Detectors/MuonEvent.h"
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
class vtkMuonEvent : public Abstract::uLibVtkPolydata {
|
class vtkMuonEvent : public Puppet, public Polydata {
|
||||||
typedef MuonEventData Content;
|
typedef MuonEventData Content;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vtkMuonEvent(const MuonEventData &content);
|
vtkMuonEvent(const MuonEventData &content);
|
||||||
vtkMuonEvent(MuonEventData &content);
|
vtkMuonEvent(MuonEventData &content);
|
||||||
~vtkMuonEvent();
|
~vtkMuonEvent();
|
||||||
|
|
||||||
Content& GetContent();
|
Content &GetContent();
|
||||||
|
|
||||||
void PrintSelf(std::ostream &o) const;
|
void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
virtual vtkProp *GetProp();
|
virtual vtkPolyData *GetPolyData() const;
|
||||||
|
|
||||||
virtual vtkPolyData* GetPolyData() const;
|
|
||||||
|
|
||||||
void AddPocaPoint(HPoint3f poca);
|
void AddPocaPoint(HPoint3f poca);
|
||||||
|
|
||||||
@@ -74,13 +69,11 @@ public:
|
|||||||
|
|
||||||
void vtkStartInteractive();
|
void vtkStartInteractive();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InstallPipe();
|
void InstallPipe();
|
||||||
|
|
||||||
vtkMuonEvent::Content *content;
|
vtkMuonEvent::Content *content;
|
||||||
vtkPolyData *m_PolyData;
|
vtkPolyData *m_PolyData;
|
||||||
vtkActor *m_Prop;
|
|
||||||
|
|
||||||
vtkAppendPolyData *m_Appender;
|
vtkAppendPolyData *m_Appender;
|
||||||
vtkBoxWidget *m_WidgetIN;
|
vtkBoxWidget *m_WidgetIN;
|
||||||
@@ -88,7 +81,7 @@ private:
|
|||||||
HPoint3f m_Poca;
|
HPoint3f m_Poca;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
|
|
||||||
}
|
#endif // VTKMUONEVENT_H
|
||||||
|
|
||||||
#endif // VTKMUONSCATTER_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
|
||||||
@@ -23,18 +23,16 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef VTKMUONSCATTER_H
|
#ifndef VTKMUONSCATTER_H
|
||||||
#define VTKMUONSCATTER_H
|
#define VTKMUONSCATTER_H
|
||||||
|
|
||||||
#include <vtkVersion.h>
|
#include <vtkActor.h>
|
||||||
|
#include <vtkAppendPolyData.h>
|
||||||
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
#include <vtkSphereSource.h>
|
#include <vtkSphereSource.h>
|
||||||
#include <vtkAppendPolyData.h>
|
#include <vtkVersion.h>
|
||||||
#include <vtkPolyDataMapper.h>
|
|
||||||
#include <vtkLineSource.h>
|
|
||||||
#include <vtkActor.h>
|
|
||||||
|
|
||||||
#include <vtk3DWidget.h>
|
#include <vtk3DWidget.h>
|
||||||
#include <vtkBoxWidget.h>
|
#include <vtkBoxWidget.h>
|
||||||
@@ -46,8 +44,8 @@
|
|||||||
|
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "HEP/Detectors/MuonScatter.h"
|
||||||
#include "Detectors/MuonScatter.h"
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
|
||||||
class vtkRenderWindowInteractor;
|
class vtkRenderWindowInteractor;
|
||||||
|
|
||||||
@@ -56,8 +54,8 @@ namespace Vtk {
|
|||||||
|
|
||||||
class vtkMuonScatter : public Puppet, public Polydata {
|
class vtkMuonScatter : public Puppet, public Polydata {
|
||||||
typedef MuonScatter Content;
|
typedef MuonScatter Content;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
vtkMuonScatter(const MuonScatter &content);
|
vtkMuonScatter(const MuonScatter &content);
|
||||||
vtkMuonScatter(MuonScatter &content);
|
vtkMuonScatter(MuonScatter &content);
|
||||||
|
|
||||||
@@ -67,7 +65,7 @@ public:
|
|||||||
|
|
||||||
void PrintSelf(std::ostream &o) const;
|
void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
virtual vtkPolyData* GetPolyData() const;
|
virtual vtkPolyData *GetPolyData() const;
|
||||||
|
|
||||||
void AddPocaPoint(HPoint3f poca);
|
void AddPocaPoint(HPoint3f poca);
|
||||||
|
|
||||||
@@ -88,7 +86,7 @@ private:
|
|||||||
vtkPolyData *m_PolyData;
|
vtkPolyData *m_PolyData;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // vtk
|
} // namespace Vtk
|
||||||
} // uLib
|
} // namespace uLib
|
||||||
|
|
||||||
#endif // VTKMUONSCATTER_H
|
#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)
|
||||||
@@ -23,69 +23,55 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <vtkBoxWidget.h>
|
#include <vtkBoxWidget.h>
|
||||||
#include <vtkSmartPointer.h>
|
|
||||||
#include <vtkCommand.h>
|
#include <vtkCommand.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
|
|
||||||
#include <Detectors/MuonScatter.h>
|
|
||||||
#include <Math/VoxRaytracer.h>
|
|
||||||
|
|
||||||
#include "Vtk/vtkMuonScatter.h"
|
|
||||||
#include "Vtk/vtkStructuredGrid.h"
|
|
||||||
#include "Vtk/vtkVoxRaytracerRepresentation.h"
|
|
||||||
#include "Vtk/uLibVtkViewer.h"
|
|
||||||
|
|
||||||
// remove
|
|
||||||
#include <vtkCornerAnnotation.h>
|
#include <vtkCornerAnnotation.h>
|
||||||
|
|
||||||
#include "testing-prototype.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;
|
using namespace uLib;
|
||||||
|
|
||||||
|
class vtkWidgetCallback : public vtkCommand {
|
||||||
|
|
||||||
class vtkWidgetCallback : public vtkCommand
|
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
||||||
|
|
||||||
void SetTracer(Vtk::vtkVoxRaytracerRepresentation *parent)
|
void SetTracer(Vtk::vtkVoxRaytracerRepresentation *parent) {
|
||||||
{
|
|
||||||
this->vtk_raytr = parent;
|
this->vtk_raytr = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SetMuon (uLib::MuonScatter *muon) { this->muon = muon; }
|
void SetMuon(uLib::MuonScatter *muon) { this->muon = muon; }
|
||||||
|
|
||||||
void SetAnnotation ( vtkCornerAnnotation *annotation) {
|
void SetAnnotation(vtkCornerAnnotation *annotation) {
|
||||||
this->annotation = annotation;
|
this->annotation = annotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void Execute(vtkObject *caller, unsigned long, void*)
|
virtual void Execute(vtkObject *caller, unsigned long, void *) {
|
||||||
{
|
|
||||||
char str[40];
|
char str[40];
|
||||||
vtk_raytr->SetMuon(*muon);
|
vtk_raytr->SetMuon(*muon);
|
||||||
if(annotation)
|
if (annotation) {
|
||||||
{
|
sprintf(str, "total length = %f", vtk_raytr->GetRay().TotalLength());
|
||||||
sprintf(str,"total length = %f",vtk_raytr->GetRay().TotalLength());
|
annotation->SetText(1, str);
|
||||||
annotation->SetText(1,str);
|
for (int i = 0; i < vtk_raytr->GetRay().size(); ++i) {
|
||||||
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 << "L[" << i << "] = "
|
|
||||||
<< vtk_raytr->GetRay().Data().at(i).L << "\n";
|
|
||||||
}
|
}
|
||||||
std::cout << "\n";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
vtkWidgetCallback() :
|
vtkWidgetCallback() : vtk_raytr(NULL), muon(NULL), annotation(NULL) {}
|
||||||
vtk_raytr(NULL),
|
|
||||||
muon(NULL),
|
|
||||||
annotation(NULL) {}
|
|
||||||
|
|
||||||
uLib::VoxRaytracer *raytracer;
|
uLib::VoxRaytracer *raytracer;
|
||||||
Vtk::vtkVoxRaytracerRepresentation *vtk_raytr;
|
Vtk::vtkVoxRaytracerRepresentation *vtk_raytr;
|
||||||
@@ -93,50 +79,40 @@ private:
|
|||||||
vtkCornerAnnotation *annotation;
|
vtkCornerAnnotation *annotation;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(vtkVoxRaytracerRepresentationTest) {
|
||||||
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
BEGIN_TESTING(vtk VoxRaytracer);
|
|
||||||
|
|
||||||
|
|
||||||
// muon scatter //
|
// muon scatter //
|
||||||
MuonScatter muon;
|
MuonScatter muon;
|
||||||
muon.LineIn().origin << -6, 12, -6, 1;
|
muon.LineIn().origin << -6, 12, -6, 1;
|
||||||
muon.LineIn().direction << 1 , -1 , 1 , 0;
|
muon.LineIn().direction << 1, -1, 1, 0;
|
||||||
muon.LineOut().origin << 6 , -4 , 6 , 1;
|
muon.LineOut().origin << 6, -4, 6, 1;
|
||||||
muon.LineOut().direction << 1 , -1 , 1 , 0;
|
muon.LineOut().direction << 1, -1, 1, 0;
|
||||||
|
|
||||||
Vtk::vtkMuonScatter v_muon(muon);
|
Vtk::vtkMuonScatter v_muon(muon);
|
||||||
|
|
||||||
|
|
||||||
// structured grid //
|
// structured grid //
|
||||||
StructuredGrid grid(Vector3i(12,10,12));
|
StructuredGrid grid(Vector3i(12, 10, 12));
|
||||||
grid.SetSpacing(Vector3f(1,1,1));
|
grid.SetSpacing(Vector3f(1, 1, 1));
|
||||||
grid.SetPosition(Vector3f(0,0,0));
|
grid.SetPosition(Vector3f(0, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
Vtk::vtkStructuredGrid v_grid(grid);
|
Vtk::vtkStructuredGrid v_grid(grid);
|
||||||
|
|
||||||
|
|
||||||
// voxraytracer //
|
// voxraytracer //
|
||||||
VoxRaytracer rt(grid);
|
VoxRaytracer rt(grid);
|
||||||
HPoint3f pt;
|
HPoint3f pt;
|
||||||
rt.GetEntryPoint(muon.LineIn(),pt);
|
rt.GetEntryPoint(muon.LineIn(), pt);
|
||||||
std::cout << pt.transpose() << "\n";
|
std::cout << pt.transpose() << "\n";
|
||||||
|
|
||||||
Vtk::vtkVoxRaytracerRepresentation v_rt(rt);
|
Vtk::vtkVoxRaytracerRepresentation v_rt(rt);
|
||||||
v_rt.SetMuon(muon);
|
v_rt.SetMuon(muon);
|
||||||
v_rt.SetRayColor(Vector4f(1,0,0,1));
|
v_rt.SetRayColor(Vector4f(1, 0, 0, 1));
|
||||||
|
|
||||||
// // renderer //
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
// renderer //
|
||||||
Vtk::Viewer viewer;
|
Vtk::Viewer viewer;
|
||||||
|
|
||||||
// widget //
|
// widget //
|
||||||
vtkBoxWidget *widget = v_grid.GetWidget();
|
vtkBoxWidget *widget = v_grid.GetWidget();
|
||||||
|
|
||||||
|
|
||||||
vtkWidgetCallback *cbk = vtkWidgetCallback::New();
|
vtkWidgetCallback *cbk = vtkWidgetCallback::New();
|
||||||
cbk->SetTracer(&v_rt);
|
cbk->SetTracer(&v_rt);
|
||||||
cbk->SetMuon(&muon);
|
cbk->SetMuon(&muon);
|
||||||
@@ -150,7 +126,7 @@ int main()
|
|||||||
viewer.AddPuppet(v_rt);
|
viewer.AddPuppet(v_rt);
|
||||||
viewer.AddPuppet(v_muon);
|
viewer.AddPuppet(v_muon);
|
||||||
viewer.Start();
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK(v_rt.GetRay().Count() > 0);
|
||||||
END_TESTING;
|
|
||||||
}
|
}
|
||||||
@@ -27,12 +27,12 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "vtkVoxRaytracerRepresentation.h"
|
#include "Vtk/HEP/MuonTomography/vtkVoxRaytracerRepresentation.h"
|
||||||
|
|
||||||
#include "Math/VoxRaytracer.h"
|
#include "Math/VoxRaytracer.h"
|
||||||
|
|
||||||
// #include "vtkMuonEvent.h"
|
// #include "Vtk/HEP/Detectors/vtkMuonEvent.h"
|
||||||
#include "vtkMuonScatter.h"
|
#include "Vtk/HEP/Detectors/vtkMuonScatter.h"
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
@@ -114,12 +114,10 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon) {
|
|||||||
m_Line3->SetPoint1(pt1(0), pt1(1), pt1(2));
|
m_Line3->SetPoint1(pt1(0), pt1(1), pt1(2));
|
||||||
m_Line3->SetPoint2(pt2(0), pt2(1), pt2(2));
|
m_Line3->SetPoint2(pt2(0), pt2(1), pt2(2));
|
||||||
|
|
||||||
// Create a vtkPoints object and store the points in it
|
|
||||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||||
points->InsertNextPoint(pt1(0), pt1(1), pt1(2));
|
points->InsertNextPoint(pt1(0), pt1(1), pt1(2));
|
||||||
points->InsertNextPoint(pt2(0), pt2(1), pt2(2));
|
points->InsertNextPoint(pt2(0), pt2(1), pt2(2));
|
||||||
|
|
||||||
// Create a cell array to store the lines in and add the lines to it
|
|
||||||
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
||||||
|
|
||||||
vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
|
vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
|
||||||
@@ -127,19 +125,16 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon) {
|
|||||||
line->GetPointIds()->SetId(1, 1);
|
line->GetPointIds()->SetId(1, 1);
|
||||||
lines->InsertNextCell(line);
|
lines->InsertNextCell(line);
|
||||||
|
|
||||||
// Create a polydata to store everything in
|
|
||||||
vtkSmartPointer<vtkPolyData> linesPolyData =
|
vtkSmartPointer<vtkPolyData> linesPolyData =
|
||||||
vtkSmartPointer<vtkPolyData>::New();
|
vtkSmartPointer<vtkPolyData>::New();
|
||||||
|
|
||||||
// Add the points to the dataset
|
|
||||||
linesPolyData->SetPoints(points);
|
linesPolyData->SetPoints(points);
|
||||||
|
|
||||||
// Add the lines to the dataset
|
|
||||||
linesPolyData->SetLines(lines);
|
linesPolyData->SetLines(lines);
|
||||||
|
|
||||||
m_RayLine->RemoveAllInputs();
|
m_RayLine->RemoveAllInputs();
|
||||||
#if VTK_MAJOR_VERSION <= 5
|
#if VTK_MAJOR_VERSION <= 5
|
||||||
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
|
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
|
||||||
|
#else
|
||||||
|
m_RayLine->AddInputData(linesPolyData);
|
||||||
#endif
|
#endif
|
||||||
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
|
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
|
||||||
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
|
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
|
||||||
@@ -177,15 +172,12 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca) {
|
|||||||
m_Line3->SetPoint1(pt1(0), pt1(1), pt1(2));
|
m_Line3->SetPoint1(pt1(0), pt1(1), pt1(2));
|
||||||
m_Line3->SetPoint2(pt2(0), pt2(1), pt2(2));
|
m_Line3->SetPoint2(pt2(0), pt2(1), pt2(2));
|
||||||
|
|
||||||
// Create a vtkPoints object and store the points in it
|
|
||||||
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||||
points->InsertNextPoint(pt1(0), pt1(1), pt1(2));
|
points->InsertNextPoint(pt1(0), pt1(1), pt1(2));
|
||||||
points->InsertNextPoint(poca(0), poca(1), poca(2));
|
points->InsertNextPoint(poca(0), poca(1), poca(2));
|
||||||
points->InsertNextPoint(pt2(0), pt2(1), pt2(2));
|
points->InsertNextPoint(pt2(0), pt2(1), pt2(2));
|
||||||
|
|
||||||
// Create a cell array to store the lines in and add the lines to it
|
|
||||||
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
||||||
|
|
||||||
for (unsigned int i = 0; i < 2; i++) {
|
for (unsigned int i = 0; i < 2; i++) {
|
||||||
vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
|
vtkSmartPointer<vtkLine> line = vtkSmartPointer<vtkLine>::New();
|
||||||
line->GetPointIds()->SetId(0, i);
|
line->GetPointIds()->SetId(0, i);
|
||||||
@@ -193,19 +185,16 @@ void vtkVoxRaytracerRepresentation::SetMuon(MuonScatter &muon, HPoint3f poca) {
|
|||||||
lines->InsertNextCell(line);
|
lines->InsertNextCell(line);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a polydata to store everything in
|
|
||||||
vtkSmartPointer<vtkPolyData> linesPolyData =
|
vtkSmartPointer<vtkPolyData> linesPolyData =
|
||||||
vtkSmartPointer<vtkPolyData>::New();
|
vtkSmartPointer<vtkPolyData>::New();
|
||||||
|
|
||||||
// Add the points to the dataset
|
|
||||||
linesPolyData->SetPoints(points);
|
linesPolyData->SetPoints(points);
|
||||||
|
|
||||||
// Add the lines to the dataset
|
|
||||||
linesPolyData->SetLines(lines);
|
linesPolyData->SetLines(lines);
|
||||||
|
|
||||||
m_RayLine->RemoveAllInputs();
|
m_RayLine->RemoveAllInputs();
|
||||||
#if VTK_MAJOR_VERSION <= 5
|
#if VTK_MAJOR_VERSION <= 5
|
||||||
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
|
m_RayLine->AddInputConnection(linesPolyData->GetProducerPort());
|
||||||
|
#else
|
||||||
|
m_RayLine->AddInputData(linesPolyData);
|
||||||
#endif
|
#endif
|
||||||
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
|
m_RayLine->AddInputConnection(m_Line1->GetOutputPort());
|
||||||
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
|
m_RayLine->AddInputConnection(m_Sphere1->GetOutputPort());
|
||||||
@@ -263,9 +252,11 @@ void vtkVoxRaytracerRepresentation::SetRay(VoxRaytracer::RayData *ray) {
|
|||||||
cube->Update();
|
cube->Update();
|
||||||
#if VTK_MAJOR_VERSION <= 5
|
#if VTK_MAJOR_VERSION <= 5
|
||||||
appender->AddInput(cube->GetOutput());
|
appender->AddInput(cube->GetOutput());
|
||||||
|
#else
|
||||||
|
appender->AddInputData(cube->GetOutput());
|
||||||
#endif
|
#endif
|
||||||
appender->Update();
|
|
||||||
}
|
}
|
||||||
|
appender->Modified();
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkVoxRaytracerRepresentation::SetVoxelsColor(Vector4f rgba) {
|
void vtkVoxRaytracerRepresentation::SetVoxelsColor(Vector4f rgba) {
|
||||||
@@ -294,21 +285,18 @@ void vtkVoxRaytracerRepresentation::InstallPipe() {
|
|||||||
append->AddInputConnection(m_Line1->GetOutputPort());
|
append->AddInputConnection(m_Line1->GetOutputPort());
|
||||||
append->AddInputConnection(m_Line2->GetOutputPort());
|
append->AddInputConnection(m_Line2->GetOutputPort());
|
||||||
|
|
||||||
append->Update();
|
|
||||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
|
||||||
mapper->SetInputConnection(append->GetOutputPort());
|
mapper->SetInputConnection(append->GetOutputPort());
|
||||||
mapper->Update();
|
|
||||||
|
|
||||||
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
vtkSmartPointer<vtkActor> actor = vtkActor::New();
|
||||||
actor->SetMapper(mapper);
|
actor->SetMapper(mapper);
|
||||||
actor->GetProperty()->SetColor(0.6, 0.6, 1);
|
actor->GetProperty()->SetColor(0.6, 0.6, 1);
|
||||||
this->SetProp(actor);
|
this->SetProp(actor);
|
||||||
|
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(m_RayLine->GetOutputPort());
|
mapper->SetInputConnection(m_RayLine->GetOutputPort());
|
||||||
mapper->Update();
|
|
||||||
|
|
||||||
m_RayLineActor->SetMapper(mapper);
|
m_RayLineActor->SetMapper(mapper);
|
||||||
m_RayLineActor->GetProperty()->SetColor(1, 0, 0);
|
m_RayLineActor->GetProperty()->SetColor(1, 0, 0);
|
||||||
@@ -322,7 +310,6 @@ void vtkVoxRaytracerRepresentation::InstallPipe() {
|
|||||||
|
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(polyfilter->GetOutputPort());
|
mapper->SetInputConnection(polyfilter->GetOutputPort());
|
||||||
mapper->Update();
|
|
||||||
|
|
||||||
vtkActor *vra = m_RayRepresentationActor;
|
vtkActor *vra = m_RayRepresentationActor;
|
||||||
vra->SetMapper(mapper);
|
vra->SetMapper(mapper);
|
||||||
@@ -23,39 +23,36 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef U_VTKVOXRAYTRACERREPRESENTATION_H
|
#ifndef U_VTKVOXRAYTRACERREPRESENTATION_H
|
||||||
#define U_VTKVOXRAYTRACERREPRESENTATION_H
|
#define U_VTKVOXRAYTRACERREPRESENTATION_H
|
||||||
|
|
||||||
#include <vtkLine.h>
|
|
||||||
#include <vtkCellArray.h>
|
#include <vtkCellArray.h>
|
||||||
|
#include <vtkLine.h>
|
||||||
|
|
||||||
#include <vtkLineSource.h>
|
#include <vtkActor.h>
|
||||||
#include <vtkSphereSource.h>
|
#include <vtkAppendPolyData.h>
|
||||||
|
#include <vtkAssembly.h>
|
||||||
#include <vtkBoundingBox.h>
|
#include <vtkBoundingBox.h>
|
||||||
#include <vtkCubeSource.h>
|
#include <vtkCubeSource.h>
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkPolyData.h>
|
||||||
#include <vtkPolyDataMapper.h>
|
#include <vtkPolyDataMapper.h>
|
||||||
#include <vtkAppendPolyData.h>
|
|
||||||
#include <vtkActor.h>
|
|
||||||
#include <vtkAssembly.h>
|
|
||||||
#include <vtkProp3DCollection.h>
|
#include <vtkProp3DCollection.h>
|
||||||
#include <vtkProperty.h>
|
#include <vtkProperty.h>
|
||||||
#include <vtkPolyData.h>
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkSphereSource.h>
|
||||||
#include <vtkTransform.h>
|
#include <vtkTransform.h>
|
||||||
#include <vtkTransformPolyDataFilter.h>
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
|
||||||
#include "Detectors/MuonScatter.h"
|
#include "HEP/Detectors/MuonScatter.h"
|
||||||
|
|
||||||
#include "Math/StructuredGrid.h"
|
#include "Math/StructuredGrid.h"
|
||||||
#include "Math/VoxRaytracer.h"
|
#include "Math/VoxRaytracer.h"
|
||||||
|
|
||||||
|
|
||||||
class vtkActor;
|
class vtkActor;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
@@ -63,6 +60,7 @@ namespace Vtk {
|
|||||||
|
|
||||||
class vtkVoxRaytracerRepresentation : public Puppet {
|
class vtkVoxRaytracerRepresentation : public Puppet {
|
||||||
typedef VoxRaytracer Content;
|
typedef VoxRaytracer Content;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vtkVoxRaytracerRepresentation(Content &content);
|
vtkVoxRaytracerRepresentation(Content &content);
|
||||||
~vtkVoxRaytracerRepresentation();
|
~vtkVoxRaytracerRepresentation();
|
||||||
@@ -73,10 +71,7 @@ public:
|
|||||||
|
|
||||||
vtkPolyData *GetPolyData() const;
|
vtkPolyData *GetPolyData() const;
|
||||||
|
|
||||||
enum RepresentationElements {
|
enum RepresentationElements { RayElements, VoxelsElements };
|
||||||
RayElements,
|
|
||||||
VoxelsElements
|
|
||||||
};
|
|
||||||
void SetRepresentationElements(enum RepresentationElements el);
|
void SetRepresentationElements(enum RepresentationElements el);
|
||||||
|
|
||||||
void SetMuon(MuonScatter &muon);
|
void SetMuon(MuonScatter &muon);
|
||||||
@@ -98,8 +93,6 @@ public:
|
|||||||
void SetVoxelsColor(Vector4f rgba);
|
void SetVoxelsColor(Vector4f rgba);
|
||||||
void SetRayColor(Vector4f rgba);
|
void SetRayColor(Vector4f rgba);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InstallPipe();
|
void InstallPipe();
|
||||||
|
|
||||||
@@ -124,9 +117,7 @@ private:
|
|||||||
vtkAppendPolyData *m_SelectedElement;
|
vtkAppendPolyData *m_SelectedElement;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
|
|
||||||
#endif // VTKVOXRAYTRACERREPRESENTATION_H
|
#endif // VTKVOXRAYTRACERREPRESENTATION_H
|
||||||
22
src/Vtk/Math/CMakeLists.txt
Normal file
22
src/Vtk/Math/CMakeLists.txt
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
################################################################################
|
||||||
|
##### Vtk/Math - VTK wrappers for Math module objects #########################
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
set(MATH_SOURCES
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkStructuredGrid.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkTriangleMesh.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkVoxImage.cpp
|
||||||
|
PARENT_SCOPE)
|
||||||
|
|
||||||
|
set(MATH_HEADERS
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkHLineRepresentation.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkStructuredGrid.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkTriangleMesh.h
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/vtkVoxImage.h
|
||||||
|
PARENT_SCOPE)
|
||||||
|
|
||||||
|
if(BUILD_TESTING)
|
||||||
|
include(uLibTargetMacros)
|
||||||
|
add_subdirectory(testing)
|
||||||
|
endif()
|
||||||
18
src/Vtk/Math/testing/CMakeLists.txt
Normal file
18
src/Vtk/Math/testing/CMakeLists.txt
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# TESTS
|
||||||
|
set(TESTS
|
||||||
|
vtkStructuredGridTest
|
||||||
|
vtkTriangleMeshTest
|
||||||
|
vtkVoxImageTest
|
||||||
|
)
|
||||||
|
|
||||||
|
set(LIBRARIES
|
||||||
|
${PACKAGE_LIBPREFIX}Core
|
||||||
|
${PACKAGE_LIBPREFIX}Math
|
||||||
|
${PACKAGE_LIBPREFIX}Vtk
|
||||||
|
${VTK_LIBRARIES}
|
||||||
|
Boost::unit_test_framework
|
||||||
|
)
|
||||||
|
|
||||||
|
uLib_add_tests(VtkMath)
|
||||||
|
|
||||||
|
configure_file(capelluzzo.stl ${CMAKE_CURRENT_BINARY_DIR}/capelluzzo.stl COPYONLY)
|
||||||
BIN
src/Vtk/Math/testing/capelluzzo.stl
Normal file
BIN
src/Vtk/Math/testing/capelluzzo.stl
Normal file
Binary file not shown.
@@ -23,29 +23,26 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include "Vtk/Math/vtkStructuredGrid.h"
|
||||||
|
|
||||||
|
|
||||||
#include "Math/StructuredGrid.h"
|
#include "Math/StructuredGrid.h"
|
||||||
|
|
||||||
#include "Vtk/vtkStructuredGrid.h"
|
|
||||||
#include "Vtk/uLibVtkViewer.h"
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
#include "testing-prototype.h"
|
#define BOOST_TEST_MODULE VtkStructuredGridTest
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace uLib;
|
using namespace uLib;
|
||||||
|
|
||||||
int main()
|
BOOST_AUTO_TEST_CASE(vtkStructuredGridTest) {
|
||||||
{
|
StructuredGrid grid(Vector3i(10, 10, 100));
|
||||||
|
grid.SetSpacing(Vector3f(3, 1, 1));
|
||||||
StructuredGrid grid(Vector3i(10,10,100));
|
|
||||||
grid.SetSpacing(Vector3f(3,1,1));
|
|
||||||
|
|
||||||
Vtk::vtkStructuredGrid grid_viewer(grid);
|
Vtk::vtkStructuredGrid grid_viewer(grid);
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
Vtk::Viewer viewer;
|
Vtk::Viewer viewer;
|
||||||
viewer.AddPuppet(grid_viewer);
|
viewer.AddPuppet(grid_viewer);
|
||||||
viewer.Start();
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
BOOST_CHECK(grid_viewer.GetWidget() != nullptr);
|
||||||
}
|
}
|
||||||
@@ -23,64 +23,49 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include "Vtk/Math/vtkTriangleMesh.h"
|
||||||
|
|
||||||
#ifndef SOLID_H
|
|
||||||
#define SOLID_H
|
|
||||||
|
|
||||||
#include "Core/Object.h"
|
|
||||||
#include "Math/Dense.h"
|
|
||||||
#include "Math/TriangleMesh.h"
|
#include "Math/TriangleMesh.h"
|
||||||
#include "Detectors/Matter.h"
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
class G4Material;
|
#define BOOST_TEST_MODULE VtkTriangleMeshTest
|
||||||
class G4LogicalVolume;
|
#include <boost/test/unit_test.hpp>
|
||||||
class G4TessellatedSolid;
|
|
||||||
|
|
||||||
|
using namespace uLib;
|
||||||
|
|
||||||
namespace uLib {
|
BOOST_AUTO_TEST_CASE(vtkTriangleMeshConstruction) {
|
||||||
|
TriangleMesh mesh;
|
||||||
class Solid : public Object {
|
|
||||||
public:
|
|
||||||
|
|
||||||
Solid();
|
|
||||||
Solid(const char *name);
|
|
||||||
|
|
||||||
void SetNistMaterial(const char *name);
|
|
||||||
|
|
||||||
void SetMaterial(G4Material *material);
|
|
||||||
|
|
||||||
uLibGetMacro(Material,G4Material *)
|
|
||||||
uLibGetMacro(Logical,G4LogicalVolume *)
|
|
||||||
|
|
||||||
protected:
|
|
||||||
G4Material *m_Material;
|
|
||||||
G4LogicalVolume *m_Logical;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class TessellatedSolid : public Solid {
|
|
||||||
typedef Solid BaseClass;
|
|
||||||
|
|
||||||
public:
|
|
||||||
TessellatedSolid(const char *name);
|
|
||||||
|
|
||||||
void SetMesh(TriangleMesh &mesh);
|
|
||||||
|
|
||||||
uLibGetMacro(Solid,G4TessellatedSolid *)
|
|
||||||
private:
|
|
||||||
G4TessellatedSolid *m_Solid;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
mesh.AddPoint(Vector3f(0, 0, 0));
|
||||||
|
mesh.AddPoint(Vector3f(0, 1, 0));
|
||||||
|
mesh.AddPoint(Vector3f(1, 0, 0));
|
||||||
|
mesh.AddTriangle(Vector3i(0, 1, 2));
|
||||||
|
|
||||||
|
Vtk::vtkTriangleMesh v_mesh(mesh);
|
||||||
|
v_mesh.Update();
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
Vtk::Viewer viewer;
|
||||||
|
viewer.AddPuppet(v_mesh);
|
||||||
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOST_CHECK_EQUAL(mesh.Points().size(), 3u);
|
||||||
|
BOOST_CHECK_EQUAL(mesh.Triangles().size(), 1u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(vtkTriangleMeshConstruction2) {
|
||||||
|
TriangleMesh mesh;
|
||||||
|
|
||||||
|
Vtk::vtkTriangleMesh v_mesh(mesh);
|
||||||
|
v_mesh.ReadFromStlFile("capelluzzo.stl");
|
||||||
|
v_mesh.Update();
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
Vtk::Viewer viewer;
|
||||||
|
viewer.AddPuppet(v_mesh);
|
||||||
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // SOLID_H
|
BOOST_CHECK_EQUAL(mesh.Points().size(), 3u);
|
||||||
|
BOOST_CHECK_EQUAL(mesh.Triangles().size(), 1u);
|
||||||
|
}
|
||||||
@@ -23,40 +23,37 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
#include "Vtk/Math/vtkVoxImage.h"
|
||||||
|
#include "Math/VoxImage.h"
|
||||||
#include "Detectors/MuonScatter.h"
|
|
||||||
#include "Vtk/vtkMuonScatter.h"
|
|
||||||
|
|
||||||
#include "Vtk/uLibVtkViewer.h"
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
#include "testing-prototype.h"
|
#define BOOST_TEST_MODULE VtkVoxImageTest
|
||||||
|
#include <boost/test/unit_test.hpp>
|
||||||
|
|
||||||
using namespace uLib;
|
using namespace uLib;
|
||||||
|
|
||||||
int main()
|
struct TestVoxel {
|
||||||
{
|
Scalarf Value;
|
||||||
MuonScatter event;
|
unsigned int Count;
|
||||||
event.LineIn().direction << 0, -1, 1, 0;
|
};
|
||||||
event.LineIn().origin << 0, 1, -1, 1;
|
|
||||||
|
|
||||||
event.LineOut().direction << 0, -1, 0, 0;
|
BOOST_AUTO_TEST_CASE(vtkVoxImageConstruction) {
|
||||||
event.LineOut().origin << 0, -1, 0, 1;
|
TestVoxel zero = {0, 0};
|
||||||
|
TestVoxel nonzero = {5.5f * 1e-6f, 100};
|
||||||
|
|
||||||
Vtk::vtkMuonScatter v_event(event);
|
VoxImage<TestVoxel> img(Vector3i(10, 10, 10));
|
||||||
v_event.AddPocaPoint(HPoint3f(0,0,0));
|
img.SetSpacing(Vector3f(3, 3, 3));
|
||||||
|
img.InitVoxels(zero);
|
||||||
|
img[Vector3i(3, 3, 3)] = nonzero;
|
||||||
|
|
||||||
v_event.SaveToXMLFile("vtk_testing_muonevent.vtp");
|
Vtk::vtkVoxImage vtk_img(img);
|
||||||
|
vtk_img.SaveToXMLFile("test_vtkvoximage.vti");
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
Vtk::Viewer viewer;
|
Vtk::Viewer viewer;
|
||||||
|
viewer.AddPuppet(vtk_img);
|
||||||
// Vtk::Tie<Vtk::vtkMuonScatter> tms;
|
|
||||||
// tms.DoAction();
|
|
||||||
// Vtk::Tie<Vtk::Viewer> vms;
|
|
||||||
// vms.DoAction();
|
|
||||||
|
|
||||||
viewer.AddPuppet(v_event);
|
|
||||||
viewer.Start();
|
viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
BOOST_CHECK(vtk_img.GetImageData() != nullptr);
|
||||||
}
|
}
|
||||||
@@ -23,30 +23,20 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef VTKHLINEREPRESENTATION_H
|
#ifndef VTKHLINEREPRESENTATION_H
|
||||||
#define VTKHLINEREPRESENTATION_H
|
#define VTKHLINEREPRESENTATION_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class vtkProp;
|
class vtkProp;
|
||||||
class vtkPolyData;
|
class vtkPolyData;
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
|
||||||
class vtkHLineRepresentationDefault {
|
class vtkHLineRepresentationDefault {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vtkHLineRepresentationDefault();
|
vtkHLineRepresentationDefault();
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace uLib
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // VTKHLINEREPRESENTATION_H
|
#endif // VTKHLINEREPRESENTATION_H
|
||||||
114
src/Vtk/Math/vtkStructuredGrid.cpp
Normal file
114
src/Vtk/Math/vtkStructuredGrid.cpp
Normal file
@@ -0,0 +1,114 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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/StructuredGrid.h"
|
||||||
|
#include "Vtk/Math/vtkStructuredGrid.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////// VTK STRUCTURED GRID /////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
vtkStructuredGrid::vtkStructuredGrid(Content &content)
|
||||||
|
: m_Content(&content), m_Actor(vtkActor::New()),
|
||||||
|
m_Widget(vtkBoxWidget::New()), m_Transform(vtkTransform::New()) {
|
||||||
|
vtkSmartPointer<vtkWidgetCallback> callback =
|
||||||
|
vtkSmartPointer<vtkWidgetCallback>::New();
|
||||||
|
callback->SetGrid(this);
|
||||||
|
m_Widget->AddObserver(vtkCommand::InteractionEvent, callback);
|
||||||
|
|
||||||
|
this->InstallPipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkStructuredGrid::~vtkStructuredGrid() {
|
||||||
|
m_Actor->Delete();
|
||||||
|
m_Widget->Delete();
|
||||||
|
m_Transform->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkStructuredGrid::SetTransform(vtkTransform *t) {
|
||||||
|
vtkMatrix4x4 *vmat = t->GetMatrix();
|
||||||
|
Matrix4f mat;
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
mat(i, j) = vmat->GetElement(i, j);
|
||||||
|
m_Content->SetMatrix(mat);
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmat2 = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
mat = m_Content->GetWorldMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmat2->SetElement(i, j, mat(i, j));
|
||||||
|
m_Transform->SetMatrix(vmat2);
|
||||||
|
m_Transform->Update();
|
||||||
|
this->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkBoxWidget *vtkStructuredGrid::GetWidget() { return m_Widget; }
|
||||||
|
|
||||||
|
void vtkStructuredGrid::Update() { m_Actor->GetMapper()->Update(); }
|
||||||
|
|
||||||
|
void vtkStructuredGrid::InstallPipe() {
|
||||||
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||||
|
vtkSmartPointer<vtkTransformPolyDataFilter> filter =
|
||||||
|
vtkSmartPointer<vtkTransformPolyDataFilter>::New();
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f mat = m_Content->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);
|
||||||
|
filter->SetTransform(m_Transform);
|
||||||
|
filter->SetInputConnection(cube->GetOutputPort());
|
||||||
|
|
||||||
|
Vector3i dims = m_Content->GetDims();
|
||||||
|
cube->SetBounds(0, dims(0), 0, dims(1), 0, dims(2));
|
||||||
|
cube->Update();
|
||||||
|
filter->Update();
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputConnection(filter->GetOutputPort());
|
||||||
|
|
||||||
|
m_Actor->SetMapper(mapper);
|
||||||
|
m_Actor->GetProperty()->SetRepresentationToSurface();
|
||||||
|
m_Actor->GetProperty()->SetEdgeVisibility(true);
|
||||||
|
m_Actor->GetProperty()->SetOpacity(0.4);
|
||||||
|
m_Actor->GetProperty()->SetAmbient(0.7);
|
||||||
|
this->Update();
|
||||||
|
m_Widget->SetProp3D(m_Actor);
|
||||||
|
|
||||||
|
this->SetProp(m_Actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
@@ -23,64 +23,59 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef U_VTKSTRUCTUREDGRID_H
|
#ifndef U_VTKSTRUCTUREDGRID_H
|
||||||
#define U_VTKSTRUCTUREDGRID_H
|
#define U_VTKSTRUCTUREDGRID_H
|
||||||
|
|
||||||
#include <vtkLineSource.h>
|
#include <vtkActor.h>
|
||||||
#include <vtkBoundingBox.h>
|
#include <vtkBoundingBox.h>
|
||||||
#include <vtkCubeSource.h>
|
#include <vtkCubeSource.h>
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkLineSource.h>
|
||||||
#include <vtkPolyDataMapper.h>
|
#include <vtkPolyDataMapper.h>
|
||||||
#include <vtkActor.h>
|
|
||||||
#include <vtkProperty.h>
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
#include <vtkTransform.h>
|
|
||||||
#include <vtkTransformPolyDataFilter.h>
|
|
||||||
#include <vtkBoxWidget.h>
|
#include <vtkBoxWidget.h>
|
||||||
#include <vtkCommand.h>
|
#include <vtkCommand.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
#include <vtkTransformPolyDataFilter.h>
|
||||||
|
|
||||||
#include "Math/Dense.h"
|
#include "Math/Dense.h"
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
|
||||||
#include "Math/StructuredGrid.h"
|
#include "Math/StructuredGrid.h"
|
||||||
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
class vtkStructuredGrid : public Puppet {
|
class vtkStructuredGrid : public Puppet {
|
||||||
typedef StructuredGrid Content;
|
typedef StructuredGrid Content;
|
||||||
public:
|
|
||||||
|
|
||||||
|
public:
|
||||||
vtkStructuredGrid(Content &content);
|
vtkStructuredGrid(Content &content);
|
||||||
~vtkStructuredGrid();
|
~vtkStructuredGrid();
|
||||||
|
|
||||||
void SetTransform(class vtkTransform *t);
|
void SetTransform(class vtkTransform *t);
|
||||||
|
|
||||||
class vtkBoxWidget * GetWidget();
|
class vtkBoxWidget *GetWidget();
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InstallPipe();
|
void InstallPipe();
|
||||||
|
|
||||||
class vtkWidgetCallback : public vtkCommand
|
class vtkWidgetCallback : public vtkCommand {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
static vtkWidgetCallback *New() { return new vtkWidgetCallback; }
|
||||||
|
|
||||||
void SetGrid(uLib::Vtk::vtkStructuredGrid *grid) { this->grid = grid; }
|
void SetGrid(uLib::Vtk::vtkStructuredGrid *grid) { this->grid = grid; }
|
||||||
|
|
||||||
virtual void Execute(vtkObject *caller, unsigned long, void*)
|
virtual void Execute(vtkObject *caller, unsigned long, void *) {
|
||||||
{
|
|
||||||
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
|
||||||
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget*>(caller);
|
vtkBoxWidget *widget = reinterpret_cast<vtkBoxWidget *>(caller);
|
||||||
widget->GetTransform(t);
|
widget->GetTransform(t);
|
||||||
grid->SetTransform(t);
|
grid->SetTransform(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
uLib::Vtk::vtkStructuredGrid *grid;
|
uLib::Vtk::vtkStructuredGrid *grid;
|
||||||
};
|
};
|
||||||
@@ -91,9 +86,7 @@ private:
|
|||||||
vtkTransform *m_Transform;
|
vtkTransform *m_Transform;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
|
|
||||||
#endif // VTKSTRUCTUREDGRID_H
|
#endif // VTKSTRUCTUREDGRID_H
|
||||||
166
src/Vtk/Math/vtkTriangleMesh.cpp
Normal file
166
src/Vtk/Math/vtkTriangleMesh.cpp
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <vtkSmartPointer.h>
|
||||||
|
|
||||||
|
#include <vtkOBJReader.h>
|
||||||
|
#include <vtkPolyDataReader.h>
|
||||||
|
#include <vtkSTLReader.h>
|
||||||
|
#include <vtkXMLPolyDataReader.h>
|
||||||
|
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkCellArray.h>
|
||||||
|
#include <vtkPoints.h>
|
||||||
|
#include <vtkPolyData.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
|
||||||
|
#include "Vtk/Math/vtkTriangleMesh.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
void vtkTriangleMesh::vtk2uLib_update() {
|
||||||
|
vtkIdType number_of_points = m_Poly->GetNumberOfPoints();
|
||||||
|
vtkIdType number_of_triangles = m_Poly->GetNumberOfPolys();
|
||||||
|
|
||||||
|
std::cout << "//////\n"
|
||||||
|
<< "number of points = " << number_of_points << "\n"
|
||||||
|
<< "number of polys = " << number_of_triangles << "\n"
|
||||||
|
<< "//////\n";
|
||||||
|
|
||||||
|
m_content.Points().resize(number_of_points);
|
||||||
|
for (int i = 0; i < number_of_points; ++i) {
|
||||||
|
double *point = m_Poly->GetPoint(i);
|
||||||
|
m_content.Points()[i](0) = point[0];
|
||||||
|
m_content.Points()[i](1) = point[1];
|
||||||
|
m_content.Points()[i](2) = point[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
m_content.Triangles().resize(number_of_triangles);
|
||||||
|
m_Poly->GetPolys()->InitTraversal();
|
||||||
|
vtkSmartPointer<vtkIdList> idList = vtkSmartPointer<vtkIdList>::New();
|
||||||
|
for (int i = 0; i < number_of_triangles; ++i) {
|
||||||
|
m_Poly->GetPolys()->GetNextCell(idList);
|
||||||
|
m_content.Triangles()[i](0) = idList->GetId(0);
|
||||||
|
m_content.Triangles()[i](1) = idList->GetId(1);
|
||||||
|
m_content.Triangles()[i](2) = idList->GetId(2);
|
||||||
|
}
|
||||||
|
m_Poly->Modified();
|
||||||
|
m_Actor->GetMapper()->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkTriangleMesh::uLib2vtk_update() {
|
||||||
|
vtkIdType number_of_points = m_content.Points().size();
|
||||||
|
vtkIdType number_of_triangles = m_content.Triangles().size();
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
||||||
|
points->SetNumberOfPoints(number_of_points);
|
||||||
|
for (vtkIdType i = 0; i < number_of_points; i++) {
|
||||||
|
double x, y, z;
|
||||||
|
x = m_content.Points().at(i)(0);
|
||||||
|
y = m_content.Points().at(i)(1);
|
||||||
|
z = m_content.Points().at(i)(2);
|
||||||
|
points->SetPoint(i, x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkCellArray> polys = vtkSmartPointer<vtkCellArray>::New();
|
||||||
|
for (vtkIdType i = 0; i < number_of_triangles; i++) {
|
||||||
|
vtkIdType a, b, c;
|
||||||
|
a = m_content.Triangles().at(i)(0);
|
||||||
|
b = m_content.Triangles().at(i)(1);
|
||||||
|
c = m_content.Triangles().at(i)(2);
|
||||||
|
polys->InsertNextCell(3);
|
||||||
|
polys->InsertCellPoint(a);
|
||||||
|
polys->InsertCellPoint(b);
|
||||||
|
polys->InsertCellPoint(c);
|
||||||
|
}
|
||||||
|
|
||||||
|
m_Poly->SetPoints(points);
|
||||||
|
m_Poly->SetPolys(polys);
|
||||||
|
m_Poly->Modified();
|
||||||
|
m_Actor->GetMapper()->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------- //
|
||||||
|
|
||||||
|
vtkTriangleMesh::vtkTriangleMesh(vtkTriangleMesh::Content &content)
|
||||||
|
: m_content(content), m_Poly(vtkPolyData::New()), m_Actor(vtkActor::New()) {
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
mapper->SetInputData(m_Poly);
|
||||||
|
m_Actor->SetMapper(mapper);
|
||||||
|
this->SetProp(m_Actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkTriangleMesh::~vtkTriangleMesh() {
|
||||||
|
m_Poly->Delete();
|
||||||
|
m_Actor->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkTriangleMesh::ReadFromFile(const char *filename) {
|
||||||
|
vtkSmartPointer<vtkPolyDataReader> reader =
|
||||||
|
vtkSmartPointer<vtkPolyDataReader>::New();
|
||||||
|
reader->SetFileName(filename);
|
||||||
|
reader->Update();
|
||||||
|
m_Poly->DeepCopy(reader->GetOutput());
|
||||||
|
vtk2uLib_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkTriangleMesh::ReadFromXMLFile(const char *filename) {
|
||||||
|
vtkSmartPointer<vtkXMLPolyDataReader> reader =
|
||||||
|
vtkSmartPointer<vtkXMLPolyDataReader>::New();
|
||||||
|
reader->SetFileName(filename);
|
||||||
|
reader->Update();
|
||||||
|
m_Poly->DeepCopy(reader->GetOutput());
|
||||||
|
vtk2uLib_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkTriangleMesh::ReadFromObjFile(const char *filename) {
|
||||||
|
vtkSmartPointer<vtkOBJReader> reader = vtkSmartPointer<vtkOBJReader>::New();
|
||||||
|
reader->SetFileName(filename);
|
||||||
|
reader->Update();
|
||||||
|
m_Poly->DeepCopy(reader->GetOutput());
|
||||||
|
vtk2uLib_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkTriangleMesh::ReadFromStlFile(const char *filename) {
|
||||||
|
vtkSmartPointer<vtkSTLReader> reader = vtkSmartPointer<vtkSTLReader>::New();
|
||||||
|
reader->SetFileName(filename);
|
||||||
|
reader->Update();
|
||||||
|
m_Poly->DeepCopy(reader->GetOutput());
|
||||||
|
vtk2uLib_update();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkPolyData *vtkTriangleMesh::GetPolyData() const { return m_Poly; }
|
||||||
|
|
||||||
|
void vtkTriangleMesh::Update() { uLib2vtk_update(); }
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
@@ -23,22 +23,21 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef VTKTRIANGLEMESH_H
|
#ifndef VTKTRIANGLEMESH_H
|
||||||
#define VTKTRIANGLEMESH_H
|
#define VTKTRIANGLEMESH_H
|
||||||
|
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
|
||||||
#include "Math/TriangleMesh.h"
|
#include "Math/TriangleMesh.h"
|
||||||
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
|
||||||
class vtkPolyData;
|
class vtkPolyData;
|
||||||
|
class vtkActor;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
class vtkTriangleMesh : public Puppet, public Polydata {
|
||||||
class vtkTriangleMesh : public Abstract::uLibVtkPolydata {
|
|
||||||
typedef TriangleMesh Content;
|
typedef TriangleMesh Content;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
vtkTriangleMesh(Content &content);
|
vtkTriangleMesh(Content &content);
|
||||||
~vtkTriangleMesh();
|
~vtkTriangleMesh();
|
||||||
@@ -51,8 +50,6 @@ public:
|
|||||||
|
|
||||||
void ReadFromStlFile(const char *filename);
|
void ReadFromStlFile(const char *filename);
|
||||||
|
|
||||||
virtual class vtkProp *GetProp();
|
|
||||||
|
|
||||||
virtual class vtkPolyData *GetPolyData() const;
|
virtual class vtkPolyData *GetPolyData() const;
|
||||||
|
|
||||||
void Update();
|
void Update();
|
||||||
@@ -66,8 +63,7 @@ private:
|
|||||||
vtkActor *m_Actor;
|
vtkActor *m_Actor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
}
|
|
||||||
|
|
||||||
#endif // VTKTRIANGLEMESH_H
|
#endif // VTKTRIANGLEMESH_H
|
||||||
286
src/Vtk/Math/vtkVoxImage.cpp
Normal file
286
src/Vtk/Math/vtkVoxImage.cpp
Normal file
@@ -0,0 +1,286 @@
|
|||||||
|
/*//////////////////////////////////////////////////////////////////////////////
|
||||||
|
// 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 <vtkImageExport.h>
|
||||||
|
#include <vtkImageImport.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
|
#include <vtkFloatArray.h>
|
||||||
|
#include <vtkPointData.h>
|
||||||
|
|
||||||
|
#include <vtkGenericDataObjectReader.h>
|
||||||
|
#include <vtkImageShiftScale.h>
|
||||||
|
|
||||||
|
#include <vtkColorTransferFunction.h>
|
||||||
|
#include <vtkPiecewiseFunction.h>
|
||||||
|
#include <vtkSmartVolumeMapper.h>
|
||||||
|
#include <vtkVolumeProperty.h>
|
||||||
|
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
|
||||||
|
#include <Math/VoxImage.h>
|
||||||
|
|
||||||
|
#include "Vtk/Math/vtkVoxImage.h"
|
||||||
|
|
||||||
|
namespace uLib {
|
||||||
|
namespace Vtk {
|
||||||
|
|
||||||
|
void vtkVoxImage::GetContent() {
|
||||||
|
const int *dims = static_cast<const int *>(m_Content.GetDims().data());
|
||||||
|
m_Image->SetDimensions(dims);
|
||||||
|
|
||||||
|
float *spacing = m_Content.GetSpacing().data();
|
||||||
|
m_Image->SetSpacing(spacing[0], spacing[1], spacing[2]);
|
||||||
|
|
||||||
|
float *pos = m_Content.GetPosition().data();
|
||||||
|
m_Image->SetOrigin(pos[0], pos[1], pos[2]);
|
||||||
|
|
||||||
|
vtkFloatArray *array =
|
||||||
|
vtkFloatArray::SafeDownCast(m_Image->GetPointData()->GetScalars());
|
||||||
|
array->SetNumberOfTuples(m_Content.GetDims().prod());
|
||||||
|
Vector3i index(0, 0, 0);
|
||||||
|
int i = 0;
|
||||||
|
for (int zv = 0; zv < dims[2]; ++zv) {
|
||||||
|
for (int yv = 0; yv < dims[1]; ++yv) {
|
||||||
|
for (int xv = 0; xv < dims[0]; ++xv) {
|
||||||
|
index << xv, yv, zv;
|
||||||
|
array->SetValue(i++, m_Content.GetValue(index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m_Image->GetPointData()->SetScalars(array);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::SetContent() {
|
||||||
|
int *ext = m_Image->GetExtent();
|
||||||
|
int dims[3] = {ext[1] - ext[0] + 1, ext[3] - ext[2] + 1, ext[5] - ext[4] + 1};
|
||||||
|
m_Content.SetDims(Vector3i(dims[0], dims[1], dims[2]));
|
||||||
|
|
||||||
|
double *spacing = m_Image->GetSpacing();
|
||||||
|
m_Content.SetSpacing(Vector3f(spacing[0], spacing[1], spacing[2]));
|
||||||
|
|
||||||
|
double *pos = m_Image->GetOrigin();
|
||||||
|
m_Content.SetPosition(Vector3f(pos[0], pos[1], pos[2]));
|
||||||
|
|
||||||
|
vtkFloatArray *array =
|
||||||
|
vtkFloatArray::SafeDownCast(m_Image->GetPointData()->GetScalars());
|
||||||
|
if (array) {
|
||||||
|
Vector3i index(0, 0, 0);
|
||||||
|
int i = 0;
|
||||||
|
for (int zv = 0; zv < dims[2]; ++zv) {
|
||||||
|
for (int yv = 0; yv < dims[1]; ++yv) {
|
||||||
|
for (int xv = 0; xv < dims[0]; ++xv) {
|
||||||
|
index << xv, yv, zv;
|
||||||
|
m_Content.SetValue(index, array->GetValue(i++));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error reading array Value Data\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// VTK VOXIMAGE
|
||||||
|
|
||||||
|
vtkVoxImage::vtkVoxImage(Content &content)
|
||||||
|
: m_Content(content), m_Actor(vtkVolume::New()),
|
||||||
|
m_Image(vtkImageData::New()), m_Outline(vtkCubeSource::New()),
|
||||||
|
m_Reader(NULL), m_Writer(NULL), writer_factor(1.E6) {
|
||||||
|
GetContent();
|
||||||
|
InstallPipe();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkVoxImage::~vtkVoxImage() {
|
||||||
|
m_Image->Delete();
|
||||||
|
m_Actor->Delete();
|
||||||
|
m_Outline->Delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkImageData *vtkVoxImage::GetImageData() {
|
||||||
|
GetContent();
|
||||||
|
return m_Image;
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::SaveToXMLFile(const char *fname) {
|
||||||
|
vtkSmartPointer<vtkXMLImageDataWriter> writer =
|
||||||
|
vtkSmartPointer<vtkXMLImageDataWriter>::New();
|
||||||
|
writer->SetFileName(fname);
|
||||||
|
GetContent();
|
||||||
|
vtkSmartPointer<vtkImageShiftScale> vtkscale =
|
||||||
|
vtkSmartPointer<vtkImageShiftScale>::New();
|
||||||
|
|
||||||
|
#if VTK_MAJOR_VERSION <= 5
|
||||||
|
vtkscale->SetInputConnection(m_Image->GetProducerPort());
|
||||||
|
#else
|
||||||
|
vtkscale->SetInputData(m_Image);
|
||||||
|
#endif
|
||||||
|
vtkscale->SetScale(writer_factor);
|
||||||
|
vtkscale->Update();
|
||||||
|
writer->SetInputConnection(vtkscale->GetOutputPort());
|
||||||
|
writer->Update();
|
||||||
|
writer->Write();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::ReadFromVKTFile(const char *fname) {
|
||||||
|
vtkSmartPointer<vtkGenericDataObjectReader> reader =
|
||||||
|
vtkSmartPointer<vtkGenericDataObjectReader>::New();
|
||||||
|
reader->SetFileName(fname);
|
||||||
|
reader->Update();
|
||||||
|
if (reader->IsFileStructuredPoints()) {
|
||||||
|
vtkSmartPointer<vtkImageShiftScale> vtkscale =
|
||||||
|
vtkSmartPointer<vtkImageShiftScale>::New();
|
||||||
|
vtkscale->SetInputConnection(reader->GetOutputPort());
|
||||||
|
vtkscale->SetScale(1 / writer_factor);
|
||||||
|
vtkscale->Update();
|
||||||
|
|
||||||
|
m_Image->DeepCopy(vtkscale->GetOutput());
|
||||||
|
SetContent();
|
||||||
|
} else {
|
||||||
|
std::cerr << "Error: file does not contain structured points\n";
|
||||||
|
}
|
||||||
|
m_Actor->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::ReadFromXMLFile(const char *fname) {
|
||||||
|
vtkSmartPointer<vtkXMLImageDataReader> reader =
|
||||||
|
vtkSmartPointer<vtkXMLImageDataReader>::New();
|
||||||
|
reader->SetFileName(fname);
|
||||||
|
reader->Update();
|
||||||
|
vtkSmartPointer<vtkImageShiftScale> vtkscale =
|
||||||
|
vtkSmartPointer<vtkImageShiftScale>::New();
|
||||||
|
vtkscale->SetInputConnection(reader->GetOutputPort());
|
||||||
|
vtkscale->SetScale(1 / writer_factor);
|
||||||
|
vtkscale->Update();
|
||||||
|
|
||||||
|
m_Image->DeepCopy(vtkscale->GetOutput());
|
||||||
|
SetContent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::setShadingPreset(int blendType) {
|
||||||
|
vtkSmartVolumeMapper *mapper = (vtkSmartVolumeMapper *)m_Actor->GetMapper();
|
||||||
|
vtkVolumeProperty *property = m_Actor->GetProperty();
|
||||||
|
|
||||||
|
static vtkColorTransferFunction *colorFun = vtkColorTransferFunction::New();
|
||||||
|
static vtkPiecewiseFunction *opacityFun = vtkPiecewiseFunction::New();
|
||||||
|
|
||||||
|
float window = 40 / writer_factor;
|
||||||
|
float level = 20 / writer_factor;
|
||||||
|
|
||||||
|
property->SetColor(colorFun);
|
||||||
|
property->SetScalarOpacity(opacityFun);
|
||||||
|
property->SetInterpolationTypeToLinear();
|
||||||
|
|
||||||
|
if (blendType != 6) {
|
||||||
|
colorFun->RemoveAllPoints();
|
||||||
|
opacityFun->RemoveAllPoints();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (blendType) {
|
||||||
|
case 0:
|
||||||
|
colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0);
|
||||||
|
opacityFun->AddSegment(level - 0.5 * window, 0.0, level + 0.5 * window,
|
||||||
|
1.0);
|
||||||
|
mapper->SetBlendModeToMaximumIntensity();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
colorFun->AddRGBSegment(level - 0.5 * window, 0.0, 0.0, 0.0,
|
||||||
|
level + 0.5 * window, 1.0, 1.0, 1.0);
|
||||||
|
opacityFun->AddSegment(level - 0.5 * window, 0.0, level + 0.5 * window,
|
||||||
|
1.0);
|
||||||
|
mapper->SetBlendModeToComposite();
|
||||||
|
property->ShadeOff();
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
colorFun->AddRGBSegment(0.0, 1.0, 1.0, 1.0, 255.0, 1.0, 1.0, 1.0);
|
||||||
|
opacityFun->AddSegment(level - 0.5 * window, 0.0, level + 0.5 * window,
|
||||||
|
1.0);
|
||||||
|
mapper->SetBlendModeToComposite();
|
||||||
|
property->ShadeOn();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
colorFun->AddRGBPoint(-3024, 0, 0, 0, 0.5, 0.0);
|
||||||
|
colorFun->AddRGBPoint(-1000, .62, .36, .18, 0.5, 0.0);
|
||||||
|
colorFun->AddRGBPoint(-500, .88, .60, .29, 0.33, 0.45);
|
||||||
|
colorFun->AddRGBPoint(3071, .83, .66, 1, 0.5, 0.0);
|
||||||
|
opacityFun->AddPoint(-3024, 0, 0.5, 0.0);
|
||||||
|
opacityFun->AddPoint(-1000, 0, 0.5, 0.0);
|
||||||
|
opacityFun->AddPoint(-500, 1.0, 0.33, 0.45);
|
||||||
|
opacityFun->AddPoint(3071, 1.0, 0.5, 0.0);
|
||||||
|
mapper->SetBlendModeToComposite();
|
||||||
|
property->ShadeOn();
|
||||||
|
property->SetAmbient(0.1);
|
||||||
|
property->SetDiffuse(0.9);
|
||||||
|
property->SetSpecular(0.2);
|
||||||
|
property->SetSpecularPower(10.0);
|
||||||
|
property->SetScalarOpacityUnitDistance(0.8919);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
vtkGenericWarningMacro("Unknown blend type.");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::Update() {
|
||||||
|
m_Actor->Update();
|
||||||
|
m_Outline->SetBounds(m_Image->GetBounds());
|
||||||
|
m_Outline->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
void vtkVoxImage::InstallPipe() {
|
||||||
|
vtkSmartPointer<vtkSmartVolumeMapper> mapper =
|
||||||
|
vtkSmartPointer<vtkSmartVolumeMapper>::New();
|
||||||
|
#if VTK_MAJOR_VERSION <= 5
|
||||||
|
mapper->SetInputConnection(m_Image->GetProducerPort());
|
||||||
|
#else
|
||||||
|
mapper->SetInputData(m_Image);
|
||||||
|
#endif
|
||||||
|
mapper->Update();
|
||||||
|
|
||||||
|
m_Actor->SetMapper(mapper);
|
||||||
|
this->setShadingPreset(0);
|
||||||
|
mapper->Update();
|
||||||
|
|
||||||
|
m_Outline->SetBounds(m_Image->GetBounds());
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper> mmapper =
|
||||||
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
mmapper->SetInputConnection(m_Outline->GetOutputPort());
|
||||||
|
vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
|
||||||
|
actor->SetMapper(mmapper);
|
||||||
|
actor->GetProperty()->SetRepresentationToWireframe();
|
||||||
|
actor->GetProperty()->SetAmbient(0.7);
|
||||||
|
|
||||||
|
this->SetProp(m_Actor);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
@@ -23,29 +23,25 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef U_VTKVOXIMAGE_H
|
#ifndef U_VTKVOXIMAGE_H
|
||||||
#define U_VTKVOXIMAGE_H
|
#define U_VTKVOXIMAGE_H
|
||||||
|
|
||||||
#include <vtkVolume.h>
|
#include <vtkCubeSource.h>
|
||||||
#include <vtkImageData.h>
|
#include <vtkImageData.h>
|
||||||
|
#include <vtkVolume.h>
|
||||||
#include <vtkXMLImageDataReader.h>
|
#include <vtkXMLImageDataReader.h>
|
||||||
#include <vtkXMLImageDataWriter.h>
|
#include <vtkXMLImageDataWriter.h>
|
||||||
#include <vtkCubeSource.h>
|
|
||||||
|
|
||||||
#include <Math/VoxImage.h>
|
#include <Math/VoxImage.h>
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "Vtk/uLibVtkInterface.h"
|
||||||
|
|
||||||
|
|
||||||
class vtkImageData;
|
class vtkImageData;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
class vtkVoxImage : public Puppet
|
class vtkVoxImage : public Puppet {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
typedef Abstract::VoxImage Content;
|
typedef Abstract::VoxImage Content;
|
||||||
|
|
||||||
@@ -57,7 +53,7 @@ public:
|
|||||||
|
|
||||||
void SetContent();
|
void SetContent();
|
||||||
|
|
||||||
vtkImageData * GetImageData();
|
vtkImageData *GetImageData();
|
||||||
|
|
||||||
void SaveToXMLFile(const char *fname);
|
void SaveToXMLFile(const char *fname);
|
||||||
|
|
||||||
@@ -85,11 +81,9 @@ private:
|
|||||||
|
|
||||||
float m_Window;
|
float m_Window;
|
||||||
float m_Level;
|
float m_Level;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // vtk
|
} // namespace Vtk
|
||||||
} // uLib
|
} // namespace uLib
|
||||||
|
|
||||||
|
|
||||||
#endif // VTKVOXIMAGE_H
|
#endif // VTKVOXIMAGE_H
|
||||||
@@ -1,93 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
#if VTK_5_x
|
|
||||||
_VTK_LIBS = -lQVTK \
|
|
||||||
-lLSDyna \
|
|
||||||
-lMapReduceMPI \
|
|
||||||
-lmpistubs \
|
|
||||||
-lvtkalglib \
|
|
||||||
-lvtkCharts \
|
|
||||||
-lvtkCommon \
|
|
||||||
-lvtkDICOMParser \
|
|
||||||
-lvtkexoIIc \
|
|
||||||
-lvtkFiltering \
|
|
||||||
-lvtkftgl \
|
|
||||||
-lvtkGenericFiltering \
|
|
||||||
-lvtkGraphics \
|
|
||||||
-lvtkHybrid \
|
|
||||||
-lvtkImaging \
|
|
||||||
-lvtkInfovis \
|
|
||||||
-lvtkmetaio \
|
|
||||||
-lvtkNetCDF_cxx \
|
|
||||||
-lvtkNetCDF \
|
|
||||||
-lvtkproj4 \
|
|
||||||
-lvtkRendering \
|
|
||||||
-lvtksqlite \
|
|
||||||
-lvtksys \
|
|
||||||
-lvtkverdict \
|
|
||||||
-lvtkViews \
|
|
||||||
-lvtkVolumeRendering \
|
|
||||||
-lvtkWidgets
|
|
||||||
|
|
||||||
AM_CFLAGS += $(VTK_CFLAGS)
|
|
||||||
AM_CXXFLAGS += $(VTK_CXXFLAGS)
|
|
||||||
AM_LDFLAGS += $(VTK_LDFLAGS) $(_VTK_LIBS)
|
|
||||||
|
|
||||||
#else
|
|
||||||
#_VTK_LIBS = \
|
|
||||||
# -lvtkRenderingOpenGL-6.0 \
|
|
||||||
# -lvtkImagingHybrid-6.0 \
|
|
||||||
# -lvtkIOImage-6.0 \
|
|
||||||
# -lvtkCommonDataModel-6.0 \
|
|
||||||
# -lvtkCommonMath-6.0 \
|
|
||||||
# -lvtkCommonCore-6.0 \
|
|
||||||
# -lvtksys-6.0 \
|
|
||||||
# -lvtkCommonMisc-6.0 \
|
|
||||||
# -lvtkCommonSystem-6.0 \
|
|
||||||
# -lvtkCommonTransforms-6.0 \
|
|
||||||
# -lvtkCommonExecutionModel-6.0 \
|
|
||||||
# -lvtkDICOMParser-6.0 \
|
|
||||||
# -lvtkIOCore-6.0 \
|
|
||||||
# -lvtkzlib-6.0 \
|
|
||||||
# -lvtkmetaio-6.0 \
|
|
||||||
# -lvtkjpeg-6.0 \
|
|
||||||
# -lvtkpng-6.0 \
|
|
||||||
# -lvtktiff-6.0 \
|
|
||||||
# -lvtkImagingCore-6.0 \
|
|
||||||
# -lvtkRenderingCore-6.0 \
|
|
||||||
# -lvtkFiltersExtraction-6.0 \
|
|
||||||
# -lvtkFiltersCore-6.0 \
|
|
||||||
# -lvtkFiltersGeneral-6.0 \
|
|
||||||
# -lvtkCommonComputationalGeometry-6.0 \
|
|
||||||
# -lvtkFiltersStatistics-6.0 \
|
|
||||||
# -lvtkImagingFourier-6.0 \
|
|
||||||
# -lvtkalglib-6.0 \
|
|
||||||
# -lvtkFiltersGeometry-6.0 \
|
|
||||||
# -lvtkFiltersSources-6.0 \
|
|
||||||
# -lvtkIOXMLParser-6.0 \
|
|
||||||
# -lvtkexpat-6.0 \
|
|
||||||
# -lvtkRenderingAnnotation-6.0 \
|
|
||||||
# -lvtkImagingColor-6.0 \
|
|
||||||
# -lvtkRenderingFreeType-6.0 \
|
|
||||||
# -lvtkfreetype-6.0 \
|
|
||||||
# -lvtkftgl-6.0 \
|
|
||||||
# -lvtkInteractionStyle-6.0 \
|
|
||||||
# -lvtkRenderingVolumeOpenGL-6.0 \
|
|
||||||
# -lvtkRenderingVolume-6.0 \
|
|
||||||
# -lvtkIOXML-6.0 \
|
|
||||||
# -lvtkIOGeometry-6.0 \
|
|
||||||
# -lvtkjsoncpp-6.0 \
|
|
||||||
# -lvtkInteractionWidgets-6.0 \
|
|
||||||
# -lvtkFiltersHybrid-6.0 \
|
|
||||||
# -lvtkImagingSources-6.0 \
|
|
||||||
# -lvtkFiltersModeling-6.0 \
|
|
||||||
# -lvtkImagingGeneral-6.0 \
|
|
||||||
# -lvtkIOLegacy-6.0 \
|
|
||||||
# -lvtkRenderingFreeTypeOpenGL-6.0
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#AM_CFLAGS += $(VTK_CFLAGS)
|
|
||||||
#AM_CXXFLAGS += $(VTK_CXXFLAGS) -rdynamic
|
|
||||||
#AM_LDFLAGS += $(VTK_LDFLAGS) $(_VTK_LIBS) -lGLU -lSM -lICE -lX11 -lXext -lSM -lICE -lX11 -lXext -lXt -lm -ldl -lGL
|
|
||||||
#endif
|
|
||||||
@@ -2,9 +2,6 @@
|
|||||||
set( TESTS
|
set( TESTS
|
||||||
vtkViewerTest
|
vtkViewerTest
|
||||||
vtkContainerBoxTest
|
vtkContainerBoxTest
|
||||||
vtkMuonScatter
|
|
||||||
vtkStructuredGridTest
|
|
||||||
vtkVoxRaytracerTest
|
|
||||||
# vtkVoxImageTest
|
# vtkVoxImageTest
|
||||||
# vtkTriangleMeshTest
|
# vtkTriangleMeshTest
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -23,8 +23,6 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include "Vtk/uLibVtkViewer.h"
|
#include "Vtk/uLibVtkViewer.h"
|
||||||
|
|
||||||
#include "Math/ContainerBox.h"
|
#include "Math/ContainerBox.h"
|
||||||
@@ -37,17 +35,16 @@ using namespace uLib;
|
|||||||
int main() {
|
int main() {
|
||||||
BEGIN_TESTING(vtk ContainerBox Test);
|
BEGIN_TESTING(vtk ContainerBox Test);
|
||||||
|
|
||||||
Vtk::Viewer v_viewer;
|
|
||||||
|
|
||||||
ContainerBox box;
|
ContainerBox box;
|
||||||
box.SetSize(Vector3f(2,3,4));
|
box.SetSize(Vector3f(2, 3, 4));
|
||||||
box.SetPosition(Vector3f(1,2,3));
|
box.SetPosition(Vector3f(1, 2, 3));
|
||||||
|
Vtk::vtkContainerBox v_box(&box);
|
||||||
Vtk::vtkContainerBox v_box(box);
|
|
||||||
|
|
||||||
|
if (std::getenv("CTEST_PROJECT_NAME") == nullptr) {
|
||||||
|
Vtk::Viewer v_viewer;
|
||||||
v_viewer.AddPuppet(v_box);
|
v_viewer.AddPuppet(v_box);
|
||||||
v_viewer.Start();
|
v_viewer.Start();
|
||||||
|
}
|
||||||
|
|
||||||
END_TESTING;
|
END_TESTING;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,102 +0,0 @@
|
|||||||
/*//////////////////////////////////////////////////////////////////////////////
|
|
||||||
// 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 "Math/VoxImage.h"
|
|
||||||
#include "Vtk/vtkVoxImage.h"
|
|
||||||
#include "Vtk/uLibVtkViewer.h"
|
|
||||||
|
|
||||||
#include "testing-prototype.h"
|
|
||||||
|
|
||||||
using namespace uLib;
|
|
||||||
|
|
||||||
struct TestVoxel {
|
|
||||||
Scalarf Value;
|
|
||||||
unsigned int Count;
|
|
||||||
};
|
|
||||||
|
|
||||||
int main()
|
|
||||||
{
|
|
||||||
BEGIN_TESTING(Vtk Vox Image);
|
|
||||||
|
|
||||||
TestVoxel zero = {0,0};
|
|
||||||
TestVoxel nonzero = {5.5*1E-6,100};
|
|
||||||
|
|
||||||
// { // SIMPLE TESTS //
|
|
||||||
// VoxImage<TestVoxel> img(Vector3i(10,10,10));
|
|
||||||
// img.SetSpacing(Vector3f(3,3,3));
|
|
||||||
|
|
||||||
// img.InitVoxels(zero);
|
|
||||||
// img[Vector3i(3,3,3)] = nonzero;
|
|
||||||
|
|
||||||
// Vtk::vtkVoxImage vtk_img(img);
|
|
||||||
|
|
||||||
// vtk_img.SaveToXMLFile("test.vti");
|
|
||||||
// vtk_img.setShadingPreset(0);
|
|
||||||
|
|
||||||
// // vtk_img.ReadFromVKTFile("error.vtk");
|
|
||||||
|
|
||||||
// // VoxImage<TestVoxel> img2 = img;
|
|
||||||
|
|
||||||
// // Vtk::vtkVoxImage vtk_img2(img2);
|
|
||||||
|
|
||||||
// // img2.ExportToVtk("error_saved.vtk",0);
|
|
||||||
|
|
||||||
// // vtk_img2.SaveToXMLFile("error_saved.vti");
|
|
||||||
|
|
||||||
// Vtk::Viewer viewer;
|
|
||||||
// viewer.AddPuppet(vtk_img);
|
|
||||||
// viewer.Start();
|
|
||||||
// }
|
|
||||||
|
|
||||||
{ // SIMPLE TESTS //
|
|
||||||
VoxImage<TestVoxel> img(Vector3i(10,10,1));
|
|
||||||
img.SetSpacing(Vector3f(3,3,3));
|
|
||||||
|
|
||||||
img.InitVoxels(zero);
|
|
||||||
img[Vector3i(3,3,0)] = nonzero;
|
|
||||||
|
|
||||||
Vtk::vtkVoxImage vtk_img(img);
|
|
||||||
|
|
||||||
vtk_img.ReadFromVKTFile("test.vtk");
|
|
||||||
vtk_img.Update();
|
|
||||||
|
|
||||||
// vtk_img.SaveToXMLFile("test.vti");
|
|
||||||
// vtk_img.setShadingPreset(0);
|
|
||||||
|
|
||||||
// Vtk::vtkVoxImage vtk_img2(img2);
|
|
||||||
// img2.ExportToVtk("error_saved.vtk",0);
|
|
||||||
// vtk_img2.SaveToXMLFile("error_saved.vti");
|
|
||||||
|
|
||||||
Vtk::Viewer viewer;
|
|
||||||
viewer.AddPuppet(vtk_img);
|
|
||||||
viewer.Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
END_TESTING;
|
|
||||||
}
|
|
||||||
@@ -23,17 +23,11 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ULIBVTKINTERFACE_H
|
#ifndef ULIBVTKINTERFACE_H
|
||||||
#define ULIBVTKINTERFACE_H
|
#define ULIBVTKINTERFACE_H
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#include <ostream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <ostream>
|
||||||
|
|
||||||
|
|
||||||
// vtk classes forward declaration //
|
// vtk classes forward declaration //
|
||||||
class vtkProp;
|
class vtkProp;
|
||||||
@@ -42,19 +36,17 @@ class vtkPropCollection;
|
|||||||
class vtkRenderer;
|
class vtkRenderer;
|
||||||
class vtkRendererCollection;
|
class vtkRendererCollection;
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
class Puppet
|
class Puppet {
|
||||||
{
|
|
||||||
public:
|
public:
|
||||||
Puppet();
|
Puppet();
|
||||||
~Puppet();
|
~Puppet();
|
||||||
|
|
||||||
virtual vtkProp * GetProp();
|
virtual vtkProp *GetProp();
|
||||||
|
|
||||||
virtual vtkPropCollection * GetProps();
|
virtual vtkPropCollection *GetProps();
|
||||||
|
|
||||||
void ConnectRenderer(vtkRenderer *renderer);
|
void ConnectRenderer(vtkRenderer *renderer);
|
||||||
|
|
||||||
@@ -64,15 +56,15 @@ public:
|
|||||||
|
|
||||||
void DisonnectViewer(class Viewer *viewer);
|
void DisonnectViewer(class Viewer *viewer);
|
||||||
|
|
||||||
vtkRendererCollection * GetRenderers() const;
|
vtkRendererCollection *GetRenderers() const;
|
||||||
|
|
||||||
|
|
||||||
virtual void PrintSelf(std::ostream &o) const;
|
virtual void PrintSelf(std::ostream &o) const;
|
||||||
|
|
||||||
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor) { (void)interactor; }
|
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor) {
|
||||||
|
(void)interactor;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
void SetProp(vtkProp *prop);
|
void SetProp(vtkProp *prop);
|
||||||
|
|
||||||
void RemoveProp(vtkProp *prop);
|
void RemoveProp(vtkProp *prop);
|
||||||
@@ -82,13 +74,9 @@ private:
|
|||||||
class PuppetData *d;
|
class PuppetData *d;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Polydata {
|
class Polydata {
|
||||||
public:
|
public:
|
||||||
|
virtual vtkPolyData *GetPolyData() const { return NULL; }
|
||||||
virtual vtkPolyData * GetPolyData() const { return NULL; }
|
|
||||||
|
|
||||||
virtual void SaveToFile(const char *vtk_file);
|
virtual void SaveToFile(const char *vtk_file);
|
||||||
|
|
||||||
@@ -98,10 +86,7 @@ protected:
|
|||||||
virtual ~Polydata() {}
|
virtual ~Polydata() {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // ULIBVTKINTERFACE_H
|
#endif // ULIBVTKINTERFACE_H
|
||||||
|
|||||||
@@ -23,137 +23,164 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include <vtkSmartPointer.h>
|
|
||||||
#include <vtkRendererCollection.h>
|
|
||||||
#include <vtkRenderWindowInteractor.h>
|
#include <vtkRenderWindowInteractor.h>
|
||||||
|
#include <vtkRendererCollection.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
#include <vtkTextProperty.h>
|
|
||||||
#include <vtkAxesActor.h>
|
#include <vtkAxesActor.h>
|
||||||
#include <vtkCamera.h>
|
#include <vtkCamera.h>
|
||||||
|
#include <vtkCameraOrientationWidget.h>
|
||||||
|
#include <vtkInteractorStyleTrackballCamera.h>
|
||||||
|
#include <vtkObjectFactory.h>
|
||||||
|
#include <vtkTextProperty.h>
|
||||||
|
|
||||||
#include "uLibVtkViewer.h"
|
#include "uLibVtkViewer.h"
|
||||||
|
|
||||||
|
// Custom interactor style: disables spin/inertia so the scene only
|
||||||
|
// rotates while the mouse is actively being moved with the button held.
|
||||||
|
class vtkInteractorStyleNoSpin : public vtkInteractorStyleTrackballCamera {
|
||||||
|
public:
|
||||||
|
static vtkInteractorStyleNoSpin *New();
|
||||||
|
vtkTypeMacro(vtkInteractorStyleNoSpin, vtkInteractorStyleTrackballCamera);
|
||||||
|
|
||||||
|
// Override: when the left button is released, immediately stop any
|
||||||
|
// ongoing motion (rotation/spin) so no momentum is carried over.
|
||||||
|
void OnLeftButtonUp() override {
|
||||||
|
this->StopState();
|
||||||
|
vtkInteractorStyleTrackballCamera::OnLeftButtonUp();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
vtkStandardNewMacro(vtkInteractorStyleNoSpin);
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
///// VTK VIEWER //////////////////////////////////////////////////////////////
|
///// VTK VIEWER //////////////////////////////////////////////////////////////
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
Viewer::Viewer()
|
||||||
|
: m_RenderWindow(vtkRenderWindow::New()), m_Renderer(vtkRenderer::New()),
|
||||||
Viewer::Viewer() :
|
|
||||||
m_RenderWindow(vtkRenderWindow::New()),
|
|
||||||
m_Renderer(vtkRenderer::New()),
|
|
||||||
m_Annotation(vtkCornerAnnotation::New()),
|
m_Annotation(vtkCornerAnnotation::New()),
|
||||||
m_Marker(vtkOrientationMarkerWidget::New())
|
m_Marker(vtkOrientationMarkerWidget::New()), m_CameraWidget(nullptr) {
|
||||||
{
|
#if VTK_MAJOR_VERSION >= 9 || \
|
||||||
|
(VTK_MAJOR_VERSION == 8 && VTK_MINOR_VERSION >= 90)
|
||||||
|
m_CameraWidget = vtkCameraOrientationWidget::New();
|
||||||
|
#endif
|
||||||
InstallPipe();
|
InstallPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
Viewer::~Viewer()
|
Viewer::~Viewer() {
|
||||||
{
|
|
||||||
UninstallPipe();
|
UninstallPipe();
|
||||||
|
|
||||||
m_Annotation->Delete();
|
m_Annotation->Delete();
|
||||||
m_Marker->Delete();
|
m_Marker->Delete();
|
||||||
|
if (m_CameraWidget)
|
||||||
|
m_CameraWidget->Delete();
|
||||||
m_Renderer->Delete();
|
m_Renderer->Delete();
|
||||||
m_RenderWindow->Delete();
|
m_RenderWindow->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::InstallPipe()
|
void Viewer::InstallPipe() {
|
||||||
{
|
|
||||||
m_RenderWindow->AddRenderer(m_Renderer);
|
m_RenderWindow->AddRenderer(m_Renderer);
|
||||||
|
m_RenderWindow->SetSize(600,600);
|
||||||
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
|
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
|
||||||
vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
vtkSmartPointer<vtkRenderWindowInteractor>::New();
|
||||||
renderWindowInteractor->SetRenderWindow(m_RenderWindow);
|
renderWindowInteractor->SetRenderWindow(m_RenderWindow);
|
||||||
|
|
||||||
|
// Use a custom style with no spin/inertia
|
||||||
|
vtkSmartPointer<vtkInteractorStyleNoSpin> style =
|
||||||
|
vtkSmartPointer<vtkInteractorStyleNoSpin>::New();
|
||||||
|
renderWindowInteractor->SetInteractorStyle(style);
|
||||||
|
|
||||||
// annotation //
|
// annotation //
|
||||||
m_Annotation->GetTextProperty()->SetColor(1,1,1);
|
m_Annotation->GetTextProperty()->SetColor(1, 1, 1);
|
||||||
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
m_Annotation->GetTextProperty()->SetFontFamilyToArial();
|
||||||
m_Annotation->GetTextProperty()->SetOpacity(0.5);
|
m_Annotation->GetTextProperty()->SetOpacity(0.5);
|
||||||
m_Annotation->SetMaximumFontSize(10);
|
m_Annotation->SetMaximumFontSize(10);
|
||||||
m_Annotation->SetText(0,"uLib VTK Viewer - OpenCMT all right reserved.");
|
m_Annotation->SetText(0, "uLib VTK Viewer - OpenCMT all right reserved.");
|
||||||
m_Renderer->AddViewProp(m_Annotation);
|
m_Renderer->AddViewProp(m_Annotation);
|
||||||
|
|
||||||
// orientation marker //
|
// orientation marker //
|
||||||
vtkSmartPointer<vtkAxesActor> axes =
|
vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
|
||||||
vtkSmartPointer<vtkAxesActor>::New();
|
|
||||||
m_Marker->SetInteractor(renderWindowInteractor);
|
m_Marker->SetInteractor(renderWindowInteractor);
|
||||||
m_Marker->SetOrientationMarker(axes);
|
m_Marker->SetOrientationMarker(axes);
|
||||||
m_Marker->SetViewport(0.0,0.0,0.2,0.2);
|
m_Marker->SetViewport(0.0, 0.0, 0.2, 0.2);
|
||||||
m_Marker->SetEnabled(true);
|
m_Marker->SetEnabled(true);
|
||||||
m_Marker->InteractiveOff();
|
m_Marker->InteractiveOff();
|
||||||
|
|
||||||
|
// camera orientation widget //
|
||||||
|
if (m_CameraWidget) {
|
||||||
|
m_CameraWidget->SetParentRenderer(m_Renderer);
|
||||||
|
m_CameraWidget->SetInteractor(renderWindowInteractor);
|
||||||
|
m_CameraWidget->On();
|
||||||
|
}
|
||||||
|
|
||||||
// Must be rendered here in Vtk-6.0 or seg-fault //
|
// Must be rendered here in Vtk-6.0 or seg-fault //
|
||||||
m_RenderWindow->Render();
|
m_RenderWindow->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::UninstallPipe()
|
void Viewer::UninstallPipe() {
|
||||||
{
|
|
||||||
m_Renderer->RemoveAllViewProps();
|
m_Renderer->RemoveAllViewProps();
|
||||||
m_Renderer->Clear();
|
m_Renderer->Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::addProp(vtkProp *prop)
|
void Viewer::addProp(vtkProp *prop) {
|
||||||
{
|
|
||||||
m_Renderer->AddActor(prop);
|
m_Renderer->AddActor(prop);
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::RemoveProp(vtkProp *prop)
|
void Viewer::RemoveProp(vtkProp *prop) {
|
||||||
{
|
|
||||||
m_Renderer->RemoveViewProp(prop);
|
m_Renderer->RemoveViewProp(prop);
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::AddPuppet(Puppet &prop)
|
void Viewer::AddPuppet(Puppet &prop) {
|
||||||
{
|
|
||||||
prop.ConnectRenderer(m_Renderer);
|
prop.ConnectRenderer(m_Renderer);
|
||||||
|
prop.ConnectInteractor(this->GetInteractor());
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::RemovePuppet(Puppet &prop)
|
void Viewer::RemovePuppet(Puppet &prop) {
|
||||||
{
|
|
||||||
prop.DisconnectRenderer(m_Renderer);
|
prop.DisconnectRenderer(m_Renderer);
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::Start()
|
vtkSmartPointer<vtkCameraOrientationWidget>
|
||||||
{
|
Viewer::MakeCameraOrientationWidget(vtkRenderWindowInteractor *interactor,
|
||||||
m_RenderWindow->GetInteractor()->Start();
|
vtkRenderer *renderer) {
|
||||||
|
vtkSmartPointer<vtkCameraOrientationWidget> widget =
|
||||||
|
vtkSmartPointer<vtkCameraOrientationWidget>::New();
|
||||||
|
widget->SetParentRenderer(renderer);
|
||||||
|
widget->SetInteractor(interactor);
|
||||||
|
widget->On();
|
||||||
|
return widget;
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkCornerAnnotation *Viewer::GetAnnotation()
|
void Viewer::Start() { m_RenderWindow->GetInteractor()->Start(); }
|
||||||
{
|
|
||||||
return m_Annotation;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkRenderer *Viewer::GetRenderer()
|
vtkCornerAnnotation *Viewer::GetAnnotation() { return m_Annotation; }
|
||||||
{
|
|
||||||
return m_Renderer;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkRenderWindowInteractor *Viewer::GetInteractor()
|
vtkRenderer *Viewer::GetRenderer() { return m_Renderer; }
|
||||||
{
|
|
||||||
|
vtkRenderWindowInteractor *Viewer::GetInteractor() {
|
||||||
return m_RenderWindow->GetInteractor();
|
return m_RenderWindow->GetInteractor();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewer::Reset()
|
vtkCameraOrientationWidget *Viewer::GetCameraWidget() { return m_CameraWidget; }
|
||||||
{
|
|
||||||
m_Renderer->ResetCameraClippingRange();
|
void Viewer::Reset() {
|
||||||
m_Renderer->ResetCamera();
|
this->ZoomAuto();
|
||||||
m_Renderer->Render();
|
m_Renderer->Render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Viewer::ZoomAuto() {
|
||||||
|
m_Renderer->ResetCameraClippingRange();
|
||||||
|
m_Renderer->ResetCamera();
|
||||||
|
}
|
||||||
|
|
||||||
} // vtk
|
} // namespace Vtk
|
||||||
} // uLib
|
} // namespace uLib
|
||||||
|
|
||||||
|
|||||||
@@ -23,60 +23,63 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ULIBVTKVIEWER_H
|
#ifndef ULIBVTKVIEWER_H
|
||||||
#define ULIBVTKVIEWER_H
|
#define ULIBVTKVIEWER_H
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "uLibVtkInterface.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include <vtkRenderer.h>
|
|
||||||
#include <vtkRenderWindow.h>
|
|
||||||
#include <vtkCornerAnnotation.h>
|
#include <vtkCornerAnnotation.h>
|
||||||
#include <vtkOrientationMarkerWidget.h>
|
#include <vtkOrientationMarkerWidget.h>
|
||||||
|
#include <vtkRenderWindow.h>
|
||||||
|
#include <vtkRenderer.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
|
||||||
class vtkProp;
|
class vtkProp;
|
||||||
class vtk3DWidget;
|
class vtk3DWidget;
|
||||||
class vtkCornerAnnotation;
|
class vtkCornerAnnotation;
|
||||||
class vtkRenderWindowInteractor;
|
class vtkRenderWindowInteractor;
|
||||||
class vtkRenderer;
|
class vtkRenderer;
|
||||||
|
class vtkCameraOrientationWidget;
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
|
template <class T> class Tie {
|
||||||
template <class T>
|
|
||||||
class Tie {
|
|
||||||
public:
|
public:
|
||||||
void DoAction() {
|
void DoAction() {
|
||||||
std::cout << "Tie::DoAction -> generic Tie does nothing\n";
|
std::cout << "Tie::DoAction -> generic Tie does nothing\n";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
class Viewer {
|
class Viewer {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Viewer();
|
Viewer();
|
||||||
~Viewer();
|
~Viewer();
|
||||||
|
|
||||||
|
|
||||||
void AddPuppet(Puppet &prop);
|
void AddPuppet(Puppet &prop);
|
||||||
|
|
||||||
void RemovePuppet(Puppet &prop);
|
void RemovePuppet(Puppet &prop);
|
||||||
|
|
||||||
void AddWidget(vtk3DWidget *widget);
|
void AddWidget(vtk3DWidget *widget);
|
||||||
|
|
||||||
|
static vtkSmartPointer<vtkCameraOrientationWidget>
|
||||||
|
MakeCameraOrientationWidget(vtkRenderWindowInteractor *interactor,
|
||||||
|
vtkRenderer *renderer);
|
||||||
|
|
||||||
void Reset();
|
void Reset();
|
||||||
|
void ZoomAuto();
|
||||||
|
|
||||||
void Start();
|
void Start();
|
||||||
|
|
||||||
vtkCornerAnnotation *GetAnnotation();
|
vtkCornerAnnotation *GetAnnotation();
|
||||||
|
|
||||||
vtkRenderer * GetRenderer();
|
vtkRenderer *GetRenderer();
|
||||||
|
|
||||||
vtkRenderWindowInteractor * GetInteractor();
|
vtkRenderWindowInteractor *GetInteractor();
|
||||||
|
|
||||||
|
vtkCameraOrientationWidget *GetCameraWidget();
|
||||||
|
|
||||||
void addProp(vtkProp *prop);
|
void addProp(vtkProp *prop);
|
||||||
|
|
||||||
@@ -90,18 +93,15 @@ private:
|
|||||||
vtkRenderWindow *m_RenderWindow;
|
vtkRenderWindow *m_RenderWindow;
|
||||||
vtkCornerAnnotation *m_Annotation;
|
vtkCornerAnnotation *m_Annotation;
|
||||||
vtkOrientationMarkerWidget *m_Marker;
|
vtkOrientationMarkerWidget *m_Marker;
|
||||||
|
vtkCameraOrientationWidget *m_CameraWidget;
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <> class Tie<Viewer> {
|
||||||
class Tie<Viewer> {
|
|
||||||
public:
|
public:
|
||||||
void DoAction() {
|
void DoAction() { std::cout << " VIEWER TIE !!! \n"; }
|
||||||
std::cout << " VIEWER TIE !!! \n";
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
} // vtk
|
} // namespace uLib
|
||||||
} // uLib
|
|
||||||
|
|
||||||
#endif // ULIBVTKVIEWER_H
|
#endif // ULIBVTKVIEWER_H
|
||||||
|
|||||||
@@ -23,69 +23,95 @@
|
|||||||
|
|
||||||
//////////////////////////////////////////////////////////////////////////////*/
|
//////////////////////////////////////////////////////////////////////////////*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
#include <vtkSmartPointer.h>
|
|
||||||
#include <vtkCubeSource.h>
|
|
||||||
#include <vtkActor.h>
|
|
||||||
#include <vtkAxes.h>
|
|
||||||
#include <vtkAssembly.h>
|
|
||||||
#include <vtkPolyDataMapper.h>
|
|
||||||
#include <vtkProperty.h>
|
|
||||||
#include <vtkLineSource.h>
|
|
||||||
|
|
||||||
#include "vtkContainerBox.h"
|
#include "vtkContainerBox.h"
|
||||||
|
#include <vtkActor.h>
|
||||||
|
#include <vtkAssembly.h>
|
||||||
|
#include <vtkAxes.h>
|
||||||
|
#include <vtkCubeSource.h>
|
||||||
|
#include <vtkLineSource.h>
|
||||||
|
#include <vtkMatrix4x4.h>
|
||||||
|
#include <vtkPolyDataMapper.h>
|
||||||
|
#include <vtkProperty.h>
|
||||||
|
#include <vtkSmartPointer.h>
|
||||||
|
#include <vtkTransform.h>
|
||||||
|
|
||||||
|
|
||||||
namespace uLib {
|
namespace uLib {
|
||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
|
vtkContainerBox::vtkContainerBox(vtkContainerBox::Content *content)
|
||||||
vtkContainerBox::vtkContainerBox(vtkContainerBox::Content &content) :
|
: m_Cube(vtkActor::New()), m_Axes(vtkActor::New()),
|
||||||
m_Cube(vtkActor::New()),
|
|
||||||
m_Axes(vtkActor::New()),
|
|
||||||
m_Pivot(vtkActor::New()),
|
m_Pivot(vtkActor::New()),
|
||||||
m_Content(&content)
|
m_Content(content) {
|
||||||
{
|
|
||||||
this->InstallPipe();
|
this->InstallPipe();
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkContainerBox::~vtkContainerBox()
|
vtkContainerBox::~vtkContainerBox() {
|
||||||
{
|
|
||||||
m_Cube->Delete();
|
m_Cube->Delete();
|
||||||
m_Axes->Delete();
|
m_Axes->Delete();
|
||||||
m_Pivot->Delete();
|
m_Pivot->Delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkPolyData *vtkContainerBox::GetPolyData() const
|
vtkPolyData *vtkContainerBox::GetPolyData() const {
|
||||||
{
|
|
||||||
// TODO
|
// TODO
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void vtkContainerBox::InstallPipe()
|
void vtkContainerBox::Update() {
|
||||||
{
|
if (!m_Content)
|
||||||
if(!m_Content) return;
|
return;
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f transform = m_Content->GetMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmat->SetElement(i, j, transform(i, j));
|
||||||
|
|
||||||
|
// std::cout << "transform: " << transform << std::endl;
|
||||||
|
// m_RelativeTransform->SetMatrix(vmat);
|
||||||
|
// m_RelativeTransform->Update();
|
||||||
|
|
||||||
|
m_Cube->SetUserMatrix(vmat);
|
||||||
|
m_Axes->SetUserMatrix(vmat);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void vtkContainerBox::InstallPipe() {
|
||||||
|
if (!m_Content)
|
||||||
|
return;
|
||||||
Content *c = m_Content;
|
Content *c = m_Content;
|
||||||
|
|
||||||
// CUBE
|
// CUBE
|
||||||
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
vtkSmartPointer<vtkCubeSource> cube = vtkSmartPointer<vtkCubeSource>::New();
|
||||||
|
|
||||||
Vector3f p = c->GetPosition();
|
Vector3f p = c->GetPosition();
|
||||||
cube->SetCenter(p(0),p(1),p(2));
|
// cube->SetCenter(p(0), p(1), p(2));
|
||||||
Vector4f p1 = c->GetWorldPoint(HPoint3f(0,0,0));
|
// Vector4f p1 = c->GetWorldPoint(HPoint3f(0, 0, 0));
|
||||||
Vector4f p2 = c->GetWorldPoint(HPoint3f(1,1,1));
|
// Vector4f p2 = c->GetWorldPoint(HPoint3f(1, 1, 1));
|
||||||
vtkSmartPointer<vtkLineSource> line = vtkSmartPointer<vtkLineSource>::New();
|
// vtkSmartPointer<vtkLineSource> line =
|
||||||
line->SetPoint1(p1(0),p1(1),p1(2));
|
// vtkSmartPointer<vtkLineSource>::New(); line->SetPoint1(p1(0), p1(1),
|
||||||
line->SetPoint2(p2(0),p2(1),p2(2));
|
// p1(2)); line->SetPoint2(p2(0), p2(1), p2(2)); line->Update();
|
||||||
line->Update();
|
// cube->SetBounds(line->GetOutput()->GetBounds());
|
||||||
cube->SetBounds(line->GetOutput()->GetBounds());
|
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> vmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
Matrix4f transform = c->GetMatrix();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
vmat->SetElement(i, j, transform(i, j));
|
||||||
|
|
||||||
|
m_Cube->SetUserMatrix(vmat);
|
||||||
|
|
||||||
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
||||||
vtkSmartPointer<vtkPolyDataMapper>::New();
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
|
cube->SetBounds(0, 1, 0, 1, 0, 1);
|
||||||
mapper->SetInputConnection(cube->GetOutputPort());
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
mapper->Update();
|
mapper->Update();
|
||||||
m_Cube->SetMapper(mapper);
|
m_Cube->SetMapper(mapper);
|
||||||
@@ -94,11 +120,12 @@ void vtkContainerBox::InstallPipe()
|
|||||||
|
|
||||||
// AXES //
|
// AXES //
|
||||||
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
vtkSmartPointer<vtkAxes> axes = vtkSmartPointer<vtkAxes>::New();
|
||||||
axes->SetOrigin(p1(0),p1(1),p1(2));
|
axes->SetOrigin(0, 0, 0);
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(axes->GetOutputPort());
|
mapper->SetInputConnection(axes->GetOutputPort());
|
||||||
mapper->Update();
|
mapper->Update();
|
||||||
m_Axes->SetMapper(mapper);
|
m_Axes->SetMapper(mapper);
|
||||||
|
m_Axes->SetUserMatrix(vmat);
|
||||||
Vector3f s = c->GetSize();
|
Vector3f s = c->GetSize();
|
||||||
// m_Axes->SetScale(s(0),s(1),s(2));
|
// m_Axes->SetScale(s(0),s(1),s(2));
|
||||||
m_Axes->GetProperty()->SetLineWidth(3);
|
m_Axes->GetProperty()->SetLineWidth(3);
|
||||||
@@ -107,11 +134,19 @@ void vtkContainerBox::InstallPipe()
|
|||||||
|
|
||||||
// PIVOT //
|
// PIVOT //
|
||||||
axes = vtkSmartPointer<vtkAxes>::New();
|
axes = vtkSmartPointer<vtkAxes>::New();
|
||||||
axes->SetOrigin(p(0),p(1),p(2));
|
axes->SetOrigin(0, 0, 0);
|
||||||
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
|
||||||
mapper->SetInputConnection(axes->GetOutputPort());
|
mapper->SetInputConnection(axes->GetOutputPort());
|
||||||
mapper->Update();
|
mapper->Update();
|
||||||
|
m_Pivot->SetUserMatrix(vmat);
|
||||||
m_Pivot->SetMapper(mapper);
|
m_Pivot->SetMapper(mapper);
|
||||||
|
|
||||||
|
Matrix4f pivotTransform = c->AffineTransform::GetWorldMatrix();
|
||||||
|
vtkSmartPointer<vtkMatrix4x4> pmat = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
|
for (int i = 0; i < 4; ++i)
|
||||||
|
for (int j = 0; j < 4; ++j)
|
||||||
|
pmat->SetElement(i, j, pivotTransform(i, j));
|
||||||
|
m_Pivot->SetUserMatrix(pmat);
|
||||||
s = c->GetScale();
|
s = c->GetScale();
|
||||||
// m_Pivot->SetScale(s(0),s(1),s(2));
|
// m_Pivot->SetScale(s(0),s(1),s(2));
|
||||||
m_Pivot->GetProperty()->SetLineWidth(3);
|
m_Pivot->GetProperty()->SetLineWidth(3);
|
||||||
@@ -123,7 +158,5 @@ void vtkContainerBox::InstallPipe()
|
|||||||
this->SetProp(m_Pivot);
|
this->SetProp(m_Pivot);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
} // namespace Vtk
|
||||||
|
} // namespace uLib
|
||||||
} // vtk
|
|
||||||
} // uLib
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user