isce3 0.25.0
Loading...
Searching...
No Matches
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
17template<typename U>
19
20protected:
21 using Map = typename Eigen::Map<const EArray2D<U>>;
22
23 // Public interface
24public:
26 virtual ~Interpolator() {}
27
28protected:
30 virtual U interp_impl(double x, double y, const Map& map) const = 0;
31
32public:
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
70protected:
71 inline Interpolator(dataInterpMethod method) : _method {method} {}
72 dataInterpMethod _method;
73};
74
76template<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
85public:
87 BilinearInterpolator() : super_t {BILINEAR_METHOD} {}
88
89 // Inherit overloads for other datatypes
91};
92
94template<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
103public:
105 BicubicInterpolator() : super_t {BICUBIC_METHOD} {}
106
107 // Inherit overloads for other datatypes
109};
110
112template<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
122public:
124 NearestNeighborInterpolator() : super_t {NEAREST_METHOD} {}
125
126 // Inherit overloads for other datatypes
128};
129
131template<typename U>
133
134 using super_t = Interpolator<U>;
135 using typename super_t::Map;
136
137public:
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
146
147 // Data members
148private:
149 size_t _order;
150
151 // Utility spline functions
152private:
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
161template<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
170public:
172 Sinc2dInterpolator(int kernelLength, int decimationFactor);
173
174 // Inherit overloads for other datatypes
176
177private:
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 Matrix<double> _kernel;
188 // Sinc decimation factor
189 int _decimationFactor;
190
191 // Length of sinc kernel
192 int _kernelLength;
193
194 // Half length of sinc kernel
195 int _halfKernelLength;
196};
197
198// Extra interpolation and utility functions
199namespace isce3 { namespace core {
200
203template<typename U>
204inline Interpolator<U>*
205createInterpolator(dataInterpMethod method, size_t order = 6,
206 int sincLen = SINC_LEN, int sincSub = SINC_SUB)
207{
208 if (method == BILINEAR_METHOD) {
209 return new BilinearInterpolator<U>();
210 } else if (method == BICUBIC_METHOD) {
211 return new BicubicInterpolator<U>();
212 } else if (method == BIQUINTIC_METHOD) {
213 return new Spline2dInterpolator<U>(order);
214 } else if (method == NEAREST_METHOD) {
216 } else if (method == SINC_METHOD) {
217 return new Sinc2dInterpolator<U>(sincLen, sincSub);
218 } else {
219 return new BilinearInterpolator<U>();
220 }
221}
222
223// Sinc evaluation in 1D
224template<class U, class V>
225U sinc_eval(const Matrix<U>&, const Matrix<V>&, int, int, double, int);
226
227}} // namespace isce3::core
Definition of BicubicInterpolator.
Definition Interpolator.h:95
BicubicInterpolator()
Default constructor.
Definition Interpolator.h:105
Definition of BilinearInterpolator.
Definition Interpolator.h:77
BilinearInterpolator()
Default constructor.
Definition Interpolator.h:87
Definition of parent Interpolator.
Definition Interpolator.h:18
virtual ~Interpolator()
Virtual destructor (allow destruction of base Interpolator pointer)
Definition Interpolator.h:26
virtual U interp_impl(double x, double y, const Map &map) const =0
Base implementation for all types.
U interpolate(double x, double y, const Map &map) const
Interpolate at a given coordinate for an input Eigen::Map.
Definition Interpolator.h:35
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
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
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
dataInterpMethod method() const
Return interpolation method.
Definition Interpolator.h:67
Data structure for a 2D row-major matrix.
Definition Matrix.h:23
Definition of NearestNeighborInterpolator.
Definition Interpolator.h:114
NearestNeighborInterpolator()
Default constructor.
Definition Interpolator.h:124
Definition of Sinc2dInterpolator.
Definition Interpolator.h:162
Sinc2dInterpolator(int kernelLength, int decimationFactor)
Default constructor.
Definition Sinc2dInterpolator.cpp:14
Definition of Spline2dInterpolator.
Definition Interpolator.h:132
U interp_impl(double x, double y, const Map &z) const override
Interpolate at a given coordinate.
Definition Spline2dInterpolator.cpp:33
Spline2dInterpolator(size_t order)
Default constructor.
Definition Spline2dInterpolator.cpp:12
base interpolator is an abstract base class
Definition BinarySearchFunc.cpp:5

Generated for ISCE3.0 by doxygen 1.13.2.