From 6e7debb874885f178691b7ace514c5ee101e2b33 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 15 Apr 2015 16:36:23 +0200 Subject: [PATCH] test helpers --- .../CGAL/boost/graph/Euler_operations.h | 5 --- BGL/include/CGAL/boost/graph/helpers.h | 44 ++++++++++++++++++- BGL/test/BGL/CMakeLists.txt | 3 ++ BGL/test/BGL/data/cube-quads.off | 16 +++++++ BGL/test/BGL/data/tetrahedron.off | 20 ++++----- BGL/test/BGL/test_helpers.cpp | 38 ++++++++++++++++ 6 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 BGL/test/BGL/data/cube-quads.off create mode 100644 BGL/test/BGL/test_helpers.cpp diff --git a/BGL/include/CGAL/boost/graph/Euler_operations.h b/BGL/include/CGAL/boost/graph/Euler_operations.h index da76fe39123..0b8838e3c87 100644 --- a/BGL/include/CGAL/boost/graph/Euler_operations.h +++ b/BGL/include/CGAL/boost/graph/Euler_operations.h @@ -200,16 +200,13 @@ typename boost::graph_traits::halfedge_descriptor make_hexahedron(const P& p0, const P& p1, const P& p2, const P& p3, const P& p4, const P& p5, const P& p6, const P& p7, Graph& g) { - std::cerr << "A"<< std::endl; typedef typename boost::graph_traits Traits; typedef typename Traits::halfedge_descriptor halfedge_descriptor; typedef typename Traits::vertex_descriptor vertex_descriptor; typedef typename Traits::face_descriptor face_descriptor; halfedge_descriptor hb = make_quadrangle(p0, p1, p2, p3, g); - std::cerr << "B"<< std::endl; halfedge_descriptor ht = prev(make_quadrangle(p4, p7, p6, p5, g),g); - std::cerr << "C"<< std::endl; for(int i=0; i <4; i++){ halfedge_descriptor h = halfedge(add_edge(g),g); set_target(h,target(hb,g),g); @@ -222,12 +219,10 @@ make_hexahedron(const P& p0, const P& p1, const P& p2, const P& p3, hb = next(hb,g); ht = prev(ht,g); } - std::cerr << "D"<< std::endl; for(int i=0; i <4; i++){ fill_hole(opposite(hb,g),g); hb = next(hb,g); } - std::cerr << "E"<< std::endl; return hb; } /** diff --git a/BGL/include/CGAL/boost/graph/helpers.h b/BGL/include/CGAL/boost/graph/helpers.h index d4d87d7dcb8..bdcbd49db29 100644 --- a/BGL/include/CGAL/boost/graph/helpers.h +++ b/BGL/include/CGAL/boost/graph/helpers.h @@ -161,7 +161,7 @@ template if(! is_border(opposite(hd,g),g)) return false; hd = next(hd,g); } - return next(hd,g)== beg; + return hd == beg; } /*! @@ -207,7 +207,7 @@ bool is_quad(typename boost::graph_traits::halfedge_descriptor hd, co if(! is_border(opposite(hd,g),g)) return false; hd = next(hd,g); } - return next(hd,g)== beg; + return hd == beg; } @@ -245,6 +245,7 @@ template template bool is_tetrahedron( typename boost::graph_traits::halfedge_descriptor h1, const FaceGraph& g) { + if(is_border(h1,g)) return false; typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; halfedge_descriptor h2 = next(h1,g); halfedge_descriptor h3 = next(h2,g); @@ -258,6 +259,7 @@ bool is_tetrahedron( typename boost::graph_traits::halfedge_descripto if ( h6 == opposite(h2,g) ) return false; // exact three edges at vertices 1, 2, 3. if ( next(opposite(h4,g),g) != opposite(h3,g) ) return false; + std::cerr << "B1"<< std::endl; if ( next(opposite(h5,g),g) != opposite(h1,g) ) return false; if ( next(opposite(h6,g),g) != opposite(h2,g) ) return false; // three edges at v4. @@ -278,6 +280,44 @@ bool is_tetrahedron( typename boost::graph_traits::halfedge_descripto } + /*! + \ingroup PkgBGLHelperFct + returns `true` iff the connected component denoted by `h` is a hexahedron. + */ +template +bool is_hexahedron( typename boost::graph_traits::halfedge_descriptor h1, const FaceGraph& g) +{ + if(is_border(h1,g)) return false; + typedef typename boost::graph_traits::halfedge_descriptor halfedge_descriptor; + halfedge_descriptor h2 = next(h1,g); + halfedge_descriptor h3 = next(h2,g); + halfedge_descriptor h4 = next(h3,g); + halfedge_descriptor h1o = opposite(h1,g); + halfedge_descriptor h2o = opposite(h2,g); + halfedge_descriptor h3o = opposite(h3,g); + halfedge_descriptor h4o = opposite(h4,g); + if(opposite(next(h2o,g),g) != prev(h1o,g)) return false; + if(opposite(next(h3o,g),g) != prev(h2o,g)) return false; + if(opposite(next(h4o,g),g) != prev(h3o,g)) return false; + if(opposite(next(h1o,g),g) != prev(h4o,g)) return false; + if(! is_quad(face(h1,g),g)) return false; + if(! is_quad(face(h1o,g),g)) return false; + if(! is_quad(face(h2o,g),g)) return false; + if(! is_quad(face(h3o,g),g)) return false; + if(! is_quad(face(h4o,g),g)) return false; + h1o =next(next(h1o,g),g); + h2o =next(next(h2o,g),g); + h3o =next(next(h3o,g),g); + h4o =next(next(h4o,g),g); + if(next(opposite(h2o,g),g) != opposite(h1o,g)) return false; + if(next(opposite(h3o,g),g) != opposite(h2o,g)) return false; + if(next(opposite(h4o,g),g) != opposite(h3o,g)) return false; + if(next(opposite(h1o,g),g) != opposite(h4o,g)) return false; + + if(! is_quad(face(opposite(h4o,g),g),g)) return false; + return true; +} + } // namespace CGAL diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index 9d51316bebc..7ac8cf18194 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -73,6 +73,9 @@ create_single_source_cgal_program( "graph_concept_Polyhedron_3.cpp" ) create_single_source_cgal_program( "graph_concept_Triangulation_2.cpp" ) create_single_source_cgal_program( "test_graph_geometry.cpp" ) + +create_single_source_cgal_program( "test_helpers.cpp" ) + if(OpenMesh_FOUND) target_link_libraries( test_graph_geometry ${OPENMESH_LIBRARIES}) endif() diff --git a/BGL/test/BGL/data/cube-quads.off b/BGL/test/BGL/data/cube-quads.off new file mode 100644 index 00000000000..e9e10fcb0a5 --- /dev/null +++ b/BGL/test/BGL/data/cube-quads.off @@ -0,0 +1,16 @@ +OFF +8 6 0 +0 0 0 +1 0 0 +1 1 0 +0 1 0 +0 0 1 +1 0 1 +1 1 1 +0 1 1 +4 0 1 5 4 +4 4 5 6 7 +4 5 1 2 6 +4 2 1 0 3 +4 4 7 3 0 +4 7 6 2 3 diff --git a/BGL/test/BGL/data/tetrahedron.off b/BGL/test/BGL/data/tetrahedron.off index 0206de92c32..e87dd57c03e 100644 --- a/BGL/test/BGL/data/tetrahedron.off +++ b/BGL/test/BGL/data/tetrahedron.off @@ -1,15 +1,11 @@ OFF -5 6 0 +4 4 0 -0 0 100 -100 0 0 -0 100 0 0 0 0 -25 25 0 -3 3 4 1 -3 0 3 1 -3 0 2 3 -3 0 1 2 -3 2 4 3 -3 1 4 2 - +1 0 0 +0 1 0 +0 0 1 +3 0 1 2 +3 3 1 0 +3 3 2 1 +3 3 0 2 diff --git a/BGL/test/BGL/test_helpers.cpp b/BGL/test/BGL/test_helpers.cpp new file mode 100644 index 00000000000..91d1f3f8b6d --- /dev/null +++ b/BGL/test/BGL/test_helpers.cpp @@ -0,0 +1,38 @@ +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian K; + +typedef CGAL::Surface_mesh Mesh; +typedef boost::graph_traits::vertex_descriptor vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; + +void +test(char *fname, bool triangle, bool quad, bool tetrahedron, bool hexahedron) +{ + std::cerr << "test(" << fname << ")"<< std::endl; + Mesh m; + std::ifstream in(fname); + in >> m; + halfedge_descriptor hd = *halfedges(m).first; + assert(CGAL::is_triangle(hd, m) == triangle); + assert(CGAL::is_quad(hd, m) == quad); + assert(CGAL::is_tetrahedron(hd, m) == tetrahedron); + assert(CGAL::is_hexahedron(hd, m) == hexahedron); + } + +int main() +{ + // triangle quad tetra hexa + test("data/triangle.off", true, false, false, false ); + test("data/quad.off", false, true, false, false ); + test("data/tetrahedron.off", false, false, true, false ); + test("data/cube.off", false, false, false, false ); + test("data/cube-quads.off", false, false, false, true ); + + std::cerr << "done" << std::endl; + return 0; +}