From 5094916ff67f89159ea98467e75dc341681d1a94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20M=C3=B6bius?= Date: Tue, 17 Sep 2013 13:09:19 +0000 Subject: [PATCH] =?UTF-8?q?Bugfix=20=20:=20If=20bool=20property=20is=20wri?= =?UTF-8?q?tten=20and=20conatins=200x20=20in=20file,=20reader=20will=20fai?= =?UTF-8?q?l=20(Thanks=20to=20Simon=20Fl=C3=B6ry=20for=20the=20patch)=20Un?= =?UTF-8?q?ittest:=20Added=20test=20case=20for=20this=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://www.openmesh.org/svnrepo/OpenMesh/trunk@957 fdac6126-5c0c-442c-9429-916003d36597 --- src/OpenMesh/Core/IO/reader/OMReader.cc | 7 +++ src/Unittests/unittests_read_write_OM.hh | 72 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+) diff --git a/src/OpenMesh/Core/IO/reader/OMReader.cc b/src/OpenMesh/Core/IO/reader/OMReader.cc index 60514111..1767f82e 100644 --- a/src/OpenMesh/Core/IO/reader/OMReader.cc +++ b/src/OpenMesh/Core/IO/reader/OMReader.cc @@ -93,6 +93,13 @@ bool _OMReader_::read(const std::string& _filename, BaseImporter& _bi, Options& // Open file std::ifstream ifs(_filename.c_str(), std::ios::binary); + + /* Clear formatting flag skipws (Skip whitespaces). If set, operator>> will + * skip bytes set to whitespace chars (e.g. 0x20 bytes) in + * Property::restore. + */ + ifs.unsetf(std::ios::skipws); + if (!ifs.is_open() || !ifs.good()) { omerr() << "[OMReader] : cannot not open file " << _filename << std::endl; return false; diff --git a/src/Unittests/unittests_read_write_OM.hh b/src/Unittests/unittests_read_write_OM.hh index dc2e709e..eb8bbd3d 100644 --- a/src/Unittests/unittests_read_write_OM.hh +++ b/src/Unittests/unittests_read_write_OM.hh @@ -300,6 +300,78 @@ TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolProperty) { } +/* + * Save and load simple mesh with custom property + */ +TEST_F(OpenMeshReadWriteOM, WriteTriangleVertexBoolPropertySpaceEquivalent) { + + Mesh mesh; + + const std::string filename = "triangle-minimal-VBProp-pattern-test.om"; + + // generate data + Mesh::VertexHandle v1 = mesh.add_vertex(Mesh::Point(1.0,0.0,0.0)); + Mesh::VertexHandle v2 = mesh.add_vertex(Mesh::Point(0.0,1.0,0.0)); + Mesh::VertexHandle v3 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + mesh.add_face(v1,v2,v3); + + Mesh::VertexHandle v4 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + Mesh::VertexHandle v5 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + Mesh::VertexHandle v6 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + mesh.add_face(v4,v5,v6); + + Mesh::VertexHandle v7 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + Mesh::VertexHandle v8 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + Mesh::VertexHandle v9 = mesh.add_vertex(Mesh::Point(0.0,0.0,1.0)); + + OpenMesh::VPropHandleT prop; + mesh.add_property(prop,"VBProp"); + mesh.property(prop).set_persistent(true); + + // Create a 0x20 hex pattern in the bitset + mesh.property(prop,v1) = false; + mesh.property(prop,v2) = false; + mesh.property(prop,v3) = false; + mesh.property(prop,v4) = false; + mesh.property(prop,v5) = false; + mesh.property(prop,v6) = true; + mesh.property(prop,v7) = false; + mesh.property(prop,v8) = false; + mesh.property(prop,v9) = true; + + // save + bool ok = OpenMesh::IO::write_mesh(mesh,filename); + EXPECT_TRUE(ok) << "Unable to write "<