From 19169d9caeb9b08fd31f60e4fc833a75d75b0593 Mon Sep 17 00:00:00 2001 From: Simon Giraudot Date: Thu, 24 Jan 2019 14:46:39 +0100 Subject: [PATCH] Remove CGAL::Classification::RGB_Color and HSV_Color and just use CGAL::Color everywhere --- Classification/include/CGAL/Classification.h | 1 - .../include/CGAL/Classification/Color.h | 140 ------------------ .../Classification/Feature/Color_channel.h | 10 +- .../Classification/Mesh_feature_generator.h | 2 - .../Point_set_feature_generator.h | 8 +- .../test_classification_point_set.cpp | 10 +- .../Classification/Cluster_classification.cpp | 14 +- .../Classification/Cluster_classification.h | 6 +- .../Point_set_item_classification.cpp | 14 +- .../Point_set_item_classification.h | 6 +- 10 files changed, 33 insertions(+), 178 deletions(-) delete mode 100644 Classification/include/CGAL/Classification/Color.h diff --git a/Classification/include/CGAL/Classification.h b/Classification/include/CGAL/Classification.h index 6be192f22b8..fea4a0c044c 100644 --- a/Classification/include/CGAL/Classification.h +++ b/Classification/include/CGAL/Classification.h @@ -36,7 +36,6 @@ #endif #include -#include #include #include #include diff --git a/Classification/include/CGAL/Classification/Color.h b/Classification/include/CGAL/Classification/Color.h deleted file mode 100644 index 8b619b9c497..00000000000 --- a/Classification/include/CGAL/Classification/Color.h +++ /dev/null @@ -1,140 +0,0 @@ -// Copyright (c) 2017 GeometryFactory Sarl (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org). -// You can redistribute it and/or modify it under the terms of the GNU -// General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// SPDX-License-Identifier: GPL-3.0+ -// -// Author(s) : Simon Giraudot - -#ifndef CGAL_CLASSIFICATION_COLOR_H -#define CGAL_CLASSIFICATION_COLOR_H - -#include -#include -#include -#include - -namespace CGAL { -namespace Classification { - - /*! - \ingroup PkgClassificationColor - - %Color described in red/green/blue space. Each component is stored - as an unsigned char ranging from 0 (no color) to 255 (full color). - */ -typedef CGAL::cpp11::array RGB_Color; - /*! - \ingroup PkgClassificationColor - - %Color described in hue/saturation/value space. Each component is stored - as a float: - - - `hue` ranges from 0° to 360° (corresponding to the color tint) - - `saturation` ranges from 0.0 (gray) to 100.0 (full saturation) - - `value` ranges from 0.0 (black) to 100.0 (white) - */ -typedef CGAL::cpp11::array HSV_Color; - - - /// \cond SKIP_IN_MANUAL -inline HSV_Color rgb_to_hsv (const RGB_Color& c) -{ - double r = (double)(c[0]) / 255.; - double g = (double)(c[1]) / 255.; - double b = (double)(c[2]) / 255.; - double Cmax = (std::max) (r, (std::max) (g, b)); - double Cmin = (std::min) (r, (std::min) (g, b)); - double delta = Cmax - Cmin; - double H = 0.; - - if (delta != 0.) - { - if (Cmax == r) - H = 60. * ((g - b) / delta); - else if (Cmax == g) - H = 60. * (((b - r) / delta) + 2.); - else - H = 60. * (((r - g) / delta) + 4.); - } - if (H < 0.) H += 360.; - double S = (Cmax == 0. ? 0. : 100. * (delta / Cmax)); - double V = 100. * Cmax; - HSV_Color out = {{ float(H), float(S), float(V) }}; - return out; -} - -inline RGB_Color hsv_to_rgb (const HSV_Color& c) -{ - double h = c[0]; - double s = c[1]; - double v = c[2]; - - s /= 100.; - v /= 100.; - double C = v*s; - int hh = (int)(h/60.); - double X = C * (1-CGAL::abs (hh % 2 - 1)); - double r = 0, g = 0, b = 0; - - if( hh>=0 && hh<1 ) - { - r = C; - g = X; - } - else if( hh>=1 && hh<2 ) - { - r = X; - g = C; - } - else if( hh>=2 && hh<3 ) - { - g = C; - b = X; - } - else if( hh>=3 && hh<4 ) - { - g = X; - b = C; - } - else if( hh>=4 && hh<5 ) - { - r = X; - b = C; - } - else - { - r = C; - b = X; - } - double m = v-C; - r += m; - g += m; - b += m; - r *= 255.0; - g *= 255.0; - b *= 255.0; - - RGB_Color out = {{ (unsigned char)r, (unsigned char)g, (unsigned char)b }}; - return out; -} - /// \endcond - -} // namespace Classification -} // namespace CGAL - - - -#endif // CGAL_CLASSIFICATION_COLOR_H diff --git a/Classification/include/CGAL/Classification/Feature/Color_channel.h b/Classification/include/CGAL/Classification/Feature/Color_channel.h index 73ff155f5b8..4d3ecea6459 100644 --- a/Classification/include/CGAL/Classification/Feature/Color_channel.h +++ b/Classification/include/CGAL/Classification/Feature/Color_channel.h @@ -25,7 +25,6 @@ #include -#include #include namespace CGAL { @@ -65,7 +64,7 @@ namespace Feature { `ColorMap`. \tparam ColorMap model of `ReadablePropertyMap` whose key type is the value type of the iterator of `PointRange` and value type - is `CGAL::Classification::RGB_Color`. + is `CGAL::Color`. */ template class Color_channel : public Feature_base @@ -82,9 +81,6 @@ public: private: - typedef typename Classification::RGB_Color RGB_Color; - typedef typename Classification::HSV_Color HSV_Color; - const PointRange& input; ColorMap color_map; Channel m_channel; @@ -111,8 +107,8 @@ public: /// \cond SKIP_IN_MANUAL virtual float value (std::size_t pt_index) { - HSV_Color c = Classification::rgb_to_hsv (get(color_map, *(input.begin()+pt_index))); - return c[std::size_t(m_channel)]; + cpp11::array c = get(color_map, *(input.begin()+pt_index)).to_hsv(); + return float(c[std::size_t(m_channel)]); } /// \endcond }; diff --git a/Classification/include/CGAL/Classification/Mesh_feature_generator.h b/Classification/include/CGAL/Classification/Mesh_feature_generator.h index d15b139cb3e..8e4fc337535 100644 --- a/Classification/include/CGAL/Classification/Mesh_feature_generator.h +++ b/Classification/include/CGAL/Classification/Mesh_feature_generator.h @@ -153,8 +153,6 @@ public: typedef Classification::Feature::Verticality Verticality; typedef Classification::Feature::Eigenvalue Eigenvalue; - - typedef typename Classification::RGB_Color RGB_Color; /// \endcond private: diff --git a/Classification/include/CGAL/Classification/Point_set_feature_generator.h b/Classification/include/CGAL/Classification/Point_set_feature_generator.h index b017ebe427c..46a89172c45 100644 --- a/Classification/include/CGAL/Classification/Point_set_feature_generator.h +++ b/Classification/include/CGAL/Classification/Point_set_feature_generator.h @@ -154,8 +154,6 @@ public: typedef Classification::Feature::Gradient_of_feature Gradient_of_feature; #endif - - typedef typename Classification::RGB_Color RGB_Color; /// \endcond private: @@ -336,7 +334,7 @@ public: typedef typename Default::Get::type Vmap; - typedef typename Default::Get::type + typedef typename Default::Get::type Cmap; typedef typename Default::Get::type Emap; @@ -349,7 +347,7 @@ public: // Functions to remove when deprecated constructor is removed void generate_normal_based_features(const CGAL::Constant_property_map&) { } - void generate_color_based_features(const CGAL::Constant_property_map&) { } + void generate_color_based_features(const CGAL::Constant_property_map&) { } void generate_echo_based_features(const CGAL::Constant_property_map&) { } #endif @@ -435,7 +433,7 @@ public: \tparam ColorMap model of `ReadablePropertyMap` whose key type is the value type of the iterator of `PointRange` and value type is - `CGAL::Classification::RGB_Color`. + `CGAL::Color`. \param features the feature set where the features are instantiated. \param color_map property map to access the colors of the input points (if any). diff --git a/Classification/test/Classification/test_classification_point_set.cpp b/Classification/test/Classification/test_classification_point_set.cpp index 4636e07913b..3890533b608 100644 --- a/Classification/test/Classification/test_classification_point_set.cpp +++ b/Classification/test/Classification/test_classification_point_set.cpp @@ -37,7 +37,7 @@ typedef Classification::Point_set_feature_generator Size_t_map; -typedef Point_set::Property_map Color_map; +typedef Point_set::Property_map Color_map; @@ -55,7 +55,7 @@ int main (int, char**) normal_map = pts.normal_map(); boost::tie (echo_map, map_added) = pts.add_property_map ("echo"); assert (map_added); - boost::tie (color_map, map_added) = pts.add_property_map ("color"); + boost::tie (color_map, map_added) = pts.add_property_map ("color"); assert (map_added); for (std::size_t i = 0; i < 1000; ++ i) @@ -68,9 +68,9 @@ int main (int, char**) CGAL::get_default_random().get_double(), CGAL::get_default_random().get_double())); echo_map[*it] = std::size_t(CGAL::get_default_random().get_int(0, 4)); - color_map[*it] = CGAL::make_array ((unsigned char)(CGAL::get_default_random().get_int(0, 255)), - (unsigned char)(CGAL::get_default_random().get_int(0, 255)), - (unsigned char)(CGAL::get_default_random().get_int(0, 255))); + color_map[*it] = CGAL::Color ((unsigned char)(CGAL::get_default_random().get_int(0, 255)), + (unsigned char)(CGAL::get_default_random().get_int(0, 255)), + (unsigned char)(CGAL::get_default_random().get_int(0, 255))); } Feature_set features; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp b/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp index a8ed8358285..516c56bbed4 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.cpp @@ -396,12 +396,12 @@ void Cluster_classification::backup_existing_colors_and_add_new() { if (m_points->point_set()->has_colors()) { - m_color = m_points->point_set()->add_property_map("real_color").first; + m_color = m_points->point_set()->add_property_map("real_color").first; for (Point_set::const_iterator it = m_points->point_set()->begin(); it != m_points->point_set()->first_selected(); ++ it) - m_color[*it] = {{ (unsigned char)(255 * m_points->point_set()->red(*it)), - (unsigned char)(255 * m_points->point_set()->green(*it)), - (unsigned char)(255 * m_points->point_set()->blue(*it)) }}; + m_color[*it] = CGAL::Color ((unsigned char)(255 * m_points->point_set()->red(*it)), + (unsigned char)(255 * m_points->point_set()->green(*it)), + (unsigned char)(255 * m_points->point_set()->blue(*it))); m_points->point_set()->remove_colors(); } @@ -411,7 +411,7 @@ void Cluster_classification::backup_existing_colors_and_add_new() void Cluster_classification::reset_colors() { - if (m_color == Point_set::Property_map()) + if (m_color == Point_set::Property_map()) m_points->point_set()->remove_colors(); else { @@ -606,7 +606,7 @@ int Cluster_classification::real_index_color() const { int out = m_index_color; - if (out == 0 && m_color == Point_set::Property_map()) + if (out == 0 && m_color == Point_set::Property_map()) out = -1; return out; } @@ -642,7 +642,7 @@ void Cluster_classification::compute_features (std::size_t nb_scales, float voxe if (normals) normal_map = m_points->point_set()->normal_map(); - bool colors = (m_color != Point_set::Property_map()); + bool colors = (m_color != Point_set::Property_map()); Point_set::Property_map echo_map; bool echo; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.h b/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.h index 53753e7cbbb..fd88c9e7507 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Cluster_classification.h @@ -27,7 +27,6 @@ class Cluster_classification : public Item_classification_base public: typedef Kernel::Point_3 Point_3; typedef Kernel::Vector_3 Vector_3; - typedef CGAL::Classification::RGB_Color Color; typedef Point_set::Point_map Point_map; typedef Point_set::Vector_map Vector_map; @@ -382,7 +381,10 @@ class Cluster_classification : public Item_classification_base std::vector m_clusters; - Point_set::Property_map m_color; + Point_set::Property_map m_red; + Point_set::Property_map m_green; + Point_set::Property_map m_blue; + Point_set::Property_map m_color; Point_set::Property_map m_cluster_id; Point_set::Property_map m_training; Point_set::Property_map m_classif; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp b/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp index 2b64ea7349a..aee56b923e6 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.cpp @@ -327,12 +327,12 @@ void Point_set_item_classification::backup_existing_colors_and_add_new() { if (m_points->point_set()->has_colors()) { - m_color = m_points->point_set()->add_property_map("real_color").first; + m_color = m_points->point_set()->add_property_map("real_color").first; for (Point_set::const_iterator it = m_points->point_set()->begin(); it != m_points->point_set()->first_selected(); ++ it) - m_color[*it] = {{ (unsigned char)(255 * m_points->point_set()->red(*it)), - (unsigned char)(255 * m_points->point_set()->green(*it)), - (unsigned char)(255 * m_points->point_set()->blue(*it)) }}; + m_color[*it] = CGAL::Color((unsigned char)(255 * m_points->point_set()->red(*it)), + (unsigned char)(255 * m_points->point_set()->green(*it)), + (unsigned char)(255 * m_points->point_set()->blue(*it))); m_points->point_set()->remove_colors(); } @@ -342,7 +342,7 @@ void Point_set_item_classification::backup_existing_colors_and_add_new() void Point_set_item_classification::reset_colors() { - if (m_color == Point_set::Property_map()) + if (m_color == Point_set::Property_map()) m_points->point_set()->remove_colors(); else { @@ -493,7 +493,7 @@ int Point_set_item_classification::real_index_color() const { int out = m_index_color; - if (out == 0 && m_color == Point_set::Property_map()) + if (out == 0 && m_color == Point_set::Property_map()) out = -1; return out; } @@ -532,7 +532,7 @@ void Point_set_item_classification::compute_features (std::size_t nb_scales, flo if (normals) normal_map = m_points->point_set()->normal_map(); - bool colors = (m_color != Point_set::Property_map()); + bool colors = (m_color != Point_set::Property_map()); Point_set::Property_map echo_map; bool echo; diff --git a/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.h b/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.h index 3dc0ba57af9..4de6fce22fc 100644 --- a/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.h +++ b/Polyhedron/demo/Polyhedron/Plugins/Classification/Point_set_item_classification.h @@ -30,7 +30,6 @@ class Point_set_item_classification : public Item_classification_base public: typedef Kernel::Point_3 Point_3; typedef Kernel::Vector_3 Vector_3; - typedef CGAL::Classification::RGB_Color Color; typedef Point_set::Point_map Point_map; typedef Point_set::Vector_map Vector_map; @@ -398,9 +397,12 @@ class Point_set_item_classification : public Item_classification_base std::vector m_clusters; + Point_set::Property_map m_red; + Point_set::Property_map m_green; + Point_set::Property_map m_blue; + Point_set::Property_map m_color; std::vector > m_label_probabilities; - Point_set::Property_map m_color; Point_set::Property_map m_training; Point_set::Property_map m_classif;