/*////////////////////////////////////////////////////////////////////////////// // 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 #include #include namespace uLib { namespace Vtk { TessellatedSolid::TessellatedSolid(Geant::PhysicalVolume *content) : GeantSolid(content), m_TessSolid(nullptr) { if (content && content->GetLogical()) { m_TessSolid = dynamic_cast(content->GetLogical()->GetSolid()); } } TessellatedSolid::~TessellatedSolid() {} void TessellatedSolid::Update() { this->UpdateGeometry(); this->UpdateTransform(); } void TessellatedSolid::UpdateGeometry() { if (!m_TessSolid || !m_TessSolid->GetMesh() || m_TessSolid->GetMesh()->Points().empty()) { // Fallback to base tessellation if no model mesh GeantSolid::UpdateGeometry(); return; } const TriangleMesh &mesh = *m_TessSolid->GetMesh(); vtkNew points; for (const auto& pt : mesh.Points()) { points->InsertNextPoint(pt(0), pt(1), pt(2)); } vtkNew 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