diff --git a/BGL/include/CGAL/boost/graph/IO/GOCAD.h b/BGL/include/CGAL/boost/graph/IO/GOCAD.h index 3cc622bdab6..d8483eec223 100644 --- a/BGL/include/CGAL/boost/graph/IO/GOCAD.h +++ b/BGL/include/CGAL/boost/graph/IO/GOCAD.h @@ -45,17 +45,18 @@ class GOCAD_builder typedef typename Base::Face_container Face_container; public: - GOCAD_builder(std::istream& is_) : Base(is_) { } + GOCAD_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } // @check ascii template bool read(std::istream& input, Point_container& points, Face_container& faces, - const NamedParameters& np) + const NamedParameters& np, + bool verbose) { std::pair name_and_color; - bool res = read_GOCAD(input, name_and_color, points, faces, np); + bool res = read_GOCAD(input, name_and_color, points, faces, np, verbose); if(res) { name = name_and_color.first; @@ -77,12 +78,13 @@ template bool read_GOCAD(std::istream& in, std::pair& name_and_color, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; - IO::internal::GOCAD_builder builder(in); + IO::internal::GOCAD_builder builder(in, verbose); if(!builder(g, np)) return false; @@ -113,10 +115,11 @@ bool read_GOCAD(std::istream& in, template bool read_GOCAD(std::istream& in, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::pair dummy; - return read_GOCAD(in, dummy,g, np); + return read_GOCAD(in, dummy,g, np, verbose); } template @@ -147,13 +150,13 @@ bool read_GOCAD(std::istream& in, \see \ref IOStreamGOCAD */ template -bool read_GOCAD(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_GOCAD(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, bool verbose = true) { std::ifstream in(fname); std::string unused_name; std::string unused_color; - return read_GOCAD(in, unused_name, unused_color, g, np); + return read_GOCAD(in, unused_name, unused_color, g, np, verbose); } template diff --git a/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_builder.h b/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_builder.h index b930e4faf79..f7881a5f275 100644 --- a/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_builder.h +++ b/BGL/include/CGAL/boost/graph/IO/Generic_facegraph_builder.h @@ -36,7 +36,7 @@ protected: typedef typename boost::graph_traits::face_descriptor face_descriptor; public: - Generic_facegraph_builder(std::istream& in_) : m_in(in_) { } + Generic_facegraph_builder(std::istream& in_, bool verbose) : m_in(in_), m_verbose(verbose) { } template bool operator()(FaceGraph& g, const NamedParameters& np) @@ -81,11 +81,13 @@ public: std::vector vertex_textures; std::vector face_colors; - bool ok = static_cast(this)->read(m_in, m_points, m_faces, - parameters::vertex_normal_output_iterator(std::back_inserter(vertex_normals)) - .vertex_color_output_iterator(std::back_inserter(vertex_colors)) - .vertex_texture_output_iterator(std::back_inserter(vertex_textures)) - .face_color_output_iterator(std::back_inserter(face_colors))); + bool ok = + static_cast(this)->read(m_in, m_points, m_faces, + parameters::vertex_normal_output_iterator(std::back_inserter(vertex_normals)) + .vertex_color_output_iterator(std::back_inserter(vertex_colors)) + .vertex_texture_output_iterator(std::back_inserter(vertex_textures)) + .face_color_output_iterator(std::back_inserter(face_colors)), + m_verbose); if(!ok) return false; @@ -140,6 +142,7 @@ protected: Point_container m_points; Face_container m_faces; + bool m_verbose; }; } // end internal diff --git a/BGL/include/CGAL/boost/graph/IO/OBJ.h b/BGL/include/CGAL/boost/graph/IO/OBJ.h index fdcb867cc28..242acd7a627 100644 --- a/BGL/include/CGAL/boost/graph/IO/OBJ.h +++ b/BGL/include/CGAL/boost/graph/IO/OBJ.h @@ -50,15 +50,16 @@ class OBJ_builder typedef typename Base::Face_container Face_container; public: - OBJ_builder(std::istream& is_) : Base(is_) { } + OBJ_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } template bool read(std::istream& input, Point_container& points, Face_container& faces, - const NamedParameters& np) + const NamedParameters& np, + bool verbose) { - return read_OBJ(input, points, faces, np); + return read_OBJ(input, points, faces, np, verbose); } }; @@ -88,12 +89,13 @@ public: template bool read_OBJ(std::istream& in, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; - IO::internal::OBJ_builder builder(in); + IO::internal::OBJ_builder builder(in, verbose); return builder(g, np); } @@ -121,18 +123,20 @@ bool read_OBJ(std::istream& in, template bool read_OBJ(const char* fname, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream in(fname); - return read_OBJ(in, g, np); + return read_OBJ(in, g, np, verbose); } template bool read_OBJ(const std::string& fname, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return read_OBJ(fname.c_str(), g, np); + return read_OBJ(fname.c_str(), g, np, verbose); } template diff --git a/BGL/include/CGAL/boost/graph/IO/OFF.h b/BGL/include/CGAL/boost/graph/IO/OFF.h index c7995b77e0b..a79911edb50 100644 --- a/BGL/include/CGAL/boost/graph/IO/OFF.h +++ b/BGL/include/CGAL/boost/graph/IO/OFF.h @@ -48,15 +48,16 @@ class OFF_builder typedef typename Base::Face_container Face_container; public: - OFF_builder(std::istream& is_) : Base(is_) { } + OFF_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } template bool read(std::istream& input, Point_container& points, Face_container& faces, - const NamedParameters& np) + const NamedParameters& np, + bool verbose) { - return read_OFF(input, points, faces, np); + return read_OFF(input, points, faces, np, verbose); } }; @@ -65,12 +66,13 @@ public: template bool read_OFF_BGL(std::istream& in, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; - IO::internal::OFF_builder builder(in); + IO::internal::OFF_builder builder(in, verbose); return builder(g, np); } @@ -104,9 +106,9 @@ bool read_OFF_BGL(std::istream& in, \see \ref IOStreamOFF */ template -bool read_OFF(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_OFF(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, bool verbose = true) { - return IO::internal::read_OFF_BGL(in, g, np); + return IO::internal::read_OFF_BGL(in, g, np, verbose); } /*! @@ -136,16 +138,18 @@ bool read_OFF(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) \see \ref IOStreamOFF */ template -bool read_OFF(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_OFF(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream in(fname); - return read_OFF(in, g, np); + return read_OFF(in, g, np, verbose); } template -bool read_OFF(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_OFF(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return read_OFF(fname.c_str(), g, np); + return read_OFF(fname.c_str(), g, np, verbose); } template diff --git a/BGL/include/CGAL/boost/graph/IO/PLY.h b/BGL/include/CGAL/boost/graph/IO/PLY.h index ef1f3aeb7a8..888f158d933 100644 --- a/BGL/include/CGAL/boost/graph/IO/PLY.h +++ b/BGL/include/CGAL/boost/graph/IO/PLY.h @@ -43,42 +43,46 @@ class PLY_builder typedef typename Base::Face_container Face_container; public: - PLY_builder(std::istream& is_) : Base(is_) { } + PLY_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } //! TODO: use vertex_point_map template bool read(std::istream& input, Point_container& points, Face_container& faces, - const NamedParameters& np) + const NamedParameters& np, + bool verbose) { - return read_PLY(input, points, faces, np); + return read_PLY(input, points, faces, np, verbose); } }; template bool read_PLY_BGL(std::istream& in, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; - IO::internal::PLY_builder builder(in); + IO::internal::PLY_builder builder(in, verbose); return builder(g, np); } // document that too template -bool read_PLY(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_PLY(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream in(fname); - return read_PLY(in, g, np); + return read_PLY(in, g, np, verbose); } template -bool read_PLY(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_PLY(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return read_PLY(fname.c_str(), g, np); + return read_PLY(fname.c_str(), g, np, verbose); } template @@ -118,9 +122,9 @@ bool read_PLY(const std::string& fname, FaceGraph& g) { return read_PLY(fname, g \see \ref IOStreamPLY */ template -bool read_PLY(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_PLY(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, bool verbose = true) { - return IO::internal::read_PLY_BGL(in, g, np); + return IO::internal::read_PLY_BGL(in, g, np, verbose); } /*! @@ -148,16 +152,18 @@ bool read_PLY(std::istream& in, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) \see \ref IOStreamPLY */ template -bool read_PLY(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_PLY(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream is(fname); - return IO::internal::read_PLY_BGL(is, g, np); + return IO::internal::read_PLY_BGL(is, g, np, verbose); } template -bool read_PLY(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_PLY(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return IO::internal::read_PLY_BGL(fname.c_str(), g, np); + return IO::internal::read_PLY_BGL(fname.c_str(), g, np, verbose); } diff --git a/BGL/include/CGAL/boost/graph/IO/STL.h b/BGL/include/CGAL/boost/graph/IO/STL.h index 92e4ce4b336..2f22264f050 100644 --- a/BGL/include/CGAL/boost/graph/IO/STL.h +++ b/BGL/include/CGAL/boost/graph/IO/STL.h @@ -45,15 +45,16 @@ class STL_builder typedef typename Base::Face_container Face_container; public: - STL_builder(std::istream& is_) : Base(is_) { } + STL_builder(std::istream& is_, bool verbose) : Base(is_, verbose) { } template bool read(std::istream& input, Point_container& points, Face_container& faces, - const NamedParameters& np) + const NamedParameters& np, + bool verbose) { - return read_STL(input, points, faces, np); + return read_STL(input, points, faces, np, verbose); } }; @@ -63,26 +64,29 @@ public: template bool read_STL(std::istream& in, FaceGraph& g, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { typedef typename CGAL::GetVertexPointMap::type VPM; typedef typename boost::property_traits::value_type Point; - IO::internal::STL_builder builder(in); + IO::internal::STL_builder builder(in, verbose); return builder(g, np); } template -bool read_STL(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_STL(const char* fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream in(fname); - return read_STL(in, g, np); + return read_STL(in, g, np, verbose); } template -bool read_STL(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np) +bool read_STL(const std::string& fname, FaceGraph& g, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return read_STL(fname.c_str(), g, np); + return read_STL(fname.c_str(), g, np, verbose); } template diff --git a/BGL/include/CGAL/boost/graph/io.h b/BGL/include/CGAL/boost/graph/io.h index 365e034ebef..23c5f3fbc06 100644 --- a/BGL/include/CGAL/boost/graph/io.h +++ b/BGL/include/CGAL/boost/graph/io.h @@ -22,44 +22,111 @@ #include namespace CGAL{ + +/*! + * + */ template bool read_polygon_mesh(std::istream& is, FaceGraph& g, const NamedParameters& np) { bool ok = false; - ok = read_OFF(is, g, np); + ok = read_OFF(is, g, np, false); if(ok) return true; g.clear(); is.clear();//reset the error state is.seekg (0, is.beg); - ok = read_OBJ(is, g, np); + ok = read_OBJ(is, g, np, false); if(ok) return true; g.clear(); is.clear(); is.seekg (0, is.beg); - ok = read_PLY(is, g, np); + ok = read_PLY(is, g, np, false); if(ok) return true; g.clear(); is.clear(); is.seekg (0, is.beg); - ok = read_STL(is, g, np); + ok = read_STL(is, g, np, false); if(ok) return true; g.clear(); is.clear(); is.seekg (0, is.beg); - ok = read_GOCAD(is, g, np); + ok = read_GOCAD(is, g, np, false); return ok; } + template bool read_polygon_mesh(std::istream& is, FaceGraph& g) { return read_polygon_mesh(is, g, parameters::all_default()); } + +/*! + * + */ +template +bool read_polygon_mesh(const std::string& fname, + FaceGraph& g, + const NamedParameters& np) +{ + if (fname.find(".TS") != std::string::npos) { + return read_GOCAD(fname, g, np); + } + + if (fname.find(".obj") != std::string::npos) { + return read_OBJ(fname, g, np); + } + + if (fname.find(".off") != std::string::npos) { + return read_OFF(fname, g, np); + } + + if (fname.find(".ply") != std::string::npos) { + return read_PLY(fname, g, np); + } + + if (fname.find(".stl") != std::string::npos) { + return read_STL(fname, g, np); + } + + if (fname.find(".vtp") != std::string::npos) { + return read_VTP(fname, g, np); + } + + std::istream is(fname.c_str()); + return read_polygon_mesh(is, g, np, false); +} + +template +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) +{ + return read_polygon_mesh(std::string(fname), g, np); +} + +template +bool read_polygon_mesh(const char* fname, + FaceGraph& g) +{ + return read_polygon_mesh(fname, g, parameters::all_default()); +} + + }//end CGAL #endif // CGAL_BOOST_GRAPH_IO_H diff --git a/BGL/test/BGL/test_bgl_read_write.cpp b/BGL/test/BGL/test_bgl_read_write.cpp index 7fa4453c1a0..24bc852e1cb 100644 --- a/BGL/test/BGL/test_bgl_read_write.cpp +++ b/BGL/test/BGL/test_bgl_read_write.cpp @@ -76,6 +76,7 @@ void test_bgl_OFF(const char* filename) Mesh sm; std::ifstream in(filename); CGAL::read_polygon_mesh(in,sm); + CGAL::write_OFF(std::cout, sm); } @@ -564,7 +565,7 @@ int main(int argc, char** argv) { const char* filename=(argc>1) ? argv[1] : "data/prim.off"; // OFF - /*test_bgl_OFF(filename); + test_bgl_OFF(filename); test_bgl_OFF(filename); test_bgl_OFF(filename); #ifdef CGAL_USE_OPENMESH @@ -594,7 +595,7 @@ int main(int argc, char** argv) #ifdef CGAL_USE_OPENMESH test_bgl_OBJ_with_np(); #endif -*/ + //PLY if(!test_bgl_PLY()) diff --git a/Polyhedron/include/CGAL/IO/Polyhedron_OFF_iostream.h b/Polyhedron/include/CGAL/IO/Polyhedron_OFF_iostream.h index dbbb4eb6bd3..67fd6502566 100644 --- a/Polyhedron/include/CGAL/IO/Polyhedron_OFF_iostream.h +++ b/Polyhedron/include/CGAL/IO/Polyhedron_OFF_iostream.h @@ -6,7 +6,7 @@ // $URL$ // $Id$ // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial -// +// // // Author(s) : Lutz Kettner @@ -62,7 +62,7 @@ template bool read_OFF(std::istream& in, Polyhedron_3& P, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, bool verbose = true) { // reads a polyhedron from `in' and appends it to P. typedef typename CGAL::GetVertexPointMap, CGAL_BGL_NP_CLASS>::type VPM; @@ -70,7 +70,7 @@ bool read_OFF(std::istream& in, using parameters::choose_parameter; using parameters::get_parameter; - CGAL::scan_OFF(in, P); + CGAL::scan_OFF(in, P, verbose); if(!parameters::is_default_parameter(get_parameter(np, internal_np::vertex_point))) { diff --git a/Polyhedron/include/CGAL/IO/scan_OFF.h b/Polyhedron/include/CGAL/IO/scan_OFF.h index db63ae8cb1c..ef25f830e56 100644 --- a/Polyhedron/include/CGAL/IO/scan_OFF.h +++ b/Polyhedron/include/CGAL/IO/scan_OFF.h @@ -47,7 +47,7 @@ template void scan_OFF(std::istream& in, Polyhedron_3& P, - bool verbose = false) + bool verbose = true) { // reads a polyhedron from `in' and appends it to P. typedef Polyhedron_3 Polyhedron; diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h index 12133e805be..e221a499132 100644 --- a/Stream_support/include/CGAL/IO/GOCAD.h +++ b/Stream_support/include/CGAL/IO/GOCAD.h @@ -39,8 +39,10 @@ bool read_GOCAD(std::istream& input, std::pair& name_and_color, PointRange& points, PolygonRange& polygons, - const NamedParameters&) + const NamedParameters&, + bool verbose = true) { + CGAL_USE(verbose); typedef typename boost::range_value::type Point; typedef typename boost::range_value::type CGAL_Polygon; int offset = 0; diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index a93190f7b18..b370e8e389c 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -37,7 +37,8 @@ template ::type Point; typedef typename CGAL::Kernel_traits::Kernel Kernel; @@ -103,12 +104,14 @@ bool read_OBJ(std::istream& is, } if(maxi<0) { - //not a OBJ file + if(verbose) + std::cerr<<"No face detected."< static_cast(points.size()) || mini < -static_cast(points.size())) { - std::cerr << "a face index is invalid " << std::endl; + if(verbose) + std::cerr << "a face index is invalid " << std::endl; return false; } bool res = is.bad(); @@ -123,30 +126,34 @@ template bool read_OBJ(const char* fname, PointRange& points, PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream in(fname); - return read_OBJ(in, points, polygons, np); + return read_OBJ(in, points, polygons, np, verbose); } template -bool read_OBJ(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) +bool read_OBJ(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return read_OBJ(fname.c_str(), points, polygons, np); + return read_OBJ(fname.c_str(), points, polygons, np, verbose); } //! \ingroup IOstreamFunctions diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 721c3874f92..9ea32d22000 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -49,8 +49,10 @@ bool read_OFF(std::istream& is, VertexNormalOutputIterator vn_out, VertexColorOutputIterator vc_out, VertexTextureOutputIterator vt_out, - FaceColorOutputIterator fc_out) + FaceColorOutputIterator fc_out, + bool verbose = true) { + CGAL_USE(verbose); typedef typename boost::range_value::type Point; typedef typename CGAL::Kernel_traits::Kernel Kernel; typedef typename Kernel::Point_2 Texture; @@ -154,7 +156,8 @@ template bool read_OFF(std::istream& is, PointRange& points, PolygonRange& polygons, - const NamedParameters& np) + const NamedParameters& np, + bool verbose = true) { using parameters::choose_parameter; using parameters::get_parameter; @@ -167,23 +170,26 @@ bool read_OFF(std::istream& is, choose_parameter(get_parameter(np, internal_np::vertex_texture_output_iterator), CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), - CGAL::Emptyset_iterator())); + CGAL::Emptyset_iterator()), + verbose); } template bool read_OFF(const char* fname, PointRange& points, PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { std::ifstream in(fname); - return read_OFF(in, points, polygons, np); + return read_OFF(in, points, polygons, np, verbose); } template -bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) +bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { - return read_OFF(fname.c_str(), points, polygons, np); + return read_OFF(fname.c_str(), points, polygons, np, verbose); } /*! diff --git a/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h b/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h index 13416ca37d6..e31308410ea 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h +++ b/Stream_support/include/CGAL/IO/OFF/File_header_OFF_impl.h @@ -241,11 +241,6 @@ std::istream& operator>>( std::istream& in, File_header_OFF& h) { } if ( ! in ) return in; - if( ! h.off_header()) - { - in.clear( std::ios::badbit); - return in; - } h.set_skel(false); h.set_binary(false); h.set_index_offset(1); @@ -265,7 +260,14 @@ std::istream& operator>>( std::istream& in, File_header_OFF& h) { keyword[i] = '\0'; if ( i < 2 || (std::isdigit(keyword[0]) && keyword[0] != '4') || std::isdigit(keyword[1])) { - h.set_vertices( std::atoi( keyword)); + in.clear( std::ios::badbit); + if ( h.verbose()) { + std::cerr << " " << std::endl; + std::cerr << "error: File_header_OFF: " + "Missing header." + << std::endl; + } + return in; } else { h.set_index_offset( 0); int j = 0; diff --git a/Stream_support/include/CGAL/IO/PLY.h b/Stream_support/include/CGAL/IO/PLY.h index 097bcb705fe..d1e54121040 100644 --- a/Stream_support/include/CGAL/IO/PLY.h +++ b/Stream_support/include/CGAL/IO/PLY.h @@ -39,7 +39,7 @@ bool read_PLY(std::istream& is, ColorOutputIterator fc_out, ColorOutputIterator vc_out, HUVOutputIterator huvs_out, - bool /* verbose */ = false, + bool verbose = true, typename std::enable_if< CGAL::is_iterator::value >::type* =0) @@ -48,11 +48,12 @@ bool read_PLY(std::istream& is, typedef CGAL::Color Color_rgb; if(!is.good()) { - std::cerr << "Error: cannot open file" << std::endl; + if(verbose) + std::cerr << "Error: cannot open file" << std::endl; return false; } - IO::internal::PLY_reader reader; + IO::internal::PLY_reader reader(verbose); if(!(reader.init(is))) { @@ -124,7 +125,8 @@ bool read_PLY(std::istream& is, IO::internal::read_PLY_faces(is, element, polygons, fc_out, "vertex_index"); else { - std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; + if(verbose) + std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; return false; } } @@ -203,12 +205,12 @@ bool read_PLY(std::istream& is, ColorRange& fcolors, ColorRange& vcolors, HUVRange& huvs, - bool /* verbose */ = false, + bool verbose =true, typename std::enable_if< !CGAL::is_iterator::value >::type* =0) { - return IO::internal::read_PLY(is, points, polygons, std::back_inserter(hedges), std::back_inserter(fcolors), std::back_inserter(vcolors), std::back_inserter(huvs)); + return IO::internal::read_PLY(is, points, polygons, std::back_inserter(hedges), std::back_inserter(fcolors), std::back_inserter(vcolors), std::back_inserter(huvs), verbose); } template bool read_PLY(std::istream& is, @@ -216,19 +218,20 @@ bool read_PLY(std::istream& is, PolygonRange& polygons, ColorRange& fcolors, ColorRange& vcolors, - bool /* verbose */ = false) + bool verbose = true) { std::vector > dummy_pui; std::vector > dummy_pf; - return IO::internal::read_PLY(is, points, polygons, dummy_pui, std::back_inserter(fcolors), std::back_inserter(vcolors), dummy_pf); + return IO::internal::read_PLY(is, points, polygons, dummy_pui, std::back_inserter(fcolors), std::back_inserter(vcolors), dummy_pf, verbose); } -template +template bool read_PLY(std::istream& is, PointRange& points, PolygonRange& polygons, - const NamedParameters& np) + const CGAL_BGL_NP_CLASS& np, + bool verbose = true) { using parameters::choose_parameter; @@ -241,7 +244,7 @@ bool read_PLY(std::istream& is, CGAL::Emptyset_iterator()), choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), CGAL::Emptyset_iterator()), - std::back_inserter(dummy_pf)); + std::back_inserter(dummy_pf), verbose); } @@ -263,7 +266,8 @@ template bool read_PLY(std::istream& is, PointRange& points, - PolygonRange& polygons + PolygonRange& polygons, + bool verbose = true #ifndef DOXYGEN_RUNNING ,typename std::enable_if< boost::has_value_type::value @@ -274,11 +278,12 @@ read_PLY(std::istream& is, typedef typename PointRange::value_type Point_3; if(!is.good()) { - std::cerr << "Error: cannot open file" << std::endl; + if(verbose) + std::cerr << "Error: cannot open file" << std::endl; return false; } - IO::internal::PLY_reader reader; + IO::internal::PLY_reader reader(verbose); if(!(reader.init(is))) { @@ -325,7 +330,8 @@ read_PLY(std::istream& is, IO::internal::read_PLY_faces(is, element, polygons, dummy, "vertex_index"); else { - std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; + if(verbose) + std::cerr << "Error: can't find vertex indices in PLY input" << std::endl; return false; } } @@ -352,10 +358,11 @@ template diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h index 2c7dd493778..5254f0be7c8 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h @@ -414,9 +414,10 @@ class PLY_reader { std::vector m_elements; std::string m_comments; + bool m_verbose; public: - PLY_reader() { } + PLY_reader(bool verbose) : m_verbose(verbose) { } std::size_t number_of_elements() const { return m_elements.size(); } PLY_element& element(std::size_t idx) @@ -449,7 +450,8 @@ public: if(!(iss >> signature) || (signature != "ply")) { // if wrong file format - std::cerr << "Error: incorrect file format line " << lineNumber << " of file" << std::endl; + if(m_verbose) + std::cerr << "Error: incorrect file format line " << lineNumber << " of file" << std::endl; return false; } } @@ -460,7 +462,8 @@ public: std::string tag, format_string, version; if( !(iss >> tag >> format_string >> version) ) { - std::cerr << "Error line " << lineNumber << " of file" << std::endl; + if(m_verbose) + std::cerr << "Error line " << lineNumber << " of file" << std::endl; return false; } if(format_string == "ascii") format = ASCII; @@ -468,7 +471,8 @@ public: else if(format_string == "binary_big_endian") format = BINARY_BIG_ENDIAN; else { - std::cerr << "Error: unknown file format \"" << format_string << "\" line " << lineNumber << std::endl; + if(m_verbose) + std::cerr << "Error: unknown file format \"" << format_string << "\" line " << lineNumber << std::endl; return false; } } @@ -479,7 +483,8 @@ public: std::string keyword; if(!(iss >> keyword)) { - std::cerr << "Error line " << lineNumber << " of file" << std::endl; + if(m_verbose) + std::cerr << "Error line " << lineNumber << " of file" << std::endl; return false; } @@ -488,7 +493,8 @@ public: std::string type, name; if(!(iss >> type >> name)) { - std::cerr << "Error line " << lineNumber << " of file" << std::endl; + if(m_verbose) + std::cerr << "Error line " << lineNumber << " of file" << std::endl; return false; } @@ -500,7 +506,8 @@ public: name.clear(); if(!(iss >> index_type >> name)) { - std::cerr << "Error line " << lineNumber << " of file" << std::endl; + if(m_verbose) + std::cerr << "Error line " << lineNumber << " of file" << std::endl; return false; } @@ -542,7 +549,8 @@ public: std::size_t number; if(!(iss >> type >> number)) { - std::cerr << "Error line " << lineNumber << " of file" << std::endl; + if(m_verbose) + std::cerr << "Error line " << lineNumber << " of file" << std::endl; return false; } diff --git a/Stream_support/include/CGAL/IO/STL.h b/Stream_support/include/CGAL/IO/STL.h index 5aeee3522bf..6fb9b5359cb 100644 --- a/Stream_support/include/CGAL/IO/STL.h +++ b/Stream_support/include/CGAL/IO/STL.h @@ -34,9 +34,9 @@ template Mesh; typedef typename Mesh::Vertex_index Vertex_index; @@ -97,7 +96,8 @@ bool read_OFF(std::istream& is, .vertex_normal_map(vnormals) .vertex_color_map(vcolors) .vertex_texture_map(vtextures) - .face_color_map(fcolors)); + .face_color_map(fcolors), + verbose); } //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index 8a980a51962..38577c28134 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -932,13 +932,15 @@ bool write_PLY(std::ostream& os, template bool read_PLY(std::istream& is, Surface_mesh

& sm, - std::string& comments) + std::string& comments, + bool verbose = true) { typedef typename Surface_mesh

::size_type size_type; if(!is.good()) { - std::cerr << "Error: cannot open file" << std::endl; + if(verbose) + std::cerr << "Error: cannot open file" << std::endl; return false; }