add properties groups
This commit is contained in:
@@ -61,6 +61,7 @@
|
||||
|
||||
#include "uLibVtkInterface.h"
|
||||
#include "vtkHandlerWidget.h"
|
||||
#include "Math/Dense.h"
|
||||
#include "Core/Property.h"
|
||||
|
||||
|
||||
@@ -96,9 +97,9 @@ public:
|
||||
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;
|
||||
m_Position = Vector3d::Zero();
|
||||
m_Orientation = Vector3d::Zero();
|
||||
m_Scale = Vector3d::Ones();
|
||||
}
|
||||
|
||||
~PuppetData() {
|
||||
@@ -124,9 +125,9 @@ public:
|
||||
bool m_Selected;
|
||||
bool m_Visibility;
|
||||
bool m_Dragable;
|
||||
double m_Position[3];
|
||||
double m_Orientation[3];
|
||||
double m_Scale[3];
|
||||
Vector3d m_Position;
|
||||
Vector3d m_Orientation;
|
||||
Vector3d m_Scale;
|
||||
|
||||
void ApplyAppearance(vtkProp *p) {
|
||||
p->SetVisibility(m_Visibility);
|
||||
@@ -156,9 +157,9 @@ public:
|
||||
// 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);
|
||||
// p3d->SetPosition(m_Position.data());
|
||||
// p3d->SetOrientation(m_Orientation.data());
|
||||
// p3d->SetScale(m_Scale.data());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -499,9 +500,9 @@ void Puppet::Update()
|
||||
|
||||
// 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);
|
||||
p3d->SetPosition(pd->m_Position.data());
|
||||
p3d->SetOrientation(pd->m_Orientation.data());
|
||||
p3d->SetScale(pd->m_Scale.data());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -549,9 +550,9 @@ void Puppet::SyncFromVtk()
|
||||
|
||||
// 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];
|
||||
pd->m_Position(i) = pos[i];
|
||||
pd->m_Orientation(i) = ori[i];
|
||||
pd->m_Scale(i) = scale[i];
|
||||
}
|
||||
|
||||
// Get the properties from the object
|
||||
@@ -567,26 +568,37 @@ void Puppet::ConnectInteractor(vtkRenderWindowInteractor *interactor)
|
||||
{
|
||||
}
|
||||
|
||||
struct TransformProxy {
|
||||
PuppetData* pd;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_hrp("Position", pd->m_Position, "mm");
|
||||
ar & boost::serialization::make_hrp("Orientation", pd->m_Orientation, "deg");
|
||||
ar & boost::serialization::make_hrp("Scale", pd->m_Scale, "");
|
||||
}
|
||||
};
|
||||
|
||||
struct AppearanceProxy {
|
||||
PuppetData* pd;
|
||||
template<class Archive>
|
||||
void serialize(Archive & ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_hrp("ColorR", pd->m_Color[0]);
|
||||
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_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);
|
||||
}
|
||||
};
|
||||
|
||||
void Puppet::serialize_display(Archive::display_properties_archive & ar, const unsigned int version) {
|
||||
ar & boost::serialization::make_hrp("ColorR", pd->m_Color[0]);
|
||||
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_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);
|
||||
AppearanceProxy appearance{pd};
|
||||
ar & boost::serialization::make_nvp("Appearance", appearance);
|
||||
|
||||
// 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]);
|
||||
TransformProxy transform{pd};
|
||||
ar & boost::serialization::make_nvp("Transform", transform);
|
||||
}
|
||||
|
||||
void Puppet::serialize(Archive::xml_oarchive & ar, const unsigned int v) { }
|
||||
|
||||
@@ -29,6 +29,9 @@
|
||||
#include <iomanip>
|
||||
#include <ostream>
|
||||
#include <vector>
|
||||
#include <boost/type_traits/is_class.hpp>
|
||||
#include <boost/mpl/bool.hpp>
|
||||
#include <boost/serialization/serialization.hpp>
|
||||
#include "Core/Object.h"
|
||||
#include "Core/Property.h"
|
||||
#include "Core/Monitor.h"
|
||||
@@ -157,10 +160,19 @@ public:
|
||||
boost::archive::detail::common_oarchive<display_properties_archive>(boost::archive::no_header),
|
||||
m_Puppet(puppet) {}
|
||||
|
||||
std::string GetCurrentGroup() const {
|
||||
std::string group;
|
||||
for (const auto& g : m_GroupStack) {
|
||||
if (!group.empty()) group += ".";
|
||||
group += g;
|
||||
}
|
||||
return group;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void save_override(const boost::serialization::hrp<T> &t) {
|
||||
if (m_Puppet) {
|
||||
uLib::Property<T>* p = new uLib::Property<T>(m_Puppet, t.name(), &const_cast<boost::serialization::hrp<T>&>(t).value(), t.units() ? t.units() : "");
|
||||
uLib::Property<T>* p = new uLib::Property<T>(m_Puppet, t.name(), &const_cast<boost::serialization::hrp<T>&>(t).value(), t.units() ? t.units() : "", GetCurrentGroup());
|
||||
m_Puppet->RegisterDisplayProperty(p);
|
||||
Vtk::Puppet* puppet = m_Puppet;
|
||||
uLib::Object::connect(p, &uLib::PropertyBase::Updated, [puppet](){ puppet->Update(); });
|
||||
@@ -170,7 +182,7 @@ public:
|
||||
template<class T>
|
||||
void save_override(const boost::serialization::hrp_enum<T> &t) {
|
||||
if (m_Puppet) {
|
||||
uLib::EnumProperty* p = new uLib::EnumProperty(m_Puppet, t.name(), (int*)&const_cast<boost::serialization::hrp_enum<T>&>(t).value(), t.labels(), t.units() ? t.units() : "");
|
||||
uLib::EnumProperty* p = new uLib::EnumProperty(m_Puppet, t.name(), (int*)&const_cast<boost::serialization::hrp_enum<T>&>(t).value(), t.labels(), t.units() ? t.units() : "", GetCurrentGroup());
|
||||
m_Puppet->RegisterDisplayProperty(p);
|
||||
Vtk::Puppet* puppet = m_Puppet;
|
||||
uLib::Object::connect(p, &uLib::PropertyBase::Updated, [puppet](){ puppet->Update(); });
|
||||
@@ -178,10 +190,23 @@ public:
|
||||
}
|
||||
|
||||
template<class T> void save_override(const boost::serialization::nvp<T> &t) {
|
||||
boost::archive::detail::common_oarchive<display_properties_archive>::save_override(t.const_value());
|
||||
if (t.name()) m_GroupStack.push_back(t.name());
|
||||
this->save_helper(t.const_value(), typename boost::is_class<T>::type());
|
||||
if (t.name()) m_GroupStack.pop_back();
|
||||
}
|
||||
|
||||
template<class T> void save_override(const T &t) {}
|
||||
// Recursion for nested classes, ignore primitives
|
||||
template<class T> void save_override(const T &t) {
|
||||
this->save_helper(t, typename boost::is_class<T>::type());
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void save_helper(const T &t, boost::mpl::true_) {
|
||||
boost::serialization::serialize_adl(*this, const_cast<T&>(t), 0);
|
||||
}
|
||||
|
||||
template<class T>
|
||||
void save_helper(const T &t, boost::mpl::false_) {}
|
||||
|
||||
void save_override(const boost::archive::object_id_type & t) {}
|
||||
void save_override(const boost::archive::object_reference_type & t) {}
|
||||
@@ -194,6 +219,7 @@ public:
|
||||
|
||||
private:
|
||||
Vtk::Puppet* m_Puppet;
|
||||
std::vector<std::string> m_GroupStack;
|
||||
};
|
||||
|
||||
} // namespace Archive
|
||||
|
||||
Reference in New Issue
Block a user