add vtk solids
This commit is contained in:
62
src/Vtk/HEP/Geant/vtkTessellatedSolid.cpp
Normal file
62
src/Vtk/HEP/Geant/vtkTessellatedSolid.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
/*//////////////////////////////////////////////////////////////////////////////
|
||||
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
Copyright (c) 2014, Universita' degli Studi Padova, INFN sez. di Padova
|
||||
All rights reserved
|
||||
|
||||
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////*/
|
||||
|
||||
#include "vtkTessellatedSolid.h"
|
||||
|
||||
#include <vtkPoints.h>
|
||||
#include <vtkCellArray.h>
|
||||
#include <vtkPolyData.h>
|
||||
|
||||
namespace uLib {
|
||||
namespace Vtk {
|
||||
|
||||
vtkTessellatedSolid::vtkTessellatedSolid(Geant::TessellatedSolid *content)
|
||||
: vtkGeantSolid(content), m_TessContent(content) {
|
||||
this->Update();
|
||||
}
|
||||
|
||||
vtkTessellatedSolid::~vtkTessellatedSolid() {}
|
||||
|
||||
void vtkTessellatedSolid::Update() {
|
||||
this->UpdateGeometry();
|
||||
this->UpdateTransform();
|
||||
}
|
||||
|
||||
void vtkTessellatedSolid::UpdateGeometry() {
|
||||
if (!m_TessContent || m_TessContent->GetMesh().Points().empty()) {
|
||||
// Fallback to base tessellation if no model mesh
|
||||
vtkGeantSolid::UpdateGeometry();
|
||||
return;
|
||||
}
|
||||
|
||||
const TriangleMesh &mesh = m_TessContent->GetMesh();
|
||||
|
||||
vtkNew<vtkPoints> points;
|
||||
for (const auto& pt : mesh.Points()) {
|
||||
points->InsertNextPoint(pt(0), pt(1), pt(2));
|
||||
}
|
||||
|
||||
vtkNew<vtkCellArray> polys;
|
||||
for (const auto& trg : mesh.Triangles()) {
|
||||
vtkIdType ids[3] = { (vtkIdType)trg(0), (vtkIdType)trg(1), (vtkIdType)trg(2) };
|
||||
polys->InsertNextCell(3, ids);
|
||||
}
|
||||
|
||||
vtkPolyData *poly = GetPolyData();
|
||||
if (poly) {
|
||||
poly->SetPoints(points);
|
||||
poly->SetPolys(polys);
|
||||
poly->Modified();
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Vtk
|
||||
} // namespace uLib
|
||||
Reference in New Issue
Block a user