All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RasterTransform.h
Go to the documentation of this file.
1 /* Copyright (C) 2001-2009 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 RasterTransform.h
22 
23  \brief A Raster Transform is a class that defines functions to transform a styled raster.
24 */
25 
26 #ifndef __TERRALIB_MAPTOOLS_INTERNAL_RASTERTRANSFORM_H
27 #define __TERRALIB_MAPTOOLS_INTERNAL_RASTERTRANSFORM_H
28 
29 // TerraLib
30 #include "Config.h"
31 #include "../color/RGBAColor.h"
32 #include "../color/ColorBar.h"
33 
34 // STL
35 #include <map>
36 
37 namespace te
38 {
39 // Forward declarations
40  namespace se
41  {
42  class RasterSymbolizer;
43  }
44 
45  namespace rst
46  {
47  class Raster;
48  class RasterProperty;
49  }
50 
51  namespace map
52  {
53 // Forward declarations
54 
55  /*!
56  \class RasterTransform
57 
58  \brief A Raster Transform is a class that defines functions to transform a styled raster.
59 
60  \sa
61  */
63  {
64  public:
65 
66  typedef void (RasterTransform::*TransformFunction)(double, double, double, double);
67  typedef te::color::RGBAColor (RasterTransform::*RGBAFunction)(double, double);
68 
69  typedef std::pair<double, double> RasterThreshold;
70 
71  typedef std::map<RasterThreshold, te::color::RGBAColor> CategorizedMap;
72  typedef std::map<RasterThreshold, te::color::ColorBar> InterpolatedMap;
73 
74  //! The three channels of a display
76  {
77  RED_CHANNEL=0,
78  GREEN_CHANNEL=1,
79  BLUE_CHANNEL=2
80  };
81 
82  // The raster transform functions type
84  {
85  NO_TRANSF=0,
86  MONO2THREE_TRANSF=1,
87  EXTRACT2RGB_TRANSF=2,
88  RED2THREE_TRANSF=3,
89  GREEN2THREE_TRANSF=4,
90  BLUE2THREE_TRANSF=5,
91  CATEGORIZE_TRANSF=6,
92  INTERPOLATE_TRANSF=7,
93  BAND2BAND_TRANSF
94  };
95 
96  public:
97 
98  /*!
99  \brief Constructor
100 
101  \param input
102  \param output
103 
104  \note
105  */
107 
108  /*! \brief Destructor. */
109  ~RasterTransform();
110 
111  /*! \brief Gets the input raster. */
112  te::rst::Raster* getInputRaster() { return m_rasterIn; }
113 
114  /*! \brief Gets the output raster. */
115  te::rst::Raster* getOutputRaster() { return m_rasterOut; }
116 
117  /*! \brief Sets the transparency. */
118  void setTransparency(double value) { m_transp = value; }
119 
120  /*! \brief Gets the transparency. */
121  double getTransparency() { return m_transp; }
122 
123  /*! \brief Sets the gain. */
124  void setGain(double value) { m_gain = value; }
125 
126  /*! \brief Gets the gain. */
127  double getGain() { return m_gain; }
128 
129  /*! \brief Sets the offset. */
130  void setOffset(double value) { m_offset = value; }
131 
132  /*! \brief Gets the offset. */
133  double getOffset() { return m_offset; }
134 
135  /*! \brief Sets the constrast value for red band. */
136  void setContrastR(double value) { m_rContrast = value; }
137 
138  /*! \brief Gets the constrast value for red band. */
139  double getContrastR() { return m_rContrast; }
140 
141  /*! \brief Sets the constrast value for green band. */
142  void setContrastG(double value) { m_gContrast = value; }
143 
144  /*! \brief Gets the constrast value for green band. */
145  double getContrastG() { return m_gContrast; }
146 
147  /*! \brief Sets the constrast value for blue band. */
148  void setContrastB(double value) { m_bContrast = value; }
149 
150  /*! \brief Gets the constrast value for blue band. */
151  double getContrastB() { return m_bContrast; }
152 
153  /*! \brief Sets the constrast value for gray band. */
154  void setContrastM(double value) { m_mContrast = value; }
155 
156  /*! \brief Gets the constrast value for gray band. */
157  double getContrastM() { return m_mContrast; }
158 
159  /*! \brief Sets the rgb map values. */
160  void setRGBMap(std::map<RGBChannels, short>& rgbMap);
161 
162  /*! Sets the mapping from a particular input band to a particular output channel */
163  void setBChannelMapping(short bIn, RGBChannels bOut) { m_rgbMap[bOut] = bIn; }
164 
165  /*! Clears current mapping from bands to channel */
166  void clearRGBMap() { m_rgbMap.clear(); }
167 
168  /*! Returns the mapping from a particular input band to a particular output channel */
169  std::map<RGBChannels, short>& getRGBMap() { return m_rgbMap; }
170 
171  /*! Sets the mono band to be transformed */
172  void setSrcBand(short n) { m_monoBand = n; }
173 
174  /*! Gets the mono band to be transformed */
175  short getSrcBand() { return m_monoBand; }
176 
177  /*! Sets the destination of the mono band */
178  void setDestBand(short n) { m_monoBandOut = n; }
179 
180  /*! Gets the destination of the mono band */
181  short getDestBand() { return m_monoBandOut; }
182 
183  /*! Sets the categorize map information */
184  void setCategorizedMap(CategorizedMap map) { m_categorizeMap = map; }
185 
186  /*! Gets the categorize map information */
187  CategorizedMap& getCategorizedMap() { return m_categorizeMap; }
188 
189  /*! Sets the interpolate map information */
190  void setInterpolatedMap(InterpolatedMap map) { m_interpolateMap = map; }
191 
192  /*! Gets the categorize map information */
193  InterpolatedMap& getInterpolatedMap() { return m_interpolateMap; }
194 
195  /*!
196  \brief Set parameters of linear transformation
197 
198  \param vmin smallest input value
199  \param vmax largest input value
200  \param rmin smallest value of the output range
201  \param rmax largest value of the output range
202 
203  */
204  void setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax);
205 
206  /*! Returns the identifier of the transformation function currently set */
207  RasterTransfFunctions getTransfFunction();
208 
209  /*! Sets the associated transformation function from an identifier */
210  void setTransfFunction(RasterTransfFunctions func);
211 
212  /*! Sets the transformation method to be used */
213  void setTransfFunction(RasterTransform::TransformFunction transfFuncPtr) { m_transfFuncPtr = transfFuncPtr; }
214 
215  /*! Sets the transformation method to be used */
216  void setRGBAFunction(RasterTransform::RGBAFunction transfFuncPtr) { m_RGBAFuncPtr = transfFuncPtr; }
217 
218  /*! Applies the selected transformation method */
219  void apply(double icol, double ilin, double ocol, double olin) {(this->*m_transfFuncPtr)(icol,ilin,ocol,olin); }
220 
221  te::color::RGBAColor apply(double icol, double ilin){return (this->*m_RGBAFuncPtr)(icol,ilin); }
222 
223  protected:
224 
225  /*! This transformation repeats the value of the first band in input three bands of the output */
226  void setMono2ThreeBand(double icol, double ilin, double ocol, double olin);
227 
228  /*! This transformation repeats the value of the first band in input three bands of the output */
229  te::color::RGBAColor getMono2ThreeBand(double icol, double ilin);
230 
231  /*! This transformation is used to define a particular mapping from input bands to RGB channels */
232  void setExtractRGB(double icol, double ilin, double ocol, double olin);
233 
234  /*! This transformation is used to define a particular mapping from input bands to RGB channels */
235  te::color::RGBAColor getExtractRGB(double icol, double ilin);
236 
237  /*! This transformation repeats the value of the first band in input three bands of the output */
238  void setRed2ThreeBand(double icol, double ilin, double ocol, double olin);
239 
240  /*! This transformation repeats the value of the first band in input three bands of the output */
241  te::color::RGBAColor getRed2ThreeBand(double icol, double ilin);
242 
243  /*! This transformation repeats the value of the first band in input three bands of the output */
244  void setGreen2ThreeBand(double icol, double ilin, double ocol, double olin);
245 
246  /*! This transformation repeats the value of the first band in input three bands of the output */
247  te::color::RGBAColor getGreen2ThreeBand(double icol, double ilin);
248 
249  /*! This transformation repeats the value of the first band in input three bands of the output */
250  void setBlue2ThreeBand(double icol, double ilin, double ocol, double olin);
251 
252  /*! This transformation repeats the value of the first band in input three bands of the output */
253  te::color::RGBAColor getBlue2ThreeBand(double icol, double ilin);
254 
255  /*! This transformation get the value of the selected band in input and set the categorized value in output bands of the output */
256  void setCategorize(double icol, double ilin, double ocol, double olin);
257 
258  /*! This transformation get the value of the selected band in input and get the categorized value */
259  te::color::RGBAColor getCategorize(double icol, double ilin);
260 
261  /*! This transformation get the value of the selected band in input and set the interpolated value in output bands of the output */
262  void setInterpolate(double icol, double ilin, double ocol, double olin);
263 
264  /*! This transformation get the value of the selected band in input and get the interpolated value */
265  te::color::RGBAColor getInterpolate(double icol, double ilin);
266 
267  /*! This transformation repeats the value of the n band in input to b band in output */
268  void setBand2Band(double icol, double ilin, double ocol, double olin);
269 
270 
271  /*! Function used to adjust the value in raster range */
272  void fixValue(double& value);
273 
274  /*!
275  \brief Function used to check if value is or not a valid value
276 
277  \return True if the value is EQUAL to NoValue and false in other case.
278  */
279  bool checkNoValue(double& value, int band);
280 
281  /*! Function used to get the interpolated color given a pixel value */
282  te::color::RGBAColor getInterpolatedColor(double value);
283 
284  /*! Function used to get the categorized color given a pixel value */
285  te::color::RGBAColor getCategorizedColor(double value);
286 
287  private:
288 
289  te::rst::Raster* m_rasterIn; //!< Pointer to a input raster.
290  te::rst::Raster* m_rasterOut; //!< Pointer to a output raster.
291 
292  double m_transp; //!< Transparency factor
293  double m_gain; //!< Gain factor.
294  double m_offset; //!< Offset factor.
295  double m_rstMinValue; //!< Min value from input raster.
296  double m_rstMaxValue; //!< Max value from input raster.
297  double m_rContrast; //!< Contrast value used in red band.
298  double m_gContrast; //!< Contrast value used in green band.
299  double m_bContrast; //!< Contrast value used in blue band.
300  double m_mContrast; //!< Contrast value used in gray band.
301 
302  std::map<RGBChannels, short> m_rgbMap; //!< Map used to set the band order.
303  short m_monoBand; //!< Value for the gray band.
304  short m_monoBandOut; //!< Value for output gray band channel.
305 
306  TransformFunction m_transfFuncPtr; //!< Function used in transformation operation.
307  RGBAFunction m_RGBAFuncPtr; //!< Function used in transformation operation.
308 
309  CategorizedMap m_categorizeMap; //!< Attribute to define the categorized transformation.
310  InterpolatedMap m_interpolateMap; //!< Attribute to define the interpolated transformation.
311  };
312 
313  } // end namespace map
314 } // end namespace te
315 
316 #endif // __TERRALIB_MAPTOOLS_INTERNAL_RASTERTRANSFORM_H
CategorizedMap m_categorizeMap
Attribute to define the categorized transformation.
void setContrastM(double value)
Sets the constrast value for gray band.
void setCategorizedMap(CategorizedMap map)
void setTransparency(double value)
Sets the transparency.
double m_offset
Offset factor.
double getContrastM()
Gets the constrast value for gray band.
double m_rstMinValue
Min value from input raster.
void setRGBAFunction(RasterTransform::RGBAFunction transfFuncPtr)
void(RasterTransform::* TransformFunction)(double, double, double, double)
double m_gContrast
Contrast value used in green band.
double getContrastB()
Gets the constrast value for blue band.
te::rst::Raster * m_rasterIn
Pointer to a input raster.
double m_rstMaxValue
Max value from input raster.
short m_monoBand
Value for the gray band.
void setGain(double value)
Sets the gain.
te::rst::Raster * getInputRaster()
Gets the input raster.
#define TEMAPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:98
double m_mContrast
Contrast value used in gray band.
double m_transp
Transparency factor.
short m_monoBandOut
Value for output gray band channel.
void setOffset(double value)
Sets the offset.
double m_bContrast
Contrast value used in blue band.
te::color::RGBAColor(RasterTransform::* RGBAFunction)(double, double)
void setTransfFunction(RasterTransform::TransformFunction transfFuncPtr)
TransformFunction m_transfFuncPtr
Function used in transformation operation.
void setInterpolatedMap(InterpolatedMap map)
RGBChannels
The three channels of a display.
InterpolatedMap m_interpolateMap
Attribute to define the interpolated transformation.
std::pair< double, double > RasterThreshold
std::map< RasterThreshold, te::color::ColorBar > InterpolatedMap
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
double m_rContrast
Contrast value used in red band.
double getGain()
Gets the gain.
double getContrastR()
Gets the constrast value for red band.
te::rst::Raster * getOutputRaster()
Gets the output raster.
InterpolatedMap & getInterpolatedMap()
RGBAFunction m_RGBAFuncPtr
Function used in transformation operation.
std::map< RGBChannels, short > m_rgbMap
Map used to set the band order.
std::map< RasterThreshold, te::color::RGBAColor > CategorizedMap
std::map< RGBChannels, short > & getRGBMap()
te::rst::Raster * m_rasterOut
Pointer to a output raster.
void setContrastB(double value)
Sets the constrast value for blue band.
void setContrastR(double value)
Sets the constrast value for red band.
double getOffset()
Gets the offset.
void setContrastG(double value)
Sets the constrast value for green band.
A Raster Transform is a class that defines functions to transform a styled raster.
An abstract class for raster data strucutures.
Definition: Raster.h:70
void setBChannelMapping(short bIn, RGBChannels bOut)
te::color::RGBAColor apply(double icol, double ilin)
double getTransparency()
Gets the transparency.
void apply(double icol, double ilin, double ocol, double olin)
double m_gain
Gain factor.
double getContrastG()
Gets the constrast value for green band.
CategorizedMap & getCategorizedMap()