src/terralib/raster/Band.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 terralib/raster/Band.cpp
22 
23  \brief It gives access to values in one band (dimension) of a raster.
24 */
25 
26 // TerraLib
27 
28 #include "Band.h"
29 #include "BandProperty.h"
30 #include "PositionIterator.h"
31 #include "Utils.h"
32 
33 // STL
34 #include <cassert>
35 #include <limits>
36 
38  : m_property(p),
39  m_idx(idx)
40 {
41 }
42 
44 {
45  delete m_property;
46 }
47 
49 {
50  if(this != &rhs)
51  {
52  delete m_property;
53 
54  m_property = rhs.m_property ? new BandProperty(*rhs.m_property) : nullptr;
55 
56  m_idx = rhs.m_idx;
57  }
58 
59  return *this;
60 }
61 
62 void te::rst::Band::getValue(unsigned int c, unsigned int r, std::complex<double>& value) const
63 {
64  double vr = 0.0;
65 
66  double vi = 0.0;
67 
68  getValue(c, r, vr);
69 
70  getIValue(c, r, vi);
71 
72  value = std::complex<double>(vr, vi);
73 }
74 
75 void te::rst::Band::setValue(unsigned int c, unsigned int r, const std::complex<double>& value)
76 {
77  setValue(c, r, value.real());
78 
79  setIValue(c, r, value.imag());
80 }
81 
82 std::complex<double> te::rst::Band::getMinValue(bool readall, unsigned int rs, unsigned int cs, unsigned int rf, unsigned int cf) const
83 {
84  std::complex<double> pixel;
85  double min_img = std::numeric_limits<double>::max();
86  double min_real = std::numeric_limits<double>::max();
87  double no_data = getProperty()->m_noDataValue;
88 
89  if ((rf == cf) && (rf == 0))
90  {
91  rf = getRaster()->getNumberOfRows() - 1;
92  cf = getRaster()->getNumberOfColumns() - 1;
93 
94 // read up to 1000 pixels in random positions
95  const unsigned int maxInputPoints = 1000;
96  if (readall == false && (rf * cf) > maxInputPoints)
97  {
98  std::vector<te::gm::Point*> randomPoints = te::rst::GetRandomPointsInRaster(*getRaster(), maxInputPoints);
101  while (pit != pitend)
102  {
103  getValue(pit.getColumn(), pit.getRow(), pixel);
104  ++pit;
105 
106  if(pixel.real() == no_data)
107  continue;
108 
109  if (pixel.real() < min_real)
110  min_real = pixel.real();
111 
112  if (pixel.imag() < min_img)
113  min_img = pixel.imag();
114  }
115 
116  while (!randomPoints.empty()) {
117  delete randomPoints.back();
118  randomPoints.pop_back();
119  }
120 
121  return std::complex<double>(min_real, min_img);
122  }
123  }
124 
125 // read all pixels in range
126  for (unsigned r = rs; r <= rf; r++)
127  for (unsigned c = cs; c <= cf; c++)
128  {
129  getValue(c, r, pixel);
130 
131  if(pixel.real() == no_data)
132  continue;
133 
134  if (pixel.real() < min_real)
135  min_real = pixel.real();
136 
137  if (pixel.imag() < min_img)
138  min_img = pixel.imag();
139  }
140 
141  return std::complex<double>(min_real, min_img);
142 }
143 
144 std::complex<double> te::rst::Band::getMaxValue(bool readall, unsigned int rs, unsigned int cs, unsigned int rf, unsigned int cf) const
145 {
146  std::complex<double> pixel;
147  double max_img = std::numeric_limits<double>::min();
148  double max_real = std::numeric_limits<double>::min();
149  double no_data = getProperty()->m_noDataValue;
150 
151  if ((rf == cf) && (rf == 0))
152  {
153  rf = getRaster()->getNumberOfRows() - 1;
154  cf = getRaster()->getNumberOfColumns() - 1;
155 
156 // read up to 1000 pixels in random positions
157  const unsigned int maxInputPoints = 1000;
158  if (readall == false && (rf * cf) > maxInputPoints)
159  {
160  std::vector<te::gm::Point*> randomPoints = te::rst::GetRandomPointsInRaster(*getRaster(), maxInputPoints);
163  while (pit != pitend)
164  {
165  getValue(pit.getColumn(), pit.getRow(), pixel);
166  ++pit;
167 
168  if(pixel.real() == no_data)
169  continue;
170 
171  if (pixel.real() > max_real)
172  max_real = pixel.real();
173 
174  if (pixel.imag() > max_img)
175  max_img = pixel.imag();
176  }
177 
178  while (!randomPoints.empty()) {
179  delete randomPoints.back();
180  randomPoints.pop_back();
181  }
182 
183  return std::complex<double>(max_real, max_img);
184  }
185  }
186 
187 // read all pixels in range
188  for (unsigned r = rs; r <= rf; r++)
189  for (unsigned c = cs; c <= cf; c++)
190  {
191  getValue(c, r, pixel);
192 
193  if(pixel.real() == no_data)
194  continue;
195 
196  if (pixel.real() > max_real)
197  max_real = pixel.real();
198 
199  if (pixel.imag() > max_img)
200  max_img = pixel.imag();
201  }
202 
203  return std::complex<double>(max_real, max_img);
204 }
205 
206 std::complex<double> te::rst::Band::getStdValue(unsigned int rs, unsigned int cs, unsigned int rf, unsigned int cf) const
207 {
208  if ((rf == cf) && (rf == 0))
209  {
210  rf = getRaster()->getNumberOfRows() - 1;
211 
212  cf = getRaster()->getNumberOfColumns() - 1;
213  }
214 
215  std::complex<double> pixel;
216 
217  std::complex<double> mean = getMeanValue(rs, cs, rf, cf);
218 
219  std::complex<double> diff;
220 
221  std::complex<double> sumDiffs(0.0, 0.0);
222 
223  unsigned n = (rf-rs+1) * (cf-cs+1) - 1;
224 
225  if (n == 0)
226  return std::complex<double> (1.0, 1.0);
227 
228  for (unsigned r = rs; r <= rf; r++)
229  for (unsigned c = cs; c <= cf; c++)
230  {
231  getValue(c, r, pixel);
232 
233  diff = pixel - mean;
234 
235  sumDiffs += diff * diff;
236  }
237 
238  return std::complex<double> (std::sqrt(sumDiffs.real() / n), std::sqrt(sumDiffs.imag() / n));
239 }
240 
241 std::complex<double> te::rst::Band::getMeanValue(unsigned int rs, unsigned int cs, unsigned int rf, unsigned int cf) const
242 {
243  if ((rf == cf) && (rf == 0))
244  {
245  rf = getRaster()->getNumberOfRows() - 1;
246 
247  cf = getRaster()->getNumberOfColumns() - 1;
248  }
249 
250  std::complex<double> pixel;
251 
252  std::complex<double> sumValue(0.0, 0.0);
253 
254  unsigned int n = (rf-rs+1) * (cf-cs+1);
255 
256  for (unsigned r = rs; r <= rf; r++)
257  for (unsigned c = cs; c <= cf; c++)
258  {
259  getValue(c, r, pixel);
260 
261  sumValue += pixel;
262  }
263 
264  if (n == 0)
265  return std::complex<double> (0.0, 0.0);
266 
267  return std::complex<double> (sumValue.real() / n, sumValue.imag() / n);
268 }
269 
270 std::map<double, unsigned> te::rst::Band::getHistogramR(unsigned int rs, unsigned int cs, unsigned int rf, unsigned int cf, unsigned int b) const
271 {
272  std::map<double, unsigned> histogram;
273  getHistogramR( rs, cs,rf, cf, b, 1, histogram );
274  return histogram;
275 }
276 
277 void te::rst::Band::getHistogramR( const unsigned int rowStart, const unsigned int colStart,
278  const unsigned int finalRow, const unsigned int finalCol, const unsigned int histoBins,
279  const unsigned int sampleStep, std::map<double, unsigned>& histogram ) const
280 {
281  if( finalRow < rowStart )
282  {
283  throw te::rst::Exception( "Invalid Row start/final" );
284  }
285  if( finalCol < colStart )
286  {
287  throw te::rst::Exception( "Invalid Col start/final" );
288  }
289  if( sampleStep < 1 )
290  {
291  throw te::rst::Exception( "Invalid sample step" );
292  }
293 
294  histogram.clear();
295 
296  // globals
297 
298  const bool processAllPixels = ( ( rowStart == 0 ) && ( colStart == 0 ) &&
299  ( finalRow == 0 ) && ( finalCol == 0 ) );
300  const long int nBlocksX = (long int)m_property->m_nblocksx;
301  const long int nBlocksY = (long int)m_property->m_nblocksy;
302  const long int blocksWidth = (long int)m_property->m_blkw;
303  const long int blocksHeight = (long int)m_property->m_blkh;
304  const long int rowsBound = processAllPixels ? getRaster()->getNumberOfRows() :
305  std::min( finalRow + 1, getRaster()->getNumberOfRows() );
306  const long int colsBound = processAllPixels ? getRaster()->getNumberOfColumns() :
307  std::min( finalCol + 1, getRaster()->getNumberOfColumns() );
308  const double& noDataValue = m_property->m_noDataValue;
309  long int blockXIndex = 0;
310  long int blockYIndex = 0;
311  long int blockColStart = 0;
312  long int blockRowStart = 0;
313  long int blockColsBound = 0;
314  long int blockRowsBound = 0;
315  double pixelValue = 0;
316  long int samplesRowStart = 0;
317  long int samplesColStart = 0;
318  long int sampleRow = 0;
319  long int sampleCol = 0;
320 
321  // find limits to divide into bins
322 
323  double pmin = std::numeric_limits<double>::max();
324  double pmax = -1.0 * std::numeric_limits<double>::max();
325  unsigned int pixelsCount = 0;
326 
327  for( blockYIndex = 0 ; blockYIndex < nBlocksY ; ++blockYIndex )
328  {
329  blockRowStart = blockYIndex * blocksHeight;
330  blockRowsBound = std::min( rowsBound, ( blockYIndex + 1 ) * blocksHeight );
331 
332  samplesRowStart = blockRowStart % sampleStep;
333  if( samplesRowStart )
334  {
335  samplesRowStart = blockRowStart + ( sampleStep - samplesRowStart );
336  }
337  else
338  {
339  samplesRowStart = blockRowStart;
340  }
341 
342 
343  for( blockXIndex = 0 ; blockXIndex < nBlocksX ; ++blockXIndex )
344  {
345  blockColStart = blockXIndex * blocksWidth;
346  blockColsBound = std::min( colsBound, ( blockXIndex + 1 ) * blocksWidth );
347 
348  samplesColStart = blockColStart % sampleStep;
349  if( samplesColStart )
350  {
351  samplesColStart = blockColStart + ( sampleStep - samplesColStart );
352  }
353  else
354  {
355  samplesColStart = blockColStart;
356  }
357 
358  for( sampleRow = samplesRowStart ; sampleRow < blockRowsBound ; sampleRow += sampleStep )
359  {
360  for( sampleCol = samplesColStart ; sampleCol < blockColsBound; sampleCol += sampleStep )
361  {
362  getValue(sampleCol, sampleRow, pixelValue);
363 
364  if (pixelValue == noDataValue)
365  continue;
366 
367  if (pixelValue > pmax)
368  pmax = pixelValue;
369 
370  if (pixelValue < pmin)
371  pmin = pixelValue;
372 
373  ++pixelsCount;
374  }
375  }
376  }
377  }
378 
379  if( pixelsCount == 0 )
380  {
381  return;
382  }
383 
384  // create histogram with bins
385 
386  std::vector< unsigned int > histoVector;
387  double delta = 0.0;
388 
389  if( histoBins == 0 )
390  {
391  if(
393  ||
395  )
396  {
397  delta = ( (pmax - pmin) / ( (double)( 254 ) ) );
398  histoVector.resize( 255, 0 );
399  }
400  else
401  {
402  delta = 1.0;
403  histoVector.resize( (std::size_t)( (pmax - pmin) + 1 ), 0 );
404  }
405  }
406  else
407  {
408  delta = ( (pmax - pmin) / ( (double)( histoBins - 1 ) ) );
409  histoVector.resize( (std::size_t)histoBins, 0 );
410  }
411 
412  if( delta == 0 )
413  {
414  if( pixelsCount )
415  {
416  histogram[ pmax ] = pixelsCount;
417  }
418 
419  return;
420  }
421 
422  // fill histogram
423 
424  std::size_t histoVectorIdx = 0;
425 
426  for( blockYIndex = 0 ; blockYIndex < nBlocksY ; ++blockYIndex )
427  {
428  blockRowStart = blockYIndex * blocksHeight;
429  blockRowsBound = std::min( rowsBound, ( blockYIndex + 1 ) * blocksHeight );
430 
431  samplesRowStart = blockRowStart % sampleStep;
432  if( samplesRowStart )
433  {
434  samplesRowStart = blockRowStart + ( sampleStep - samplesRowStart );
435  }
436  else
437  {
438  samplesRowStart = blockRowStart;
439  }
440 
441  for( blockXIndex = 0 ; blockXIndex < nBlocksX ; ++blockXIndex )
442  {
443  blockColStart = blockXIndex * blocksWidth;
444  blockColsBound = std::min( colsBound, ( blockXIndex + 1 ) * blocksWidth );
445 
446  samplesColStart = blockColStart % sampleStep;
447  if( samplesColStart )
448  {
449  samplesColStart = blockColStart + ( sampleStep - samplesColStart );
450  }
451  else
452  {
453  samplesColStart = blockColStart;
454  }
455 
456  for( sampleRow = samplesRowStart ; sampleRow < blockRowsBound ; sampleRow += sampleStep )
457  {
458  for( sampleCol = samplesColStart ; sampleCol < blockColsBound; sampleCol += sampleStep )
459  {
460  getValue(sampleCol, sampleRow, pixelValue);
461 
462  if (pixelValue != noDataValue)
463  {
464  histoVectorIdx = static_cast< size_t >( std::floor( ( pixelValue - pmin ) / delta ) );
465  assert( histoVectorIdx < histoVector.size() );
466  ++( histoVector[ histoVectorIdx ] );
467  }
468  }
469  }
470  }
471  }
472 
473  const std::size_t histoVectorSize = histoVector.size();
474 
475  for ( histoVectorIdx = 0 ; histoVectorIdx < histoVectorSize ; ++histoVectorIdx )
476  {
477  histogram[ pmin + ( ((double)histoVectorIdx) * delta ) ] = histoVector[ histoVectorIdx ];
478  }
479 }
480 
481 std::map<double, unsigned> te::rst::Band::getHistogramI(unsigned int rs, unsigned int cs, unsigned int rf, unsigned int cf, unsigned int b) const
482 {
483  if ((rf == cf) && (rf == 0))
484  {
485  rf = getRaster()->getNumberOfRows() - 1;
486 
487  cf = getRaster()->getNumberOfColumns() - 1;
488  }
489 
490  std::map<double, unsigned> hist;
491 
492  double pixel;
493 
494  if (b == 0)
495  for (unsigned r = rs; r <= rf; r++)
496  for (unsigned c = cs; c <= cf; c++)
497  {
498  getIValue(c, r, pixel);
499 
500  hist[pixel]++;
501  }
502  else
503  {
504 // find limits to divide into bins
505  double pmin = std::numeric_limits<double>::max();
506  double pmax = -1.0 * std::numeric_limits<double>::max();
507 
508  for (unsigned r = rs; r <= rf; r++)
509  for (unsigned c = cs; c <= cf; c++)
510  {
511  getIValue(c, r, pixel);
512 
513  if (pixel > pmax)
514  pmax = pixel;
515 
516  if (pixel < pmin)
517  pmin = pixel;
518  }
519 
520 // create histogram with bins
521  double delta = (pmax * 1.000001 - pmin) / b;
522 
523  std::map<std::size_t, double> binsLocations;
524 
525  std::size_t location = 0;
526 
527  for (double bins = pmin; bins < pmax; bins += delta)
528  {
529  hist[bins] = 0;
530 
531  binsLocations[location++] = bins;
532  }
533 
534 // fill histogram
535  for (unsigned r = rs; r <= rf; r++)
536  for (unsigned c = cs; c <= cf; c++)
537  {
538  getIValue(c, r, pixel);
539 
540  location = (std::size_t) ((pixel - pmin) / delta);
541 
542  hist[binsLocations[location]]++;
543  }
544 
545 // removing empty bins from histogram
546  for (double bins = pmin; bins < pmax; bins += delta)
547  if(hist[bins] == 0)
548  hist.erase(bins);
549 
550  }
551 
552  return hist;
553 }
554 
555 std::complex<double> te::rst::Band::getScaleValue() const
556 {
557  return m_property->m_valuesScale;
558 }
559 
560 void te::rst::Band::setScaleValue(const std::complex<double> s)
561 {
563 }
564 
565 std::complex<double> te::rst::Band::getOffsetValue() const
566 {
567  return m_property->m_valuesOffset;
568 }
569 
570 void te::rst::Band::setOffsetValue(const std::complex<double> o)
571 {
573 }
574 
576 {
577  return m_property;
578 }
579 
581 {
582  return m_property;
583 }
584 
585 te::rst::Band& te::rst::Band::callOperator(std::complex<double>(*f)(std::complex<double>, std::complex<double>), te::rst::Band& rhs)
586 {
587  assert(getRaster()->getNumberOfRows() == rhs.getRaster()->getNumberOfRows());
588  assert(getRaster()->getNumberOfColumns() == rhs.getRaster()->getNumberOfColumns());
589  assert(getRaster()->getAccessPolicy() == te::common::RWAccess || getRaster()->getAccessPolicy() == te::common::WAccess);
590 
591  std::complex<double> lhsv, rhsv;
592 
593  std::vector<std::pair<unsigned, unsigned> > rcStPos, rcFPos;
594 
595  unsigned last_y;
596  unsigned last_x;
597  for (unsigned x = 0; x < (unsigned) getProperty()->m_nblocksx; x++)
598  {
599  for (unsigned y = 0; y < (unsigned) getProperty()->m_nblocksy; y++)
600  {
601  rcStPos.push_back(std::pair<unsigned, unsigned> (y * getProperty()->m_blkh, x * getProperty()->m_blkw));
602  last_y = (y + 1) * getProperty()->m_blkh;
603  last_x = (x + 1) * getProperty()->m_blkw;
604  if (last_y > getRaster()->getNumberOfRows())
605  last_y = getRaster()->getNumberOfRows();
606  if (last_x > getRaster()->getNumberOfColumns())
607  last_x = getRaster()->getNumberOfColumns();
608  rcFPos.push_back(std::pair<unsigned, unsigned> (last_y, last_x));
609  }
610  }
611 
612 // rasters without no data values
613  if (getProperty()->m_noDataValue == std::numeric_limits<double>::max())
614  {
615  for (unsigned i = 0; i < rcStPos.size(); i++)
616  {
617  for (unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
618  for (unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
619  {
620  getValue(c, r, lhsv);
621  rhs.getValue(c, r, rhsv);
622 
623  lhsv = f(lhsv, rhsv);
624  setValue(c, r, lhsv);
625  }
626  }
627  }
628 // rasters with no data values
629  else
630  {
631  for (unsigned i = 0; i < rcStPos.size(); i++)
632  {
633  for (unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
634  for (unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
635  {
636 // lhs data
637  getValue(c, r, lhsv);
638  if (lhsv.real() == getProperty()->m_noDataValue)
639  continue;
640 
641 // rhs data
642  rhs.getValue(c, r, rhsv);
643  if (rhsv.real() == rhs.getProperty()->m_noDataValue)
644  continue;
645 
646  lhsv = f(lhsv, rhsv);
647  setValue(c, r, lhsv);
648  }
649  }
650  }
651 
652  return *this;
653 }
654 
655 te::rst::Band& te::rst::Band::callOperator(std::complex<double>(*f)(std::complex<double>, std::complex<double>), std::complex<double>& cvalue)
656 {
657  assert(getRaster()->getAccessPolicy() == te::common::RWAccess || getRaster()->getAccessPolicy() == te::common::WAccess);
658 
659  std::complex<double> lhsv;
660 
661  std::vector<std::pair<unsigned, unsigned> > rcStPos, rcFPos;
662 
663  unsigned last_y;
664  unsigned last_x;
665  for (unsigned x = 0; x < (unsigned) getProperty()->m_nblocksx; x++)
666  {
667  for (unsigned y = 0; y < (unsigned) getProperty()->m_nblocksy; y++)
668  {
669  rcStPos.push_back(std::pair<unsigned, unsigned> (y * getProperty()->m_blkh, x * getProperty()->m_blkw));
670  last_y = (y + 1) * getProperty()->m_blkh;
671  last_x = (x + 1) * getProperty()->m_blkw;
672  if (last_y > getRaster()->getNumberOfRows())
673  last_y = getRaster()->getNumberOfRows();
674  if (last_x > getRaster()->getNumberOfColumns())
675  last_x = getRaster()->getNumberOfColumns();
676  rcFPos.push_back(std::pair<unsigned, unsigned> (last_y, last_x));
677  }
678  }
679 
680 // rasters without no data values
681  if (getProperty()->m_noDataValue == std::numeric_limits<double>::max())
682  {
683  for (unsigned i = 0; i < rcStPos.size(); i++)
684  {
685  for (unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
686  for (unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
687  {
688  getValue(c, r, lhsv);
689 
690  lhsv = f(lhsv, cvalue);
691  setValue(c, r, lhsv);
692  }
693  }
694  }
695 // rasters with no data values
696  else
697  {
698  for (unsigned i = 0; i < rcStPos.size(); i++)
699  {
700  for (unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
701  for (unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
702  {
703 // lhs data
704  getValue(c, r, lhsv);
705  if (lhsv.real() == getProperty()->m_noDataValue)
706  continue;
707 
708  lhsv = f(lhsv, cvalue);
709  setValue(c, r, lhsv);
710  }
711  }
712  }
713 
714  return *this;
715 }
716 
717 std::complex<double> plus(std::complex<double> lhs, std::complex<double> rhs)
718 {
719  return lhs + rhs;
720 }
721 
722 std::complex<double> minus(std::complex<double> lhs, std::complex<double> rhs)
723 {
724  return lhs - rhs;
725 }
726 
727 std::complex<double> times(std::complex<double> lhs, std::complex<double> rhs)
728 {
729  return lhs * rhs;
730 }
731 
732 std::complex<double> divide(std::complex<double> lhs, std::complex<double> rhs)
733 {
734  return lhs / rhs;
735 }
736 
738 {
739  return callOperator(plus, rhs);
740 }
741 
742 te::rst::Band& te::rst::Band::operator+=(std::complex<double>& cvalue)
743 {
744  return callOperator(plus, cvalue);
745 }
746 
748 {
749  return callOperator(minus, rhs);
750 }
751 
752 te::rst::Band& te::rst::Band::operator-=(std::complex<double>& cvalue)
753 {
754  return callOperator(minus, cvalue);
755 }
756 
757 te::rst::Band& te::rst::Band::operator*=(std::complex<double>& cvalue)
758 {
759  return callOperator(times, cvalue);
760 }
761 
763 {
764  return callOperator(times, rhs);
765 }
766 
768 {
769  return callOperator(divide, rhs);
770 }
771 
772 te::rst::Band& te::rst::Band::operator/=(std::complex<double>& cvalue)
773 {
774  return callOperator(divide, cvalue);
775 }
776 
778 {
779  int blkw = m_property->m_blkw;
780 
781  int blkh = m_property->m_blkh;
782 
783  int pxlsize = GetPixelSize(m_property->getType());
784 
785  int blksize = blkw * blkh * pxlsize;
786 
787  return blksize;
788 }
789 
791  : m_property(nullptr),
792  m_idx(rhs.m_idx)
793 {
794  m_property = rhs.m_property ? new BandProperty(*rhs.m_property) : nullptr;
795 }
796 
virtual void setIValue(unsigned int c, unsigned int r, const double value)=0
Sets the imaginary attribute value in a complex band of a cell.
It gives access to values in one band (dimension) of a raster.
Band(BandProperty *p, std::size_t idx)
Constructor.
It describes one band (or dimension) of a raster.
std::complex< double > getOffsetValue() const
It returns the offset values (real and imaginary) to be applied to the band.
A raster band description.
Definition: BandProperty.h:61
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
virtual Band & operator*=(Band &rhs)
It returns the band product (pixel by pixel).
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
virtual Band & operator=(const Band &rhs)
Assignment operator.
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
unsigned int getColumn() const
Returns the current column in iterator.
static PointSetIterator end(const te::rst::Raster *r, const std::vector< te::gm::Point * > p)
Returns an iterator referring to after the end of the iterator.
double pixelValue
int m_type
The data type of the elements in the band ( See te::dt namespace basic data types for reference )...
Definition: BandProperty.h:133
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
Definition: BandProperty.h:136
void setScaleValue(const std::complex< double > s)
Sets the scale values (real and imaginary) to be applied to the band.
void setOffsetValue(const std::complex< double > o)
Sets the offset values (real and imaginary) to be applied to the band.
virtual std::map< double, unsigned > getHistogramR(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0, unsigned int b=0) const
It computes and returns the histogram occurring values (real part) in a window of the band...
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
virtual Band & operator+=(Band &rhs)
It returns the band sum (pixel by pixel).
virtual void getIValue(unsigned int c, unsigned int r, double &value) const =0
Returns the imaginary attribute value in a complex band of a cell.
Band & callOperator(std::complex< double >(*f)(std::complex< double >, std::complex< double >), Band &rhs)
It calls a parameter function f to apply in all pixels from two bands, e.g. pixel = f(lhs...
Utility functions for the raster module.
int b
Definition: TsRtree.cpp:32
virtual std::map< double, unsigned > getHistogramI(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0, unsigned int b=0) const
It computes and returns the histogram occurring values (imaginary part) in a window of the band...
std::complex< double > divide(std::complex< double > lhs, std::complex< double > rhs)
virtual std::complex< double > getMaxValue(bool readall=false, unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the maximum occurring value in a window of the band.
virtual std::complex< double > getStdValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the standard deviation of the occurring values in a window of the band...
unsigned int getNumberOfRows() const
Returns the raster number of rows.
BandProperty * getProperty()
Returns the band property.
std::complex< double > m_valuesScale
Scale is the values (real and imaginary) which is multiplied to grid values for this sample dimension...
Definition: BandProperty.h:138
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
std::complex< double > plus(std::complex< double > lhs, std::complex< double > rhs)
virtual Band & operator-=(Band &rhs)
It returns the band subtraction (pixel by pixel).
std::complex< double > times(std::complex< double > lhs, std::complex< double > rhs)
te::gm::Polygon * p
A raster band description.
std::complex< double > getScaleValue() const
It returns the scale values (real and imaginary) to be applied to the band.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
virtual Band & operator/=(Band &rhs)
It returns the band division (pixel by pixel).
virtual std::complex< double > getMinValue(bool readall=false, unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the minimum occurring value in a window of the band.
virtual std::complex< double > getMeanValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the mean of the occurring values in a window of the band. ...
virtual Raster * getRaster() const =0
Returns the associated raster.
TERASTEREXPORT std::vector< te::gm::Point * > GetRandomPointsInRaster(const te::rst::Raster &inputRaster, unsigned int numberOfPoints=1000)
Creates a vector of random positions (points) inside the raster.
std::size_t m_idx
The band index.
std::complex< double > minus(std::complex< double > lhs, std::complex< double > rhs)
std::complex< double > m_valuesOffset
Offset is the values (real and imaginary) to add to grid values for this sample dimension, default is 0.
Definition: BandProperty.h:137
int getType() const
It returns the data type of the elements in the band.
Definition: BandProperty.h:113
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
unsigned int getRow() const
Returns the current row in iterator.
virtual ~Band()
Virtual destructor.
static PointSetIterator begin(const te::rst::Raster *r, const std::vector< te::gm::Point * > p)
Returns an iterator referring to the first value of the band.
BandProperty * m_property
The band information.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.