72 value = std::complex<double>(vr, vi);
77 setValue(c, r, value.real());
79 setIValue(c, r, value.imag());
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;
89 if ((rf == cf) && (rf == 0))
91 rf = getRaster()->getNumberOfRows() - 1;
92 cf = getRaster()->getNumberOfColumns() - 1;
95 const unsigned int maxInputPoints = 1000;
96 if (readall ==
false && (rf * cf) > maxInputPoints)
101 while (pit != pitend)
106 if(pixel.real() == no_data)
109 if (pixel.real() < min_real)
110 min_real = pixel.real();
112 if (pixel.imag() < min_img)
113 min_img = pixel.imag();
116 return std::complex<double>(min_real, min_img);
121 for (
unsigned r = rs; r <= rf; r++)
122 for (
unsigned c = cs; c <= cf; c++)
124 getValue(c, r, pixel);
126 if(pixel.real() == no_data)
129 if (pixel.real() < min_real)
130 min_real = pixel.real();
132 if (pixel.imag() < min_img)
133 min_img = pixel.imag();
136 return std::complex<double>(min_real, min_img);
141 std::complex<double> pixel;
142 double max_img = std::numeric_limits<double>::min();
143 double max_real = std::numeric_limits<double>::min();
144 double no_data = getProperty()->m_noDataValue;
146 if ((rf == cf) && (rf == 0))
148 rf = getRaster()->getNumberOfRows() - 1;
149 cf = getRaster()->getNumberOfColumns() - 1;
152 const unsigned int maxInputPoints = 1000;
153 if (readall ==
false && (rf * cf) > maxInputPoints)
158 while (pit != pitend)
163 if(pixel.real() == no_data)
166 if (pixel.real() > max_real)
167 max_real = pixel.real();
169 if (pixel.imag() > max_img)
170 max_img = pixel.imag();
173 return std::complex<double>(max_real, max_img);
178 for (
unsigned r = rs; r <= rf; r++)
179 for (
unsigned c = cs; c <= cf; c++)
181 getValue(c, r, pixel);
183 if(pixel.real() == no_data)
186 if (pixel.real() > max_real)
187 max_real = pixel.real();
189 if (pixel.imag() > max_img)
190 max_img = pixel.imag();
193 return std::complex<double>(max_real, max_img);
198 if ((rf == cf) && (rf == 0))
200 rf = getRaster()->getNumberOfRows() - 1;
202 cf = getRaster()->getNumberOfColumns() - 1;
205 std::complex<double> pixel;
207 std::complex<double> mean = getMeanValue(rs, cs, rf, cf);
209 std::complex<double> diff;
211 std::complex<double> sumDiffs(0.0, 0.0);
213 unsigned n = (rf-rs+1) * (cf-cs+1) - 1;
216 return std::complex<double> (1.0, 1.0);
218 for (
unsigned r = rs; r <= rf; r++)
219 for (
unsigned c = cs; c <= cf; c++)
221 getValue(c, r, pixel);
225 sumDiffs += diff * diff;
228 return std::complex<double> (std::sqrt(sumDiffs.real() / n), std::sqrt(sumDiffs.imag() / n));
233 if ((rf == cf) && (rf == 0))
235 rf = getRaster()->getNumberOfRows() - 1;
237 cf = getRaster()->getNumberOfColumns() - 1;
240 std::complex<double> pixel;
242 std::complex<double> sumValue(0.0, 0.0);
244 unsigned int n = (rf-rs+1) * (cf-cs+1);
246 for (
unsigned r = rs; r <= rf; r++)
247 for (
unsigned c = cs; c <= cf; c++)
249 getValue(c, r, pixel);
255 return std::complex<double> (0.0, 0.0);
257 return std::complex<double> (sumValue.real() / n, sumValue.imag() / n);
262 if ((rf == cf) && (rf == 0))
264 rf = getRaster()->getNumberOfRows() - 1;
266 cf = getRaster()->getNumberOfColumns() - 1;
269 std::map<double, unsigned> hist;
274 for (
unsigned r = rs; r <= rf; r++)
275 for (
unsigned c = cs; c <= cf; c++)
277 getValue(c, r, pixel);
279 if (pixel == m_property->m_noDataValue)
287 double pmin = std::numeric_limits<double>::max();
288 double pmax = -1.0 * std::numeric_limits<double>::max();
290 for (
unsigned r = rs; r <= rf; r++)
291 for (
unsigned c = cs; c <= cf; c++)
293 getValue(c, r, pixel);
295 if (pixel == m_property->m_noDataValue)
306 double delta = (pmax * 1.000001 - pmin) / b;
308 std::map<std::size_t, double> binsLocations;
310 std::size_t location = 0;
312 for (
double bins = pmin; bins < pmax; bins += delta)
316 binsLocations[location++] = bins;
320 for (
unsigned r = rs; r <= rf; r++)
321 for (
unsigned c = cs; c <= cf; c++)
323 getValue(c, r, pixel);
325 if (pixel == m_property->m_noDataValue)
328 location = (std::size_t) ((pixel - pmin) / delta);
330 hist[binsLocations[location]]++;
334 for (
double bins = pmin; bins < pmax; bins += delta)
345 if ((rf == cf) && (rf == 0))
347 rf = getRaster()->getNumberOfRows() - 1;
349 cf = getRaster()->getNumberOfColumns() - 1;
352 std::map<double, unsigned> hist;
357 for (
unsigned r = rs; r <= rf; r++)
358 for (
unsigned c = cs; c <= cf; c++)
360 getIValue(c, r, pixel);
367 double pmin = std::numeric_limits<double>::max();
368 double pmax = -1.0 * std::numeric_limits<double>::max();
370 for (
unsigned r = rs; r <= rf; r++)
371 for (
unsigned c = cs; c <= cf; c++)
373 getIValue(c, r, pixel);
383 double delta = (pmax * 1.000001 - pmin) / b;
385 std::map<std::size_t, double> binsLocations;
387 std::size_t location = 0;
389 for (
double bins = pmin; bins < pmax; bins += delta)
393 binsLocations[location++] = bins;
397 for (
unsigned r = rs; r <= rf; r++)
398 for (
unsigned c = cs; c <= cf; c++)
400 getIValue(c, r, pixel);
402 location = (std::size_t) ((pixel - pmin) / delta);
404 hist[binsLocations[location]]++;
408 for (
double bins = pmin; bins < pmax; bins += delta)
419 return m_property->m_valuesScale;
424 m_property->m_valuesScale = s;
429 return m_property->m_valuesOffset;
434 m_property->m_valuesOffset = o;
453 std::complex<double> lhsv, rhsv;
455 std::vector<std::pair<unsigned, unsigned> > rcStPos, rcFPos;
459 for (
unsigned x = 0; x < (unsigned) getProperty()->m_nblocksx; x++)
461 for (
unsigned y = 0; y < (unsigned) getProperty()->m_nblocksy; y++)
463 rcStPos.push_back(std::pair<unsigned, unsigned> (y * getProperty()->m_blkh, x * getProperty()->m_blkw));
464 last_y = (y + 1) * getProperty()->m_blkh;
465 last_x = (x + 1) * getProperty()->m_blkw;
466 if (last_y > getRaster()->getNumberOfRows())
467 last_y = getRaster()->getNumberOfRows();
468 if (last_x > getRaster()->getNumberOfColumns())
469 last_x = getRaster()->getNumberOfColumns();
470 rcFPos.push_back(std::pair<unsigned, unsigned> (last_y, last_x));
475 if (getProperty()->m_noDataValue == std::numeric_limits<double>::max())
477 for (
unsigned i = 0; i < rcStPos.size(); i++)
479 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
480 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
482 getValue(c, r, lhsv);
485 lhsv = f(lhsv, rhsv);
486 setValue(c, r, lhsv);
493 for (
unsigned i = 0; i < rcStPos.size(); i++)
495 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
496 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
499 getValue(c, r, lhsv);
500 if (lhsv.real() == getProperty()->m_noDataValue)
508 lhsv = f(lhsv, rhsv);
509 setValue(c, r, lhsv);
521 std::complex<double> lhsv;
523 std::vector<std::pair<unsigned, unsigned> > rcStPos, rcFPos;
527 for (
unsigned x = 0; x < (unsigned) getProperty()->m_nblocksx; x++)
529 for (
unsigned y = 0; y < (unsigned) getProperty()->m_nblocksy; y++)
531 rcStPos.push_back(std::pair<unsigned, unsigned> (y * getProperty()->m_blkh, x * getProperty()->m_blkw));
532 last_y = (y + 1) * getProperty()->m_blkh;
533 last_x = (x + 1) * getProperty()->m_blkw;
534 if (last_y > getRaster()->getNumberOfRows())
535 last_y = getRaster()->getNumberOfRows();
536 if (last_x > getRaster()->getNumberOfColumns())
537 last_x = getRaster()->getNumberOfColumns();
538 rcFPos.push_back(std::pair<unsigned, unsigned> (last_y, last_x));
543 if (getProperty()->m_noDataValue == std::numeric_limits<double>::max())
545 for (
unsigned i = 0; i < rcStPos.size(); i++)
547 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
548 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
550 getValue(c, r, lhsv);
552 lhsv = f(lhsv, cvalue);
553 setValue(c, r, lhsv);
560 for (
unsigned i = 0; i < rcStPos.size(); i++)
562 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
563 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
566 getValue(c, r, lhsv);
567 if (lhsv.real() == getProperty()->m_noDataValue)
570 lhsv = f(lhsv, cvalue);
571 setValue(c, r, lhsv);
579 std::complex<double>
plus(std::complex<double> lhs, std::complex<double> rhs)
584 std::complex<double>
minus(std::complex<double> lhs, std::complex<double> rhs)
589 std::complex<double>
times(std::complex<double> lhs, std::complex<double> rhs)
594 std::complex<double>
divide(std::complex<double> lhs, std::complex<double> rhs)
601 return callOperator(
plus, rhs);
606 return callOperator(
plus, cvalue);
611 return callOperator(
minus, rhs);
616 return callOperator(
minus, cvalue);
621 return callOperator(
times, cvalue);
626 return callOperator(
times, rhs);
631 return callOperator(
divide, rhs);
636 return callOperator(
divide, cvalue);
641 int blkw = m_property->m_blkw;
643 int blkh = m_property->m_blkh;
647 int blksize = blkw * blkh * pxlsize;
Band(BandProperty *p, std::size_t idx)
Constructor.
It describes one band (or dimension) of a raster.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
std::complex< double > getOffsetValue() const
It returns the offset values (real and imaginary) to be applied to the band.
A raster band description.
std::complex< double > times(std::complex< double > lhs, std::complex< double > rhs)
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
virtual Band & operator*=(Band &rhs)
It returns the band product (pixel by pixel).
virtual Band & operator=(const Band &rhs)
Assignment operator.
std::complex< double > divide(std::complex< double > lhs, std::complex< double > rhs)
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 m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
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).
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...
std::complex< double > plus(std::complex< double > lhs, std::complex< double > rhs)
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...
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.
Utility functions for the raster module.
virtual Raster * getRaster() const =0
Returns the associated raster.
virtual Band & operator-=(Band &rhs)
It returns the band subtraction (pixel by pixel).
It gives access to values in one band (dimension) of a raster.
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.
std::complex< double > minus(std::complex< double > lhs, std::complex< double > rhs)
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. ...
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.
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.