diff --git a/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h b/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h index fcacf8b4685..5d780e7f9e5 100644 --- a/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h +++ b/Point_set_processing_3/include/CGAL/IO/read_xyz_points.h @@ -25,6 +25,7 @@ #include #include +#include #include #include #include diff --git a/Stream_support/include/CGAL/IO/3MF.h b/Stream_support/include/CGAL/IO/3MF.h index 8801f7e9363..a573822f6a0 100644 --- a/Stream_support/include/CGAL/IO/3MF.h +++ b/Stream_support/include/CGAL/IO/3MF.h @@ -32,10 +32,9 @@ namespace CGAL { //////////////////////////////////////////////////////////////////////////////////////////////////// /// Read - template -int read_from_3mf(const std::string& file_name, +int read_from_3mf(const std::string& fname, PointRanges& all_points, PolygonRanges& all_polygons, ColorRanges& all_colors, @@ -80,7 +79,7 @@ int read_from_3mf(const std::string& file_name, } // Import Model from File - hResult = NMR::lib3mf_reader_readfromfileutf8(pReader, file_name.c_str()); + hResult = NMR::lib3mf_reader_readfromfileutf8(pReader, fname.c_str()); if(hResult != LIB3MF_OK) { std::cerr << "could not parse file: " << std::hex << hResult << std::endl; @@ -368,7 +367,6 @@ int read_from_3mf(const std::string& file_name, return all_points.size(); } - /*! * \ingroup IOstreamFunctions * @@ -387,20 +385,20 @@ int read_from_3mf(const std::string& file_name, * a model of the concepts `RandomAccessContainer` and `BackInsertionSequence` * whose `value type` is `CGAL::Color`. * - * \param file_name the name of the 3mf file to read. - * \param all_points a `PointRanges` that will contain the points of the meshes in `file_name`. + * \param fname the name of the 3mf file to read. + * \param all_points a `PointRanges` that will contain the points of the meshes in `fname`. * Each of these meshes will add a range of its points. - * \param all_polygons a `PolygonRanges` that will contain the triangles of the meshes in `file_name`. + * \param all_polygons a `PolygonRanges` that will contain the triangles of the meshes in `fname`. * Each of these meshes will add a range of its triangles. A `triangle` of * `all_polygons[i]` contains the indices of its points in `all_points[i]`. * \param all_colors will contain the color of each triangle for each soup. - * \param names will contain the name of each mesh in `file_name` if any. + * \param names will contain the name of each mesh in `fname` if any. * If the i'th mesh has no name, it will be called "Unknown Mesh" in names. * * \return the number of soups read. */ template -int read_triangle_soups_from_3mf(const std::string& file_name, +int read_triangle_soups_from_3mf(const std::string& fname, PointRanges& all_points, PolygonRanges& all_polygons, ColorRanges& all_colors, @@ -411,9 +409,10 @@ int read_triangle_soups_from_3mf(const std::string& file_name, typedef typename ColorRanges::value_type ColorRange; return read_from_3mf - (file_name, all_points, all_polygons, all_colors, names, + (fname, all_points, all_polygons, all_colors, names, extract_soups); } + //////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////// /// Write @@ -422,7 +421,7 @@ int read_triangle_soups_from_3mf(const std::string& file_name, * \ingroup IOstreamFunctions * * \brief writes the triangle soups contained in `all_points` and - * `all_polygons` into the 3mf file `file_name`. + * `all_polygons` into the 3mf file `fname`. * * \tparam PointRanges a model of the concepts `RandomAccessContainer` and * `BackInsertionSequence` whose `value type` is @@ -433,15 +432,15 @@ int read_triangle_soups_from_3mf(const std::string& file_name, * whose `value_type` is a model of the concept `RandomAccessContainer` whose * `value_type` is std::size_t. * - * \param file_name the name of the 3mf file to write. + * \param fname the name of the 3mf file to write. * \param all_points a `PointRanges` that contains the points of the soups to write. - * \param all_polygons a `PolygonRanges` that contains the triangles of the soups in `file_name`. - * \param names will contains the name of each mesh in `file_name`. + * \param all_polygons a `PolygonRanges` that contains the triangles of the soups in `fname`. + * \param names contains the name of each mesh to be output. * * \return `true` if the writing is successful, `false` otherwise. */ template -bool write_triangle_soups_to_3mf(const std::string& file_name, +bool write_triangle_soups_to_3mf(const std::string& fname, const PointRanges& all_points, const PolygonRanges& all_polygons, const std::vector& names) diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h index 5e19b8cfba4..801fc74ec43 100644 --- a/Stream_support/include/CGAL/IO/GOCAD.h +++ b/Stream_support/include/CGAL/IO/GOCAD.h @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include diff --git a/Stream_support/include/CGAL/IO/Generic_writer.h b/Stream_support/include/CGAL/IO/Generic_writer.h index ae38bc4985e..58014bc3f64 100644 --- a/Stream_support/include/CGAL/IO/Generic_writer.h +++ b/Stream_support/include/CGAL/IO/Generic_writer.h @@ -17,7 +17,6 @@ #ifndef CGAL_IO_GENERIC_WRITER_H #define CGAL_IO_GENERIC_WRITER_H -#include #include #include diff --git a/Stream_support/include/CGAL/IO/OBJ.h b/Stream_support/include/CGAL/IO/OBJ.h index 980a0aa07ab..e014043ae62 100644 --- a/Stream_support/include/CGAL/IO/OBJ.h +++ b/Stream_support/include/CGAL/IO/OBJ.h @@ -18,6 +18,7 @@ #include #include +#include #include #include @@ -149,19 +150,16 @@ bool read_OBJ(std::istream& is, } template -bool read_OBJ(const char* fname, - PointRange& points, - PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np, - bool verbose = true) +bool read_OBJ(const char* fname, PointRange& points, PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np, bool verbose = true) { std::ifstream in(fname); 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 verbose = true) +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, verbose); } @@ -216,6 +214,25 @@ bool write_OBJ(std::ostream& os, return writer(points, polygons); } +template +bool write_OBJ(const char* fname, const PointRange& points, const PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream out(fname); + return write_OBJ(out, points, polygons, np); +} + +template +bool write_OBJ(const std::string& fname, const PointRange& points, const PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np) +{ + return write_OBJ(fname.c_str(), points, polygons, np); +} + /*! * \ingroup ObjIoFuncs * @@ -223,27 +240,12 @@ bool write_OBJ(std::ostream& os, * * \see \ref IOStreamOBJ */ -template -bool write_OBJ(std::ostream& os, - const PointRange& points, - const PolygonRange& polygons) +template +bool write_OBJ(std::ostream& os, const PointRange& points, const PolygonRange& polygons) { return write_OBJ(os, points, polygons, parameters::all_default()); } -template -bool write_OBJ(const char* fname, - const PointRange& points, - const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) -{ - std::ofstream out(fname); - return write_OBJ(out, points, polygons, np); -} - /*! * \ingroup ObjIoFuncs * @@ -251,24 +253,10 @@ bool write_OBJ(const char* fname, * * \see \ref IOStreamOBJ */ -template -bool write_OBJ(const char* fname, - const PointRange& points, - const PolygonRange& polygons) +template +bool write_OBJ(const char* fname, const PointRange& points, const PolygonRange& polygons) { - return write_OBJ(fname, points, polygons); -} - -template -bool write_OBJ(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np) -{ - return write_OBJ(fname.c_str(), points, polygons,np); + return write_OBJ(fname, points, polygons, parameters::all_default()); } template diff --git a/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h index 4bf99fc4ee6..1e68245d9b7 100644 --- a/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h +++ b/Stream_support/include/CGAL/IO/OBJ/File_writer_wavefront.h @@ -25,18 +25,18 @@ namespace CGAL { class File_writer_wavefront { - std::ostream* m_out; + std::ostream* m_os; std::size_t m_facets; public: - std::ostream& out() const { return *m_out; } + std::ostream& out() const { return *m_os; } void write_header(std::ostream& o, std::size_t vertices, std::size_t halfedges, std::size_t facets) { - m_out = &o; + m_os = &o; m_facets = facets; // Print header. diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 28f68bad76a..d6c65a4dee4 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -52,13 +52,14 @@ bool read_OFF(std::istream& is, 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; typedef typename Kernel::Vector_3 Normal; typedef CGAL::Color Color; + CGAL_USE(verbose); + if(!is.good()) return false; @@ -145,8 +146,7 @@ bool read_OFF(std::istream& is, } } - bool res = !is.fail(); - return res; + return !is.fail(); } } // namespace internal @@ -230,17 +230,6 @@ bool read_OFF(const std::string& fname, PointRange& points, PolygonRange& polygo //////////////////////////////////////////////////////////////////////////////////////////////////// /// Write - -template -bool write_OFF(std::ostream& os, - const PointRange& points, - const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& ) -{ - Generic_writer writer(os); - return writer(points, polygons); -} - /*! * \ingroup OffIoFuncs * @@ -248,26 +237,14 @@ bool write_OFF(std::ostream& os, * * \see \ref IOStreamOFF */ -template +template bool write_OFF(std::ostream& os, - const PointRange& points, - const PolygonRange& polygons - ,typename boost::enable_if< - typename boost::has_range_const_iterator::type - >::type* =0) -{ - return write_OFF(os, points, polygons, parameters::all_default()); -} - -template -bool write_OFF(const char* fname, const PointRange& points, const PolygonRange& polygons, - const CGAL_BGL_NP_CLASS&) + const CGAL_BGL_NP_CLASS& np) { - std::ofstream os(fname); Generic_writer writer(os); - return writer(points, polygons); + return writer(points, polygons, np); } /*! @@ -277,38 +254,53 @@ bool write_OFF(const char* fname, * * \see \ref IOStreamOFF */ +template +bool write_OFF(const char* fname, + const PointRange& points, + const PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + Generic_writer writer(os); + return writer(points, polygons, np); +} + +template +bool write_OFF(std::ostream& os, const PointRange& points, const PolygonRange& polygons, + typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0) +{ + return write_OFF(os, points, polygons, parameters::all_default()); +} + template bool write_OFF(const char* fname, const PointRange& points, - const PolygonRange& polygons - ,typename boost::enable_if< - typename boost::has_range_const_iterator::type + const PolygonRange& polygons, + typename boost::enable_if< + typename boost::has_range_const_iterator::type >::type* =0) { return write_OFF(fname, points, polygons, parameters::all_default()); } template -bool write_OFF(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons, +bool write_OFF(const std::string& fname, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { return write_OFF(fname.c_str(), points, polygons, np); } template -bool write_OFF(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons - ,typename boost::enable_if< - typename boost::has_range_const_iterator::type +bool write_OFF(const std::string& fname, const PointRange& points, const PolygonRange& polygons, + typename boost::enable_if< + typename boost::has_range_const_iterator::type >::type* =0) { return write_OFF(fname, points, polygons, parameters::all_default()); } - } // namespace CGAL #endif // CGAL_IO_OFF_H diff --git a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h index 9ea5a15b0c3..7420a8210de 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h +++ b/Stream_support/include/CGAL/IO/OFF/File_scanner_OFF.h @@ -271,6 +271,7 @@ public: std::cerr<<"error while reading vertex."<> iformat(w))) { diff --git a/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h b/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h index d7af635b927..9b99e2357f4 100644 --- a/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h +++ b/Stream_support/include/CGAL/IO/OFF/File_writer_OFF.h @@ -27,14 +27,14 @@ namespace CGAL { class File_writer_OFF { - std::ostream* m_out; + std::ostream* m_os; File_header_OFF m_header; public: File_writer_OFF(bool verbose = false) : m_header(verbose) {} File_writer_OFF(const File_header_OFF& h) : m_header(h) {} - std::ostream& out() { return *m_out; } + std::ostream& out() { return *m_os; } File_header_OFF& header() { return m_header; } const File_header_OFF& header() const { return m_header; } @@ -44,7 +44,7 @@ public: std::size_t facets, bool normals = false) { - m_out = &os; + m_os = &os; m_header.set_vertices(vertices); m_header.set_facets(facets); diff --git a/Stream_support/include/CGAL/IO/OI/File_writer_inventor.h b/Stream_support/include/CGAL/IO/OI/File_writer_inventor.h index 73e6557a814..7feef93c563 100644 --- a/Stream_support/include/CGAL/IO/OI/File_writer_inventor.h +++ b/Stream_support/include/CGAL/IO/OI/File_writer_inventor.h @@ -25,19 +25,19 @@ namespace CGAL { class File_writer_inventor { - Inventor_ostream_base* m_out; + Inventor_ostream_base* m_os; std::size_t m_facets; public: File_writer_inventor() {} - std::ostream& out() const { return m_out->os(); } + std::ostream& out() const { return m_os->os(); } void write_header(Inventor_ostream_base& o, std::size_t vertices, std::size_t halfedges, std::size_t facets) { - m_out = &o; + m_os = &o; m_facets = facets; out() << "# " << vertices << " vertices\n"; diff --git a/Stream_support/include/CGAL/IO/PLY.h b/Stream_support/include/CGAL/IO/PLY.h index 39b23332dd8..b6df7e2f411 100644 --- a/Stream_support/include/CGAL/IO/PLY.h +++ b/Stream_support/include/CGAL/IO/PLY.h @@ -37,8 +37,9 @@ namespace CGAL { namespace IO { namespace internal { -//HEdgesRange" = range of std::pair -//HUVRange = range of std::pair + +// HEdgesRange" = range of std::pair +// HUVRange = range of std::pair template bool read_PLY(std::istream& is, PointRange& points, @@ -47,13 +48,14 @@ bool read_PLY(std::istream& is, ColorOutputIterator fc_out, ColorOutputIterator vc_out, HUVOutputIterator huvs_out, - bool verbose = true, + bool verbose = true, typename std::enable_if< CGAL::is_iterator::value >::type* =0) { typedef typename PointRange::value_type Point_3; typedef CGAL::Color Color_rgb; + if(!is.good()) { if(verbose) @@ -69,7 +71,7 @@ bool read_PLY(std::istream& is, return false; } - for(std::size_t i = 0; i < reader.number_of_elements(); ++ i) + for(std::size_t i=0; i("red") || element.has_property("r")) && (element.has_property("green") || element.has_property("g")) && (element.has_property("blue") || element.has_property("b"))) { has_colors = true; + if(element.has_property("red")) { - rtag = "red"; gtag = "green"; btag = "blue"; + rtag = "red"; + gtag = "green"; + btag = "blue"; } } - for(std::size_t j = 0; j < element.number_of_items(); ++ j) + for(std::size_t j=0; jget(is); @@ -100,23 +106,24 @@ bool read_PLY(std::istream& is, } std::tuple new_vertex; - if(has_colors) { IO::internal::process_properties(element, new_vertex, - make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex)), - std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_vertex), - PLY_property(rtag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_vertex), - PLY_property(gtag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_vertex), - PLY_property(btag.c_str()))); + make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex)), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_vertex), + PLY_property(rtag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_vertex), + PLY_property(gtag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_vertex), + PLY_property(btag.c_str()))); *vc_out++ = Color_rgb(get<1>(new_vertex), get<2>(new_vertex), get<3>(new_vertex)); } else + { IO::internal::process_properties(element, new_vertex, make_ply_point_reader(CGAL::make_nth_of_tuple_property_map<0>(new_vertex))); + } points.push_back(get<0>(new_vertex)); } @@ -124,13 +131,21 @@ bool read_PLY(std::istream& is, else if(element.name() == "face" || element.name() == "faces") { if(element.has_property >("vertex_indices")) + { IO::internal::read_PLY_faces(is, element, polygons, fc_out, "vertex_indices"); + } else if(element.has_property >("vertex_indices")) + { IO::internal::read_PLY_faces(is, element, polygons, fc_out, "vertex_indices"); + } else if(element.has_property >("vertex_index")) + { IO::internal::read_PLY_faces(is, element, polygons, fc_out, "vertex_index"); + } else if(element.has_property >("vertex_index")) + { IO::internal::read_PLY_faces(is, element, polygons, fc_out, "vertex_index"); + } else { if(verbose) @@ -142,18 +157,18 @@ bool read_PLY(std::istream& is, { bool has_uv = false; std::string stag = "source", ttag = "target", utag = "u", vtag = "v"; - if( element.has_property("source") && - element.has_property("target") && - element.has_property("u") && - element.has_property("v")) + if(element.has_property("source") && + element.has_property("target") && + element.has_property("u") && + element.has_property("v")) { has_uv = true; } - cpp11::tuple new_hedge; - for(std::size_t j = 0; j < element.number_of_items(); ++ j) + std::tuple new_hedge; + for(std::size_t j=0; jget(is); @@ -165,33 +180,33 @@ bool read_PLY(std::istream& is, if(has_uv) { IO::internal::process_properties(element, new_hedge, - std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), - PLY_property(stag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), - PLY_property(ttag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_hedge), - PLY_property(utag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_hedge), - PLY_property(vtag.c_str()))); + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), + PLY_property(stag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), + PLY_property(ttag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<2>(new_hedge), + PLY_property(utag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<3>(new_hedge), + PLY_property(vtag.c_str()))); + *hedges_out++ = std::make_pair(get<0>(new_hedge), get<1>(new_hedge)); *huvs_out++ = std::make_pair(get<2>(new_hedge), get<3>(new_hedge)); } else { IO::internal::process_properties(element, new_hedge, - std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), - PLY_property(stag.c_str())), - std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), - PLY_property(ttag.c_str())) - ); + std::make_pair(CGAL::make_nth_of_tuple_property_map<0>(new_hedge), + PLY_property(stag.c_str())), + std::make_pair(CGAL::make_nth_of_tuple_property_map<1>(new_hedge), + PLY_property(ttag.c_str()))); } } } else // Read other elements and ignore { - for(std::size_t j = 0; j < element.number_of_items(); ++ j) + for(std::size_t j=0; jget(is); @@ -203,8 +218,10 @@ bool read_PLY(std::istream& is, } return !is.fail(); } -}// End of internal -}// End of IO + +} // namespace internal +} // namespace IO + template bool read_PLY(std::istream& is, PointRange& points, @@ -213,13 +230,14 @@ bool read_PLY(std::istream& is, ColorRange& fcolors, ColorRange& vcolors, HUVRange& huvs, - bool verbose =true, + 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), verbose); } + template bool read_PLY(std::istream& is, PointRange& points, @@ -230,10 +248,10 @@ bool read_PLY(std::istream& is, { std::vector > dummy_pui; std::vector > dummy_pf; + return IO::internal::read_PLY(is, points, polygons, std::back_inserter(dummy_pui), std::back_inserter(fcolors), std::back_inserter(vcolors), std::back_inserter(dummy_pf), verbose); } - template bool read_PLY(std::istream& is, PointRange& points, @@ -241,22 +259,20 @@ bool read_PLY(std::istream& is, const CGAL_BGL_NP_CLASS& np, bool verbose = true) { - using parameters::choose_parameter; using parameters::get_parameter; + std::vector > dummy_pui; std::vector > dummy_pf; return IO::internal::read_PLY(is, points, polygons,std::back_inserter(dummy_pui), - choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), - CGAL::Emptyset_iterator()), - choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), - CGAL::Emptyset_iterator()), - std::back_inserter(dummy_pf), verbose); + choose_parameter(get_parameter(np, internal_np::face_color_output_iterator), + CGAL::Emptyset_iterator()), + choose_parameter(get_parameter(np, internal_np::vertex_color_output_iterator), + CGAL::Emptyset_iterator()), + std::back_inserter(dummy_pf), verbose); } - - /*! * \ingroup PlyIoFuncs * @@ -271,17 +287,16 @@ bool read_PLY(std::istream& is, * \see \ref IOStreamPLY */ template -bool -read_PLY(std::istream& is, - PointRange& points, - PolygonRange& polygons, - bool verbose = true +bool read_PLY(std::istream& is, + PointRange& points, + PolygonRange& polygons, + bool verbose = true #ifndef DOXYGEN_RUNNING - ,typename std::enable_if< - boost::has_value_type::value - >::type* =0 - #endif - ) + , typename std::enable_if< + boost::has_value_type::value + >::type* =0 +#endif + ) { typedef typename PointRange::value_type Point_3; if(!is.good()) @@ -292,22 +307,21 @@ read_PLY(std::istream& is, } IO::internal::PLY_reader reader(verbose); - if(!(reader.init(is))) { is.setstate(std::ios::failbit); return false; } - for(std::size_t i = 0; i < reader.number_of_elements(); ++ i) + for(std::size_t i=0; iget(is); @@ -317,10 +331,8 @@ read_PLY(std::istream& is, } Point_3 new_vertex; - IO::internal::process_properties(element, new_vertex, - make_ply_point_reader(CGAL::Identity_property_map())); - + make_ply_point_reader(CGAL::Identity_property_map())); points.push_back(new_vertex); } } @@ -329,13 +341,21 @@ read_PLY(std::istream& is, std::vector dummy; if(element.has_property >("vertex_indices")) + { IO::internal::read_PLY_faces(is, element, polygons, dummy, "vertex_indices"); + } else if(element.has_property >("vertex_indices")) + { IO::internal::read_PLY_faces(is, element, polygons, dummy, "vertex_indices"); + } else if(element.has_property >("vertex_index")) + { IO::internal::read_PLY_faces(is, element, polygons, dummy, "vertex_index"); + } else if(element.has_property >("vertex_index")) + { IO::internal::read_PLY_faces(is, element, polygons, dummy, "vertex_index"); + } else { if(verbose) @@ -345,9 +365,9 @@ read_PLY(std::istream& is, } else // Read other elements and ignore { - for(std::size_t j = 0; j < element.number_of_items(); ++ j) + for(std::size_t j=0; jget(is); @@ -363,11 +383,8 @@ read_PLY(std::istream& is, } template -bool read_PLY(const char* fname, - PointRange& points, - PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np, - bool verbose = true) +bool read_PLY(const char* fname, PointRange& points, PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np, bool verbose = true) { std::ifstream is(fname); return read_PLY(is, points, polygons, np, verbose); @@ -390,22 +407,19 @@ template bool read_PLY(const char* fname, PointRange& points, PolygonRange& polygons - #ifndef DOXYGEN_RUNNING - ,typename std::enable_if< - !CGAL::is_iterator::value - >::type* =0 - #endif - ) +#ifndef DOXYGEN_RUNNING + , typename std::enable_if< + !CGAL::is_iterator::value + >::type* =0 +#endif + ) { return read_PLY(fname, points, polygons, parameters::all_default()); } template -bool read_PLY(const std::string& fname, - PointRange& points, - PolygonRange& polygons, - const CGAL_BGL_NP_CLASS& np, - bool verbose = true) +bool read_PLY(const std::string& fname, PointRange& points, PolygonRange& polygons, + const CGAL_BGL_NP_CLASS& np, bool verbose = true) { return read_PLY(fname.c_str(), points, polygons, np, verbose); } @@ -414,12 +428,12 @@ template bool read_PLY(const std::string fname, PointRange& points, PolygonRange& polygons - #ifndef DOXYGEN_RUNNING - ,typename std::enable_if< - !CGAL::is_iterator::value - >::type* =0 - #endif - ) +#ifndef DOXYGEN_RUNNING + , typename std::enable_if< + !CGAL::is_iterator::value + >::type* =0 +#endif + ) { return read_PLY(fname, points, polygons, parameters::all_default()); } @@ -433,18 +447,19 @@ bool write_PLY(std::ostream& out, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& - #ifndef DOXYGEN_RUNNING - ,typename boost::enable_if< - typename boost::has_range_const_iterator::type - >::type* =0, +#ifndef DOXYGEN_RUNNING + , typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0, typename std::enable_if< - boost::has_value_type::value + boost::has_value_type::value >::type* =0 - #endif +#endif ) { typedef typename PointRange::value_type Point_3; typedef typename PolygonRange::value_type Polygon_3; + if(!out.good()) { std::cerr << "Error: cannot open file" << std::endl; @@ -457,7 +472,7 @@ bool write_PLY(std::ostream& out, << "comment Generated by the CGAL library" << std::endl << "element vertex " << points.size() << std::endl; - IO::internal::output_property_header(out, make_ply_point_writer (CGAL::Identity_property_map())); + IO::internal::output_property_header(out, make_ply_point_writer(CGAL::Identity_property_map())); out << "element face " << polygons.size() << std::endl; @@ -466,19 +481,18 @@ bool write_PLY(std::ostream& out, out << "end_header" << std::endl; - for (std::size_t i = 0; i < points.size(); ++ i) + for(std::size_t i=0; i())); + make_ply_point_writer(CGAL::Identity_property_map())); - for (std::size_t i = 0; i < polygons.size(); ++ i) + for(std::size_t i=0; i(), - PLY_property >("vertex_indices"))); + std::make_pair(CGAL::Identity_property_map(), + PLY_property >("vertex_indices"))); return out.good(); } - /*! * \ingroup PlyIoFuncs * @@ -495,14 +509,14 @@ template bool write_PLY(std::ostream& out, const PointRange& points, const PolygonRange& polygons - #ifndef DOXYGEN_RUNNING - ,typename boost::enable_if< - typename boost::has_range_const_iterator::type - >::type* =0, +#ifndef DOXYGEN_RUNNING + , typename boost::enable_if< + typename boost::has_range_const_iterator::type + >::type* =0, typename std::enable_if< - boost::has_value_type::value + boost::has_value_type::value >::type* =0 - #endif +#endif ) { return write_PLY(out, points, polygons, parameters::all_default()); @@ -518,7 +532,6 @@ bool write_PLY(const char* fname, return write_PLY(os, points, polygons, np); } - /*! * \ingroup PlyIoFuncs * @@ -532,26 +545,20 @@ bool write_PLY(const char* fname, * \see \ref IOStreamPLY */ template -bool write_PLY(const char* fname, - const PointRange& points, - const PolygonRange& polygons) +bool write_PLY(const char* fname, const PointRange& points, const PolygonRange& polygons) { return write_PLY(fname, points, polygons, parameters::all_default()); } template -bool write_PLY(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons, +bool write_PLY(const std::string& fname, const PointRange& points, const PolygonRange& polygons, const CGAL_BGL_NP_CLASS& np) { return write_PLY(fname.c_str(), points, polygons, np); } template -bool write_PLY(const std::string& fname, - const PointRange& points, - const PolygonRange& polygons) +bool write_PLY(const std::string& fname, const PointRange& points, const PolygonRange& polygons) { return write_PLY(fname, points, polygons, parameters::all_default()); } diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h index 139a5afbff9..0ad97718546 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h @@ -79,10 +79,10 @@ struct Get_FT_from_map template std::tuple::Kernel::Construct_point_3, -PLY_property::type>, -PLY_property::type>, -PLY_property::type> > + typename Kernel_traits::Kernel::Construct_point_3, + PLY_property::type>, + PLY_property::type>, + PLY_property::type> > make_ply_point_reader(PointMap point_map) { return std::make_tuple(point_map, typename Kernel_traits::Kernel::Construct_point_3(), @@ -93,10 +93,10 @@ make_ply_point_reader(PointMap point_map) template std::tuple::Kernel::Construct_vector_3, -PLY_property::type>, -PLY_property::type>, -PLY_property::type> > + typename Kernel_traits::Kernel::Construct_vector_3, + PLY_property::type>, + PLY_property::type>, + PLY_property::type> > make_ply_normal_reader(VectorMap normal_map) { return std::make_tuple(normal_map, typename Kernel_traits::Kernel::Construct_vector_3(), @@ -107,9 +107,9 @@ make_ply_normal_reader(VectorMap normal_map) template std::tuple::type>, -PLY_property::type>, -PLY_property::type> > + PLY_property::type>, + PLY_property::type>, + PLY_property::type> > make_ply_point_writer(PointMap point_map) { return std::make_tuple(point_map, @@ -120,9 +120,9 @@ make_ply_point_writer(PointMap point_map) template std::tuple::type>, -PLY_property::type>, -PLY_property::type> > + PLY_property::type>, + PLY_property::type>, + PLY_property::type> > make_ply_normal_writer(VectorMap normal_map) { return std::make_tuple(normal_map, @@ -160,6 +160,7 @@ public: else stream.clear(std::ios::badbit); } + void read_ascii(std::istream& stream, signed char& c) const { short s; @@ -168,6 +169,7 @@ public: else stream.clear(std::ios::badbit); } + void read_ascii(std::istream& stream, unsigned char& c) const { unsigned short s; @@ -197,7 +199,6 @@ public: stream.clear(std::ios::badbit); } - template Type read(std::istream& stream) const { @@ -241,46 +242,39 @@ class PLY_read_typed_number : public PLY_read_number public: PLY_read_typed_number(std::string name, std::size_t format) : PLY_read_number(name, format) - { - } - void get(std::istream& stream) const - { - m_buffer =(this->read(stream)); - } - const Type& buffer() const - { - return m_buffer; - } + { } + + void get(std::istream& stream) const { m_buffer =(this->read(stream)); } + + const Type& buffer() const { return m_buffer; } }; template -class PLY_read_typed_list : public PLY_read_number +class PLY_read_typed_list + : public PLY_read_number { protected: mutable std::vector m_buffer; + public: PLY_read_typed_list(std::string name, std::size_t format) : PLY_read_number(name, format) - { - } + { } + virtual void get(std::istream& stream) const = 0; - const std::vector& buffer() const - { - return m_buffer; - } + const std::vector& buffer() const { return m_buffer; } }; template class PLY_read_typed_list_with_typed_size - : public PLY_read_typed_list + : public PLY_read_typed_list { - public: PLY_read_typed_list_with_typed_size(std::string name, std::size_t format) : PLY_read_typed_list(name, format) - { - } + { } + void get(std::istream& stream) const { std::size_t size = static_cast(this->template read(stream)); @@ -294,10 +288,9 @@ class PLY_element { std::string m_name; std::size_t m_number; - std::vector m_properties; -public: +public: PLY_element(const std::string& name, std::size_t number) : m_name(name), m_number(number) { } @@ -339,6 +332,7 @@ public: { return has_property(tag, Type()); } + template bool has_property(const char* tag, const std::vector&) { @@ -356,6 +350,7 @@ public: return (dynamic_cast*>(m_properties[i]) != nullptr); return false; } + bool has_property(const char* tag, double) { for(std::size_t i = 0; i < number_of_properties(); ++ i) @@ -585,7 +580,6 @@ void get_value(Reader& r, T& v, PLY_property& wrapper) return r.assign(v, wrapper.name); } - template struct Filler { @@ -709,7 +703,11 @@ bool read_PLY_faces(std::istream& in, { has_colors = true; if(element.has_property("red")) - rtag = "red"; gtag = "green"; btag = "blue"; + { + rtag = "red"; + gtag = "green"; + btag = "blue"; + } } for(std::size_t j = 0; j < element.number_of_items(); ++ j) @@ -766,6 +764,7 @@ bool read_PLY_faces(std::istream& in, { return read_PLY_faces(in, element, polygons, std::back_inserter(fcolors), vertex_indices_tag); } + } // namespace PLY } // namespace internal /// \endcond diff --git a/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h b/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h index 8248c903540..aa90d44ff77 100644 --- a/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h +++ b/Stream_support/include/CGAL/IO/VRML/File_writer_VRML_2.h @@ -28,19 +28,19 @@ namespace CGAL { class File_writer_VRML_2 { - VRML_2_ostream* m_out; + VRML_2_ostream* m_os; std::size_t m_facets; public: File_writer_VRML_2() {} - std::ostream& out() const { return m_out->os(); } + std::ostream& out() const { return m_os->os(); } void write_header(VRML_2_ostream& o, std::size_t vertices, std::size_t halfedges, std::size_t facets) { - m_out = &o; + m_os = &o; m_facets = facets; out() << " #-- Begin of Polygon Mesh\n"; diff --git a/Stream_support/include/CGAL/IO/VTK.h b/Stream_support/include/CGAL/IO/VTK.h index 4368c837786..b19121710a4 100644 --- a/Stream_support/include/CGAL/IO/VTK.h +++ b/Stream_support/include/CGAL/IO/VTK.h @@ -84,8 +84,8 @@ bool vtkPointSet_to_polygon_soup(vtkPointSet* poly_data, return true; } -}//end internal -}//end IO +} // namespace internal +} // namespace IO //////////////////////////////////////////////////////////////////////////////////////////////////// @@ -339,9 +339,8 @@ void write_soup_polys_points(std::ostream& os, write_vector(os, coordinates); } -}//end internal -}//end IO - +} // namespace internal +} // namespace IO template bool write_VTP(std::ostream& os, @@ -458,7 +457,7 @@ bool write_VTP(const std::string& fname, return write_VTP(fname, points, polygons, parameters::all_default()); } -}//end CGAL +} // namespace CGAL #elif DOXYGEN_RUNNING /*! @@ -472,6 +471,7 @@ template bool read_VTP(const char* fname, PointRange& points, PolygonRange& polygons); + /*! * \ingroup VtpIoFuncs * @@ -482,6 +482,7 @@ template bool write_VTP(std::ostream& os, const PointRange& points, const PolygonRange& polygons); + /*! * \ingroup VtpIoFuncs * diff --git a/Stream_support/include/CGAL/IO/VTK/VTK_reader.h b/Stream_support/include/CGAL/IO/VTK/VTK_reader.h index 30b04811064..771920a50d2 100644 --- a/Stream_support/include/CGAL/IO/VTK/VTK_reader.h +++ b/Stream_support/include/CGAL/IO/VTK/VTK_reader.h @@ -72,13 +72,13 @@ private: }; template -vtkSmartPointer read_vtk_file(const std::string& input_filename, +vtkSmartPointer read_vtk_file(const std::string& fname, vtkSmartPointer errorObserver) { vtkSmartPointer reader = vtkSmartPointer::New(); reader->AddObserver(vtkCommand::ErrorEvent, errorObserver); reader->AddObserver(vtkCommand::WarningEvent, errorObserver); - reader->SetFileName(input_filename.data()); + reader->SetFileName(fname.data()); reader->Update(); return reader; diff --git a/Stream_support/include/CGAL/IO/WKT.h b/Stream_support/include/CGAL/IO/WKT.h index c59e532f999..f38f7216482 100644 --- a/Stream_support/include/CGAL/IO/WKT.h +++ b/Stream_support/include/CGAL/IO/WKT.h @@ -544,7 +544,7 @@ std::ostream& write_multi_linestring_WKT(std::ostream& out, template -std::istream& read_WKT(std::istream& input, +std::istream& read_WKT(std::istream& is, MultiPoint& points, MultiLineString& polylines, MultiPolygon& polygons) @@ -556,8 +556,8 @@ std::istream& read_WKT(std::istream& input, typedef typename MultiPolygon::value_type Polygon; std::string line; - std::streampos input_pos = input.tellg(); - std::getline(input, line); + std::streampos input_pos = is.tellg(); + std::getline(is, line); std::istringstream iss(line); std::string t; std::string type=""; @@ -572,51 +572,51 @@ std::istream& read_WKT(std::istream& input, type.push_back(c); } - input.seekg(input_pos); + is.seekg(input_pos); if(type == "POINT") { Point p; - CGAL::read_point_WKT(input, p); + CGAL::read_point_WKT(is, p); points.push_back(p); } else if(type == "LINESTRING") { LineString l; - CGAL::read_linestring_WKT(input, l); + CGAL::read_linestring_WKT(is, l); polylines.push_back(l); } else if(type == "POLYGON") { Polygon p; - CGAL::read_polygon_WKT(input, p); + CGAL::read_polygon_WKT(is, p); if(!p.outer_boundary().is_empty()) polygons.push_back(p); } else if(type == "MULTIPOINT") { MultiPoint mp; - CGAL::read_multi_point_WKT(input, mp); + CGAL::read_multi_point_WKT(is, mp); for(const Point& point : mp) points.push_back(point); } else if(type == "MULTILINESTRING") { MultiLineString mls; - CGAL::read_multi_linestring_WKT(input, mls); + CGAL::read_multi_linestring_WKT(is, mls); for(const LineString& ls : mls) polylines.push_back(ls); } else if(type == "MULTIPOLYGON") { MultiPolygon mp; - CGAL::read_multi_polygon_WKT(input, mp); + CGAL::read_multi_polygon_WKT(is, mp); for(const Polygon& poly : mp) polygons.push_back(poly); } } - while(input.good() && !input.eof()); + while(is.good() && !is.eof()); - return input; + return !is.fail(); } } // namespace CGAL CGAL