44#include <OpenMesh/Core/System/config.h>
45#include <OpenMesh/Core/Utils/HandleToPropHandle.hh>
46#include <OpenMesh/Core/Utils/PropertyManager.hh>
47#include <OpenMesh/Core/Mesh/PolyConnectivity.hh>
53#include <OpenMesh/Core/IO/SR_store.hh>
58#define OM_CONCAT_IMPL(a, b) a##b
59#define OM_CONCAT(a, b) OM_CONCAT_IMPL(a, b)
74 virtual std::string type_id_string() = 0;
77 bool can_you_create(
const std::string &_type_name);
96 template <
typename HandleT>
106template <>
inline void PropertyCreator::create_property<VertexHandle> (BaseKernel& _mesh,
const std::string& _property_name) {
create_vertex_property (_mesh, _property_name); }
107template <>
inline void PropertyCreator::create_property<HalfedgeHandle>(BaseKernel& _mesh,
const std::string& _property_name) {
create_halfedge_property(_mesh, _property_name); }
108template <>
inline void PropertyCreator::create_property<EdgeHandle> (BaseKernel& _mesh,
const std::string& _property_name) {
create_edge_property (_mesh, _property_name); }
109template <>
inline void PropertyCreator::create_property<FaceHandle> (BaseKernel& _mesh,
const std::string& _property_name) {
create_face_property (_mesh, _property_name); }
110template <>
inline void PropertyCreator::create_property<MeshHandle> (BaseKernel& _mesh,
const std::string& _property_name) {
create_mesh_property (_mesh, _property_name); }
114template <
typename PropertyCreatorT>
118 std::string type_id_string()
override {
return get_type_name<typename PropertyCreatorT::type>(); }
120 template <
typename HandleT,
typename PropT>
121 void create_prop(
BaseKernel& _mesh,
const std::string& _property_name)
129 void create_vertex_property (
BaseKernel& _mesh,
const std::string& _property_name)
override { create_prop<VertexHandle , typename PropertyCreatorT::type>(_mesh, _property_name); }
131 void create_edge_property (
BaseKernel& _mesh,
const std::string& _property_name)
override { create_prop<EdgeHandle , typename PropertyCreatorT::type>(_mesh, _property_name);}
132 void create_face_property (
BaseKernel& _mesh,
const std::string& _property_name)
override { create_prop<FaceHandle , typename PropertyCreatorT::type>(_mesh, _property_name);}
133 void create_mesh_property (
BaseKernel& _mesh,
const std::string& _property_name)
override { create_prop<MeshHandle , typename PropertyCreatorT::type>(_mesh, _property_name);}
137 PropertyCreatorImpl() {}
143class PropertyCreatorT :
public PropertyCreatorImpl<PropertyCreatorT<T>>
150#define OM_REGISTER_PROPERTY_TYPE(ClassName) \
151namespace OpenMesh { \
154class PropertyCreatorT<ClassName> : public PropertyCreatorImpl<PropertyCreatorT<ClassName>> \
157 using type = ClassName; \
158 std::string type_string() override { return OpenMesh::IO::binary<type>::type_identifier(); } \
162 PropertyCreationManager::instance().register_property_creator(this); \
164 ~PropertyCreatorT() override {} \
168static PropertyCreatorT<ClassName> OM_CONCAT(property_creator_registration_object_, __LINE__); \
186 template <
typename HandleT>
187 void create_property(
BaseKernel& _mesh,
const std::string& _type_name,
const std::string& _property_name)
191 return pc->can_you_create(_type_name);
194 std::vector<OpenMesh::PropertyCreator*>::iterator pc_iter = std::find_if(property_creators_.begin(),
195 property_creators_.end(), can_create);
196 if (pc_iter != property_creators_.end())
198 const auto& pc = *pc_iter;
199 pc->create_property<HandleT>(_mesh, _property_name);
203 omerr() <<
"No property creator registered that can create a property of type " << _type_name << std::endl;
204 omerr() <<
"You need to register your custom type using OM_REGISTER_PROPERTY_TYPE(ClassName) and declare the struct binary<ClassName>.\
205 See documentation for more details." << std::endl;
206 omerr() <<
"Adding property failed." << std::endl;
211 for (
auto pc : property_creators_)
212 if (pc->type_string() == _property_creator->
type_string())
214 if (pc->type_id_string() != _property_creator->type_id_string())
216 omerr() <<
"And it looks like you are trying to add a different type with an already existing string identification." << std::endl;
217 omerr() <<
"Type id of existing type is " << pc->type_id_string() <<
" trying to add for " << _property_creator->type_id_string() << std::endl;
221 property_creators_.push_back(_property_creator);
229 std::vector<PropertyCreator*> property_creators_;
236template <
typename HandleT>
239 PropertyCreationManager::instance().create_property<HandleT>(_mesh, _type_name, _property_name);
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59
void create_property_from_string(BaseKernel &_mesh, const std::string &_type_name, const std::string &_property_name)
Create a property with type corresponding to _type_name on _mesh with name _property_name.
Definition: PropertyCreator.hh:237
This class provides low-level property management like adding/removing properties and access to prope...
Definition: BaseKernel.hh:98
void add_property(VPropHandleT< T > &_ph, const std::string &_name="<vprop>")
You should not use this function directly.
Definition: BaseKernel.hh:141
bool get_property_handle(VPropHandleT< T > &_ph, const std::string &_name) const
You should not use this function directly.
Definition: BaseKernel.hh:254
Definition: Property.hh:487
Base class for property creators.
Definition: PropertyCreator.hh:68
virtual void create_face_property(BaseKernel &_mesh, const std::string &_property_name)=0
Create a face property on _mesh with name _property_name.
virtual std::string type_string()=0
The string that corresponds to the type this property creator can create.
virtual void create_halfedge_property(BaseKernel &_mesh, const std::string &_property_name)=0
Create a halfedge property on _mesh with name _property_name.
void create_property(BaseKernel &_mesh, const std::string &_property_name)
Create a property for the element of type HandleT on _mesh with name _property_name.
virtual void create_mesh_property(BaseKernel &_mesh, const std::string &_property_name)=0
Create a mesh property on _mesh with name _property_name.
virtual void create_vertex_property(BaseKernel &_mesh, const std::string &_property_name)=0
Create a vertex property on _mesh with name _property_name.
virtual void create_edge_property(BaseKernel &_mesh, const std::string &_property_name)=0
Create an edge property on _mesh with name _property_name.
Helper class that contains the implementation of the create_<HandleT>_property methods.
Definition: PropertyCreator.hh:116
void create_edge_property(BaseKernel &_mesh, const std::string &_property_name) override
Create an edge property on _mesh with name _property_name.
Definition: PropertyCreator.hh:131
void create_face_property(BaseKernel &_mesh, const std::string &_property_name) override
Create a face property on _mesh with name _property_name.
Definition: PropertyCreator.hh:132
void create_vertex_property(BaseKernel &_mesh, const std::string &_property_name) override
Create a vertex property on _mesh with name _property_name.
Definition: PropertyCreator.hh:129
void create_mesh_property(BaseKernel &_mesh, const std::string &_property_name) override
Create a mesh property on _mesh with name _property_name.
Definition: PropertyCreator.hh:133
void create_halfedge_property(BaseKernel &_mesh, const std::string &_property_name) override
Create a halfedge property on _mesh with name _property_name.
Definition: PropertyCreator.hh:130
Class for adding properties based on strings.
Definition: PropertyCreator.hh:181