diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt index ce0b8b564fe..1eb42323524 100644 --- a/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/CMakeLists.txt @@ -76,6 +76,7 @@ if (EIGEN3_FOUND) create_single_source_cgal_program("test_stitching.cpp") create_single_source_cgal_program("remove_degeneracies_test.cpp") create_single_source_cgal_program("test_pmp_bgl_named_params.cpp") + create_single_source_cgal_program("measures_test.cpp") if(NOT (${EIGEN3_VERSION} VERSION_LESS 3.2.0)) create_single_source_cgal_program("fairing_test.cpp") diff --git a/Polygon_mesh_processing/test/Polygon_mesh_processing/measures_test.cpp b/Polygon_mesh_processing/test/Polygon_mesh_processing/measures_test.cpp new file mode 100644 index 00000000000..3a6843989d9 --- /dev/null +++ b/Polygon_mesh_processing/test/Polygon_mesh_processing/measures_test.cpp @@ -0,0 +1,106 @@ +#include + +#include +#include +#include + +#include +#include + +#include + +#include +#include +#include +#include + +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef K::Point_3 Point; + +typedef CGAL::Polyhedron_3 Polyhedron; +typedef CGAL::Surface_mesh Surface_mesh; + +namespace PMP = CGAL::Polygon_mesh_processing; + +template +void test(const Mesh& pmesh) +{ + typedef boost::graph_traits::halfedge_descriptor halfedge_descriptor; + typedef boost::graph_traits::face_descriptor face_descriptor; + + halfedge_descriptor border_he; + BOOST_FOREACH(halfedge_descriptor h, halfedges(pmesh)) + { + if (is_border(h, pmesh)) + { + border_he = h; + break; + } + } + double border_l = PMP::border_length(border_he, pmesh); + std::cout << "length of hole border = " << border_l << std::endl; + + std::list patch; + BOOST_FOREACH(halfedge_descriptor h, halfedges(pmesh)) + { + if (is_border(h, pmesh) || is_border(opposite(h, pmesh), pmesh)) + continue; + else + { + patch.push_back(face(h, pmesh)); + patch.push_back(face(opposite(h, pmesh), pmesh)); + patch.push_back(face(opposite(next(h, pmesh), pmesh), pmesh)); + patch.push_back(face(opposite(prev(h, pmesh), pmesh), pmesh)); + break; + } + } + double patch_area = PMP::area(patch, pmesh); + std::cout << "patch area = " << patch_area << std::endl; + +} + +void test_polyhedron(const char* filename) +{ + //run test for a Polyhedron + Polyhedron poly; // file should contain oriented polyhedron + std::ifstream input(filename); + + if (!input || !(input >> poly)) + { + std::cerr << "Error: cannot read Polyhedron : " << filename << "\n"; + assert(!poly.empty()); + assert(false); + return; + } + + test(poly); +} + +void test_surface_mesh(const char* filename) +{ + Surface_mesh sm; + std::ifstream input(filename); + + if (!input || !(input >> sm)) + { + std::cerr << "Error: cannot read Surface mesh : " << filename << "\n"; + assert(sm.number_of_vertices() > 0); + assert(false); + return; + } + + test(sm); +} + +int main(int argc, char* argv[]) +{ + const char* filename = (argc > 1) ? argv[1] : "data/mech-holes-shark.off"; + + test_polyhedron(filename); + test_surface_mesh(filename); + + std::cerr << "All done." << std::endl; + return 0; +}