mirror of https://github.com/CGAL/cgal
Clean up the example
This commit is contained in:
parent
0fa954bc8a
commit
e398acd624
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,92 @@
|
|||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
|
||||
#include <CGAL/Surface_mesh.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Surface_mesh.h>
|
||||
|
||||
#if defined(CGAL_USE_OPENMESH)
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
|
||||
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
|
||||
|
||||
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 <CGAL/boost/graph/copy_face_graph.h>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef Kernel::Point_3 Point;
|
||||
|
||||
typedef CGAL::Polyhedron_3<Kernel> Source;
|
||||
typedef boost::graph_traits<Source>::vertex_descriptor sm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Source>::halfedge_descriptor sm_halfedge_descriptor;
|
||||
|
||||
typedef CGAL::Surface_mesh<Point> 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<Target1>::vertex_descriptor tm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target1>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
boost::unordered_map<sm_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<sm_halfedge_descriptor, tm_halfedge_descriptor> 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</* MyTraits*/> Target2;
|
||||
Target2 T2;
|
||||
{
|
||||
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Target2;
|
||||
|
||||
typedef boost::graph_traits<Target2>::vertex_descriptor tm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target2>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
boost::unordered_map<sm_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<sm_halfedge_descriptor, tm_halfedge_descriptor> h2h;
|
||||
|
||||
CGAL::copy_face_graph(S,T2,v2v,h2h);
|
||||
|
||||
OpenMesh::IO::write_mesh(T2, "om.off");
|
||||
}
|
||||
#endif
|
||||
S.clear();
|
||||
{
|
||||
typedef boost::graph_traits<Target1>::vertex_descriptor source_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target1>::halfedge_descriptor source_halfedge_descriptor;
|
||||
|
||||
typedef boost::graph_traits<Source>::vertex_descriptor tm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Source>::halfedge_descriptor tm_halfedge_descriptor;
|
||||
|
||||
boost::unordered_map<source_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<source_halfedge_descriptor, tm_halfedge_descriptor> h2h;
|
||||
|
||||
CGAL::copy_face_graph(T1,S,v2v,h2h);
|
||||
std::ofstream out("reverse.off");
|
||||
out << T1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,87 +0,0 @@
|
|||
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <CGAL/Polyhedron_3.h>
|
||||
#include <CGAL/IO/Polyhedron_iostream.h>
|
||||
#include <CGAL/boost/graph/graph_traits_Polyhedron_3.h>
|
||||
|
||||
#include <OpenMesh/Core/IO/MeshIO.hh>
|
||||
|
||||
#if 1
|
||||
#include <OpenMesh/Core/Mesh/PolyMesh_ArrayKernelT.hh>
|
||||
#include <CGAL/boost/graph/graph_traits_PolyMesh_ArrayKernelT.h>
|
||||
#else
|
||||
#include <OpenMesh/Core/Mesh/TriMesh_ArrayKernelT.hh>
|
||||
#include <CGAL/boost/graph/graph_traits_TriMesh_ArrayKernelT.h>
|
||||
#endif
|
||||
|
||||
#include <CGAL/boost/graph/convert_surface_mesh.h>
|
||||
|
||||
#include <boost/unordered_map.hpp>
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
|
||||
typedef Kernel::Vector_3 Vector;
|
||||
typedef Kernel::Point_3 Point;
|
||||
typedef CGAL::Polyhedron_3<Kernel> Source;
|
||||
|
||||
#if 1
|
||||
typedef OpenMesh::PolyMesh_ArrayKernelT</* MyTraits*/> Target;
|
||||
#else
|
||||
typedef OpenMesh::TriMesh_ArrayKernelT</* MyTraits*/> Target;
|
||||
#endif
|
||||
typedef boost::graph_traits<Source>::vertex_descriptor sm_vertex_descriptor;
|
||||
typedef boost::graph_traits<Target>::vertex_descriptor tm_vertex_descriptor;
|
||||
|
||||
typedef boost::graph_traits<Source>::halfedge_descriptor sm_halfedge_descriptor;
|
||||
typedef boost::graph_traits<Target>::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<sm_vertex_descriptor, tm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<sm_halfedge_descriptor, tm_halfedge_descriptor> h2h;
|
||||
|
||||
convert_surface_mesh(S,T,v2v,h2h);
|
||||
OpenMesh::IO::write_mesh(T, "om.off");
|
||||
}
|
||||
S.clear();
|
||||
{
|
||||
boost::unordered_map<tm_vertex_descriptor, sm_vertex_descriptor> v2v;
|
||||
boost::unordered_map<tm_halfedge_descriptor, sm_halfedge_descriptor> h2h;
|
||||
|
||||
convert_surface_mesh(T,S,v2v,h2h);
|
||||
std::ofstream out("reverse.off");
|
||||
out << S << std::endl;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
Loading…
Reference in New Issue