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