Commit 84c4d7d2 authored by remi cresson's avatar remi cresson
Browse files

ADD: new functors TSMaxReduceFunctor and TSAmplitudeReduceFunctor

parent 3426d050
......@@ -125,29 +125,29 @@ private:
/**
* \class TSReduceFromRangeFunctor
* \class TSCumulatedRangeReduceFunctor
*
* \brief Class for reducing N-components pixel into M-component pixel (N=nb. of images and M=nb. of years)
* given a range (dd/mm--->dd'/mm')
*
*/
template< class TInputPixel, class TOutputPixel>
class TSReduceFromRangeFunctor : TSReduceFunctorBase<TInputPixel,TOutputPixel>
class TSCumulatedRangeReduceFunctor : TSReduceFunctorBase<TInputPixel,TOutputPixel>
{
public:
typedef typename TSReduceFunctorBase<TInputPixel,TOutputPixel>::DatesType DatesType;
typedef typename TInputPixel::ValueType PixelValueType;
TSReduceFromRangeFunctor() {}
TSCumulatedRangeReduceFunctor() {}
~TSReduceFromRangeFunctor() {}
~TSCumulatedRangeReduceFunctor() {}
bool operator!=( const TSReduceFromRangeFunctor & ) const {
bool operator!=( const TSCumulatedRangeReduceFunctor & ) const {
return false;
}
bool operator==( const TSReduceFromRangeFunctor & other ) const {
bool operator==( const TSCumulatedRangeReduceFunctor & other ) const {
return !(*this != other);
}
......@@ -155,7 +155,7 @@ inline TOutputPixel operator ()(const TInputPixel& input) const
{
TOutputPixel output;
output.SetSize(this->GetOutputSize());
output.Fill(0);
output.Fill(this->GetInputNoDataValue());
DatesType m_Dates = this->GetDates();
......@@ -193,7 +193,150 @@ int m_Day2;
int m_Month1;
int m_Month2;
}; // TSReduceFromRangeFunctor
}; // TSCumulatedRangeReduceFunctor
/**
* \class TSMaxReduceFunctor
*
* \brief Class for reducing N-components pixel into M-component pixel (N=nb. of images and M=nb. of years)
* returns for each year the max() value
*
*/
template< class TInputPixel, class TOutputPixel>
class TSMaxReduceFunctor : TSReduceFunctorBase<TInputPixel,TOutputPixel>
{
public:
typedef typename TSReduceFunctorBase<TInputPixel,TOutputPixel>::DatesType DatesType;
typedef typename TInputPixel::ValueType PixelValueType;
TSMaxReduceFunctor() {}
~TSMaxReduceFunctor() {}
bool operator!=( const TSMaxReduceFunctor & ) const {
return false;
}
bool operator==( const TSMaxReduceFunctor & other ) const {
return !(*this != other);
}
inline TOutputPixel operator ()(const TInputPixel& input) const
{
TOutputPixel output;
output.SetSize(this->GetOutputSize());
output.Fill(this->GetInputNoDataValue());
DatesType m_Dates = this->GetDates();
int firstYear = m_Dates[0].year;
for (unsigned int i = 0; i < input.Size(); i++)
{
int index = m_Dates[i].year - firstYear;
PixelValueType inValue = input[i];
if (inValue != this->GetInputNoDataValue())
{
if (output[index] == this->GetInputNoDataValue())
{
output[index] = inValue;
}
else if (output[index] < inValue)
{
output[index] = inValue;
}
}
}
return output;
}
}; // TSMaxReduceFunctor
/**
* \class TSAmplitudeReduceFunctor
*
* \brief Class for reducing N-components pixel into M-component pixel (N=nb. of images and M=nb. of years)
* returns for each year the max()-min() value
*
*/
template< class TInputPixel, class TOutputPixel>
class TSAmplitudeReduceFunctor : TSReduceFunctorBase<TInputPixel,TOutputPixel>
{
public:
typedef typename TSReduceFunctorBase<TInputPixel,TOutputPixel>::DatesType DatesType;
typedef typename TInputPixel::ValueType PixelValueType;
TSAmplitudeReduceFunctor() {}
~TSAmplitudeReduceFunctor() {}
bool operator!=( const TSAmplitudeReduceFunctor & ) const {
return false;
}
bool operator==( const TSAmplitudeReduceFunctor & other ) const {
return !(*this != other);
}
inline TOutputPixel operator ()(const TInputPixel& input) const
{
TOutputPixel output;
output.SetSize(this->GetOutputSize());
output.Fill(this->GetInputNoDataValue());
DatesType m_Dates = this->GetDates();
TOutputPixel minimums, maximums;
minimums.SetSize(this->GetOutputSize());
maximums.SetSize(this->GetOutputSize());
minimums.Fill(this->GetInputNoDataValue());
maximums.Fill(this->GetInputNoDataValue());
int firstYear = m_Dates[0].year;
for (unsigned int i = 0; i < input.Size(); i++)
{
int index = m_Dates[i].year - firstYear;
PixelValueType inValue = input[i];
if (inValue != this->GetInputNoDataValue())
{
// Update maximums
if (maximums[index] == this->GetInputNoDataValue())
{
maximums[index] = inValue;
}
else if (maximums[index] < inValue)
{
maximums[index] = inValue;
}
// Update minimums
if (minimums[index] == this->GetInputNoDataValue())
{
minimums[index] = inValue;
}
else if (inValue < minimums[index])
{
minimums[index] = inValue;
}
}
}
// Compute amplitude
int lastYear = m_Dates[m_Dates.Size()-1].year;
for (unsigned int i = 0 ; i < lastYear - firstYear +1 ; i++ )
{
if (minimums[i] != m_InputNoDataValue && maximums[i] != m_InputNoDataValue)
{
output[i] = maximums[i] - minimums[i];
}
}
return output;
}
}; // TSAmplitudeReduceFunctor
/**
* \class SlopeAndPValueFunctor
......@@ -442,7 +585,7 @@ protected:
unsigned int numberOfComponentsPerPixel;
};
}; // SlopeAndPValueLabelingFunctor
} // namespace functor
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment