diff --git a/src/OpenMesh/Core/IO/reader/OMReader.cc b/src/OpenMesh/Core/IO/reader/OMReader.cc index 6e6eb4a0..be1a4004 100644 --- a/src/OpenMesh/Core/IO/reader/OMReader.cc +++ b/src/OpenMesh/Core/IO/reader/OMReader.cc @@ -59,6 +59,8 @@ #include #include +#include + //=== NAMESPACES ============================================================== @@ -806,50 +808,86 @@ size_t _OMReader_::restore_binary_custom_data(std::istream& _is, BaseProperty* _ //--------------------------------helper void _OMReader_:: add_generic_property(OMFormat::Chunk::PropertyName& _property_type, BaseImporter& _bi) const { - if(_property_type == get_string_for_type(bool())) + PropertyCreationManager& manager = PropertyCreationManager::instance(); + switch (chunk_header_.entity_) { - add_generic_property_aux(_bi); - } - else if(_property_type == get_string_for_type(char())) + case OMFormat::Chunk::Entity_Vertex: { - add_generic_property_aux(_bi); + manager.create_property(*_bi.kernel(), _property_type, property_name_); + break; } - else if(_property_type == get_string_for_type(double())) + case OMFormat::Chunk::Entity_Face: { - add_generic_property_aux(_bi); + manager.create_property(*_bi.kernel(), _property_type, property_name_); + break; } - else if(_property_type == get_string_for_type(float())) + case OMFormat::Chunk::Entity_Edge: { - add_generic_property_aux(_bi); + manager.create_property(*_bi.kernel(), _property_type, property_name_); + break; } - else if(_property_type == get_string_for_type(int())) + case OMFormat::Chunk::Entity_Halfedge: { - add_generic_property_aux(_bi); + manager.create_property(*_bi.kernel(), _property_type, property_name_); + break; } - else if(_property_type == get_string_for_type(long())) + case OMFormat::Chunk::Entity_Mesh: { - add_generic_property_aux(_bi); + manager.create_property(*_bi.kernel(), _property_type, property_name_); + break; } - else if(_property_type == get_string_for_type(short())) - { - add_generic_property_aux(_bi); - } - else if(_property_type == get_string_for_type(uchar())) - { - add_generic_property_aux(_bi); - } - else if(_property_type == get_string_for_type(uint())) - { - add_generic_property_aux(_bi); - } - else if(_property_type == get_string_for_type(ulong())) - { - add_generic_property_aux(_bi); - } - else - { - check_all_vector_types(_property_type, _bi); + case OMFormat::Chunk::Entity_Sentinel: + ; + break; + default: + ; } + + +// if(_property_type == get_string_for_type(bool())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(char())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(double())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(float())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(int())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(long())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(short())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(uchar())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(uint())) +// { +// add_generic_property_aux(_bi); +// } +// else if(_property_type == get_string_for_type(ulong())) +// { +// add_generic_property_aux(_bi); +// } +// else +// { +// check_all_vector_types(_property_type, _bi); +// } } void _OMReader_::check_all_vector_types(OMFormat::Chunk::PropertyName& _property_type, BaseImporter& _bi) const diff --git a/src/OpenMesh/Core/Utils/PropertyCreator.hh b/src/OpenMesh/Core/Utils/PropertyCreator.hh index 12ad8d44..8d49a417 100644 --- a/src/OpenMesh/Core/Utils/PropertyCreator.hh +++ b/src/OpenMesh/Core/Utils/PropertyCreator.hh @@ -50,6 +50,13 @@ #include #include +#include +#include +#include +#include +#include + + namespace OpenMesh { #define OM_CONCAT_IMPL(a, b) a##b @@ -74,24 +81,24 @@ public: bool can_you_create(const std::string &_type_name); /// Create a vertex property on _mesh with name _property_name - virtual void create_vertex_property (PolyConnectivity& _mesh, const std::string& _property_name) = 0; + virtual void create_vertex_property (BaseKernel& _mesh, const std::string& _property_name) = 0; /// Create a halfedge property on _mesh with name _property_name - virtual void create_halfedge_property(PolyConnectivity& _mesh, const std::string& _property_name) = 0; + virtual void create_halfedge_property(BaseKernel& _mesh, const std::string& _property_name) = 0; /// Create an edge property on _mesh with name _property_name - virtual void create_edge_property (PolyConnectivity& _mesh, const std::string& _property_name) = 0; + virtual void create_edge_property (BaseKernel& _mesh, const std::string& _property_name) = 0; /// Create a face property on _mesh with name _property_name - virtual void create_face_property (PolyConnectivity& _mesh, const std::string& _property_name) = 0; + virtual void create_face_property (BaseKernel& _mesh, const std::string& _property_name) = 0; /// Create a mesh property on _mesh with name _property_name - virtual void create_mesh_property (PolyConnectivity& _mesh, const std::string& _property_name) = 0; + virtual void create_mesh_property (BaseKernel& _mesh, const std::string& _property_name) = 0; /// Create a property for the element of type HandleT on _mesh with name _property_name template - void create_property(PolyConnectivity& _mesh, const std::string& _property_name); + void create_property(BaseKernel& _mesh, const std::string& _property_name); virtual ~PropertyCreator() {} @@ -100,11 +107,11 @@ protected: }; -template <> inline void PropertyCreator::create_property (PolyConnectivity& _mesh, const std::string& _property_name) { create_vertex_property (_mesh, _property_name); } -template <> inline void PropertyCreator::create_property(PolyConnectivity& _mesh, const std::string& _property_name) { create_halfedge_property(_mesh, _property_name); } -template <> inline void PropertyCreator::create_property (PolyConnectivity& _mesh, const std::string& _property_name) { create_edge_property (_mesh, _property_name); } -template <> inline void PropertyCreator::create_property (PolyConnectivity& _mesh, const std::string& _property_name) { create_face_property (_mesh, _property_name); } -template <> inline void PropertyCreator::create_property (PolyConnectivity& _mesh, const std::string& _property_name) { create_mesh_property (_mesh, _property_name); } +template <> inline void PropertyCreator::create_property (BaseKernel& _mesh, const std::string& _property_name) { create_vertex_property (_mesh, _property_name); } +template <> inline void PropertyCreator::create_property(BaseKernel& _mesh, const std::string& _property_name) { create_halfedge_property(_mesh, _property_name); } +template <> inline void PropertyCreator::create_property (BaseKernel& _mesh, const std::string& _property_name) { create_edge_property (_mesh, _property_name); } +template <> inline void PropertyCreator::create_property (BaseKernel& _mesh, const std::string& _property_name) { create_face_property (_mesh, _property_name); } +template <> inline void PropertyCreator::create_property (BaseKernel& _mesh, const std::string& _property_name) { create_mesh_property (_mesh, _property_name); } /// Helper class that contains the implementation of the create__property methods. /// Implementation is injected into PropertyCreatorT. @@ -113,11 +120,16 @@ class PropertyCreatorImpl : public PropertyCreator { public: std::string type_id_string() override { return get_type_name(); } - void create_vertex_property (PolyConnectivity& _mesh, const std::string& _property_name) override { VProp prop(_mesh, _property_name.c_str()); } - void create_halfedge_property(PolyConnectivity& _mesh, const std::string& _property_name) override { HProp prop(_mesh, _property_name.c_str()); } - void create_edge_property (PolyConnectivity& _mesh, const std::string& _property_name) override { EProp prop(_mesh, _property_name.c_str()); } - void create_face_property (PolyConnectivity& _mesh, const std::string& _property_name) override { FProp prop(_mesh, _property_name.c_str()); } - void create_mesh_property (PolyConnectivity& _mesh, const std::string& _property_name) override { MProp prop(_mesh, _property_name.c_str()); } + void create_vertex_property (BaseKernel& _mesh, const std::string& _property_name) override { VPropHandleT prop; + _mesh.add_property(prop, _property_name); } + void create_halfedge_property(BaseKernel& _mesh, const std::string& _property_name) override { HPropHandleT prop; + _mesh.add_property(prop, _property_name); } + void create_edge_property (BaseKernel& _mesh, const std::string& _property_name) override { EPropHandleT prop; + _mesh.add_property(prop, _property_name); } + void create_face_property (BaseKernel& _mesh, const std::string& _property_name) override { FPropHandleT prop; + _mesh.add_property(prop, _property_name); } + void create_mesh_property (BaseKernel& _mesh, const std::string& _property_name) override { MPropHandleT prop; + _mesh.add_property(prop, _property_name); } ~PropertyCreatorImpl() override {} protected: @@ -132,9 +144,12 @@ class PropertyCreatorT : public PropertyCreatorImpl> }; } +///used to register custom type, where typename.hh does NOT provide a string for type recognition #define OM_REGISTER_PROPERTY_TYPE(ClassName, TypeString) \ namespace OpenMesh { \ +inline std::string get_string_for_type(ClassName){ return TypeString;} \ + \ namespace { /* ensure internal linkage of class */ \ template <> \ class PropertyCreatorT : public PropertyCreatorImpl> \ @@ -154,6 +169,31 @@ public: static PropertyCreatorT OM_CONCAT(property_creator_registration_object_, __LINE__); \ } \ + + +///used to register custom type, where typename.hh does provide a string for type recognition +/// +#define OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(ClassName) \ +namespace OpenMesh { \ +namespace { /* ensure internal linkage of class */ \ +template <> \ +class PropertyCreatorT : public PropertyCreatorImpl> \ +{ \ +public: \ + using type = ClassName; \ + std::string type_string() override { return OpenMesh::get_string_for_type(type()); } \ + \ + PropertyCreatorT() \ + { \ + PropertyCreationManager::instance().register_property_creator(this); \ + } \ + ~PropertyCreatorT() override {} \ +}; \ +} \ +/* static to ensure internal linkage of object */ \ +static PropertyCreatorT OM_CONCAT(property_creator_registration_object_, __LINE__); \ +} + /** \brief Class for adding properties based on strings * * The PropertyCreationManager holds all PropertyCreators and dispatches the property creation @@ -170,7 +210,7 @@ public: static PropertyCreationManager& instance(); template - void create_property(PolyConnectivity& _mesh, const std::string& _type_name, const std::string& _property_name) + void create_property(BaseKernel& _mesh, const std::string& _type_name, const std::string& _property_name) { for (const auto& pc : property_creators_) if (pc->can_you_create(_type_name)) @@ -214,13 +254,84 @@ private: * For user defined types you need to register the type using OM_REGISTER_PROPERTY_TYPE(ClassName, TypeString) * */ template -void create_property_from_string(PolyConnectivity& _mesh, const std::string& _type_name, const std::string& _property_name) +void create_property_from_string(BaseKernel& _mesh, const std::string& _type_name, const std::string& _property_name) { PropertyCreationManager::instance().create_property(_mesh, _type_name, _property_name); } - - } /* namespace OpenMesh */ +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(OpenMesh::FaceHandle) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(OpenMesh::EdgeHandle) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(OpenMesh::HalfedgeHandle) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(OpenMesh::VertexHandle) + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(bool) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(char) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(signed char) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(double) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(float) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(int) +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(short) + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(unsigned char); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(unsigned int); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(unsigned short); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(unsigned long); + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1c); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1uc); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1s); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1us); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1i); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1ui); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1f); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec1d); + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2c); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2uc); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2s); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2us); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2i); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2ui); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2f); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec2d); + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3c); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3uc); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3s); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3us); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3i); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3ui); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3f); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec3d); + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4c); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4uc); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4s); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4us); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4i); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4ui); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4f); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec4d); + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5c); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5uc); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5s); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5us); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5i); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5ui); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5f); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec5d); + +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6c); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6uc); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6s); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6us); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6i); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6ui); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6f); +OM_REGISTER_PROPERTY_TYPE_USING_DEFAULT_STRING(Vec6d); + + + -OM_REGISTER_PROPERTY_TYPE(int, "int"); diff --git a/src/OpenMesh/Core/Utils/typename.hh b/src/OpenMesh/Core/Utils/typename.hh index 1b91635d..f553f392 100644 --- a/src/OpenMesh/Core/Utils/typename.hh +++ b/src/OpenMesh/Core/Utils/typename.hh @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace OpenMesh { diff --git a/src/Unittests/unittests_read_write_OM.cc b/src/Unittests/unittests_read_write_OM.cc index ebefebb7..7feba61f 100644 --- a/src/Unittests/unittests_read_write_OM.cc +++ b/src/Unittests/unittests_read_write_OM.cc @@ -1601,7 +1601,7 @@ void do_all_property_types(MeshT& _mesh, PropertyAction action) // do_property> (_mesh, action); // do_property> (_mesh, action); // do_property> (_mesh, action); - do_all_property_types_vec_all_dim(_mesh, action); + do_all_property_types_vec_all_dim(_mesh, action); } template @@ -1754,5 +1754,5 @@ TEST_F(OpenMeshReadWriteOM, PropertyFromString) } -OM_REGISTER_PROPERTY_TYPE(double, "double") +//OM_REGISTER_PROPERTY_TYPE(double, "double") OM_REGISTER_PROPERTY_TYPE(std::vector, "std::vector")