From e398acd624d70c95936e2ad8bd03f3d1a97be8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philipp=20M=C3=B6ller?= Date: Fri, 22 Jan 2016 17:42:02 +0100 Subject: [PATCH] Clean up the example --- BGL/examples/BGL_polyhedron_3/CMakeLists.txt | 8 +- .../BGL_polyhedron_3/copy_polyhedron.cpp | 92 +++++++++++++++++++ .../polyhedron_2_OpenMesh.cpp | 87 ------------------ 3 files changed, 96 insertions(+), 91 deletions(-) create mode 100644 BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp delete mode 100644 BGL/examples/BGL_polyhedron_3/polyhedron_2_OpenMesh.cpp diff --git a/BGL/examples/BGL_polyhedron_3/CMakeLists.txt b/BGL/examples/BGL_polyhedron_3/CMakeLists.txt index a84cf7493c0..1ffa079a833 100644 --- a/BGL/examples/BGL_polyhedron_3/CMakeLists.txt +++ b/BGL/examples/BGL_polyhedron_3/CMakeLists.txt @@ -34,7 +34,8 @@ endif() find_package( OpenMesh QUIET ) if ( OpenMesh_FOUND ) -include( UseOpenMesh ) + include( UseOpenMesh ) + add_definitions( -DCGAL_USE_OPENMESH ) else() message(STATUS "Examples that use OpenMesh will not be compiled.") endif() @@ -64,10 +65,9 @@ create_single_source_cgal_program( "range.cpp" ) create_single_source_cgal_program( "transform_iterator.cpp" ) - +create_single_source_cgal_program( "copy_polyhedron.cpp" ) if(OpenMesh_FOUND) - create_single_source_cgal_program( "polyhedron_2_OpenMesh.cpp" ) - target_link_libraries( polyhedron_2_OpenMesh ${OPENMESH_LIBRARIES} ) + target_link_libraries( copy_polyhedron ${OPENMESH_LIBRARIES} ) endif() diff --git a/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp b/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp new file mode 100644 index 00000000000..0318942a8f4 --- /dev/null +++ b/BGL/examples/BGL_polyhedron_3/copy_polyhedron.cpp @@ -0,0 +1,92 @@ +#include + +#include +#include +#include + +#include +#include + +#if defined(CGAL_USE_OPENMESH) +#include +#include +#include + +namespace OpenMesh { // auxiliary functions so OpenMesh Handles can be hashed +inline std::size_t hash_value(const VertexHandle& i) { return i.idx(); } +inline std::size_t hash_value(const HalfedgeHandle& i) { return i.idx(); } +inline std::size_t hash_value(const FaceHandle& i) { return i.idx(); } +} + +#endif + +#include + +#include + +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point; + +typedef CGAL::Polyhedron_3 Source; +typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; +typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; + +typedef CGAL::Surface_mesh Target1; + +int main(int argc, char* argv[]) +{ + Source S; + + std::ifstream in((argc>1)?argv[1]:"cube.off"); + in >> S; + + Target1 T1; + { + typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; + + boost::unordered_map v2v; + boost::unordered_map h2h; + + CGAL::copy_face_graph(S,T1,v2v,h2h); + std::ofstream out("sm.off"); + out << T1; + } + +#if defined(CGAL_USE_OPENMESH) + typedef OpenMesh::PolyMesh_ArrayKernelT Target2; + Target2 T2; + { + typedef OpenMesh::PolyMesh_ArrayKernelT Target2; + + typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; + + boost::unordered_map v2v; + boost::unordered_map h2h; + + CGAL::copy_face_graph(S,T2,v2v,h2h); + + OpenMesh::IO::write_mesh(T2, "om.off"); + } +#endif + S.clear(); + { + typedef boost::graph_traits::vertex_descriptor source_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor source_halfedge_descriptor; + + typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; + typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; + + boost::unordered_map v2v; + boost::unordered_map h2h; + + CGAL::copy_face_graph(T1,S,v2v,h2h); + std::ofstream out("reverse.off"); + out << T1; + } + return 0; +} diff --git a/BGL/examples/BGL_polyhedron_3/polyhedron_2_OpenMesh.cpp b/BGL/examples/BGL_polyhedron_3/polyhedron_2_OpenMesh.cpp deleted file mode 100644 index 55f64a8215d..00000000000 --- a/BGL/examples/BGL_polyhedron_3/polyhedron_2_OpenMesh.cpp +++ /dev/null @@ -1,87 +0,0 @@ - -#include - -#include -#include -#include - -#include - -#if 1 -#include -#include -#else -#include -#include -#endif - -#include - -#include - -#include -#include - - -typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; -typedef Kernel::Vector_3 Vector; -typedef Kernel::Point_3 Point; -typedef CGAL::Polyhedron_3 Source; - -#if 1 -typedef OpenMesh::PolyMesh_ArrayKernelT Target; -#else -typedef OpenMesh::TriMesh_ArrayKernelT Target; -#endif -typedef boost::graph_traits::vertex_descriptor sm_vertex_descriptor; -typedef boost::graph_traits::vertex_descriptor tm_vertex_descriptor; - -typedef boost::graph_traits::halfedge_descriptor sm_halfedge_descriptor; -typedef boost::graph_traits::halfedge_descriptor tm_halfedge_descriptor; - -namespace OpenMesh { - -inline std::size_t hash_value(const VertexHandle& i) - { - return i.idx(); - } - -inline std::size_t hash_value(const HalfedgeHandle& i) - { - return i.idx(); - } - -inline std::size_t hash_value(const FaceHandle& i) - { - return i.idx(); - } - -} - -int main(int argc, char* argv[]) -{ - Source S; - Target T; - std::ifstream in((argc>1)?argv[1]:"cube.off"); - in >> S; - - { - boost::unordered_map v2v; - boost::unordered_map h2h; - - convert_surface_mesh(S,T,v2v,h2h); - OpenMesh::IO::write_mesh(T, "om.off"); - } - S.clear(); - { - boost::unordered_map v2v; - boost::unordered_map h2h; - - convert_surface_mesh(T,S,v2v,h2h); - std::ofstream out("reverse.off"); - out << S << std::endl; - } - - - return 0; -}