diff --git a/src/OpenMesh/Core/IO/reader/PLYReader.cc b/src/OpenMesh/Core/IO/reader/PLYReader.cc index 93f902f2..3970a29e 100644 --- a/src/OpenMesh/Core/IO/reader/PLYReader.cc +++ b/src/OpenMesh/Core/IO/reader/PLYReader.cc @@ -158,7 +158,7 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) { // if ( options_.is_binary() && userOptions_.color_has_alpha() ) // options_ += Options::ColorAlpha; - return (options_.is_binary() ? read_binary(_in, _bi, swap) : read_ascii(_in, _bi)); + return (options_.is_binary() ? read_binary(_in, _bi, swap, _opt) : read_ascii(_in, _bi, _opt)); } @@ -166,7 +166,7 @@ bool _PLYReader_::read(std::istream& _in, BaseImporter& _bi, Options& _opt) { //----------------------------------------------------------------------------- -bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const { +bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi, const Options& _opt) const { omlog() << "[PLYReader] : read ascii file\n"; @@ -276,9 +276,12 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const { } vh = _bi.add_vertex(v); - _bi.set_normal(vh, n); - _bi.set_texcoord(vh, t); - _bi.set_color(vh, Vec4uc(c)); + if (_opt.vertex_has_normal()) + _bi.set_normal(vh, n); + if (_opt.vertex_has_texcoord()) + _bi.set_texcoord(vh, t); + if (_opt.vertex_has_color()) + _bi.set_color(vh, Vec4uc(c)); } // faces @@ -314,7 +317,7 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const { //----------------------------------------------------------------------------- -bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/) const { +bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap*/, const Options& _opt) const { omlog() << "[PLYReader] : read binary file format\n"; @@ -425,9 +428,12 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap } vh = _bi.add_vertex(v); - _bi.set_normal(vh, n); - _bi.set_texcoord(vh, t); - _bi.set_color(vh, Vec4uc(c)); + if (_opt.vertex_has_normal()) + _bi.set_normal(vh, n); + if (_opt.vertex_has_texcoord()) + _bi.set_texcoord(vh, t); + if (_opt.vertex_has_color()) + _bi.set_color(vh, Vec4uc(c)); } for (i = 0; i < faceCount_; ++i) { @@ -484,7 +490,7 @@ void _PLYReader_::readValue(ValueType _type, std::istream& _in, float& _value) c void _PLYReader_::readValue(ValueType _type, std::istream& _in, double& _value) const { switch (_type) { - + case ValueTypeFLOAT64: case ValueTypeDOUBLE: @@ -519,7 +525,7 @@ void _PLYReader_::readValue(ValueType _type, std::istream& _in, unsigned int& _v case ValueTypeUINT: case ValueTypeUINT32: - + restore(_in, tmp_uint32_t, options_.check(Options::MSB)); _value = tmp_uint32_t; @@ -628,7 +634,7 @@ void _PLYReader_::readInteger(ValueType _type, std::istream& _in, int& _value) c restore(_in, tmp_uint32_t, options_.check(Options::MSB)); _value = tmp_uint32_t; - + break; case ValueTypeCHAR: @@ -721,7 +727,7 @@ void _PLYReader_::readInteger(ValueType _type, std::istream& _in, unsigned int& bool _PLYReader_::can_u_read(const std::string& _filename) const { - + // !!! Assuming BaseReader::can_u_parse( std::string& ) // does not call BaseReader::read_magic()!!! @@ -740,7 +746,7 @@ bool _PLYReader_::can_u_read(const std::string& _filename) const { //----------------------------------------------------------------------------- std::string get_property_name(std::string _string1, std::string _string2) { - + if (_string1 == "float32" || _string1 == "float64" || _string1 == "float" || _string1 == "double" || _string1 == "int8" || _string1 == "uint8" || _string1 == "char" || _string1 == "uchar" || _string1 == "int32" || _string1 == "uint32" || _string1 == "int" || _string1 == "uint" || @@ -1005,7 +1011,7 @@ bool _PLYReader_::can_u_read(std::istream& _is) const { } else if (propertyName == "diffuse_blue") { std::pair entry(COLORBLUE, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; - options_ += Options::VertexColor; + options_ += Options::VertexColor; } else if (propertyName == "alpha") { std::pair entry(COLORALPHA, valueType); vertexPropertyMap_[vertexPropertyCount_] = entry; diff --git a/src/OpenMesh/Core/IO/reader/PLYReader.hh b/src/OpenMesh/Core/IO/reader/PLYReader.hh index 8649c45d..cc322cab 100644 --- a/src/OpenMesh/Core/IO/reader/PLYReader.hh +++ b/src/OpenMesh/Core/IO/reader/PLYReader.hh @@ -125,8 +125,8 @@ private: bool can_u_read(std::istream& _is) const; - bool read_ascii(std::istream& _in, BaseImporter& _bi) const; - bool read_binary(std::istream& _in, BaseImporter& _bi, bool swap) const; + bool read_ascii(std::istream& _in, BaseImporter& _bi, 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; @@ -138,14 +138,14 @@ private: void readInteger(ValueType _type, std::istream& _in, int& _value) const; void readInteger(ValueType _type, std::istream& _in, unsigned int& _value) const; - /// Read unsupported properties in PLY file + /// Read unsupported properties in PLY file void consume_input(std::istream& _in, int _count) const { _in.read(reinterpret_cast(&buff[0]), _count); } mutable unsigned char buff[8]; - /// Available options for reading + /// Available per file options for reading mutable Options options_; /// Options that the user wants to read diff --git a/src/Unittests/unittests_loading.hh b/src/Unittests/unittests_loading.hh index 70c80bc1..46db12cd 100644 --- a/src/Unittests/unittests_loading.hh +++ b/src/Unittests/unittests_loading.hh @@ -11,7 +11,7 @@ class OpenMeshLoader : public OpenMeshBase { // This function is called before each test is run virtual void SetUp() { - + // Do some initial stuff with the member data here... } @@ -22,7 +22,7 @@ class OpenMeshLoader : public OpenMeshBase { } // Member already defined in OpenMeshBase - //Mesh mesh_; + //Mesh mesh_; }; /* @@ -297,7 +297,7 @@ TEST_F(OpenMeshLoader, LoadSimpleOBJWithVertexColorsAfterVertices) { 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!"; - + EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0"; EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1"; EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(0))[2] ) << "Wrong vertex color at vertex 0 component 2"; @@ -383,8 +383,11 @@ TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) { mesh_.clear(); mesh_.request_vertex_normals(); - - bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply"); + + OpenMesh::IO::Options options; + options += OpenMesh::IO::Options::VertexNormal; + + bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-normals.ply", options); EXPECT_TRUE(ok) << "Unable to load cube-minimal-normals.ply"; @@ -392,6 +395,10 @@ TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) { 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!"; + EXPECT_TRUE(options.vertex_has_normal()) << "Wrong user options are returned!"; + EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!"; + EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!"; + EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[0] ) << "Wrong normal at vertex 0 component 0"; EXPECT_EQ(0, mesh_.normal(mesh_.vertex_handle(0))[1] ) << "Wrong normal at vertex 0 component 1";