MRPT  1.9.9
TColorManager.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "img-precomp.h" // Precompiled headers
11 #include <mrpt/img/TColorManager.h>
12 
13 using namespace mrpt::img;
14 using namespace std;
15 
16 TColorManager::TColorManager(bool use_standard_colors_first_in /* = true */)
17  : color_thresh(255)
18 {
19  this->reset();
20  this->use_standard_colors_first = use_standard_colors_first_in;
21 } // end of TColorManager (ctor)
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;
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:41
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.
uint8_t B
Definition: TColor.h:46
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.
GLuint color
Definition: glext.h:8300
#define ASSERT_(f)
Defines an assertion mechanism.
Definition: exceptions.h:113
~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:61
static constexpr TColor red()
Predefined colors.
Definition: TColor.h:60
A RGB color - floats in the range [0,1].
Definition: TColor.h:77
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:20
TColorManager(bool use_standard_colors_first=true)
Constructor.
const Scalar * const_iterator
Definition: eigen_plugins.h:27
std::set< mrpt::img::TColor > used_colors
Definition: TColorManager.h:41



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020