add vtk Properties

This commit is contained in:
AndreaRigoni
2026-03-23 15:09:35 +00:00
parent 94843de711
commit 5d0efb3078
9 changed files with 263 additions and 17 deletions

View File

@@ -3,6 +3,7 @@ set( TESTS
vtkViewerTest
vtkContainerBoxTest
vtkHandlerWidget
PuppetPropertyTest
# vtkVoxImageTest
# vtkTriangleMeshTest
)

View File

@@ -0,0 +1,68 @@
/*//////////////////////////////////////////////////////////////////////////////
// CMT Cosmic Muon Tomography project //////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
Copyright (c) 2014, Universita' degli Studi di Padova, INFN sez. di Padova
All rights reserved
Authors: Andrea Rigoni Garola < andrea.rigoni@pd.infn.it >
//////////////////////////////////////////////////////////////////////////////*/
#include "Vtk/uLibVtkInterface.h"
#include "Core/Property.h"
#include <iostream>
#include <cassert>
#include "testing-prototype.h"
using namespace uLib;
using namespace Vtk;
int main() {
BEGIN_TESTING(Puppet Property Registration Test);
std::cout << "Creating Puppet object..." << std::endl;
Puppet p;
// At this point, the Puppet constructor has called ULIB_ACTIVATE_PROPERTIES.
// This should have discovered the members used in Puppet::serialize()
// and registered them as uLib properties.
const auto& props = p.GetProperties();
std::cout << "Total registered properties: " << props.size() << std::endl;
// Verify specific properties exist
Property<double>* opacityProp = nullptr;
Property<double>* colorRProp = nullptr;
for (auto* prop : props) {
std::cout << " - [" << prop->GetTypeName() << "] " << prop->GetName()
<< " = " << prop->GetValueAsString() << std::endl;
if (prop->GetName() == "Opacity") {
opacityProp = dynamic_cast<Property<double>*>(prop);
}
if (prop->GetName() == "ColorR") {
colorRProp = dynamic_cast<Property<double>*>(prop);
}
}
assert(opacityProp != nullptr && "Opacity property not registered!");
assert(colorRProp != nullptr && "ColorR property not registered!");
// Test modification via uLib Property interface
std::cout << "Modifying Opacity via property proxy (0.25)..." << std::endl;
*opacityProp = 0.25;
// Verify the proxy correctly updated the underlying data
assert(opacityProp->Get() == 0.25);
assert(opacityProp->GetValueAsString().find("0.25") != std::string::npos);
std::cout << "Modifying ColorR via property proxy (0.9)..." << std::endl;
*colorRProp = 0.9;
assert(colorRProp->Get() == 0.9);
std::cout << "All Puppet Property Registration Tests PASSED!" << std::endl;
END_TESTING;
}

View File

@@ -60,6 +60,7 @@
#include "uLibVtkInterface.h"
#include "vtkHandlerWidget.h"
#include "Core/Property.h"
@@ -197,7 +198,12 @@ public:
Puppet::Puppet() : d(new PuppetData) { }
Puppet::Puppet() : Object(), d(new PuppetData) {
ULIB_ACTIVATE_PROPERTIES(*this);
for (auto* p : this->GetProperties()) {
uLib::Object::connect(p, &uLib::PropertyBase::Updated, this, &Puppet::Update);
}
}
Puppet::~Puppet()
{
@@ -442,6 +448,12 @@ bool Puppet::IsSelected() const
void Puppet::Update()
{
vtkProp3DCollection *props = d->m_Assembly->GetParts();
props->InitTraversal();
for (int i = 0; i < props->GetNumberOfItems(); ++i) {
d->ApplyAppearance(props->GetNextProp3D());
}
if (d->m_Selected) {
d->UpdateHighlight();
}
@@ -462,5 +474,19 @@ void Puppet::ConnectInteractor(vtkRenderWindowInteractor *interactor)
{
}
template <class Archive>
void Puppet::serialize(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]);
ar & boost::serialization::make_hrp("Opacity", d->m_Opacity);
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); }
} // namespace Vtk
} // namespace uLib

View File

@@ -28,6 +28,7 @@
#include <iomanip>
#include <ostream>
#include "Core/Object.h"
// vtk classes forward declaration //
class vtkProp;
@@ -41,7 +42,8 @@ class vtkRenderWindowInteractor;
namespace uLib {
namespace Vtk {
class Puppet {
class Puppet : public uLib::Object {
uLibTypeMacro(Puppet, uLib::Object)
public:
Puppet();
~Puppet();
@@ -90,6 +92,14 @@ public:
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);

View File

@@ -13,7 +13,7 @@ namespace Vtk {
/**
* @brief vtkObjectsContext manages VTK representations (Puppets) for a collection of uLib::Objects.
*/
class vtkObjectsContext : public uLib::Object, public Puppet {
class vtkObjectsContext : public Puppet {
public:
virtual const char* GetClassName() const override { return "vtkObjectsContext"; }
vtkObjectsContext(uLib::ObjectsContext *context);