Merge branch 'master' into use_cmake_GTest_finder

This commit is contained in:
Jan Möbius
2018-10-30 10:19:51 +01:00
15 changed files with 1016 additions and 189 deletions

View File

@@ -728,4 +728,58 @@ TEST_F(OpenMeshReadWritePLY, LoadSimpleBinaryPLYWithExtraElements) {
EXPECT_EQ(12u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
}
/*
* Ignore a file that does not contain vertices and faces
*/
TEST_F(OpenMeshReadWritePLY, IgnoreNonMeshPlyFile) {
mesh_.clear();
std::stringstream data;
data << "ply" << "\n";
data << "format binary_little_endian 1.0" << "\n";
data << "comment Image data" << "\n";
data << "element image 0" << "\n";
data << "property list uint16 uint16 row" << "\n";
data << "end_header" << "\n";
OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
EXPECT_TRUE(ok) << "This empty file should be readable without an error!";
EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
}
/*
* Ignore a file that does not contain vertices and faces
*/
TEST_F(OpenMeshReadWritePLY, FailOnUnknownPropertyTypeForLists) {
mesh_.clear();
std::stringstream data;
data << "ply" << "\n";
data << "format binary_little_endian 1.0" << "\n";
data << "comment Image data" << "\n";
data << "element image 0" << "\n";
data << "property list blibb blubb row" << "\n";
data << "end_header" << "\n";
OpenMesh::IO::Options options = OpenMesh::IO::Options::Binary;
bool ok = OpenMesh::IO::read_mesh(mesh_, data, ".ply", options);
EXPECT_FALSE(ok) << "This file should fail to read!";
EXPECT_EQ(0u, mesh_.n_vertices()) << "The number of loaded vertices is not correct!";
EXPECT_EQ(0u, mesh_.n_edges()) << "The number of loaded edges is not correct!";
EXPECT_EQ(0u, mesh_.n_faces()) << "The number of loaded faces is not correct!";
}
}

View File

@@ -0,0 +1,252 @@
#include <gtest/gtest.h>
#include <Unittests/unittests_common.hh>
#include <iostream>
#include <OpenMesh/Tools/SmartTagger/SmartTaggerT.hh>
namespace {
class OpenMeshSmartTagger : public OpenMeshBase {
protected:
// This function is called before each test is run
virtual void SetUp() {
// Do some initial stuff with the member data here...
}
// This function is called after all tests are through
virtual void TearDown() {
// Do some final stuff with the member data here...
}
// Member already defined in OpenMeshBase
//Mesh mesh_;
};
/*
* ====================================================================
* Define tests below
* ====================================================================
*/
/* Checks SmartTagger on vertices
*/
TEST_F(OpenMeshSmartTagger, SmartTaggerVertices) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[7];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
vhandle[5] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
// Add two faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[1]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[4]);
mesh_.add_face(face_vhandles);
/* Test setup:
0 ==== 2
|\ /|\
| \ / | \
| 1 | 5
| / \ | /
|/ \|/
3 ==== 4
*/
OpenMesh::SmartTaggerVT< Mesh > tagger(mesh_);
EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after init!";
// Reset tagged flag on all vertices
tagger.untag_all();
EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after first untag_all!";
// Set tagged:
tagger.set_tag(vhandle[2]);
tagger.set_tag(vhandle[4]);
EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged!";
EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged!";
EXPECT_TRUE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be tagged!";
EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged!";
EXPECT_TRUE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be tagged!";
EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged!";
// Reset tagged flag on all vertices
tagger.untag_all();
EXPECT_FALSE( tagger.is_tagged(vhandle[0] ) ) << "Vertex should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[1] ) ) << "Vertex should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[2] ) ) << "Vertex should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[3] ) ) << "Vertex should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[4] ) ) << "Vertex should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged(vhandle[5] ) ) << "Vertex should be untagged after second untag_all!";
}
/* Checks SmartTagger on vertices
*/
TEST_F(OpenMeshSmartTagger, SmartTaggerFaces) {
mesh_.clear();
// Add some vertices
Mesh::VertexHandle vhandle[7];
vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
vhandle[1] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
vhandle[2] = mesh_.add_vertex(Mesh::Point(2, 1, 0));
vhandle[3] = mesh_.add_vertex(Mesh::Point(0,-1, 0));
vhandle[4] = mesh_.add_vertex(Mesh::Point(2,-1, 0));
vhandle[5] = mesh_.add_vertex(Mesh::Point(3, 0, 0));
// Add two faces
std::vector<Mesh::VertexHandle> face_vhandles;
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[2]);
Mesh::FaceHandle fh1 = mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[4]);
Mesh::FaceHandle fh2 = mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[0]);
face_vhandles.push_back(vhandle[3]);
face_vhandles.push_back(vhandle[1]);
Mesh::FaceHandle fh3 = mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[1]);
face_vhandles.push_back(vhandle[4]);
Mesh::FaceHandle fh4 = mesh_.add_face(face_vhandles);
face_vhandles.clear();
face_vhandles.push_back(vhandle[5]);
face_vhandles.push_back(vhandle[2]);
face_vhandles.push_back(vhandle[4]);
Mesh::FaceHandle fh5 = mesh_.add_face(face_vhandles);
/* Test setup:
0 ==== 2
|\ /|\
| \ / | \
| 1 | 5
| / \ | /
|/ \|/
3 ==== 4
*/
OpenMesh::SmartTaggerFT< Mesh > tagger(mesh_);
EXPECT_FALSE( tagger.is_tagged( fh1 ) ) << "Face should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged( fh2 ) ) << "Face should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged( fh3 ) ) << "Face should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged( fh4 ) ) << "Face should be untagged after init!";
EXPECT_FALSE( tagger.is_tagged( fh5 ) ) << "Face should be untagged after init!";
// Reset tagged flag on all vertices
tagger.untag_all();
EXPECT_FALSE( tagger.is_tagged( fh1 ) ) << "Face should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh2 ) ) << "Face should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh3 ) ) << "Face should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh4 ) ) << "Face should be untagged after first untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh5 ) ) << "Face should be untagged after first untag_all!";
// Set tagged:
tagger.set_tag(fh3);
tagger.set_tag(fh5);
EXPECT_FALSE( tagger.is_tagged(fh1 ) ) << "Face should be untagged!";
EXPECT_FALSE( tagger.is_tagged(fh2 ) ) << "Face should be untagged!";
EXPECT_TRUE( tagger.is_tagged(fh3 ) ) << "Face should be tagged!";
EXPECT_FALSE( tagger.is_tagged(fh4 ) ) << "Face should be tagged!";
EXPECT_TRUE( tagger.is_tagged(fh5 ) ) << "Face should be tagged!";
// Reset tagged flag on all vertices
tagger.untag_all();
EXPECT_FALSE( tagger.is_tagged( fh1 ) ) << "Face should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh2 ) ) << "Face should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh3 ) ) << "Face should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh4 ) ) << "Face should be untagged after second untag_all!";
EXPECT_FALSE( tagger.is_tagged( fh5 ) ) << "Face should be untagged after second untag_all!";
}
}