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-2019, 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 
19 {
20  this->reset();
21  this->use_standard_colors_first = use_standard_colors_first_in;
22 } // end of TColorManager (ctor)
23 
26 {
27  if (have_exceeded_colors)
28  {
29  // pick and return a random color triad
30  return TColor(
31  rand() % (color_thresh + 1), rand() % (color_thresh + 1),
32  rand() % (color_thresh + 1));
33  }
34 
35  // start updating by the step if we don't use (or have already used) the
36  // standard colors
37  if (!use_standard_colors_first || have_used_standard_colors)
38  {
39  this->advanceRGBCounters();
40  }
41  else
42  {
43  bool used_red = used_colors.find(TColor::red()) != used_colors.end();
44  bool used_green =
45  used_colors.find(TColor::green()) != used_colors.end();
46  bool used_blue = used_colors.find(TColor::blue()) != used_colors.end();
47 
48  // fixed order of usage
49  // red -> green -> blue
50  if (!used_red)
51  {
52  curr_color = TColor::red();
53  }
54  else if (!used_green)
55  {
56  curr_color = TColor::green();
57  }
58  else if (!used_blue)
59  {
60  curr_color = TColor::blue();
61  have_used_standard_colors = true;
62  }
63  }
64 
65  this->markColorAsUsed(curr_color);
66  return curr_color;
67 } // end of getNextTColor
68 
70 {
71  return TColorf(this->getNextTColor());
72 } // end of getNextTColor
73 
75 {
76  // method is used only when we either don't use or have already used the
77  // standard colors.
78  ASSERT_(!use_standard_colors_first || have_used_standard_colors);
79 
80  THROW_EXCEPTION("Not yet implemented.");
81  // if standard colors have already been used then at first color is
82  // TColor::blue
83  if (curr_color == TColor::blue())
84  {
85  curr_color = TColor();
86 
87  color_step_triad.B = color_step;
88  }
89 
90  // first advance blue until we reach the limit 255
91  // then advance green until we reach the limit 255
92  // finally advance red until we reach the limit 255
93 
94  // TODO - how do i do this?
95  curr_color += color_step_triad;
96 
97  // if the standard colors are to be used first make sure that the color we
98  // end up on is not a standard one.
99  if (use_standard_colors_first &&
100  (curr_color == TColor::red() || curr_color == TColor::green() ||
101  curr_color == TColor::blue()))
102  {
103  this->advanceRGBCounters();
104  }
105 
106 } // end of advanceRGBCounters
107 
109 {
110  using namespace std;
111  pair<set<TColor>::const_iterator, bool> ret = used_colors.insert(color);
112 
113  // Should always return True as element shouldn't exist prior to this call
114  ASSERT_(ret.second);
115 }
116 
118 {
119  used_colors.clear();
120 
121  curr_color = TColor();
122  color_step_triad = TColor(0, 0, 50);
123 
124  have_exceeded_colors = false;
125  use_standard_colors_first = true;
126  have_used_standard_colors = false;
127 }
128 
130 {
131  bool ret = used_colors.find(TColor::red()) != used_colors.end() &&
132  used_colors.find(TColor::green()) != used_colors.end() &&
133  used_colors.find(TColor::blue()) != used_colors.end();
134 
135  return ret;
136 }
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:62
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.
mrpt::img::TColorf getNextTColorf()
Get the next RGB triad in TColorf form.
GLuint color
Definition: glext.h:8459
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:120
~TColorManager()
Destructor.
void reset()
Reset all class properties to their default values.
static constexpr TColor green()
Definition: TColor.h:61
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:60
A RGB color - floats in the range [0,1].
Definition: TColor.h:77
GLboolean reset
Definition: glext.h:3586
A RGB color - 8bit.
Definition: TColor.h:20
TColorManager(bool use_standard_colors_first=true)
Constructor.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 8fe78517f Sun Jul 14 19:43:28 2019 +0200 at lun oct 28 02:10:00 CET 2019