otbWindowedSincInterpolateImageGaussianFunction.h 4.63 KB
Newer Older
1
/*
Julien Michel's avatar
Julien Michel committed
2
 * Copyright (C) 2005-2019 Centre National d'Etudes Spatiales (CNES)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 *
 * This file is part of Orfeo Toolbox
 *
 *     https://www.orfeo-toolbox.org/
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
20

21 22
#ifndef otbWindowedSincInterpolateImageGaussianFunction_h
#define otbWindowedSincInterpolateImageGaussianFunction_h
23 24 25 26 27 28

#include "otbWindowedSincInterpolateImageFunctionBase.h"
#include "vnl/vnl_math.h"

namespace otb
{
29 30

namespace Function
31
{
32
/**
33 34 35
 * \class GaussianWindowFunction
 * \brief Gaussian interpolation windowing function.
 * \f[ w(x) = exp ( -2. \frac{sigma*sigma * \pi } ) \f]
36
 * \sa otbWindowedSincInterpolateImageFunctionBase
37 38
 *
 * \ingroup OTBInterpolation
39
 */
OTB Bot's avatar
STYLE  
OTB Bot committed
40
template<class TInput = double, class TOutput = double>
41
class GaussianWindowFunction
42 43
{
public:
44
  GaussianWindowFunction(): m_Radius(1), m_Factor(-2.0 / CONST_PI) {} // default radius is 1 at construction
OTB Bot's avatar
STYLE  
OTB Bot committed
45
  void SetRadius(unsigned int radius)
46 47
  {
    m_Radius = radius;
OTB Bot's avatar
STYLE  
OTB Bot committed
48
    m_Factor = -2. / (static_cast<double>(m_Radius * m_Radius) * CONST_PI);
49 50 51 52
  }
  double GetFactor()
  {
    return m_Factor;
OTB Bot's avatar
STYLE  
OTB Bot committed
53
  }
54 55 56
  unsigned int GetRadius() const
  {
    return m_Radius;
OTB Bot's avatar
STYLE  
OTB Bot committed
57
  }
58

OTB Bot's avatar
STYLE  
OTB Bot committed
59
  inline TOutput operator ()(const TInput& A) const
60
  {
61
    double x = static_cast<double>(A);
62
    double px = CONST_PI * x;
63 64
    double temp = std::exp(px * px * m_Factor);
    return (x == 0.0) ? static_cast<TOutput>(temp) : static_cast<TOutput>(temp * std::sin(px) / px);
65 66 67
  }
private:
  unsigned int m_Radius;
68
  double       m_Factor;
69 70
};

OTB Bot's avatar
STYLE  
OTB Bot committed
71
} //namespace Function
72 73 74 75 76 77

/**
 * \class WindowedSincInterpolateImageGaussianFunction
 * \brief Use the WindowedSincInterpolateImageFunctionBase with a Gaussian Function.
 *
 * \sa GenericInterpolatorImageFunction
78 79 80
 * \sa Function::GaussianWindowFunction
 * \sa Function::HammingWindowFunction
 * \sa Function::CosineWindowFunction
81
 * \sa Function::WelchWindowFunction
82
 * \sa Function::LanczosWindowFunction
83 84
 * \sa Function::BlackmanWindowFunction
 * \ingroup ImageFunctionBases ImageInterpolators
85 86
 *
 * \ingroup OTBInterpolation
87
 */
88
template<class TInputImage, class TBoundaryCondition = itk::ZeroFluxNeumannBoundaryCondition<TInputImage>, class TCoordRep =
OTB Bot's avatar
STYLE  
OTB Bot committed
89
      double, class TInputInterpolator = double, class TOutputInterpolator = double>
90
class ITK_EXPORT WindowedSincInterpolateImageGaussianFunction :
OTB Bot's avatar
STYLE  
OTB Bot committed
91
  public WindowedSincInterpolateImageFunctionBase<TInputImage,
92
      typename Function::GaussianWindowFunction<TInputInterpolator,
OTB Bot's avatar
STYLE  
OTB Bot committed
93 94 95
          TOutputInterpolator>,
      TBoundaryCondition,
      TCoordRep>
96 97 98
{
public:
  /** Standard class typedefs. */
OTB Bot's avatar
STYLE  
OTB Bot committed
99
  typedef WindowedSincInterpolateImageGaussianFunction Self;
100
  typedef WindowedSincInterpolateImageFunctionBase<TInputImage,
101
      typename Function::GaussianWindowFunction<TInputInterpolator,
OTB Bot's avatar
STYLE  
OTB Bot committed
102 103 104
          TOutputInterpolator>,
      TBoundaryCondition,
      TCoordRep>
OTB Bot's avatar
STYLE  
OTB Bot committed
105 106 107
  Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;
108 109 110 111 112 113 114 115 116 117 118 119

  /** Run-time type information (and related methods). */
  itkTypeMacro(WindowedSincInterpolateImageGaussianFunction, WindowedSincInterpolateImageFunctionBase);

  /** Method for creation through the object factory. */
  itkNewMacro(Self);

  /** Input and output images typedef definition. */
  typedef typename Superclass::InputImageType InputImageType;
  typedef typename Superclass::OutputType     OutputType;

  /** Dimension underlying input image. */
OTB Bot's avatar
STYLE  
OTB Bot committed
120
  itkStaticConstMacro(ImageDimension, unsigned int, Superclass::ImageDimension);
121 122

  /** Superclass typedef inheritance. */
OTB Bot's avatar
STYLE  
OTB Bot committed
123 124 125 126 127
  typedef typename Superclass::IndexType           IndexType;
  typedef typename Superclass::SizeType            SizeType;
  typedef typename Superclass::RealType            RealType;
  typedef typename Superclass::IteratorType        IteratorType;
  typedef typename Superclass::ContinuousIndexType ContinuousIndexType;
128 129 130

protected:
  WindowedSincInterpolateImageGaussianFunction() {};
131 132
  ~WindowedSincInterpolateImageGaussianFunction() override {}
  void PrintSelf(std::ostream& os, itk::Indent indent) const override
133
  {
OTB Bot's avatar
STYLE  
OTB Bot committed
134 135
    Superclass::PrintSelf(os, indent);
  }
136

137
private:
138 139
  WindowedSincInterpolateImageGaussianFunction(const Self &) = delete;
  void operator =(const Self&) = delete;
140 141
};

142 143 144
} // end namespace otb

#endif