basic_palettes.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2020, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
35 
38 #include <color_util/convert.h>
40 #include <string>
41 #include <vector>
42 
43 namespace robot_nav_rviz_plugins
44 {
46 
51 class MapPalette : public NavGridPalette
52 {
53 public:
54  std::string getName() const override { return "map"; }
55  bool hasTransparency() const override { return false; }
56  std::vector<ColorRGBA24> getColors() const override
57  {
58  std::vector<ColorRGBA24> colors(NUM_COLORS);
59  // Standard gray map palette values
60  for (int i = 0; i <= 100; i++)
61  {
62  unsigned char v = 255 - (255 * i) / 100;
63  colors[i] = ColorRGBA24(v, v, v);
64  }
65  // illegal positive values in green
66  for (int i = 101; i <= 127; i++)
67  {
68  colors[i] = ColorRGBA24(0, 255, 0);
69  }
70  // illegal negative (char) values in shades of red/yellow
71  for (int i = 128; i <= 254; i++)
72  {
73  colors[i] = ColorRGBA24(255, (255 * (i - 128)) / (254 - 128), 0);
74  }
75 
76  // legal 255 value is tasteful blueish greenish grayish color
77  colors[255] = ColorRGBA24(0x70, 0x89, 0x86);
78 
79  return colors;
80  }
81 };
87 {
88 public:
89  std::string getName() const override { return "costmap"; }
90  bool hasTransparency() const override { return true; }
91  std::vector<ColorRGBA24> getColors() const override
92  {
93  std::vector<ColorRGBA24> colors(NUM_COLORS);
94 
95  // zero values have alpha=0
96  colors[0] = ColorRGBA24(0, 0, 0, 0);
97 
98  // Blue to red spectrum for most normal cost values
99  for (int i = 1; i <= 98; i++)
100  {
101  unsigned char v = (255 * i) / 100;
102  colors[i] = ColorRGBA24(v, 0, 255 - v);
103  }
104 
105  // inscribed obstacle values (99) in cyan
106  colors[99] = ColorRGBA24(0, 255, 255);
107 
108  // lethal obstacle values (100) in purple
109  colors[100] = ColorRGBA24(255, 0, 255);
110 
111  // illegal positive values in green
112  for (int i = 101; i <= 127; i++)
113  {
114  colors[i] = ColorRGBA24(0, 255, 0);
115  }
116 
117  // illegal negative (char) values in shades of red/yellow
118  for (int i = 128; i <= 254; i++)
119  {
120  colors[i] = ColorRGBA24(255, (255 * (i - 128)) / (254 - 128), 0);
121  }
122 
123  // legal 255 value is tasteful blueish greenish grayish color
124  colors[255] = ColorRGBA24(0x70, 0x89, 0x86);
125 
126  return colors;
127  }
128 };
129 
135 {
136 public:
137  std::string getName() const override { return "raw"; }
138  bool hasTransparency() const override { return false; }
139  std::vector<ColorRGBA24> getColors() const override
140  {
141  std::vector<ColorRGBA24> colors(NUM_COLORS);
142  for (unsigned int i = 0; i < NUM_COLORS; i++)
143  {
144  colors[i] = ColorRGBA24(i, i, i);
145  }
146  return colors;
147  }
148 };
149 
154 {
155 public:
156  std::string getName() const override { return "rainbow"; }
157  bool hasTransparency() const override { return true; }
158  std::vector<ColorRGBA24> getColors() const override
159  {
160  std::vector<ColorRGBA24> colors(NUM_COLORS);
161  colors[0] = ColorRGBA24(0, 0, 0, 0);
162  for (unsigned int i = 1; i < NUM_COLORS; i++)
163  {
164  double fraction = static_cast<double>(255 - i) / 254;
165  // multiplying by 0.75 scales it to purple to red
166  color_util::ColorHSVA color(fraction * 0.75, 1.0, 1.0, 1.0);
168  }
169  return colors;
170  }
171 };
172 
177 {
178 public:
179  std::string getName() const override { return "rainbow2"; }
180  bool hasTransparency() const override { return true; }
181  std::vector<ColorRGBA24> getColors() const override
182  {
183  std::vector<ColorRGBA24> colors(NUM_COLORS);
184  colors[0] = ColorRGBA24(0, 0, 0, 0);
185  for (unsigned int i = 1; i < NUM_COLORS; i++)
186  {
187  double fraction = static_cast<double>(i - 1) / 254;
188  // multiplying by 0.75 scales it to red to purple
189  color_util::ColorHSVA color(fraction * 0.75, 1.0, 1.0, 1.0);
191  }
192  return colors;
193  }
194 };
195 
200 {
201 public:
202  // Blend from black to blue
204  : SpectrumPalette(color_util::ColorRGBA24(0, 0, 0), color_util::ColorRGBA24(0, 0, 255), true) {}
205  std::string getName() const override { return "blues"; }
206 };
207 
212 {
213 public:
214  std::string getName() const override { return "distinct"; }
215  bool hasTransparency() const override { return true; }
216 
217  std::vector<ColorRGBA24> getColors() const override
218  {
220  }
221 };
222 
223 
224 } // namespace robot_nav_rviz_plugins
225 
robot_nav_rviz_plugins::MapPalette::hasTransparency
bool hasTransparency() const override
See if the palette has any transparent colors.
Definition: basic_palettes.cpp:55
robot_nav_rviz_plugins::RawPalette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:137
color_util::ColorRGBA24
robot_nav_rviz_plugins
Several reusable pieces for displaying polygons.
Definition: nav_grid_display.h:60
robot_nav_rviz_plugins::CostmapPalette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:89
robot_nav_rviz_plugins::RawPalette
Same as rviz::MapDisplay raw palette. See https://github.com/ros-visualization/rviz/blob/4b6c0f447159...
Definition: basic_palettes.cpp:134
robot_nav_rviz_plugins::BluesPalette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:205
robot_nav_rviz_plugins::RawPalette::hasTransparency
bool hasTransparency() const override
See if the palette has any transparent colors.
Definition: basic_palettes.cpp:138
named_colors.h
robot_nav_rviz_plugins::Rainbow2Palette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:179
robot_nav_rviz_plugins::RainbowPalette::getColors
std::vector< ColorRGBA24 > getColors() const override
The actual definition of the colors.
Definition: basic_palettes.cpp:158
robot_nav_rviz_plugins::Rainbow2Palette
Rainbow hued palette from red to purple with transparent 0.
Definition: basic_palettes.cpp:176
color_util::getNamedColors
const std::vector< ColorRGBA24 > & getNamedColors()
robot_nav_rviz_plugins::NavGridPalette::NUM_COLORS
static const unsigned int NUM_COLORS
Definition: nav_grid_palette.h:53
class_list_macros.h
robot_nav_rviz_plugins::RawPalette::getColors
std::vector< ColorRGBA24 > getColors() const override
The actual definition of the colors.
Definition: basic_palettes.cpp:139
color_util
robot_nav_rviz_plugins::Rainbow2Palette::hasTransparency
bool hasTransparency() const override
See if the palette has any transparent colors.
Definition: basic_palettes.cpp:180
robot_nav_rviz_plugins::BluesPalette::BluesPalette
BluesPalette()
Definition: basic_palettes.cpp:203
PLUGINLIB_EXPORT_CLASS
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
robot_nav_rviz_plugins::RainbowPalette::hasTransparency
bool hasTransparency() const override
See if the palette has any transparent colors.
Definition: basic_palettes.cpp:157
robot_nav_rviz_plugins::RainbowPalette
Rainbow hued palette from purple to red with transparent 0.
Definition: basic_palettes.cpp:153
robot_nav_rviz_plugins::SpectrumPalette
Easy class to generate palettes that simply blend two colors together.
Definition: spectrum_palette.h:49
robot_nav_rviz_plugins::Rainbow2Palette::getColors
std::vector< ColorRGBA24 > getColors() const override
The actual definition of the colors.
Definition: basic_palettes.cpp:181
spectrum_palette.h
robot_nav_rviz_plugins::MapPalette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:54
robot_nav_rviz_plugins::DistinctPalette::getColors
std::vector< ColorRGBA24 > getColors() const override
The actual definition of the colors.
Definition: basic_palettes.cpp:217
robot_nav_rviz_plugins::CostmapPalette::getColors
std::vector< ColorRGBA24 > getColors() const override
The actual definition of the colors.
Definition: basic_palettes.cpp:91
robot_nav_rviz_plugins::DistinctPalette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:214
robot_nav_rviz_plugins::DistinctPalette
List of distinct colors for displaying individual categories.
Definition: basic_palettes.cpp:211
robot_nav_rviz_plugins::CostmapPalette::hasTransparency
bool hasTransparency() const override
See if the palette has any transparent colors.
Definition: basic_palettes.cpp:90
color_util::ColorHSVA
robot_nav_rviz_plugins::CostmapPalette
Same as rviz::MapDisplay costmap palette. See https://github.com/ros-visualization/rviz/blob/4b6c0f44...
Definition: basic_palettes.cpp:86
robot_nav_rviz_plugins::DistinctPalette::hasTransparency
bool hasTransparency() const override
See if the palette has any transparent colors.
Definition: basic_palettes.cpp:215
robot_nav_rviz_plugins::MapPalette::getColors
std::vector< ColorRGBA24 > getColors() const override
The actual definition of the colors.
Definition: basic_palettes.cpp:56
robot_nav_rviz_plugins::NavGridPalette
A simple datastructure representing a palette of up to 256 24-bit colors.
Definition: nav_grid_palette.h:50
robot_nav_rviz_plugins::BluesPalette
Palette with a gradient of blues from dark to light.
Definition: basic_palettes.cpp:199
convert.h
color_util::toInt
color_util::ColorHSVA24 toInt(const color_util::ColorHSVA &float_color)
robot_nav_rviz_plugins::MapPalette
Same as rviz::MapDisplay map palette. See https://github.com/ros-visualization/rviz/blob/4b6c0f447159...
Definition: basic_palettes.cpp:51
color_util::changeColorspace
color_util::ColorRGBA changeColorspace(const color_util::ColorHSVA &hsva)
robot_nav_rviz_plugins::RainbowPalette::getName
std::string getName() const override
Unique descriptive name for this particular palette.
Definition: basic_palettes.cpp:156
nav_grid_palette.h


robot_nav_rviz_plugins
Author(s):
autogenerated on Sun May 18 2025 02:47:50