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..60dcfca72ad 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -36,6 +36,89 @@ #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; + + 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)); + + 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; +} 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 ------------