transform properties

This commit is contained in:
AndreaRigoni
2026-03-27 02:43:30 +00:00
parent 09859e872c
commit 93e5602562
12 changed files with 299 additions and 114 deletions

View File

@@ -41,6 +41,7 @@
#include <vtkVersion.h>
#include "vtkViewport.h"
#include "uLibVtkInterface.h"
#include "Math/Transform.h"
#include <vtkActor.h>
#include <vtkPolyDataMapper.h>
#include <vtkProperty.h>
@@ -484,7 +485,7 @@ void Puppet::SetSelected(bool selected)
if (!pd->m_Selectable) return;
if (pd->m_Selected == selected) return;
pd->m_Selected = selected;
pd->UpdateHighlight();
pd->UpdateHighlight();0
}
bool Puppet::IsSelected() const
@@ -498,8 +499,25 @@ void Puppet::Update()
if (root) {
pd->ApplyAppearance(root);
// Apply transformation if it's a Prop3D
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
// Handle transformation synchronization from content
if (auto* content = dynamic_cast<uLib::AffineTransform*>(GetContent())) {
pd->m_Position = content->GetPosition().cast<double>();
pd->m_Orientation = content->GetOrientation().cast<double>();
pd->m_Scale = content->GetScale().cast<double>();
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
vtkNew<vtkMatrix4x4> vmat;
const Matrix4f& emat = content->GetMatrix();
for(int i=0; i<4; ++i) for(int j=0; j<4; ++j) vmat->SetElement(i, j, emat(i,j));
p3d->SetUserMatrix(vmat);
// Clear base transform to avoid double-application
p3d->SetPosition(0,0,0);
p3d->SetOrientation(0,0,0);
p3d->SetScale(1,1,1);
}
}
else if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
p3d->SetPosition(pd->m_Position.data());
p3d->SetOrientation(pd->m_Orientation.data());
p3d->SetScale(pd->m_Scale.data());
@@ -539,23 +557,42 @@ void Puppet::Update()
}
}
void Puppet::SyncFromVtk()
{
vtkProp* root = this->GetProp();
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
double pos[3], ori[3], scale[3];
p3d->GetPosition(pos);
p3d->GetOrientation(ori);
p3d->GetScale(scale);
// Update properties
for (int i=0; i<3; ++i) {
pd->m_Position(i) = pos[i];
pd->m_Orientation(i) = ori[i];
pd->m_Scale(i) = scale[i];
// Handle content synchronization if it's an AffineTransform
if (auto* content = dynamic_cast<uLib::AffineTransform*>(GetContent())) {
vtkMatrix4x4* vmat = p3d->GetUserMatrix();
if (vmat) {
Matrix4f emat;
for (int i=0; i<4; ++i)
for (int j=0; j<4; ++j)
emat(i, j) = vmat->GetElement(i, j);
content->SetMatrix(emat);
// Re-sync internal puppet properties from the now-updated content
pd->m_Position = content->GetPosition().cast<double>();
pd->m_Orientation = content->GetOrientation().cast<double>();
pd->m_Scale = content->GetScale().cast<double>();
}
}
else {
// Update internal puppet properties directly from base components
// only if no content exists (old behavior)
double pos[3], ori[3], scale[3];
p3d->GetPosition(pos);
p3d->GetOrientation(ori);
p3d->GetScale(scale);
for (int i=0; i<3; ++i) {
pd->m_Position(i) = pos[i];
pd->m_Orientation(i) = ori[i];
pd->m_Scale(i) = scale[i];
}
}
// Get the properties from the object
// Notify puppet properties updated
if (auto* propPos = this->GetProperty("Position")) propPos->Updated();
if (auto* propOri = this->GetProperty("Orientation")) propOri->Updated();
if (auto* propScale = this->GetProperty("Scale")) propScale->Updated();

View File

@@ -110,17 +110,16 @@ void vtkObjectsContext::Update() {
Puppet* vtkObjectsContext::CreatePuppet(uLib::Object* obj) {
if (!obj) return nullptr;
const char* className = obj->GetClassName();
if (std::strcmp(className, "ContainerBox") == 0) {
return new vtkContainerBox(static_cast<uLib::ContainerBox*>(obj));
} else if (std::strcmp(className, "DetectorChamber") == 0) {
return new vtkDetectorChamber(static_cast<uLib::DetectorChamber*>(obj));
} else if (std::strcmp(className, "Cylinder") == 0) {
return new vtkCylinder(static_cast<uLib::Cylinder*>(obj));
} else if (std::strcmp(className, "VoxImage") == 0) {
return new vtkVoxImage(*static_cast<uLib::Abstract::VoxImage*>(obj));
} else if (std::strcmp(className, "Assembly") == 0) {
return new Assembly(static_cast<uLib::Assembly*>(obj));
if (auto* box = dynamic_cast<uLib::ContainerBox*>(obj)) {
return new vtkContainerBox(box);
} else if (auto* chamber = dynamic_cast<uLib::DetectorChamber*>(obj)) {
return new vtkDetectorChamber(chamber);
} else if (auto* cylinder = dynamic_cast<uLib::Cylinder*>(obj)) {
return new vtkCylinder(cylinder);
} else if (auto* vox = dynamic_cast<uLib::Abstract::VoxImage*>(obj)) {
return new vtkVoxImage(*vox);
} else if (auto* assembly = dynamic_cast<uLib::Assembly*>(obj)) {
return new Assembly(assembly);
}
// Fallback if we don't know the exact class but it might be a context itself