casacore
Loading...
Searching...
No Matches
Interpolate2D.h
Go to the documentation of this file.
1//# Interpolate2D.h: this defines the Interpolate2D class
2//# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2004
3//# Associated Universities, Inc. Washington DC, USA.
4//#
5//# This library is free software; you can redistribute it and/or modify it
6//# under the terms of the GNU Library General Public License as published by
7//# the Free Software Foundation; either version 2 of the License, or (at your
8//# option) any later version.
9//#
10//# This library is distributed in the hope that it will be useful, but WITHOUT
11//# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12//# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13//# License for more details.
14//#
15//# You should have received a copy of the GNU Library General Public License
16//# along with this library; if not, write to the Free Software Foundation,
17//# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18//#
19//# Correspondence concerning AIPS++ should be addressed as follows:
20//# Internet email: casa-feedback@nrao.edu.
21//# Postal address: AIPS++ Project Office
22//# National Radio Astronomy Observatory
23//# 520 Edgemont Road
24//# Charlottesville, VA 22903-2475 USA
25
26#ifndef SCIMATH_INTERPOLATE2D_H
27#define SCIMATH_INTERPOLATE2D_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/BasicSL/Complex.h>
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36//# Forward declarations
37class String;
38
39// <summary>
40// A two dimension interpolator for Matrices or Arrays
41// </summary>
42
43// <use visibility=export>
44
45// <reviewed reviewer="wbrouw" date="2004/05/26" tests="" demos="">
46// </reviewed>
47
48// <prerequisite>
49// <li> <linkto class=Array>Arrays</linkto>
50// </prerequisite>
51//
52// <etymology>
53// This class is called Interpolate2D because it does 2 dimensional interpolations
54// </etymology>
55//
56// <synopsis>
57// Given a regular Array or Matrix and a vector of pixel
58// coordinates, interpolate the values of that array/matrix onto those
59// pixel coordinates.
60//
61// Absolutely no checking of the consistency of the input data
62// is done in order to preserve maximum speed. The coordinate vector
63// *must* have at least 2 elements (others will be ignored). If
64// you supply data and mask, those arrays *must* be the same shape.
65// Failure to follow these rules will result in your program
66// crashing.
67// </synopsis>
68//
69// <example>
70// <srcblock>
71//
72// Matrix<Float> matt(10,10);
73// Vector<Double> where(2);
74// where(0) = 3.452; where(1) = 6.1;
75// Interpolate2D myInterp(Interpolate2D::LINEAR);
76// Float result;
77// Bool ok = myInterp.interp(result, where, matt);
78//
79// </srcblock>
80// </example>
81//
82// <motivation>
83// 2-D interpolation is required in geometry transformation routines
84// such as in ImageRegrid.
85// </motivation>
86//
87//
88// <todo asof="1998/08/02">
89// <li> Alternative approach: instantiate with an Array, take a block of
90// vector locations, return a block of interpolation results
91// </todo>
92
93
95 public:
96
97 enum Method {
98
99 // Nearest neighbour
101
102 // Bilinear
104
105 // Bicubic
107
108 // Lanczos
110
111 // Constructor
113
114 // Copy constructor (copy semantics)
116
117 // destructor
119
120 // Assignment operator (copy semantics)
122
123 // Do one Float interpolation, supply Matrix and mask (True is good),
124 // and pixel coordinate. Returns False if coordinate out of range or data
125 // are masked. No shape integrity checking is done (see above).
126 // <group>
127 Bool interp (Float &result,
128 const Vector<Double> &where,
129 const Matrix<Float> &data) const;
130 Bool interp (Float &result,
131 const Vector<Double> &where,
132 const Matrix<Float> &data,
133 const Matrix<Bool> &mask) const;
134 // </group>
135
136 // Do one Double interpolation, supply Matrix/Array and mask (True is good),
137 // and pixel coordinate. Returns False if coordinate out of range or data
138 // are masked. No shape integrity checking is done (see above).
139 // <group>
140 Bool interp (Double &result,
141 const Vector<Double> &where,
142 const Matrix<Double> &data) const;
143 Bool interp (Double &result,
144 const Vector<Double> &where,
145 const Matrix<Double> &data,
146 const Matrix<Bool> &mask) const;
147 // </group>
148
149 // Do one Complex interpolation, supply Matrix/Array and mask (True is good),
150 // and pixel coordinate. Returns False if coordinate out of range or data
151 // are masked. No shape integrity checking is done (see above). The real
152 // and imaginary parts are treated independently (see CAS-11375).
153 // <group>
154 Bool interp (Complex &result,
155 const Vector<Double> &where,
156 const Matrix<Complex> &data) const;
157 Bool interp (Complex &result,
158 const Vector<Double> &where,
159 const Matrix<Complex> &data,
160 const Matrix<Bool> &mask) const;
161 // </group>
162
163 // Do one DComplex interpolation, supply Matrix/Array and mask (True is good),
164 // and pixel coordinate. Returns False if coordinate out of range or data
165 // are masked. No shape integrity checking is done (see above). The real
166 // and imaginary parts are treated independently (see CAS-11375).
167 // <group>
168 Bool interp (DComplex &result,
169 const Vector<Double> &where,
170 const Matrix<DComplex> &data) const;
171 Bool interp (DComplex &result,
172 const Vector<Double> &where,
173 const Matrix<DComplex> &data,
174 const Matrix<Bool> &mask) const;
175 // </group>
176
177 // Do two linear interpolations simultaneously. The second call is direct.
178 // The first call transfers to the second call. It is assumed that the
179 // structure (shape, steps) of the mask and data files are the same.
180 // <group>
181 Bool interp(Double &resultI, Double &resultJ,
182 const Vector<Double> &where,
183 const Matrix<Double> &dataI,
184 const Matrix<Double> &dataJ,
185 const Matrix<Bool> &mask) const;
186 template <typename T>
187 Bool interpLinear2(T &resultI, T &resultJ,
188 const Vector<Double> &where,
189 const Matrix<T> &dataI,
190 const Matrix<T> &dataJ,
191 const Matrix<Bool> &mask) const;
192 // </group>
193
194 // Do one interpolation, supply boolean Matrix (True is good),
195 // and pixel coordinate. Returns False if coordinate
196 // out of range. The result is False if any data value in the interpolation
197 // grid are False (bad), else True. No shape integrity checking is done.
198 // <group>
199 Bool interp (Bool &result,
200 const Vector<Double> &where,
201 const Matrix<Bool> &data) const;
202 // </group>
203
204 // Convert string ("nearest", "linear", "cubic", "lanczos") to interpolation
205 // method. The match is case insensitive.
207
208 private:
209
210 // Are any of the mask pixels bad ? Returns False if no mask.
212 Int j1, Int j2) const;
213
214 // nearest neighbour interpolation
215 template <typename T>
216 Bool interpNearest(T &result, const Vector<Double> &where,
217 const Matrix<T> &data,
218 const Matrix<Bool>* &maskPtr) const;
220 const Matrix<Bool> &data) const;
221
222 // bi-linear interpolation
223 template <typename T>
224 Bool interpLinear(T &result, const Vector<Double> &where,
225 const Matrix<T> &data,
226 const Matrix<Bool>* &maskPtr) const;
228 const Matrix<Bool> &data) const;
229
230 // bi-cubic interpolation
231 template <typename T>
232 Bool interpCubic(T &result, const Vector<Double> &where,
233 const Matrix<T> &data,
234 const Matrix<Bool>* &maskPtr) const;
236 const Matrix<Bool> &data) const;
237
238 // Lanczos interpolation
239 template <typename T>
240 Bool interpLanczos(T &result, const Vector<Double> &where,
241 const Matrix<T> &data,
242 const Matrix<Bool>* &maskPtr) const;
244 const Matrix<Bool> &data) const;
245 // Lanczos interpolation: helper functions
246 template <typename T>
247 T sinc(const T x) const;
248 template <typename T>
249 T L(const T x, const Int a) const;
250
251 // helping routine from numerical recipes
252 void bcucof (Double c[4][4], const Double y[4],
253 const Double y1[4],
254 const Double y2[4], const Double y12[4]) const;
255
256 // Typedefs for function pointers
258 (Float &result,
259 const Vector<Double> &where,
260 const Matrix<Float> &data,
261 const Matrix<Bool>* &maskPtr) const;
263 (Double &result,
264 const Vector<Double> &where,
265 const Matrix<Double> &data,
266 const Matrix<Bool>* &maskPtr) const;
268 (Bool &result,
269 const Vector<Double> &where,
270 const Matrix<Bool> &data) const;
271 //
275
276};
277
278
279} //# NAMESPACE CASACORE - END
280
281#ifndef CASACORE_NO_AUTO_TEMPLATES
282#include <casacore/scimath/Mathematics/Interpolate2D2.tcc>
283#endif //# CASACORE_NO_AUTO_TEMPLATES
284#endif
285
Bool anyBadMaskPixels(const Matrix< Bool > *&mask, Int i1, Int i2, Int j1, Int j2) const
Are any of the mask pixels bad ? Returns False if no mask.
Interpolate2D(Interpolate2D::Method method=Interpolate2D::LINEAR)
Constructor.
Bool interpLinearBool(Bool &result, const Vector< Double > &where, const Matrix< Bool > &data) const
FuncPtrDouble itsFuncPtrDouble
void bcucof(Double c[4][4], const Double y[4], const Double y1[4], const Double y2[4], const Double y12[4]) const
helping routine from numerical recipes
Bool interpLinear2(T &resultI, T &resultJ, const Vector< Double > &where, const Matrix< T > &dataI, const Matrix< T > &dataJ, const Matrix< Bool > &mask) const
Bool interp(Double &result, const Vector< Double > &where, const Matrix< Double > &data) const
Do one Double interpolation, supply Matrix/Array and mask (True is good), and pixel coordinate.
Bool interp(Bool &result, const Vector< Double > &where, const Matrix< Bool > &data) const
Do one interpolation, supply boolean Matrix (True is good), and pixel coordinate.
Interpolate2D & operator=(const Interpolate2D &other)
Assignment operator (copy semantics)
Bool(Interpolate2D::* FuncPtrDouble)(Double &result, const Vector< Double > &where, const Matrix< Double > &data, const Matrix< Bool > *&maskPtr) const
Bool interp(Double &resultI, Double &resultJ, const Vector< Double > &where, const Matrix< Double > &dataI, const Matrix< Double > &dataJ, const Matrix< Bool > &mask) const
Do two linear interpolations simultaneously.
~Interpolate2D()
destructor
Bool interp(Double &result, const Vector< Double > &where, const Matrix< Double > &data, const Matrix< Bool > &mask) const
Bool interp(DComplex &result, const Vector< Double > &where, const Matrix< DComplex > &data, const Matrix< Bool > &mask) const
Bool interpCubicBool(Bool &result, const Vector< Double > &where, const Matrix< Bool > &data) const
Bool interp(Complex &result, const Vector< Double > &where, const Matrix< Complex > &data) const
Do one Complex interpolation, supply Matrix/Array and mask (True is good), and pixel coordinate.
Bool interpLinear(T &result, const Vector< Double > &where, const Matrix< T > &data, const Matrix< Bool > *&maskPtr) const
bi-linear interpolation
Bool interpLanczosBool(Bool &result, const Vector< Double > &where, const Matrix< Bool > &data) const
Bool(Interpolate2D::* FuncPtrBool)(Bool &result, const Vector< Double > &where, const Matrix< Bool > &data) const
Bool(Interpolate2D::* FuncPtrFloat)(Float &result, const Vector< Double > &where, const Matrix< Float > &data, const Matrix< Bool > *&maskPtr) const
Typedefs for function pointers.
Interpolate2D(const Interpolate2D &other)
Copy constructor (copy semantics)
T sinc(const T x) const
Lanczos interpolation: helper functions.
Bool interpLanczos(T &result, const Vector< Double > &where, const Matrix< T > &data, const Matrix< Bool > *&maskPtr) const
Lanczos interpolation.
T L(const T x, const Int a) const
Bool interp(Float &result, const Vector< Double > &where, const Matrix< Float > &data) const
Do one Float interpolation, supply Matrix and mask (True is good), and pixel coordinate.
Bool interp(DComplex &result, const Vector< Double > &where, const Matrix< DComplex > &data) const
Do one DComplex interpolation, supply Matrix/Array and mask (True is good), and pixel coordinate.
Bool interp(Complex &result, const Vector< Double > &where, const Matrix< Complex > &data, const Matrix< Bool > &mask) const
Bool interpNearest(T &result, const Vector< Double > &where, const Matrix< T > &data, const Matrix< Bool > *&maskPtr) const
nearest neighbour interpolation
@ NEAREST
Nearest neighbour.
Bool interp(Float &result, const Vector< Double > &where, const Matrix< Float > &data, const Matrix< Bool > &mask) const
Bool interpNearestBool(Bool &result, const Vector< Double > &where, const Matrix< Bool > &data) const
Bool interpCubic(T &result, const Vector< Double > &where, const Matrix< T > &data, const Matrix< Bool > *&maskPtr) const
bi-cubic interpolation
static Interpolate2D::Method stringToMethod(const String &method)
Convert string ("nearest", "linear", "cubic", "lanczos") to interpolation method.
String: the storage and methods of handling collections of characters.
Definition String.h:223
this file contains all the compiler specific defines
Definition mainpage.dox:28
LatticeExprNode mask(const LatticeExprNode &expr)
This function returns the mask of the given expression.
float Float
Definition aipstype.h:52
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40
double Double
Definition aipstype.h:53