add vtk geant solid and scene
This commit is contained in:
89
src/Vtk/HEP/Geant/vtkGeantScene.cpp
Normal file
89
src/Vtk/HEP/Geant/vtkGeantScene.cpp
Normal file
@@ -0,0 +1,89 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// 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 "vtkGeantScene.h"
|
||||
#include "vtkGeantSolid.h"
|
||||
#include "Vtk/vtkViewport.h"
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
vtkGeantScene::vtkGeantScene(Geant::Scene *scene)
|
||||
: m_Scene(scene), m_WorldPuppet(nullptr) {
|
||||
if (!m_Scene)
|
||||
return;
|
||||
|
||||
// 1. Create the world box wireframe puppet
|
||||
ContainerBox *worldBox = m_Scene->GetWorldBox();
|
||||
if (worldBox) {
|
||||
m_WorldPuppet = new vtkContainerBox(worldBox);
|
||||
m_WorldPuppet->SetRepresentation(Puppet::Wireframe);
|
||||
m_WorldPuppet->ShowScaleMeasures(true);
|
||||
}
|
||||
|
||||
// 2. Create puppets for each non-world solid
|
||||
const Geant::Solid *world = m_Scene->GetWorld();
|
||||
const Vector<Geant::Solid *> &solids = m_Scene->GetSolids();
|
||||
|
||||
for (Geant::Solid *solid : solids) {
|
||||
// Skip the world volume itself — it's already shown as the wireframe box
|
||||
if (solid == world)
|
||||
continue;
|
||||
|
||||
// Only create a puppet if the solid has a valid G4VSolid
|
||||
if (solid->GetG4Solid()) {
|
||||
vtkGeantSolid *vtkSolid = new vtkGeantSolid(solid);
|
||||
m_SolidPuppets.push_back(vtkSolid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vtkGeantScene::~vtkGeantScene() {
|
||||
delete m_WorldPuppet;
|
||||
for (auto *p : m_SolidPuppets) {
|
||||
delete p;
|
||||
}
|
||||
}
|
||||
|
||||
void vtkGeantScene::AddToViewer(Viewport &viewer) {
|
||||
if (m_WorldPuppet) {
|
||||
viewer.AddPuppet(*m_WorldPuppet);
|
||||
}
|
||||
for (auto *p : m_SolidPuppets) {
|
||||
viewer.AddPuppet(*p);
|
||||
}
|
||||
}
|
||||
|
||||
void vtkGeantScene::RemoveFromViewer(Viewport &viewer) {
|
||||
if (m_WorldPuppet) {
|
||||
viewer.RemovePuppet(*m_WorldPuppet);
|
||||
}
|
||||
for (auto *p : m_SolidPuppets) {
|
||||
viewer.RemovePuppet(*p);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
Reference in New Issue
Block a user