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
94 public:
95 enum Method {
96
97 // Nearest neighbour
99
100 // Bilinear
102
103 // Bicubic
105
106 // Lanczos
108 };
109
110 // Constructor
112
113 // Copy constructor (copy semantics)
115
116 // destructor
118
119 // Assignment operator (copy semantics)
121
122 // Do one Float interpolation, supply Matrix and mask (True is good),
123 // and pixel coordinate. Returns False if coordinate out of range or data
124 // are masked. No shape integrity checking is done (see above).
125 // <group>
126 Bool interp(Float &result, const Vector<Double> &where, const Matrix<Float> &data) const;
127 Bool interp(Float &result, const Vector<Double> &where, const Matrix<Float> &data,
128 const Matrix<Bool> &mask) const;
129 // </group>
130
131 // Do one Double interpolation, supply Matrix/Array and mask (True is good),
132 // and pixel coordinate. Returns False if coordinate out of range or data
133 // are masked. No shape integrity checking is done (see above).
134 // <group>
135 Bool interp(Double &result, const Vector<Double> &where, const Matrix<Double> &data) const;
136 Bool interp(Double &result, const Vector<Double> &where, const Matrix<Double> &data,
137 const Matrix<Bool> &mask) const;
138 // </group>
139
140 // Do one Complex interpolation, supply Matrix/Array and mask (True is good),
141 // and pixel coordinate. Returns False if coordinate out of range or data
142 // are masked. No shape integrity checking is done (see above). The real
143 // and imaginary parts are treated independently (see CAS-11375).
144 // <group>
145 Bool interp(Complex &result, const Vector<Double> &where, const Matrix<Complex> &data) const;
146 Bool interp(Complex &result, const Vector<Double> &where, const Matrix<Complex> &data,
147 const Matrix<Bool> &mask) const;
148 // </group>
149
150 // Do one DComplex interpolation, supply Matrix/Array and mask (True is good),
151 // and pixel coordinate. Returns False if coordinate out of range or data
152 // are masked. No shape integrity checking is done (see above). The real
153 // and imaginary parts are treated independently (see CAS-11375).
154 // <group>
155 Bool interp(DComplex &result, const Vector<Double> &where, const Matrix<DComplex> &data) const;
156 Bool interp(DComplex &result, const Vector<Double> &where, const Matrix<DComplex> &data,
157 const Matrix<Bool> &mask) const;
158 // </group>
159
160 // Do two linear interpolations simultaneously. The second call is direct.
161 // The first call transfers to the second call. It is assumed that the
162 // structure (shape, steps) of the mask and data files are the same.
163 // <group>
164 Bool interp(Double &resultI, Double &resultJ, const Vector<Double> &where,
165 const Matrix<Double> &dataI, const Matrix<Double> &dataJ,
166 const Matrix<Bool> &mask) const;
167 template <typename T>
168 Bool interpLinear2(T &resultI, T &resultJ, const Vector<Double> &where, const Matrix<T> &dataI,
169 const Matrix<T> &dataJ, const Matrix<Bool> &mask) const;
170 // </group>
171
172 // Do one interpolation, supply boolean Matrix (True is good),
173 // and pixel coordinate. Returns False if coordinate
174 // out of range. The result is False if any data value in the interpolation
175 // grid are False (bad), else True. No shape integrity checking is done.
176 // <group>
177 Bool interp(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const;
178 // </group>
179
180 // Convert string ("nearest", "linear", "cubic", "lanczos") to interpolation
181 // method. The match is case insensitive.
183
184 private:
185 // Are any of the mask pixels bad ? Returns False if no mask.
186 Bool anyBadMaskPixels(const Matrix<Bool> *&mask, Int i1, Int i2, Int j1, Int j2) const;
187
188 // nearest neighbour interpolation
189 template <typename T>
190 Bool interpNearest(T &result, const Vector<Double> &where, const Matrix<T> &data,
191 const Matrix<Bool> *&maskPtr) const;
192 Bool interpNearestBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const;
193
194 // bi-linear interpolation
195 template <typename T>
196 Bool interpLinear(T &result, const Vector<Double> &where, const Matrix<T> &data,
197 const Matrix<Bool> *&maskPtr) const;
198 Bool interpLinearBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const;
199
200 // bi-cubic interpolation
201 template <typename T>
202 Bool interpCubic(T &result, const Vector<Double> &where, const Matrix<T> &data,
203 const Matrix<Bool> *&maskPtr) const;
204 Bool interpCubicBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const;
205
206 // Lanczos interpolation
207 template <typename T>
208 Bool interpLanczos(T &result, const Vector<Double> &where, const Matrix<T> &data,
209 const Matrix<Bool> *&maskPtr) const;
210 Bool interpLanczosBool(Bool &result, const Vector<Double> &where, const Matrix<Bool> &data) const;
211 // Lanczos interpolation: helper functions
212 template <typename T>
213 T sinc(const T x) const;
214 template <typename T>
215 T L(const T x, const Int a) const;
216
217 // helping routine from numerical recipes
218 void bcucof(Double c[4][4], const Double y[4], const Double y1[4], const Double y2[4],
219 const Double y12[4]) const;
220
221 // Typedefs for function pointers
222 typedef Bool (Interpolate2D::*FuncPtrFloat)(Float &result, const Vector<Double> &where,
223 const Matrix<Float> &data,
224 const Matrix<Bool> *&maskPtr) const;
225 typedef Bool (Interpolate2D::*FuncPtrDouble)(Double &result, const Vector<Double> &where,
226 const Matrix<Double> &data,
227 const Matrix<Bool> *&maskPtr) const;
228 typedef Bool (Interpolate2D::*FuncPtrBool)(Bool &result, const Vector<Double> &where,
229 const Matrix<Bool> &data) const;
230 //
234};
235
236} // namespace casacore
237
238#ifndef CASACORE_NO_AUTO_TEMPLATES
239#include <casacore/scimath/Mathematics/Interpolate2D2.tcc>
240#endif // # CASACORE_NO_AUTO_TEMPLATES
241#endif
Bool anyBadMaskPixels(const Matrix< Bool > *&mask, Int i1, Int i2, Int j1, Int j2) const
Are any of the mask pixels bad ?
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:355
For temporary backward namespace compatibility, use casa as alias for casacore.
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