All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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/RasterProperty.h"
31 #include "../se/RasterSymbolizer.h"
32 #include "../se/ChannelSelection.h"
33 #include "../se/ContrastEnhancement.h"
34 #include "../se/SelectedChannel.h"
35 #include "../se/Utils.h"
36 #include "../se.h"
37 
38 #include <limits>
39 
40 
42  m_rstSymbolizer(rs),
43  m_rstTransform(rt)
44 {
45 }
46 
48 {
49 }
50 
52 {
53  assert(m_rstSymbolizer);
54 
55  getGeneralProperties();
56 
57  if(m_rstSymbolizer->getChannelSelection())
58  {
59  getChannelSelection();
60  }
61 
62  if(m_rstSymbolizer->getColorMap())
63  {
64  getColorMapInformation();
65  }
66 }
67 
69 {
70  //get transparency
71  if(m_rstSymbolizer->getOpacity())
72  {
73  double transp = (double)TE_OPAQUE * te::se::GetDouble(m_rstSymbolizer->getOpacity());
74 
75  m_rstTransform->setTransparency(transp);
76  }
77 
78  //get gain
79  if(m_rstSymbolizer->getGain())
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
91  if(m_rstSymbolizer->getOffset())
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 {
105  te::se::ChannelSelection* cs = m_rstSymbolizer->getChannelSelection();
106 
108 
109  if(type == te::se::GRAY_COMPOSITION)
110  {
111  if((m_rstTransform->getInputRaster() && m_rstTransform->getOutputRaster()) &&
112  (m_rstTransform->getInputRaster()->getNumberOfBands() == m_rstTransform->getOutputRaster()->getNumberOfBands()))
113  m_rstTransform->setTransfFunction(te::map::RasterTransform::BAND2BAND_TRANSF);
114  else
115  m_rstTransform->setTransfFunction(te::map::RasterTransform::MONO2THREE_TRANSF);
116 
117  getGrayChannelProperties(cs->getGrayChannel());
118  }
119  else if(type == te::se::RGB_COMPOSITION)
120  {
121  m_rstTransform->setTransfFunction(te::map::RasterTransform::EXTRACT2RGB_TRANSF);
122 
123  m_rstTransform->clearRGBMap();
124 
125  getRedChannelProperties(cs->getRedChannel());
126 
127  getGreenChannelProperties(cs->getGreenChannel());
128 
129  getBlueChannelProperties(cs->getBlueChannel());
130  }
131  else if(type == te::se::RED_COMPOSITION)
132  {
133  m_rstTransform->setTransfFunction(te::map::RasterTransform::RED2THREE_TRANSF);
134 
135  m_rstTransform->clearRGBMap();
136 
137  getRedChannelProperties(cs->getRedChannel());
138  }
139  else if(type == te::se::GREEN_COMPOSITION)
140  {
141  m_rstTransform->setTransfFunction(te::map::RasterTransform::GREEN2THREE_TRANSF);
142 
143  m_rstTransform->clearRGBMap();
144 
145  getGreenChannelProperties(cs->getGreenChannel());
146  }
147  else if(type == te::se::BLUE_COMPOSITION)
148  {
149  m_rstTransform->setTransfFunction(te::map::RasterTransform::BLUE2THREE_TRANSF);
150 
151  m_rstTransform->clearRGBMap();
152 
153  getBlueChannelProperties(cs->getBlueChannel());
154  }
155  else
156  {
157  m_rstTransform->setTransfFunction(te::map::RasterTransform::NO_TRANSF);
158  }
159 }
160 
162 {
163  assert(se);
164 
165  int band = atoi(se->getSourceChannelName().c_str());
166 
167  m_rstTransform->setSrcBand(band);
168 
169  double gamma = getGammaProperty(se->getContrastEnhancement());
170 
171  m_rstTransform->setContrastM(gamma);
172 }
173 
175 {
176  assert(se);
177 
178  int band = atoi(se->getSourceChannelName().c_str());
179 
180  m_rstTransform->setBChannelMapping(band, te::map::RasterTransform::RED_CHANNEL);
181 
182  double gamma = getGammaProperty(se->getContrastEnhancement());
183 
184  m_rstTransform->setContrastR(gamma);
185 }
186 
188 {
189  assert(se);
190 
191  int band = atoi(se->getSourceChannelName().c_str());
192 
193  m_rstTransform->setBChannelMapping(band, te::map::RasterTransform::GREEN_CHANNEL);
194 
195  double gamma = getGammaProperty(se->getContrastEnhancement());
196 
197  m_rstTransform->setContrastG(gamma);
198 }
199 
201 {
202  assert(se);
203 
204  int band = atoi(se->getSourceChannelName().c_str());
205 
206  m_rstTransform->setBChannelMapping(band, te::map::RasterTransform::BLUE_CHANNEL);
207 
208  double gamma = getGammaProperty(se->getContrastEnhancement());
209 
210  m_rstTransform->setContrastB(gamma);
211 }
212 
214 {
215  if(ce)
216  {
217  return ce->getGammaValue();
218  }
219  else
220  {
222  }
223 }
224 
226 {
227  te::se::ChannelSelection* cs = m_rstSymbolizer->getChannelSelection();
228 
229  if(cs && cs->getGrayChannel())
230  {
231  getGrayChannelProperties(cs->getGrayChannel());
232  }
233  else
234  {
235  return;
236  }
237 
238  if(m_rstSymbolizer->getColorMap()->getCategorize())
239  {
240  m_rstTransform->setTransfFunction(te::map::RasterTransform::CATEGORIZE_TRANSF);
241 
242  getCategorizedMap(m_rstSymbolizer->getColorMap()->getCategorize());
243  }
244  else if(m_rstSymbolizer->getColorMap()->getInterpolate())
245  {
246  m_rstTransform->setTransfFunction(te::map::RasterTransform::INTERPOLATE_TRANSF);
247 
248  getInterpolatedMap(m_rstSymbolizer->getColorMap()->getInterpolate());
249  }
250  else
251  {
252  m_rstTransform->setTransfFunction(te::map::RasterTransform::NO_TRANSF);
253  }
254 }
255 
257 {
259 
260  std::vector<te::se::InterpolationPoint*> ip = interpolate->getInterpolationPoints();
261 
262  for(size_t i = 0; i < ip.size() - 1; ++i)
263  {
264  te::se::InterpolationPoint* ipItemInit = ip[i];
265 
266  std::string colorName = te::se::GetString(ipItemInit->getValue());
267  te::color::RGBAColor colorInit(colorName);
268  colorInit.setColor(colorInit.getRed(), colorInit.getGreen(), colorInit.getBlue());
269  double lowerLimit = ipItemInit->getData();
270 
271  te::se::InterpolationPoint* ipItemEnd = ip[i + 1];
272 
273  colorName = te::se::GetString(ipItemEnd->getValue());
274  te::color::RGBAColor colorEnd(colorName);
275  colorEnd.setColor(colorEnd.getRed(), colorEnd.getGreen(), colorEnd.getBlue());
276  double upperLimit = ipItemEnd->getData();
277 
278  te::color::ColorBar cb(colorInit, colorEnd, (int)(upperLimit - lowerLimit));
279 
280  map.insert(te::map::RasterTransform::InterpolatedMap::value_type(std::pair<double, double>(lowerLimit, upperLimit), cb));
281  }
282 
283  m_rstTransform->setInterpolatedMap(map);
284 }
285 
287 {
289 
290  std::vector<te::se::ParameterValue*> t = caterogize->getThresholds();
291  std::vector<te::se::ParameterValue*> tV = caterogize->getThresholdValues();
292 
293  for(size_t i = 0; i < tV.size(); ++i)
294  {
295  double lowerLimit, upperLimit;
296 
297  if(i == 0)
298  {
299  lowerLimit = std::numeric_limits<double>::min();
300  upperLimit = te::se::GetDouble(t[i]);
301  }
302  else if(i == tV.size() - 1)
303  {
304  lowerLimit = te::se::GetDouble(t[i - 1]);
305  upperLimit = std::numeric_limits<double>::max();
306  }
307  else
308  {
309  lowerLimit = te::se::GetDouble(t[i - 1]);
310  upperLimit = te::se::GetDouble(t[i]);
311  }
312 
313  std::string colorName = te::se::GetString(tV[i]);
314  te::color::RGBAColor color(colorName);
315  color.setColor(color.getRed(), color.getGreen(), color.getBlue());
316 
317  map.insert(te::map::RasterTransform::CategorizedMap::value_type(std::pair<double, double>(lowerLimit, upperLimit), color));
318  }
319 
320  m_rstTransform->setCategorizedMap(map);
321 }
ParameterValue * getValue() const
A selected channel to be display.
RasterTransformConfigurer(te::se::RasterSymbolizer *rs, te::map::RasterTransform *rt)
Constructor.
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:329
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:295
void getGrayChannelProperties(te::se::SelectedChannel *se)
void configure()
Configure Transformation.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:305
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:300
const std::vector< InterpolationPoint * > & getInterpolationPoints() const
Definition: Interpolate.cpp:91
void getInterpolatedMap(te::se::Interpolate *interpolate)
SelectedChannel * getRedChannel() const
TESEEXPORT double GetDouble(const te::se::ParameterValue *param)
It gets the parameter value as a double.
Definition: Utils.cpp:448
SelectedChannel * getBlueChannel() const
The transformation of continuous values to a number of values (Interpolate function).
Definition: Interpolate.h:88
std::string getSourceChannelName() const
const std::vector< ParameterValue * > & getThresholds() const
Definition: Categorize.cpp:109
void getRedChannelProperties(te::se::SelectedChannel *se)
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
Definition: Config.h:39
std::map< RasterThreshold, te::color::RGBAColor > CategorizedMap
ContrastEnhancement defines the 'stretching' of contrast for a channel of a false-color image or for ...
ColorCompositionType getColorCompositionType() const
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
void getBlueChannelProperties(te::se::SelectedChannel *se)
ColorCompositionType
Allowed color compositions type.
Definition: Enums.h:38
Utility functions for MapTools module.
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.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
#define TE_SE_DEFAULT_GAMMA_VALUE
It specifies the default gamma value.
Definition: Config.h:107
It models the concept of color bar.
Definition: ColorBar.h:49
A Raster Transform is a class that defines functions to transform a styled raster.
double getGammaProperty(te::se::ContrastEnhancement *ce)
void getGreenChannelProperties(te::se::SelectedChannel *se)
SelectedChannel * getGrayChannel() const
TESEEXPORT std::string GetString(const te::se::ParameterValue *param)
It gets the parameter value as a string.
Definition: Utils.cpp:453
const std::vector< ParameterValue * > & getThresholdValues() const
Definition: Categorize.cpp:114
ChannelSelection specifies the false-color channel selection for a multi-spectral raster source (such...