OTB  9.0.0
Orfeo Toolbox
otbSavitzkyGolayInterpolationFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbSavitzkyGolayInterpolationFunctor_h
22 #define otbSavitzkyGolayInterpolationFunctor_h
23 
24 #include "otbTimeSeries.h"
26 
27 
28 namespace otb
29 {
30 namespace Functor
31 {
32 
56 template <unsigned int Radius, class TSeries, class TDates, class TWeight = TSeries, unsigned int Degree = 2>
58 {
59 public:
60  typedef typename TSeries::ValueType ValueType;
61  typedef typename TDates::ValueType DateType;
62  typedef typename TWeight::ValueType WeightType;
63  typedef double CoefficientPrecisionType;
65  static const unsigned int nbDates = TSeries::Dimension;
66  static const unsigned int InterpolatedLength = 2 * Radius + 1;
67 
68  typedef itk::FixedArray<ValueType, InterpolatedLength> InterpolatedSeriesType;
69  typedef itk::FixedArray<DateType, InterpolatedLength> InterpolatedDatesType;
70  typedef itk::FixedArray<WeightType, InterpolatedLength> InterpolatedWeightType;
71 
74 
77  {
78  }
81  {
82  }
83 
84  inline void SetWeights(const TWeight weights)
85  {
86  for (unsigned int i = 0; i < m_WeightSeries.Size(); ++i)
87  m_WeightSeries[i] = weights[i];
88  }
89 
90  inline void SetDates(const TDates doy)
91  {
92  for (unsigned int i = 0; i < m_DoySeries.Size(); ++i)
93  m_DoySeries[i] = doy[i];
94  }
95 
96  inline TSeries operator()(const TSeries& series) const
97  {
98  TSeries outSeries;
99 
100  unsigned int firstSample = Radius;
101  unsigned int lastSample = nbDates - Radius - 1;
102 
103  for (unsigned int i = 0; i < firstSample; ++i)
104  outSeries[i] = series[i];
105  for (unsigned int i = lastSample + 1; i < nbDates; ++i)
106  outSeries[i] = series[i];
107 
108  for (unsigned int i = firstSample; i <= lastSample; ++i)
109  {
110  InterpolatedSeriesType tmpInSeries;
111  InterpolatedDatesType tmpDates;
112  InterpolatedWeightType tmpWeights;
113 
114  for (unsigned int j = 0; j <= 2 * Radius; ++j)
115  {
116  tmpInSeries[j] = series[i + j - Radius];
117  tmpDates[j] = m_DoySeries[i + j - Radius];
118  tmpWeights[j] = m_WeightSeries[i + j - Radius];
119  }
120 
121  TLSFunctorType f;
122  f.SetDates(tmpDates);
123  f.SetWeights(tmpWeights);
124  InterpolatedSeriesType tmpOutSeries = f(tmpInSeries);
125  outSeries[i] = tmpOutSeries[Radius];
126  }
127 
128  return outSeries;
129  }
130 
131 private:
132  TWeight m_WeightSeries;
133  TDates m_DoySeries;
134 };
135 }
136 } // namespace otb
137 #endif
otb::Functor::SavitzkyGolayInterpolationFunctor::TSFunctionType
otb::PolynomialTimeSeries< Degree, CoefficientPrecisionType > TSFunctionType
Definition: otbSavitzkyGolayInterpolationFunctor.h:64
otb::Functor::SavitzkyGolayInterpolationFunctor::SetDates
void SetDates(const TDates doy)
Definition: otbSavitzkyGolayInterpolationFunctor.h:90
otb::Functor::SavitzkyGolayInterpolationFunctor::InterpolatedWeightType
itk::FixedArray< WeightType, InterpolatedLength > InterpolatedWeightType
Definition: otbSavitzkyGolayInterpolationFunctor.h:70
otb::Functor::SavitzkyGolayInterpolationFunctor::WeightType
TWeight::ValueType WeightType
Definition: otbSavitzkyGolayInterpolationFunctor.h:62
otbTimeSeriesLeastSquareFittingFunctor.h
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::SavitzkyGolayInterpolationFunctor::m_WeightSeries
TWeight m_WeightSeries
Definition: otbSavitzkyGolayInterpolationFunctor.h:132
otb::Functor::SavitzkyGolayInterpolationFunctor::~SavitzkyGolayInterpolationFunctor
virtual ~SavitzkyGolayInterpolationFunctor()
Destructor.
Definition: otbSavitzkyGolayInterpolationFunctor.h:80
otb::Functor::SavitzkyGolayInterpolationFunctor::CoefficientPrecisionType
double CoefficientPrecisionType
Definition: otbSavitzkyGolayInterpolationFunctor.h:63
otb::Functor::SavitzkyGolayInterpolationFunctor::InterpolatedLength
static const unsigned int InterpolatedLength
Definition: otbSavitzkyGolayInterpolationFunctor.h:66
otb::Functor::SavitzkyGolayInterpolationFunctor::SetWeights
void SetWeights(const TWeight weights)
Definition: otbSavitzkyGolayInterpolationFunctor.h:84
otb::Functor::SavitzkyGolayInterpolationFunctor::nbDates
static const unsigned int nbDates
Definition: otbSavitzkyGolayInterpolationFunctor.h:65
otb::Functor::SavitzkyGolayInterpolationFunctor::TLSFunctorType
otb::Functor::TimeSeriesLeastSquareFittingFunctor< InterpolatedSeriesType, TSFunctionType, InterpolatedDatesType, InterpolatedWeightType > TLSFunctorType
Definition: otbSavitzkyGolayInterpolationFunctor.h:73
otb::Functor::SavitzkyGolayInterpolationFunctor::InterpolatedSeriesType
itk::FixedArray< ValueType, InterpolatedLength > InterpolatedSeriesType
Definition: otbSavitzkyGolayInterpolationFunctor.h:68
otb::Functor::SavitzkyGolayInterpolationFunctor::operator()
TSeries operator()(const TSeries &series) const
Definition: otbSavitzkyGolayInterpolationFunctor.h:96
GapFilling::doy
unsigned int doy(const std::tm &d)
Return the day of year.
otb::Functor::SavitzkyGolayInterpolationFunctor::ValueType
TSeries::ValueType ValueType
Definition: otbSavitzkyGolayInterpolationFunctor.h:60
otb::Functor::TimeSeriesLeastSquareFittingFunctor
Implements a least squares fitting of a time profile.
Definition: otbTimeSeriesLeastSquareFittingFunctor.h:59
otb::Functor::SavitzkyGolayInterpolationFunctor::InterpolatedDatesType
itk::FixedArray< DateType, InterpolatedLength > InterpolatedDatesType
Definition: otbSavitzkyGolayInterpolationFunctor.h:69
otb::Functor::SavitzkyGolayInterpolationFunctor::SavitzkyGolayInterpolationFunctor
SavitzkyGolayInterpolationFunctor()
Constructor.
Definition: otbSavitzkyGolayInterpolationFunctor.h:76
otb::Functor::SavitzkyGolayInterpolationFunctor::m_DoySeries
TDates m_DoySeries
Definition: otbSavitzkyGolayInterpolationFunctor.h:133
otb::Functor::SavitzkyGolayInterpolationFunctor
Definition: otbSavitzkyGolayInterpolationFunctor.h:57
otb::Functor::SavitzkyGolayInterpolationFunctor::DateType
TDates::ValueType DateType
Definition: otbSavitzkyGolayInterpolationFunctor.h:61
otb::Functor::TimeSeriesLeastSquareFittingFunctor::SetDates
void SetDates(const TDateType &doy)
Definition: otbTimeSeriesLeastSquareFittingFunctor.h:84
otb::Functor::TimeSeriesLeastSquareFittingFunctor::SetWeights
void SetWeights(const TWeightType &weights)
Definition: otbTimeSeriesLeastSquareFittingFunctor.h:90
otb::PolynomialTimeSeries
Definition: otbTimeSeries.h:30
otbTimeSeries.h