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,
98  CONTRAST_TRANSF /*!< Apply a contrast method ( ContrastType ) to the given raster - Use the methods getGain, setOffset and setOffset2 to setup contrast parameters. */
99  };
100 
101  /*! \enum Allowed contrast types. */
103  {
104  LINEAR_CONTRAST, /*!< The histogram range will be changed to the supplied min/max range ( linear function ). */
105  SQUARE_CONTRAST, /*!< The contrasted image will be created by using a square function. */
106  SQUARE_ROOT_CONTRAST, /*!< The contrasted image will be created by using a square root function. */
107  LOG_CONTRAST /*!< The contrasted image will be created by using a log function. */
108  };
109 
110  public:
111 
112  /*!
113  \brief Constructor
114 
115  \param input
116  \param output
117 
118  \note
119  */
121 
122  /*! \brief Destructor. */
123  ~RasterTransform();
124 
125  /*! \brief Gets the input raster. */
126  te::rst::Raster* getInputRaster() { return m_rasterIn; }
127 
128  /*! \brief Gets the output raster. */
129  te::rst::Raster* getOutputRaster() { return m_rasterOut; }
130 
131  /*! \brief Sets the transparency. */
132  void setTransparency(double value) { m_transp = value; }
133 
134  /*! \brief Gets the transparency. */
135  double getTransparency() { return m_transp; }
136 
137  /*! \brief Sets the gain. */
138  void setGain(double value) { m_gain = value; }
139 
140  /*! \brief Gets the gain. */
141  double getGain() { return m_gain; }
142 
143  /*! \brief Sets the offset 1. */
144  void setOffset(double value) { m_offset = value; }
145 
146  /*!
147  \brief Set the current contrast type.
148  \param newType New contrast type.
149  */
150  void setContrastType( const ContrastType& newType );
151 
152  /*! \brief Gets the offset. */
153  double getOffset() { return m_offset; }
154 
155  /*! \brief Sets the constrast value for red band. */
156  void setContrastR(double value) { m_rContrast = value; }
157 
158  /*! \brief Gets the constrast value for red band. */
159  double getContrastR() { return m_rContrast; }
160 
161  /*! \brief Sets the constrast value for green band. */
162  void setContrastG(double value) { m_gContrast = value; }
163 
164  /*! \brief Gets the constrast value for green band. */
165  double getContrastG() { return m_gContrast; }
166 
167  /*! \brief Sets the constrast value for blue band. */
168  void setContrastB(double value) { m_bContrast = value; }
169 
170  /*! \brief Gets the constrast value for blue band. */
171  double getContrastB() { return m_bContrast; }
172 
173  /*! \brief Sets the constrast value for gray band. */
174  void setContrastM(double value) { m_mContrast = value; }
175 
176  /*! \brief Gets the constrast value for gray band. */
177  double getContrastM() { return m_mContrast; }
178 
179  /*! \brief Sets the rgb map values. */
180  void setRGBMap(std::map<RGBChannels, short>& rgbMap);
181 
182  /*! Sets the mapping from a particular input band to a particular output channel */
183  void setBChannelMapping(short bIn, RGBChannels bOut) { m_rgbMap[bOut] = bIn; }
184 
185  /*! Clears current mapping from bands to channel */
186  void clearRGBMap() { m_rgbMap.clear(); }
187 
188  /*! Returns the mapping from a particular input band to a particular output channel */
189  std::map<RGBChannels, short>& getRGBMap() { return m_rgbMap; }
190 
191  /*! Sets the mono band to be transformed */
192  void setSrcBand(short n) { m_monoBand = n; }
193 
194  /*! Gets the mono band to be transformed */
195  short getSrcBand() { return m_monoBand; }
196 
197  /*! Sets the destination of the mono band */
198  void setDestBand(short n) { m_monoBandOut = n; }
199 
200  /*! Gets the destination of the mono band */
201  short getDestBand() { return m_monoBandOut; }
202 
203  /*! Sets the categorize map information */
204  void setCategorizedMap(CategorizedMap map) { m_categorizeMap = map; }
205 
206  /*! Gets the categorize map information */
207  CategorizedMap& getCategorizedMap() { return m_categorizeMap; }
208 
209  /*! Sets the interpolate map information */
210  void setInterpolatedMap(InterpolatedMap map) { m_interpolateMap = map; }
211 
212  /*! Gets the categorize map information */
213  InterpolatedMap& getInterpolatedMap() { return m_interpolateMap; }
214 
215  /*! Sets the recode map information */
216  void setRecodedMap(RecodedMap map) { m_recodeMap = map; }
217 
218  /*! Gets the recode map information */
219  RecodedMap& getRecodedMap() { return m_recodeMap; }
220 
221  /*!
222  \brief Set parameters of linear transformation
223 
224  \param vmin smallest input value
225  \param vmax largest input value
226  \param rmin smallest value of the output range
227  \param rmax largest value of the output range
228 
229  */
230  void setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax);
231 
232  /*! Returns the identifier of the transformation function currently set */
233  RasterTransfFunctions getTransfFunction();
234 
235  /*! Sets the associated transformation function from an identifier */
236  void setTransfFunction(RasterTransfFunctions func);
237 
238  /*! Sets the transformation method to be used */
239  void setTransfFunction(RasterTransform::TransformFunction transfFuncPtr) { m_transfFuncPtr = transfFuncPtr; }
240 
241  /*! Sets the transformation method to be used */
242  void setRGBAFunction(RasterTransform::RGBAFunction transfFuncPtr) { m_RGBAFuncPtr = transfFuncPtr; }
243 
244  /*! Applies the selected transformation method */
245  void apply(double icol, double ilin, double ocol, double olin) {(this->*m_transfFuncPtr)(icol,ilin,ocol,olin); }
246 
247  te::color::RGBAColor apply(double icol, double ilin){return (this->*m_RGBAFuncPtr)(icol,ilin); }
248 
249  /*!
250  \brief Set gain and offset parameters to be used by the CONTRAST_TRANSF method.
251  \param contrastGains A vector of gains for each raster band.
252  \param contrastOffsets1 A vector of offsets1 for each raster band.
253  \param contrastOffsets2 A vector of offsets2 for each raster band.
254  */
255  void setContrastGainsAndOffsets( const std::vector< double >& contrastGains,
256  const std::vector< double >& contrastOffsets1,
257  const std::vector< double >& contrastOffsets2 );
258 
259  protected:
260 
261  /*!
262  \brief Configures the contrast function pointer.
263  \param contrastType Contrast type..
264  */
265  void setContrastFuncPtr(const RasterTransform::ContrastType contrastType );
266 
267  /*! This transformation repeats the value of the first band in input three bands of the output */
268  void setMono2ThreeBand(double icol, double ilin, double ocol, double olin);
269 
270  /*! This transformation repeats the value of the first band in input three bands of the output */
271  te::color::RGBAColor getMono2ThreeBand(double icol, double ilin);
272 
273  /*! This transformation is used to define a particular mapping from input bands to RGB channels */
274  void setExtractRGB(double icol, double ilin, double ocol, double olin);
275 
276  /*! This transformation is used to define a particular mapping from input bands to RGB channels */
277  te::color::RGBAColor getExtractRGB(double icol, double ilin);
278 
279  /*! This transformation is used to define a particular mapping from input bands to RGBA channels */
280  void setExtractRGBA(double icol, double ilin, double ocol, double olin);
281 
282  /*! This transformation is used to define a particular mapping from input bands to RGBA channels */
283  te::color::RGBAColor getExtractRGBA(double icol, double ilin);
284 
285  /*! This transformation repeats the value of the first band in input three bands of the output */
286  void setRed2ThreeBand(double icol, double ilin, double ocol, double olin);
287 
288  /*! This transformation repeats the value of the first band in input three bands of the output */
289  te::color::RGBAColor getRed2ThreeBand(double icol, double ilin);
290 
291  /*! This transformation repeats the value of the first band in input three bands of the output */
292  void setGreen2ThreeBand(double icol, double ilin, double ocol, double olin);
293 
294  /*! This transformation repeats the value of the first band in input three bands of the output */
295  te::color::RGBAColor getGreen2ThreeBand(double icol, double ilin);
296 
297  /*! This transformation repeats the value of the first band in input three bands of the output */
298  void setBlue2ThreeBand(double icol, double ilin, double ocol, double olin);
299 
300  /*! This transformation repeats the value of the first band in input three bands of the output */
301  te::color::RGBAColor getBlue2ThreeBand(double icol, double ilin);
302 
303  /*! This transformation get the value of the selected band in input and set the categorized value in output bands of the output */
304  void setCategorize(double icol, double ilin, double ocol, double olin);
305 
306  /*! This transformation get the value of the selected band in input and get the categorized value */
307  te::color::RGBAColor getCategorize(double icol, double ilin);
308 
309  /*! This transformation get the value of the selected band in input and set the interpolated value in output bands of the output */
310  void setInterpolate(double icol, double ilin, double ocol, double olin);
311 
312  /*! This transformation get the value of the selected band in input and get the interpolated value */
313  te::color::RGBAColor getInterpolate(double icol, double ilin);
314 
315  /*! This transformation get the value of the selected band in input and set the recoded value in output bands of the output */
316  void setRecode(double icol, double ilin, double ocol, double olin);
317 
318  /*! This transformation get the value of the selected band in input and get the recoded value */
319  te::color::RGBAColor getRecode(double icol, double ilin);
320 
321  /*! This transformation repeats the value of the n band in input to b band in output */
322  void setBand2Band(double icol, double ilin, double ocol, double olin);
323 
324  /*! This transformation aplies a linear contrast */
325  void setContrastLinear(double icol, double ilin, double ocol, double olin);
326 
327  /*! This transformation aplies a square contrast */
328  void setContrastSquare(double icol, double ilin, double ocol, double olin);
329 
330  /*! This transformation aplies a square root contrast */
331  void setContrastSquareRoot(double icol, double ilin, double ocol, double olin);
332 
333  /*! This transformation aplies a log contrast */
334  void setContrastLog(double icol, double ilin, double ocol, double olin);
335 
336  /*! Function used to adjust the value in raster range */
337  void fixValue(double& value);
338 
339  /*!
340  \brief Function used to check if value is or not a valid value
341 
342  \return True if the value is EQUAL to NoValue and false in other case.
343  */
344  bool checkNoValue(double& value, int band);
345 
346  /*! Function used to get the interpolated color given a pixel value */
347  te::color::RGBAColor getInterpolatedColor(double value);
348 
349  /*! Function used to get the categorized color given a pixel value */
350  te::color::RGBAColor getCategorizedColor(double value);
351 
352  /*! Function used to get the recoded color given a pixel value */
353  te::color::RGBAColor getRecodedColor(double value);
354 
355  private:
356 
357  te::rst::Raster* m_rasterIn; //!< Pointer to a input raster.
358  te::rst::Raster* m_rasterOut; //!< Pointer to a output raster.
359 
360  double m_transp; //!< Transparency factor
361  double m_gain; //!< Gain factor.
362  double m_offset; //!< Offset factor.
363  double m_rstMinValue; //!< Min value from input raster.
364  double m_rstMaxValue; //!< Max value from input raster.
365  double m_rContrast; //!< Contrast value used in red band.
366  double m_gContrast; //!< Contrast value used in green band.
367  double m_bContrast; //!< Contrast value used in blue band.
368  double m_mContrast; //!< Contrast value used in gray band.
369  ContrastType m_currentContrastType; //!< Current contrast type.
370 
371  // Internal variables used my methods: setContrast* methods
372  // They are not supposed to be used by other methods
376 
377  std::map<RGBChannels, short> m_rgbMap; //!< Map used to set the band order.
378  short m_monoBand; //!< Value for the gray band.
379  short m_monoBandOut; //!< Value for output gray band channel.
380 
381  TransformFunction m_transfFuncPtr; //!< Function used in transformation operation.
382  RGBAFunction m_RGBAFuncPtr; //!< Function used in transformation operation.
383 
384  CategorizedMap m_categorizeMap; //!< Attribute to define the categorized transformation.
385  InterpolatedMap m_interpolateMap; //!< Attribute to define the interpolated transformation.
386  RecodedMap m_recodeMap; //!< Attribute to define the recoded transformation.
387 
388  std::vector< double > m_contrastGains; //!< A vector of gains for each band used by the CONTRAST_TRANSF method.
389  std::vector< double > m_contrastOffsets1;//!< A vector of offsets1 for each band used by the CONTRAST_TRANSF method.
390  std::vector< double > m_contrastOffsets2;//!< A vector of offsets2 for each band used by the CONTRAST_TRANSF method.
391  };
392 
393  } // end namespace map
394 } // end namespace te
395 
396 #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.
std::size_t m_setContrast_bandsNumber
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 1.
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.
ContrastType m_currentContrastType
Current contrast type.
std::vector< double > m_contrastOffsets1
A vector of offsets1 for each band used by the CONTRAST_TRANSF method.
RGBAFunction m_RGBAFuncPtr
Function used in transformation operation.
double getContrastR()
Gets the constrast value for red band.
std::vector< double > m_contrastGains
A vector of gains for each band used by the CONTRAST_TRANSF method.
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
std::vector< double > m_contrastOffsets2
A vector of offsets2 for each band used by the CONTRAST_TRANSF method.
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.