OTB  10.0.0
Orfeo Toolbox
otbSavitzkyGolayInterpolationFunctor.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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::PolynomialTimeSeries< Degree, CoefficientPrecisionType > TSFunctionType
itk::FixedArray< WeightType, InterpolatedLength > InterpolatedWeightType
otb::Functor::TimeSeriesLeastSquareFittingFunctor< InterpolatedSeriesType, TSFunctionType, InterpolatedDatesType, InterpolatedWeightType > TLSFunctorType
itk::FixedArray< DateType, InterpolatedLength > InterpolatedDatesType
itk::FixedArray< ValueType, InterpolatedLength > InterpolatedSeriesType
Implements a least squares fitting of a time profile.
unsigned int doy(const std::tm &d)
Return the day of year.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.