RasterTransform.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 RasterTransform.h
22 
23  \brief A Raster Transform is a class that defines functions to transform a styled raster.
24 */
25 
26 // TerraLib
27 #include "RasterTransform.h"
28 
29 #include "../raster/RasterProperty.h"
30 #include "../se/RasterSymbolizer.h"
31 #include "Exception.h"
32 
33 // Boost
34 #include <boost/math/special_functions/fpclassify.hpp>
35 
36 // STL
37 #include <limits>
38 #include <algorithm>
39 
41  m_rasterIn(input),
42  m_rasterOut(output),
43  m_currentContrastType( LINEAR_CONTRAST ),
44  m_contrastTransfFuncPtr( &RasterTransform::applyLinearContrast ),
45  m_transp(TE_OPAQUE),
46  m_monoBand(0),
47  m_monoBandOut(0),
48  m_transfFuncPtr(&RasterTransform::setExtractRGB),
49  m_RGBAFuncPtr(&RasterTransform::getExtractRGB)
50 {
51  m_rstMinValue.resize(std::max( static_cast<size_t>(4), input->getNumberOfBands() ), -std::numeric_limits<double>::max());
52  m_rstMaxValue.resize(std::max( static_cast<size_t>(4), input->getNumberOfBands() ), std::numeric_limits<double>::max());
53 
54  m_gamma.resize( std::max( static_cast<size_t>(4), input->getNumberOfBands() ), 1.0 );
55  m_contrastGains.resize( std::max( static_cast<size_t>(4), input->getNumberOfBands() ), 1.0 );
56  m_contrastOffsets1.resize( std::max( static_cast<size_t>(4), input->getNumberOfBands() ), 0.0 );
57  m_contrastOffsets2.resize( std::max( static_cast<size_t>(4), input->getNumberOfBands() ), 0.0 );
58 }
59 
61 {
62  m_categorizeMap.clear();
63  m_interpolateMap.clear();
64  m_recodeMap.clear();
65  m_rgbMap.clear();
66 }
67 
69 {
70  std::fill( m_contrastGains.begin(), m_contrastGains.end(), value );
71 }
72 
74 {
75  assert( !m_contrastGains.empty() );
76  return m_contrastGains[ 0 ];
77 }
78 
80 {
81  std::fill( m_contrastOffsets1.begin(), m_contrastOffsets1.end(), value );
82  std::fill( m_contrastOffsets2.begin(), m_contrastOffsets2.end(), value );
83 }
84 
86 {
87  m_currentContrastType = newType;
89 }
90 
92 {
93  assert( !m_contrastOffsets1.empty() );
94  return m_contrastOffsets1[ 0 ];
95 }
96 
98 {
99  assert( m_gamma.size() > RED_CHANNEL );
100  m_gamma[ RED_CHANNEL ] = value;
101 }
102 
104 {
105  assert( m_gamma.size() > RED_CHANNEL );
106  return m_gamma[ RED_CHANNEL ];
107 }
108 
110 {
111  assert( m_gamma.size() > GREEN_CHANNEL );
112  m_gamma[ GREEN_CHANNEL ] = value;
113 }
114 
116 {
117  assert( m_gamma.size() > GREEN_CHANNEL );
118  return m_gamma[ GREEN_CHANNEL ];
119 }
120 
122 {
123  assert( m_gamma.size() > BLUE_CHANNEL );
124  m_gamma[ BLUE_CHANNEL ] = value;
125 }
126 
128 {
129  assert( m_gamma.size() > BLUE_CHANNEL );
130  return m_gamma[ BLUE_CHANNEL ];
131 }
132 
134 {
135  assert( m_gamma.size() > static_cast<std::size_t>(m_monoBand) );
136  m_gamma[ static_cast<size_t>(m_monoBand) ] = value;
137 }
138 
140 {
141  assert( m_gamma.size() > static_cast<std::size_t>(m_monoBand) );
142  return m_gamma[ static_cast<size_t>(m_monoBand) ];
143 }
144 
145 void te::map::RasterTransform::setRGBMap(std::map<RGBChannels, short>& /*rgbMap*/)
146 {
147  m_rgbMap.clear();
148  m_rgbMap[RED_CHANNEL] = -1;
149  m_rgbMap[GREEN_CHANNEL] = -1;
150  m_rgbMap[BLUE_CHANNEL] = -1;
151  m_rgbMap[ALPHA_CHANNEL] = -1;
152 
153  std::map<RGBChannels,short>::iterator it = m_rgbMap.begin();
154  while (it != m_rgbMap.end())
155  {
156  if (it->first == RED_CHANNEL)
157  m_rgbMap[RED_CHANNEL] = it->second;
158 
159  else if (it->first == GREEN_CHANNEL)
160  m_rgbMap[GREEN_CHANNEL] = it->second;
161 
162  else if (it->first == BLUE_CHANNEL)
163  m_rgbMap[BLUE_CHANNEL] = it->second;
164 
165  else if (it->first == ALPHA_CHANNEL)
166  m_rgbMap[ALPHA_CHANNEL] = it->second;
167 
168  ++it;
169  }
170 }
171 
172 void te::map::RasterTransform::setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax)
173 {
174  std::fill(m_rstMinValue.begin(), m_rstMinValue.end(), rmin);
175  std::fill(m_rstMaxValue.begin(), m_rstMaxValue.end(), rmax);
176 
177  double gain = 1.0;
178  double offset = 0.0;
179 
180  if(vmax == vmin)
181  {
182  gain = 1.0;
183  offset = 0.0;
184  }
185  else
186  {
187  gain = static_cast<double>(rmax-rmin)/(vmax-vmin);
188 
189  if(boost::math::isnan(gain) || boost::math::isinf(gain))
190  {
191  gain = 1.0;
192  offset = 0.0;
193  }
194  else
195  {
196  offset = -1*gain*vmin+rmin;
197  }
198  }
199 
200  std::fill( m_contrastGains.begin(), m_contrastGains.end(), gain );
201  std::fill( m_contrastOffsets1.begin(), m_contrastOffsets1.end(), offset );
202  std::fill( m_contrastOffsets2.begin(), m_contrastOffsets2.end(), offset );
203 }
204 
205 void te::map::RasterTransform::setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax, int band)
206 {
207  m_rstMinValue[static_cast<size_t>(band)] = rmin;
208  m_rstMaxValue[static_cast<size_t>(band)] = rmax;
209 
210  double gain = 1.0;
211  double offset = 0.0;
212 
213  if (vmax == vmin)
214  {
215  gain = 1.0;
216  offset = 0.0;
217  }
218  else
219  {
220  gain = static_cast<double>(rmax - rmin) / (vmax - vmin);
221 
222  if (boost::math::isnan(gain) || boost::math::isinf(gain))
223  {
224  gain = 1.0;
225  offset = 0.0;
226  }
227  else
228  {
229  offset = -1 * gain*vmin + rmin;
230  }
231  }
232 
233  m_contrastGains[static_cast<size_t>(band)] = gain;
234  m_contrastOffsets1[static_cast<size_t>(band)] = offset;
235  m_contrastOffsets2[static_cast<size_t>(band)] = offset;
236 }
237 
239 {
240  if (m_transfFuncPtr == nullptr || m_RGBAFuncPtr)
241  {
242  return NO_TRANSF;
243  }
246  {
247  return MONO2THREE_TRANSF;
248  }
251  {
252  return EXTRACT2RGB_TRANSF;
253  }
256  {
257  return RED2THREE_TRANSF;
258  }
261  {
262  return GREEN2THREE_TRANSF;
263  }
266  {
267  return BLUE2THREE_TRANSF;
268  }
271  {
272  return CATEGORIZE_TRANSF;
273  }
276  {
277  return INTERPOLATE_TRANSF;
278  }
281  {
282  return RECODE_TRANSF;
283  }
285  {
286  return BAND2BAND_TRANSF;
287  }
288  else
289  {
290  return NO_TRANSF;
291  }
292 }
293 
295 {
296  if (func == MONO2THREE_TRANSF)
297  {
300  }
301  else if (func == EXTRACT2RGB_TRANSF)
302  {
305  }
306  else if (func == RED2THREE_TRANSF)
307  {
310  }
311  else if (func == GREEN2THREE_TRANSF)
312  {
315  }
316  else if (func == BLUE2THREE_TRANSF)
317  {
320  }
321  else if (func == CATEGORIZE_TRANSF)
322  {
325  }
326  else if (func == INTERPOLATE_TRANSF)
327  {
330  }
331  else if (func == RECODE_TRANSF)
332  {
335  }
336  else if (func == BAND2BAND_TRANSF)
337  {
339  m_RGBAFuncPtr = nullptr;
340  }
341  else if (func == EXTRACT2RGBA_TRANSF)
342  {
345  }
346  else
347  {
348  m_transfFuncPtr = nullptr;
349  m_RGBAFuncPtr = nullptr;
350  }
351 }
352 
354  const std::vector< double >& contrastGains,
355  const std::vector< double >& contrastOffsets1,
356  const std::vector< double >& contrastOffsets2 )
357 {
358  if(
359  ( contrastGains.size() != m_rasterIn->getNumberOfBands() )
360  ||
361  ( contrastOffsets1.size() != m_rasterIn->getNumberOfBands() )
362  ||
363  ( contrastOffsets2.size() != m_rasterIn->getNumberOfBands() )
364  )
365  {
366  throw Exception(TE_TR("Invalid vector size"));
367  }
368 
369  m_contrastGains = contrastGains;
370  m_contrastOffsets1 = contrastOffsets1;
371  m_contrastOffsets2 = contrastOffsets2;
372 }
373 
375  const RasterTransform::ContrastType contrastType )
376 {
377  switch( contrastType )
378  {
379  case LINEAR_CONTRAST :
380  {
382  break;
383  }
384  case SQUARE_CONTRAST :
385  {
387  break;
388  }
389  case SQUARE_ROOT_CONTRAST :
390  {
392  break;
393  }
394  case LOG_CONTRAST :
395  {
397  break;
398  }
399  }
400 }
401 
402 void te::map::RasterTransform::setMono2ThreeBand(double icol, double ilin, double ocol, double olin)
403 {
404  double val;
405 
406  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
407 
408  if(checkNoValue(val, m_monoBand) == false)
409  {
410  (this->*(m_contrastTransfFuncPtr))( static_cast<unsigned int>(m_monoBand), val, val );
411 
412  val *= m_gamma[ static_cast<size_t>(m_monoBand) ];
413 
414  fixValue(val, m_monoBand);
415 
416  std::vector<double> vecValues;
417  vecValues.resize(3, val);
418 
419  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
420  }
421 }
422 
424 {
425  double val;
426 
427  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val,static_cast<unsigned int>( m_monoBand));
428 
429  if(checkNoValue(val, m_monoBand) == false)
430  {
431  (this->*(m_contrastTransfFuncPtr))( static_cast<unsigned int>(m_monoBand), val, val );
432 
433  val *= m_gamma[ static_cast<size_t>(m_monoBand) ];
434 
435  fixValue(val, m_monoBand);
436 
437  if(std::isnan(val))
438  {
439  return te::color::RGBAColor();
440  }
441 
442  double transp = checkAlphaValue(icol, ilin);
443 
444  te::color::RGBAColor c(static_cast<int>(val), static_cast<int>(val), static_cast<int>(val), static_cast<int>(transp));
445 
446  return c;
447  }
448 
449  return te::color::RGBAColor();
450 }
451 
452 void te::map::RasterTransform::setExtractRGB(double icol, double ilin, double ocol, double olin)
453 {
454  double valR, valG, valB;
455 
456  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valR, static_cast<size_t>(m_rgbMap[RED_CHANNEL]));
457  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valG, static_cast<size_t>(m_rgbMap[GREEN_CHANNEL]));
458  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valB, static_cast<size_t>(m_rgbMap[BLUE_CHANNEL]));
459 
460  if(checkNoValue(valR, m_rgbMap[RED_CHANNEL]) == false ||
461  checkNoValue(valG, m_rgbMap[GREEN_CHANNEL]) == false ||
462  checkNoValue(valB, m_rgbMap[BLUE_CHANNEL]) == false)
463  {
464  std::vector<double> vecValues;
465 
466  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[RED_CHANNEL]), valR, valR);
467  valR *= m_gamma[ RED_CHANNEL ];
468  fixValue(valR, m_rgbMap[RED_CHANNEL]);
469  vecValues.push_back(valR);
470 
471  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[GREEN_CHANNEL]), valG, valG);
472  valG *= m_gamma[ GREEN_CHANNEL ];
473  fixValue(valG, m_rgbMap[GREEN_CHANNEL]);
474  vecValues.push_back(valG);
475 
476  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[BLUE_CHANNEL]), valB, valB);
477  valB *= m_gamma[ BLUE_CHANNEL ];
478  fixValue(valB, m_rgbMap[BLUE_CHANNEL]);
479  vecValues.push_back(valB);
480 
481  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
482  }
483 }
484 
486 {
487  double valR, valG, valB;
488 
489  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valR, static_cast<size_t>(m_rgbMap[RED_CHANNEL]));
490  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valG, static_cast<size_t>(m_rgbMap[GREEN_CHANNEL]));
491  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valB, static_cast<size_t>(m_rgbMap[BLUE_CHANNEL]));
492 
493  if(checkNoValue(valR, m_rgbMap[RED_CHANNEL]) == false ||
494  checkNoValue(valG, m_rgbMap[GREEN_CHANNEL]) == false ||
495  checkNoValue(valB, m_rgbMap[BLUE_CHANNEL]) == false)
496  {
497  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[RED_CHANNEL]), valR, valR);
498  valR *= m_gamma[ RED_CHANNEL ];
499  fixValue(valR, m_rgbMap[RED_CHANNEL]);
500 
501  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[GREEN_CHANNEL]), valG, valG);
502  valG *= m_gamma[ GREEN_CHANNEL ];
503  fixValue(valG, m_rgbMap[GREEN_CHANNEL]);
504 
505  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[BLUE_CHANNEL]), valB, valB);
506  valB *= m_gamma[ BLUE_CHANNEL ];
507  fixValue(valB, m_rgbMap[BLUE_CHANNEL]);
508 
509  double transp = checkAlphaValue(icol, ilin);
510 
511  te::color::RGBAColor c(static_cast<int>(valR), static_cast<int>(valG), static_cast<int>(valB), static_cast<int>(transp));
512 
513  return c;
514  }
515 
516  return te::color::RGBAColor();
517 }
518 
519 void te::map::RasterTransform::setExtractRGBA(double icol, double ilin, double ocol, double olin)
520 {
521  double valR, valG, valB, valA;
522 
523  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valR, static_cast<size_t>(m_rgbMap[RED_CHANNEL]));
524  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valG, static_cast<size_t>(m_rgbMap[GREEN_CHANNEL]));
525  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valB, static_cast<size_t>(m_rgbMap[BLUE_CHANNEL]));
526  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valA, static_cast<size_t>(m_rgbMap[ALPHA_CHANNEL]));
527 
528  if(checkNoValue(valR, m_rgbMap[RED_CHANNEL]) == false ||
529  checkNoValue(valG, m_rgbMap[GREEN_CHANNEL]) == false ||
530  checkNoValue(valB, m_rgbMap[BLUE_CHANNEL]) == false ||
531  checkNoValue(valA, m_rgbMap[ALPHA_CHANNEL]) == false)
532  {
533  std::vector<double> vecValues;
534 
535  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[RED_CHANNEL]), valR, valR);
536  valR *= m_gamma[ RED_CHANNEL ];
537  fixValue(valR, m_rgbMap[RED_CHANNEL]);
538  vecValues.push_back(valR);
539 
540  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[GREEN_CHANNEL]), valG, valG);
541  valG *= m_gamma[ GREEN_CHANNEL ];
542  fixValue(valG, m_rgbMap[GREEN_CHANNEL]);
543  vecValues.push_back(valG);
544 
545  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[BLUE_CHANNEL]), valB, valB);
546  valB *= m_gamma[ BLUE_CHANNEL ];
547  fixValue(valB, m_rgbMap[BLUE_CHANNEL]);
548  vecValues.push_back(valB);
549 
550  fixValue(valA, m_rgbMap[ALPHA_CHANNEL]);
551  vecValues.push_back(valB);
552 
553  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
554  }
555 }
556 
558 {
559  double valR, valG, valB, valA;
560 
561  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valR, static_cast<size_t>(m_rgbMap[RED_CHANNEL]));
562  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valG, static_cast<size_t>(m_rgbMap[GREEN_CHANNEL]));
563  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valB, static_cast<size_t>(m_rgbMap[BLUE_CHANNEL]));
564  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), valA, static_cast<size_t>(m_rgbMap[ALPHA_CHANNEL]));
565 
566  if(checkNoValue(valR, m_rgbMap[RED_CHANNEL]) == false ||
567  checkNoValue(valG, m_rgbMap[GREEN_CHANNEL]) == false ||
568  checkNoValue(valB, m_rgbMap[BLUE_CHANNEL]) == false ||
569  checkNoValue(valA, m_rgbMap[ALPHA_CHANNEL]) == false)
570  {
571  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[RED_CHANNEL]), valR, valR);
572  valR *= m_gamma[ RED_CHANNEL ];
573  fixValue(valR, m_rgbMap[RED_CHANNEL]);
574 
575  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[GREEN_CHANNEL]), valG, valG);
576  valG *= m_gamma[ GREEN_CHANNEL ];
577  fixValue(valG, m_rgbMap[GREEN_CHANNEL]);
578 
579  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[BLUE_CHANNEL]), valB, valB);
580  valB *= m_gamma[ BLUE_CHANNEL ];
581  fixValue(valB, m_rgbMap[BLUE_CHANNEL]);
582 
583  fixValue(valA, m_rgbMap[ALPHA_CHANNEL]);
584 
585  if(valA < m_transp)
586  return te::color::RGBAColor(static_cast<int>(valR), static_cast<int>(valG), static_cast<int>(valB), static_cast<int>(valA));
587  else
588  return te::color::RGBAColor(static_cast<int>(valR), static_cast<int>(valG), static_cast<int>(valB), static_cast<int>(m_transp));
589  }
590 
591  return te::color::RGBAColor();
592 }
593 
594 void te::map::RasterTransform::setRed2ThreeBand(double icol, double ilin, double ocol, double olin)
595 {
596  double val;
597 
598  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_rgbMap[RED_CHANNEL]));
599 
600  if(checkNoValue(val, m_rgbMap[RED_CHANNEL]) == false)
601  {
602  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[RED_CHANNEL]), val, val);
603  val *= m_gamma[ RED_CHANNEL ];
604  fixValue(val, m_rgbMap[RED_CHANNEL]);
605 
606  std::vector<double> vecValues;
607  vecValues.push_back(val);
608  vecValues.push_back(0.);
609  vecValues.push_back(0.);
610 
611  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
612  }
613 }
614 
616 {
617  double val;
618 
619  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_rgbMap[RED_CHANNEL]));
620 
621  if(checkNoValue(val, m_rgbMap[RED_CHANNEL]) == false)
622  {
623  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[RED_CHANNEL]), val, val);
624  val *= m_gamma[ RED_CHANNEL ];
625  fixValue(val, m_rgbMap[RED_CHANNEL]);
626 
627  double transp = checkAlphaValue(icol, ilin);
628 
629  te::color::RGBAColor c(static_cast<int>(val), static_cast<int>(0.), static_cast<int>(0.), static_cast<int>(transp));
630 
631  return c;
632 
633  }
634 
635  return te::color::RGBAColor();
636 }
637 
638 void te::map::RasterTransform::setGreen2ThreeBand(double icol, double ilin, double ocol, double olin)
639 {
640  double val;
641 
642  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_rgbMap[GREEN_CHANNEL]));
643 
644  if(checkNoValue(val, m_rgbMap[GREEN_CHANNEL]) == false)
645  {
646  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[GREEN_CHANNEL]), val, val);
647  val *= m_gamma[ GREEN_CHANNEL ];
648  fixValue(val, m_rgbMap[GREEN_CHANNEL]);
649 
650  std::vector<double> vecValues;
651  vecValues.push_back(0.);
652  vecValues.push_back(val);
653  vecValues.push_back(0.);
654 
655  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
656  }
657 }
658 
660 {
661  double val;
662 
663  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_rgbMap[GREEN_CHANNEL]));
664 
665  if(checkNoValue(val, m_rgbMap[GREEN_CHANNEL]) == false)
666  {
667  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[GREEN_CHANNEL]), val, val);
668  val *= m_gamma[ GREEN_CHANNEL ];
669  fixValue(val, m_rgbMap[GREEN_CHANNEL]);
670 
671  double transp = checkAlphaValue(icol, ilin);
672 
673  te::color::RGBAColor c(static_cast<int>(0.), static_cast<int>(val), static_cast<int>(0.), static_cast<int>(transp));
674 
675  return c;
676 
677  }
678 
679  return te::color::RGBAColor();
680 }
681 
682 void te::map::RasterTransform::setBlue2ThreeBand(double icol, double ilin, double ocol, double olin)
683 {
684  double val;
685 
686  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_rgbMap[BLUE_CHANNEL]));
687 
688  if(checkNoValue(val, m_rgbMap[BLUE_CHANNEL]) == false)
689  {
690  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[BLUE_CHANNEL]), val, val);
691  val *= m_gamma[ BLUE_CHANNEL ];
692  fixValue(val, m_rgbMap[BLUE_CHANNEL]);
693 
694  std::vector<double> vecValues;
695  vecValues.push_back(0.);
696  vecValues.push_back(0.);
697  vecValues.push_back(val);
698 
699  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
700  }
701 }
702 
704 {
705  double val;
706 
707  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_rgbMap[BLUE_CHANNEL]));
708 
709  if(checkNoValue(val, m_rgbMap[BLUE_CHANNEL]) == false)
710  {
711  (this->*(m_contrastTransfFuncPtr))(static_cast<unsigned int>(m_rgbMap[BLUE_CHANNEL]), val, val);
712  val *= m_gamma[ BLUE_CHANNEL ];
713  fixValue(val, m_rgbMap[BLUE_CHANNEL]);
714 
715  double transp = checkAlphaValue(icol, ilin);
716 
717  te::color::RGBAColor c(static_cast<int>(0.), static_cast<int>(0.), static_cast<int>(val), static_cast<int>(transp));
718 
719  return c;
720 
721  }
722 
723  return te::color::RGBAColor();
724 }
725 
726 void te::map::RasterTransform::setCategorize(double icol, double ilin, double ocol, double olin)
727 {
728  double val;
729 
730  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
731 
733 
734  std::vector<double> vecValues;
735  vecValues.push_back(c.getRed());
736  vecValues.push_back(c.getGreen());
737  vecValues.push_back(c.getBlue());
738 
739  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
740 }
741 
743 {
744  double val;
745 
746  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
747 
748  if(checkNoValue(val, m_monoBand) == false)
749  return getCategorizedColor(val);
750 
751  return te::color::RGBAColor();
752 }
753 
754 void te::map::RasterTransform::setInterpolate(double icol, double ilin, double ocol, double olin)
755 {
756  double val;
757 
758  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
759 
761 
762  std::vector<double> vecValues;
763  vecValues.push_back(c.getRed());
764  vecValues.push_back(c.getGreen());
765  vecValues.push_back(c.getBlue());
766 
767  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
768 }
769 
771 {
772  double val;
773 
774  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
775 
776  if(checkNoValue(val, m_monoBand) == false)
777  return getInterpolatedColor(val);
778 
779  return te::color::RGBAColor();
780 }
781 
782 void te::map::RasterTransform::setRecode(double icol, double ilin, double ocol, double olin)
783 {
784  double val;
785 
786  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
787 
789 
790  std::vector<double> vecValues;
791  vecValues.push_back(c.getRed());
792  vecValues.push_back(c.getGreen());
793  vecValues.push_back(c.getBlue());
794 
795  m_rasterOut->setValues(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), vecValues);
796 }
797 
799 {
800  double val;
801 
802  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, static_cast<size_t>(m_monoBand));
803 
804  if (checkNoValue(val, m_monoBand) == false)
805  return getRecodedColor(val);
806 
807  return te::color::RGBAColor();
808 }
809 
810 void te::map::RasterTransform::setBand2Band(double icol, double ilin, double ocol, double olin)
811 {
812  double val;
813 
814  for(std::size_t t = 0; t < m_rasterIn->getNumberOfBands(); ++t)
815  {
816  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), val, t);
817 
818  if(checkNoValue(val, static_cast<int>(t) == false))
819  {
820  (this->*(m_contrastTransfFuncPtr))( static_cast<unsigned int>(t), val, val );
821  val *= m_gamma[ t ];
822 
823  short band = static_cast<short>(t);
824  fixValue(val, band);
825 
826  m_rasterOut->setValue(static_cast<unsigned int>(ocol), static_cast<unsigned int>(olin), val, t);
827  }
828  }
829 }
830 
831 double te::map::RasterTransform::checkAlphaValue(double icol, double ilin)
832 {
833  std::map<RGBChannels, short>::iterator it = m_rgbMap.find(ALPHA_CHANNEL);
834 
835  if (it != m_rgbMap.end() && it->second != -1)
836  {
837  double transp = 0.;
838  m_rasterIn->getValue(static_cast<unsigned int>(icol), static_cast<unsigned int>(ilin), transp, static_cast<size_t>(m_rgbMap[ALPHA_CHANNEL]));
839 
840  if (transp < m_transp)
841  return transp;
842  else
843  return m_transp;
844  }
845 
846  return m_transp;
847 }
848 
850 {
851  InterpolatedMap::iterator it = m_interpolateMap.begin();
852 
853  while(it != m_interpolateMap.end())
854  {
855  RasterThreshold rt = it->first;
856 
857  if(rt.first<= value && rt.second > value)
858  {
859  int distance = int(value - it->first.first);
860 
861  if(distance < 0)
862  {
863  distance = 0;
864  }
865  else if(distance >= static_cast<int>(it->second.getColorBar().size()))
866  {
867  distance = static_cast<int>(it->second.getColorBar().size() - 1);
868  }
869 
870  return it->second.getColorBar()[static_cast<size_t>(distance)];
871  }
872 
873  ++it;
874  }
875 
876  return te::color::RGBAColor();
877 }
878 
880 {
881  CategorizedMap::iterator it = m_categorizeMap.begin();
882 
883  while(it != m_categorizeMap.end())
884  {
885  RasterThreshold rt = it->first;
886 
887  if(rt.first<= value && rt.second > value)
888  {
889  return it->second;
890  }
891 
892  ++it;
893  }
894 
895  return te::color::RGBAColor();
896 }
897 
899 {
900  return m_recodeMap[static_cast<int>(value)];
901 }
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
virtual void setValues(unsigned int c, unsigned int r, const std::vector< double > &values)
Sets the imaginary attribute values in all complex bands of a cell.
void setContrastType(const ContrastType &newType)
Set the current contrast type.
void setCategorize(double icol, double ilin, double ocol, double olin)
void setTransfFunction(RasterTransfFunctions func)
unsigned int band
void setGain(double value)
Sets the gain.
te::color::RGBAColor getInterpolatedColor(double value)
std::vector< double > m_rstMinValue
Min value from input raster.
A Raster Transform is a class that defines functions to transform a styled raster.
void setRGBMap(std::map< RGBChannels, short > &rgbMap)
Sets the rgb map values.
An exception class for the MapTools module.
int getRed() const
It returns the red component color value (a value from 0 to 255).
Definition: RGBAColor.h:307
void fixValue(double &value, short &band) const
void setGreen2ThreeBand(double icol, double ilin, double ocol, double olin)
void setInterpolate(double icol, double ilin, double ocol, double olin)
void setBand2Band(double icol, double ilin, double ocol, double olin)
Base exception class for plugin module.
void applySquareContrast(const unsigned int &bandIdx, const double &inputValue, double &outputValue) const
void setExtractRGBA(double icol, double ilin, double ocol, double olin)
void setContrastGainsAndOffsets(const std::vector< double > &contrastGains, const std::vector< double > &contrastOffsets1, const std::vector< double > &contrastOffsets2)
Set gain and offset parameters to be used by the CONTRAST_TRANSF method.
void setGammaG(double value)
Sets the constrast value for green band.
void setMono2ThreeBand(double icol, double ilin, double ocol, double olin)
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
Definition: RGBAColor.h:317
te::color::RGBAColor getMono2ThreeBand(double icol, double ilin)
int getGreen() const
It returns the green component color value (a value from 0 to 255).
Definition: RGBAColor.h:312
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
void setRecode(double icol, double ilin, double ocol, double olin)
te::color::RGBAColor getRecode(double icol, double ilin)
te::rst::Raster * m_rasterIn
Pointer to a input raster.
RecodedMap m_recodeMap
Attribute to define the recoded transformation.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void applyLogContrast(const unsigned int &bandIdx, const double &inputValue, double &outputValue) const
bool checkNoValue(double &value, int band) const
Function used to check if value is or not a valid value.
void setOffset(double value)
Sets the offset 1.
ContrastTransformFunction m_contrastTransfFuncPtr
Function used in contrast transformation operation.
RasterTransfFunctions getTransfFunction()
double getOffset()
Gets the offset.
void setLinearTransfParameters(double vmin, double vmax, double rmin, double rmax)
Set parameters of linear transformation.
ContrastType m_currentContrastType
Current contrast type.
void applySquareRootContrast(const unsigned int &bandIdx, const double &inputValue, double &outputValue) const
std::vector< double > m_contrastOffsets1
A vector of offsets1 for each band used by the CONTRAST method.
RGBAFunction m_RGBAFuncPtr
Function used in transformation operation.
std::vector< double > m_contrastGains
A vector of gains for each band used by the CONTRAST method.
double checkAlphaValue(double icol, double ilin)
Function used to check the alpha value.
void setContrastFuncPtr(const RasterTransform::ContrastType contrastType)
Configures the contrast function pointer.
void setRed2ThreeBand(double icol, double ilin, double ocol, double olin)
An abstract class for raster data strucutures.
te::color::RGBAColor getGreen2ThreeBand(double icol, double ilin)
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
RasterTransform(te::rst::Raster *input, te::rst::Raster *output)
Constructor.
double getGammaG()
Gets the constrast value for green band.
double m_transp
Transparency factor.
te::color::RGBAColor getBlue2ThreeBand(double icol, double ilin)
void setBlue2ThreeBand(double icol, double ilin, double ocol, double olin)
std::vector< double > m_contrastOffsets2
A vector of offsets2 for each band used by the CONTRAST method.
double getGain() const
Gets the gain.
double getGammaR()
Gets the constrast value for red band.
te::color::RGBAColor getRecodedColor(double value)
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
double getGammaB()
Gets the constrast value for blue band.
void setGammaR(double value)
Sets the constrast value for red band.
void applyLinearContrast(const unsigned int &bandIdx, const double &inputValue, double &outputValue) const
TransformFunction m_transfFuncPtr
Function used in transformation operation.
te::rst::Raster * m_rasterOut
Pointer to a output raster.
te::color::RGBAColor getCategorizedColor(double value)
double getGammaM()
Gets the constrast value for gray band.
std::vector< double > m_gamma
A vector of gamma gains for each band.
InterpolatedMap m_interpolateMap
Attribute to define the interpolated transformation.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
Definition: RGBAColor.h:57
short m_monoBand
Value for the gray band.
te::color::RGBAColor getInterpolate(double icol, double ilin)
A Raster Transform is a class that defines functions to transform a styled raster.
te::color::RGBAColor getExtractRGB(double icol, double ilin)
void setGammaM(double value)
Sets the constrast value for gray band.
void setExtractRGB(double icol, double ilin, double ocol, double olin)
std::pair< double, double > RasterThreshold
te::color::RGBAColor getExtractRGBA(double icol, double ilin)
std::map< RGBChannels, short > m_rgbMap
Map used to set the band order.
te::color::RGBAColor getRed2ThreeBand(double icol, double ilin)
te::color::RGBAColor getCategorize(double icol, double ilin)
CategorizedMap m_categorizeMap
Attribute to define the categorized transformation.
std::vector< double > m_rstMaxValue
Max value from input raster.
void setGammaB(double value)
Sets the constrast value for blue band.