casacore
Loading...
Searching...
No Matches
LatticeConvolver.h
Go to the documentation of this file.
1// # Convolver.h: this defines Convolver a class for doing convolution
2// # Copyright (C) 1996,1997,1998,1999,2000,2001,2002,2003
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 LATTICES_LATTICECONVOLVER_H
27#define LATTICES_LATTICECONVOLVER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/scimath/Mathematics/NumericTraits.h>
32#include <casacore/lattices/Lattices/TempLattice.h>
33#include <casacore/casa/Arrays/IPosition.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// # Forward Declarations
38// template <class T> class LatticeConvolver;
39class IPosition;
40
41// <summary>Lists the different types of Convolutions that can be done</summary>
42// <synopsis>This enumerator is brought out as a separate class because g++
43// currently cannot handle enumerators in a templated class. When it can this
44// class will go away and this enumerator moved into the Convolver
45// class</synopsis>
46class ConvEnums {
47 public:
48 enum ConvType {
49 // Linear convolution
50 LINEAR,
51 // Circular Convolution
53 // # Assume the point spread function is symmetric
54 // #REALSYMMETRIC
55 };
56};
57
58// <summary>A class for doing multi-dimensional convolution</summary>
59
60// <use visibility=export>
61
62// <reviewed reviewer="" date="yyyy/mm/dd" tests="tLatticeConvolver">
63// </reviewed>
64
65// <prerequisite>
66// <li> The mathematical concept of convolution
67// </prerequisite>
68//
69// <etymology>
70// The LatticeConvolver class will convolve Lattices. This class
71// complements the Convolver class which will convolve Arrays.
72// </etymology>
73//
74// <synopsis>
75// This class performs linear or circular convolution on Lattices. See the
76// <linkto class="Convolver">Convolver</linkto> class description of the
77// difference between linear and circular convolution.
78
79// This class does convolutions by multiplying the Fourier transforms of the
80// supplied Lattices and returning the inverse transform of the product. This
81// is the best algorithm to use when the point spread function is large. This
82// class does all the padding with zeros necessary to implement this
83// algorithm. Hence the
84
85// </synopsis>
86//
87// <example>
88// <srcblock>
89//
90// </srcblock>
91// </example>
92//
93// <motivation>
94// </motivation>
95//
96// <thrown>
97// <li> AipsError: if psf and model have a differing numbers of dimensions
98// </thrown>
99//
100// <todo asof="yyyy/mm/dd">
101// <li> the class should detect if the psf or image is small and do the
102// convolution directly rather than use the Fourier domain
103// <li> Allow the psf to be specified with a
104// <linkto class=Function>Function</linkto>.
105// </todo>
106
107template <class T>
109 public:
111
112 // Create a convolver that is initialised to do circular convolution with the
113 // specified point spread function. It is assumed that the supplied model
114 // will be the same shape as the point spread function.
115 LatticeConvolver(const Lattice<T>& psf, Bool doFast = False);
116
117 // Create a convolver that is initialised to do linear convolution with the
118 // specified point spread function. The size of the model you will convolve
119 // with must be specified.
120 LatticeConvolver(const Lattice<T>& psf, const IPosition& modelShape, Bool doFast = False);
121
122 // Create a convolver that is initialised to do the specified type of
123 // convolution with the specified point spread function. The size of the
124 // model you expect to convolve with must be specified.
126 Bool doFast = False);
127
128 // The copy constructor uses reference semantics
130
131 // The assignment operator also uses reference semantics
133
134 // The destructor does nothing special.
136
137 // Perform linear convolution of the model with the previously specified
138 // psf. The supplied Lattices must be the same shape.
139 void linear(Lattice<T>& result, const Lattice<T>& model);
140
141 // Perform in-place linear convolution of the model with the previously
142 // specified psf. Return the result in the same Lattice as the
143 // model.
144 void linear(Lattice<T>& modelAndResult);
145
146 // Perform circular convolution of the model with the previously
147 // specified psf. Return the answer in result.
148 void circular(Lattice<T>& result, const Lattice<T>& model);
149
150 // Perform in-place linear convolution of the model with the previously
151 // specified psf. Return the result in the same Lattice as the model.
152 void circular(Lattice<T>& modelAndResult);
153
154 // Perform convolution on the specified model using the currently initialised
155 // convolution type (linear or circular). These functions will not resize the
156 // LatticeConvolver if the supplied Lattice is the wrong shape.
157 //
158 // If the LatticeConvolver is setup for circular Convolution then the size of
159 // the supplied model must be less than or equal to the shape returned by the
160 // fftshape() function, which is usually the same as the shape of the psf.
161 //
162 // If the LatticeConvolver is setup to do linear convolution the the
163 // input and output Lattices must have the same shape as the result from the
164 // shape() member function. The convolution may be either in-place or not.
165 // <group>
166 void convolve(Lattice<T>& modelAndResult) const;
167 void convolve(Lattice<T>& result, const Lattice<T>& model) const;
168 // </group>
169
170 // Return the psf currently used by this convolver. The supplied Lattice must
171 // be the correct shape ie., the same as returned by the psfShape member
172 // function.
173 void getPsf(Lattice<T>& psf) const;
174
175 // Resize the LatticeConvolver to do convolutions of the specified type and
176 // shape. The supplied function must always have the same number of
177 // dimensions as the internal point spread function (which can be found using
178 // the shape member function). The LatticeConvolver will be set up to do
179 // circular or linear convolutions depending on the supplied type
180 void resize(const IPosition& modelShape, ConvEnums::ConvType type);
181
182 // Returns the shape of the Lattices that the convolver will convolve. This
183 // shape will always have as many dimensions as the psf that was used to
184 // initialise the LatticeConvolver. If the LatticeConvolver is setup to do
185 // circular convolutions then every axis of the returned IPosition will be
186 // zero length. If the LatticeConvolver is setup to do linear convolutions
187 // then the returned IPosition will have a positive values on each axis that
188 // indicate the expected shape of the input model.
190
191 // Returns the shape of the point spread function that the LatticeConvolver
192 // was initialised with.
194
195 // Returns the type of convolution the LatticeConvolver is currently set up
196 // to do.
198
199 // Returns the shape of the FFT's that the LatticeConvolver will do when
200 // performing the convolution. Not really useful except as a diagnostic
201 // tool. If the shape contains a lot of poorly factorisable lengths then the
202 // convolution will be slow.
204
205 // Set usage of fast convolve with lesser flips
207
208 private:
209 // # The following functions are used in various places in the code and are
210 // # documented in the .cc file. Static functions are used when the functions
211 // # do not use the object state. They ensure that implicit assumptions
212 // # about the current state and implicit side-effects are not possible
213 // # because all information must be suplied in the input arguments
214 static void pad(Lattice<T>& paddedLat, const Lattice<T>& inLat);
215 static void unpad(Lattice<T>& result, const Lattice<T>& paddedResult);
216 void makeXfr(const Lattice<T>& psf);
217 void makePsf(Lattice<T>& psf) const;
218 static IPosition calcFFTShape(const IPosition& psfShape, const IPosition& modelShape,
220
229};
230
231} // namespace casacore
232
233#ifndef CASACORE_NO_AUTO_TEMPLATES
234#include <casacore/lattices/LatticeMath/LatticeConvolver.tcc>
235#endif // # CASACORE_NO_AUTO_TEMPLATES
236#endif
@ LINEAR
Linear convolution.
@ CIRCULAR
Circular Convolution.
LatticeConvolver< T > & operator=(const LatticeConvolver< T > &other)
The assignment operator also uses reference semantics.
ConvEnums::ConvType type() const
Returns the type of convolution the LatticeConvolver is currently set up to do.
IPosition shape() const
Returns the shape of the Lattices that the convolver will convolve.
TempLattice< typename NumericTraits< T >::ConjugateType > * itsXfr
ConvEnums::ConvType itsType
LatticeConvolver(const Lattice< T > &psf, Bool doFast=False)
Create a convolver that is initialised to do circular convolution with the specified point spread fun...
void linear(Lattice< T > &modelAndResult)
Perform in-place linear convolution of the model with the previously specified psf.
void linear(Lattice< T > &result, const Lattice< T > &model)
Perform linear convolution of the model with the previously specified psf.
void makeXfr(const Lattice< T > &psf)
~LatticeConvolver()
The destructor does nothing special.
IPosition psfShape() const
Returns the shape of the point spread function that the LatticeConvolver was initialised with.
void getPsf(Lattice< T > &psf) const
Return the psf currently used by this convolver.
LatticeConvolver(const LatticeConvolver< T > &other)
The copy constructor uses reference semantics.
LatticeConvolver(const Lattice< T > &psf, const IPosition &modelShape, Bool doFast=False)
Create a convolver that is initialised to do linear convolution with the specified point spread funct...
static void unpad(Lattice< T > &result, const Lattice< T > &paddedResult)
void setFastConvolve()
Set usage of fast convolve with lesser flips.
IPosition fftShape() const
Returns the shape of the FFT's that the LatticeConvolver will do when performing the convolution.
void makePsf(Lattice< T > &psf) const
void circular(Lattice< T > &modelAndResult)
Perform in-place linear convolution of the model with the previously specified psf.
void circular(Lattice< T > &result, const Lattice< T > &model)
Perform circular convolution of the model with the previously specified psf.
void convolve(Lattice< T > &modelAndResult) const
Perform convolution on the specified model using the currently initialised convolution type (linear o...
static void pad(Lattice< T > &paddedLat, const Lattice< T > &inLat)
void resize(const IPosition &modelShape, ConvEnums::ConvType type)
Resize the LatticeConvolver to do convolutions of the specified type and shape.
LatticeConvolver(const Lattice< T > &psf, const IPosition &modelShape, ConvEnums::ConvType type, Bool doFast=False)
Create a convolver that is initialised to do the specified type of convolution with the specified poi...
void convolve(Lattice< T > &result, const Lattice< T > &model) const
static IPosition calcFFTShape(const IPosition &psfShape, const IPosition &modelShape, ConvEnums::ConvType type)
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40