72 value = std::complex<double>(vr, vi);
84 std::complex<double> pixel;
85 double min_img = std::numeric_limits<double>::max();
86 double min_real = std::numeric_limits<double>::max();
89 if ((rf == cf) && (rf == 0))
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 while (!randomPoints.empty()) {
117 delete randomPoints.back();
118 randomPoints.pop_back();
121 return std::complex<double>(min_real, min_img);
126 for (
unsigned r = rs; r <= rf; r++)
127 for (
unsigned c = cs; c <= cf; c++)
131 if(pixel.real() == no_data)
134 if (pixel.real() < min_real)
135 min_real = pixel.real();
137 if (pixel.imag() < min_img)
138 min_img = pixel.imag();
141 return std::complex<double>(min_real, min_img);
146 std::complex<double> pixel;
147 double max_img = std::numeric_limits<double>::min();
148 double max_real = std::numeric_limits<double>::min();
151 if ((rf == cf) && (rf == 0))
157 const unsigned int maxInputPoints = 1000;
158 if (readall ==
false && (rf * cf) > maxInputPoints)
163 while (pit != pitend)
168 if(pixel.real() == no_data)
171 if (pixel.real() > max_real)
172 max_real = pixel.real();
174 if (pixel.imag() > max_img)
175 max_img = pixel.imag();
178 while (!randomPoints.empty()) {
179 delete randomPoints.back();
180 randomPoints.pop_back();
183 return std::complex<double>(max_real, max_img);
188 for (
unsigned r = rs; r <= rf; r++)
189 for (
unsigned c = cs; c <= cf; c++)
193 if(pixel.real() == no_data)
196 if (pixel.real() > max_real)
197 max_real = pixel.real();
199 if (pixel.imag() > max_img)
200 max_img = pixel.imag();
203 return std::complex<double>(max_real, max_img);
208 if ((rf == cf) && (rf == 0))
215 std::complex<double> pixel;
217 std::complex<double> mean =
getMeanValue(rs, cs, rf, cf);
219 std::complex<double> diff;
221 std::complex<double> sumDiffs(0.0, 0.0);
223 unsigned n = (rf-rs+1) * (cf-cs+1) - 1;
226 return std::complex<double> (1.0, 1.0);
228 for (
unsigned r = rs; r <= rf; r++)
229 for (
unsigned c = cs; c <= cf; c++)
235 sumDiffs += diff * diff;
238 return std::complex<double> (std::sqrt(sumDiffs.real() / n), std::sqrt(sumDiffs.imag() / n));
243 if ((rf == cf) && (rf == 0))
250 std::complex<double> pixel;
252 std::complex<double> sumValue(0.0, 0.0);
254 unsigned int n = (rf-rs+1) * (cf-cs+1);
256 for (
unsigned r = rs; r <= rf; r++)
257 for (
unsigned c = cs; c <= cf; c++)
265 return std::complex<double> (0.0, 0.0);
267 return std::complex<double> (sumValue.real() / n, sumValue.imag() / n);
272 std::map<double, unsigned> histogram;
278 const unsigned int finalRow,
const unsigned int finalCol,
const unsigned int histoBins,
279 const unsigned int sampleStep, std::map<double, unsigned>& histogram )
const 281 if( finalRow < rowStart )
283 throw te::rst::Exception(
"Invalid Row start/final" );
285 if( finalCol < colStart )
287 throw te::rst::Exception(
"Invalid Col start/final" );
291 throw te::rst::Exception(
"Invalid sample step" );
298 const bool processAllPixels = ( ( rowStart == 0 ) && ( colStart == 0 ) &&
299 ( finalRow == 0 ) && ( finalCol == 0 ) );
305 std::min( finalRow + 1,
getRaster()->getNumberOfRows() );
307 std::min( finalCol + 1,
getRaster()->getNumberOfColumns() );
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;
316 long int samplesRowStart = 0;
317 long int samplesColStart = 0;
318 long int sampleRow = 0;
319 long int sampleCol = 0;
323 double pmin = std::numeric_limits<double>::max();
324 double pmax = -1.0 * std::numeric_limits<double>::max();
325 unsigned int pixelsCount = 0;
327 for( blockYIndex = 0 ; blockYIndex < nBlocksY ; ++blockYIndex )
329 blockRowStart = blockYIndex * blocksHeight;
330 blockRowsBound = std::min( rowsBound, ( blockYIndex + 1 ) * blocksHeight );
332 samplesRowStart = blockRowStart % sampleStep;
333 if( samplesRowStart )
335 samplesRowStart = blockRowStart + ( sampleStep - samplesRowStart );
339 samplesRowStart = blockRowStart;
343 for( blockXIndex = 0 ; blockXIndex < nBlocksX ; ++blockXIndex )
345 blockColStart = blockXIndex * blocksWidth;
346 blockColsBound = std::min( colsBound, ( blockXIndex + 1 ) * blocksWidth );
348 samplesColStart = blockColStart % sampleStep;
349 if( samplesColStart )
351 samplesColStart = blockColStart + ( sampleStep - samplesColStart );
355 samplesColStart = blockColStart;
358 for( sampleRow = samplesRowStart ; sampleRow < blockRowsBound ; sampleRow += sampleStep )
360 for( sampleCol = samplesColStart ; sampleCol < blockColsBound; sampleCol += sampleStep )
362 getValue(sampleCol, sampleRow, pixelValue);
364 if (pixelValue == noDataValue)
367 if (pixelValue > pmax)
370 if (pixelValue < pmin)
379 if( pixelsCount == 0 )
386 std::vector< unsigned int > histoVector;
397 delta = ( (pmax - pmin) / ( (
double)( 254 ) ) );
398 histoVector.resize( 255, 0 );
403 histoVector.resize( (std::size_t)( (pmax - pmin) + 1 ), 0 );
408 delta = ( (pmax - pmin) / ( (
double)( histoBins - 1 ) ) );
409 histoVector.resize( (std::size_t)histoBins, 0 );
416 histogram[ pmax ] = pixelsCount;
424 std::size_t histoVectorIdx = 0;
426 for( blockYIndex = 0 ; blockYIndex < nBlocksY ; ++blockYIndex )
428 blockRowStart = blockYIndex * blocksHeight;
429 blockRowsBound = std::min( rowsBound, ( blockYIndex + 1 ) * blocksHeight );
431 samplesRowStart = blockRowStart % sampleStep;
432 if( samplesRowStart )
434 samplesRowStart = blockRowStart + ( sampleStep - samplesRowStart );
438 samplesRowStart = blockRowStart;
441 for( blockXIndex = 0 ; blockXIndex < nBlocksX ; ++blockXIndex )
443 blockColStart = blockXIndex * blocksWidth;
444 blockColsBound = std::min( colsBound, ( blockXIndex + 1 ) * blocksWidth );
446 samplesColStart = blockColStart % sampleStep;
447 if( samplesColStart )
449 samplesColStart = blockColStart + ( sampleStep - samplesColStart );
453 samplesColStart = blockColStart;
456 for( sampleRow = samplesRowStart ; sampleRow < blockRowsBound ; sampleRow += sampleStep )
458 for( sampleCol = samplesColStart ; sampleCol < blockColsBound; sampleCol += sampleStep )
460 getValue(sampleCol, sampleRow, pixelValue);
462 if (pixelValue != noDataValue)
464 histoVectorIdx =
static_cast< size_t >( std::floor( ( pixelValue - pmin ) / delta ) );
465 assert( histoVectorIdx < histoVector.size() );
466 ++( histoVector[ histoVectorIdx ] );
473 const std::size_t histoVectorSize = histoVector.size();
475 for ( histoVectorIdx = 0 ; histoVectorIdx < histoVectorSize ; ++histoVectorIdx )
477 histogram[ pmin + ( ((double)histoVectorIdx) * delta ) ] = histoVector[ histoVectorIdx ];
483 if ((rf == cf) && (rf == 0))
490 std::map<double, unsigned> hist;
495 for (
unsigned r = rs; r <= rf; r++)
496 for (
unsigned c = cs; c <= cf; c++)
505 double pmin = std::numeric_limits<double>::max();
506 double pmax = -1.0 * std::numeric_limits<double>::max();
508 for (
unsigned r = rs; r <= rf; r++)
509 for (
unsigned c = cs; c <= cf; c++)
521 double delta = (pmax * 1.000001 - pmin) / b;
523 std::map<std::size_t, double> binsLocations;
525 std::size_t location = 0;
527 for (
double bins = pmin; bins < pmax; bins += delta)
531 binsLocations[location++] = bins;
535 for (
unsigned r = rs; r <= rf; r++)
536 for (
unsigned c = cs; c <= cf; c++)
540 location = (std::size_t) ((pixel - pmin) / delta);
542 hist[binsLocations[location]]++;
546 for (
double bins = pmin; bins < pmax; bins += delta)
591 std::complex<double> lhsv, rhsv;
593 std::vector<std::pair<unsigned, unsigned> > rcStPos, rcFPos;
606 if (last_x >
getRaster()->getNumberOfColumns())
608 rcFPos.push_back(std::pair<unsigned, unsigned> (last_y, last_x));
613 if (
getProperty()->m_noDataValue == std::numeric_limits<double>::max())
615 for (
unsigned i = 0; i < rcStPos.size(); i++)
617 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
618 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
623 lhsv = f(lhsv, rhsv);
631 for (
unsigned i = 0; i < rcStPos.size(); i++)
633 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
634 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
646 lhsv = f(lhsv, rhsv);
659 std::complex<double> lhsv;
661 std::vector<std::pair<unsigned, unsigned> > rcStPos, rcFPos;
674 if (last_x >
getRaster()->getNumberOfColumns())
676 rcFPos.push_back(std::pair<unsigned, unsigned> (last_y, last_x));
681 if (
getProperty()->m_noDataValue == std::numeric_limits<double>::max())
683 for (
unsigned i = 0; i < rcStPos.size(); i++)
685 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
686 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
690 lhsv = f(lhsv, cvalue);
698 for (
unsigned i = 0; i < rcStPos.size(); i++)
700 for (
unsigned r = rcStPos[i].first; r < rcFPos[i].first; r++)
701 for (
unsigned c = rcStPos[i].second; c < rcFPos[i].second; c++)
708 lhsv = f(lhsv, cvalue);
717 std::complex<double>
plus(std::complex<double> lhs, std::complex<double> rhs)
722 std::complex<double>
minus(std::complex<double> lhs, std::complex<double> rhs)
727 std::complex<double>
times(std::complex<double> lhs, std::complex<double> rhs)
732 std::complex<double>
divide(std::complex<double> lhs, std::complex<double> rhs)
785 int blksize = blkw * blkh * pxlsize;
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.
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.
virtual Band & operator=(const Band &rhs)
Assignment operator.
int m_nblocksy
The number of blocks in y.
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.
int m_type
The data type of the elements in the band ( See te::dt namespace basic data types for reference )...
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::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).
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.
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...
int m_blkw
Block width (pixels).
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)
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.
int getType() const
It returns the data type of the elements in the band.
int m_blkh
Block height (pixels).
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.