emitter representation

This commit is contained in:
AndreaRigoni
2026-03-19 13:57:10 +00:00
parent ca5f576b99
commit 1e6e3ae4f4
9 changed files with 261 additions and 9 deletions

View File

@@ -0,0 +1,72 @@
#include "vtkEmitterPrimary.h"
#include <vtkActor.h>
#include <vtkArrowSource.h>
#include <vtkMatrix4x4.h>
#include <vtkNew.h>
#include <vtkPolyDataMapper.h>
#include <vtkTransform.h>
#include <vtkTransformPolyDataFilter.h>
#include "Math/vtkDense.h"
namespace uLib {
namespace Vtk {
vtkEmitterPrimary::vtkEmitterPrimary(Geant::EmitterPrimary &emitter)
: m_emitter(emitter), m_Poly(nullptr), m_Actor(vtkActor::New()) {
vtkNew<vtkArrowSource> arrow;
// Default arrow is along X+. Rotate to point towards Z- relative to the origin
vtkNew<vtkTransform> transform;
transform->RotateY(90.0);
vtkNew<vtkTransformPolyDataFilter> transformFilter;
transformFilter->SetTransform(transform);
transformFilter->SetInputConnection(arrow->GetOutputPort());
transformFilter->Update();
vtkSmartPointer<vtkPolyDataMapper> mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(transformFilter->GetOutput());
m_Actor->SetMapper(mapper);
m_Actor->SetScale(1000.0); // 1 meter long
vtkNew<vtkMatrix4x4> vmat;
Matrix4fToVtk(m_emitter.GetWorldMatrix(), vmat);
m_Actor->SetUserMatrix(vmat);
this->SetProp(m_Actor);
Object::connect(&m_emitter, &Object::Updated, this, &vtkEmitterPrimary::contentUpdate);
this->contentUpdate();
}
vtkEmitterPrimary::~vtkEmitterPrimary() {
Object::disconnect(&m_emitter, &Object::Updated, this, &vtkEmitterPrimary::contentUpdate);
m_Actor->Delete();
}
void vtkEmitterPrimary::contentUpdate() {
vtkMatrix4x4 *vmat = m_Actor->GetUserMatrix();
if (!vmat) {
vtkNew<vtkMatrix4x4> mat;
m_Actor->SetUserMatrix(mat);
vmat = mat;
}
Matrix4f transform = m_emitter.GetWorldMatrix();
Matrix4fToVtk(transform, vmat);
Puppet::Update();
}
void vtkEmitterPrimary::Update() {
vtkMatrix4x4 *vmat = m_Actor->GetUserMatrix();
if (!vmat) return;
Matrix4f transform = VtkToMatrix4f(vmat);
m_emitter.SetMatrix(transform);
m_emitter.Updated();
}
} // namespace Vtk
} // namespace uLib