Use Output_rep to output colors

This commit is contained in:
Simon Giraudot 2017-06-13 12:10:49 +02:00
parent 8d52a9259d
commit e01f62a09f
2 changed files with 17 additions and 15 deletions

View File

@ -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; typedef CGAL::Nth_of_tuple_property_map<2, PCI> Intensity_map;
// Define how a color should be stored // Define how a color should be stored
namespace CGAL namespace CGAL {
{ template< class F >
std::ostream& operator<< (std::ostream& stream, const CGAL::cpp11::array<unsigned char, 4>& c) struct Output_rep< ::Color, F > {
{ const ::Color& c;
if (CGAL::get_mode(stream) == CGAL::IO::ASCII) static const bool is_specialized = true;
stream << int(c[0]) << " " << int(c[1]) << " " << int(c[2]) << " " << int(c[3]); Output_rep (const ::Color& c) : c(c)
else if (CGAL::get_mode(stream) == CGAL::IO::BINARY) { }
stream.write(reinterpret_cast<const char*>(&c), sizeof(c)); std::ostream& operator() (std::ostream& out) const
else
{ {
std::cerr << "Error: mode pretty not handled." << std::endl; if (is_ascii(out))
abort(); 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**) int main(int, char**)
{ {
std::vector<PCI> points; // store points std::vector<PCI> 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.), points.push_back (CGAL::cpp11::make_tuple (Point (i / 10., i / 20., i / 30.),
CGAL::make_array ((unsigned char)(255 / (i + 1)), CGAL::make_array ((unsigned char)(255 / (i + 1)),
(unsigned char)(192 / (i + 1)), (unsigned char)(192 / (i + 1)),

View File

@ -169,7 +169,7 @@ namespace internal {
typename PropertyMap> typename PropertyMap>
void property_write (std::ostream& stream, ForwardIterator it, PropertyMap map) void property_write (std::ostream& stream, ForwardIterator it, PropertyMap map)
{ {
stream << get (map, *it); stream << CGAL::oformat(get (map, *it));
} }
template <typename ForwardIterator, template <typename ForwardIterator,