fix some on properties and signal connection
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
#include <vtkPolyData.h>
|
||||
#include <vtkFeatureEdges.h>
|
||||
#include <vtkTransform.h>
|
||||
#include <vtkRenderWindow.h>
|
||||
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkHandlerWidget.h"
|
||||
@@ -87,12 +88,17 @@ public:
|
||||
m_Assembly(vtkSmartPointer<vtkAssembly>::New()),
|
||||
m_ShowBoundingBox(false),
|
||||
m_ShowScaleMeasures(false),
|
||||
m_Representation(-1),
|
||||
m_Representation(Puppet::Surface),
|
||||
m_Opacity(-1.0),
|
||||
m_Selectable(true),
|
||||
m_Selected(false)
|
||||
m_Selected(false),
|
||||
m_Visibility(true),
|
||||
m_Dragable(true)
|
||||
{
|
||||
m_Color[0] = m_Color[1] = m_Color[2] = -1.0;
|
||||
m_Position[0] = m_Position[1] = m_Position[2] = 0.0;
|
||||
m_Orientation[0] = m_Orientation[1] = m_Orientation[2] = 0.0;
|
||||
m_Scale[0] = m_Scale[1] = m_Scale[2] = 1.0;
|
||||
}
|
||||
|
||||
~PuppetData() {
|
||||
@@ -110,25 +116,49 @@ public:
|
||||
|
||||
bool m_ShowBoundingBox;
|
||||
bool m_ShowScaleMeasures;
|
||||
|
||||
int m_Representation;
|
||||
double m_Color[3];
|
||||
double m_Opacity;
|
||||
|
||||
bool m_Selectable;
|
||||
bool m_Selected;
|
||||
bool m_Visibility;
|
||||
bool m_Dragable;
|
||||
double m_Position[3];
|
||||
double m_Orientation[3];
|
||||
double m_Scale[3];
|
||||
|
||||
void ApplyAppearance(vtkProp *p) {
|
||||
p->SetVisibility(m_Visibility);
|
||||
p->SetPickable(m_Selectable);
|
||||
p->SetDragable(m_Dragable);
|
||||
|
||||
vtkActor *actor = vtkActor::SafeDownCast(p);
|
||||
if (!actor) return;
|
||||
if (actor) {
|
||||
if (m_Representation != -1) {
|
||||
if (m_Representation == Puppet::SurfaceWithEdges) {
|
||||
actor->GetProperty()->SetRepresentation(VTK_SURFACE);
|
||||
actor->GetProperty()->SetEdgeVisibility(1);
|
||||
} else {
|
||||
actor->GetProperty()->SetRepresentation(m_Representation);
|
||||
actor->GetProperty()->SetEdgeVisibility(0);
|
||||
}
|
||||
}
|
||||
if (m_Color[0] != -1.0) {
|
||||
actor->GetProperty()->SetColor(m_Color);
|
||||
}
|
||||
|
||||
if (m_Representation != -1) {
|
||||
actor->GetProperty()->SetRepresentation(m_Representation);
|
||||
if (m_Opacity != -1.0) {
|
||||
actor->GetProperty()->SetOpacity(m_Opacity);
|
||||
}
|
||||
}
|
||||
|
||||
if (m_Color[0] != -1.0) {
|
||||
actor->GetProperty()->SetColor(m_Color);
|
||||
}
|
||||
|
||||
if (m_Opacity != -1.0) {
|
||||
actor->GetProperty()->SetOpacity(m_Opacity);
|
||||
// Handle transformation if it's a Prop3D
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(p)) {
|
||||
// NOTE: Usually managed by Puppet::Update from model, but here for direct prop manipulation
|
||||
// p3d->SetPosition(m_Position);
|
||||
// p3d->SetOrientation(m_Orientation);
|
||||
// p3d->SetScale(m_Scale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -188,9 +218,6 @@ public:
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool m_Selectable;
|
||||
bool m_Selected;
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------- //
|
||||
@@ -226,6 +253,21 @@ void Puppet::SetProp(vtkProp *prop)
|
||||
pd->m_Assembly->AddPart(p3d);
|
||||
}
|
||||
pd->ApplyAppearance(prop);
|
||||
|
||||
// For the first actor added, seed the tracked display values from the VTK
|
||||
// actor's current state so the display properties panel shows meaningful
|
||||
// initial values instead of the -1 "not-overriding" sentinels.
|
||||
if (pd->m_Assembly->GetParts()->GetNumberOfItems() == 1) {
|
||||
if (auto* actor = vtkActor::SafeDownCast(prop)) {
|
||||
vtkProperty* vp = actor->GetProperty();
|
||||
if (pd->m_Representation < 0)
|
||||
pd->m_Representation = vp->GetRepresentation();
|
||||
if (pd->m_Opacity < 0)
|
||||
pd->m_Opacity = vp->GetOpacity();
|
||||
if (pd->m_Color[0] < 0)
|
||||
vp->GetColor(pd->m_Color);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -370,13 +412,7 @@ void Puppet::ShowScaleMeasures(bool show)
|
||||
|
||||
void Puppet::SetRepresentation(Representation mode)
|
||||
{
|
||||
int rep = VTK_SURFACE;
|
||||
switch (mode) {
|
||||
case Points: rep = VTK_POINTS; break;
|
||||
case Wireframe: rep = VTK_WIREFRAME; break;
|
||||
case Surface: rep = VTK_SURFACE; break;
|
||||
}
|
||||
pd->m_Representation = rep;
|
||||
pd->m_Representation = static_cast<int>(mode);
|
||||
|
||||
vtkProp3DCollection *props = pd->m_Assembly->GetParts();
|
||||
props->InitTraversal();
|
||||
@@ -391,6 +427,10 @@ void Puppet::SetRepresentation(const char *mode)
|
||||
if (s == "points") SetRepresentation(Points);
|
||||
else if (s == "wireframe") SetRepresentation(Wireframe);
|
||||
else if (s == "shaded" || s == "surface") SetRepresentation(Surface);
|
||||
else if (s == "edges" || s == "surface+edges" || s == "surfacewithedges") SetRepresentation(SurfaceWithEdges);
|
||||
else if (s == "volume") SetRepresentation(Volume);
|
||||
else if (s == "outline") SetRepresentation(Outline);
|
||||
else if (s == "slice") SetRepresentation(Slice);
|
||||
}
|
||||
|
||||
void Puppet::SetColor(double r, double g, double b)
|
||||
@@ -453,6 +493,18 @@ bool Puppet::IsSelected() const
|
||||
|
||||
void Puppet::Update()
|
||||
{
|
||||
vtkProp* root = this->GetProp();
|
||||
if (root) {
|
||||
pd->ApplyAppearance(root);
|
||||
|
||||
// Apply transformation if it's a Prop3D
|
||||
if (auto* p3d = vtkProp3D::SafeDownCast(root)) {
|
||||
p3d->SetPosition(pd->m_Position);
|
||||
p3d->SetOrientation(pd->m_Orientation);
|
||||
p3d->SetScale(pd->m_Scale);
|
||||
}
|
||||
}
|
||||
|
||||
vtkProp3DCollection *props = pd->m_Assembly->GetParts();
|
||||
props->InitTraversal();
|
||||
for (int i = 0; i < props->GetNumberOfItems(); ++i) {
|
||||
@@ -473,6 +525,42 @@ void Puppet::Update()
|
||||
double* bounds = pd->m_Assembly->GetBounds();
|
||||
pd->m_CubeAxesActor->SetBounds(bounds);
|
||||
}
|
||||
|
||||
// Notify that the object has been updated (important for UI refresh)
|
||||
this->Object::Updated();
|
||||
|
||||
// Trigger immediate re-render of all connected viewports
|
||||
pd->m_Renderers->InitTraversal();
|
||||
for (int i = 0; i < pd->m_Renderers->GetNumberOfItems(); ++i) {
|
||||
if (auto* ren = pd->m_Renderers->GetNextItem()) {
|
||||
if (ren->GetRenderWindow()) ren->GetRenderWindow()->Render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
// Get the properties from the object
|
||||
if (auto* propPos = this->GetProperty("Position")) propPos->Updated();
|
||||
if (auto* propOri = this->GetProperty("Orientation")) propOri->Updated();
|
||||
if (auto* propScale = this->GetProperty("Scale")) propScale->Updated();
|
||||
|
||||
this->Object::Updated();
|
||||
}
|
||||
}
|
||||
|
||||
void Puppet::ConnectInteractor(vtkRenderWindowInteractor *interactor)
|
||||
@@ -484,7 +572,21 @@ void Puppet::serialize_display(Archive::display_properties_archive & ar, const u
|
||||
ar & boost::serialization::make_hrp("ColorG", pd->m_Color[1]);
|
||||
ar & boost::serialization::make_hrp("ColorB", pd->m_Color[2]);
|
||||
ar & boost::serialization::make_hrp("Opacity", pd->m_Opacity);
|
||||
ar & boost::serialization::make_hrp("Representation", pd->m_Representation);
|
||||
ar & boost::serialization::make_hrp_enum("Representation", pd->m_Representation, {"Points", "Wireframe", "Surface", "SurfaceWithEdges", "Volume", "Outline", "Slice"});
|
||||
ar & boost::serialization::make_hrp("Visibility", pd->m_Visibility);
|
||||
ar & boost::serialization::make_hrp("Pickable", pd->m_Selectable);
|
||||
ar & boost::serialization::make_hrp("Dragable", pd->m_Dragable);
|
||||
|
||||
// Geometry knobs (caution: these might be overridden by internal matrices)
|
||||
ar & boost::serialization::make_hrp("PosX", pd->m_Position[0], "mm");
|
||||
ar & boost::serialization::make_hrp("PosY", pd->m_Position[1], "mm");
|
||||
ar & boost::serialization::make_hrp("PosZ", pd->m_Position[2], "mm");
|
||||
ar & boost::serialization::make_hrp("OriX", pd->m_Orientation[0], "deg");
|
||||
ar & boost::serialization::make_hrp("OriY", pd->m_Orientation[1], "deg");
|
||||
ar & boost::serialization::make_hrp("OriZ", pd->m_Orientation[2], "deg");
|
||||
ar & boost::serialization::make_hrp("ScaleX", pd->m_Scale[0]);
|
||||
ar & boost::serialization::make_hrp("ScaleY", pd->m_Scale[1]);
|
||||
ar & boost::serialization::make_hrp("ScaleZ", pd->m_Scale[2]);
|
||||
}
|
||||
|
||||
void Puppet::serialize(Archive::xml_oarchive & ar, const unsigned int v) { }
|
||||
|
||||
Reference in New Issue
Block a user