- the PLY reader now checks the options set by the user and will skip components that are not requested
- modified the loading unittest to test this behavior refs #1077 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@741 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -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,8 +276,11 @@ bool _PLYReader_::read_ascii(std::istream& _in, BaseImporter& _bi) const {
|
||||
}
|
||||
|
||||
vh = _bi.add_vertex(v);
|
||||
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));
|
||||
}
|
||||
|
||||
@@ -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,8 +428,11 @@ bool _PLYReader_::read_binary(std::istream& _in, BaseImporter& _bi, bool /*_swap
|
||||
}
|
||||
|
||||
vh = _bi.add_vertex(v);
|
||||
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));
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -145,7 +145,7 @@ private:
|
||||
|
||||
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
|
||||
|
||||
@@ -384,7 +384,10 @@ TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) {
|
||||
|
||||
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";
|
||||
|
||||
Reference in New Issue
Block a user