add cylinder emitter
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user