vtkProperties

This commit is contained in:
AndreaRigoni
2026-03-23 17:46:42 +00:00
parent 5d0efb3078
commit f13342ff30
19 changed files with 745 additions and 186 deletions

View File

@@ -99,6 +99,15 @@ public:
template <class ArchiveT>
void serialize(ArchiveT &ar, const unsigned int version);
virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) {}
virtual void serialize(Archive::xml_iarchive & ar, const unsigned int version) {}
virtual void serialize(Archive::text_oarchive & ar, const unsigned int version) {}
virtual void serialize(Archive::text_iarchive & ar, const unsigned int version) {}
virtual void serialize(Archive::hrt_oarchive & ar, const unsigned int version) {}
virtual void serialize(Archive::hrt_iarchive & ar, const unsigned int version) {}
virtual void serialize(Archive::log_archive & ar, const unsigned int version) {}
template <class ArchiveT>
void save_override(ArchiveT &ar, const unsigned int version);

View File

@@ -4,6 +4,7 @@
#include <string>
#include <sstream>
#include <typeinfo>
#include <typeindex> // Added
#include <boost/serialization/nvp.hpp>
#include <boost/lexical_cast.hpp>
#include "Core/Archives.h"
@@ -21,6 +22,7 @@ public:
virtual const std::string& GetName() const = 0;
virtual const char* GetTypeName() const = 0;
virtual std::string GetValueAsString() const = 0;
virtual std::type_index GetTypeIndex() const = 0; // Added
// Signal support
signals:
@@ -62,8 +64,11 @@ public:
if (m_own) delete m_value;
}
const std::string& GetName() const override { return m_name; }
const char* GetTypeName() const override { return typeid(T).name(); }
// Identification
virtual const std::string& GetName() const override { return m_name; }
virtual const char* GetTypeName() const override { return typeid(T).name(); }
virtual std::type_index GetTypeIndex() const override { return std::type_index(typeid(T)); }
std::string GetValueAsString() const override {
try {
@@ -191,7 +196,7 @@ public:
// Handle standard NVPs by recursing (important for base classes)
template<class T>
void save_override(const boost::serialization::nvp<T> &t) {
this->detail_common_oarchive::save_override(t.const_value());
boost::archive::detail::common_oarchive<property_register_archive>::save_override(t.const_value());
}
// Ignore everything else

View File

@@ -58,7 +58,7 @@ class vtkActor;
namespace uLib {
namespace Vtk {
class vtkVoxRaytracerRepresentation : public Puppet, public Object {
class vtkVoxRaytracerRepresentation : public Puppet {
typedef VoxRaytracer Content;
public:

View File

@@ -199,8 +199,8 @@ public:
Puppet::Puppet() : Object(), d(new PuppetData) {
ULIB_ACTIVATE_PROPERTIES(*this);
for (auto* p : this->GetProperties()) {
ULIB_ACTIVATE_DISPLAY_PROPERTIES;
for (auto* p : this->GetDisplayProperties()) {
uLib::Object::connect(p, &uLib::PropertyBase::Updated, this, &Puppet::Update);
}
}
@@ -235,6 +235,11 @@ void Puppet::RemoveProp(vtkProp *prop)
}
vtkPropCollection *Puppet::GetParts()
{
return d->m_Assembly->GetParts();
}
vtkPropCollection *Puppet::GetProps()
{
return d->m_Assembly->GetParts();
@@ -474,8 +479,7 @@ void Puppet::ConnectInteractor(vtkRenderWindowInteractor *interactor)
{
}
template <class Archive>
void Puppet::serialize(Archive & ar, const unsigned int version) {
void Puppet::serialize_display(Archive::display_properties_archive & ar, const unsigned int version) {
ar & boost::serialization::make_hrp("ColorR", d->m_Color[0]);
ar & boost::serialization::make_hrp("ColorG", d->m_Color[1]);
ar & boost::serialization::make_hrp("ColorB", d->m_Color[2]);
@@ -483,10 +487,13 @@ void Puppet::serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::make_hrp("Representation", d->m_Representation);
}
void Puppet::save_override(Archive::xml_oarchive & ar, const unsigned int v) { serialize(ar, v); }
void Puppet::save_override(Archive::hrt_oarchive & ar, const unsigned int v) { serialize(ar, v); }
void Puppet::save_override(Archive::log_archive & ar, const unsigned int v) { serialize(ar, v); }
void Puppet::save_override(Archive::text_oarchive & ar, const unsigned int v) { serialize(ar, v); }
void Puppet::serialize(Archive::xml_oarchive & ar, const unsigned int v) { }
void Puppet::serialize(Archive::xml_iarchive & ar, const unsigned int v) { }
void Puppet::serialize(Archive::text_oarchive & ar, const unsigned int v) { }
void Puppet::serialize(Archive::text_iarchive & ar, const unsigned int v) { }
void Puppet::serialize(Archive::hrt_oarchive & ar, const unsigned int v) { }
void Puppet::serialize(Archive::hrt_iarchive & ar, const unsigned int v) { }
void Puppet::serialize(Archive::log_archive & ar, const unsigned int v) { }
} // namespace Vtk
} // namespace uLib

View File

@@ -28,7 +28,9 @@
#include <iomanip>
#include <ostream>
#include <vector>
#include "Core/Object.h"
#include "Core/Property.h"
// vtk classes forward declaration //
class vtkProp;
@@ -38,6 +40,10 @@ class vtkRenderer;
class vtkRendererCollection;
class vtkRenderWindowInteractor;
namespace uLib {
namespace Archive { class display_properties_archive; }
namespace Vtk { class Puppet; class Viewer; }
}
namespace uLib {
namespace Vtk {
@@ -46,37 +52,21 @@ class Puppet : public uLib::Object {
uLibTypeMacro(Puppet, uLib::Object)
public:
Puppet();
~Puppet();
virtual ~Puppet();
virtual vtkProp *GetProp();
virtual vtkPropCollection *GetParts();
virtual vtkPropCollection *GetProps();
void ConnectRenderer(vtkRenderer *renderer);
void DisconnectRenderer(vtkRenderer *renderer);
void ConnectViewer(class Viewer *viewer);
void ConnectViewer(Viewer *viewer);
void DisonnectViewer(class Viewer *viewer);
vtkRendererCollection *GetRenderers() const;
enum Representation {
Points,
Wireframe,
Surface
};
virtual void PrintSelf(std::ostream &o) const;
void ShowBoundingBox(bool show = true);
void ShowScaleMeasures(bool show = true);
void SetRepresentation(Representation mode);
void SetRepresentation(const char *mode);
void DisonnectViewer(Viewer *viewer);
void SetColor(double r, double g, double b);
@@ -90,21 +80,39 @@ public:
virtual void Update();
enum Representation { Points, Wireframe, Surface };
void SetRepresentation(Representation mode);
void SetRepresentation(const char *mode);
virtual void PrintSelf(std::ostream &o) const;
void ShowBoundingBox(bool show);
void ShowScaleMeasures(bool show);
vtkRendererCollection *GetRenderers() const;
virtual void serialize(Archive::xml_oarchive & ar, const unsigned int version) override;
virtual void serialize(Archive::xml_iarchive & ar, const unsigned int version) override;
virtual void serialize(Archive::text_oarchive & ar, const unsigned int version) override;
virtual void serialize(Archive::text_iarchive & ar, const unsigned int version) override;
virtual void serialize(Archive::hrt_oarchive & ar, const unsigned int version) override;
virtual void serialize(Archive::hrt_iarchive & ar, const unsigned int version) override;
virtual void serialize(Archive::log_archive & ar, const unsigned int version) override;
const std::vector<uLib::PropertyBase*>& GetDisplayProperties() const { return m_DisplayProperties; }
void RegisterDisplayProperty(uLib::PropertyBase* prop) { m_DisplayProperties.push_back(prop); }
virtual void serialize_display(uLib::Archive::display_properties_archive & ar, const unsigned int version = 0);
virtual void ConnectInteractor(class vtkRenderWindowInteractor *interactor);
// Serialization and Reflection
template<class Archive>
void serialize(Archive & ar, const unsigned int version);
void save_override(Archive::xml_oarchive & ar, const unsigned int version);
void save_override(Archive::hrt_oarchive & ar, const unsigned int version);
void save_override(Archive::log_archive & ar, const unsigned int version);
void save_override(Archive::text_oarchive & ar, const unsigned int version);
protected:
void SetProp(vtkProp *prop);
void RemoveProp(vtkProp *prop);
std::vector<uLib::PropertyBase*> m_DisplayProperties;
private:
Puppet(const Puppet&) = delete;
Puppet& operator=(const Puppet&) = delete;
@@ -113,11 +121,60 @@ private:
class PuppetData *d;
};
} // namespace Vtk
} // namespace uLib
// -------------------------------------------------------------------------- //
namespace uLib {
namespace Archive {
/**
* @brief Specialized archive for registering display-only properties in Puppets.
*/
class display_properties_archive : public boost::archive::detail::common_oarchive<display_properties_archive> {
public:
display_properties_archive(Vtk::Puppet* puppet) :
boost::archive::detail::common_oarchive<display_properties_archive>(boost::archive::no_header),
m_Puppet(puppet) {}
template<class T>
void save_override(const boost::serialization::hrp<T> &t) {
if (m_Puppet) {
m_Puppet->RegisterDisplayProperty(
new uLib::Property<T>(m_Puppet, t.name(), &const_cast<boost::serialization::hrp<T>&>(t).value())
);
}
}
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());
}
template<class T> void save_override(const T &t) {}
void save_override(const boost::archive::object_id_type & t) {}
void save_override(const boost::archive::object_reference_type & t) {}
void save_override(const boost::archive::version_type & t) {}
void save_override(const boost::archive::class_id_type & t) {}
void save_override(const boost::archive::class_id_optional_type & t) {}
void save_override(const boost::archive::class_id_reference_type & t) {}
void save_override(const boost::archive::class_name_type & t) {}
void save_override(const boost::archive::tracking_type & t) {}
private:
Vtk::Puppet* m_Puppet;
};
} // namespace Archive
// This macro MUST be defined after both Puppet and display_properties_archive are fully defined.
#define ULIB_ACTIVATE_DISPLAY_PROPERTIES \
{ \
uLib::Archive::display_properties_archive dar(this); \
this->serialize_display(dar, 0); \
}
} // namespace uLib
#endif // ULIBVTKINTERFACE_H