From c6291eb2d3d4b6126042285292091062ca665de3 Mon Sep 17 00:00:00 2001 From: remi cresson <remi.cresson@teledetection.fr> Date: Thu, 3 Aug 2017 09:03:56 +0000 Subject: [PATCH] REFAC: externalize dates classes --- app/otbClearCutsMultitemporalDetection.cxx | 37 +++--------------- include/otbDeltaNDVIFunctor.h | 45 ++-------------------- 2 files changed, 8 insertions(+), 74 deletions(-) diff --git a/app/otbClearCutsMultitemporalDetection.cxx b/app/otbClearCutsMultitemporalDetection.cxx index 8d26150..a0366ff 100644 --- a/app/otbClearCutsMultitemporalDetection.cxx +++ b/app/otbClearCutsMultitemporalDetection.cxx @@ -39,6 +39,9 @@ #include "otbMosaicFromDirectoryHandler.h" #include "itkMaskImageFilter.h" +// Dates +#include "otbDates.h" + //// Label image filtering //#include "otbConnectedComponentsFunctorImageFilter.h" @@ -68,7 +71,7 @@ public: typedef ObjectList<ExtractROIFilterType> ExtractROIFilterListType; /** Typedefs for temporal correlation */ - typedef otb::Functor::DeltaNDVIDate DateType; + typedef otb::dates::SingleDate DateType; typedef otb::Functor::MultitemporalCorrelationFunctor<FloatVectorImageType::PixelType, UInt8VectorImageType::PixelType> TemporalCorrelationFunctorType; typedef otb::UnaryFunctorImageFilter<FloatVectorImageType, UInt8VectorImageType, TemporalCorrelationFunctorType> TemporalCorrelationFilterType; @@ -171,41 +174,11 @@ public: std::vector<DateType> GetTimeSeriesDates() { - std::vector<DateType> dates; std::vector<std::string> list = this->GetParameterStringList("dates"); - 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]); - if (0 >= mm || mm > 12) - otbAppLogFATAL("Incorrect month in date: " << list[i]); - 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]); - - // 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!"); - } + std::vector<DateType> dates = otb::dates::GetDatesFromStringVector(list); otbAppLogINFO("Using " << dates.size() << " input dates from " << list[0] << " to " << list[list.size()-1] ); - // return output return dates; } // diff --git a/include/otbDeltaNDVIFunctor.h b/include/otbDeltaNDVIFunctor.h index c935941..18e77ac 100644 --- a/include/otbDeltaNDVIFunctor.h +++ b/include/otbDeltaNDVIFunctor.h @@ -17,6 +17,7 @@ #include "vnl/vnl_vector.h" #include "vnl/vnl_matrix.h" #include <vector> +#include "otbDates.h" namespace otb { @@ -85,47 +86,6 @@ private: }; -class DeltaNDVIDate -{ -public: - DeltaNDVIDate(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(); - } - - ~DeltaNDVIDate (){} - - 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 MultitemporalCorrelationFunctor * \brief This functor computes the "NDVI drop" index * @@ -137,7 +97,8 @@ class MultitemporalCorrelationFunctor { typedef typename TNDVIStack::ValueType NDVIValueType; typedef typename TOutputLabel::ValueType OutputLabelValueType; - typedef std::vector<DeltaNDVIDate> DatesType; + typedef otb::dates::SingleDate DateType; + typedef std::vector<DateType> DatesType; public: -- GitLab