From 2d49f7d7027d319b8a692b03d73179a68e8f6c2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mael=20Rouxel-Labb=C3=A9?= Date: Sun, 21 Jun 2020 11:52:08 +0200 Subject: [PATCH] Countless IO fixes... Don't have the patience to split it nicely --- .../Classification/example_classification.cpp | 5 +- .../Classification/example_feature.cpp | 11 +- .../Convex_hull_3/extreme_indices_3.cpp | 4 +- .../Tutorials/Tutorial_reconstruction.txt | 12 +- .../examples/Point_set_3/draw_point_set_3.cpp | 2 +- .../Point_set_3/point_set_advanced.cpp | 10 +- Point_set_3/include/CGAL/Point_set_3/IO.h | 44 +- Point_set_3/include/CGAL/Point_set_3/IO/LAS.h | 81 ++- Point_set_3/include/CGAL/Point_set_3/IO/OFF.h | 93 +++- Point_set_3/include/CGAL/Point_set_3/IO/PLY.h | 200 +++++-- Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h | 92 +++- .../test/Point_set_3/point_set_test_join.cpp | 1 - .../PackageDescription.txt | 28 +- .../Point_set_processing_3.txt | 26 +- .../bilateral_smooth_point_set_example.cpp | 22 +- .../edge_aware_upsample_point_set_example.cpp | 3 +- .../grid_simplify_indices.cpp | 1 - .../hierarchy_simplification_example.cpp | 7 +- .../normal_estimation.cpp | 2 +- .../read_las_example.cpp | 2 +- .../read_ply_points_with_colors_example.cpp | 2 +- .../scale_estimation_2d_example.cpp | 1 - .../Point_set_processing_3/analysis_test.cpp | 13 +- .../bilateral_smoothing_test.cpp | 19 +- .../edge_aware_upsample_test.cpp | 20 +- .../normal_estimation_test.cpp | 12 +- .../test/Point_set_processing_3/read_test.cpp | 44 +- .../read_test_with_different_pmaps.cpp | 5 +- .../remove_outliers_test.cpp | 13 +- .../Point_set_processing_3/smoothing_test.cpp | 13 +- .../test_read_write_point_set.cpp | 253 +++++---- .../Point_set_processing_3/vcm_all_test.cpp | 14 +- .../wlop_simplify_and_regularize_test.cpp | 13 +- ...olyfit_example_model_complexty_control.cpp | 2 +- .../polyfit_example_user_provided_planes.cpp | 2 +- ...al_surface_reconstruction_test_framework.h | 3 +- STL_Extension/include/CGAL/is_iterator.h | 1 + .../scale_space.cpp | 21 +- .../scale_space_advancing_front.cpp | 9 +- .../scale_space_incremental.cpp | 22 +- .../scale_space_manifold.cpp | 47 +- .../shape_detection_basic_deprecated.cpp | 2 +- .../test_efficient_RANSAC_scene.cpp | 13 +- .../File_formats/Supported_file_formats.txt | 2 +- .../doc/Stream_support/IOstream.txt | 491 +++++++++--------- .../doc/Stream_support/PackageDescription.txt | 2 + Stream_support/include/CGAL/IO/GOCAD.h | 2 +- Stream_support/include/CGAL/IO/OFF.h | 2 +- .../include/CGAL/IO/PLY/PLY_reader.h | 2 +- .../include/CGAL/IO/STL/STL_reader.h | 2 +- Stream_support/include/CGAL/IO/helpers.h | 38 +- .../include/CGAL/Surface_mesh/IO/OFF.h | 2 +- .../include/CGAL/Surface_mesh/IO/PLY.h | 2 +- 53 files changed, 998 insertions(+), 737 deletions(-) diff --git a/Classification/examples/Classification/example_classification.cpp b/Classification/examples/Classification/example_classification.cpp index 469d40b57ae..377038f7058 100644 --- a/Classification/examples/Classification/example_classification.cpp +++ b/Classification/examples/Classification/example_classification.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include @@ -52,8 +52,7 @@ int main (int argc, char** argv) std::vector pts; std::cerr << "Reading input" << std::endl; - if (!in - || !(CGAL::read_PLY (in, std::back_inserter (pts)))) + if (!in || !(CGAL::read_points(in, std::back_inserter(pts)))) { std::cerr << "Error: cannot read " << filename << std::endl; return EXIT_FAILURE; diff --git a/Classification/examples/Classification/example_feature.cpp b/Classification/examples/Classification/example_feature.cpp index 270490a4eb6..87638724e84 100644 --- a/Classification/examples/Classification/example_feature.cpp +++ b/Classification/examples/Classification/example_feature.cpp @@ -3,15 +3,15 @@ // converts 64 to 32 bits integers #endif +#include +#include +#include + #include #include #include #include -#include -#include -#include - typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point; typedef Kernel::Iso_cuboid_3 Iso_cuboid_3; @@ -71,8 +71,7 @@ int main (int argc, char** argv) std::vector pts; std::cerr << "Reading input" << std::endl; - if (!in - || !(CGAL::read_PLY (in, std::back_inserter (pts)))) + if (!in || !(CGAL::read_points(in, std::back_inserter(pts)))) { std::cerr << "Error: cannot read " << filename << std::endl; return EXIT_FAILURE; diff --git a/Convex_hull_3/examples/Convex_hull_3/extreme_indices_3.cpp b/Convex_hull_3/examples/Convex_hull_3/extreme_indices_3.cpp index b697eb883c9..d5c8c8080d0 100644 --- a/Convex_hull_3/examples/Convex_hull_3/extreme_indices_3.cpp +++ b/Convex_hull_3/examples/Convex_hull_3/extreme_indices_3.cpp @@ -1,7 +1,7 @@ #include #include #include -#include +#include #include @@ -23,7 +23,7 @@ int main(int argc, char* argv[]) } std::vector points; - CGAL::read_off_points(in, std::back_inserter(points)); + CGAL::read_points(in, std::back_inserter(points)); //This will contain the extreme vertices std::vector extreme_point_indices; diff --git a/Documentation/doc/Documentation/Tutorials/Tutorial_reconstruction.txt b/Documentation/doc/Documentation/Tutorials/Tutorial_reconstruction.txt index fb60465bbc0..4f80cd33642 100644 --- a/Documentation/doc/Documentation/Tutorials/Tutorial_reconstruction.txt +++ b/Documentation/doc/Documentation/Tutorials/Tutorial_reconstruction.txt @@ -83,12 +83,12 @@ a newline character and each coordinate separated by a white space. Other formats available are 'OFF', 'PLY' and 'LAS'. \cgal provides functions to read such formats: -- `read_xyz_points()` -- `read_off_points()` -- `read_ply_points()` -- `read_ply_points_with_properties()` to read additional PLY properties -- `read_las_points()` -- `read_las_points_with_properties()` to read additional LAS properties +- `read_XYZ()` +- `read_OFF()` +- `read_PLY()` +- `read_PLY_with_properties()` to read additional PLY properties +- `read_LAS()` +- `read_LAS_with_properties()` to read additional LAS properties \cgal also provides a dedicated container `CGAL::Point_set_3` to handle point sets with additional properties such as normal diff --git a/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp b/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp index db9e8d13899..07cd0ed8776 100644 --- a/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp +++ b/Point_set_3/examples/Point_set_3/draw_point_set_3.cpp @@ -16,7 +16,7 @@ int main (int argc, char** argv) Point_set point_set; // Reading input in XYZ format - if (!f || !CGAL::read_XYZ (f, point_set)) + if (!f || !CGAL::read_point_set(f, point_set)) { std::cerr<<"Can't read input file " <<(argc > 1 ? argv[1] : "data/oni.xyz")<< std::endl; diff --git a/Point_set_3/examples/Point_set_3/point_set_advanced.cpp b/Point_set_3/examples/Point_set_3/point_set_advanced.cpp index 88d8c7d9bdc..85b06934c0b 100644 --- a/Point_set_3/examples/Point_set_3/point_set_advanced.cpp +++ b/Point_set_3/examples/Point_set_3/point_set_advanced.cpp @@ -1,6 +1,6 @@ #include + #include -#include #include #include @@ -19,11 +19,9 @@ int main (int argc, char** argv) Point_set point_set; point_set.add_normal_map(); // Reading input in OFF format - if (!f || !CGAL::read_OFF - (f, - point_set.index_back_inserter(), // OutputIterator - CGAL::parameters::point_map(point_set.point_push_map()). - normal_map(point_set.normal_push_map()))) + if (!f || !CGAL::read_point_set(f, point_set.index_back_inserter(), // OutputIterator + CGAL::parameters::point_map(point_set.point_push_map()) + .normal_map(point_set.normal_push_map()))) { std::cerr << "Can't read input file " << std::endl; return EXIT_FAILURE; diff --git a/Point_set_3/include/CGAL/Point_set_3/IO.h b/Point_set_3/include/CGAL/Point_set_3/IO.h index ff8dedc6a09..dd034b42900 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO.h @@ -72,7 +72,7 @@ std::istream& operator>>(std::istream& is, CGAL::read_PLY(is, ps); #ifdef CGAL_LINKED_WITH_LASLIB else if(line.find("LASF") == 0) - CGAL::read_las_points(is, ps); + CGAL::read_LAS(is, ps); #endif // LAS else CGAL::read_XYZ(is, ps); @@ -171,28 +171,38 @@ std::ostream& operator<<(std::ostream& os, \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" \param fname the path to the output file - \param ps the point set. + \param ps the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. */ -template -bool write_point_set(const std::string& fname, - CGAL::Point_set_3& ps) +template +bool write_point_set(const char* fname, + CGAL::Point_set_3& ps, + const CGAL_BGL_NP_CLASS& np) { const std::string ext = IO::internal::get_file_extension(fname); if(ext == "xyz") - return write_XYZ(fname, ps); + return write_XYZ(fname, ps, np); else if(ext == "off") - return write_OFF(fname, ps); + return write_OFF(fname, ps, np); else if(ext == "ply") - return write_PLY(fname, ps); + return write_PLY(fname, ps, np); #ifdef CGAL_LINKED_WITH_LASLIB else if(ext == "las") - return write_LAS(fname, ps); + return write_LAS(fname, ps, np); #endif return false; @@ -201,7 +211,19 @@ bool write_point_set(const std::string& fname, template bool write_point_set(const char* fname, CGAL::Point_set_3& ps) { - return write_point_set(std::string(fname), ps); + return write_point_set(fname, ps, parameters::all_default()); +} + +template +bool write_point_set(const std::string& fname, CGAL::Point_set_3& ps, const CGAL_BGL_NP_CLASS& np) +{ + return write_point_set(fname.c_str(), ps, np); +} + +template +bool write_point_set(const std::string& fname, CGAL::Point_set_3& ps) +{ + return write_point_set(fname.c_str(), ps, parameters::all_default()); } } // namespace CGAL diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/LAS.h b/Point_set_3/include/CGAL/Point_set_3/IO/LAS.h index c7a539e08b6..e577a2b12d3 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/LAS.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/LAS.h @@ -65,16 +65,16 @@ void check_if_property_is_used(PointSet& point_set, \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` - \param stream the input stream - \param point_set the point set. + \param is the input stream + \param point_set the point set \return `true` if the reading was successful, `false` otherwise. */ template -bool read_LAS(std::istream& stream, +bool read_LAS(std::istream& is, CGAL::Point_set_3& point_set) { - if(!stream) + if(!is) { std::cerr << "Error: cannot open file" << std::endl; return false; @@ -108,7 +108,7 @@ bool read_LAS(std::istream& stream, bool okay = read_LAS_with_properties - (stream, point_set.index_back_inserter(), + (is, point_set.index_back_inserter(), make_las_point_reader(point_set.point_push_map()), std::make_pair(point_set.push_property_map(intensity), LAS_property::Intensity()), std::make_pair(point_set.push_property_map(return_number), LAS_property::Return_number()), @@ -172,10 +172,10 @@ bool read_LAS(const std::string& fname, CGAL::Point_set_3& point_ \deprecated This function is deprecated since \cgal 5.2, `CGAL::read_LAS()` should be used instead. */ template -CGAL_DEPRECATED bool read_las_point_set(std::istream& stream, ///< input stream. +CGAL_DEPRECATED bool read_las_point_set(std::istream& is, ///< input stream. CGAL::Point_set_3& point_set) ///< point set { - return read_LAS(stream, point_set); + return read_LAS(is, point_set); } #endif // CGAL_NO_DEPRECATED_CODE @@ -191,22 +191,36 @@ CGAL_DEPRECATED bool read_las_point_set(std::istream& stream, ///< input stream. \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - \param stream the output stream - \param point_set the point set. + \param os the output stream + \param point_set the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. */ -template -bool write_LAS(std::ostream& stream, - CGAL::Point_set_3& point_set) +template +bool write_LAS(std::ostream& os, + CGAL::Point_set_3& point_set, + const CGAL_BGL_NP_CLASS& np) { - if(!stream) + if(!os) { std::cerr << "Error: cannot open file" << std::endl; return false; } + const int precision = parameters::choose_parameter(parameters::get_parameter(np, internal_np::stream_precision), 6); + os << std::setprecision(precision); + typedef CGAL::Point_set_3 Point_set; typedef typename Point_set::template Property_map Float_map; typedef typename Point_set::template Property_map Double_map; @@ -324,7 +338,7 @@ bool write_LAS(std::ostream& stream, bool okay = write_LAS_with_properties - (stream, point_set, + (os, point_set, make_las_point_writer(point_set.point_map()), std::make_pair(intensity, LAS_property::Intensity()), std::make_pair(return_number, LAS_property::Return_number()), @@ -367,6 +381,12 @@ bool write_LAS(std::ostream& stream, return okay; } +template +bool write_LAS(std::ostream& os, CGAL::Point_set_3& point_set) +{ + return write_LAS(os, point_set, parameters::all_default()); +} + /*! \ingroup PkgPointSet3IO @@ -374,23 +394,46 @@ bool write_LAS(std::ostream& stream, \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" \param fname the path to the output file - \param point_set the point set. + \param point_set the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. */ +template +bool write_LAS(const char* fname, CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return write_LAS(os, point_set, np); +} + template bool write_LAS(const char* fname, CGAL::Point_set_3& point_set) { std::ofstream os(fname); - return write_LAS(os, point_set); + return write_LAS(os, point_set, parameters::all_default()); +} + +template +bool write_LAS(const std::string& fname, CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + return write_LAS(fname.c_str(), point_set, np); } template bool write_LAS(const std::string& fname, CGAL::Point_set_3& point_set) { - return write_LAS(fname.c_str(), point_set); + return write_LAS(fname.c_str(), point_set, parameters::all_default()); } #ifndef CGAL_NO_DEPRECATED_CODE @@ -401,10 +444,10 @@ bool write_LAS(const std::string& fname, CGAL::Point_set_3& point \deprecated This function is deprecated since \cgal 5.2, `CGAL::write_LAS()` should be used instead. */ template -CGAL_DEPRECATED bool write_las_point_set(std::ostream& stream, ///< output stream. +CGAL_DEPRECATED bool write_las_point_set(std::ostream& os, ///< output stream. CGAL::Point_set_3& point_set) ///< point set { - return write_LAS(stream, point_set); + return write_LAS(os, point_set); } #endif // CGAL_NO_DEPRECATED_CODE diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h b/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h index e2051bf22a9..f5dc6b7c447 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/OFF.h @@ -46,21 +46,20 @@ class Point_set_3; \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` - \param stream the input stream - \param point_set the point set. + \param is the input stream + \param point_set the point set \return `true` if the reading was successful, `false` otherwise. \see \ref IOStreamOFF */ template -bool read_OFF(std::istream& stream, +bool read_OFF(std::istream& is, CGAL::Point_set_3& point_set) { point_set.add_normal_map(); - bool out = CGAL::read_OFF(stream, - point_set.index_back_inserter(), + bool out = CGAL::read_OFF(is, point_set.index_back_inserter(), CGAL::parameters::point_map(point_set.point_push_map()) .normal_map(point_set.normal_push_map())); @@ -88,16 +87,15 @@ bool read_OFF(std::istream& stream, \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` - \param fname the path to the input file. - \param point_set the point set. + \param fname the path to the input file + \param point_set the point set \return `true` if the reading was successful, `false` otherwise. \see \ref IOStreamOFF */ template -bool read_OFF(const char* fname, - CGAL::Point_set_3& point_set) +bool read_OFF(const char* fname, CGAL::Point_set_3& point_set) { std::ifstream is(fname); return read_OFF(is, point_set); @@ -117,10 +115,10 @@ bool read_OFF(const std::string& fname, CGAL::Point_set_3& point_ \deprecated This function is deprecated since \cgal 5.2, `CGAL::read_OFF()` should be used instead. */ template -CGAL_DEPRECATED bool read_off_point_set(std::istream& stream, ///< input stream. +CGAL_DEPRECATED bool read_off_point_set(std::istream& is, ///< input stream. CGAL::Point_set_3& point_set) ///< point set. { - return read_OFF(stream, point_set); + return read_OFF(is, point_set); } #endif // CGAL_NO_DEPRECATED_CODE @@ -131,53 +129,98 @@ CGAL_DEPRECATED bool read_off_point_set(std::istream& stream, ///< input stream /*! \ingroup PkgPointSet3IO + writes the content of a point set into an output stream in the OFF format. \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - \param stream the output stream - \param point_set the point set. + \param os the output stream + \param point_set the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. + \see \ref IOStreamOFF */ -template -bool write_OFF(std::ostream& stream, - const CGAL::Point_set_3& point_set) +template +bool write_OFF(std::ostream& os, + const CGAL::Point_set_3& point_set, + const CGAL_BGL_NP_CLASS& np) { if(point_set.has_normal_map()) - return CGAL::write_OFF(stream, point_set, - CGAL::parameters::point_map(point_set.point_map()) - .normal_map(point_set.normal_map())); + return Point_set_processing_3::internal::write_OFF_PSP(os, point_set, + np.point_map(point_set.point_map()) + .normal_map(point_set.normal_map())); - return CGAL::write_OFF(stream, point_set, CGAL::parameters::point_map(point_set.point_map())); + return Point_set_processing_3::internal::write_OFF_PSP(os, point_set, + np.point_map(point_set.point_map())); +} + +template +bool write_OFF(std::ostream& os, const CGAL::Point_set_3& point_set) +{ + return write_OFF(os, point_set, parameters::all_default()); } /*! \ingroup PkgPointSet3IO + writes the content of a point set into an output file in the OFF format. \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" \param fname the path to the output file - \param point_set the point set. + \param point_set the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. + \see \ref IOStreamOFF */ +template +bool write_OFF(const char* fname, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return write_OFF(os, point_set, np); +} + template bool write_OFF(const char* fname, const CGAL::Point_set_3& point_set) { std::ofstream os(fname); - return write_OFF(os, point_set); + return write_OFF(os, point_set, parameters::all_default()); +} + +template +bool write_OFF(const std::string& fname, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + return write_OFF(fname.c_str(), point_set, np); } template bool write_OFF(const std::string& fname, const CGAL::Point_set_3& point_set) { - return write_OFF(fname.c_str(), point_set); + return write_OFF(fname.c_str(), point_set, parameters::all_default()); } #ifndef CGAL_NO_DEPRECATED_CODE @@ -188,10 +231,10 @@ bool write_OFF(const std::string& fname, const CGAL::Point_set_3& \deprecated This function is deprecated since \cgal 5.2, `CGAL::write_OFF()` should be used instead. */ template -CGAL_DEPRECATED bool write_off_point_set(std::ostream& stream, ///< output stream. +CGAL_DEPRECATED bool write_off_point_set(std::ostream& os, ///< output stream. const CGAL::Point_set_3& point_set) ///< point set { - return write_OFF(stream, point_set); + return write_OFF(os, point_set); } #endif // CGAL_NO_DEPRECATED_CODE diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h b/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h index d8de3985e99..34465fc1a19 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/PLY.h @@ -15,6 +15,8 @@ #include +#include +#include #include #include @@ -22,6 +24,11 @@ #include #include +#ifdef DOXYGEN_RUNNING +#define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters +#define CGAL_BGL_NP_CLASS NamedParameters +#endif + namespace CGAL { template @@ -242,11 +249,11 @@ public: \see \ref IOStreamPLY */ template -bool read_PLY(std::istream& stream, +bool read_PLY(std::istream& is, CGAL::Point_set_3& point_set, std::string& comments) { - if(!stream) + if(!is) { std::cerr << "Error: cannot open file" << std::endl; return false; @@ -255,9 +262,9 @@ bool read_PLY(std::istream& stream, IO::internal::PLY_reader reader(true); IO::internal::Point_set_3_filler filler(point_set); - if(!(reader.init(stream))) + if(!(reader.init(is))) { - stream.setstate(std::ios::failbit); + is.setstate(std::ios::failbit); return false; } @@ -279,8 +286,8 @@ bool read_PLY(std::istream& stream, for(std::size_t k=0; kget(stream); - if(stream.fail()) + property->get(is); + if(is.fail()) return false; } @@ -289,14 +296,14 @@ bool read_PLY(std::istream& stream, } } - return !stream.bad(); + return !is.bad(); } template -bool read_PLY(std::istream& stream, CGAL::Point_set_3& point_set) +bool read_PLY(std::istream& is, CGAL::Point_set_3& point_set) { std::string dummy; - return read_PLY(stream, point_set, dummy); + return read_PLY(is, point_set, dummy); } template @@ -333,19 +340,19 @@ bool read_PLY(const std::string& fname, CGAL::Point_set_3& point_ appended to the `comments` string (without the "comment " word). */ template -CGAL_DEPRECATED bool read_ply_point_set(std::istream& stream, ///< input stream. +CGAL_DEPRECATED bool read_ply_point_set(std::istream& is, ///< input stream. CGAL::Point_set_3& point_set, ///< point set std::string& comments) ///< PLY comments. { - return read_PLY(stream, point_set, comments); + return read_PLY(is, point_set, comments); } template -CGAL_DEPRECATED bool read_ply_point_set(std::istream& stream, ///< input stream. +CGAL_DEPRECATED bool read_ply_point_set(std::istream& is, ///< input stream. CGAL::Point_set_3& point_set) ///< point set { std::string dummy; - return read_PLY(stream, point_set, dummy); + return read_PLY(is, point_set, dummy); } #endif // CGAL_NO_DEPRECATED_CODE @@ -368,18 +375,29 @@ CGAL_DEPRECATED bool read_ply_point_set(std::istream& stream, ///< input stream. \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - \param stream the path to the input file. - \param point_set the point set. + \param os the path to the input file + \param point_set the point set \param comments optional PLY comments + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the reading was successful, `false` otherwise. \see \ref IOStreamPLY */ -template -bool write_PLY(std::ostream& stream, +template +bool write_PLY(std::ostream& os, const CGAL::Point_set_3& point_set, - const std::string& comments = std::string()) + const std::string& comments, + const CGAL_BGL_NP_CLASS& np) { typedef CGAL::Point_set_3 Point_set; typedef typename Point_set::Index Index; @@ -396,22 +414,34 @@ bool write_PLY(std::ostream& stream, typedef typename Point_set::template Property_map Float_map; typedef typename Point_set::template Property_map Double_map; - stream << "ply" << std::endl - << ((get_mode(stream) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl - << "comment Generated by the CGAL library" << std::endl; + using CGAL::parameters::choose_parameter; + using CGAL::parameters::get_parameter; + + if(!os) + { + std::cerr << "Error: cannot open file" << std::endl; + return false; + } + + const int precision = choose_parameter(get_parameter(np, internal_np::stream_precision), 6); + os << std::setprecision(precision); + + os << "ply" << std::endl + << ((get_mode(os) == IO::BINARY) ? "format binary_little_endian 1.0" : "format ascii 1.0") << std::endl + << "comment Generated by the CGAL library" << std::endl; if(comments != std::string()) { - std::istringstream iss (comments); + std::istringstream iss(comments); std::string line; while(getline(iss, line)) { if(line != "Generated by the CGAL library") // Avoid repeating the line if multiple savings - stream << "comment " << line << std::endl; + os << "comment " << line << std::endl; } } - stream << "element vertex " << point_set.number_of_points() << std::endl; + os << "element vertex " << point_set.number_of_points() << std::endl; std::vector prop = point_set.base().properties(); std::vector*> printers; @@ -425,15 +455,15 @@ bool write_PLY(std::ostream& stream, { if(boost::is_same::type, float>::value) { - stream << "property float x" << std::endl - << "property float y" << std::endl - << "property float z" << std::endl; + os << "property float x" << std::endl + << "property float y" << std::endl + << "property float z" << std::endl; } else { - stream << "property double x" << std::endl - << "property double y" << std::endl - << "property double z" << std::endl; + os << "property double x" << std::endl + << "property double y" << std::endl + << "property double z" << std::endl; } printers.push_back(new IO::internal::Property_printer(point_set.point_map())); continue; @@ -442,15 +472,15 @@ bool write_PLY(std::ostream& stream, { if(boost::is_same::type, float>::value) { - stream << "property float nx" << std::endl - << "property float ny" << std::endl - << "property float nz" << std::endl; + os << "property float nx" << std::endl + << "property float ny" << std::endl + << "property float nz" << std::endl; } else { - stream << "property double nx" << std::endl - << "property double ny" << std::endl - << "property double nz" << std::endl; + os << "property double nx" << std::endl + << "property double ny" << std::endl + << "property double nz" << std::endl; } printers.push_back(new IO::internal::Property_printer(point_set.normal_map())); continue; @@ -462,7 +492,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property char " << prop[i] << std::endl; + os << "property char " << prop[i] << std::endl; printers.push_back(new IO::internal::Char_property_printer(pmap)); continue; } @@ -472,7 +502,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property uchar " << prop[i] << std::endl; + os << "property uchar " << prop[i] << std::endl; printers.push_back(new IO::internal::Char_property_printer(pmap)); continue; } @@ -482,7 +512,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property short " << prop[i] << std::endl; + os << "property short " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -492,7 +522,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property ushort " << prop[i] << std::endl; + os << "property ushort " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -502,7 +532,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property int " << prop[i] << std::endl; + os << "property int " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -512,7 +542,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property uint " << prop[i] << std::endl; + os << "property uint " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -522,7 +552,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property int " << prop[i] << std::endl; + os << "property int " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -532,7 +562,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property uint " << prop[i] << std::endl; + os << "property uint " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -542,7 +572,7 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property float " << prop[i] << std::endl; + os << "property float " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } @@ -552,25 +582,26 @@ bool write_PLY(std::ostream& stream, boost::tie(pmap, okay) = point_set.template property_map(prop[i]); if(okay) { - stream << "property double " << prop[i] << std::endl; + os << "property double " << prop[i] << std::endl; printers.push_back(new IO::internal::Simple_property_printer(pmap)); continue; } } } - stream << "end_header" << std::endl; + os << "end_header" << std::endl; for(typename Point_set::const_iterator it = point_set.begin(); it != point_set.end(); ++it) { for(std::size_t i=0; iprint(stream, *it); - if(get_mode(stream) == IO::ASCII) - stream << " "; + printers[i]->print(os, *it); + if(get_mode(os) == IO::ASCII) + os << " "; } - if(get_mode(stream) == IO::ASCII) - stream << std::endl; + + if(get_mode(os) == IO::ASCII) + os << std::endl; } for(std::size_t i=0; i +bool write_PLY(std::ostream& os, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + return write_PLY(os, point_set, std::string(), np); +} + +template +bool write_PLY(std::ostream& os, const CGAL::Point_set_3& point_set, const std::string& comments) +{ + return write_PLY(os, point_set, comments, parameters::all_default()); +} + +template +bool write_PLY(std::ostream& os, const CGAL::Point_set_3& point_set) +{ + return write_PLY(os, point_set, std::string(), parameters::all_default()); +} + +template +bool write_PLY(const char* fname, const CGAL::Point_set_3& point_set, + const std::string& comments, const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return write_PLY(os, point_set, comments, np); +} + template bool write_PLY(const char* fname, const CGAL::Point_set_3& point_set) { @@ -585,10 +642,43 @@ bool write_PLY(const char* fname, const CGAL::Point_set_3& point_ return write_PLY(os, point_set); } +template +bool write_PLY(const char* fname, const CGAL::Point_set_3& point_set, const std::string& comments) +{ + std::ofstream os(fname); + return write_PLY(os, point_set, comments, parameters::all_default()); +} + +template +bool write_PLY(const char* fname, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return write_PLY(os, point_set, std::string(), np); +} + +template +bool write_PLY(const std::string& fname, const CGAL::Point_set_3& point_set, + const std::string& comments, const CGAL_BGL_NP_CLASS& np) +{ + return write_PLY(fname.c_str(), point_set, comments, np); +} + +template +bool write_PLY(const std::string& fname, const CGAL::Point_set_3& point_set, const std::string& comments) +{ + return write_PLY(fname.c_str(), point_set, comments, parameters::all_default()); +} + +template +bool write_PLY(const std::string& fname, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + return write_PLY(fname.c_str(), point_set, std::string(), np); +} + template bool write_PLY(const std::string& fname, const CGAL::Point_set_3& point_set) { - return write_PLY(fname.c_str(), point_set); + return write_PLY(fname.c_str(), point_set, std::string(), parameters::all_default()); } #ifndef CGAL_NO_DEPRECATED_CODE @@ -599,11 +689,11 @@ bool write_PLY(const std::string& fname, const CGAL::Point_set_3& \deprecated This function is deprecated since \cgal 5.2, `CGAL::write_PLY()` should be used instead. */ template -CGAL_DEPRECATED bool write_ply_point_set(std::ostream& stream, +CGAL_DEPRECATED bool write_ply_point_set(std::ostream& os, const CGAL::Point_set_3& point_set, const std::string& comments = std::string()) { - return write_PLY(stream, point_set, comments); + return write_PLY(os, point_set, comments); } #endif // CGAL_NO_DEPRECATED_CODE diff --git a/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h b/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h index 4008547596e..93156c9313e 100644 --- a/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h +++ b/Point_set_3/include/CGAL/Point_set_3/IO/XYZ.h @@ -15,12 +15,19 @@ #include +#include +#include #include #include #include #include +#ifdef DOXYGEN_RUNNING +#define CGAL_BGL_NP_TEMPLATE_PARAMETERS NamedParameters +#define CGAL_BGL_NP_CLASS NamedParameters +#endif + namespace CGAL { template @@ -38,7 +45,7 @@ class Point_set_3; \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` - \param stream the input stream + \param is the input stream \param point_set the point set \return `true` if the reading was successful, `false` otherwise. @@ -46,15 +53,14 @@ class Point_set_3; \see \ref IOStreamXYZ */ template -bool read_XYZ(std::istream& stream, +bool read_XYZ(std::istream& is, CGAL::Point_set_3& point_set) { point_set.add_normal_map(); - bool out = CGAL::read_xyz_points(stream, - point_set.index_back_inserter(), - CGAL::parameters::point_map(point_set.point_push_map()) - .normal_map(point_set.normal_push_map())); + bool out = CGAL::read_XYZ(is, point_set.index_back_inserter(), + CGAL::parameters::point_map(point_set.point_push_map()) + .normal_map(point_set.normal_push_map())); bool has_normals = false; for(typename CGAL::Point_set_3::const_iterator it=point_set.begin(); it!=point_set.end(); ++it) @@ -108,10 +114,9 @@ bool read_XYZ(const std::string& fname, CGAL::Point_set_3& point_ \deprecated This function is deprecated since \cgal 5.2, `CGAL::read_XYZ()` should be used instead. */ template -CGAL_DEPRECATED bool read_xyz_point_set(std::istream& stream, ///< input stream. - CGAL::Point_set_3& point_set) ///< point set +CGAL_DEPRECATED bool read_xyz_point_set(std::istream& is, CGAL::Point_set_3& point_set) { - return read_XYZ(stream, point_set); + return read_XYZ(is, point_set); } #endif // CGAL_NO_DEPRECATED_CODE @@ -127,24 +132,41 @@ CGAL_DEPRECATED bool read_xyz_point_set(std::istream& stream, ///< input stream. \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" - \param stream the output stream - \param point_set the point set. + \param os the output stream + \param point_set the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. \see \ref IOStreamXYZ */ -template -bool write_XYZ(std::ostream& stream, - const CGAL::Point_set_3& point_set) +template +bool write_XYZ(std::ostream& os, + const CGAL::Point_set_3& point_set, + const CGAL_BGL_NP_CLASS& np) { if(point_set.has_normal_map()) - return CGAL::write_XYZ(stream, point_set, - CGAL::parameters::point_map(point_set.point_map()) - .normal_map(point_set.normal_map())); + return Point_set_processing_3::internal::write_XYZ_PSP(os, point_set, + np.point_map(point_set.point_map()) + .normal_map(point_set.normal_map())); - return CGAL::write_XYZ(stream, point_set, CGAL::parameters::point_map(point_set.point_map())); + return Point_set_processing_3::internal::write_XYZ_PSP(os, point_set, np.point_map(point_set.point_map())); +} + +template +bool write_XYZ(std::ostream& os, const CGAL::Point_set_3& point_set) +{ + return write_XYZ(os, point_set, parameters::all_default()); } /*! @@ -154,25 +176,48 @@ bool write_XYZ(std::ostream& stream, \tparam Point a `CGAL::Point_3` \tparam Vector a `CGAL::Vector_3` + \tparam NamedParameters a sequence of \ref bgl_namedparameters "Named Parameters" \param fname the path to the output file - \param point_set the point set. + \param point_set the point set + \param np an optional sequence of \ref bgl_namedparameters "Named Parameters" among the ones listed below + + \cgalNamedParamsBegin + \cgalParamNBegin{stream_precision} + \cgalParamDescription{a parameter used to set the precision (i.e. how many digits are generated) of the output stream} + \cgalParamType{int} + \cgalParamDefault{`6`} + \cgalParamNEnd + \cgalNamedParamsEnd \return `true` if the writing was successful, `false` otherwise. \see \ref IOStreamXYZ */ +template +bool write_XYZ(const char* fname, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + std::ofstream os(fname); + return write_XYZ(os, point_set, np); +} + template bool write_XYZ(const char* fname, const CGAL::Point_set_3& point_set) { std::ofstream os(fname); - return write_XYZ(os, point_set); + return write_XYZ(os, point_set, parameters::all_default()); +} + +template +bool write_XYZ(const std::string& fname, const CGAL::Point_set_3& point_set, const CGAL_BGL_NP_CLASS& np) +{ + return write_XYZ(fname.c_str(), point_set, np); } template bool write_XYZ(const std::string& fname, const CGAL::Point_set_3& point_set) { - return write_XYZ(fname.c_str(), point_set); + return write_XYZ(fname.c_str(), point_set, parameters::all_default()); } #ifndef CGAL_NO_DEPRECATED_CODE @@ -183,10 +228,9 @@ bool write_XYZ(const std::string& fname, const CGAL::Point_set_3& \deprecated This function is deprecated since \cgal 5.2, `CGAL::write_XYZ()` should be used instead. */ template -CGAL_DEPRECATED bool write_xyz_point_set(std::ostream& stream, - const CGAL::Point_set_3& point_set) +CGAL_DEPRECATED bool write_xyz_point_set(std::ostream& os, const CGAL::Point_set_3& point_set) { - return write_XYZ(stream, point_set); + return write_XYZ(os, point_set); } #endif // CGAL_NO_DEPRECATED_CODE diff --git a/Point_set_3/test/Point_set_3/point_set_test_join.cpp b/Point_set_3/test/Point_set_3/point_set_test_join.cpp index 5ee3e40917b..b45098b8d2f 100644 --- a/Point_set_3/test/Point_set_3/point_set_test_join.cpp +++ b/Point_set_3/test/Point_set_3/point_set_test_join.cpp @@ -1,7 +1,6 @@ #include #include -#include #include #include diff --git a/Point_set_processing_3/doc/Point_set_processing_3/PackageDescription.txt b/Point_set_processing_3/doc/Point_set_processing_3/PackageDescription.txt index 4de8bcc62dd..a5f0a6e0d27 100644 --- a/Point_set_processing_3/doc/Point_set_processing_3/PackageDescription.txt +++ b/Point_set_processing_3/doc/Point_set_processing_3/PackageDescription.txt @@ -10,6 +10,9 @@ simplification, etc.). \defgroup PkgPointSetProcessing3IO IO (I/O Functions) \ingroup PkgPointSetProcessing3Ref +\defgroup PkgPointSetProcessing3IODeprecated IO (I/O Functions (Deprecated)) +\ingroup PkgPointSetProcessing3IO + \defgroup PkgPointSetProcessing3IOOff IO (OFF Formats) \ingroup PkgPointSetProcessing3Ref @@ -75,6 +78,11 @@ format. - `CGAL::vcm_is_on_feature_edge()` - `CGAL::structure_point_set()` +\cgalCRPSection{IO (All Formats)} + +- `CGAL::read_points()` +- `CGAL::write_points()` + \cgalCRPSection{IO (XYZ/OFF Formats)} - \link PkgPointSetProcessing3IOOff OFF I/O Functions (`read_OFF()` and `write_OFF()`)\endlink @@ -82,10 +90,10 @@ format. \cgalCRPSection{IO (PLY Format)} -- `CGAL::read_ply_points()` -- `CGAL::read_ply_points_with_properties()` -- `CGAL::write_ply_points()` -- `CGAL::write_ply_points_with_properties()` +- \link PkgPointSetProcessing3IOPly `CGAL::read_PLY()` \endlink +- `CGAL::read_PLY_with_properties()` +- \link PkgPointSetProcessing3IOPly `CGAL::write_PLY()` \endlink +- `CGAL::write_PLY_with_properties()` - `CGAL::PLY_property` - `CGAL::make_ply_point_reader()` - `CGAL::make_ply_point_writer()` @@ -94,16 +102,12 @@ format. \cgalCRPSection{IO (LAS Format)} -- `CGAL::read_las_points()` -- `CGAL::read_las_points_with_properties()` -- `CGAL::write_las_points()` -- `CGAL::write_las_points_with_properties()` +- `CGAL::read_LAS()` +- `CGAL::read_LAS_with_properties()` +- `CGAL::write_LAS()` +- `CGAL::write_LAS_with_properties()` - `CGAL::make_las_point_reader()` - `CGAL::make_las_point_writer()` -\cgalCRPSection{IO (All Formats)} - -- `CGAL::read_points()` -- `CGAL::write_points()` */ diff --git a/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt b/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt index 57a7ddca2d9..6a46d5be3b2 100644 --- a/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt +++ b/Point_set_processing_3/doc/Point_set_processing_3/Point_set_processing_3.txt @@ -160,14 +160,16 @@ not handle normals and requires the \ref thirdpartyLASlib library. The following functions are available: -- `read_xyz_points()` -- `read_off_points()` -- `read_ply_points()` -- `read_las_points()` -- `write_xyz_points()` -- `write_off_points()` -- `write_ply_points()` -- `write_las_points()` +- `read_points()` +- `read_XYZ()` +- `read_OFF()` +- `read_PLY()` +- `read_LAS()` +- `write_points()` +- `write_XYZ()` +- `write_OFF()` +- `write_PLY()` +- `write_LAS()` All of these functions (with the exception of the LAS format) can read and write either points alone or points with normals (depending on @@ -196,8 +198,8 @@ any structure the user needs. Handling of %LAS files works similarly with the difference that the property names and types are fixed and defined by the %LAS standard. -Functions `read_ply_points_with_properties()` and -`read_las_points_with_properties()` allow the user to read any +Functions `read_PLY_with_properties()` and +`read_LAS_with_properties()` allow the user to read any property needed. The user must provide a set of property handlers that are used to instantiate number types and complex objects from %PLY/%LAS properties. This handlers are either: @@ -223,7 +225,7 @@ object, users need to provide an overload of `CGAL::Output_rep`. \subsubsection Point_set_processing_3Example_ply_read PLY Reading Example The following example shows how to call -`read_ply_points_with_properties()` to read a point set with points, +`read_PLY_with_properties()` to read a point set with points, normals, RGB colors and intensity and stores these attributes in a user-defined container. @@ -232,7 +234,7 @@ user-defined container. \subsubsection Point_set_processing_3Example_las_read LAS Reading Example The following example shows how to call -`read_las_points_with_properties()` to read a point set with points +`read_LAS_with_properties()` to read a point set with points and RGBI colors and stores these attributes in a user-defined container. diff --git a/Point_set_processing_3/examples/Point_set_processing_3/bilateral_smooth_point_set_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/bilateral_smooth_point_set_example.cpp index 5b3d492110b..8ce0079d9e3 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/bilateral_smooth_point_set_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/bilateral_smooth_point_set_example.cpp @@ -1,8 +1,9 @@ #include -#include -#include -#include + #include +#include +#include +#include #include #include // defines std::pair @@ -26,10 +27,9 @@ int main(int argc, char*argv[]) // Reads a .xyz point set file in points[] * with normals *. std::vector points; - if (!CGAL::read_points(input_filename, - std::back_inserter(points), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map()))) + if (!CGAL::read_points(input_filename, std::back_inserter(points), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map()))) { std::cerr << "Error: cannot read file " << input_filename << std::endl; return EXIT_FAILURE; @@ -56,11 +56,9 @@ int main(int argc, char*argv[]) //// Save point set. std::ofstream out(output_filename); out.precision(17); - if (!out || - !CGAL::write_XYZ( - out, points, - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map()))) + if (!out || !CGAL::write_XYZ(out, points, + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map()))) { return EXIT_FAILURE; } diff --git a/Point_set_processing_3/examples/Point_set_processing_3/edge_aware_upsample_point_set_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/edge_aware_upsample_point_set_example.cpp index ea3196cefa3..9ebee879767 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/edge_aware_upsample_point_set_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/edge_aware_upsample_point_set_example.cpp @@ -1,7 +1,8 @@ #include + #include #include -#include +#include #include #include diff --git a/Point_set_processing_3/examples/Point_set_processing_3/grid_simplify_indices.cpp b/Point_set_processing_3/examples/Point_set_processing_3/grid_simplify_indices.cpp index 8e98cf2495e..85581dd060a 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/grid_simplify_indices.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/grid_simplify_indices.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include diff --git a/Point_set_processing_3/examples/Point_set_processing_3/hierarchy_simplification_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/hierarchy_simplification_example.cpp index a491907df97..a751668be0b 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/hierarchy_simplification_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/hierarchy_simplification_example.cpp @@ -1,9 +1,10 @@ #include -#include + #include -#include -#include +#include +#include #include +#include #include #include diff --git a/Point_set_processing_3/examples/Point_set_processing_3/normal_estimation.cpp b/Point_set_processing_3/examples/Point_set_processing_3/normal_estimation.cpp index 05a93e3cf03..52980c2cfe7 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/normal_estimation.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/normal_estimation.cpp @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include // defines std::pair #include diff --git a/Point_set_processing_3/examples/Point_set_processing_3/read_las_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/read_las_example.cpp index 9c3d2706fe2..23bb19016cd 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/read_las_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/read_las_example.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/Point_set_processing_3/examples/Point_set_processing_3/read_ply_points_with_colors_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/read_ply_points_with_colors_example.cpp index e9d8eb3243f..212b54ceb62 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/read_ply_points_with_colors_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/read_ply_points_with_colors_example.cpp @@ -1,6 +1,6 @@ #include #include -#include +#include #include #include diff --git a/Point_set_processing_3/examples/Point_set_processing_3/scale_estimation_2d_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/scale_estimation_2d_example.cpp index ab36fe989d4..d024169ff25 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/scale_estimation_2d_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/scale_estimation_2d_example.cpp @@ -1,6 +1,5 @@ #include #include -#include #include #include diff --git a/Point_set_processing_3/test/Point_set_processing_3/analysis_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/analysis_test.cpp index 59006d4f9ee..5745b19fbb3 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/analysis_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/analysis_test.cpp @@ -15,7 +15,7 @@ // This package #include -#include +#include #include #include @@ -94,23 +94,18 @@ int main(int argc, char * argv[]) // Loads point set //*************************************** - // File name is: - std::string input_filename = argv[i]; - // Reads the point set file in points[]. std::deque points; - std::cerr << "Open " << input_filename << " for reading..." << std::endl; + std::cerr << "Open " << argv[i] << " for reading..." << std::endl; // If XYZ file format: - std::ifstream stream(input_filename.c_str()); - if(stream && - CGAL::read_XYZ(stream, std::back_inserter(points))) + if(CGAL::read_points(argv[i], std::back_inserter(points))) { std::cerr << "ok (" << points.size() << " points)" << std::endl; } else { - std::cerr << "Error: cannot read file " << input_filename << std::endl; + std::cerr << "Error: cannot read file " << argv[i] << std::endl; accumulated_fatal_err = EXIT_FAILURE; continue; } diff --git a/Point_set_processing_3/test/Point_set_processing_3/bilateral_smoothing_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/bilateral_smoothing_test.cpp index bd4cb7a0d54..45dad2baa51 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/bilateral_smoothing_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/bilateral_smoothing_test.cpp @@ -15,7 +15,7 @@ // This package #include -#include +#include #include #include @@ -103,26 +103,21 @@ int main(int argc, char * argv[]) // Loads point set //*************************************** - // File name is: - std::string input_filename = argv[i]; - // Reads the point set file in points[]. std::deque points; - std::cerr << "Opening " << input_filename << " for reading..." << std::endl; + std::cerr << "Opening " << argv[i] << " for reading..." << std::endl; // If XYZ file format: - std::ifstream stream(input_filename.c_str()); - if(stream && - CGAL::read_XYZ(stream, - std::back_inserter(points), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map()))) + if(CGAL::read_points(argv[i], + std::back_inserter(points), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map()))) { std::cerr << "ok (" << points.size() << " points)" << std::endl; } else { - std::cerr << "Error: cannot read file " << input_filename << std::endl; + std::cerr << "Error: cannot read file " << argv[i] << std::endl; accumulated_fatal_err = EXIT_FAILURE; continue; } diff --git a/Point_set_processing_3/test/Point_set_processing_3/edge_aware_upsample_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/edge_aware_upsample_test.cpp index 3a9f2d26eb2..c6279fbeb48 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/edge_aware_upsample_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/edge_aware_upsample_test.cpp @@ -14,7 +14,7 @@ // This package #include -#include +#include #include #include @@ -113,27 +113,21 @@ int main(int argc, char * argv[]) // Loads point set //*************************************** - // File name is: - std::string input_filename = argv[i]; - // Reads the point set file in points[]. std::vector points; - std::cerr << "Opening " << input_filename << " for reading..." << std::endl; + std::cerr << "Opening " << argv[i] << " for reading..." << std::endl; // If XYZ file format: - std::ifstream stream(input_filename.c_str()); - if(stream && - CGAL::read_XYZ - (stream, - std::back_inserter(points), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map()))) + if(CGAL::read_points(argv[i], + std::back_inserter(points), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map()))) { std::cerr << "ok (" << points.size() << " points)" << std::endl; } else { - std::cerr << "Error: cannot read file " << input_filename << std::endl; + std::cerr << "Error: cannot read file " << argv[i] << std::endl; accumulated_fatal_err = EXIT_FAILURE; continue; } diff --git a/Point_set_processing_3/test/Point_set_processing_3/normal_estimation_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/normal_estimation_test.cpp index 1fdfb543495..cd011c9b71f 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/normal_estimation_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/normal_estimation_test.cpp @@ -20,8 +20,7 @@ #include #include #include -#include -#include +#include #include #include @@ -322,12 +321,9 @@ int main(int argc, char * argv[]) extension == ".pwn" || extension == ".PWN") { std::ifstream stream(input_filename.c_str()); - success = stream && - CGAL::read_XYZ(stream, - std::back_inserter(points), - CGAL::parameters::normal_map - (CGAL::make_normal_of_point_with_normal_map(PointList::value_type())) - ); + success = stream && CGAL::read_XYZ(stream, + std::back_inserter(points), + CGAL::parameters::normal_map(CGAL::make_normal_of_point_with_normal_map(PointList::value_type()))); } if (success) { diff --git a/Point_set_processing_3/test/Point_set_processing_3/read_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/read_test.cpp index 4b1ca60797f..38425020f11 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/read_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/read_test.cpp @@ -1,8 +1,6 @@ #include #include -#include -#include -#include +#include #include @@ -18,51 +16,39 @@ typedef std::pair PointVectorPair; bool read(std::string s) { - std::ifstream fs(s.c_str()); std::vector pv_pairs; - return CGAL::read_XYZ(fs, - back_inserter(pv_pairs), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map())); + return CGAL::read_points(s, back_inserter(pv_pairs), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map())); } - - bool read(std::string s, std::vector& pv_pairs) { - std::ifstream fs(s.c_str()); - - return CGAL::read_XYZ(fs, - back_inserter(pv_pairs), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map())); + return CGAL::read_points(s, + back_inserter(pv_pairs), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map())); } bool read_off(std::string s, std::vector& pv_pairs) { - std::ifstream fs(s.c_str()); - - return CGAL::read_OFF(fs, + return CGAL::read_OFF(s, back_inserter(pv_pairs), CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). normal_map(CGAL::Second_of_pair_property_map())); } -bool read_ply (std::string s, - std::vector& pv_pairs) +bool read_ply(std::string s, + std::vector& pv_pairs) { - std::ifstream fs(s.c_str()); - - return CGAL::read_PLY (fs, - back_inserter(pv_pairs), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map())); + return CGAL::read_PLY(s, + back_inserter(pv_pairs), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). + normal_map(CGAL::Second_of_pair_property_map())); } - - int main() { std::cerr << "### There should be three errors following this line...\n"; diff --git a/Point_set_processing_3/test/Point_set_processing_3/read_test_with_different_pmaps.cpp b/Point_set_processing_3/test/Point_set_processing_3/read_test_with_different_pmaps.cpp index b486a67f77d..316e832db0d 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/read_test_with_different_pmaps.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/read_test_with_different_pmaps.cpp @@ -1,7 +1,6 @@ #include -#include -#include -#include + +#include #include #include diff --git a/Point_set_processing_3/test/Point_set_processing_3/remove_outliers_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/remove_outliers_test.cpp index 50e552d928b..227be719550 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/remove_outliers_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/remove_outliers_test.cpp @@ -15,7 +15,7 @@ // This package #include -#include +#include #include #include @@ -105,23 +105,18 @@ int main(int argc, char * argv[]) // Loads point set //*************************************** - // File name is: - std::string input_filename = argv[i]; - // Reads the point set file in points[]. std::deque points; - std::cerr << "Open " << input_filename << " for reading..." << std::endl; + std::cerr << "Open " << argv[i] << " for reading..." << std::endl; // If XYZ file format: - std::ifstream stream(input_filename.c_str()); - if(stream && - CGAL::read_XYZ(stream, std::back_inserter(points))) + if(CGAL::read_points(argv[i], std::back_inserter(points))) { std::cerr << "ok (" << points.size() << " points)" << std::endl; } else { - std::cerr << "Error: cannot read file " << input_filename << std::endl; + std::cerr << "Error: cannot read file " << argv[i] << std::endl; accumulated_fatal_err = EXIT_FAILURE; continue; } diff --git a/Point_set_processing_3/test/Point_set_processing_3/smoothing_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/smoothing_test.cpp index 33e3efc229f..30ba51e94ff 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/smoothing_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/smoothing_test.cpp @@ -15,7 +15,7 @@ // This package #include -#include +#include #include #include @@ -96,23 +96,18 @@ int main(int argc, char * argv[]) // Loads point set //*************************************** - // File name is: - std::string input_filename = argv[i]; - // Reads the point set file in points[]. std::deque points; - std::cerr << "Open " << input_filename << " for reading..." << std::endl; + std::cerr << "Open " << argv[i] << " for reading..." << std::endl; // If XYZ file format: - std::ifstream stream(input_filename.c_str()); - if(stream && - CGAL::read_XYZ(stream, std::back_inserter(points))) + if(CGAL::read_points(argv[i], std::back_inserter(points))) { std::cerr << "ok (" << points.size() << " points)" << std::endl; } else { - std::cerr << "Error: cannot read file " << input_filename << std::endl; + std::cerr << "Error: cannot read file " << argv[i] << std::endl; accumulated_fatal_err = EXIT_FAILURE; continue; } diff --git a/Point_set_processing_3/test/Point_set_processing_3/test_read_write_point_set.cpp b/Point_set_processing_3/test/Point_set_processing_3/test_read_write_point_set.cpp index d1f4514c014..b25f9807fcc 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/test_read_write_point_set.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/test_read_write_point_set.cpp @@ -1,89 +1,79 @@ +#include + +#include +#include +#include +#include // Just to try and create ambiguities + +#include + #include #include #include #include -#include -#include -#include -#include -#include - typedef CGAL::Simple_cartesian Kernel; typedef Kernel::Point_3 Point_3; typedef Kernel::Vector_3 Vector_3; +const double epsilon = 5e-4; - -const double epsilon=5e-4; template < typename Type > bool approx_equal_nt(const Type &t1, const Type &t2) { - if (t1 == t2) - return true; - if (CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) < std::abs(t1)*epsilon) - return true; + if(t1 == t2) + return true; + if(CGAL::abs(t1 - t2) / (CGAL::max)(CGAL::abs(t1), CGAL::abs(t2)) < std::abs(t1)*epsilon) + return true; - std::cout << " Approximate comparison failed between : " << t1 << " and " << t2 << std::endl; - std::cout<<"abs(t1 - t2) = "< PointVectorPair; bool ps_are_equal(const CGAL::Point_set_3& ps, const CGAL::Point_set_3& ps2) { if(ps.size() != ps2.size()) return false; + typedef CGAL::Point_set_3::const_iterator Iterator; - for(Iterator it1 = ps.begin(), it2 = ps2.begin(); - it1!=ps.end(), it2!=ps2.end(); ++it1, ++it2) + for(Iterator it1 = ps.begin(), it2 = ps2.begin(); it1!=ps.end() && it2!=ps2.end(); ++it1, ++it2) { - Point_3 p1 = ps.point(*it1); - Point_3 p2 = ps2.point(*it2); - if(!(approx_equal_nt(p1.x(), p2.x()) - && approx_equal_nt(p1.y(), p2.y()) - && approx_equal_nt(p1.z(), p2.z()))) - { + const Point_3& p1 = ps.point(*it1); + const Point_3& p2 = ps2.point(*it2); + if(!(approx_equal_nt(p1.x(), p2.x()) && approx_equal_nt(p1.y(), p2.y()) && approx_equal_nt(p1.z(), p2.z()))) return false; - } } return true; } - typedef std::pair PointVectorPair; bool points_are_equal(const std::vector& ps, - const std::vector& ps2) + const std::vector& ps2) { if(ps.size() != ps2.size()) return false; + typedef std::vector::const_iterator Iterator; - for(Iterator it1 = ps.begin(), it2 = ps2.begin(); - it1!=ps.end(), it2!=ps2.end(); ++it1, ++it2) + for(Iterator it1 = ps.begin(), it2 = ps2.begin(); it1!=ps.end() && it2!=ps2.end(); ++it1, ++it2) { - Point_3 p1 = *it1; - Point_3 p2 = *it2; - if(!(approx_equal_nt(p1.x(), p2.x()) - && approx_equal_nt(p1.y(), p2.y()) - && approx_equal_nt(p1.z(), p2.z()))) - { + const Point_3& p1 = *it1; + const Point_3& p2 = *it2; + if(!(approx_equal_nt(p1.x(), p2.x()) && approx_equal_nt(p1.y(), p2.y()) && approx_equal_nt(p1.z(), p2.z()))) return false; - } } return true; } - bool test_points_with_np(std::string s) { std::vector points; @@ -94,89 +84,133 @@ bool test_points_with_np(std::string s) points.push_back(std::make_pair(Point_3(1,1,1), Vector_3(1,1,1))); bool ok = CGAL::write_points(s, points, - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map())); + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map())); assert(ok); std::vector pv_pairs; - ok = CGAL::read_points(s, - std::back_inserter(pv_pairs), - CGAL::parameters::point_map(CGAL::First_of_pair_property_map()). - normal_map(CGAL::Second_of_pair_property_map())); + ok = CGAL::read_points(s, std::back_inserter(pv_pairs), + CGAL::parameters::point_map(CGAL::First_of_pair_property_map()) + .normal_map(CGAL::Second_of_pair_property_map())); assert(ok); assert(pv_pairs[0] == std::make_pair(Point_3(0,0,0), Vector_3(0,0,0))); assert(pv_pairs[1] == std::make_pair(Point_3(1,0,0), Vector_3(1,0,0))); assert(pv_pairs[2] == std::make_pair(Point_3(0,1,0), Vector_3(0,1,0))); assert(pv_pairs[3] == std::make_pair(Point_3(0,0,1), Vector_3(0,0,1))); assert(pv_pairs[4] == std::make_pair(Point_3(1,1,1), Vector_3(1,1,1))); + + return true; } +#define CGAL_DEF_TEST_POINT_SET_3_FUNCTION(TYPE, type) \ +void test_##TYPE(std::string s) \ +{ \ + CGAL::Point_set_3 ps; \ + bool ok = CGAL::read_##TYPE(s, ps); \ + assert(ok); \ + ps.clear(); \ + ok = CGAL::read_##TYPE(s.c_str(), ps); \ + assert(ok); \ + ps.clear(); \ + std::ifstream in(s); \ + ok = CGAL::read_##TYPE(in, ps); \ + assert(ok); \ + const char* ext = type; \ + std::string fname = "tmp."; \ + fname.append(ext); \ + ok = CGAL::write_##TYPE(fname, ps); \ + assert(ok); \ + ok = CGAL::write_##TYPE(fname, ps, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + ok = CGAL::write_##TYPE(fname.c_str(), ps); \ + assert(ok); \ + ok = CGAL::write_##TYPE(fname.c_str(), ps, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + std::ofstream out(fname); \ + ok = CGAL::write_##TYPE(out, ps); \ + assert(ok); \ + std::ofstream out2(fname); \ + ok = CGAL::write_##TYPE(out2, ps, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + CGAL::Point_set_3 ps2; \ + std::ifstream is(fname); \ + ok = CGAL::read_##TYPE(is, ps2); \ + assert(ok); \ + assert(ps_are_equal(ps, ps2)); \ + ok = CGAL::write_point_set(fname, ps2); \ + assert(ok); \ + ok = CGAL::write_point_set(fname, ps2, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + ok = CGAL::write_point_set(fname.c_str(), ps2); \ + assert(ok); \ + ok = CGAL::write_point_set(fname.c_str(), ps2, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + ps2.clear(); \ + ok = CGAL::read_point_set(fname, ps2); \ + assert(ok); \ + assert(ps_are_equal(ps, ps2)); \ + } -#define CGAL_DEF_TEST_PS_FUNCTION(TYPE, type)\ -void test_##TYPE(std::string s) \ -{ \ - CGAL::Point_set_3 ps; \ - bool ok = CGAL::read_##TYPE(s, ps); \ - assert(ok); \ - const char* ext= type; \ - std::string fname = "tmp."; \ - fname.append(ext); \ - ok = CGAL::write_##TYPE(fname, ps); \ - assert(ok); \ - CGAL::Point_set_3 ps2; \ - std::ifstream is(fname); \ - ok = CGAL::read_##TYPE(is, ps2); \ - assert(ok); \ - assert(ps_are_equal(ps, ps2)); \ - ok = CGAL::write_point_set(fname, ps2); \ - assert(ok); \ - ps2.clear(); \ - ok = CGAL::read_point_set(fname, ps2); \ - assert(ok); \ - assert(ps_are_equal(ps, ps2)); \ -} - -CGAL_DEF_TEST_PS_FUNCTION(XYZ, "xyz") -CGAL_DEF_TEST_PS_FUNCTION(OFF,"off") -CGAL_DEF_TEST_PS_FUNCTION(PLY,"ply") +CGAL_DEF_TEST_POINT_SET_3_FUNCTION(XYZ, "xyz") +CGAL_DEF_TEST_POINT_SET_3_FUNCTION(OFF, "off") +CGAL_DEF_TEST_POINT_SET_3_FUNCTION(PLY, "ply") #ifdef CGAL_LINKED_WITH_LASLIB -CGAL_DEF_TEST_PS_FUNCTION(LAS,"las") +CGAL_DEF_TEST_POINT_SET_3_FUNCTION(LAS, "las") #endif + #undef CGAL_DEF_INITIALIZE_ID_FUCNTION -#define CGAL_DEF_TEST_POINTS_FUNCTION(TYPE, type) \ -void test_points_##TYPE(std::string s) \ -{ \ - std::vector ps; \ - bool ok = CGAL::read_##TYPE(s, std::back_inserter(ps)); \ - assert(ok); \ - const char* ext= type; \ - std::string fname = "tmp."; \ - fname.append(ext); \ - ok = CGAL::write_##TYPE(fname, ps); \ - assert(ok); \ - std::vector ps2; \ - std::ifstream is(fname); \ - ok = CGAL::read_##TYPE(is, std::back_inserter(ps2)); \ - assert(ok); \ - assert(points_are_equal(ps, ps2)); \ - ok = CGAL::write_points(fname, ps2); \ - assert(ok); \ - ps2.clear(); \ - ok = CGAL::read_points(fname, std::back_inserter(ps2)); \ - assert(ok); \ - assert(points_are_equal(ps, ps2)); \ -} +#define CGAL_DEF_TEST_POINTS_FUNCTION(TYPE, type) \ +void test_points_##TYPE(std::string s) \ +{ \ + std::vector ps; \ + bool ok = CGAL::read_##TYPE(s, std::back_inserter(ps)); \ + assert(ok); \ + ps.clear(); \ + ok = CGAL::read_##TYPE(s.c_str(), std::back_inserter(ps)); \ + assert(ok); \ + ps.clear(); \ + std::ifstream in(s); \ + ok = CGAL::read_##TYPE(in, std::back_inserter(ps)); \ + assert(ok); \ + const char* ext = type; \ + std::string fname = "tmp."; \ + fname.append(ext); \ + ok = CGAL::write_##TYPE(fname, ps); \ + assert(ok); \ + ok = CGAL::write_##TYPE(fname, ps, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + ok = CGAL::write_##TYPE(fname.c_str(), ps); \ + assert(ok); \ + ok = CGAL::write_##TYPE(fname.c_str(), ps, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + std::ofstream out(fname); \ + ok = CGAL::write_##TYPE(out, ps); \ + assert(ok); \ + std::ofstream out2(fname); \ + ok = CGAL::write_##TYPE(out2, ps, CGAL::parameters::stream_precision(10)); \ + assert(ok); \ + std::vector ps2; \ + std::ifstream is(fname); \ + ok = CGAL::read_##TYPE(is, std::back_inserter(ps2)); \ + assert(ok); \ + assert(points_are_equal(ps, ps2)); \ + ok = CGAL::write_points(fname, ps2); \ + assert(ok); \ + ps2.clear(); \ + ok = CGAL::read_points(fname, std::back_inserter(ps2)); \ + assert(ok); \ + assert(points_are_equal(ps, ps2)); \ + } CGAL_DEF_TEST_POINTS_FUNCTION(XYZ, "xyz") -CGAL_DEF_TEST_POINTS_FUNCTION(OFF,"off") -CGAL_DEF_TEST_POINTS_FUNCTION(PLY,"ply") +CGAL_DEF_TEST_POINTS_FUNCTION(OFF, "off") +CGAL_DEF_TEST_POINTS_FUNCTION(PLY, "ply") #ifdef CGAL_LINKED_WITH_LASLIB -CGAL_DEF_TEST_POINTS_FUNCTION(LAS,"las") +CGAL_DEF_TEST_POINTS_FUNCTION(LAS, "las") #endif + #undef CGAL_DEF_INITIALIZE_ID_FUCNTION - - int main() { test_XYZ("data/read_test/ok_2.xyz"); @@ -189,16 +223,15 @@ int main() test_points_PLY("data/read_test/simple_ascii.ply"); test_points_PLY("data/read_test/simple.ply"); - - #ifdef CGAL_LINKED_WITH_LASLIB +#ifdef CGAL_LINKED_WITH_LASLIB test_LAS("data/read_test/pig_points.las"); test_points_LAS("data/read_test/pig_points.las"); - #endif +#endif test_points_with_np("test.xyz"); test_points_with_np("test.off"); test_points_with_np("test.ply"); + // don't test normals with LAS as it is not supported by the format - //don't test normals with LAS as it is not supported by the format - return 0; + return EXIT_SUCCESS; } diff --git a/Point_set_processing_3/test/Point_set_processing_3/vcm_all_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/vcm_all_test.cpp index 931f4587bbd..f5dea30dbfb 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/vcm_all_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/vcm_all_test.cpp @@ -1,7 +1,8 @@ #include + #include #include -#include +#include #include @@ -25,17 +26,16 @@ std::cout << "=== test_fandisk ===\n"; Covariance expected; int index; - // Reads a .xyz point set file in points[]. + // Reads a point set file in points[]. std::vector points; std::vector cov; boost::dynamic_bitset on_feature_edge(nb_points); points.reserve(nb_points); cov.reserve(nb_points); - std::ifstream stream("data/fandisk.off"); - if (!stream || - !CGAL::read_OFF(stream, - std::back_inserter(points), - CGAL::parameters::point_map(pmap))) + + if(CGAL::read_points("data/fandisk.off", + std::back_inserter(points), + CGAL::parameters::point_map(pmap))) { std::cerr << "Error: cannot read file data/fandisk.off" << std::endl; return false; diff --git a/Point_set_processing_3/test/Point_set_processing_3/wlop_simplify_and_regularize_test.cpp b/Point_set_processing_3/test/Point_set_processing_3/wlop_simplify_and_regularize_test.cpp index 064da66fe7c..5b5611ed0eb 100644 --- a/Point_set_processing_3/test/Point_set_processing_3/wlop_simplify_and_regularize_test.cpp +++ b/Point_set_processing_3/test/Point_set_processing_3/wlop_simplify_and_regularize_test.cpp @@ -15,7 +15,7 @@ // This package #include -#include +#include #include #include @@ -117,23 +117,18 @@ int main(int argc, char * argv[]) // Loads point set //*************************************** - // File name is: - std::string input_filename = argv[i]; - // Reads the point set file in points[]. std::vector points; - std::cerr << "Opening " << input_filename << " for reading..." << std::endl; + std::cerr << "Opening " << argv[i] << " for reading..." << std::endl; // If XYZ file format: - std::ifstream stream(input_filename.c_str()); - if(stream && - CGAL::read_XYZ(stream, std::back_inserter(points))) + if(CGAL::read_points(argv[i], std::back_inserter(points))) { std::cerr << "ok (" << points.size() << " points)" << std::endl; } else { - std::cerr << "Error: cannot read file " << input_filename << std::endl; + std::cerr << "Error: cannot read file " << argv[i] << std::endl; accumulated_fatal_err = EXIT_FAILURE; continue; } diff --git a/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_model_complexty_control.cpp b/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_model_complexty_control.cpp index 09953e4f292..16097f674e0 100644 --- a/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_model_complexty_control.cpp +++ b/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_model_complexty_control.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_user_provided_planes.cpp b/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_user_provided_planes.cpp index 3a77feeba8f..584799e034f 100644 --- a/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_user_provided_planes.cpp +++ b/Polygonal_surface_reconstruction/examples/Polygonal_surface_reconstruction/polyfit_example_user_provided_planes.cpp @@ -1,5 +1,5 @@ #include -#include +#include #include #include #include diff --git a/Polygonal_surface_reconstruction/test/Polygonal_surface_reconstruction/polygonal_surface_reconstruction_test_framework.h b/Polygonal_surface_reconstruction/test/Polygonal_surface_reconstruction/polygonal_surface_reconstruction_test_framework.h index b1e7476bc6b..01021729f87 100644 --- a/Polygonal_surface_reconstruction/test/Polygonal_surface_reconstruction/polygonal_surface_reconstruction_test_framework.h +++ b/Polygonal_surface_reconstruction/test/Polygonal_surface_reconstruction/polygonal_surface_reconstruction_test_framework.h @@ -1,8 +1,7 @@ #ifndef POLYFIT_TEST_FRAMEWORK_H_ #define POLYFIT_TEST_FRAMEWORK_H_ -#include -#include +#include #include #include #include diff --git a/STL_Extension/include/CGAL/is_iterator.h b/STL_Extension/include/CGAL/is_iterator.h index 28d3ca2b80b..1e563aaf781 100644 --- a/STL_Extension/include/CGAL/is_iterator.h +++ b/STL_Extension/include/CGAL/is_iterator.h @@ -26,6 +26,7 @@ namespace CGAL { namespace internal { + BOOST_MPL_HAS_XXX_TRAIT_DEF(iterator_category) BOOST_MPL_HAS_XXX_TRAIT_DEF(value_type) BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type) diff --git a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space.cpp b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space.cpp index 39a4b9e9639..e91f6f8787a 100644 --- a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space.cpp +++ b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space.cpp @@ -1,21 +1,18 @@ +#include + +#include +#include +#include #include #include -#include - -#include - -#include -#include - typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; +typedef Kernel::Point_3 Point; -typedef CGAL::Scale_space_surface_reconstruction_3 Reconstruction; +typedef CGAL::Scale_space_surface_reconstruction_3 Reconstruction; -typedef Kernel::Point_3 Point; - -typedef Reconstruction::Facet_const_iterator Facet_iterator; +typedef Reconstruction::Facet_const_iterator Facet_iterator; int main(int argc, char** argv) { @@ -27,7 +24,7 @@ int main(int argc, char** argv) std::vector points; std::ifstream in(argv[1]); std::cerr << "Reading " << std::flush; - if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) { + if( !in || !CGAL::read_points( in, std::back_inserter( points ) ) ) { std::cerr << "Error: cannot read file" << std::endl; return EXIT_FAILURE; } diff --git a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_advancing_front.cpp b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_advancing_front.cpp index 7d6060dd02a..4d8438ee965 100644 --- a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_advancing_front.cpp +++ b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_advancing_front.cpp @@ -1,18 +1,15 @@ - -#include -#include - #include #include -#include #include #include #include -#include #include +#include +#include + typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Scale_space_surface_reconstruction_3 Reconstruction; diff --git a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_incremental.cpp b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_incremental.cpp index 2016a522032..964eb5ae1a0 100644 --- a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_incremental.cpp +++ b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_incremental.cpp @@ -1,10 +1,10 @@ -#include -#include -#include - #include #include -#include +#include + +#include +#include +#include typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; @@ -30,19 +30,23 @@ void dump_reconstruction(const Reconstruction& reconstruct, std::string name) output << "3 " << *it << std::endl; } -int main(int argc, char* argv[]) { +int main(int argc, char* argv[]) +{ // Read the data. std::vector points; if (argc!=2){ std::cerr << "Error, no input file provided\n"; return 1; } + std::ifstream in(argv[1]); std::cout << "Reading " << std::flush; - if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) { - std::cerr << "Error: cannot read file" << std::endl; - return EXIT_FAILURE; + if( !in || !CGAL::read_points(in, std::back_inserter(points))) + { + std::cerr << "Error: cannot read file" << std::endl; + return EXIT_FAILURE; } + std::cout << "done: " << points.size() << " points." << std::endl; // Construct the reconstruction diff --git a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_manifold.cpp b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_manifold.cpp index e050a133ce6..0a1f223af6f 100644 --- a/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_manifold.cpp +++ b/Scale_space_reconstruction_3/examples/Scale_space_reconstruction_3/scale_space_manifold.cpp @@ -1,14 +1,13 @@ - -#include -#include +#include #include -#include - -#include +#include #include +#include +#include + typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel; typedef CGAL::Scale_space_surface_reconstruction_3< Kernel > Reconstruction; @@ -21,39 +20,44 @@ typedef Reconstruction::Facet_const_iterator Facet_iterator; typedef Mesher::Facet_const_iterator Mesher_iterator; typedef CGAL::Timer Timer; -int main(int argc, char* argv[]) { - if (argc!=2){ +int main(int argc, char* argv[]) +{ + if(argc != 2) + { std::cerr << "Error, no input file provided\n"; return 1; } + // Read the data. std::vector points; std::ifstream in(argv[1]); std::cerr << "Reading " << std::flush; - if( !in || !CGAL::read_off_points( in, std::back_inserter( points ) ) ) { + if(!in || !CGAL::read_points(in, std::back_inserter(points))) + { std::cerr << "Error: cannot read file" << std::endl; return EXIT_FAILURE; } + std::cerr << "done: " << points.size() << " points." << std::endl; Timer t; t.start(); // Construct the mesh in a scale space. - Reconstruction reconstruct( points.begin(), points.end() ); - Smoother smoother( 10, 200 ); - reconstruct.increase_scale (4, smoother); + Reconstruction reconstruct(points.begin(), points.end() ); + Smoother smoother(10, 200 ); + reconstruct.increase_scale(4, smoother); - Mesher mesher( smoother.squared_radius(), - false, // Do not separate shells - true // Force manifold output + Mesher mesher(smoother.squared_radius(), + false, // Do not separate shells + true // Force manifold output ); - reconstruct.reconstruct_surface( mesher ); + reconstruct.reconstruct_surface(mesher); std::cerr << "Reconstruction done in " << t.time() << " sec." << std::endl; t.reset(); - std::ofstream out ("out.off"); + std::ofstream out("out.off"); // Write the reconstruction. - for( Facet_iterator it = reconstruct.facets_begin( ); it != reconstruct.facets_end( ); ++it ) + for(Facet_iterator it = reconstruct.facets_begin(); it != reconstruct.facets_end(); ++it ) out << "3 "<< *it << '\n'; // We write a '3' in front so that it can be assembled into an OFF file std::cerr << "Writing result in " << t.time() << " sec." << std::endl; @@ -61,14 +65,13 @@ int main(int argc, char* argv[]) { out.close(); t.reset(); - std::ofstream garbage ("garbage.off"); + std::ofstream garbage("garbage.off"); // Write facets that were removed to force manifold output - for( Mesher_iterator it = mesher.garbage_begin( ); it != mesher.garbage_end( ); ++it ) + for(Mesher_iterator it = mesher.garbage_begin(); it != mesher.garbage_end(); ++it ) garbage << "3 "<< *it << '\n'; // We write a '3' in front so that it can be assembled into an OFF file std::cerr << "Writing garbage facets in " << t.time() << " sec." << std::endl; - garbage.close (); - std::cerr << "Done." << std::endl; + return EXIT_SUCCESS; } diff --git a/Shape_detection/examples/Shape_detection/shape_detection_basic_deprecated.cpp b/Shape_detection/examples/Shape_detection/shape_detection_basic_deprecated.cpp index db53ce3c8de..531709d4ec5 100644 --- a/Shape_detection/examples/Shape_detection/shape_detection_basic_deprecated.cpp +++ b/Shape_detection/examples/Shape_detection/shape_detection_basic_deprecated.cpp @@ -38,7 +38,7 @@ int run(const char* filename) { Pwn_vector points; // Load a point set from a file. - // read_XYZ takes an OutputIterator for storing the points + // read_points takes an OutputIterator for storing the points // and a property map to store the normal vector with each point. if (!CGAL::read_points(filename, diff --git a/Shape_detection/test/Shape_detection/test_efficient_RANSAC_scene.cpp b/Shape_detection/test/Shape_detection/test_efficient_RANSAC_scene.cpp index c1c44406ba8..42a7a9c9bd5 100644 --- a/Shape_detection/test/Shape_detection/test_efficient_RANSAC_scene.cpp +++ b/Shape_detection/test/Shape_detection/test_efficient_RANSAC_scene.cpp @@ -1,7 +1,7 @@ #include "include/test_efficient_RANSAC_generators.h" #include -#include +#include #include #include @@ -31,15 +31,14 @@ bool test_scene(int argc, char** argv) { Pwn_vector points; // Load point set from a file. - // read_xyz_points_and_normals takes an OutputIterator for storing the points + // read_points takes an OutputIterator for storing the points // and a property map to store the normal vector with each point. std::ifstream stream((argc > 1) ? argv[1] : "data/cube.pwn"); - if (!stream || - !CGAL::read_XYZ(stream, - std::back_inserter(points), - CGAL::parameters::point_map(Point_map()). - normal_map(Normal_map()))) + if (!stream || !CGAL::read_points(stream, + std::back_inserter(points), + CGAL::parameters::point_map(Point_map()) + .normal_map(Normal_map()))) { std::cerr << "Error: cannot read file cube.pwn" << std::endl; return EXIT_FAILURE; diff --git a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt index 1b583340d86..8d7bc2b535a 100644 --- a/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt +++ b/Stream_support/doc/Stream_support/File_formats/Supported_file_formats.txt @@ -120,7 +120,7 @@ is .pwn for points with normals.) \subsection IOStreamZYZInput Reading XYZ files Objects represented in the `.XYZ` or `.PWN` format can be imported into \cgal's working environment -using the CGAL::Point_set_3 and the function read_xyz_point_set(). +using the `CGAL::Point_set_3` and the function `CGAL::read_point_set()`. \subsection IOStreamXYZOutput Writing XYZ files The CGAL::Point_set_3 can be exported into a `XYZ` or a `PWN` file using the function diff --git a/Stream_support/doc/Stream_support/IOstream.txt b/Stream_support/doc/Stream_support/IOstream.txt index ac0e821363f..c54bb305f99 100644 --- a/Stream_support/doc/Stream_support/IOstream.txt +++ b/Stream_support/doc/Stream_support/IOstream.txt @@ -10,26 +10,262 @@ namespace CGAL { \section IOstreamIntro Introduction -CGAL algorithms and data structures are usually part of a pipeline of algorithms. -Everything is not entirely self-contained. -Need a way to import and export data to known file formats. -Can in addition enhance the existing stream system coming with the STL. +An algorithm is the application of a serie of steps to convert some input data into output data. +As such, it is necessary to have a way to input and output external data into \cgal data structures. +This is achieved using input-output (IO) streams of data, which enables reading and writing +to and from files, the console, or other custom structures. -We first explain which file formats are supported for various types of structures in CGAL. -Then we explain how to customize your stream to read and write objects that do not necessarily already -have an existing overload. +\subsection PMPOutline Outline -Supported file formats are listed on the \link IOStreamSupportedFileFormats following page\endlink. +- \ref IOstreamIO : the most essential data structures of \cgal, its kernel objects, all provide + adapted input and output operators. In addition, \cgal provides tools to enhance + the existing stream system of the STL to easily read and write classes external to \cgal. +- \ref IOstreamSupportedFormats : a number of traditional data structures such as point sets or + polygon meshes have well-established standards specifying + a particular data format to facilitate data exchanges. Formats + supported for \cgal data structures are detailed in this section. + The page \ref IOStreamSupportedFileFormats offers the reversed viewpoint + (file format to \cgal data structure). -\section IOstreamSupportedFormats Importing and Exporting Data +\section IOstreamIO Reading and Writing Data With Streams -CGAL algorithms work on different types of data structures, such as \ref Chapter_Point_Set_3 "point sets", - \ref PolygonSoups "polygon soups", or \ref PMPDef "polygon meshes". +All classes in the \cgal kernel provide input and output operators for +%IO streams. Classes external to \cgal are also supported, by means of `oformat()` +(Section \ref seciofornoncgaltypes "IO for Non CGAL Types"). +The basic task of such an operator is to produce a +representation of an object that can be written as a sequence of +characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii, +a raw binary, and a pretty printing format. + +\code{.cpp} +enum Mode {ASCII = 0, BINARY, PRETTY}; +\endcode + +In `ASCII` mode, objects are written as +a set of numbers, e.g. the coordinates of a point or +the coefficients of a line, in a machine independent format. +In `BINARY` mode, +data are written in a binary format, e.g. a double is represented +as a sequence of four byte. The format depends on the machine. +The mode `PRETTY` +serves mainly for debugging as the type of the geometric +object is written, as well as the data defining the object. For example +for a point at the origin with Cartesian double coordinates, the output +would be `PointC2(0.0, 0.0)`. At the moment \cgal does not +provide input operations for pretty printed data. By default a stream +is in Ascii mode. + +\cgal provides the following functions to modify the mode of an IO stream. + +\code{.cpp} +IO::Mode set_mode(std::ios& s, IO::Mode m); +IO::Mode set_ascii_mode(std::ios& s); +IO::Mode set_binary_mode(std::ios& s); +IO::Mode set_pretty_mode(std::ios& s); +\endcode + +The following functions enable testing whether a stream is in a certain mode: +\code{.cpp} +IO::Mode get_mode(std::ios& s); +bool is_ascii(std::ios& s); +bool is_binary(std::ios& s); +bool is_pretty(std::ios& s); +\endcode + +\subsection IOstreamInput Input Operator + +\cgal defines input operators for classes that are derived +from the class `istream`. This allows to read from istreams +as `std::cin`, as well as from `std::istringstream` and `std::ifstream`. +The input operator is defined for all classes in the \cgal `Kernel`. +Let `is` be an input stream. + +\code{.cpp} +// Extracts object `c` from the stream `is`. Returns `is`. +istream& operator>>(istream& is, Class c); +\endcode + +\code{.cpp} +#include +#include + +#include +#include + +typedef CGAL::Point_2< CGAL::Cartesian > Point; +typedef CGAL::Segment_2< CGAL::Cartesian > Segment; + +int +main() +{ + Point p, q; + Segment s; + + CGAL::set_ascii_mode(std::cin); + std::cin >> p >> q; + + std::ifstream f("data.txt"); + CGAL::set_binary_mode(f); + f >> s >> p; + + return 1; +} +\endcode + +\subsection IOstreamOutput Output Operator + +\cgal defines output operators for classes that are derived +from the class `ostream`. This allows to write to ostreams +as `std::cout` or `std::cerr`, as well as to `std::ostringstream` +and `std::ofstream`. +The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` (see +Section \ref IOstreamColors) as well. +Let `os` be an output stream. + +\code{.cpp} +// Inserts object `c` in the stream `os`. Returns `os`. +ostream& operator<<(ostream& os, Class c); +\endcode + +\code{.cpp} +#include +#include + +#include +#include + +typedef CGAL::Point_2< CGAL::Cartesian > Point; +typedef CGAL::Segment_2< CGAL::Cartesian > Segment; + +int main() +{ + Point p(0,1), q(2,2); + Segment s(p,q); + + CGAL::set_pretty_mode(std::cout); + std::cout << p << std::endl << q << std::endl; + + std::ofstream f("data.txt"); + CGAL::set_binary_mode(f); + f << s << p ; + + return 1; +} +\endcode + +\subsection seciofornoncgaltypes IO for Non-CGAL Types + +\subsubsection IOstreamUsingOutputFormatting Using Output Formatting + +To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used. +For types with a `Output_rep` specialization, the respective output routine of `Output_rep` +will be called by `oformat()`. Otherwise, the stream output operator will be called. + +\code{.cpp} +std::cout << CGAL::oformat( myobject ); +\endcode + +Optionally, you can provide a second template parameter `F` as a formatting tag: +\code{.cpp} +std::cout << CGAL::oformat( myobject, My_formatting_tag() ); +\endcode + +For a list of formatting tags supported by the type `T`, please +refer to the documentation of the respective type. + +\subsubsection IOstreamCustomizingOutputFormatting Customizing Output Formatting + +In some situations, you want to control the output formatting for a +type `T`. For external types (third party libraries etc.), +there might be problems if their stream output operator does not +respect `IO::Mode`. The purpose of `Output_rep` is to provide a way to +control output formatting that works independently of the object's +stream output operator. + +Instead of putting `T` directly into an output stream, +`T` is wrapped into an output representation `Output_rep`. For +convenience, a function `oformat()` exists, which constructs an instance +of `Output_rep`. + +If you do not specialize `Output_rep` for `T`, `T`'s +stream output operator is called from within `Output_rep`, by +default. If you want another behaviour for your type `T`, you +have to provide a specialization for that type. Furthermore, you can +provide specializations with a second template parameter (a formatting +tag). The second template parameter defaults to `Null_tag` and means +default behaviour. + +For example, specializing `Output_rep` for `CORE::BigRat` (without a +formatting tag parameter) could look like this: + +\code{.cpp} +template +class Output_rep< ::CORE::BigRat, F> { + const ::CORE::BigRat& t; +public: + Output_rep( const ::CORE::BigRat& tt) : t(tt) {} + + std::ostream& operator()( std::ostream& out) const { + switch (get_mode(out)) { + case IO::PRETTY:{ + if(CGAL_CORE_DENOMINATOR(t) == ::CORE::BigRat(1)) + return out <rgb-value of the color. +There are a 11 predefined `Color` constants available: +`BLACK`, `WHITE`, `GRAY`, `RED`, `GREEN`, +`DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`, +and `YELLOW`. + +\subsection IOstreamStream Stream Support + +Three classes are provided by \cgal as adaptors to input and output stream +iterators. The class `Istream_iterator` is an input iterator adaptor and +is particularly useful for classes that are similar but not compatible to +`std::istream`. Similarly, the class `Ostream_iterator` is an output +iterator adaptor. The class `Verbose_ostream` can be used as an output +stream. The stream +output operator `<<` is defined for any type. The class +stores in an internal state a stream and whether the +output is active or not. If the state is active, the stream output +operator `<<` uses the internal stream to output its argument. If +the state is inactive, nothing happens. + +\section IOstreamSupportedFormats Importing and Exporting Data using Standard Formats + +Although there is a large number of different types of input data structures in \cgal algorithms, +some common data structures such as point sets or polygon meshes appear more often. These +traditional data structures have long been used and specific standards have been created +to facilite information exchange. In the following section, supported file formats are listed +for the most common data structures used in \cgal. A reverse viewpoint, listing the data structures +which can be used for a specific file format is available on \ref IOStreamSupportedFileFormats. \subsection IOstreamPointSetIO Point Set IO -The CGAL::Point_set_3 is a vector based data structure that contains -a default property (named point) for the coordinates of the points, -and is able to work with dynamic properties. +The class `CGAL::Point_set_3` is the data structure used in \cgal to represent point sets. +It is a vector-based data structure that contains a default property (named point) +for the coordinates of the points, and is able to work with dynamic properties. +The file formats supported for `CGAL::Point_set_3` are detailed in the table below. @@ -96,7 +332,7 @@ their indices per face (i.e a vector of 3 integers represent a triangle face). \subsection IOstreamPolygonMeshIO Polygon Mesh IO A Polygon Mesh is a 3D structure that refines the concept of `FaceGraph` -with some other restrictions. A more precise definition can be found \ref PMPDef "here". +with some additional restrictions; a more precise definition can be found \ref PMPDef "here".
@@ -212,231 +448,6 @@ which might look as follows: \cgalExample{Stream_support/read_xml.cpp} -\section IOstreamIO IO Streams - -All classes in the \cgal kernel provide input and output operators for -%IO streams. Classes external to \cgal are also supported, by means of `oformat()` -(Section \ref seciofornoncgaltypes "IO for Non CGAL Types"). -The basic task of such an operator is to produce a -representation of an object that can be written as a sequence of -characters on devices as a console, a file, or a pipe. In \cgal we distinguish between a raw ascii, -a raw binary, and a pretty printing format. - -\code{.cpp} -enum Mode {ASCII = 0, BINARY, PRETTY}; -\endcode - -In `ASCII` mode, objects are written as -a set of numbers, e.g. the coordinates of a point or -the coefficients of a line, in a machine independent format. -In `BINARY` mode, -data are written in a binary format, e.g. a double is represented -as a sequence of four byte. The format depends on the machine. -The mode `PRETTY` -serves mainly for debugging as the type of the geometric -object is written, as well as the data defining the object. For example -for a point at the origin with Cartesian double coordinates, the output -would be `PointC2(0.0, 0.0)`. At the moment \cgal does not -provide input operations for pretty printed data. By default a stream -is in Ascii mode. - -\cgal provides the following functions to modify the mode of an IO stream. - -\code{.cpp} -IO::Mode set_mode(std::ios& s, IO::Mode m); -IO::Mode set_ascii_mode(std::ios& s); -IO::Mode set_binary_mode(std::ios& s); -IO::Mode set_pretty_mode(std::ios& s); -\endcode - -The following functions enable testing whether a stream is in a certain mode: -\code{.cpp} -IO::Mode get_mode(std::ios& s); -bool is_ascii(std::ios& s); -bool is_binary(std::ios& s); -bool is_pretty(std::ios& s); -\endcode - -\subsection IOstreamOutput Output Operator - -\cgal defines output operators for classes that are derived -from the class `ostream`. This allows to write to ostreams -as `std::cout` or `std::cerr`, as well as to `std::ostringstream` -and `std::ofstream`. -The output operator is defined for all classes in the \cgal `Kernel` and for the class `Color` (see -Section \ref IOstreamColors) as well. -Let `os` be an output stream. - -\code{.cpp} -// Inserts object `c` in the stream `os`. Returns `os`. -ostream& operator<<(ostream& os, Class c); -\endcode - -\code{.cpp} -#include -#include - -#include -#include - -typedef CGAL::Point_2< CGAL::Cartesian > Point; -typedef CGAL::Segment_2< CGAL::Cartesian > Segment; - -int main() -{ - Point p(0,1), q(2,2); - Segment s(p,q); - - CGAL::set_pretty_mode(std::cout); - std::cout << p << std::endl << q << std::endl; - - std::ofstream f("data.txt"); - CGAL::set_binary_mode(f); - f << s << p ; - - return 1; -} -\endcode - -\subsection IOstreamInput Input Operator - -\cgal defines input operators for classes that are derived -from the class `istream`. This allows to read from istreams -as `std::cin`, as well as from `std::istringstream` and `std::ifstream`. -The input operator is defined for all classes in the \cgal `Kernel`. -Let `is` be an input stream. - -\code{.cpp} -// Extracts object `c` from the stream `is`. Returns `is`. -istream& operator>>(istream& is, Class c); -\endcode - -\code{.cpp} -#include -#include - -#include -#include - -typedef CGAL::Point_2< CGAL::Cartesian > Point; -typedef CGAL::Segment_2< CGAL::Cartesian > Segment; - -int -main() -{ - Point p, q; - Segment s; - - CGAL::set_ascii_mode(std::cin); - std::cin >> p >> q; - - std::ifstream f("data.txt"); - CGAL::set_binary_mode(f); - f >> s >> p; - - return 1; -} -\endcode - -\subsection seciofornoncgaltypes IO for Non-CGAL Types - -\subsubsection IOstreamUsingOutputFormatting Using Output Formatting - -To ensure that non-\cgal types are formatted correctly (i.e., respecting `IO::Mode`), `oformat()` can be used. -For types with a `Output_rep` specialization, the respective output routine of `Output_rep` -will be called by `oformat()`. Otherwise, the stream output operator will be called. - -\code{.cpp} -std::cout << CGAL::oformat( myobject ); -\endcode - -Optionally, you can provide a second template parameter `F` as a formatting tag: -\code{.cpp} -std::cout << CGAL::oformat( myobject, My_formatting_tag() ); -\endcode - -For a list of formatting tags supported by the type `T`, please -refer to the documentation of the respective type. - -\subsubsection IOstreamCustomizingOutputFormatting Customizing Output Formatting - -In some situations, you want to control the output formatting for a -type `T`. For external types (third party libraries etc.), -there might be problems if their stream output operator does not -respect `IO::Mode`. The purpose of `Output_rep` is to provide a way to -control output formatting that works independently of the object's -stream output operator. - -Instead of putting `T` directly into an output stream, -`T` is wrapped into an output representation `Output_rep`. For -convenience, a function `oformat()` exists, which constructs an instance -of `Output_rep`. - -If you do not specialize `Output_rep` for `T`, `T`'s -stream output operator is called from within `Output_rep`, by -default. If you want another behaviour for your type `T`, you -have to provide a specialization for that type. Furthermore, you can -provide specializations with a second template parameter (a formatting -tag). The second template parameter defaults to `Null_tag` and means -default behaviour. - -For example, specializing `Output_rep` for `CORE::BigRat` (without a -formatting tag parameter) could look like this: - -\code{.cpp} -template -class Output_rep< ::CORE::BigRat, F> { - const ::CORE::BigRat& t; -public: - Output_rep( const ::CORE::BigRat& tt) : t(tt) {} - - std::ostream& operator()( std::ostream& out) const { - switch (get_mode(out)) { - case IO::PRETTY:{ - if(CGAL_CORE_DENOMINATOR(t) == ::CORE::BigRat(1)) - return out <rgb-value of the color. -There are a 11 predefined `Color` constants available: -`BLACK`, `WHITE`, `GRAY`, `RED`, `GREEN`, -`DEEPBLUE`, `BLUE`, `PURPLE`, `VIOLET`, `ORANGE`, -and `YELLOW`. - -\subsection IOstreamStream Stream Support - -Three classes are provided by \cgal as adaptors to input and output stream -iterators. The class `Istream_iterator` is an input iterator adaptor and -is particularly useful for classes that are similar but not compatible to -`std::istream`. Similarly, the class `Ostream_iterator` is an output -iterator adaptor. The class `Verbose_ostream` can be used as an output -stream. The stream -output operator `<<` is defined for any type. The class -stores in an internal state a stream and whether the -output is active or not. If the state is active, the stream output -operator `<<` uses the internal stream to output its argument. If -the state is inactive, nothing happens. - */ } /* namespace CGAL */ diff --git a/Stream_support/doc/Stream_support/PackageDescription.txt b/Stream_support/doc/Stream_support/PackageDescription.txt index 877081cbb72..8b566245a13 100644 --- a/Stream_support/doc/Stream_support/PackageDescription.txt +++ b/Stream_support/doc/Stream_support/PackageDescription.txt @@ -67,8 +67,10 @@ the printing mode. - \link OffIoFuncs I/O for OFF files (`CGAL::write_OFF()`and `CGAL::read_OFF()`)\endlink - \link GocadIoFuncs I/O for GOCAD files (`CGAL::write_GOCAD()`and `CGAL::read_GOCAD()`)\endlink - \link VtpIoFuncs I/O for VTP files (`CGAL::write_VTP()`and `CGAL::read_VTP()`)\endlink + - `GCAL::read_polygon_soup()` - `GCAL::write_polygon_soup()` + - `GCAL::read_WKT()` - `CGAL::read_point_WKT()` - `GCAL::read_multi_point_WKT()` diff --git a/Stream_support/include/CGAL/IO/GOCAD.h b/Stream_support/include/CGAL/IO/GOCAD.h index 88bca343a33..c28d3710bf8 100644 --- a/Stream_support/include/CGAL/IO/GOCAD.h +++ b/Stream_support/include/CGAL/IO/GOCAD.h @@ -13,7 +13,7 @@ #ifndef CGAL_IO_GOCAD_H #define CGAL_IO_GOCAD_H -#include +#include #include #include diff --git a/Stream_support/include/CGAL/IO/OFF.h b/Stream_support/include/CGAL/IO/OFF.h index 441eb80f4e7..40e33def33d 100644 --- a/Stream_support/include/CGAL/IO/OFF.h +++ b/Stream_support/include/CGAL/IO/OFF.h @@ -13,7 +13,7 @@ #include #include -#include +#include #include #include diff --git a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h index 0ad97718546..5901b00ae42 100644 --- a/Stream_support/include/CGAL/IO/PLY/PLY_reader.h +++ b/Stream_support/include/CGAL/IO/PLY/PLY_reader.h @@ -202,7 +202,7 @@ public: template Type read(std::istream& stream) const { - if(m_format == 0) // Ascii + if(m_format == 0) // ASCII { Type t; read_ascii(stream, t); diff --git a/Stream_support/include/CGAL/IO/STL/STL_reader.h b/Stream_support/include/CGAL/IO/STL/STL_reader.h index fce76ca49dd..0449e2812e5 100644 --- a/Stream_support/include/CGAL/IO/STL/STL_reader.h +++ b/Stream_support/include/CGAL/IO/STL/STL_reader.h @@ -13,7 +13,7 @@ #define CGAL_IO_STL_STL_READER_H #include -#include +#include #include #include diff --git a/Stream_support/include/CGAL/IO/helpers.h b/Stream_support/include/CGAL/IO/helpers.h index 1e219135426..d5bb592d42f 100644 --- a/Stream_support/include/CGAL/IO/helpers.h +++ b/Stream_support/include/CGAL/IO/helpers.h @@ -8,20 +8,20 @@ // // Author(s) : Mael Rouxel-Labbé -#ifndef CGAL_IO_READER_HELPERS_H -#define CGAL_IO_READER_HELPERS_H +#ifndef CGAL_STREAM_SUPPORT_HELPERS_H +#define CGAL_STREAM_SUPPORT_HELPERS_H #include #include +#include #include #include +#include #include -#include -#include -#include +#include -namespace CGAL{ +namespace CGAL { namespace IO { namespace internal { @@ -42,8 +42,32 @@ void fill_point(const double x, const double y, const double z, const double w, pt[0] = x/w; pt[1] = y/w; pt[2] = z/w; } +// Functions like 'write_OFF' can take : +// - write_OFF(stream, point_set) +// - write_OFF(stream, pointrange) +// - write_OFF(stream, polygon_mesh) +// so a way to distinguish is needed +BOOST_MPL_HAS_XXX_TRAIT_DEF(Point_set) + +template +struct is_Point_set_3 : has_Point_set { }; + +// Point_set_3 also functions as range, so it needs to be excluded +template +struct is_Range + : public boost::mpl::and_< + boost::has_range_const_iterator, + boost::mpl::not_ > > +{ }; + +// For polygon meshes +template +struct is_Point_set_or_Range_or_Iterator + : public boost::mpl::or_, is_Range, is_iterator > +{ }; + } // end namespace internal } // end namespace IO } // namespace CGAL -#endif // CGAL_IO_READER_HELPERS_H +#endif // CGAL_STREAM_SUPPORT_HELPERS_H diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h index 32389792ffa..512f6035b76 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/OFF.h @@ -283,7 +283,7 @@ bool read_OFF_with_or_without_vnormals(std::istream& is, /// \relates Surface_mesh /// \ingroup PkgSurfaceMeshIOFunc /// -/// Extracts the surface mesh from an input stream in Ascii OFF, COFF, NOFF, CNOFF +/// Extracts the surface mesh from an input stream in ASCII OFF, COFF, NOFF, CNOFF /// format and appends it to the surface mesh `sm`. /// /// The operator reads the point property as well as "v:normal", "v:color", `"v:texcoord"`, and "f:color". diff --git a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h index d09c15fe00a..c84ea32d57b 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/IO/PLY.h @@ -902,7 +902,7 @@ bool write_PLY(std::ostream& os, return true; } -/// Extracts the surface mesh from an input stream in Ascii or +/// Extracts the surface mesh from an input stream in ASCII or /// Binary PLY format and appends it to the surface mesh `sm`. /// /// - the operator reads the vertex `point` property and the face