From 7ac3dcd63ba209b3364e92d832e88d85be463c15 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 27 Nov 2018 10:04:32 +0100 Subject: [PATCH 1/3] Add write_wrl() for FaceGraph --- BGL/doc/BGL/PackageDescription.txt | 1 + BGL/include/CGAL/boost/graph/io.h | 88 ++++++++++++++++++++++++++++++ BGL/test/BGL/CMakeLists.txt | 2 + BGL/test/BGL/test_wrl.cpp | 18 ++++++ 4 files changed, 109 insertions(+) create mode 100644 BGL/test/BGL/test_wrl.cpp diff --git a/BGL/doc/BGL/PackageDescription.txt b/BGL/doc/BGL/PackageDescription.txt index 6ba2f1ba2d6..d069c70ee55 100644 --- a/BGL/doc/BGL/PackageDescription.txt +++ b/BGL/doc/BGL/PackageDescription.txt @@ -708,6 +708,7 @@ user might encounter. ## I/O Functions ## - \link PkgBGLIOFct CGAL::read_off() \endlink - \link PkgBGLIOFct CGAL::write_off() \endlink +- \link PkgBGLIOFct CGAL::write_wrl() \endlink */ diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 2ad04ff8fe8..f5775e63662 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -36,6 +36,94 @@ #include namespace CGAL { + /*! + \ingroup PkgBGLIOFct + writes the graph `g` in the wrl format (VRML 2.0). + + \cgalNamedParamsBegin + * \cgalParamBegin{vertex_point_map} the property map with the points associated to the vertices of `g`. + * If this parameter is omitted, an internal property map for + * `CGAL::vertex_point_t` should be available in `FaceGraph`\cgalParamEnd + * \cgalNamedParamsEnd + */ +template +bool write_wrl(std::ostream& os, + const FaceGraph& g, + const NamedParameters& np) +{ + typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; + typedef typename boost::graph_traits::face_descriptor face_descriptor; + typedef typename boost::graph_traits::vertices_size_type vertices_size_type; + typedef typename boost::graph_traits::faces_size_type faces_size_type; + + + typename Polygon_mesh_processing::GetVertexPointMap::const_type + vpm = choose_param(get_param(np, internal_np::vertex_point), + get_const_property_map(CGAL::vertex_point, g)); + + vertices_size_type nv = static_cast(std::distance(vertices(g).first, vertices(g).second)); + faces_size_type nf = static_cast(std::distance(faces(g).first, faces(g).second)); + + boost::container::flat_map reindex; + int n = 0; + + os << "#VRML V2.0 utf8\n" + "Group {\n" + "children [\n" + "Shape {\n" + "appearance DEF A1 Appearance {\n" + "material Material {\n" + "diffuseColor .6 .5 .9\n" + "}\n" + "}\n" + "appearance\n" + "Appearance {\n" + "material DEF Material Material {}\n" + "}\n" + "}\n" + "Group {\n" + "children [\n" + "Shape {\n" + "appearance Appearance { material USE Material }\n" + "geometry IndexedFaceSet {\n" + "convex FALSE\n" + "solid FALSE\n" + "coord Coordinate {\n" + "point [\n"; + + BOOST_FOREACH(vertex_descriptor v, vertices(g)){ + os << get(vpm,v) << ",\n"; + reindex[v]=n++; + } + os << "] #point\n" + "} #coord Coordinate\n" + "coordIndex [\n"; + BOOST_FOREACH(face_descriptor f, faces(g)){ + BOOST_FOREACH(vertex_descriptor v, vertices_around_face(halfedge(f,g),g)){ + os << reindex[v] << ","; + } + os << "-1,\n"; + } + + os << "] #coordIndex\n" + "} #geometry\n" + "} #Shape\n" + "] #children\n" + "} #group\n" + "]\n" + "}\n"; + + return os.good(); +} + +template +bool write_wrl(std::ostream& os, + const FaceGraph& g) +{ + return write_wrl(os, g, + parameters::all_default()); +} + /*! \ingroup PkgBGLIOFct writes the graph `g` in the OFF format. diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index 8b6ef06e78d..0949c353647 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -97,6 +97,8 @@ create_single_source_cgal_program( "test_graph_traits.cpp" ) create_single_source_cgal_program( "test_Properties.cpp" ) +create_single_source_cgal_program( "test_wrl.cpp" ) + if(OpenMesh_FOUND) target_link_libraries( test_clear PRIVATE ${OPENMESH_LIBRARIES}) target_link_libraries( test_Euler_operations PRIVATE ${OPENMESH_LIBRARIES}) diff --git a/BGL/test/BGL/test_wrl.cpp b/BGL/test/BGL/test_wrl.cpp new file mode 100644 index 00000000000..f8a29ee8533 --- /dev/null +++ b/BGL/test/BGL/test_wrl.cpp @@ -0,0 +1,18 @@ +#include +#include +#include +#include +#include + +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; +typedef CGAL::Surface_mesh Mesh; + +int main() +{ + Mesh sm; + + CGAL::make_tetrahedron(Point(0,0,0), Point(1,0,0), Point(1,1,0), Point(0,0,1), sm); + CGAL::write_wrl(std::cout, sm); + return 0; +} From 5f007da4615d34e7f177210477b7c6a644d6c908 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Wed, 28 Nov 2018 07:56:14 +0100 Subject: [PATCH 2/3] Remove unused variables --- BGL/include/CGAL/boost/graph/io.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index f5775e63662..71bb55def86 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -61,9 +61,6 @@ bool write_wrl(std::ostream& os, vpm = choose_param(get_param(np, internal_np::vertex_point), get_const_property_map(CGAL::vertex_point, g)); - vertices_size_type nv = static_cast(std::distance(vertices(g).first, vertices(g).second)); - faces_size_type nf = static_cast(std::distance(faces(g).first, faces(g).second)); - boost::container::flat_map reindex; int n = 0; From c570e86661610857447f8a2e6c37bbfafa95f85b Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Thu, 29 Nov 2018 08:12:26 +0100 Subject: [PATCH 3/3] Removed unused typedef; Added to CHANGES.md --- BGL/include/CGAL/boost/graph/io.h | 2 -- Installation/CHANGES.md | 4 ++++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 71bb55def86..60dcfca72ad 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -54,8 +54,6 @@ bool write_wrl(std::ostream& os, typedef typename boost::graph_traits::vertex_descriptor vertex_descriptor; typedef typename boost::graph_traits::face_descriptor face_descriptor; typedef typename boost::graph_traits::vertices_size_type vertices_size_type; - typedef typename boost::graph_traits::faces_size_type faces_size_type; - typename Polygon_mesh_processing::GetVertexPointMap::const_type vpm = choose_param(get_param(np, internal_np::vertex_point), diff --git a/Installation/CHANGES.md b/Installation/CHANGES.md index 672d71541a4..86dd48044b6 100644 --- a/Installation/CHANGES.md +++ b/Installation/CHANGES.md @@ -54,6 +54,10 @@ Release date: March 2019 `Arr_polyline_traits_2`, `Arr_polycurve_traits_2`, and `Arr_polycurve_basic_traits_2`. +### CGAL and the Boost Graph Library (BGL) + +- Add function `write_wrl()` for writing into VRML 2.0 format. + Release 4.13 ------------