109 lines
3.5 KiB
C++
109 lines
3.5 KiB
C++
/*//////////////////////////////////////////////////////////////////////////////
|
|
// 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 "vtkGeantEvent.h"
|
|
|
|
#include <vtkPolyData.h>
|
|
#include <vtkPoints.h>
|
|
#include <vtkCellArray.h>
|
|
#include <vtkPolyDataMapper.h>
|
|
#include <vtkProperty.h>
|
|
#include <vtkSmartPointer.h>
|
|
|
|
namespace uLib {
|
|
namespace Vtk {
|
|
|
|
GeantEvent::GeantEvent(Content *content)
|
|
: m_MuonPath(vtkActor::New()), m_Content(content) {
|
|
this->InstallPipe();
|
|
this->Update();
|
|
}
|
|
|
|
GeantEvent::~GeantEvent() {
|
|
m_MuonPath->Delete();
|
|
}
|
|
|
|
vtkPolyData *GeantEvent::GetPolyData() const {
|
|
if (!m_MuonPath || !m_MuonPath->GetMapper())
|
|
return NULL;
|
|
return vtkPolyData::SafeDownCast(m_MuonPath->GetMapper()->GetInput());
|
|
}
|
|
|
|
void GeantEvent::Update() {
|
|
if (!m_Content)
|
|
return;
|
|
|
|
vtkSmartPointer<vtkPoints> points = vtkSmartPointer<vtkPoints>::New();
|
|
vtkSmartPointer<vtkCellArray> lines = vtkSmartPointer<vtkCellArray>::New();
|
|
|
|
const HLine3f &gen = m_Content->GenVector();
|
|
const Vector<Geant::GeantEvent::Delta> &path = m_Content->Path();
|
|
|
|
// Start point from generation vector
|
|
Vector3f currentPos(gen.origin(0), gen.origin(1), gen.origin(2));
|
|
points->InsertNextPoint(currentPos(0), currentPos(1), currentPos(2));
|
|
|
|
for (size_t i = 0; i < path.size(); ++i) {
|
|
const Geant::GeantEvent::Delta &delta = path[i];
|
|
|
|
// P_{i+1} = P_i + Length * Direction
|
|
// Note: HVector3f is stored as (x,y,z,0) in HPoint3f template
|
|
Vector3f dir(delta.Direction()(0), delta.Direction()(1), delta.Direction()(2));
|
|
currentPos += delta.GetLength() * dir;
|
|
|
|
points->InsertNextPoint(currentPos(0), currentPos(1), currentPos(2));
|
|
|
|
vtkIdType line[2] = {static_cast<vtkIdType>(i),
|
|
static_cast<vtkIdType>(i + 1)};
|
|
lines->InsertNextCell(2, line);
|
|
}
|
|
|
|
vtkPolyData *polyData = GetPolyData();
|
|
if (polyData) {
|
|
polyData->SetPoints(points);
|
|
polyData->SetLines(lines);
|
|
polyData->Modified();
|
|
}
|
|
}
|
|
|
|
void GeantEvent::InstallPipe() {
|
|
vtkSmartPointer<vtkPolyData> polyData = vtkSmartPointer<vtkPolyData>::New();
|
|
vtkSmartPointer<vtkPolyDataMapper> mapper =
|
|
vtkSmartPointer<vtkPolyDataMapper>::New();
|
|
mapper->SetInputData(polyData);
|
|
|
|
m_MuonPath->SetMapper(mapper);
|
|
|
|
// Set default look: Red line
|
|
m_MuonPath->GetProperty()->SetColor(1.0, 1.0, 1.0);
|
|
m_MuonPath->GetProperty()->SetLineWidth(1.0);
|
|
m_MuonPath->GetProperty()->SetAmbient(1.0);
|
|
|
|
this->SetProp(m_MuonPath);
|
|
}
|
|
|
|
} // namespace Vtk
|
|
} // namespace uLib
|