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