isce3  0.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Interpolator.h
1 //
2 // Author: Joshua Cohen, Bryan Riel, Liang Yu
3 // Copyright 2017-2018
4 //
5 
6 #pragma once
7 
8 #include "forward.h"
9 
10 #include <valarray>
11 
12 #include "Constants.h"
13 #include "EMatrix.h"
14 #include "Matrix.h"
15 
17 template<typename U>
19 
20 protected:
21  using Map = typename Eigen::Map<const EArray2D<U>>;
22 
23  // Public interface
24 public:
26  virtual ~Interpolator() {}
27 
28 protected:
30  virtual U interp_impl(double x, double y, const Map& map) const = 0;
31 
32 public:
33 
35  U interpolate(double x, double y, const Map& map) const
36  {
37  return interp_impl(x, y, map);
38  }
39 
41  U interpolate(double x, double y, const Matrix<U>& z) const
42  {
43  return interp_impl(x, y, z.map());
44  }
45 
47  U interpolate(double x, double y, std::valarray<U>& z_data,
48  size_t width) const
49  {
50  const Map z {&z_data[0],
51  static_cast<Eigen::Index>(z_data.size() / width),
52  static_cast<Eigen::Index>(width)};
53  return interp_impl(x, y, z);
54  }
55 
57  U interpolate(double x, double y, std::vector<U>& z_data,
58  size_t width) const
59  {
60  const Map z {&z_data[0],
61  static_cast<Eigen::Index>(z_data.size() / width),
62  static_cast<Eigen::Index>(width)};
63  return interp_impl(x, y, z);
64  }
65 
67  dataInterpMethod method() const { return _method; }
68 
69  // Protected constructor and data to be used by derived classes
70 protected:
71  inline Interpolator(dataInterpMethod method) : _method {method} {}
72  dataInterpMethod _method;
73 };
74 
76 template<typename U>
78 
79  using super_t = Interpolator<U>;
80  using typename super_t::Map;
81 
83  U interp_impl(double x, double y, const Map& z) const override;
84 
85 public:
87  BilinearInterpolator() : super_t {BILINEAR_METHOD} {}
88 
89  // Inherit overloads for other datatypes
91 };
92 
94 template<typename U>
96 
97  using super_t = Interpolator<U>;
98  using typename super_t::Map;
99 
101  U interp_impl(double x, double y, const Map& z) const override;
102 
103 public:
105  BicubicInterpolator() : super_t {BICUBIC_METHOD} {}
106 
107  // Inherit overloads for other datatypes
108  using super_t::interpolate;
109 };
110 
112 template<typename U>
114  public isce3::core::Interpolator<U> {
115 
116  using super_t = Interpolator<U>;
117  using typename super_t::Map;
118 
120  U interp_impl(double x, double y, const Map& z) const override;
121 
122 public:
124  NearestNeighborInterpolator() : super_t {NEAREST_METHOD} {}
125 
126  // Inherit overloads for other datatypes
127  using super_t::interpolate;
128 };
129 
131 template<typename U>
133 
134  using super_t = Interpolator<U>;
135  using typename super_t::Map;
136 
137 public:
139  Spline2dInterpolator(size_t order);
140 
142  U interp_impl(double x, double y, const Map& z) const override;
143 
144  // Inherit overloads for other datatypes
145  using super_t::interpolate;
146 
147  // Data members
148 private:
149  size_t _order;
150 
151  // Utility spline functions
152 private:
153  void _initSpline(const std::valarray<U>&, int, std::valarray<U>&,
154  std::valarray<U>&) const;
155 
156  U _spline(double, const std::valarray<U>&, int,
157  const std::valarray<U>&) const;
158 };
159 
161 template<typename U>
163 
164  using super_t = Interpolator<U>;
165  using typename super_t::Map;
166 
168  U interp_impl(double x, double y, const Map& z) const override;
169 
170 public:
172  Sinc2dInterpolator(int sincLen, int sincSub);
173 
174  // Inherit overloads for other datatypes
175  using super_t::interpolate;
176 
177 private:
178  // Compute sinc coefficients
179  void _sinc_coef(double beta, double relfiltlen, int decfactor,
180  double pedestal, int weight,
181  std::valarray<double>& filter) const;
182 
183  // Evaluate sinc
184  U _sinc_eval_2d(const Map& z, int intpx, int intpy, double frpx,
185  double frpy) const;
186 
187 private:
188  Matrix<double> _kernel;
189  int _kernelLength, _kernelWidth, _sincHalf;
190 };
191 
192 // Extra interpolation and utility functions
193 namespace isce3 { namespace core {
194 
197 template<typename U>
198 inline Interpolator<U>*
199 createInterpolator(dataInterpMethod method, size_t order = 6,
200  int sincLen = SINC_LEN, int sincSub = SINC_SUB)
201 {
202  if (method == BILINEAR_METHOD) {
203  return new BilinearInterpolator<U>();
204  } else if (method == BICUBIC_METHOD) {
205  return new BicubicInterpolator<U>();
206  } else if (method == BIQUINTIC_METHOD) {
207  return new Spline2dInterpolator<U>(order);
208  } else if (method == NEAREST_METHOD) {
209  return new NearestNeighborInterpolator<U>();
210  } else if (method == SINC_METHOD) {
211  return new Sinc2dInterpolator<U>(sincLen, sincSub);
212  } else {
213  return new BilinearInterpolator<U>();
214  }
215 }
216 
217 // Sinc evaluation in 1D
218 template<class U, class V>
219 U sinc_eval(const Matrix<U>&, const Matrix<V>&, int, int, double, int);
220 
221 }} // namespace isce3::core
dataInterpMethod
Enumeration type to indicate interpolation method.
Definition: Constants.h:23
virtual U interp_impl(double x, double y, const Map &map) const =0
Base implementation for all types.
Definition of BicubicInterpolator.
Definition: forward.h:35
U sinc_eval(const Matrix< U > &, const Matrix< V > &, int, int, double, int)
1-D sinc evaluation
Definition: Interpolator.cpp:11
virtual ~Interpolator()
Virtual destructor (allow destruction of base Interpolator pointer)
Definition: Interpolator.h:26
U interpolate(double x, double y, const Matrix< U > &z) const
Interpolate at a given coordinate for an input isce3::core::Matrix.
Definition: Interpolator.h:41
Interpolator< U > * createInterpolator(dataInterpMethod method, size_t order=6, int sincLen=SINC_LEN, int sincSub=SINC_SUB)
Utility function to create interpolator pointer given an interpolator enum type.
Definition: Interpolator.h:199
NearestNeighborInterpolator()
Default constructor.
Definition: Interpolator.h:124
U interpolate(double x, double y, std::valarray< U > &z_data, size_t width) const
Interpolate at a given coordinate for data passed as a valarray.
Definition: Interpolator.h:47
Sinc2dInterpolator(int sincLen, int sincSub)
Default constructor.
Definition: Sinc2dInterpolator.cpp:14
U interp_impl(double x, double y, const Map &z) const override
Interpolate at a given coordinate.
Definition: Spline2dInterpolator.cpp:33
Data structure for a 2D row-major matrix.
Definition: forward.h:31
BicubicInterpolator()
Default constructor.
Definition: Interpolator.h:105
Spline2dInterpolator(size_t order)
Default constructor.
Definition: Spline2dInterpolator.cpp:12
U interpolate(double x, double y, const Map &map) const
Interpolate at a given coordinate for an input Eigen::Map.
Definition: Interpolator.h:35
BilinearInterpolator()
Default constructor.
Definition: Interpolator.h:87
Definition of NearestNeighborInterpolator.
Definition: forward.h:36
dataInterpMethod method() const
Return interpolation method.
Definition: Interpolator.h:67
Definition of Sinc2dInterpolator.
Definition: forward.h:38
Definition of BilinearInterpolator.
Definition: forward.h:34
Definition of Spline2dInterpolator.
Definition: forward.h:37
U interpolate(double x, double y, std::vector< U > &z_data, size_t width) const
Interpolate at a given coordinate for data passed as a vector.
Definition: Interpolator.h:57
Definition of parent Interpolator.
Definition: forward.h:33

Generated for ISCE3.0 by doxygen 1.8.5.