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 {
47public:
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> class LatticeConvolver
108{
109public:
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,
121 Bool doFast=False);
122
123 // Create a convolver that is initialised to do the specified type of
124 // convolution with the specified point spread function. The size of the
125 // model you expect to convolve with must be specified.
126 LatticeConvolver(const Lattice<T> & psf, const IPosition & modelShape,
128
129 // The copy constructor uses reference semantics
131
132 // The assignment operator also uses reference semantics
134
135 // The destructor does nothing special.
137
138 // Perform linear convolution of the model with the previously specified
139 // psf. The supplied Lattices must be the same shape.
140 void linear(Lattice<T> & result, const Lattice<T> & model);
141
142 // Perform in-place linear convolution of the model with the previously
143 // specified psf. Return the result in the same Lattice as the
144 // model.
145 void linear(Lattice<T> & modelAndResult);
146
147 // Perform circular convolution of the model with the previously
148 // specified psf. Return the answer in result.
149 void circular(Lattice<T> & result, const Lattice<T> & model);
150
151 // Perform in-place linear convolution of the model with the previously
152 // specified psf. Return the result in the same Lattice as the model.
153 void circular(Lattice<T> & modelAndResult);
154
155 // Perform convolution on the specified model using the currently initialised
156 // convolution type (linear or circular). These functions will not resize the
157 // LatticeConvolver if the supplied Lattice is the wrong shape.
158 //
159 // If the LatticeConvolver is setup for circular Convolution then the size of
160 // the supplied model must be less than or equal to the shape returned by the
161 // fftshape() function, which is usually the same as the shape of the psf.
162 //
163 // If the LatticeConvolver is setup to do linear convolution the the
164 // input and output Lattices must have the same shape as the result from the
165 // shape() member function. The convolution may be either in-place or not.
166 // <group>
167 void convolve(Lattice<T> & modelAndResult) const;
168 void convolve(Lattice<T> & result, const Lattice<T> & model) const;
169 // </group>
170
171 // Return the psf currently used by this convolver. The supplied Lattice must
172 // be the correct shape ie., the same as returned by the psfShape member
173 // function.
174 void getPsf(Lattice<T> & psf) const;
175
176 // Resize the LatticeConvolver to do convolutions of the specified type and
177 // shape. The supplied function must always have the same number of
178 // dimensions as the internal point spread function (which can be found using
179 // the shape member function). The LatticeConvolver will be set up to do
180 // circular or linear convolutions depending on the supplied type
181 void resize(const IPosition & modelShape, ConvEnums::ConvType type);
182
183 // Returns the shape of the Lattices that the convolver will convolve. This
184 // shape will always have as many dimensions as the psf that was used to
185 // initialise the LatticeConvolver. If the LatticeConvolver is setup to do
186 // circular convolutions then every axis of the returned IPosition will be
187 // zero length. If the LatticeConvolver is setup to do linear convolutions
188 // then the returned IPosition will have a positive values on each axis that
189 // indicate the expected shape of the input model.
191
192 // Returns the shape of the point spread function that the LatticeConvolver
193 // was initialised with.
195
196 // Returns the type of convolution the LatticeConvolver is currently set up
197 // to do.
199
200 // Returns the shape of the FFT's that the LatticeConvolver will do when
201 // performing the convolution. Not really useful except as a diagnostic
202 // tool. If the shape contains a lot of poorly factorisable lengths then the
203 // convolution will be slow.
205
206 // Set usage of fast convolve with lesser flips
208
209private:
210 //# The following functions are used in various places in the code and are
211 //# documented in the .cc file. Static functions are used when the functions
212 //# do not use the object state. They ensure that implicit assumptions
213 //# about the current state and implicit side-effects are not possible
214 //# because all information must be suplied in the input arguments
215 static void pad(Lattice<T> & paddedLat, const Lattice<T> & inLat);
216 static void unpad(Lattice<T> & result, const Lattice<T> & paddedResult);
217 void makeXfr(const Lattice<T> & psf);
218 void makePsf(Lattice<T> & psf) const;
220 const IPosition & modelShape,
222
231};
232
233} //# NAMESPACE CASACORE - END
234
235#ifndef CASACORE_NO_AUTO_TEMPLATES
236#include <casacore/lattices/LatticeMath/LatticeConvolver.tcc>
237#endif //# CASACORE_NO_AUTO_TEMPLATES
238#endif
239
@ LINEAR
Linear convolution.
@ CIRCULAR
Circular Convolution.
A class for doing multi-dimensional 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)
this file contains all the compiler specific defines
Definition mainpage.dox:28
const Bool False
Definition aipstype.h:42
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40