MRPT  1.9.9
TColorManager.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | https://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2020, Individual contributors, see AUTHORS file |
6  | See: https://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See: https://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "img-precomp.h" // Precompiled headers
11 
12 #include <mrpt/img/TColorManager.h>
13 
14 using namespace mrpt::img;
15 using namespace std;
16 
17 TColorManager::TColorManager(bool use_standard_colors_first_in /* = true */)
18  : use_standard_colors_first(use_standard_colors_first_in)
19 {
20  this->reset();
21 }
22 
25 {
27  {
28  // pick and return a random color triad
29  return TColor(
30  rand() % (color_thresh + 1), rand() % (color_thresh + 1),
31  rand() % (color_thresh + 1));
32  }
33 
34  // start updating by the step if we don't use (or have already used) the
35  // standard colors
37  {
38  this->advanceRGBCounters();
39  }
40  else
41  {
42  bool used_red = used_colors.find(TColor::red()) != used_colors.end();
43  bool used_green =
44  used_colors.find(TColor::green()) != used_colors.end();
45  bool used_blue = used_colors.find(TColor::blue()) != used_colors.end();
46 
47  // fixed order of usage
48  // red -> green -> blue
49  if (!used_red)
50  {
52  }
53  else if (!used_green)
54  {
56  }
57  else if (!used_blue)
58  {
61  }
62  }
63 
65  return curr_color;
66 } // end of getNextTColor
67 
69 {
70  return TColorf(this->getNextTColor());
71 } // end of getNextTColor
72 
74 {
75  // method is used only when we either don't use or have already used the
76  // standard colors.
78 
79  THROW_EXCEPTION("Not yet implemented.");
80  // if standard colors have already been used then at first color is
81  // TColor::blue
82  if (curr_color == TColor::blue())
83  {
84  curr_color = TColor();
85 
87  }
88 
89  // first advance blue until we reach the limit 255
90  // then advance green until we reach the limit 255
91  // finally advance red until we reach the limit 255
92 
93  // TODO - how do i do this?
95 
96  // if the standard colors are to be used first make sure that the color we
97  // end up on is not a standard one.
100  curr_color == TColor::blue()))
101  {
102  this->advanceRGBCounters();
103  }
104 
105 } // end of advanceRGBCounters
106 
108 {
109  using namespace std;
110  pair<set<TColor>::const_iterator, bool> ret = used_colors.insert(color);
111 
112  // Should always return True as element shouldn't exist prior to this call
113  ASSERT_(ret.second);
114 }
115 
117 {
118  used_colors.clear();
119 
120  curr_color = TColor();
121  color_step_triad = TColor(0, 0, 50);
122 
123  have_exceeded_colors = false;
126 }
127 
129 {
130  bool ret = used_colors.find(TColor::red()) != used_colors.end() &&
131  used_colors.find(TColor::green()) != used_colors.end() &&
132  used_colors.find(TColor::blue()) != used_colors.end();
133 
134  return ret;
135 }
void markColorAsUsed(mrpt::img::TColor color)
Mark the given color as used.
#define THROW_EXCEPTION(msg)
Definition: exceptions.h:67
static constexpr TColor blue()
Definition: TColor.h:68
bool checkStdColorsUsed()
Check if the standard colors have already been used.
mrpt::img::TColor getNextTColor()
Get the next RGB triad in TColor form.
STL namespace.
uint8_t B
Definition: TColor.h:51
mrpt::img::TColor color_step_triad
Definition: TColorManager.h:68
bool use_standard_colors_first
Indicates if the standard colors are to be returned first.
Definition: TColorManager.h:44
mrpt::img::TColorf getNextTColorf()
Get the next RGB triad in TColorf form.
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
~TColorManager()
Destructor.
const uint8_t color_thresh
Definition: TColorManager.h:62
void reset()
Reset all class properties to their default values.
static constexpr TColor green()
Definition: TColor.h:67
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:66
An RGBA color - floats in the range [0,1].
Definition: TColor.h:88
mrpt::img::TColor curr_color
Definition: TColorManager.h:40
bool have_used_standard_colors
Indicates if the standard colors have already been used.
Definition: TColorManager.h:54
A RGB color - 8bit.
Definition: TColor.h:25
TColorManager(bool use_standard_colors_first=true)
Constructor.
std::set< mrpt::img::TColor > used_colors
Definition: TColorManager.h:41



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: c7a3bec24 Sun Mar 29 18:33:13 2020 +0200 at dom mar 29 18:50:38 CEST 2020