diff --git a/Alpha_shapes_3/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h b/Alpha_shapes_3/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h index 2308b93b92d..59e031b9668 100644 --- a/Alpha_shapes_3/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h +++ b/Alpha_shapes_3/include/CGAL/IO/Alpha_shape_3_VRML_2_ostream.h @@ -5,7 +5,7 @@ // Max-Planck-Institute Saarbruecken (Germany), // and Tel-Aviv University (Israel). All rights reserved. // -// This file is part of CGAL (www.cgal.org); +// This file is part of CGAL (www.cgal.org). // // $URL$ // $Id$ diff --git a/BGL/include/CGAL/boost/graph/IO/OFF.h b/BGL/include/CGAL/boost/graph/IO/OFF.h index c5b4273b33c..2fd011e91e7 100644 --- a/BGL/include/CGAL/boost/graph/IO/OFF.h +++ b/BGL/include/CGAL/boost/graph/IO/OFF.h @@ -222,14 +222,15 @@ bool write_OFF_BGL(std::ostream& os, \cgalParamBegin{face_color_map} the property map with the colors associated to the faces of `g`.\cgalParamEnd \cgalNamedParamsEnd - \sa Overloads of this function for specific models of the concept `FaceGraph`. + \returns `true` if writing was successful. + \sa Overloads of this function for specific models of the concept `FaceGraph`. \see \ref IOStreamOFF */ template bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np, typename boost::disable_if< - typename boost::has_range_const_iterator::type + typename boost::has_range_const_iterator::type >::type* =0) { return IO::internal::write_OFF_BGL(os, g, np); @@ -263,9 +264,9 @@ bool write_OFF(std::ostream& os, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np \see \ref IOStreamOFF */ template -bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np - ,typename boost::disable_if< - typename boost::has_range_const_iterator::type +bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + typename boost::disable_if< + typename boost::has_range_const_iterator::type >::type* =0) { std::ofstream out(fname); @@ -273,9 +274,9 @@ bool write_OFF(const char* fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& n } template -bool write_OFF(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np - ,typename boost::disable_if< - typename boost::has_range_const_iterator::type +bool write_OFF(const std::string& fname, const FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + typename boost::disable_if< + typename boost::has_range_const_iterator::type >::type* =0) { return write_OFF(fname.c_str(), g, np); diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index 02081c904d8..e78edddd108 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -19,10 +19,10 @@ #include #include +#include namespace CGAL { - //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// /// Read @@ -44,7 +44,7 @@ class PLY_builder public: PLY_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } - //! TODO: use vertex_point_map + template bool read(std::istream& input, Point_container& points, diff --git a/BGL/include/CGAL/boost/graph/IO/WRL.h b/BGL/include/CGAL/boost/graph/IO/WRL.h index a431d57f539..26808337d68 100644 --- a/BGL/include/CGAL/boost/graph/IO/WRL.h +++ b/BGL/include/CGAL/boost/graph/IO/WRL.h @@ -21,6 +21,10 @@ namespace CGAL { +//////////////////////////////////////////////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////////////////////////////////////////////////// +/// Write + /*! \ingroup PkgBGLIOFct diff --git a/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h index 7397dec4019..fd4f46893e2 100644 --- a/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h +++ b/BGL/include/CGAL/boost/graph/IO/polygon_mesh_io.h @@ -95,55 +95,43 @@ bool read_polygon_mesh(const std::string& fname, FaceGraph& g, const NamedParameters& np) { - - if (fname.find(".obj") != std::string::npos) { + if(fname.find(".obj") != std::string::npos) return read_OBJ(fname, g, np); - } - if (fname.find(".off") != std::string::npos) { + if(fname.find(".off") != std::string::npos) return read_OFF(fname, g, np); - } - if (fname.find(".ply") != std::string::npos) { + if(fname.find(".ply") != std::string::npos) return read_PLY(fname, g, np); - } - if (fname.find(".stl") != std::string::npos) { + if(fname.find(".stl") != std::string::npos) return read_STL(fname, g, np); - } #ifdef CGAL_USE_VTK - if (fname.find(".vtp") != std::string::npos) { + if(fname.find(".vtp") != std::string::npos) return read_VTP(fname, g, np); - } #endif - if (fname.find(".ts") != std::string::npos) { + if(fname.find(".ts") != std::string::npos) return read_GOCAD(fname, g, np); - } + return false; } template -bool read_polygon_mesh(const std::string& fname, - FaceGraph& g) +bool read_polygon_mesh(const std::string& fname, FaceGraph& g) { return read_polygon_mesh(fname, g, parameters::all_default()); } - - template -bool read_polygon_mesh(const char* fname, - FaceGraph& g, - const NamedParameters& np) +bool read_polygon_mesh(const char* fname, FaceGraph& g, const NamedParameters& np) { return read_polygon_mesh(std::string(fname), g, np); } template -bool read_polygon_mesh(const char* fname, - FaceGraph& g) +bool read_polygon_mesh(const char* fname, FaceGraph& g) { return read_polygon_mesh(fname, g, parameters::all_default()); } @@ -154,83 +142,76 @@ bool read_polygon_mesh(const char* fname, /*! * \ingroup PkgBGLIOFct + * * \brief writes a polygon mesh in a file. - * \tparam FaceGraph a model of `FaceGraph` + * + * \tparam FaceGraph a model of `FaceListGraph` and `HalfedgeListGraph` * \tparam NamedParameters a sequence of \ref pmp_namedparameters "Named Parameters" * * \param fname the name of the file. Its extension must be one of the following : * `.off` (\ref IOStreamOFF "OFF file format") , `.obj` (\ref IOStreamOBJ "OBJ file format"), * `.stl` (\ref IOStreamSTL "STL file format"), `.ply` (\ref IOStreamPLY "PLY file format"), * `.vtp`(\ref IOStreamVTK "VTP file format") or `.ts`(\ref IOStreamGocad "GOCAD file format"). - * \param g the mesh + * \param g the mesh to be output * \param np optional \ref pmp_namedparameters "Named Parameters" described below * * \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 + * \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 - * Other named parameters may be used according to the file extension. - * See `PkgBGLIOFct` for an exhaustive list. - * \return `true` if the writing worked, `false` otherwise. * - * \see \ref IOStreamOFF + * Other named parameters may be used according to the file extension, see \ref PkgBGLIOFct for an exhaustive list. + * + * \return `true` if writing was successful, `false` otherwise. */ template bool write_polygon_mesh(const std::string& fname, FaceGraph& g, const NamedParameters& np) { - if (fname.find(".ts") != std::string::npos) { - return write_GOCAD(fname, g, np); - } - - if (fname.find(".obj") != std::string::npos) { + if(fname.find(".obj") != std::string::npos) // @fixme what about my_super_file.obj.off return write_OBJ(fname, g, np); - } - if (fname.find(".off") != std::string::npos) { + if(fname.find(".off") != std::string::npos) // @fixme case sensitivity return write_OFF(fname, g, np); - } - if (fname.find(".ply") != std::string::npos) { + if(fname.find(".ply") != std::string::npos) return write_PLY(fname, g, np); - } - if (fname.find(".stl") != std::string::npos) { + if(fname.find(".stl") != std::string::npos) return write_STL(fname, g, np); - } + + if(fname.find(".ts") != std::string::npos) + return write_GOCAD(fname, g, np); + #ifdef CGAL_USE_VTK - if (fname.find(".vtp") != std::string::npos) { + if(fname.find(".vtp") != std::string::npos) return write_VTP(fname, g, np); - } #endif return false; } template -bool write_polygon_mesh(const std::string& fname, - FaceGraph& g) +bool write_polygon_mesh(const std::string& fname, FaceGraph& g) { return write_polygon_mesh(fname, g, parameters::all_default()); } template -bool write_polygon_mesh(const char* fname, - FaceGraph& g, - const NamedParameters& np) +bool write_polygon_mesh(const char* fname, FaceGraph& g, const NamedParameters& np) { return write_polygon_mesh(std::string(fname), g, np); } template -bool write_polygon_mesh(const char* fname, - FaceGraph& g) +bool write_polygon_mesh(const char* fname, FaceGraph& g) { return write_polygon_mesh(fname, g, parameters::all_default()); } -}//end CGAL +} // namespace CGAL #endif // CGAL_BOOST_GRAPH_POLYGON_MESH_IO_H diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index 4d4c32f0da3..ecb13c8e6a7 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -25,20 +25,19 @@ #include #include -typedef CGAL::Simple_cartesian Kernel; -typedef Kernel::Point_3 Point; +typedef CGAL::Simple_cartesian Kernel; +typedef Kernel::Point_3 Point; -typedef CGAL::Polyhedron_3 Polyhedron; +typedef CGAL::Polyhedron_3 Polyhedron; -typedef CGAL::Surface_mesh SM; +typedef CGAL::Surface_mesh SM; -typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; -typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper - <2, 3, MyTraits>::type LCC; +typedef CGAL::Linear_cell_complex_traits<3, Kernel> MyTraits; +typedef CGAL::Linear_cell_complex_for_bgl_combinatorial_map_helper<2, 3, MyTraits>::type LCC; #if defined(CGAL_USE_OPENMESH) -typedef OpenMesh::PolyMesh_ArrayKernelT OMesh; +typedef OpenMesh::PolyMesh_ArrayKernelT OMesh; #endif @@ -70,7 +69,6 @@ void fill_soup(PointRange& points, PolygonRange& polygons) polygons[3] = poly; } - void test_polygon_soup_io() { std::vector points; @@ -79,9 +77,7 @@ void test_polygon_soup_io() std::string filenames[5] = {"soup.obj", "soup.off", "soup.stl", "soup.ts", "soup.ply"}; for(const std::string& name : filenames) - { CGAL_assertion(CGAL::write_polygon_soup(name, points, polygons)); - } for(const std::string& name : filenames) { @@ -134,36 +130,37 @@ void test_bgl_OFF_with_np() { Mesh fg; std::ifstream in("data/full.off"); + typedef typename boost::property_map >::type VertexNormalMap; - VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t(), fg); + VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t(), fg); typedef typename boost::property_map >::type VertexColorMap; - VertexColorMap vcm = get(CGAL::dynamic_vertex_property_t(), fg); + VertexColorMap vcm = get(CGAL::dynamic_vertex_property_t(), fg); typedef typename boost::property_map >::type VertexTextureMap; - VertexTextureMap vtm = get(CGAL::dynamic_vertex_property_t(), fg); + VertexTextureMap vtm = get(CGAL::dynamic_vertex_property_t(), fg); typedef typename boost::property_map >::type FaceColorMap; - FaceColorMap fcm = get(CGAL::dynamic_face_property_t(), fg); - + FaceColorMap fcm = get(CGAL::dynamic_face_property_t(), fg); bool ok = CGAL::read_OFF(in, fg, CGAL::parameters::vertex_normal_map(vnm) - .vertex_color_map(vcm) - .vertex_texture_map(vtm) - .face_color_map(fcm)); + .vertex_color_map(vcm) + .vertex_texture_map(vtm) + .face_color_map(fcm)); CGAL_assertion(ok); + fg.clear(); vnm = get(CGAL::dynamic_vertex_property_t(), fg); ok = CGAL::read_polygon_mesh("data/full.off", fg, CGAL::parameters::vertex_normal_map(vnm) - .vertex_color_map(vcm) - .vertex_texture_map(vtm) - .face_color_map(fcm)); + .vertex_color_map(vcm) + .vertex_texture_map(vtm) + .face_color_map(fcm)); CGAL_assertion(ok); ok = CGAL::write_OFF(std::cout, fg, CGAL::parameters::vertex_normal_map(vnm) - .vertex_color_map(vcm) - .vertex_texture_map(vtm) - .face_color_map(fcm)); + .vertex_color_map(vcm) + .vertex_texture_map(vtm) + .face_color_map(fcm)); CGAL_assertion(ok); } @@ -172,6 +169,7 @@ void test_soup_off(const char* filename) std::vector points; std::vector > polygons; std::ifstream in(filename); + CGAL::read_OFF(in,points, polygons); CGAL::write_OFF(std::cout, points, polygons); } @@ -182,19 +180,22 @@ bool test_bgl_OBJ() Mesh fg; CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), Point(2, 0, 1), Point(3, 0, 0), fg); + std::ostringstream out; CGAL::write_OBJ(out, fg); - std::istringstream in( out.str()); + + std::istringstream in(out.str()); + fg.clear(); CGAL::read_OBJ(in, fg); CGAL_assertion(num_vertices(fg) == 4); CGAL_assertion(num_faces(fg) == 4); + fg.clear(); CGAL::read_polygon_mesh("data/sphere.obj", fg); CGAL_assertion(num_vertices(fg) == 162); CGAL_assertion(num_faces(fg) == 320); - return true; } @@ -204,25 +205,26 @@ bool test_bgl_OBJ_with_np() Mesh fg, fg2; CGAL::make_tetrahedron(Point(0, 0, 0), Point(1, 1, 0), Point(2, 0, 1), Point(3, 0, 0), fg); - typedef typename boost::property_map >::type VertexNormalMap; - VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t(), fg); - VertexNormalMap vnm2 = get(CGAL::dynamic_vertex_property_t(), fg2); + typedef typename boost::property_map >::type VertexNormalMap; + VertexNormalMap vnm = get(CGAL::dynamic_vertex_property_t(), fg); + VertexNormalMap vnm2 = get(CGAL::dynamic_vertex_property_t(), fg2); for(const auto& v : vertices(fg)) put(vnm, v, Kernel::Vector_3(0.0,1.0,0.0)); + std::ostringstream out; CGAL::write_OBJ(out, fg, CGAL::parameters::vertex_normal_map(vnm)); - std::istringstream in( out.str()); + std::istringstream in(out.str()); CGAL::read_OBJ(in, fg2, CGAL::parameters::vertex_normal_map(vnm2)); - CGAL_assertion(num_vertices(fg2) == 4); CGAL_assertion(num_faces(fg2) == 4); + typename boost::graph_traits::vertex_iterator vit, vit2; - for( vit = vertices(fg).begin(), vit2 = vertices(fg2).begin(); - vit != vertices(fg).end(), vit2 != vertices(fg2).end(); - ++vit, ++vit2) + for(vit = vertices(fg).begin(), vit2 = vertices(fg2).begin(); + vit != vertices(fg).end(), vit2 != vertices(fg2).end(); + ++vit, ++vit2) { CGAL_assertion(get(vnm, *vit) == get(vnm2, *vit2)); } @@ -234,18 +236,20 @@ void test_bgl_soup_obj() { std::vector points; std::vector > polygons; - std::ostringstream out; fill_soup(points, polygons); + std::ostringstream out; CGAL::write_OBJ(out, points, polygons); + points.clear(); polygons.clear(); - std::istringstream in( out.str()); + + std::istringstream in(out.str()); CGAL::read_OBJ(in,points, polygons); CGAL_assertion(points.size() == 4); CGAL_assertion(polygons.size() == 4); - } + #ifdef CGAL_USE_VTK template bool test_bgl_vtp(bool binary = false) @@ -258,20 +262,21 @@ bool test_bgl_vtp(bool binary = false) CGAL::write_VTP(os, fg, CGAL::parameters::use_binary_mode(binary)); if(!os) { - std::cerr<<"vtp writing failed."<(bool binary) Point(2, 0, 1), Point(3, 0, 0), fg); typedef boost::property_map >::type VertexIdMap; - VertexIdMap vid = get(CGAL::dynamic_vertex_property_t(), fg); - std::size_t id = 0; - for(auto v : vertices(fg)) - put(vid,v, id++); + VertexIdMap vid = get(CGAL::dynamic_vertex_property_t(), fg); + std::size_t id = 0; + for(auto v : vertices(fg)) + put(vid,v, id++); + std::ofstream os("tetrahedron.vtp"); CGAL::write_VTP(os, fg, CGAL::parameters::vertex_index_map(vid).use_binary_mode(binary)); if(!os) { - std::cerr<<"vtp writing failed."< soup_points; std::vector > soup_polygons; CGAL::read_VTP("tetrahedron_soup.vtp", soup_points, soup_polygons); - if(4 != soup_points.size() - || 4 != soup_polygons.size()) + if(4 != soup_points.size() || 4 != soup_polygons.size()) { - std::cerr<<"Coherence problem. Wrong number of vertices or faces."< cnn; CGAL::read_GOCAD(in, cnn, fg2); - if(cnn.first != "tetrahedron"){ - std::cerr<<"reading error: tetrahedron != "< cnn; CGAL::read_GOCAD(in, cnn, fg2, CGAL::parameters::vertex_point_map(vpm2)); - if(cnn.first != "tetrahedron"){ - std::cerr<<"reading error: tetrahedron != "< >::type VertexColorMap; typedef typename boost::property_map >::type FaceColorMap; FaceColorMap fcm = get(CGAL::dynamic_face_property_t(), fg); @@ -582,15 +602,14 @@ bool test_bgl_PLY_with_np(bool binary) if(binary) CGAL::set_mode(out, CGAL::IO::BINARY); - CGAL::write_PLY(out, fg, "hello", CGAL::parameters::vertex_color_map(vcm) - .face_color_map(fcm)); + CGAL::write_PLY(out, fg, "hello", CGAL::parameters::vertex_color_map(vcm).face_color_map(fcm)); if(out.fail()) { - std::cerr<<"Tetrahedron writing failed."<(), fg); FaceColorMap fcm2 = get(CGAL::dynamic_face_property_t(), fg); if(!CGAL::read_PLY(in, fg, CGAL::parameters::vertex_color_map(vcm2).face_color_map(fcm2))){ - std::cerr<<"Tetrahedron reading failed."<(); test_polygon_mesh_io(); test_polygon_mesh_io(); - const char* filename=(argc>1) ? argv[1] : "data/prim.off"; + // OFF + const char* filename = (argc>1) ? argv[1] : "data/prim.off"; test_bgl_OFF(filename); test_bgl_OFF(filename); test_bgl_OFF(filename); #ifdef CGAL_USE_OPENMESH test_bgl_OFF(filename); #endif - //polyhedron's overload doesn't care for any np that is not vpm + + // polyhedron's overload doesn't care for any np that is not vpm test_bgl_OFF_with_np(); test_bgl_OFF_with_np(); test_bgl_OFF_with_np(); #ifdef CGAL_USE_OPENMESH test_bgl_OFF_with_np(); #endif - test_soup_off(filename); + test_soup_off(filename); // OBJ test_bgl_OBJ(); @@ -659,70 +680,68 @@ int main(int argc, char** argv) test_bgl_OBJ_with_np(); #endif - - //PLY + // PLY if(!test_bgl_PLY()) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY(true)) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY()) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY(true)) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY_with_np(false)) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY_with_np(true)) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY_with_np(false)) - return 1; + return EXIT_FAILURE; if(!test_bgl_PLY_with_np(true)) - return 1; - + return EXIT_FAILURE; // GOCAD if(!test_bgl_gocad()) - return 1; + return EXIT_FAILURE; if(!test_bgl_gocad()) - return 1; + return EXIT_FAILURE; if(!test_bgl_gocad()) - return 1; + return EXIT_FAILURE; if(!test_bgl_gocad_with_np()) - return 1; + return EXIT_FAILURE; if(!test_bgl_gocad_with_np()) - return 1; + return EXIT_FAILURE; if(!test_bgl_gocad_with_np()) - return 1; + return EXIT_FAILURE; if(!test_soup_gocad()) - return 1; + return EXIT_FAILURE; // STL if(!test_bgl_stl()) - return 1; + return EXIT_FAILURE; if(!test_bgl_stl()) - return 1; + return EXIT_FAILURE; if(!test_bgl_stl()) - return 1; + return EXIT_FAILURE; // VTP #ifdef CGAL_USE_VTK if(!test_bgl_vtp(false)) - return 1; + return EXIT_FAILURE; if(!test_bgl_vtp(false)) - return 1; + return EXIT_FAILURE; if(!test_bgl_vtp(false)) - return 1; + return EXIT_FAILURE; if(!test_soup_vtp(false)) - return 1; + return EXIT_FAILURE; if(!test_bgl_vtp(true)) - return 1; + return EXIT_FAILURE; if(!test_bgl_vtp(true)) - return 1; + return EXIT_FAILURE; if(!test_bgl_vtp(true)) - return 1; + return EXIT_FAILURE; if(!test_soup_vtp(true)) - return 1; + return EXIT_FAILURE; #endif return EXIT_SUCCESS;