diff --git a/src/OpenMesh/Core/IO/Options.hh b/src/OpenMesh/Core/IO/Options.hh index 1bf62e6add4c5bdb7703b62480108018d7114647..ebd70e2ac5f4614644760407a2de1a694f79e0b4 100644 --- a/src/OpenMesh/Core/IO/Options.hh +++ b/src/OpenMesh/Core/IO/Options.hh @@ -106,8 +106,9 @@ public: FaceNormal = 0x0100, ///< Has (r) / store (w) face normals FaceColor = 0x0200, ///< Has (r) / store (w) face colors FaceTexCoord = 0x0400, ///< Has (r) / store (w) face texture coordinates - 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) + 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) + Custom = 0x2000 ///< Has (r) custom properties (currently only implemented in PLY Reader ASCII version) }; public: diff --git a/src/OpenMesh/Core/IO/importer/BaseImporter.hh b/src/OpenMesh/Core/IO/importer/BaseImporter.hh index cd6815385fd4f285a614e0724be2641d144e16d1..1bb97efe421d0faa5dafbd484aa12a27bff5dc53 100644 --- a/src/OpenMesh/Core/IO/importer/BaseImporter.hh +++ b/src/OpenMesh/Core/IO/importer/BaseImporter.hh @@ -89,6 +89,9 @@ public: // add a vertex with coordinate \c _point 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 typedef std::vector VHandles; virtual FaceHandle add_face(const VHandles& _indices) = 0; @@ -99,6 +102,9 @@ public: // Set the texture index for a face 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 virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) = 0; diff --git a/src/OpenMesh/Core/IO/importer/ImporterT.hh b/src/OpenMesh/Core/IO/importer/ImporterT.hh index 7fa652ea129e0dac1ab18a252d8fee662c8f95a8..f93a0900ed64c57dba349ded6295900822cfe786 100644 --- a/src/OpenMesh/Core/IO/importer/ImporterT.hh +++ b/src/OpenMesh/Core/IO/importer/ImporterT.hh @@ -94,6 +94,10 @@ public: return mesh_.add_vertex(vector_cast(_point)); } + virtual VertexHandle add_vertex() + { + return mesh_.new_vertex(); + } virtual FaceHandle add_face(const VHandles& _indices) { @@ -154,6 +158,11 @@ public: // vertex attributes + virtual void set_point(VertexHandle _vh, const Vec3f& _point) + { + mesh_.set_point(_vh,vector_cast(_point)); + } + virtual void set_normal(VertexHandle _vh, const Vec3f& _normal) { if (mesh_.has_vertex_normals()) diff --git a/src/OpenMesh/Core/IO/reader/PLYReader.cc b/src/OpenMesh/Core/IO/reader/PLYReader.cc index b85f8a434fa93842d9d7228e4489d62adca2ebb3..1f150e79d6520e2043a49b02eaa6bd616f930545 100644 --- a/src/OpenMesh/Core/IO/reader/PLYReader.cc +++ b/src/OpenMesh/Core/IO/reader/PLYReader.cc @@ -156,6 +156,9 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) { if (options_.color_is_float()) { _opt += Options::ColorFloat; } + if (options_.check(Options::Custom) && userOptions_.check(Options::Custom)) { + _opt += Options::Custom; + } // //force user-choice for the alpha value when reading binary // if ( options_.is_binary() && userOptions_.color_has_alpha() ) @@ -165,6 +168,55 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) { } +template +void assignCustomProperty(std::istream& _in, BaseImporter& _bi, VertexHandle _vh, const std::string& _propName) +{ + OpenMesh::VPropHandleT prop; + if (!_bi.kernel()->get_property_handle(prop,_propName)) + _bi.kernel()->add_property(prop,_propName); + T in; + _in >> in; + _bi.kernel()->property(prop,_vh) = in; +} + + +void _PLYReader_::readCustomProperty(std::istream& _in, BaseImporter& _bi, VertexHandle _vh, const std::string& _propName, const ValueType _valueType) const +{ + switch (_valueType) + { + case ValueTypeINT8: + case ValueTypeCHAR: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + case ValueTypeINT16: + case ValueTypeSHORT: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + case ValueTypeUINT16: + case ValueTypeUSHORT: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + case ValueTypeINT32: + case ValueTypeINT: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + case ValueTypeUINT32: + case ValueTypeUINT: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + case ValueTypeFLOAT32: + case ValueTypeFLOAT: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + case ValueTypeFLOAT64: + case ValueTypeDOUBLE: + assignCustomProperty(_in,_bi,_vh,_propName); + break; + default: + std::cerr << "unsupported type" << std::endl; + break; + } +} //----------------------------------------------------------------------------- @@ -196,6 +248,8 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options // read vertices: for (i = 0; i < vertexCount_ && !_in.eof(); ++i) { + vh = _bi.add_vertex(); + v[0] = 0.0; v[1] = 0.0; v[2] = 0.0; @@ -213,7 +267,7 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options c[3] = 255; for (uint propertyIndex = 0; propertyIndex < vertexPropertyCount_; ++propertyIndex) { - switch (vertexPropertyMap_[propertyIndex].first) { + switch (vertexPropertyMap_[propertyIndex].property) { case XCOORD: _in >> v[0]; break; @@ -239,44 +293,50 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options _in >> t[1]; break; case COLORRED: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { _in >> tmp; c[0] = static_cast (tmp * 255.0f); } else _in >> c[0]; break; case COLORGREEN: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { _in >> tmp; c[1] = static_cast (tmp * 255.0f); } else _in >> c[1]; break; case COLORBLUE: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { _in >> tmp; c[2] = static_cast (tmp * 255.0f); } else _in >> c[2]; break; case COLORALPHA: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { _in >> tmp; c[3] = static_cast (tmp * 255.0f); } else _in >> c[3]; break; + case CUSTOM_PROP: + if (_opt.check(Options::Custom)) + readCustomProperty(_in, _bi, vh, vertexPropertyMap_[propertyIndex].name, vertexPropertyMap_[propertyIndex].value); + else + _in >> trash; + break; default: _in >> trash; break; } } - vh = _bi.add_vertex(v); + _bi.set_point(vh, v); if (_opt.vertex_has_normal()) _bi.set_normal(vh, n); if (_opt.vertex_has_texcoord()) @@ -356,71 +416,71 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap c[3] = 255; for (uint propertyIndex = 0; propertyIndex < vertexPropertyCount_; ++propertyIndex) { - switch (vertexPropertyMap_[propertyIndex].first) { + switch (vertexPropertyMap_[propertyIndex].property) { case XCOORD: - readValue(vertexPropertyMap_[propertyIndex].second, _in, v[0]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, v[0]); break; case YCOORD: - readValue(vertexPropertyMap_[propertyIndex].second, _in, v[1]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, v[1]); break; case ZCOORD: - readValue(vertexPropertyMap_[propertyIndex].second, _in, v[2]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, v[2]); break; case XNORM: - readValue(vertexPropertyMap_[propertyIndex].second, _in, n[0]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, n[0]); break; case YNORM: - readValue(vertexPropertyMap_[propertyIndex].second, _in, n[1]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, n[1]); break; case ZNORM: - readValue(vertexPropertyMap_[propertyIndex].second, _in, n[2]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, n[2]); break; case TEXX: - readValue(vertexPropertyMap_[propertyIndex].second, _in, t[0]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, t[0]); break; case TEXY: - readValue(vertexPropertyMap_[propertyIndex].second, _in, t[1]); + readValue(vertexPropertyMap_[propertyIndex].value, _in, t[1]); break; case COLORRED: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { - readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp); + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { + readValue(vertexPropertyMap_[propertyIndex].value, _in, tmp); c[0] = static_cast (tmp * 255.0f); } else - readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[0]); + readInteger(vertexPropertyMap_[propertyIndex].value, _in, c[0]); break; case COLORGREEN: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { - readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp); + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { + readValue(vertexPropertyMap_[propertyIndex].value, _in, tmp); c[1] = static_cast (tmp * 255.0f); } else - readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[1]); + readInteger(vertexPropertyMap_[propertyIndex].value, _in, c[1]); break; case COLORBLUE: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { - readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp); + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { + readValue(vertexPropertyMap_[propertyIndex].value, _in, tmp); c[2] = static_cast (tmp * 255.0f); } else - readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[2]); + readInteger(vertexPropertyMap_[propertyIndex].value, _in, c[2]); break; case COLORALPHA: - if (vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT32 || - vertexPropertyMap_[propertyIndex].second == ValueTypeFLOAT) { - readValue(vertexPropertyMap_[propertyIndex].second, _in, tmp); + if (vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT32 || + vertexPropertyMap_[propertyIndex].value == ValueTypeFLOAT) { + readValue(vertexPropertyMap_[propertyIndex].value, _in, tmp); c[3] = static_cast (tmp * 255.0f); } else - readInteger(vertexPropertyMap_[propertyIndex].second, _in, c[3]); + readInteger(vertexPropertyMap_[propertyIndex].value, _in, c[3]); break; default: // Read unsupported property - consume_input(_in, scalar_size_[vertexPropertyMap_[propertyIndex].second]); + consume_input(_in, scalar_size_[vertexPropertyMap_[propertyIndex].value]); break; } @@ -959,84 +1019,86 @@ bool _PLYReader_::can_u_read(std::istream& _is) const { propertyName = get_property_name(tmp1, tmp2); if (propertyName == "x") { - std::pair entry(XCOORD, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - vertexDimension_++; + VertexPropertyInfo entry(XCOORD, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + vertexDimension_++; } else if (propertyName == "y") { - std::pair entry(YCOORD, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - vertexDimension_++; + VertexPropertyInfo entry(YCOORD, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + vertexDimension_++; } else if (propertyName == "z") { - std::pair entry(ZCOORD, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - vertexDimension_++; + VertexPropertyInfo entry(ZCOORD, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + vertexDimension_++; } else if (propertyName == "nx") { - std::pair entry(XNORM, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexNormal; + VertexPropertyInfo entry(XNORM, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexNormal; } else if (propertyName == "ny") { - std::pair entry(YNORM, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexNormal; + VertexPropertyInfo entry(YNORM, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexNormal; } else if (propertyName == "nz") { - std::pair entry(ZNORM, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexNormal; + VertexPropertyInfo entry(ZNORM, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexNormal; } else if (propertyName == "u" || propertyName == "s") { - std::pair entry(TEXX, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexTexCoord; + VertexPropertyInfo entry(TEXX, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexTexCoord; } else if (propertyName == "v" || propertyName == "t") { - std::pair entry(TEXY, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexTexCoord; + VertexPropertyInfo entry(TEXY, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexTexCoord; } else if (propertyName == "red") { - std::pair entry(COLORRED, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexColor; - if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) - options_ += Options::ColorFloat; + VertexPropertyInfo entry(COLORRED, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "green") { - std::pair entry(COLORGREEN, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexColor; - if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) - options_ += Options::ColorFloat; + VertexPropertyInfo entry(COLORGREEN, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "blue") { - std::pair entry(COLORBLUE, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexColor; - if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) - options_ += Options::ColorFloat; + VertexPropertyInfo entry(COLORBLUE, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexColor; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else if (propertyName == "diffuse_red") { - std::pair entry(COLORRED, valueType); + VertexPropertyInfo entry(COLORRED, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) options_ += Options::ColorFloat; } else if (propertyName == "diffuse_green") { - std::pair entry(COLORGREEN, valueType); + VertexPropertyInfo entry(COLORGREEN, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) options_ += Options::ColorFloat; } else if (propertyName == "diffuse_blue") { - std::pair entry(COLORBLUE, valueType); + VertexPropertyInfo entry(COLORBLUE, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; options_ += Options::VertexColor; if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) options_ += Options::ColorFloat; } else if (propertyName == "alpha") { - std::pair entry(COLORALPHA, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexColor; - options_ += Options::ColorAlpha; - if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) - options_ += Options::ColorFloat; + VertexPropertyInfo entry(COLORALPHA, valueType); + vertexPropertyMap_[vertexPropertyCount_] = entry; + options_ += Options::VertexColor; + options_ += Options::ColorAlpha; + if (valueType == ValueTypeFLOAT || valueType == ValueTypeFLOAT32) + options_ += Options::ColorFloat; } else { - std::pair entry(UNSUPPORTED, valueType); - vertexPropertyMap_[vertexPropertyCount_] = entry; - std::cerr << "Unsupported property : " << propertyName << std::endl; + VertexProperty prop = (!options_.is_binary()) ? CUSTOM_PROP : UNSUPPORTED; // loading vertex properties is not yet supported by the binary loader + if (prop != UNSUPPORTED) + options_ += Options::Custom; + VertexPropertyInfo entry(prop, valueType, propertyName); + vertexPropertyMap_[vertexPropertyCount_] = entry; } vertexPropertyCount_++; diff --git a/src/OpenMesh/Core/IO/reader/PLYReader.hh b/src/OpenMesh/Core/IO/reader/PLYReader.hh index 998ae0dca7418f41c66aafa357bec227a325484e..3ed6ad7c0fb486544ee4698c7e026af8b6404c9c 100644 --- a/src/OpenMesh/Core/IO/reader/PLYReader.hh +++ b/src/OpenMesh/Core/IO/reader/PLYReader.hh @@ -129,6 +129,7 @@ private: bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap, const Options& _opt) 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, double& _value) const; @@ -164,7 +165,7 @@ private: XCOORD,YCOORD,ZCOORD, TEXX,TEXY, COLORRED,COLORGREEN,COLORBLUE,COLORALPHA, - XNORM,YNORM,ZNORM, + XNORM,YNORM,ZNORM, CUSTOM_PROP, UNSUPPORTED }; @@ -173,7 +174,16 @@ private: // Number of vertex properties 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_; }; diff --git a/src/Unittests/TestFiles/cube-minimal-custom_props.ply b/src/Unittests/TestFiles/cube-minimal-custom_props.ply new file mode 100644 index 0000000000000000000000000000000000000000..5a94a0b29bb095653623f0fa3d0b65c3c60592ca --- /dev/null +++ b/src/Unittests/TestFiles/cube-minimal-custom_props.ply @@ -0,0 +1,28 @@ +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 diff --git a/src/Unittests/unittests_read_write_PLY.cc b/src/Unittests/unittests_read_write_PLY.cc index 73bbeff90fa1a03aa1670ada14ac2cb400a03c02..1f176a0cebe68a4eb7edd076798fbbc0a775d73e 100644 --- a/src/Unittests/unittests_read_write_PLY.cc +++ b/src/Unittests/unittests_read_write_PLY.cc @@ -438,5 +438,44 @@ TEST_F(OpenMeshReadWritePLY, LoadSimplePLYWithNormals) { 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 qualityProp; + OpenMesh::VPropHandleT 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"; + } }