Merge remote-tracking branch 'origin/PropertyManagerRefactoring' into SmartRanges
# Conflicts: # src/OpenMesh/Core/Utils/PropertyManager.hh
This commit is contained in:
@@ -74,30 +74,19 @@ Below is the complete source code:
|
|||||||
|
|
||||||
## Property Lifetime
|
## Property Lifetime
|
||||||
|
|
||||||
In the above example, we chose to use makeTemporaryProperty(). This causes the created property to automatically be removed from the mesh as soon as we leave the scope of the associated handle variable \c cog.
|
In the above example, we chose to use VProp without a name. This causes the created property to automatically be removed from the mesh as soon as we leave the scope of the associated handle variable \c cog.
|
||||||
|
|
||||||
If, instead, a property is desired to survive its local scope, it should be created with using getOrMakeProperty(). In that case, the property must be given a name that can later be used to retrieve the property. For example:
|
If, instead, a property is desired to survive its local scope, it should be created with a name. For example:
|
||||||
|
|
||||||
\code
|
\code
|
||||||
auto face_area = OpenMesh::makeTemporaryProperty<OpenMesh::FaceHandle, double>(mesh, "face_area");
|
auto face_area = OpenMesh::FProp<double>(mesh, "face_area");
|
||||||
\endcode
|
\endcode
|
||||||
|
|
||||||
At a later time, we can use the getProperty() function to obtain a handle to a property that was previously created by refering to its name:
|
At a later time, we can access the same property by using the same name. If we want to make sure, that we access a property that has already been created earler, we can use hasProperty() to test whether a mesh has the desired property:
|
||||||
\code
|
\code
|
||||||
try {
|
if (OpenMesh::hasProperty<OpenMesh::FaceHandle, double>(mesh, "face_area")) {
|
||||||
auto face_area = OpenMesh::getProperty<OpenMesh::FaceHandle, double>(mesh, "face_area");
|
|
||||||
// Use the face_area property.
|
|
||||||
}
|
|
||||||
catch (const std::runtime_error& e) {
|
|
||||||
// Property not found. Handle the error here.
|
|
||||||
}
|
|
||||||
\endcode
|
|
||||||
|
|
||||||
Using hasProperty(), we can test whether a mesh has a certain property:
|
|
||||||
\code
|
|
||||||
if (OpenMesh::hasProperty<OpenMesh::EdgeHandle, bool>(mesh, "is_valley")) {
|
|
||||||
// Property exists. Do something with it.
|
// Property exists. Do something with it.
|
||||||
auto valley = OpenMesh::getProperty<OpenMesh::EdgeHandle, bool>(mesh, "is_valley");
|
auto valley = OpenMesh::FProp<bool>(mesh, "face_area");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Property does not exist. Do something else.
|
// Property does not exist. Do something else.
|
||||||
@@ -108,9 +97,9 @@ Using hasProperty(), we can test whether a mesh has a certain property:
|
|||||||
|
|
||||||
## Low-Level Property API
|
## Low-Level Property API
|
||||||
|
|
||||||
The functions makeTemporaryProperty(), getOrMakeProperty(), and getProperty() are the convenient high-level interface for creating and accessing mesh properties.
|
The property managers VProp, HProp, EProp, FProp and MProp are the convenient high-level interface for creating and accessing mesh properties.
|
||||||
|
|
||||||
Beneath these convenience functions, there is also a low-level property interface where handle and property lifetime must be managed manually. This interface is accessed through a mesh's add_property(), remove_property(), and property() functions and several property handle classes (OpenMesh::VPropHandleT, OpenMesh::HPropHandleT, OpenMesh::EPropHandleT, OpenMesh::FPropHandleT, OpenMesh::MPropHandleT).
|
Beneath these convenience functions, there is also a low-level property interface where handle and property lifetime must be managed manually. This interface is accessed through a mesh's add_property(), get_property(), remove_property(), and property() functions and several property handle classes (OpenMesh::VPropHandleT, OpenMesh::HPropHandleT, OpenMesh::EPropHandleT, OpenMesh::FPropHandleT, OpenMesh::MPropHandleT).
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|||||||
@@ -184,15 +184,15 @@ class PropertyManager {
|
|||||||
*
|
*
|
||||||
* Asks for a property with name propname and creates one if none exists. Lifetime is not managed.
|
* Asks for a property with name propname and creates one if none exists. Lifetime is not managed.
|
||||||
*
|
*
|
||||||
* @param initial_value If the proeprty is newly created, it will be initialized with intial_value.
|
* @param initial_value If the proeprty is newly created, it will be initialized with initial_value.
|
||||||
* If the property already existed, nothing is changes.
|
* If the property already existed, nothing is changes.
|
||||||
* @param mesh The mesh on which to create the property.
|
* @param mesh The mesh on which to create the property.
|
||||||
* @param propname The name of the property.
|
* @param propname The name of the property.
|
||||||
*/
|
*/
|
||||||
PropertyManager(const Value& intial_value, PolyConnectivity& mesh, const char *propname) : mesh_(mesh), retain_(true), name_(propname) {
|
PropertyManager(const Value& initial_value, PolyConnectivity& mesh, const char *propname) : mesh_(mesh), retain_(true), name_(propname) {
|
||||||
if (!mesh_.get_property_handle(prop_, propname)) {
|
if (!mesh_.get_property_handle(prop_, propname)) {
|
||||||
PropertyManager::mesh().add_property(prop_, propname);
|
PropertyManager::mesh().add_property(prop_, propname);
|
||||||
set_range(mesh_.all_elements<Handle>(), intial_value);
|
set_range(mesh_.all_elements<Handle>(), initial_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,12 +212,12 @@ class PropertyManager {
|
|||||||
*
|
*
|
||||||
* Create an anonymous property. Lifetime is managed.
|
* Create an anonymous property. Lifetime is managed.
|
||||||
*
|
*
|
||||||
* @param initial_value The property will be initialized with intial_value.
|
* @param initial_value The property will be initialized with initial_value.
|
||||||
* @param mesh The mesh on which to create the property.
|
* @param mesh The mesh on which to create the property.
|
||||||
*/
|
*/
|
||||||
PropertyManager(const Value& intial_value, const PolyConnectivity& mesh) : mesh_(mesh), retain_(false), name_("") {
|
PropertyManager(const Value& initial_value, const PolyConnectivity& mesh) : mesh_(mesh), retain_(false), name_("") {
|
||||||
PropertyManager::mesh().add_property(prop_, name_);
|
PropertyManager::mesh().add_property(prop_, name_);
|
||||||
set_range(mesh_.all_elements<Handle>(), intial_value);
|
set_range(mesh_.all_elements<Handle>(), initial_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user