Commit 6c0b01ce authored by Mike Kremer's avatar Mike Kremer
Browse files

Fixed property serialization system. Added serialization to file writer.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@142 66977474-1d4b-4f09-8fe9-267525286df2
parent df2bfe3c
...@@ -67,15 +67,18 @@ public: ...@@ -67,15 +67,18 @@ public:
virtual void delete_element(size_t _idx) = 0; virtual void delete_element(size_t _idx) = 0;
virtual std::ostream& serialize(std::ostream& _ostr) const = 0; virtual void serialize(std::ostream& _ostr) const = 0;
virtual std::istream& deserialize(std::istream& _istr) = 0; virtual void deserialize(std::istream& _istr) = 0;
virtual OpenVolumeMeshHandle handle() const = 0; virtual OpenVolumeMeshHandle handle() const = 0;
virtual bool persistent() const = 0; virtual bool persistent() const = 0;
virtual bool anonymous() const = 0;
protected: protected:
virtual void resize(unsigned int /*_size*/) = 0; virtual void resize(unsigned int /*_size*/) = 0;
virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0; virtual void set_handle(const OpenVolumeMeshHandle& /*_handle*/) = 0;
......
...@@ -107,10 +107,10 @@ public: ...@@ -107,10 +107,10 @@ public:
return nV; return nV;
} }
virtual void clear() { virtual void clear(bool _clearProps = true) {
vertices_.clear(); vertices_.clear();
TopologyKernelT::clear(); TopologyKernelT::clear(_clearProps);
} }
private: private:
......
...@@ -109,17 +109,15 @@ public: ...@@ -109,17 +109,15 @@ public:
} }
// Function to serialize a property // Function to serialize a property
virtual std::ostream& serialize(std::ostream& _ostr) const { virtual void serialize(std::ostream& _ostr) const {
_ostr << name_ << std::endl; _ostr << "\"" << name_ << "\"" << std::endl;
return _ostr;
} }
// Function to deserialize a property // Function to deserialize a property
virtual std::istream& deserialize(std::istream& _istr) { virtual void deserialize(std::istream& _istr) {
std::string str; std::string str;
_istr >> str; _istr >> str;
name_ = str; name_ = str;
return _istr;
} }
public: public:
......
...@@ -139,24 +139,22 @@ public: ...@@ -139,24 +139,22 @@ public:
} }
// Function to serialize a property // Function to serialize a property
virtual std::ostream& serialize(std::ostream& _ostr) const { virtual void serialize(std::ostream& _ostr) const {
_ostr << OpenVolumeMeshBaseProperty::serialize(_ostr); OpenVolumeMeshBaseProperty::serialize(_ostr);
for(typename vector_type::const_iterator it = data_.begin(); for(typename vector_type::const_iterator it = data_.begin();
it != data_.end(); ++it) { it != data_.end(); ++it) {
_ostr << *it << std::endl; _ostr << *it << std::endl;
} }
return _ostr;
} }
// Function to deserialize a property // Function to deserialize a property
virtual std::istream& deserialize(std::istream& _istr) { virtual void deserialize(std::istream& _istr) {
OpenVolumeMeshBaseProperty::deserialize(_istr); OpenVolumeMeshBaseProperty::deserialize(_istr);
for(unsigned int i = 0; i < n_elements(); ++i) { for(unsigned int i = 0; i < n_elements(); ++i) {
value_type val; value_type val;
_istr >> val; _istr >> val;
data_[i] = val; data_[i] = val;
} }
return _istr;
} }
public: public:
......
...@@ -44,6 +44,7 @@ ...@@ -44,6 +44,7 @@
#define PROPERTYDEFINES_HH_ #define PROPERTYDEFINES_HH_
#include <iostream> #include <iostream>
#include <typeinfo>
#include "BaseProperty.hh" #include "BaseProperty.hh"
#include "PropertyHandles.hh" #include "PropertyHandles.hh"
...@@ -63,58 +64,61 @@ class VertexPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPro ...@@ -63,58 +64,61 @@ class VertexPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPro
public: public:
VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle); VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle);
~VertexPropertyT() {} ~VertexPropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template<class T> template<class T>
class EdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle> { class EdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle> {
public: public:
EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle); EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle);
~EdgePropertyT() {} ~EdgePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template<class T> template<class T>
class HalfEdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle> { class HalfEdgePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle> {
public: public:
HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle); HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle);
~HalfEdgePropertyT() {} ~HalfEdgePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template<class T> template<class T>
class FacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle> { class FacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle> {
public: public:
FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle); FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle);
~FacePropertyT() {} ~FacePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template<class T> template<class T>
class HalfFacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle> { class HalfFacePropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle> {
public: public:
HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle); HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle);
~HalfFacePropertyT() {} ~HalfFacePropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template<class T> template<class T>
class CellPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle> { class CellPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle> {
public: public:
CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle); CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle);
~CellPropertyT() {} ~CellPropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template<class T> template<class T>
class MeshPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle> { class MeshPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle> {
public: public:
MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle); MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle);
~MeshPropertyT() {} ~MeshPropertyT() {}
virtual std::ostream& serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual std::istream& deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
}; };
template <class T>
const std::string typeName() { return typeid(T).name(); }
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
#if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYDEFINEST_CC) #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYDEFINEST_CC)
......
...@@ -55,16 +55,15 @@ VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _ ...@@ -55,16 +55,15 @@ VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _
} }
template<class T> template<class T>
std::ostream& VertexPropertyT<T>::serialize(std::ostream& _ostr) const { void VertexPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "VProp" << std::endl; _ostr << "VProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& VertexPropertyT<T>::deserialize(std::istream& _istr) { void VertexPropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->deserialize(_istr);
return _istr;
} }
template<class T> template<class T>
...@@ -74,16 +73,15 @@ EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resM ...@@ -74,16 +73,15 @@ EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resM
} }
template<class T> template<class T>
std::ostream& EdgePropertyT<T>::serialize(std::ostream& _ostr) const { void EdgePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "EProp" << std::endl; _ostr << "EProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& EdgePropertyT<T>::deserialize(std::istream& _istr) { void EdgePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::get()->deserialize(_istr);
return _istr;
} }
template<class T> template<class T>
...@@ -93,16 +91,15 @@ HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManage ...@@ -93,16 +91,15 @@ HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManage
} }
template<class T> template<class T>
std::ostream& HalfEdgePropertyT<T>::serialize(std::ostream& _ostr) const { void HalfEdgePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "HEProp" << std::endl; _ostr << "HEProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& HalfEdgePropertyT<T>::deserialize(std::istream& _istr) { void HalfEdgePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::get()->deserialize(_istr);
return _istr;
} }
template<class T> template<class T>
...@@ -112,16 +109,15 @@ FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resM ...@@ -112,16 +109,15 @@ FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resM
} }
template<class T> template<class T>
std::ostream& FacePropertyT<T>::serialize(std::ostream& _ostr) const { void FacePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "FProp" << std::endl; _ostr << "FProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& FacePropertyT<T>::deserialize(std::istream& _istr) { void FacePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::get()->deserialize(_istr);
return _istr;
} }
template<class T> template<class T>
...@@ -131,16 +127,15 @@ HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManage ...@@ -131,16 +127,15 @@ HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManage
} }
template<class T> template<class T>
std::ostream& HalfFacePropertyT<T>::serialize(std::ostream& _ostr) const { void HalfFacePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "HFProp" << std::endl; _ostr << "HFProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& HalfFacePropertyT<T>::deserialize(std::istream& _istr) { void HalfFacePropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::get()->deserialize(_istr);
return _istr;
} }
template<class T> template<class T>
...@@ -150,16 +145,15 @@ CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resM ...@@ -150,16 +145,15 @@ CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resM
} }
template<class T> template<class T>
std::ostream& CellPropertyT<T>::serialize(std::ostream& _ostr) const { void CellPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "CProp" << std::endl; _ostr << "CProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& CellPropertyT<T>::deserialize(std::istream& _istr) { void CellPropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::get()->deserialize(_istr);
return _istr;
} }
template<class T> template<class T>
...@@ -169,16 +163,15 @@ MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resM ...@@ -169,16 +163,15 @@ MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resM
} }
template<class T> template<class T>
std::ostream& MeshPropertyT<T>::serialize(std::ostream& _ostr) const { void MeshPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "MProp" << std::endl; _ostr << "MProp ";
_ostr << PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::get()->serialize(_ostr); _ostr << typeName<T>() << " ";
return _ostr; PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::get()->serialize(_ostr);
} }
template<class T> template<class T>
std::istream& MeshPropertyT<T>::deserialize(std::istream& _istr) { void MeshPropertyT<T>::deserialize(std::istream& _istr) {
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::get()->deserialize(_istr); PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::get()->deserialize(_istr);
return _istr;
} }
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
...@@ -99,6 +99,8 @@ public: ...@@ -99,6 +99,8 @@ public:
virtual bool persistent() const { return ptr::shared_ptr<PropT>::get()->persistent(); } virtual bool persistent() const { return ptr::shared_ptr<PropT>::get()->persistent(); }
virtual bool anonymous() const { return ptr::shared_ptr<PropT>::get()->name().empty(); }
protected: protected:
virtual void resize(unsigned int _size); virtual void resize(unsigned int _size);
......
...@@ -89,6 +89,8 @@ public: ...@@ -89,6 +89,8 @@ public:
/// Change size of stored cell properties /// Change size of stored cell properties
void resize_cprops(unsigned int _nc); void resize_cprops(unsigned int _nc);
protected:
void vertex_deleted(const VertexHandle& _h); void vertex_deleted(const VertexHandle& _h);
void edge_deleted(const EdgeHandle& _h); void edge_deleted(const EdgeHandle& _h);
...@@ -97,6 +99,22 @@ public: ...@@ -97,6 +99,22 @@ public:
void cell_deleted(const CellHandle& _h); void cell_deleted(const CellHandle& _h);
public:
void clear_vertex_props() { clearVec(vertex_props_); }
void clear_edge_props() { clearVec(edge_props_); }
void clear_halfedge_props() { clearVec(halfedge_props_); }
void clear_face_props() { clearVec(face_props_); }
void clear_halfface_props() { clearVec(halfface_props_); }
void clear_cell_props() { clearVec(cell_props_); }
void clear_mesh_props() { clearVec(mesh_props_); }
/// Get number of vertices in mesh /// Get number of vertices in mesh
virtual unsigned int n_vertices() const = 0; virtual unsigned int n_vertices() const = 0;
/// Get number of edges in mesh /// Get number of edges in mesh
...@@ -170,6 +188,36 @@ public: ...@@ -170,6 +188,36 @@ public:
template<class T> void set_persistent(MeshPropertyT<T>& _prop, bool _flag = true); template<class T> void set_persistent(MeshPropertyT<T>& _prop, bool _flag = true);
typedef std::vector<BaseProperty*> Properties;
Properties::const_iterator vertex_props_begin() const { return vertex_props_.begin(); }
Properties::const_iterator vertex_props_end() const { return vertex_props_.end(); }
Properties::const_iterator edge_props_begin() const { return edge_props_.begin(); }
Properties::const_iterator edge_props_end() const { return edge_props_.end(); }
Properties::const_iterator halfedge_props_begin() const { return halfedge_props_.begin(); }
Properties::const_iterator halfedge_props_end() const { return halfedge_props_.end(); }
Properties::const_iterator face_props_begin() const { return face_props_.begin(); }
Properties::const_iterator face_props_end() const { return face_props_.end(); }
Properties::const_iterator halfface_props_begin() const { return halfface_props_.begin(); }
Properties::const_iterator halfface_props_end() const { return halfface_props_.end(); }
Properties::const_iterator cell_props_begin() const { return cell_props_.begin(); }
Properties::const_iterator cell_props_end() const { return cell_props_.end(); }
Properties::const_iterator mesh_props_begin() const { return mesh_props_.begin(); }
Properties::const_iterator mesh_props_end() const { return mesh_props_.end(); }
private: private:
template<class StdVecT> template<class StdVecT>
...@@ -190,19 +238,19 @@ private: ...@@ -190,19 +238,19 @@ private:
template<class StdVecT> template<class StdVecT>
void clearVec(StdVecT& _vec); void clearVec(StdVecT& _vec);
std::vector<BaseProperty*> vertex_props_; Properties vertex_props_;
std::vector<BaseProperty*> edge_props_; Properties edge_props_;
std::vector<BaseProperty*> halfedge_props_; Properties halfedge_props_;
std::vector<BaseProperty*> face_props_; Properties face_props_;
std::vector<BaseProperty*> halfface_props_; Propert