add vtk solids

This commit is contained in:
AndreaRigoni
2026-03-25 21:03:13 +00:00
parent e4a8499104
commit 422113a0e9
17 changed files with 353 additions and 16 deletions

View 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