feat: add TRS serialization and display property support to MultiSelectionProp
This commit is contained in:
@@ -569,6 +569,18 @@ void Prop3D::SetOpacity(double alpha)
|
|||||||
pd->ApplyAppearance(pd->m_Prop);
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -86,8 +86,10 @@ public:
|
|||||||
void DisonnectViewer(Viewer *viewer);
|
void DisonnectViewer(Viewer *viewer);
|
||||||
|
|
||||||
void SetColor(double r, double g, double b);
|
void SetColor(double r, double g, double b);
|
||||||
|
void GetColor(double &r, double &g, double &b) const;
|
||||||
|
|
||||||
void SetOpacity(double alpha);
|
void SetOpacity(double alpha);
|
||||||
|
double GetOpacity() const;
|
||||||
|
|
||||||
void SetSelectable(bool selectable = true);
|
void SetSelectable(bool selectable = true);
|
||||||
bool IsSelectable() const;
|
bool IsSelectable() const;
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "uLibVtkInterface.h"
|
||||||
#include "vtkMultiSelectionProp.h"
|
#include "vtkMultiSelectionProp.h"
|
||||||
#include <vtkActor.h>
|
#include <vtkActor.h>
|
||||||
#include <vtkPolyDataMapper.h>
|
#include <vtkPolyDataMapper.h>
|
||||||
@@ -13,17 +14,19 @@ namespace uLib {
|
|||||||
namespace Vtk {
|
namespace Vtk {
|
||||||
|
|
||||||
MultiSelectionProp::MultiSelectionProp() : Prop3D() {
|
MultiSelectionProp::MultiSelectionProp() : Prop3D() {
|
||||||
this->SetInstanceName("Selection Group");
|
((::uLib::Object*)this)->SetInstanceName("Selection Group");
|
||||||
m_PrevMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
m_PrevMatrix = vtkSmartPointer<vtkMatrix4x4>::New();
|
||||||
m_GroupHighlightActor = vtkSmartPointer<vtkActor>::New();
|
m_GroupHighlightActor = vtkSmartPointer<vtkActor>::New();
|
||||||
|
|
||||||
vtkNew<vtkPolyDataMapper> mapper;
|
vtkNew<vtkPolyDataMapper> mapper;
|
||||||
m_GroupHighlightActor->SetMapper(mapper);
|
m_GroupHighlightActor->SetMapper(mapper);
|
||||||
m_GroupHighlightActor->GetProperty()->SetRepresentationToWireframe();
|
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()->SetLineWidth(2.0);
|
||||||
m_GroupHighlightActor->GetProperty()->SetLighting(0);
|
m_GroupHighlightActor->GetProperty()->SetLighting(0);
|
||||||
m_GroupHighlightActor->PickableOff();
|
m_GroupHighlightActor->PickableOff();
|
||||||
|
|
||||||
|
// Set default display color in Prop3D state
|
||||||
|
((Prop3D*)this)->SetColor(0.0, 1.0, 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MultiSelectionProp::~MultiSelectionProp() {
|
MultiSelectionProp::~MultiSelectionProp() {
|
||||||
@@ -32,7 +35,7 @@ MultiSelectionProp::~MultiSelectionProp() {
|
|||||||
MultiSelectionProp* MultiSelectionProp::Clone() const {
|
MultiSelectionProp* MultiSelectionProp::Clone() const {
|
||||||
auto* copy = new MultiSelectionProp();
|
auto* copy = new MultiSelectionProp();
|
||||||
copy->SetMembers(this->m_Members);
|
copy->SetMembers(this->m_Members);
|
||||||
copy->SetInstanceName(this->GetInstanceName());
|
((::uLib::Object*)copy)->SetInstanceName(((::uLib::Object*)this)->GetInstanceName());
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,13 +91,22 @@ void MultiSelectionProp::Update() {
|
|||||||
mapper->SetInputConnection(cube->GetOutputPort());
|
mapper->SetInputConnection(cube->GetOutputPort());
|
||||||
}
|
}
|
||||||
|
|
||||||
// The highlight actor itself should have identity user matrix initially,
|
// Apply TRS from m_SelectionTransform
|
||||||
// as it's defined in world space bounds.
|
vtkNew<vtkMatrix4x4> trsMatrix;
|
||||||
m_GroupHighlightActor->SetUserMatrix(nullptr);
|
Matrix4fToVtk(m_SelectionTransform.GetWorldMatrix(), trsMatrix);
|
||||||
m_PrevMatrix->Identity();
|
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
|
// Ensure it's in the renderers
|
||||||
vtkRendererCollection* rens = this->GetRenderers();
|
vtkRendererCollection* rens = ((Prop3D*)this)->GetRenderers();
|
||||||
rens->InitTraversal();
|
rens->InitTraversal();
|
||||||
for (int i = 0; i < rens->GetNumberOfItems(); ++i) {
|
for (int i = 0; i < rens->GetNumberOfItems(); ++i) {
|
||||||
vtkRenderer* ren = rens->GetNextItem();
|
vtkRenderer* ren = rens->GetNextItem();
|
||||||
@@ -126,7 +138,6 @@ void MultiSelectionProp::SyncFromVtk() {
|
|||||||
vtkMatrix4x4::Multiply4x4(delta, memberWorldMatrix, nextWorldMatrix);
|
vtkMatrix4x4::Multiply4x4(delta, memberWorldMatrix, nextWorldMatrix);
|
||||||
|
|
||||||
// Set the new world matrix.
|
// Set the new world matrix.
|
||||||
// We need to calculate the new local matrix if there's a parent.
|
|
||||||
if (tr->GetParent()) {
|
if (tr->GetParent()) {
|
||||||
Matrix4f invParentWorld = tr->GetParent()->GetWorldMatrix().inverse();
|
Matrix4f invParentWorld = tr->GetParent()->GetWorldMatrix().inverse();
|
||||||
Matrix4f nextLocalMatrix = invParentWorld * VtkToMatrix4f(nextWorldMatrix);
|
Matrix4f nextLocalMatrix = invParentWorld * VtkToMatrix4f(nextWorldMatrix);
|
||||||
@@ -140,6 +151,7 @@ void MultiSelectionProp::SyncFromVtk() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
m_PrevMatrix->DeepCopy(currentMatrix);
|
m_PrevMatrix->DeepCopy(currentMatrix);
|
||||||
|
m_SelectionTransform.FromMatrix(VtkToMatrix4f(currentMatrix));
|
||||||
}
|
}
|
||||||
|
|
||||||
vtkProp* MultiSelectionProp::GetProp() {
|
vtkProp* MultiSelectionProp::GetProp() {
|
||||||
@@ -150,5 +162,14 @@ vtkProp3D* MultiSelectionProp::GetProxyProp() {
|
|||||||
return m_GroupHighlightActor;
|
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 Vtk
|
||||||
} // namespace uLib
|
} // namespace uLib
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define ULIB_VTK_MULTISELECTIONPROP_H
|
#define ULIB_VTK_MULTISELECTIONPROP_H
|
||||||
|
|
||||||
#include "uLibVtkInterface.h"
|
#include "uLibVtkInterface.h"
|
||||||
|
#include "Math/Transform.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
#include <vtkMatrix4x4.h>
|
#include <vtkMatrix4x4.h>
|
||||||
@@ -37,10 +38,21 @@ public:
|
|||||||
virtual vtkProp* GetProp() override;
|
virtual vtkProp* GetProp() override;
|
||||||
virtual vtkProp3D* GetProxyProp() 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<MultiSelectionProp*>(this); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<Prop3D*> m_Members;
|
std::vector<Prop3D*> m_Members;
|
||||||
|
uLib::TRS m_SelectionTransform;
|
||||||
vtkSmartPointer<vtkMatrix4x4> m_PrevMatrix;
|
vtkSmartPointer<vtkMatrix4x4> m_PrevMatrix;
|
||||||
vtkSmartPointer<vtkActor> m_GroupHighlightActor;
|
vtkSmartPointer<vtkActor> m_GroupHighlightActor;
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Vtk
|
} // namespace Vtk
|
||||||
|
|||||||
Reference in New Issue
Block a user