Commit 45eec126 authored by remi cresson's avatar remi cresson
Browse files

REFAC: externalize dates classes

parent 304d4063
......@@ -26,6 +26,9 @@
#include "otbStreamingResampleImageFilter.h"
#include "itkLinearInterpolateImageFunction.h"
// Dates
#include "otbDates.h"
namespace otb
{
......@@ -68,7 +71,7 @@ public:
typedef otb::UnaryFunctorImageFilter<FloatVectorImageType, UInt8VectorImageType, SlopeAndPValueLabelFunctorType> SlopeAndPValueLabelFilterType;
/* typedefs for dates*/
typedef otb::functor::SingleDate DateType;
typedef otb::dates::SingleDate DateType;
/* typedefs for image resampling */
typedef otb::StreamingResampleImageFilter<FloatVectorImageType, FloatVectorImageType> ResampleImageFilterType;
......@@ -226,41 +229,11 @@ private:
*/
std::vector<DateType> GetTimeSeriesDates(std::string key){
std::vector<DateType> dates;
std::vector<std::string> list = this->GetParameterStringList(key);
for (unsigned int i = 0 ; i < list.size() ; i++)
{
if (list[i].size()<=10)
{
int yyyy = std::stoi( list[i].substr(0,4) );
int mm = std::stoi( list[i].substr(5,2) );
int dd = std::stoi( list[i].substr(8,2) );
// Check values ranges
if (1950 > yyyy)
otbAppLogFATAL("Incorrect year in date: " << list[i] << "(" << key << ")");
if (0 >= mm || mm > 12)
otbAppLogFATAL("Incorrect month in date: " << list[i] << "(" << key << ")");
int nbOfDaysInMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
if (0 >= dd || dd > nbOfDaysInMonth[mm-1])
otbAppLogFATAL("Incorrect day in date: " << list[i] << "(" << key << ")");
// Add new date
DateType d(yyyy, mm, dd);
dates.push_back(d);
}
}
// Check dates ordering
for (unsigned int i = 0 ; i < list.size()-1 ; i++)
{
if (dates[i+1].julianday < dates[i].julianday)
otbAppLogFATAL("Dates must be in chronological order! (" << key << ")");
}
std::vector<DateType> dates = otb::dates::GetDatesFromStringVector(list);
otbAppLogINFO("Using " << dates.size() << " input dates from " << list[0] << " to " << list[list.size()-1] << "(" << key << ")");
otbAppLogINFO("Using " << dates.size() << " input dates from " << list[0] << " to " << list[list.size()-1] );
// return output
return dates;
}
......
......@@ -12,63 +12,14 @@
#define __otbNDVITimeSeriesFunctor_h
#include "vnl/vnl_vector.h"
#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/math/distributions/students_t.hpp"
#include <vector>
#include "assert.h"
#include "otbDates.h"
namespace otb
{
namespace functor
{
/*
* \class SingleDate
*
* \brief Class to handle dates. Julian day is computed at instantiation.
*
*/
class SingleDate
{
public:
SingleDate(int yyyy, int mm, int dd) {
year = yyyy;
day = dd;
month = mm;
// Compute julianday
boost::gregorian::date d(yyyy, mm, dd);
julianday = d.julian_day();
}
~SingleDate (){}
bool IsInRange(const int& startMonth,const int& startDay,const int& endMonth, const int& endDay) const
{
if (startMonth < month && month < endMonth)
{
return true;
}
else if (startMonth == month && startDay <= day)
{
return true;
}
else if (endMonth == month && day <= endDay)
{
return true;
}
else
{
return false;
}
}
int day;
int month;
int year;
int julianday;
};
/**
* \class TSReduceFunctorBase
*
......@@ -80,7 +31,8 @@ template< class TInputPixel, class TOutputPixel>
class TSReduceFunctorBase
{
public:
typedef std::vector<SingleDate> DatesType;
typedef otb::dates::SingleDate DateType;
typedef std::vector<DateType> DatesType;
typedef typename TInputPixel::ValueType PixelValueType;
TSReduceFunctorBase() {}
......
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef otbTernaryFunctorImageFilter_h
#define otbTernaryFunctorImageFilter_h
#include "itkTernaryFunctorImageFilter.h"
namespace otb
{
/**
* \class TernaryFunctorImageFilter
* \brief Implements pixel-wise generic operation on three images.
*
* Add the capability to change the number of channel when operation on
* VectorImage compared to the itk::TernaryFunctorImageFilter
*
* The number of channel is provided by the functor: TFunction::OutputSize. If
* this number is lower or equal to zero, the behavior of the itk::TernaryFunctorImageFilter
* remains unchanged.
*
* \sa itk::TernaryFunctorImageFilter
*
* \ingroup OTBCommon
*/
template <class TInputImage1, class TInputImage2, class TInputImage3, class TOutputImage, class TFunction>
class ITK_EXPORT TernaryFunctorImageFilter : public itk::TernaryFunctorImageFilter<TInputImage1, TInputImage2, TInputImage3, TOutputImage, TFunction>
{
public:
/** Standard class typedefs. */
typedef TernaryFunctorImageFilter Self;
typedef itk::TernaryFunctorImageFilter<TInputImage1, TInputImage2, TInputImage3, TOutputImage, TFunction> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(TernaryFunctorImageFilter, itk::TernaryFunctorImageFilter);
protected:
TernaryFunctorImageFilter() {};
~TernaryFunctorImageFilter() ITK_OVERRIDE {}
/** TernaryFunctorImageFilter can produce an image which has a different number of bands
* than its input image. As such, TernaryFunctorImageFilter
* needs to provide an implementation for
* GenerateOutputInformation() in order to inform the pipeline
* execution model. The original documentation of this method is
* below.
*
* \sa ProcessObject::GenerateOutputInformaton() */
void GenerateOutputInformation() ITK_OVERRIDE
{
Superclass::GenerateOutputInformation();
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info
this->GetFunctor().GetOutputSize());
}
private:
TernaryFunctorImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
};
} // end namespace otb
#endif
......@@ -6,6 +6,7 @@ otb_module(NDVITimeSeries
OTBCommon
OTBApplicationEngine
ClearCutsDetection
TimeSeriesUtils
TEST_DEPENDS
OTBTestKernel
......
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