From a8d275123aa2cc2d13e6b9fe047db6756ad5cfc1 Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Tue, 13 Oct 2020 16:46:51 +0200 Subject: [PATCH 1/2] add unittest to check if mesh property initialization works --- src/Unittests/unittests_propertymanager.cc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Unittests/unittests_propertymanager.cc b/src/Unittests/unittests_propertymanager.cc index 87c92b95..d620f3ec 100644 --- a/src/Unittests/unittests_propertymanager.cc +++ b/src/Unittests/unittests_propertymanager.cc @@ -870,5 +870,12 @@ TEST_F(OpenMeshPropertyManager, return_property_from_function) { } +TEST_F(OpenMeshPropertyManager, mesh_property_initialization) { + + OpenMesh::MProp mesh_id(13, mesh_); + ASSERT_EQ(mesh_id(), 13); +} + + } From 657dc2c8912db5f0ba242e874e31ba11b334b93d Mon Sep 17 00:00:00 2001 From: Max Lyon Date: Tue, 13 Oct 2020 16:50:40 +0200 Subject: [PATCH 2/2] add support for initializing property managers of mesh properties --- src/OpenMesh/Core/Utils/PropertyManager.hh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/OpenMesh/Core/Utils/PropertyManager.hh b/src/OpenMesh/Core/Utils/PropertyManager.hh index b5d07764..62d87b76 100644 --- a/src/OpenMesh/Core/Utils/PropertyManager.hh +++ b/src/OpenMesh/Core/Utils/PropertyManager.hh @@ -85,14 +85,17 @@ class PropertyManager { private: // Mesh properties (MPropHandleT<...>) are stored differently than the other properties. - // This class implements different behavior when copying or swapping data from one - // property manager to a another one. + // This class implements different behavior when initializing a property or when + // copying or swapping data from one property manager to a another one. template struct StorageT; // specialization for Mesh Properties template struct StorageT> { + static void initialize(PropertyManager& pm, const Value& initial_value ) { + pm() = initial_value; + } static void copy(const PropertyManager& from, PropertyManager2& to) { *to = *from; } @@ -110,6 +113,9 @@ class PropertyManager { // definition for other Mesh Properties template struct StorageT { + static void initialize(PropertyManager& pm, const Value& initial_value ) { + pm.set_range(pm.mesh_.template all_elements(), initial_value); + } static void copy(const PropertyManager& from, PropertyManager2& to) { from.copy_to(from.mesh_.template all_elements(), to, to.mesh_.template all_elements()); } @@ -190,7 +196,7 @@ class PropertyManager { PropertyManager(const Value& initial_value, PolyConnectivity& mesh, const char *propname) : mesh_(mesh), retain_(true), name_(propname) { if (!mesh_.get_property_handle(prop_, propname)) { PropertyManager::mesh().add_property(prop_, propname); - set_range(mesh_.all_elements(), initial_value); + Storage::initialize(*this, initial_value); } } @@ -215,7 +221,7 @@ class PropertyManager { */ PropertyManager(const Value& initial_value, const PolyConnectivity& mesh) : mesh_(mesh), retain_(false), name_("") { PropertyManager::mesh().add_property(prop_, name_); - set_range(mesh_.all_elements(), initial_value); + Storage::initialize(*this, initial_value); } /**