Visual Servoing Platform version 3.7.0
Loading...
Searching...
No Matches
vpColorBlindFriendlyPalette.cpp
1/*
2 * ViSP, open source Visual Servoing Platform software.
3 * Copyright (C) 2005 - 2025 by Inria. All rights reserved.
4 *
5 * This software is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 * See the file LICENSE.txt at the root directory of this source
10 * distribution for additional information about the GNU GPL.
11 *
12 * For using ViSP with software that can not be combined with the GNU
13 * GPL, please contact Inria about acquiring a ViSP Professional
14 * Edition License.
15 *
16 * See https://visp.inria.fr for more information.
17 *
18 * This software was developed at:
19 * Inria Rennes - Bretagne Atlantique
20 * Campus Universitaire de Beaulieu
21 * 35042 Rennes Cedex
22 * France
23 *
24 * If you have questions regarding the use of this file, please contact
25 * Inria at visp@inria.fr
26 *
27 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
28 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
29 * Description:
30 * Real-time 3D point clouds plotter based on the PCL library.
31 */
32
33#include <visp3/gui/vpColorBlindFriendlyPalette.h>
34#include <visp3/core/vpIoTools.h>
35
36#if (VISP_CXX_STANDARD > VISP_CXX_STANDARD_98)
37
39std::vector<std::string> vpColorBlindFriendlyPalette::s_paletteNames =
40{
41 "black" ,
42 "orange" ,
43 "sky-blue" ,
44 "green" ,
45 "yellow" ,
46 "blue" ,
47 "vermillon" ,
48 "purple" ,
49 "unknown"
50};
51
52std::vector<vpColor> vpColorBlindFriendlyPalette::s_palette = {
53 vpColor(0,0,0), // Black = 0,
54 vpColor(230,159,0), // Orange = 1,
55 vpColor(86,180,233), // SkyBlue = 2,
56 vpColor(0,158,115), // Green = 3,
57 vpColor(240,228,66), // Yellow = 4,
58 vpColor(0,114,178), // Blue = 5,
59 vpColor(213,94,0), // Vermillon = 6,
60 vpColor(204,121,167), // Purple = 7,
61 vpColor(255,255,255) // COUNT = 8
62};
63
69
75
77 : m_colorID(Palette::COUNT)
78{
79 set_fromString(nameColor);
80}
81
86
88{
89 return s_palette[to_uint(m_colorID)];
90}
91
92std::vector<unsigned char> vpColorBlindFriendlyPalette::to_RGB() const
93{
94 vpColor color = s_palette[to_uint(m_colorID)];
95 std::vector<unsigned char> v_rgb;
96 v_rgb.push_back(color.R);
97 v_rgb.push_back(color.G);
98 v_rgb.push_back(color.B);
99 return v_rgb;
100}
101
103{
104 vpColor color = s_palette[to_uint(m_colorID)];
105 std::vector<double> v_rgb;
106 v_rgb.push_back(static_cast<double>(color.R) / 255.0);
107 v_rgb.push_back(static_cast<double>(color.G) / 255.0);
108 v_rgb.push_back(static_cast<double>(color.B) / 255.0);
109 return v_rgb;
110}
111
112bool vpColorBlindFriendlyPalette::set_fromString(const std::string &nameColor)
113{
114 m_colorID = Palette::COUNT;
115 std::string nameLowerCase = nameColor; // vpIoTools::toLowerCase(nameColor);
116 bool wasFound(false);
117 for (unsigned int i = 0; i < to_uint(Palette::COUNT) && !wasFound; i++) {
119 if (to_string(candidate) == nameLowerCase) {
120 m_colorID = candidate;
121 wasFound = true;
122 }
123 }
124 return wasFound;
125}
126
128{
129 std::string nameColor = to_string(m_colorID);
130 return nameColor;
131}
132
133std::string vpColorBlindFriendlyPalette::getAvailableColorsNames(const std::string &prefix, const std::string &separator, const std::string &suffix)
134{
135 std::string list(prefix);
136 const unsigned int nbAvailableColors = static_cast<unsigned int>(Palette::COUNT);
137 for (unsigned int i = 0; i < nbAvailableColors - 1; i++) {
138 std::string nameCandidateID = s_paletteNames[i];
139 list += nameCandidateID + separator;
140 }
141 list += s_paletteNames[nbAvailableColors - 1] + suffix;
142 return list;
143}
144
145unsigned int vpColorBlindFriendlyPalette::to_uint(const Palette &colorID)
146{
147 const unsigned int nbAvailableColors = static_cast<unsigned int>(Palette::COUNT);
148 unsigned int ID = nbAvailableColors;
149 std::string nameSearchedColor = to_string(colorID);
150 bool wasFound = false;
151 for (unsigned int i = 0; i < nbAvailableColors && !wasFound; i++) {
152 Palette candidate = (Palette)i;
153 if (to_string(candidate) == nameSearchedColor) {
154 ID = i;
155 wasFound = true;
156 }
157 }
158 return ID;
159}
160
162{
163 std::string nameColor;
164 switch (colorID) {
165 case Palette::Black:
166 nameColor = s_paletteNames[0];
167 break;
168 case Palette::Orange:
169 nameColor = s_paletteNames[1];
170 break;
171 case Palette::SkyBlue:
172 nameColor = s_paletteNames[2];
173 break;
174 case Palette::Green:
175 nameColor = s_paletteNames[3];
176 break;
177 case Palette::Yellow:
178 nameColor = s_paletteNames[4];
179 break;
180 case Palette::Blue:
181 nameColor = s_paletteNames[5];
182 break;
183 case Palette::Vermillon:
184 nameColor = s_paletteNames[6];
185 break;
186 case Palette::Purple:
187 nameColor = s_paletteNames[7];
188 break;
189 default:
190 nameColor = s_paletteNames[8];
191 }
192 return nameColor;
193}
194
195END_VISP_NAMESPACE
196
197std::ostream &operator<<(std::ostream &os, const VISP_NAMESPACE_ADDRESSING vpColorBlindFriendlyPalette &color)
198{
199 os << color.to_string();
200 return os;
201}
202
203std::istream &operator>>(std::istream &is, VISP_NAMESPACE_ADDRESSING vpColorBlindFriendlyPalette &color)
204{
205 std::string nameColor;
206 is >> nameColor;
207 color.set_fromString(nameColor);
208 return is;
209}
210#else
211void dummy_vpColorBlindFriendlyPalette() { }
212#endif
Class that furnishes a set of colors that color blind people should be able to distinguish one from a...
std::vector< unsigned char > to_RGB() const
Cast a vpColorBlindFriendlyPalette in a vector {R, G, B}. A vpColorBlindFriendlyPalette::Palette::COU...
Palette
Enum that list the different available colors.
std::string to_string() const
Get the name of the vpColorBlindFriendlyPalette object.
vpColor to_vpColor() const
Cast a vpColorBlindFriendlyPalette in a vpColor object. A vpColorBlindFriendlyPalette::Palette::COUNT...
static std::string getAvailableColorsNames(const std::string &prefix="", const std::string &separator=" ", const std::string &suffix="")
Get the list of available colors names.
static std::vector< std::string > s_paletteNames
bool set_fromString(const std::string &nameColor)
Set the fromString object.
std::vector< double > to_colorRatio() const
Cast the object in a vector of doubles that belong to the range [0; 1]. The initial R,...
Palette get_colorID() const
Get the vpColorBlindFriendlyPalette::Palette the object corresponds to.
vpColorBlindFriendlyPalette()
Construct a new vp Color Blind Friendly Palette. The default value vpColorBlindFriendlyPalette::Palet...
Class to define RGB colors available for display functionalities.
Definition vpColor.h:157