add cylinder emitter

This commit is contained in:
AndreaRigoni
2026-03-19 16:19:36 +00:00
parent ae27e9d46d
commit 80952cc706
6 changed files with 286 additions and 0 deletions

View File

@@ -10,6 +10,7 @@
#include <vtkAppendPolyData.h>
#include <vtkPolyData.h>
#include <vtkProperty.h>
#include <vtkCylinderSource.h>
#include "Math/vtkDense.h"
namespace uLib {
@@ -121,6 +122,56 @@ void vtkQuadMeshEmitterPrimary::contentUpdate() {
// For now stick with the arrow. In the future visualize the mesh if useful.
vtkEmitterPrimary::contentUpdate();
}
// -------------------------------------------------------------------------- //
// vtkCylinderEmitterPrimary
vtkCylinderEmitterPrimary::vtkCylinderEmitterPrimary(Geant::CylinderEmitterPrimary &emitter)
: vtkEmitterPrimary(emitter), m_cylinderEmitter(emitter), m_CylinderSource(vtkCylinderSource::New()) {
// vtkCylinderSource is along Y by default.
// We will update its actual dimensions in contentUpdate().
m_CylinderSource->SetResolution(64);
// Rotate it to be along local Z
vtkNew<vtkTransform> tcyl;
tcyl->RotateX(90.0);
vtkNew<vtkTransformPolyDataFilter> cylFilter;
cylFilter->SetTransform(tcyl);
cylFilter->SetInputConnection(m_CylinderSource->GetOutputPort());
vtkNew<vtkAppendPolyData> append;
// Keep the directional arrow from base class
append->AddInputData(vtkPolyData::SafeDownCast(m_Actor->GetMapper()->GetInput()));
append->AddInputConnection(cylFilter->GetOutputPort());
vtkNew<vtkPolyDataMapper> mapper;
mapper->SetInputConnection(append->GetOutputPort());
m_Actor->SetMapper(mapper);
m_Actor->GetProperty()->SetOpacity(0.5);
m_Actor->GetProperty()->SetColor(0.2, 0.6, 0.9);
this->contentUpdate();
}
vtkCylinderEmitterPrimary::~vtkCylinderEmitterPrimary() {
m_CylinderSource->Delete();
}
void vtkCylinderEmitterPrimary::contentUpdate() {
float r = m_cylinderEmitter.GetRadius();
float h = m_cylinderEmitter.GetHeight();
m_CylinderSource->SetRadius(r);
m_CylinderSource->SetHeight(h);
// vtkCylinderSource is along Y. To have the base at Y=0, we center it at h/2.
m_CylinderSource->SetCenter(0, h/2.0, 0);
m_CylinderSource->Update();
vtkEmitterPrimary::contentUpdate();
}
} // namespace Vtk
} // namespace uLib