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