Commit 9680df9f authored by Matthias Möller's avatar Matthias Möller

add custom property support for PLY reader ASCII version

git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@1181 fdac6126-5c0c-442c-9429-916003d36597
parent 3750e2a6
...@@ -106,8 +106,9 @@ public: ...@@ -106,8 +106,9 @@ public:
FaceNormal = 0x0100, ///< Has (r) / store (w) face normals FaceNormal = 0x0100, ///< Has (r) / store (w) face normals
FaceColor = 0x0200, ///< Has (r) / store (w) face colors FaceColor = 0x0200, ///< Has (r) / store (w) face colors
FaceTexCoord = 0x0400, ///< Has (r) / store (w) face texture coordinates FaceTexCoord = 0x0400, ///< Has (r) / store (w) face texture coordinates
ColorAlpha = 0x0800, ///< Has (r) / store (w) alpha values for colors ColorAlpha = 0x0800, ///< Has (r) / store (w) alpha values for colors
ColorFloat = 0x1000 ///< Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files) ColorFloat = 0x1000, ///< Has (r) / store (w) float values for colors (currently only implemented for PLY and OFF files)
Custom = 0x2000 ///< Has (r) custom properties (currently only implemented in PLY Reader ASCII version)
}; };
public: public:
......
...@@ -89,6 +89,9 @@ public: ...@@ -89,6 +89,9 @@ public:
// add a vertex with coordinate \c _point // add a vertex with coordinate \c _point
virtual VertexHandle add_vertex(const Vec3f& _point) = 0; virtual VertexHandle add_vertex(const Vec3f& _point) = 0;
// add a vertex without coordinate. Use set_point to set the position deferred
virtual VertexHandle add_vertex() = 0;
// add a face with indices _indices refering to vertices // add a face with indices _indices refering to vertices
typedef std::vector<VertexHandle> VHandles; typedef std::vector<VertexHandle> VHandles;
virtual FaceHandle add_face(const VHandles& _indices) = 0; virtual FaceHandle add_face(const VHandles& _indices) = 0;
...@@ -99,6 +102,9 @@ public: ...@@ -99,6 +102,9 @@ public:
// Set the texture index for a face // Set the texture index for a face
virtual void set_face_texindex( FaceHandle _fh, int _texId ) = 0; virtual void set_face_texindex( FaceHandle _fh, int _texId ) = 0;
// Set coordinate of the given vertex. Use this function, if you created a vertex without coordinate
virtual void set_point(VertexHandle _vh, const Vec3f& _point) = 0;
// set vertex normal // set vertex normal
virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) = 0; virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) = 0;
......
...@@ -94,6 +94,10 @@ public: ...@@ -94,6 +94,10 @@ public:
return mesh_.add_vertex(vector_cast<Point>(_point)); return mesh_.add_vertex(vector_cast<Point>(_point));
} }
virtual VertexHandle add_vertex()
{
return mesh_.new_vertex();
}
virtual FaceHandle add_face(const VHandles& _indices) virtual FaceHandle add_face(const VHandles& _indices)
{ {
...@@ -154,6 +158,11 @@ public: ...@@ -154,6 +158,11 @@ public:
// vertex attributes // vertex attributes
virtual void set_point(VertexHandle _vh, const Vec3f& _point)
{
mesh_.set_point(_vh,vector_cast<Point>(_point));
}
virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) virtual void set_normal(VertexHandle _vh, const Vec3f& _normal)
{ {
if (mesh_.has_vertex_normals()) if (mesh_.has_vertex_normals())
......
This diff is collapsed.
...@@ -129,6 +129,7 @@ private: ...@@ -129,6 +129,7 @@ private:
bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap, const Options& _opt) const; bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap, const Options& _opt) const;
float readToFloatValue(ValueType _type , std::fstream& _in) const; float readToFloatValue(ValueType _type , std::fstream& _in) const;
void readCustomProperty(std::istream& _in, BaseImporter& _bi, VertexHandle _vh, const std::string& _propName, const ValueType _valueType) const;
void readValue(ValueType _type , std::istream& _in, float& _value) const; void readValue(ValueType _type , std::istream& _in, float& _value) const;
void readValue(ValueType _type, std::istream& _in, double& _value) const; void readValue(ValueType _type, std::istream& _in, double& _value) const;
...@@ -164,7 +165,7 @@ private: ...@@ -164,7 +165,7 @@ private:
XCOORD,YCOORD,ZCOORD, XCOORD,YCOORD,ZCOORD,
TEXX,TEXY, TEXX,TEXY,
COLORRED,COLORGREEN,COLORBLUE,COLORALPHA, COLORRED,COLORGREEN,COLORBLUE,COLORALPHA,
XNORM,YNORM,ZNORM, XNORM,YNORM,ZNORM, CUSTOM_PROP,
UNSUPPORTED UNSUPPORTED
}; };
...@@ -173,7 +174,16 @@ private: ...@@ -173,7 +174,16 @@ private:
// Number of vertex properties // Number of vertex properties
mutable unsigned int vertexPropertyCount_; mutable unsigned int vertexPropertyCount_;
mutable std::map< int , std::pair< VertexProperty, ValueType> > vertexPropertyMap_; struct VertexPropertyInfo
{
VertexProperty property;
ValueType value;
std::string name;//for custom properties
VertexPropertyInfo():property(UNSUPPORTED),value(Unsupported),name(""){}
VertexPropertyInfo(VertexProperty _p, ValueType _v):property(_p),value(_v),name(""){}
VertexPropertyInfo(VertexProperty _p, ValueType _v, const std::string& _n):property(_p),value(_v),name(_n){}
};
mutable std::map< int , VertexPropertyInfo > vertexPropertyMap_;
}; };
......
ply
format ascii 1.0
element vertex 8
property float32 x
property float32 y
property float32 z
property float32 nx
property float32 ny
property float32 nz
property float32 quality
property uint index
element face 6
property list uint8 int32 vertex_indices
end_header
-1 -1 -1 0.0 0.0 1.0 1.0 0
1 -1 -1 0.0 1.0 0.0 0.5 1
1 1 -1 0.0 1.0 1.0 0.7 2
-1 1 -1 1.0 0.0 0.0 1.0 3
-1 -1 1 1.0 0.0 1.0 0.1 4
1 -1 1 1.0 1.0 0.0 0.0 5
1 1 1 1.0 1.0 1.0 2.0 6
-1 1 1 1.0 1.0 2.0 5.0 7
4 0 1 2 3
4 5 4 7 6
4 6 2 1 5
4 3 7 4 0
4 7 3 2 6
4 5 1 0 4
...@@ -438,5 +438,44 @@ TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithNormals) { ...@@ -438,5 +438,44 @@ TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithNormals) {
mesh_.release_vertex_normals(); mesh_.release_vertex_normals();
}
/*
* Just load a ply with custom properties, ascii mode
*/
TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithCustomProps) {
mesh_.clear();
OpenMesh::IO::Options options;
options += OpenMesh::IO::Options::Custom;
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-custom_props.ply", options);
EXPECT_TRUE(ok) << "Unable to load cube-minimal-custom_props.ply";
EXPECT_EQ(8u , mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
EXPECT_EQ(18u , mesh_.n_edges()) << "The number of loaded edges is not correct!";
EXPECT_EQ(12u , mesh_.n_faces()) << "The number of loaded faces is not correct!";
OpenMesh::VPropHandleT<float> qualityProp;
OpenMesh::VPropHandleT<unsigned int> indexProp;
EXPECT_TRUE(mesh_.get_property_handle(qualityProp,"quality")) << "Could not access quality property";
EXPECT_TRUE(mesh_.get_property_handle(indexProp,"index")) << "Could not access index property";
//check index property
for (unsigned i = 0; i < mesh_.n_vertices(); ++i)
EXPECT_EQ(i ,mesh_.property(indexProp,OpenMesh::VertexHandle(i))) << "Vertex index at vertex " << i << " is wrong";
//check quality property
EXPECT_EQ(1.f,mesh_.property(qualityProp,OpenMesh::VertexHandle(0))) << "Wrong quality value at Vertex 0";
EXPECT_EQ(0.5f,mesh_.property(qualityProp,OpenMesh::VertexHandle(1))) << "Wrong quality value at Vertex 1";
EXPECT_EQ(0.7f,mesh_.property(qualityProp,OpenMesh::VertexHandle(2))) << "Wrong quality value at Vertex 2";
EXPECT_EQ(1.f,mesh_.property(qualityProp,OpenMesh::VertexHandle(3))) << "Wrong quality value at Vertex 3";
EXPECT_EQ(0.1f,mesh_.property(qualityProp,OpenMesh::VertexHandle(4))) << "Wrong quality value at Vertex 4";
EXPECT_EQ(0.f,mesh_.property(qualityProp,OpenMesh::VertexHandle(5))) << "Wrong quality value at Vertex 5";
EXPECT_EQ(2.f,mesh_.property(qualityProp,OpenMesh::VertexHandle(6))) << "Wrong quality value at Vertex 6";
EXPECT_EQ(5.f,mesh_.property(qualityProp,OpenMesh::VertexHandle(7))) << "Wrong quality value at Vertex 7";
} }
} }
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment