diff --git a/src/Vtk/uLibVtkInterface.cxx b/src/Vtk/uLibVtkInterface.cxx index 9fab3ff..d341063 100644 --- a/src/Vtk/uLibVtkInterface.cxx +++ b/src/Vtk/uLibVtkInterface.cxx @@ -569,6 +569,18 @@ void Prop3D::SetOpacity(double alpha) pd->ApplyAppearance(pd->m_Prop); } +void Prop3D::GetColor(double &r, double &g, double &b) const +{ + r = pd->m_Color[0]; + g = pd->m_Color[1]; + b = pd->m_Color[2]; +} + +double Prop3D::GetOpacity() const +{ + return pd->m_Opacity; +} + diff --git a/src/Vtk/uLibVtkInterface.h b/src/Vtk/uLibVtkInterface.h index f47307c..d0f52bf 100644 --- a/src/Vtk/uLibVtkInterface.h +++ b/src/Vtk/uLibVtkInterface.h @@ -86,8 +86,10 @@ public: void DisonnectViewer(Viewer *viewer); void SetColor(double r, double g, double b); + void GetColor(double &r, double &g, double &b) const; void SetOpacity(double alpha); + double GetOpacity() const; void SetSelectable(bool selectable = true); bool IsSelectable() const; diff --git a/src/Vtk/vtkMultiSelectionProp.cpp b/src/Vtk/vtkMultiSelectionProp.cpp index b6131b4..c636939 100644 --- a/src/Vtk/vtkMultiSelectionProp.cpp +++ b/src/Vtk/vtkMultiSelectionProp.cpp @@ -1,3 +1,4 @@ +#include "uLibVtkInterface.h" #include "vtkMultiSelectionProp.h" #include #include @@ -13,17 +14,19 @@ namespace uLib { namespace Vtk { MultiSelectionProp::MultiSelectionProp() : Prop3D() { - this->SetInstanceName("Selection Group"); + ((::uLib::Object*)this)->SetInstanceName("Selection Group"); m_PrevMatrix = vtkSmartPointer::New(); m_GroupHighlightActor = vtkSmartPointer::New(); vtkNew mapper; m_GroupHighlightActor->SetMapper(mapper); m_GroupHighlightActor->GetProperty()->SetRepresentationToWireframe(); - m_GroupHighlightActor->GetProperty()->SetColor(0.0, 1.0, 0.0); // Green for group m_GroupHighlightActor->GetProperty()->SetLineWidth(2.0); m_GroupHighlightActor->GetProperty()->SetLighting(0); m_GroupHighlightActor->PickableOff(); + + // Set default display color in Prop3D state + ((Prop3D*)this)->SetColor(0.0, 1.0, 0.0); } MultiSelectionProp::~MultiSelectionProp() { @@ -32,7 +35,7 @@ MultiSelectionProp::~MultiSelectionProp() { MultiSelectionProp* MultiSelectionProp::Clone() const { auto* copy = new MultiSelectionProp(); copy->SetMembers(this->m_Members); - copy->SetInstanceName(this->GetInstanceName()); + ((::uLib::Object*)copy)->SetInstanceName(((::uLib::Object*)this)->GetInstanceName()); return copy; } @@ -88,13 +91,22 @@ void MultiSelectionProp::Update() { mapper->SetInputConnection(cube->GetOutputPort()); } - // The highlight actor itself should have identity user matrix initially, - // as it's defined in world space bounds. - m_GroupHighlightActor->SetUserMatrix(nullptr); - m_PrevMatrix->Identity(); + // Apply TRS from m_SelectionTransform + vtkNew trsMatrix; + Matrix4fToVtk(m_SelectionTransform.GetWorldMatrix(), trsMatrix); + m_GroupHighlightActor->SetUserMatrix(trsMatrix); + + // Apply Display Properties (Color, Opacity) + double r, g, b; + ((Prop3D*)this)->GetColor(r, g, b); + m_GroupHighlightActor->GetProperty()->SetColor(r, g, b); + m_GroupHighlightActor->GetProperty()->SetOpacity(((Prop3D*)this)->GetOpacity()); + + // Update Prev Matrix for delta calculations + m_PrevMatrix->DeepCopy(trsMatrix); // Ensure it's in the renderers - vtkRendererCollection* rens = this->GetRenderers(); + vtkRendererCollection* rens = ((Prop3D*)this)->GetRenderers(); rens->InitTraversal(); for (int i = 0; i < rens->GetNumberOfItems(); ++i) { vtkRenderer* ren = rens->GetNextItem(); @@ -126,7 +138,6 @@ void MultiSelectionProp::SyncFromVtk() { vtkMatrix4x4::Multiply4x4(delta, memberWorldMatrix, nextWorldMatrix); // Set the new world matrix. - // We need to calculate the new local matrix if there's a parent. if (tr->GetParent()) { Matrix4f invParentWorld = tr->GetParent()->GetWorldMatrix().inverse(); Matrix4f nextLocalMatrix = invParentWorld * VtkToMatrix4f(nextWorldMatrix); @@ -140,6 +151,7 @@ void MultiSelectionProp::SyncFromVtk() { } m_PrevMatrix->DeepCopy(currentMatrix); + m_SelectionTransform.FromMatrix(VtkToMatrix4f(currentMatrix)); } vtkProp* MultiSelectionProp::GetProp() { @@ -150,5 +162,14 @@ vtkProp3D* MultiSelectionProp::GetProxyProp() { return m_GroupHighlightActor; } +void MultiSelectionProp::serialize(Archive::property_register_archive &ar, const unsigned int version) { + ar & boost::serialization::make_nvp("Transform", m_SelectionTransform); +} + +void MultiSelectionProp::serialize_display(uLib::Archive::display_properties_archive &ar, const unsigned int version) { + // Call base class to register standard display properties (Color, Opacity) + ((Prop3D*)this)->serialize_display(ar, version); +} + } // namespace Vtk } // namespace uLib diff --git a/src/Vtk/vtkMultiSelectionProp.h b/src/Vtk/vtkMultiSelectionProp.h index 0030c89..fca4394 100644 --- a/src/Vtk/vtkMultiSelectionProp.h +++ b/src/Vtk/vtkMultiSelectionProp.h @@ -2,6 +2,7 @@ #define ULIB_VTK_MULTISELECTIONPROP_H #include "uLibVtkInterface.h" +#include "Math/Transform.h" #include #include #include @@ -37,10 +38,21 @@ public: virtual vtkProp* GetProp() override; virtual vtkProp3D* GetProxyProp() override; + // Serialization for Properties Panel (TRS) + void serialize(Archive::property_register_archive &ar, const unsigned int version); + + // Serialization for Display Properties Panel (Color, Opacity) + void serialize_display(uLib::Archive::display_properties_archive &ar, const unsigned int version = 0) override; + + virtual uLib::Object* GetContent() const override { return const_cast(this); } + private: std::vector m_Members; + uLib::TRS m_SelectionTransform; vtkSmartPointer m_PrevMatrix; vtkSmartPointer m_GroupHighlightActor; + + }; } // namespace Vtk