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