ColorBar.h
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/color/ColorBar.h
22 
23  \brief The concept of color bar.
24 */
25 
26 #ifndef __TERRALIB_COLOR_INTERNAL_COLORBAR_H
27 #define __TERRALIB_COLOR_INTERNAL_COLORBAR_H
28 
29 // TerraLib
30 #include "RGBAColor.h"
31 
32 // STL
33 #include <vector>
34 #include <map>
35 
36 namespace te
37 {
38  namespace color
39  {
40  /*!
41  \class ColorBar
42 
43  \brief It models the concept of color bar.
44 
45  It is used to construct color bar.
46 
47  \ingroup color
48  */
50  {
51  public:
52 
53  /** @name Initializer Methods
54  * Methods related to instantiation and destruction.
55  */
56  //@{
57 
58  /*!
59  \brief It initializes a new ColorBar(default constructor)
60  */
61  ColorBar();
62 
63  /*!
64  \brief It initializes a new ColorBar.
65 
66  \param size Number of colors to be generated.
67  \note By default the first color is red and the second is white.
68  */
69  ColorBar(int size);
70 
71  /*!
72  \brief It initializes a new ColorBar.
73 
74  \param colorBegin Begin color.
75  \param colorEnd End color.
76  \param size Number of colors to be generated.
77  */
78  ColorBar(const RGBAColor& colorBegin, const RGBAColor& colorEnd, int size);
79 
80  /*! \brief Copy constructor. */
81  ColorBar(const ColorBar& rhs);
82 
83  /*! Assignment operator. */
84  te::color::ColorBar& operator=(const ColorBar& rhs);
85 
86  /*! \brief Destructor */
87  ~ColorBar();
88 
89  //@}
90 
91  /** @name Accessor methods
92  * Methods used to get or set properties.
93  */
94  //@{
95 
96  /*!
97  \brief It returns the color bar name.
98 
99  \return The color bar name.
100  */
101  const std::string& getName() const;
102 
103  /*!
104  \brief It sets the color bar name and adjust its entry in the scheme group if needed.
105 
106  \param name The new color bar name.
107  */
108  void setName(const std::string& name);
109 
110  /*!
111  \brief It gets color map.
112 
113  \return Generated color bar.
114  */
115  const std::map<double, te::color::RGBAColor>& getColorMap() const;
116 
117  /*!
118  \brief It generates color bar.
119 
120  \return Generated color bar.
121  */
122  const std::vector<te::color::RGBAColor>& getColorBar();
123 
124  /*!
125  \brief It generates color bar.
126  \param n Number of slices. It is the amount of legends.
127 
128  \return Generated color steps.
129  */
130  const std::vector<te::color::RGBAColor>& getSlices(const int& n);
131 
132  const te::color::RGBAColor& getMeanSlice();
133 
134  const std::vector<te::color::RGBAColor>& getLowerMeanSlices(const int& n);
135 
136  const std::vector<te::color::RGBAColor>& getUpperMeanSlices(const int& n);
137 
138  /*!
139  \brief It sets number of colors in the color bar.
140 
141  \param size Number of colors in the color bar.
142  */
143  void setBarSize(const int& size);
144 
145  /*!
146  \brief It returns number of colors in the color bar.
147 
148  \return number of colors in the color bar.
149  */
150  int getBarSize();
151 
152  /*!
153  \brief It adds a color in the color bar.
154 
155  \param color Color to be added in the color bar.
156  \param pos Position where the color is added.
157  \note 0 <= pos <= 1
158  \note If you add to the first position, the color previously occupied is shifted to be between this and the next color of the bar.
159  \note If you add to the last position, the color previously occupied is shifted to be between this and the previous color of the bar.
160  \note If you add where there is already another, the color previously occupied is shifted to be between this and the next/previous color of the bar.
161  */
162  void addColor(const RGBAColor& color, const double& pos);
163 
164  /*!
165  \brief It removes a color in the color bar.
166 
167  \param color Color to be removed in the color bar.
168  \note If you remove the first color, the color next to occupy its place.
169  \note If you remove the last color, the previous color will take its place.
170  \note The bar should have at least two colors.
171  */
172  void remove(const RGBAColor& color);
173 
174  /*!
175  \brief It removes a color in the color bar.
176 
177  \param index Index of color to be removed in the color bar.
178  \note 0:remove the first color; 1:remove the second color...
179  \note If you remove the first color, the color next to occupy its place.
180  \note If you remove the last color, the previous color will take its place.
181  \note The bar should have at least two colors.
182  */
183  void remove(const int& index);
184 
185  /*!
186  \brief It removes a color in the color bar.
187 
188  \param pos Position of color to be removed in the color bar.
189  \note If you remove the first color, the color next to occupy its place.
190  \note If you remove the last color, the previous color will take its place.
191  \note The bar should have at least two colors.
192  */
193  void remove(const double& pos);
194 
195  /*!
196  \brief It removes a color in the color bar.
197 
198  \param index Reverse index of color to be removed in the color bar.
199  \note 0:remove the last color; 1:remove the penultimate color...
200  \note If you remove the first color, the color next to occupy its place.
201  \note If you remove the last color, the previous color will take its place.
202  \note The bar should have at least two colors.
203  */
204  void removeReverse(const int& index);
205 
206  /*!
207  \brief It moves a color to new posisiton.
208 
209  \param pos position of the color in the color bar.
210  \param color The new color.
211  */
212  void changeColor(const double& pos, const RGBAColor& color);
213 
214  /*!
215  \brief It moves a color to new posisiton.
216 
217  \param index index of the color in the color bar.
218  \param color The new color.
219  */
220  void changeColor(const int& index, const RGBAColor& color);
221 
222  /*!
223  \brief It moves a color to new posisiton.
224 
225  \param color Color to be moved in the color bar.
226  \note Move the first color matching found in the color bar.
227  \note If you place the color where there is already another, the color previously occupied is shifted to be between this and the next color of the bar.
228  */
229  void move(const RGBAColor& color, const double& pos);
230 
231  /*!
232  \brief It moves a color to new posisiton.
233 
234  \param index Index of color to be moved in the color bar.
235  \param pos The new postion of color in the color bar.
236  \note 0:move the first color; 1:remove the second color...
237  \note If you place the color where there is already another, the color previously occupied is shifted to be between this and the next color of the bar.
238 
239  \return The index of color. The index may have changed depending on the new position that the color will take on the color bar.
240  */
241  int move(const int& index, const double& pos);
242 
243  /*!
244  \brief It moves a color to new posisiton.
245 
246  \param index Index of color to be moved in the color bar.
247  \param pos The new postion of color in the color bar.
248  \note 0:move the first color; 1:remove the second color...
249  \note If you place the color where there is already another, the color previously occupied is shifted to be between this and the next color of the bar.
250 
251  \return The position of color. The position may have changed depending on the new position that the color will take on the color bar.
252  */
253  double move(const double& pi, const double& pm);
254 
255  /*!
256  \brief It moves a color to new posisiton.
257 
258  \param index Reverse index of color to be moved in the color bar.
259  \param pos The new postion of color in the color bar.
260  \note 0:move the last color; 1:remove the penultimate color...
261  \note If you place the color where there is already another, the color previously occupied is shifted to be between this and the next color of the bar.
262 
263  \return The position of color. The position may have changed depending on the new position that the color will take on the color bar.
264  */
265  int moveReverse(const int& index, const double& pos);
266 
267  //@}
268 
269  private:
270  /** @name Private methods
271  * Methods used to generate colors.
272  */
273  //@{
274  /*!
275  \brief It generates bar colors.
276  */
277  void generateColorBar();
278 
279  /*!
280  \brief It generates legend colors.
281 
282  \param n Number of slices. It is the amount of legends.
283  */
284  void generateSlices(const int& n);
285 
286  //@}
287 
288  private:
289 
290  std::vector<RGBAColor> m_colorBarVec; //!< Color vector.
291  std::vector<RGBAColor> m_colorSliceVec; //!< Color step vector.
292  std::string m_name; //!< Color bar name.
293  int m_barSize; //!< Size of color bar (number of colors in the color bar).
294  std::map<double, RGBAColor> m_colorMap; //!< Color map.
295  };
296 
297  } // end namespace color
298 } // end namespace te
299 
300 #endif // __TERRALIB_COLOR_INTERNAL_COLORBAR_H
301 
std::vector< RGBAColor > m_colorSliceVec
Color step vector.
Definition: ColorBar.h:291
A helper class for 24-bit RGBA (Red-Green-Blue-Alpha channel) color.
int m_barSize
Size of color bar (number of colors in the color bar).
Definition: ColorBar.h:293
URI C++ Library.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
std::vector< RGBAColor > m_colorBarVec
Color vector.
Definition: ColorBar.h:290
It models the concept of color bar.
Definition: ColorBar.h:49
std::map< double, RGBAColor > m_colorMap
Color map.
Definition: ColorBar.h:294
std::string m_name
Color bar name.
Definition: ColorBar.h:292
#define TECOLOREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:73