Commit be1d02fc authored by Mike Kremer's avatar Mike Kremer

Integrated serialization of vector-valued properties.

git-svn-id: http://www.openvolumemesh.org/svnrepo/OpenVolumeMesh/trunk@250 66977474-1d4b-4f09-8fe9-267525286df2
parent bdd11d20
...@@ -77,6 +77,10 @@ public: ...@@ -77,6 +77,10 @@ public:
virtual bool anonymous() const = 0; virtual bool anonymous() const = 0;
virtual const std::string entityType() const = 0;
virtual const std::string typeNameWrapper() const = 0;
protected: protected:
virtual void delete_multiple_entries(const std::vector<bool>& _tags) = 0; virtual void delete_multiple_entries(const std::vector<bool>& _tags) = 0;
......
...@@ -111,9 +111,7 @@ public: ...@@ -111,9 +111,7 @@ public:
} }
// Function to serialize a property // Function to serialize a property
virtual void serialize(std::ostream& _ostr) const { virtual void serialize(std::ostream& /*_ostr*/) const {}
_ostr << "\"" << name_ << "\"" << std::endl;
}
// Function to deserialize a property // Function to deserialize a property
virtual void deserialize(std::istream& /*_istr*/) {} virtual void deserialize(std::istream& /*_istr*/) {}
......
...@@ -145,7 +145,6 @@ public: ...@@ -145,7 +145,6 @@ public:
// Function to serialize a property // Function to serialize a property
virtual void serialize(std::ostream& _ostr) const { virtual void serialize(std::ostream& _ostr) const {
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;
......
...@@ -42,6 +42,8 @@ ...@@ -42,6 +42,8 @@
#include "PropertyDefines.hh" #include "PropertyDefines.hh"
#include "../Geometry/VectorT.hh"
namespace OpenVolumeMesh { namespace OpenVolumeMesh {
template <> const std::string typeName<int>() { return "int"; } template <> const std::string typeName<int>() { return "int"; }
......
...@@ -59,79 +59,93 @@ class PropertyPtr; ...@@ -59,79 +59,93 @@ class PropertyPtr;
class ResourceManager; class ResourceManager;
template <class T>
const std::string typeName();
template <> const std::string typeName<int>();
template <> const std::string typeName<unsigned int>();
template <> const std::string typeName<short>();
template <> const std::string typeName<long>();
template <> const std::string typeName<unsigned long>();
template <> const std::string typeName<char>();
template <> const std::string typeName<unsigned char>();
template <> const std::string typeName<bool>();
template <> const std::string typeName<float>();
template <> const std::string typeName<double>();
template <> const std::string typeName<std::string>();
/// Property classes for the different entity types /// Property classes for the different entity types
template<class T> template<class T>
class VertexPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle> { class VertexPropertyT : public PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle> {
public: public:
VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle, const T _def = T()); VertexPropertyT(const std::string& _name, ResourceManager& _resMan, VertexPropHandle _handle, const T _def = T());
~VertexPropertyT() {} virtual ~VertexPropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "VProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
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, const T _def = T()); EdgePropertyT(const std::string& _name, ResourceManager& _resMan, EdgePropHandle _handle, const T _def = T());
~EdgePropertyT() {} virtual ~EdgePropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "EProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
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, const T _def = T()); HalfEdgePropertyT(const std::string& _name, ResourceManager& _resMan, HalfEdgePropHandle _handle, const T _def = T());
~HalfEdgePropertyT() {} virtual ~HalfEdgePropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "HEProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
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, const T _def = T()); FacePropertyT(const std::string& _name, ResourceManager& _resMan, FacePropHandle _handle, const T _def = T());
~FacePropertyT() {} virtual ~FacePropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "FProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
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, const T _def = T()); HalfFacePropertyT(const std::string& _name, ResourceManager& _resMan, HalfFacePropHandle _handle, const T _def = T());
~HalfFacePropertyT() {} virtual ~HalfFacePropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "HFProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
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, const T _def = T()); CellPropertyT(const std::string& _name, ResourceManager& _resMan, CellPropHandle _handle, const T _def = T());
~CellPropertyT() {} virtual ~CellPropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "CProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
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, const T _def = T()); MeshPropertyT(const std::string& _name, ResourceManager& _resMan, MeshPropHandle _handle, const T _def = T());
~MeshPropertyT() {} virtual ~MeshPropertyT() {}
virtual void serialize(std::ostream& _ostr) const; virtual void serialize(std::ostream& _ostr) const;
virtual void deserialize(std::istream& _istr); virtual void deserialize(std::istream& _istr);
virtual const std::string entityType() const { return "MProp"; }
virtual const std::string typeNameWrapper() const { return typeName<T>(); }
}; };
template <class T>
const std::string typeName();
template <> const std::string typeName<int>();
template <> const std::string typeName<unsigned int>();
template <> const std::string typeName<short>();
template <> const std::string typeName<long>();
template <> const std::string typeName<unsigned long>();
template <> const std::string typeName<char>();
template <> const std::string typeName<unsigned char>();
template <> const std::string typeName<bool>();
template <> const std::string typeName<float>();
template <> const std::string typeName<double>();
template <> const std::string typeName<std::string>();
} // Namespace OpenVolumeMesh } // Namespace OpenVolumeMesh
#if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYDEFINEST_CC) #if defined(INCLUDE_TEMPLATES) && !defined(PROPERTYDEFINEST_CC)
......
...@@ -56,8 +56,6 @@ VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _ ...@@ -56,8 +56,6 @@ VertexPropertyT<T>::VertexPropertyT(const std::string& _name, ResourceManager& _
template<class T> template<class T>
void VertexPropertyT<T>::serialize(std::ostream& _ostr) const { void VertexPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "VProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, VertexPropHandle>::get()->serialize(_ostr);
} }
...@@ -74,8 +72,6 @@ EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resM ...@@ -74,8 +72,6 @@ EdgePropertyT<T>::EdgePropertyT(const std::string& _name, ResourceManager& _resM
template<class T> template<class T>
void EdgePropertyT<T>::serialize(std::ostream& _ostr) const { void EdgePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "EProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, EdgePropHandle>::get()->serialize(_ostr);
} }
...@@ -92,8 +88,6 @@ HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManage ...@@ -92,8 +88,6 @@ HalfEdgePropertyT<T>::HalfEdgePropertyT(const std::string& _name, ResourceManage
template<class T> template<class T>
void HalfEdgePropertyT<T>::serialize(std::ostream& _ostr) const { void HalfEdgePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "HEProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfEdgePropHandle>::get()->serialize(_ostr);
} }
...@@ -110,8 +104,6 @@ FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resM ...@@ -110,8 +104,6 @@ FacePropertyT<T>::FacePropertyT(const std::string& _name, ResourceManager& _resM
template<class T> template<class T>
void FacePropertyT<T>::serialize(std::ostream& _ostr) const { void FacePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "FProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, FacePropHandle>::get()->serialize(_ostr);
} }
...@@ -128,8 +120,6 @@ HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManage ...@@ -128,8 +120,6 @@ HalfFacePropertyT<T>::HalfFacePropertyT(const std::string& _name, ResourceManage
template<class T> template<class T>
void HalfFacePropertyT<T>::serialize(std::ostream& _ostr) const { void HalfFacePropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "HFProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, HalfFacePropHandle>::get()->serialize(_ostr);
} }
...@@ -146,8 +136,6 @@ CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resM ...@@ -146,8 +136,6 @@ CellPropertyT<T>::CellPropertyT(const std::string& _name, ResourceManager& _resM
template<class T> template<class T>
void CellPropertyT<T>::serialize(std::ostream& _ostr) const { void CellPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "CProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, CellPropHandle>::get()->serialize(_ostr);
} }
...@@ -164,8 +152,6 @@ MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resM ...@@ -164,8 +152,6 @@ MeshPropertyT<T>::MeshPropertyT(const std::string& _name, ResourceManager& _resM
template<class T> template<class T>
void MeshPropertyT<T>::serialize(std::ostream& _ostr) const { void MeshPropertyT<T>::serialize(std::ostream& _ostr) const {
_ostr << "MProp ";
_ostr << typeName<T>() << " ";
PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::get()->serialize(_ostr); PropertyPtr<OpenVolumeMeshPropertyT<T>, MeshPropHandle>::get()->serialize(_ostr);
} }
......
...@@ -58,6 +58,8 @@ namespace OpenVolumeMesh { ...@@ -58,6 +58,8 @@ namespace OpenVolumeMesh {
namespace IO { namespace IO {
using namespace OpenVolumeMesh::Geometry;
//================================================== //==================================================
template <class MeshT> template <class MeshT>
...@@ -329,6 +331,24 @@ void FileManager::readProperty(std::istream& _iff, MeshT& _mesh) const { ...@@ -329,6 +331,24 @@ void FileManager::readProperty(std::istream& _iff, MeshT& _mesh) const {
else if(prop_t == typeName<float>()) generateGenericProperty<float, MeshT>(entity_t, name, _iff, _mesh); else if(prop_t == typeName<float>()) generateGenericProperty<float, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<double>()) generateGenericProperty<double, MeshT>(entity_t, name, _iff, _mesh); else if(prop_t == typeName<double>()) generateGenericProperty<double, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<std::string>()) generateGenericProperty<std::string, MeshT>(entity_t, name, _iff, _mesh); else if(prop_t == typeName<std::string>()) generateGenericProperty<std::string, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec2f>()) generateGenericProperty<Vec2f, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec2d>()) generateGenericProperty<Vec2d, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec2i>()) generateGenericProperty<Vec2i, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec2ui>()) generateGenericProperty<Vec2ui, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec3f>()) generateGenericProperty<Vec3f, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec3d>()) generateGenericProperty<Vec3d, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec3i>()) generateGenericProperty<Vec3i, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec3ui>()) generateGenericProperty<Vec3ui, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec4f>()) generateGenericProperty<Vec4f, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec4d>()) generateGenericProperty<Vec4d, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec4i>()) generateGenericProperty<Vec4i, MeshT>(entity_t, name, _iff, _mesh);
else if(prop_t == typeName<Vec4ui>()) generateGenericProperty<Vec4ui, MeshT>(entity_t, name, _iff, _mesh);
} }
//================================================== //==================================================
...@@ -488,6 +508,11 @@ void FileManager::writeProps(std::ostream& _ostr, const IteratorT& _begin, const ...@@ -488,6 +508,11 @@ void FileManager::writeProps(std::ostream& _ostr, const IteratorT& _begin, const
std::cerr << "Serialization of anonymous properties is not supported!" << std::endl; std::cerr << "Serialization of anonymous properties is not supported!" << std::endl;
continue; continue;
} }
_ostr << (*p_it)->entityType() << " ";
_ostr << (*p_it)->typeNameWrapper() << " ";
_ostr << "\"" << (*p_it)->name() << "\"" << std::endl;
(*p_it)->serialize(_ostr); (*p_it)->serialize(_ostr);
} }
} }
......
/*
* Vector.cc
*
* Created on: Aug 8, 2013
* Author: kremer
*/
#include <string>
#include "VectorT.hh"
namespace OpenVolumeMesh {
using namespace Geometry;
template <> const std::string typeName<Vec2f>() { return "vec2f"; }
template <> const std::string typeName<Vec2d>() { return "vec2d"; }
template <> const std::string typeName<Vec2i>() { return "vec2i"; }
template <> const std::string typeName<Vec2ui>() { return "vec2ui"; }
template <> const std::string typeName<Vec3f>() { return "vec3f"; }
template <> const std::string typeName<Vec3d>() { return "vec3d"; }
template <> const std::string typeName<Vec3i>() { return "vec3i"; }
template <> const std::string typeName<Vec3ui>() { return "vec3ui"; }
template <> const std::string typeName<Vec4f>() { return "vec4f"; }
template <> const std::string typeName<Vec4d>() { return "vec4d"; }
template <> const std::string typeName<Vec4i>() { return "vec4i"; }
template <> const std::string typeName<Vec4ui>() { return "vec4ui"; }
}
...@@ -99,7 +99,7 @@ template <typename Scalar,int N> struct VectorDataT ...@@ -99,7 +99,7 @@ template <typename Scalar,int N> struct VectorDataT
/// This specialization enables us to use aligned SSE instructions. /// This specialization enables us to use aligned SSE instructions.
template <> struct VectorDataT<float, 4> template <> struct VectorDataT<float, 4>
{ {
union union
{ {
__m128 m128; __m128 m128;
float values_[4]; float values_[4];
...@@ -141,7 +141,7 @@ template <> struct VectorDataT<float, 4> ...@@ -141,7 +141,7 @@ template <> struct VectorDataT<float, 4>
#define TEMPLATE_HEADER template <typename Scalar> #define TEMPLATE_HEADER template <typename Scalar>
#define CLASSNAME VectorT<Scalar,DIM> #define CLASSNAME VectorT<Scalar,DIM>
#define DERIVED VectorDataT<Scalar,DIM> #define DERIVED VectorDataT<Scalar,DIM>
...@@ -191,21 +191,21 @@ template <> struct VectorDataT<float, 4> ...@@ -191,21 +191,21 @@ template <> struct VectorDataT<float, 4>
/// cross product for Vec3f /// cross product for Vec3f
template<> template<>
inline VectorT<float,3> inline VectorT<float,3>
VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
{ {
return return
VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1], VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2], values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]); values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
} }
/// cross product for Vec3d /// cross product for Vec3d
template<> template<>
inline VectorT<double,3> inline VectorT<double,3>
VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
{ {
return return
VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1], VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2], values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]); values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
...@@ -229,16 +229,16 @@ inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) { ...@@ -229,16 +229,16 @@ inline VectorT<Scalar,N> operator*(Scalar _s, const VectorT<Scalar,N>& _v) {
/// \relates OpenVolumeMesh::VectorT /// \relates OpenVolumeMesh::VectorT
/// symmetric version of the dot product /// symmetric version of the dot product
template<typename Scalar, int N> template<typename Scalar, int N>
inline Scalar inline Scalar
dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) { dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
return (_v1 | _v2); return (_v1 | _v2);
} }
/// \relates OpenVolumeMesh::VectorT /// \relates OpenVolumeMesh::VectorT
/// symmetric version of the cross product /// symmetric version of the cross product
template<typename Scalar, int N> template<typename Scalar, int N>
inline VectorT<Scalar,N> inline VectorT<Scalar,N>
cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) { cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
return (_v1 % _v2); return (_v1 % _v2);
} }
...@@ -335,6 +335,27 @@ typedef VectorT<double,6> Vec6d; ...@@ -335,6 +335,27 @@ typedef VectorT<double,6> Vec6d;
//============================================================================= //=============================================================================
} // namespace Geometry } // namespace Geometry
using namespace Geometry;
template <class T>
const std::string typeName();
template <> const std::string typeName<Vec2f>();
template <> const std::string typeName<Vec2d>();
template <> const std::string typeName<Vec2i>();
template <> const std::string typeName<Vec2ui>();
template <> const std::string typeName<Vec3f>();
template <> const std::string typeName<Vec3d>();
template <> const std::string typeName<Vec3i>();
template <> const std::string typeName<Vec3ui>();
template <> const std::string typeName<Vec4f>();
template <> const std::string typeName<Vec4d>();
template <> const std::string typeName<Vec4i>();
template <> const std::string typeName<Vec4ui>();
} // namespace OpenVolumeMesh } // namespace OpenVolumeMesh
//============================================================================= //=============================================================================
#endif // OPENVOLUMEMESH_VECTOR_HH defined #endif // OPENVOLUMEMESH_VECTOR_HH defined
......
...@@ -118,6 +118,125 @@ TEST_F(PolyhedralMeshBase, SaveFileWithProps) { ...@@ -118,6 +118,125 @@ TEST_F(PolyhedralMeshBase, SaveFileWithProps) {
} }
} }
TEST_F(PolyhedralMeshBase, SaveFileWithVectorProps) {
OpenVolumeMesh::IO::FileManager fileManager;
ASSERT_TRUE(fileManager.readFile("Cylinder.ovm", mesh_));
EXPECT_EQ(399u, mesh_.n_vertices());
EXPECT_EQ(1070u, mesh_.n_edges());
EXPECT_EQ(960u, mesh_.n_faces());
EXPECT_EQ(288u, mesh_.n_cells());
// Attach non-persistent properties
HalfFacePropertyT<Vec3d> hfprop = mesh_.request_halfface_property<Vec3d>("MyHalfFaceProp");
VertexPropertyT<Vec2i> vprop = mesh_.request_vertex_property<Vec2i>("MyVertexProp");
for(unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
hfprop[i] = Vec3d((double)i/2.0, (double)i/2.0, (double)i/2.0);
}
for(unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
vprop[i] = Vec2i(i, i, i);
}
mesh_.set_persistent(hfprop);
mesh_.set_persistent(vprop);
// Write file
ASSERT_TRUE(fileManager.writeFile("Cylinder.copy.ovm", mesh_));
mesh_.clear();
ASSERT_TRUE(fileManager.readFile("Cylinder.copy.ovm", mesh_));
EXPECT_EQ(399u, mesh_.n_vertices());
EXPECT_EQ(1070u, mesh_.n_edges());
EXPECT_EQ(960u, mesh_.n_faces());
EXPECT_EQ(288u, mesh_.n_cells());
EXPECT_EQ(1u, mesh_.n_halfface_props());
EXPECT_EQ(1u, mesh_.n_vertex_props());
HalfFacePropertyT<Vec3d> hfprop2 = mesh_.request_halfface_property<Vec3d>("MyHalfFaceProp");
VertexPropertyT<Vec2i> vprop2 = mesh_.request_vertex_property<Vec2i>("MyVertexProp");
for(unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
EXPECT_FLOAT_EQ((double)i/2.0, hfprop2[i][0]);
EXPECT_FLOAT_EQ((double)i/2.0, hfprop2[i][1]);
EXPECT_FLOAT_EQ((double)i/2.0, hfprop2[i][2]);
}
for(unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
EXPECT_EQ(i, vprop2[i][0]);
EXPECT_EQ(i, vprop2[i][1]);
}
}
TEST_F(PolyhedralMeshBase, SerializeVectorValuedProperties) {
OpenVolumeMesh::IO::FileManager fileManager;
ASSERT_TRUE(fileManager.readFile("Cylinder.ovm", mesh_));
EXPECT_EQ(399u, mesh_.n_vertices());
EXPECT_EQ(1070u, mesh_.n_edges());
EXPECT_EQ(960u, mesh_.n_faces());
EXPECT_EQ(288u, mesh_.n_cells());
// Attach persistent properties
HalfFacePropertyT<Vec3d> hfprop = mesh_.request_halfface_property<Vec3d>("MyHalfFaceProp");
VertexPropertyT<Vec2i> vprop = mesh_.request_vertex_property<Vec2i>("MyVertexProp");
for(unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
hfprop[i] = Vec3d((double)i/2.0, (double)i/2.0, (double)i/2.0);
}
for(unsigned int i = 0; i < mesh_.n_vertices(); ++i) {
vprop[i] = Vec2i(i, i, i);
}
mesh_.set_persistent(hfprop);
mesh_.set_persistent(vprop);
std::ofstream ofs1("hfVecPropTest");
std::ofstream ofs2("vVecPropTest");
hfprop.serialize(ofs1);
vprop.serialize(ofs2);
ofs1.close();
ofs2.close();
/*
* Change property values
*/
for(unsigned int i = 0; i < mesh_.n_halffaces(); ++i) {
hfprop[i] = Vec3d((double)i/3.0, (double)i/3.0, (double)i/3.0);
}