From e01f62a09fa416e1fe5a3f2b777129ff8baa0bec Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Tue, 13 Jun 2017 12:10:49 +0200 Subject: [PATCH] Use Output_rep to output colors --- .../write_ply_points_example.cpp | 30 ++++++++++--------- .../include/CGAL/IO/write_ply_points.h | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp b/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp index 1e6b724ac60..8b3f88aaf4b 100644 --- a/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp +++ b/Point_set_processing_3/examples/Point_set_processing_3/write_ply_points_example.cpp @@ -20,28 +20,30 @@ typedef CGAL::Nth_of_tuple_property_map<1, PCI> Color_map; typedef CGAL::Nth_of_tuple_property_map<2, PCI> Intensity_map; // Define how a color should be stored -namespace CGAL -{ - std::ostream& operator<< (std::ostream& stream, const CGAL::cpp11::array& c) - { - if (CGAL::get_mode(stream) == CGAL::IO::ASCII) - stream << int(c[0]) << " " << int(c[1]) << " " << int(c[2]) << " " << int(c[3]); - else if (CGAL::get_mode(stream) == CGAL::IO::BINARY) - stream.write(reinterpret_cast(&c), sizeof(c)); - else +namespace CGAL { + template< class F > + struct Output_rep< ::Color, F > { + const ::Color& c; + static const bool is_specialized = true; + Output_rep (const ::Color& c) : c(c) + { } + std::ostream& operator() (std::ostream& out) const { - std::cerr << "Error: mode pretty not handled." << std::endl; - abort(); + if (is_ascii(out)) + out << int(c[0]) << " " << int(c[1]) << " " << int(c[2]) << " " << int(c[3]); + else + CGAL::write(out, c); + return out; } - return stream; - } + }; } + int main(int, char**) { std::vector points; // store points - for (std::size_t i = 0; i < 10; ++ i) + for (int i = 0; i < 10; ++ i) points.push_back (CGAL::cpp11::make_tuple (Point (i / 10., i / 20., i / 30.), CGAL::make_array ((unsigned char)(255 / (i + 1)), (unsigned char)(192 / (i + 1)), diff --git a/Point_set_processing_3/include/CGAL/IO/write_ply_points.h b/Point_set_processing_3/include/CGAL/IO/write_ply_points.h index 2596e5287a1..91c53a80dec 100644 --- a/Point_set_processing_3/include/CGAL/IO/write_ply_points.h +++ b/Point_set_processing_3/include/CGAL/IO/write_ply_points.h @@ -169,7 +169,7 @@ namespace internal { typename PropertyMap> void property_write (std::ostream& stream, ForwardIterator it, PropertyMap map) { - stream << get (map, *it); + stream << CGAL::oformat(get (map, *it)); } template