casacore
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: aips2-request@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 //# $Id$
27 
28 #ifndef SCIMATH_INTERPOLATE2D_H
29 #define SCIMATH_INTERPOLATE2D_H
30 
31 //# Includes
32 #include <casacore/casa/aips.h>
33 #include <casacore/casa/Arrays/ArrayFwd.h>
34 #include <casacore/casa/BasicSL/Complex.h>
35 
36 namespace casacore { //# NAMESPACE CASACORE - BEGIN
37 
38 //# Forward declarations
39 class String;
40 
41 // <summary>
42 // A two dimension interpolator for Matrices or Arrays
43 // </summary>
44 
45 // <use visibility=export>
46 
47 // <reviewed reviewer="wbrouw" date="2004/05/26" tests="" demos="">
48 // </reviewed>
49 
50 // <prerequisite>
51 // <li> <linkto class=Array>Arrays</linkto>
52 // </prerequisite>
53 //
54 // <etymology>
55 // This class is called Interpolate2D because it does 2 dimensional interpolations
56 // </etymology>
57 //
58 // <synopsis>
59 // Given a regular Array or Matrix and a vector of pixel
60 // coordinates, interpolate the values of that array/matrix onto those
61 // pixel coordinates.
62 //
63 // Absolutely no checking of the consistency of the input data
64 // is done in order to preserve maximum speed. The coordinate vector
65 // *must* have at least 2 elements (others will be ignored). If
66 // you supply data and mask, those arrays *must* be the same shape.
67 // Failure to follow these rules will result in your program
68 // crashing.
69 // </synopsis>
70 //
71 // <example>
72 // <srcblock>
73 //
74 // Matrix<Float> matt(10,10);
75 // Vector<Double> where(2);
76 // where(0) = 3.452; where(1) = 6.1;
77 // Interpolate2D myInterp(Interpolate2D::LINEAR);
78 // Float result;
79 // Bool ok = myInterp.interp(result, where, matt);
80 //
81 // </srcblock>
82 // </example>
83 //
84 // <motivation>
85 // 2-D interpolation is required in geometry transformation routines
86 // such as in ImageRegrid.
87 // </motivation>
88 //
89 //
90 // <todo asof="1998/08/02">
91 // <li> Alternative approach: instantiate with an Array, take a block of
92 // vector locations, return a block of interpolation results
93 // </todo>
94 
95 
97  public:
98 
99  enum Method {
100 
101  // Nearest neighbour
103 
104  // Bilinear
106 
107  // Bicubic
109 
110  // Lanczos
112 
113  // Constructor
115 
116  // Copy constructor (copy semantics)
118 
119  // destructor
121 
122  // Assignment operator (copy semantics)
124 
125  // Do one Float interpolation, supply Matrix and mask (True is good),
126  // and pixel coordinate. Returns False if coordinate out of range or data
127  // are masked. No shape integrity checking is done (see above).
128  // <group>
129  Bool interp (Float &result,
130  const Vector<Double> &where,
131  const Matrix<Float> &data) const;
132  Bool interp (Float &result,
133  const Vector<Double> &where,
134  const Matrix<Float> &data,
135  const Matrix<Bool> &mask) const;
136  // </group>
137 
138  // Do one Double interpolation, supply Matrix/Array and mask (True is good),
139  // and pixel coordinate. Returns False if coordinate out of range or data
140  // are masked. No shape integrity checking is done (see above).
141  // <group>
142  Bool interp (Double &result,
143  const Vector<Double> &where,
144  const Matrix<Double> &data) const;
145  Bool interp (Double &result,
146  const Vector<Double> &where,
147  const Matrix<Double> &data,
148  const Matrix<Bool> &mask) const;
149  // </group>
150 
151  // Do one Complex interpolation, supply Matrix/Array and mask (True is good),
152  // and pixel coordinate. Returns False if coordinate out of range or data
153  // are masked. No shape integrity checking is done (see above). The real
154  // and imaginary parts are treated independently (see CAS-11375).
155  // <group>
156  Bool interp (Complex &result,
157  const Vector<Double> &where,
158  const Matrix<Complex> &data) const;
159  Bool interp (Complex &result,
160  const Vector<Double> &where,
161  const Matrix<Complex> &data,
162  const Matrix<Bool> &mask) const;
163  // </group>
164 
165  // Do one DComplex interpolation, supply Matrix/Array and mask (True is good),
166  // and pixel coordinate. Returns False if coordinate out of range or data
167  // are masked. No shape integrity checking is done (see above). The real
168  // and imaginary parts are treated independently (see CAS-11375).
169  // <group>
170  Bool interp (DComplex &result,
171  const Vector<Double> &where,
172  const Matrix<DComplex> &data) const;
173  Bool interp (DComplex &result,
174  const Vector<Double> &where,
175  const Matrix<DComplex> &data,
176  const Matrix<Bool> &mask) const;
177  // </group>
178 
179  // Do two linear interpolations simultaneously. The second call is direct.
180  // The first call transfers to the second call. It is assumed that the
181  // structure (shape, steps) of the mask and data files are the same.
182  // <group>
183  Bool interp(Double &resultI, Double &resultJ,
184  const Vector<Double> &where,
185  const Matrix<Double> &dataI,
186  const Matrix<Double> &dataJ,
187  const Matrix<Bool> &mask) const;
188  template <typename T>
189  Bool interpLinear2(T &resultI, T &resultJ,
190  const Vector<Double> &where,
191  const Matrix<T> &dataI,
192  const Matrix<T> &dataJ,
193  const Matrix<Bool> &mask) const;
194  // </group>
195 
196  // Do one interpolation, supply boolean Matrix (True is good),
197  // and pixel coordinate. Returns False if coordinate
198  // out of range. The result is False if any data value in the interpolation
199  // grid are False (bad), else True. No shape integrity checking is done.
200  // <group>
201  Bool interp (Bool &result,
202  const Vector<Double> &where,
203  const Matrix<Bool> &data) const;
204  // </group>
205 
206  // Convert string ("nearest", "linear", "cubic", "lanczos") to interpolation
207  // method. The match is case insensitive.
209 
210  private:
211 
212  // Are any of the mask pixels bad ? Returns False if no mask.
214  Int j1, Int j2) const;
215 
216  // nearest neighbour interpolation
217  template <typename T>
218  Bool interpNearest(T &result, const Vector<Double> &where,
219  const Matrix<T> &data,
220  const Matrix<Bool>* &maskPtr) const;
221  Bool interpNearestBool(Bool &result, const Vector<Double> &where,
222  const Matrix<Bool> &data) const;
223 
224  // bi-linear interpolation
225  template <typename T>
226  Bool interpLinear(T &result, const Vector<Double> &where,
227  const Matrix<T> &data,
228  const Matrix<Bool>* &maskPtr) const;
229  Bool interpLinearBool(Bool &result, const Vector<Double> &where,
230  const Matrix<Bool> &data) const;
231 
232  // bi-cubic interpolation
233  template <typename T>
234  Bool interpCubic(T &result, const Vector<Double> &where,
235  const Matrix<T> &data,
236  const Matrix<Bool>* &maskPtr) const;
237  Bool interpCubicBool(Bool &result, const Vector<Double> &where,
238  const Matrix<Bool> &data) const;
239 
240  // Lanczos interpolation
241  template <typename T>
242  Bool interpLanczos(T &result, const Vector<Double> &where,
243  const Matrix<T> &data,
244  const Matrix<Bool>* &maskPtr) const;
245  Bool interpLanczosBool(Bool &result, const Vector<Double> &where,
246  const Matrix<Bool> &data) const;
247  // Lanczos interpolation: helper functions
248  template <typename T>
249  T sinc(const T x) const;
250  template <typename T>
251  T L(const T x, const Int a) const;
252 
253  // helping routine from numerical recipes
254  void bcucof (Double c[4][4], const Double y[4],
255  const Double y1[4],
256  const Double y2[4], const Double y12[4]) const;
257 
258  // Typedefs for function pointers
260  (Float &result,
261  const Vector<Double> &where,
262  const Matrix<Float> &data,
263  const Matrix<Bool>* &maskPtr) const;
265  (Double &result,
266  const Vector<Double> &where,
267  const Matrix<Double> &data,
268  const Matrix<Bool>* &maskPtr) const;
270  (Bool &result,
271  const Vector<Double> &where,
272  const Matrix<Bool> &data) const;
273  //
277 
278 };
279 
280 
281 } //# NAMESPACE CASACORE - END
282 
283 #ifndef CASACORE_NO_AUTO_TEMPLATES
284 #include <casacore/scimath/Mathematics/Interpolate2D2.tcc>
285 #endif //# CASACORE_NO_AUTO_TEMPLATES
286 #endif
287 
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.
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
Interpolate2D & operator=(const Interpolate2D &other)
Assignment operator (copy semantics)
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
FuncPtrFloat itsFuncPtrFloat
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:225
const Double c
Fundamental physical constants (SI units):
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:54
int Int
Definition: aipstype.h:50
bool Bool
Define the standard types used by Casacore.
Definition: aipstype.h:42
double Double
Definition: aipstype.h:55