From fa7c0f670e5d17bfb5b9533aebbb4af699d862f2 Mon Sep 17 00:00:00 2001 From: AndreaRigoni Date: Fri, 27 Mar 2026 15:23:59 +0000 Subject: [PATCH] fix display of cylinder --- src/Vtk/Math/vtkCylinder.cpp | 41 ++++++++++++++++++------------------ src/Vtk/Math/vtkCylinder.h | 5 ++++- src/Vtk/uLibVtkInterface.cxx | 8 +++++++ 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/src/Vtk/Math/vtkCylinder.cpp b/src/Vtk/Math/vtkCylinder.cpp index d9f2741..3e14246 100644 --- a/src/Vtk/Math/vtkCylinder.cpp +++ b/src/Vtk/Math/vtkCylinder.cpp @@ -55,17 +55,12 @@ void vtkCylinder::contentUpdate() { vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp()); if (!root) return; - // 1. Placement (Position/Rotation/Model-level Scale) goes to the root prop - vtkMatrix4x4* vmat = root->GetUserMatrix(); - if (!vmat) { - vtkNew mat; - root->SetUserMatrix(mat); - vmat = mat; - } - Matrix4f transform = m_Content->GetMatrix(); - Matrix4fToVtk(transform, vmat); + // 1. Placement handled by base Puppet class via Sync / Update logic + // Update internal pd->m_Transform from content + Puppet::Update(); // 2. Shape-local properties (Radius, Height, Axis alignment) go to the internal actor + // These are relative to the root assembly vtkTransform* alignment = vtkTransform::SafeDownCast(m_Actor->GetUserTransform()); if (alignment) { alignment->Identity(); @@ -83,23 +78,29 @@ void vtkCylinder::contentUpdate() { } root->Modified(); - Puppet::Update(); } void vtkCylinder::Update() { + this->contentUpdate(); +} + +void vtkCylinder::SyncFromVtk() { if (!m_Content) return; - - vtkProp3D* root = vtkProp3D::SafeDownCast(this->GetProp()); - if (!root) return; - - vtkMatrix4x4* vmat = root->GetUserMatrix(); - if (!vmat) return; - // Pull the placement matrix directly from VTK - Matrix4f transform = VtkToMatrix4f(vmat); - m_Content->SetMatrix(transform); + vtkProp3D* assembly = vtkProp3D::SafeDownCast(this->GetProp()); + if (!assembly) return; - m_Content->Updated(); + double pos[3], ori[3], scale[3]; + assembly->GetPosition(pos); + assembly->GetOrientation(ori); + assembly->GetScale(scale); + + m_Content->SetPosition(Vector3f(pos[0], pos[1], pos[2])); + // Convert VTK degrees to model radians + m_Content->SetOrientation(Vector3f(ori[0], ori[1], ori[2]) * CLHEP::degree); + m_Content->SetScale(Vector3f(scale[0], scale[1], scale[2])); + + m_Content->Updated(); // Notify change } void vtkCylinder::InstallPipe() { diff --git a/src/Vtk/Math/vtkCylinder.h b/src/Vtk/Math/vtkCylinder.h index fc246f9..1965293 100644 --- a/src/Vtk/Math/vtkCylinder.h +++ b/src/Vtk/Math/vtkCylinder.h @@ -52,7 +52,10 @@ public: virtual void contentUpdate(); /** Synchronizes the uLib model matrix with the VTK actor (e.g., after UI manipulation) */ - virtual void Update(); + virtual void Update() override; + + /** Synchronizes the uLib model matrix with the VTK actor specifically for gizmo interactions */ + virtual void SyncFromVtk() override; virtual uLib::Object* GetContent() const override { return (uLib::Object*)m_Content; } diff --git a/src/Vtk/uLibVtkInterface.cxx b/src/Vtk/uLibVtkInterface.cxx index 97e525f..d390f58 100644 --- a/src/Vtk/uLibVtkInterface.cxx +++ b/src/Vtk/uLibVtkInterface.cxx @@ -121,6 +121,7 @@ public: TRS m_Transform; void ApplyAppearance(vtkProp *p) { + if (!p) return; p->SetVisibility(m_Visibility); p->SetPickable(m_Selectable); p->SetDragable(m_Dragable); @@ -143,6 +144,13 @@ public: if (m_Opacity != -1.0) { actor->GetProperty()->SetOpacity(m_Opacity); } + } else if (vtkAssembly *asm_p = vtkAssembly::SafeDownCast(p)) { + // Recursively apply to parts of the assembly + vtkProp3DCollection *parts = asm_p->GetParts(); + parts->InitTraversal(); + for (int i = 0; i < parts->GetNumberOfItems(); ++i) { + this->ApplyAppearance(parts->GetNextProp3D()); + } } }