- now the OM reader also checks user options
- added some corresponding unittests refs #1077 git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@743 fdac6126-5c0c-442c-9429-916003d36597
This commit is contained in:
@@ -89,6 +89,7 @@ bool _OMReader_::read(const std::string& _filename, BaseImporter& _bi, Options&
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
_opt += Options::Binary; // only binary format supported!
|
_opt += Options::Binary; // only binary format supported!
|
||||||
|
fileOptions_ = Options::Binary;
|
||||||
|
|
||||||
// Open file
|
// Open file
|
||||||
std::ifstream ifs(_filename.c_str(), std::ios::binary);
|
std::ifstream ifs(_filename.c_str(), std::ios::binary);
|
||||||
@@ -103,6 +104,8 @@ bool _OMReader_::read(const std::string& _filename, BaseImporter& _bi, Options&
|
|||||||
// close input stream
|
// close input stream
|
||||||
ifs.close();
|
ifs.close();
|
||||||
|
|
||||||
|
_opt = _opt & fileOptions_;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,6 +119,7 @@ bool _OMReader_::read(std::istream& _is, BaseImporter& _bi, Options& _opt)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
_opt += Options::Binary; // only binary format supported!
|
_opt += Options::Binary; // only binary format supported!
|
||||||
|
fileOptions_ = Options::Binary;
|
||||||
|
|
||||||
if (!_is.good()) {
|
if (!_is.good()) {
|
||||||
omerr() << "[OMReader] : cannot read from stream " << std::endl;
|
omerr() << "[OMReader] : cannot read from stream " << std::endl;
|
||||||
@@ -128,6 +132,8 @@ bool _OMReader_::read(std::istream& _is, BaseImporter& _bi, Options& _opt)
|
|||||||
if (result)
|
if (result)
|
||||||
_opt += Options::Binary;
|
_opt += Options::Binary;
|
||||||
|
|
||||||
|
_opt = _opt & fileOptions_;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,20 +295,22 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
|
|||||||
case Chunk::Type_Normal:
|
case Chunk::Type_Normal:
|
||||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
|
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
|
||||||
|
|
||||||
_opt += Options::VertexNormal;
|
fileOptions_ += Options::VertexNormal;
|
||||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
||||||
bytes_ += vector_restore(_is, v3f, _swap);
|
bytes_ += vector_restore(_is, v3f, _swap);
|
||||||
_bi.set_normal(VertexHandle(vidx), v3f);
|
if (fileOptions_.vertex_has_normal() && _opt.vertex_has_normal())
|
||||||
|
_bi.set_normal(VertexHandle(vidx), v3f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Chunk::Type_Texcoord:
|
case Chunk::Type_Texcoord:
|
||||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec2f::dim()));
|
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec2f::dim()));
|
||||||
|
|
||||||
_opt += Options::VertexTexCoord;
|
fileOptions_ += Options::VertexTexCoord;
|
||||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
||||||
bytes_ += vector_restore(_is, v2f, _swap);
|
bytes_ += vector_restore(_is, v2f, _swap);
|
||||||
_bi.set_texcoord(VertexHandle(vidx), v2f);
|
if (fileOptions_.vertex_has_texcoord() && _opt.vertex_has_texcoord())
|
||||||
|
_bi.set_texcoord(VertexHandle(vidx), v2f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -310,11 +318,12 @@ bool _OMReader_::read_binary_vertex_chunk(std::istream &_is, BaseImporter &_bi,
|
|||||||
|
|
||||||
assert( OMFormat::dimensions(chunk_header_) == 3);
|
assert( OMFormat::dimensions(chunk_header_) == 3);
|
||||||
|
|
||||||
_opt += Options::VertexColor;
|
fileOptions_ += Options::VertexColor;
|
||||||
|
|
||||||
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
for (; vidx < header_.n_vertices_ && !_is.eof(); ++vidx) {
|
||||||
bytes_ += vector_restore(_is, v3uc, _swap);
|
bytes_ += vector_restore(_is, v3uc, _swap);
|
||||||
_bi.set_color(VertexHandle(vidx), v3uc);
|
if (fileOptions_.vertex_has_color() && _opt.vertex_has_color())
|
||||||
|
_bi.set_color(VertexHandle(vidx), v3uc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -386,10 +395,11 @@ bool _OMReader_::read_binary_face_chunk(std::istream &_is, BaseImporter &_bi, Op
|
|||||||
case Chunk::Type_Normal:
|
case Chunk::Type_Normal:
|
||||||
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
|
assert( OMFormat::dimensions(chunk_header_) == size_t(OpenMesh::Vec3f::dim()));
|
||||||
|
|
||||||
_opt += Options::FaceNormal;
|
fileOptions_ += Options::FaceNormal;
|
||||||
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
|
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
|
||||||
bytes_ += vector_restore(_is, v3f, _swap);
|
bytes_ += vector_restore(_is, v3f, _swap);
|
||||||
_bi.set_normal(FaceHandle(fidx), v3f);
|
if( fileOptions_.face_has_normal() && _opt.face_has_normal())
|
||||||
|
_bi.set_normal(FaceHandle(fidx), v3f);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -397,10 +407,11 @@ bool _OMReader_::read_binary_face_chunk(std::istream &_is, BaseImporter &_bi, Op
|
|||||||
|
|
||||||
assert( OMFormat::dimensions(chunk_header_) == 3);
|
assert( OMFormat::dimensions(chunk_header_) == 3);
|
||||||
|
|
||||||
_opt += Options::FaceColor;
|
fileOptions_ += Options::FaceColor;
|
||||||
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
|
for (; fidx < header_.n_faces_ && !_is.eof(); ++fidx) {
|
||||||
bytes_ += vector_restore(_is, v3uc, _swap);
|
bytes_ += vector_restore(_is, v3uc, _swap);
|
||||||
_bi.set_color(FaceHandle(fidx), v3uc);
|
if( fileOptions_.face_has_color() && _opt.face_has_color())
|
||||||
|
_bi.set_color(FaceHandle(fidx), v3uc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|||||||
@@ -4,10 +4,10 @@
|
|||||||
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
|
* Copyright (C) 2001-2012 by Computer Graphics Group, RWTH Aachen *
|
||||||
* www.openmesh.org *
|
* www.openmesh.org *
|
||||||
* *
|
* *
|
||||||
*---------------------------------------------------------------------------*
|
*---------------------------------------------------------------------------*
|
||||||
* This file is part of OpenMesh. *
|
* This file is part of OpenMesh. *
|
||||||
* *
|
* *
|
||||||
* OpenMesh is free software: you can redistribute it and/or modify *
|
* OpenMesh is free software: you can redistribute it and/or modify *
|
||||||
* it under the terms of the GNU Lesser General Public License as *
|
* it under the terms of the GNU Lesser General Public License as *
|
||||||
* published by the Free Software Foundation, either version 3 of *
|
* published by the Free Software Foundation, either version 3 of *
|
||||||
* the License, or (at your option) any later version with the *
|
* the License, or (at your option) any later version with the *
|
||||||
@@ -30,10 +30,10 @@
|
|||||||
* License along with OpenMesh. If not, *
|
* License along with OpenMesh. If not, *
|
||||||
* see <http://www.gnu.org/licenses/>. *
|
* see <http://www.gnu.org/licenses/>. *
|
||||||
* *
|
* *
|
||||||
\*===========================================================================*/
|
\*===========================================================================*/
|
||||||
|
|
||||||
/*===========================================================================*\
|
/*===========================================================================*\
|
||||||
* *
|
* *
|
||||||
* $Revision$ *
|
* $Revision$ *
|
||||||
* $Date$ *
|
* $Date$ *
|
||||||
* *
|
* *
|
||||||
@@ -76,8 +76,8 @@ namespace IO {
|
|||||||
//== IMPLEMENTATION ===========================================================
|
//== IMPLEMENTATION ===========================================================
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Implementation of the OM format reader. This class is singleton'ed by
|
Implementation of the OM format reader. This class is singleton'ed by
|
||||||
SingletonT to OMReader.
|
SingletonT to OMReader.
|
||||||
*/
|
*/
|
||||||
class OPENMESHDLLEXPORT _OMReader_ : public BaseReader
|
class OPENMESHDLLEXPORT _OMReader_ : public BaseReader
|
||||||
@@ -90,20 +90,20 @@ public:
|
|||||||
std::string get_description() const { return "OpenMesh File Format"; }
|
std::string get_description() const { return "OpenMesh File Format"; }
|
||||||
std::string get_extensions() const { return "om"; }
|
std::string get_extensions() const { return "om"; }
|
||||||
std::string get_magic() const { return "OM"; }
|
std::string get_magic() const { return "OM"; }
|
||||||
|
|
||||||
bool read(const std::string& _filename,
|
bool read(const std::string& _filename,
|
||||||
BaseImporter& _bi,
|
BaseImporter& _bi,
|
||||||
Options& _opt );
|
Options& _opt );
|
||||||
|
|
||||||
//! Stream Reader for std::istream input in binary format
|
//! Stream Reader for std::istream input in binary format
|
||||||
bool read(std::istream& _is,
|
bool read(std::istream& _is,
|
||||||
BaseImporter& _bi,
|
BaseImporter& _bi,
|
||||||
Options& _opt );
|
Options& _opt );
|
||||||
|
|
||||||
virtual bool can_u_read(const std::string& _filename) const;
|
virtual bool can_u_read(const std::string& _filename) const;
|
||||||
virtual bool can_u_read(std::istream& _is) const;
|
virtual bool can_u_read(std::istream& _is) const;
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
bool supports( const OMFormat::uint8 version ) const;
|
bool supports( const OMFormat::uint8 version ) const;
|
||||||
@@ -117,38 +117,39 @@ private:
|
|||||||
|
|
||||||
// initialized/updated by read_binary*/read_ascii*
|
// initialized/updated by read_binary*/read_ascii*
|
||||||
mutable size_t bytes_;
|
mutable size_t bytes_;
|
||||||
|
mutable Options fileOptions_;
|
||||||
mutable Header header_;
|
mutable Header header_;
|
||||||
mutable ChunkHeader chunk_header_;
|
mutable ChunkHeader chunk_header_;
|
||||||
mutable PropertyName property_name_;
|
mutable PropertyName property_name_;
|
||||||
|
|
||||||
bool read_binary_vertex_chunk( std::istream &_is,
|
bool read_binary_vertex_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap) const;
|
bool _swap) const;
|
||||||
|
|
||||||
bool read_binary_face_chunk( std::istream &_is,
|
bool read_binary_face_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap) const;
|
bool _swap) const;
|
||||||
|
|
||||||
bool read_binary_edge_chunk( std::istream &_is,
|
bool read_binary_edge_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap) const;
|
bool _swap) const;
|
||||||
|
|
||||||
bool read_binary_halfedge_chunk( std::istream &_is,
|
bool read_binary_halfedge_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap) const;
|
bool _swap) const;
|
||||||
|
|
||||||
bool read_binary_mesh_chunk( std::istream &_is,
|
bool read_binary_mesh_chunk( std::istream &_is,
|
||||||
BaseImporter &_bi,
|
BaseImporter &_bi,
|
||||||
Options &_opt,
|
Options &_opt,
|
||||||
bool _swap) const;
|
bool _swap) const;
|
||||||
|
|
||||||
size_t restore_binary_custom_data( std::istream& _is,
|
size_t restore_binary_custom_data( std::istream& _is,
|
||||||
BaseProperty* _bp,
|
BaseProperty* _bp,
|
||||||
size_t _n_elem,
|
size_t _n_elem,
|
||||||
bool _swap) const;
|
bool _swap) const;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
BIN
src/Unittests/TestFiles/cube-minimal-texCoords.om
Normal file
BIN
src/Unittests/TestFiles/cube-minimal-texCoords.om
Normal file
Binary file not shown.
BIN
src/Unittests/TestFiles/cube-minimal-vertexColors.om
Normal file
BIN
src/Unittests/TestFiles/cube-minimal-vertexColors.om
Normal file
Binary file not shown.
@@ -531,5 +531,87 @@ TEST_F(OpenMeshLoader, LoadSimplePLYWithNormals) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Just load an om file of a cube with vertex texCoords
|
||||||
|
*/
|
||||||
|
TEST_F(OpenMeshLoader, LoadSimpleOMWithTexCoords) {
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
mesh_.request_vertex_texcoords2D();
|
||||||
|
|
||||||
|
OpenMesh::IO::Options options;
|
||||||
|
options += OpenMesh::IO::Options::VertexTexCoord;
|
||||||
|
|
||||||
|
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-texCoords.om",options);
|
||||||
|
|
||||||
|
EXPECT_TRUE(ok) << "Unable to load cube-minimal-texCoords.om";
|
||||||
|
|
||||||
|
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(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[0] ) << "Wrong vertex color at vertex 0 component 0";
|
||||||
|
EXPECT_EQ(10, mesh_.texcoord2D(mesh_.vertex_handle(0))[1] ) << "Wrong vertex color at vertex 0 component 1";
|
||||||
|
|
||||||
|
EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[0] ) << "Wrong vertex color at vertex 2 component 0";
|
||||||
|
EXPECT_EQ(6, mesh_.texcoord2D(mesh_.vertex_handle(2))[1] ) << "Wrong vertex color at vertex 2 component 1";
|
||||||
|
|
||||||
|
EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
|
||||||
|
EXPECT_EQ(9, mesh_.texcoord2D(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
|
||||||
|
|
||||||
|
EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
|
||||||
|
EXPECT_EQ(12, mesh_.texcoord2D(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
|
||||||
|
|
||||||
|
|
||||||
|
EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
|
||||||
|
EXPECT_TRUE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
|
||||||
|
EXPECT_FALSE(options.vertex_has_color()) << "Wrong user options are returned!";
|
||||||
|
|
||||||
|
mesh_.release_vertex_texcoords2D();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Just load an om file of a cube with vertex colors
|
||||||
|
*/
|
||||||
|
TEST_F(OpenMeshLoader, LoadSimpleOMWithVertexColors) {
|
||||||
|
|
||||||
|
mesh_.clear();
|
||||||
|
|
||||||
|
mesh_.request_vertex_colors();
|
||||||
|
|
||||||
|
OpenMesh::IO::Options options;
|
||||||
|
options += OpenMesh::IO::Options::VertexColor;
|
||||||
|
|
||||||
|
bool ok = OpenMesh::IO::read_mesh(mesh_, "cube-minimal-vertexColors.om",options);
|
||||||
|
|
||||||
|
EXPECT_TRUE(ok) << "Unable to load cube-minimal-vertexColors.om";
|
||||||
|
|
||||||
|
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(255, 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";
|
||||||
|
|
||||||
|
EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(3))[0] ) << "Wrong vertex color at vertex 3 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[1] ) << "Wrong vertex color at vertex 3 component 1";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(3))[2] ) << "Wrong vertex color at vertex 3 component 2";
|
||||||
|
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[0] ) << "Wrong vertex color at vertex 4 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(4))[1] ) << "Wrong vertex color at vertex 4 component 1";
|
||||||
|
EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(4))[2] ) << "Wrong vertex color at vertex 4 component 2";
|
||||||
|
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[0] ) << "Wrong vertex color at vertex 7 component 0";
|
||||||
|
EXPECT_EQ(0, mesh_.color(mesh_.vertex_handle(7))[1] ) << "Wrong vertex color at vertex 7 component 1";
|
||||||
|
EXPECT_EQ(255, mesh_.color(mesh_.vertex_handle(7))[2] ) << "Wrong vertex color at vertex 7 component 2";
|
||||||
|
|
||||||
|
EXPECT_FALSE(options.vertex_has_normal()) << "Wrong user options are returned!";
|
||||||
|
EXPECT_FALSE(options.vertex_has_texcoord()) << "Wrong user options are returned!";
|
||||||
|
EXPECT_TRUE(options.vertex_has_color()) << "Wrong user options are returned!";
|
||||||
|
|
||||||
|
mesh_.release_vertex_colors();
|
||||||
|
}
|
||||||
|
|
||||||
#endif // INCLUDE GUARD
|
#endif // INCLUDE GUARD
|
||||||
|
|||||||
Reference in New Issue
Block a user