RasterTransformConfigurer.cpp
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 RasterTransformConfigurer.h
22 
23  \brief A Raster Transform configurer generates a Raster Transform given a RasterSymbolzier.
24 */
25 
26 // TerraLib
28 #include "Utils.h"
29 #include "../raster/Raster.h"
30 #include "../raster/Band.h"
31 #include "../raster/BandProperty.h"
32 #include "../raster/RasterProperty.h"
33 #include "../se/RasterSymbolizer.h"
34 #include "../se/ChannelSelection.h"
35 #include "../se/ContrastEnhancement.h"
36 #include "../se/SelectedChannel.h"
37 #include "../se/Utils.h"
38 #include "../se.h"
39 
40 #include <limits>
41 
42 
44  m_rstSymbolizer(rs),
45  m_rstTransform(rt)
46 {
47 }
48 
50 
52 {
53  assert(m_rstSymbolizer);
54 
56 
58  {
60  }
61 
63  {
65  }
66 }
67 
69 {
70  //get transparency
72  {
74 
76  }
77 
78  //get gain
80  {
81  double gain = te::se::GetDouble(m_rstSymbolizer->getGain());
82 
83  double curGain = m_rstTransform->getGain();
84 
85  curGain += gain;
86 
87  m_rstTransform->setGain(curGain);
88  }
89 
90  //get offset
92  {
93  double offset = te::se::GetDouble(m_rstSymbolizer->getOffset());
94 
95  double curOffset = m_rstTransform->getOffset();
96 
97  curOffset += offset;
98 
99  m_rstTransform->setOffset(curOffset);
100  }
101 }
102 
104 {
106 
108 
109  if(type == te::se::GRAY_COMPOSITION)
110  {
111  if(
113  &&
114  (
116  ==
118  )
119  )
120  {
122  }
123  else if(
125  m_rstTransform->getSrcBand() )->getProperty()->m_colorInterp
126  ==
128  )
129  {
131 
132  // Building a RecodedMap
133 
135  m_rstTransform->getSrcBand() )->getProperty();
136 
138  te::color::RGBAColor auxRGBACol;
139 
140  for( size_t palIndex = 0 ; palIndex < bandProp.m_palette.size() ; ++palIndex )
141  {
142  auxRGBACol.setColor(static_cast<int>(bandProp.m_palette[palIndex].c1),
143  static_cast<int>(bandProp.m_palette[palIndex].c2), static_cast<int>(bandProp.m_palette[palIndex].c3),
144  static_cast<int>(bandProp.m_palette[palIndex].c4)
145  );
146 
147  map[static_cast<int>(palIndex)] = auxRGBACol;
148  }
149 
151  }
152  else
153  {
155  }
156 
158  }
159  else if(type == te::se::RGB_COMPOSITION)
160  {
162 
164 
166 
168 
170  }
171  else if(type == te::se::RED_COMPOSITION)
172  {
174 
176 
178  }
179  else if(type == te::se::GREEN_COMPOSITION)
180  {
182 
184 
186  }
187  else if(type == te::se::BLUE_COMPOSITION)
188  {
190 
192 
194  }
195  else
196  {
198  }
199 
200  //check alpha channel
202  for (std::size_t t = 0; t < inputRaster->getNumberOfBands(); ++t)
203  {
204  if (inputRaster->getBand(t)->getProperty()->m_colorInterp == te::rst::AlphaCInt)
205  {
207  break;
208  }
209  }
210 }
211 
213 {
214  assert(se);
215 
216  int band = atoi(se->getSourceChannelName().c_str());
217 
218  m_rstTransform->setSrcBand(band);
219 
220  double gamma = getGammaProperty(se->getContrastEnhancement());
221 
222  m_rstTransform->setGammaM(gamma);
223 }
224 
226 {
227  assert(se);
228 
229  int band = atoi(se->getSourceChannelName().c_str());
230 
232 
233  double gamma = getGammaProperty(se->getContrastEnhancement());
234 
235  m_rstTransform->setGammaR(gamma);
236 }
237 
239 {
240  assert(se);
241 
242  int band = atoi(se->getSourceChannelName().c_str());
243 
245 
246  double gamma = getGammaProperty(se->getContrastEnhancement());
247 
248  m_rstTransform->setGammaG(gamma);
249 }
250 
252 {
253  assert(se);
254 
255  int band = atoi(se->getSourceChannelName().c_str());
256 
258 
259  double gamma = getGammaProperty(se->getContrastEnhancement());
260 
261  m_rstTransform->setGammaB(gamma);
262 }
263 
265 {
266  if(ce)
267  {
268  return ce->getGammaValue();
269  }
270  else
271  {
273  }
274 }
275 
277 {
279 
280  if(cs && cs->getGrayChannel())
281  {
283  }
284  else
285  {
286  return;
287  }
288 
290  {
292 
294  }
296  {
298 
300  }
301  else if (m_rstSymbolizer->getColorMap()->getRecode())
302  {
304 
306  }
307  else
308  {
310  }
311 }
312 
314 {
316 
317  std::vector<te::se::InterpolationPoint*> ip = interpolate->getInterpolationPoints();
318 
319  for(size_t i = 0; i < ip.size() - 1; ++i)
320  {
321  te::se::InterpolationPoint* ipItemInit = ip[i];
322 
323  std::string colorName = te::se::GetString(ipItemInit->getValue());
324  te::color::RGBAColor colorInit(colorName);
325  colorInit.setColor(colorInit.getRed(), colorInit.getGreen(), colorInit.getBlue());
326  double lowerLimit = ipItemInit->getData();
327 
328  te::se::InterpolationPoint* ipItemEnd = ip[i + 1];
329 
330  colorName = te::se::GetString(ipItemEnd->getValue());
331  te::color::RGBAColor colorEnd(colorName);
332  colorEnd.setColor(colorEnd.getRed(), colorEnd.getGreen(), colorEnd.getBlue());
333  double upperLimit = ipItemEnd->getData();
334 
335  te::color::ColorBar cb(colorInit, colorEnd, (int)(upperLimit - lowerLimit));
336 
337  map.insert(te::map::RasterTransform::InterpolatedMap::value_type(std::pair<double, double>(lowerLimit, upperLimit), cb));
338  }
339 
341 }
342 
344 {
346 
347  std::vector<te::se::ParameterValue*> t = caterogize->getThresholds();
348  std::vector<te::se::ParameterValue*> tV = caterogize->getThresholdValues();
349 
350  for(size_t i = 0; i < tV.size(); ++i)
351  {
352  double lowerLimit, upperLimit;
353 
354  if(i == 0)
355  {
356  lowerLimit = std::numeric_limits<double>::min();
357  upperLimit = te::se::GetDouble(t[i]);
358  }
359  else if(i == tV.size() - 1)
360  {
361  lowerLimit = te::se::GetDouble(t[i - 1]);
362  upperLimit = std::numeric_limits<double>::max();
363  }
364  else
365  {
366  lowerLimit = te::se::GetDouble(t[i - 1]);
367  upperLimit = te::se::GetDouble(t[i]);
368  }
369 
370  std::string colorName = te::se::GetString(tV[i]);
371  te::color::RGBAColor color(colorName);
372  color.setColor(color.getRed(), color.getGreen(), color.getBlue());
373 
374  map.insert(te::map::RasterTransform::CategorizedMap::value_type(std::pair<double, double>(lowerLimit, upperLimit), color));
375  }
376 
378 }
379 
381 {
383 
384  std::vector<te::se::MapItem*> mItems = recode->getMapItems();
385 
386  for (std::size_t i = 0; i < mItems.size(); ++i)
387  {
388  std::string colorName = te::se::GetString(mItems[i]->getValue());
389  te::color::RGBAColor color(colorName);
390  color.setColor(color.getRed(), color.getGreen(), color.getBlue());
391 
392  map.insert(te::map::RasterTransform::RecodedMap::value_type(static_cast<int>(mItems[i]->getData()), color));
393  }
394 
396 }
ParameterValue * getValue() const
void setTransfFunction(RasterTransfFunctions func)
Palette indexes color interpretation.
unsigned int band
A selected channel to be display.
void setGain(double value)
Sets the gain.
RasterTransformConfigurer(te::se::RasterSymbolizer *rs, te::map::RasterTransform *rt)
Constructor.
void setRecodedMap(RecodedMap map)
Alpha channel color interpretation.
The transformation of continuous values to distinct values (Categorize function). ...
Definition: Categorize.h:90
void getCategorizedMap(te::se::Categorize *caterogize)
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color.
Definition: RGBAColor.h:341
std::vector< ColorEntry > m_palette
The color palette.
Definition: BandProperty.h:142
void setTransparency(double value)
Sets the transparency.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
Interpolate * getInterpolate() const
Definition: ColorMap.cpp:84
A raster band description.
Definition: BandProperty.h:61
void getGrayChannelProperties(te::se::SelectedChannel *se)
te::se::RasterSymbolizer * m_rstSymbolizer
SE element that describes the raster style.
ParameterValue * getOffset() const
void setGammaG(double value)
Sets the constrast value for green band.
void configure()
Configure Transformation.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
te::se::ChannelSelection * getChannelSelection() const
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
const std::vector< InterpolationPoint * > & getInterpolationPoints() const
Definition: Interpolate.cpp:91
void getInterpolatedMap(te::se::Interpolate *interpolate)
SelectedChannel * getRedChannel() const
te::map::RasterTransform * m_rstTransform
Raster transformation object.
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
SelectedChannel * getBlueChannel() const
The transformation of continuous values to a number of values (Interpolate function).
Definition: Interpolate.h:88
void setOffset(double value)
Sets the offset 1.
double getOffset()
Gets the offset.
void setBChannelMapping(short bIn, RGBChannels bOut)
std::string getSourceChannelName() const
te::rst::Raster * getOutputRaster()
Gets the output raster.
const std::vector< ParameterValue * > & getThresholds() const
Definition: Categorize.cpp:109
ParameterValue * getGain() const
void getRedChannelProperties(te::se::SelectedChannel *se)
te::rst::Raster * getInputRaster()
Gets the input raster.
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
std::map< RasterThreshold, te::color::RGBAColor > CategorizedMap
void setCategorizedMap(CategorizedMap map)
BandProperty * getProperty()
Returns the band property.
ParameterValue * getOpacity() const
ContrastEnhancement defines the &#39;stretching&#39; of contrast for a channel of a false-color image or for ...
ColorCompositionType getColorCompositionType() const
Recode * getRecode() const
Definition: ColorMap.cpp:95
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
void getBlueChannelProperties(te::se::SelectedChannel *se)
double getGain() const
Gets the gain.
Transformation of discrete values to other values.
Definition: Recode.h:75
std::vector< MapItem * > getMapItems() const
Definition: Recode.cpp:73
ColorCompositionType
Allowed color compositions type.
void setGammaR(double value)
Sets the constrast value for red band.
std::map< int, te::color::RGBAColor > RecodedMap
#define TE_SE_DEFAULT_GAMMA_VALUE
It specifies the default gamma value.
SelectedChannel * getGreenChannel() const
ContrastEnhancement * getContrastEnhancement() const
They are used to define a graph of points.
std::map< RasterThreshold, te::color::ColorBar > InterpolatedMap
A Raster Transform configurer generates a Raster Transform given a RasterSymbolzier.
void setInterpolatedMap(InterpolatedMap map)
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
Categorize * getCategorize() const
Definition: ColorMap.cpp:73
It models the concept of color bar.
te::se::ColorMap * getColorMap() const
A Raster Transform is a class that defines functions to transform a styled raster.
double getGammaProperty(te::se::ContrastEnhancement *ce)
Utility functions for MapTools module.
void setGammaM(double value)
Sets the constrast value for gray band.
void getGreenChannelProperties(te::se::SelectedChannel *se)
SelectedChannel * getGrayChannel() const
ColorInterp m_colorInterp
The color interpretation.
Definition: BandProperty.h:140
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
const std::vector< ParameterValue * > & getThresholdValues() const
Definition: Categorize.cpp:114
void setGammaB(double value)
Sets the constrast value for blue band.
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...