// Copyright (c) 2015 GeometryFactory (France). All rights reserved. // // This file is part of CGAL (www.cgal.org) // // $URL$ // $Id$ // SPDX-License-Identifier: LGPL-3.0-or-later OR LicenseRef-Commercial // // Author(s) : Andreas Fabri // Mael Rouxel-Labbé #ifndef CGAL_BGL_IO_WRL_H #define CGAL_BGL_IO_WRL_H #include #include #include #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 \see \ref IOStreamWRL */ 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; using parameters::get_parameter; using parameters::choose_parameter; typename CGAL::GetVertexPointMap::const_type vpm = choose_parameter(get_parameter(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"; for(vertex_descriptor v : vertices(g)) { os << get(vpm,v) << ",\n"; reindex[v] = n++; } os << "] #point\n" "} #coord Coordinate\n" "coordIndex [\n"; for(face_descriptor f : faces(g)) { for(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(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np) { return write_WRL(fname.c_str(), g, np); } template bool write_WRL(std::ostream& os, const FaceGraph& g) { return write_WRL(os, g, parameters::all_default()); } template bool write_WRL(const char* fname, const FaceGraph& g) { return write_WRL(fname, g, parameters::all_default()); } template bool write_WRL(const std::string& fname, const FaceGraph& g) { return write_WRL(fname, g, parameters::all_default()); } } // namespace CGAL #endif // CGAL_BGL_IO_WRL_H