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