LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
Convolve.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
25 #ifndef LSST_AFW_MATH_DETAIL_CONVOLVE_H
26 #define LSST_AFW_MATH_DETAIL_CONVOLVE_H
27 
36 #include <memory>
37 #include <sstream>
38 
39 #include "lsst/pex/exceptions.h"
40 #include "lsst/afw/geom.h"
41 #include "lsst/afw/image/Image.h"
43 #include "lsst/afw/math/Kernel.h"
45 
46 #define IS_INSTANCE(A, B) (dynamic_cast<B const*>(&(A)) != NULL)
47 
48 namespace lsst {
49 namespace afw {
50 namespace math {
51 
52 namespace detail {
53  template <typename OutImageT, typename InImageT>
54  void basicConvolve(
55  OutImageT& convolvedImage,
56  InImageT const& inImage,
57  lsst::afw::math::Kernel const& kernel,
58  lsst::afw::math::ConvolutionControl const& convolutionControl);
59 
60  template <typename OutImageT, typename InImageT>
61  void basicConvolve(
62  OutImageT& convolvedImage,
63  InImageT const& inImage,
66 
67  template <typename OutImageT, typename InImageT>
68  void basicConvolve(
69  OutImageT& convolvedImage,
70  InImageT const& inImage,
72  lsst::afw::math::ConvolutionControl const& convolutionControl);
73 
74  template <typename OutImageT, typename InImageT>
75  void basicConvolve(
76  OutImageT& convolvedImage,
77  InImageT const& inImage,
79  lsst::afw::math::ConvolutionControl const& convolutionControl);
80 
81  template <typename OutImageT, typename InImageT>
83  OutImageT &convolvedImage,
84  InImageT const& inImage,
85  lsst::afw::math::Kernel const& kernel,
86  lsst::afw::math::ConvolutionControl const& convolutionControl);
87 
88  // I would prefer this to be nested in KernelImagesForRegion but SWIG doesn't support that
89  class RowOfKernelImagesForRegion;
90 
112  {
113  public:
115  typedef lsst::afw::image::Image<lsst::afw::math::Kernel::Pixel> Image;
116  typedef PTR(Image) ImagePtr;
117  typedef CONST_PTR(Image) ImageConstPtr;
120 
134  enum Location {
136  };
137 
139  KernelConstPtr kernelPtr,
140  lsst::afw::geom::Box2I const &bbox,
141  lsst::afw::geom::Point2I const &xy0,
142  bool doNormalize);
144  KernelConstPtr kernelPtr,
145  lsst::afw::geom::Box2I const &bbox,
146  lsst::afw::geom::Point2I const &xy0,
147  bool doNormalize,
148  ImagePtr bottomLeftImagePtr,
149  ImagePtr bottomRightImagePtr,
150  ImagePtr topLeftImagePtr,
151  ImagePtr topRightImagePtr);
152 
156  lsst::afw::geom::Box2I getBBox() const { return _bbox; };
160  lsst::afw::geom::Point2I getXY0() const { return _xy0; };
164  bool getDoNormalize() const { return _doNormalize; };
165  ImagePtr getImage(Location location) const;
169  KernelConstPtr getKernel() const { return _kernelPtr; };
171  bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const;
172 
177  private:
178  typedef std::vector<Location> LocationList;
179 
180  void _computeImage(Location location) const;
181  inline void _insertImage(Location location, ImagePtr imagePtr) const;
182  void _moveUp(bool isFirst, int newHeight);
183 
184  // static helper functions
185  static inline int _computeNextSubregionLength(int length, int nDivisions);
186  static std::vector<int> _computeSubregionLengths(int length, int nDivisions);
187 
188  // member variables
193  mutable std::vector<ImagePtr> _imagePtrList;
194 
195  static int const _MinInterpolationSize;
196  };
197 
204  public:
205  typedef std::vector<PTR(KernelImagesForRegion)> RegionList;
206  typedef RegionList::iterator Iterator;
207  typedef RegionList::const_iterator ConstIterator;
208 
209  RowOfKernelImagesForRegion(int nx, int ny);
213  RegionList::const_iterator begin() const { return _regionList.begin(); };
217  RegionList::const_iterator end() const { return _regionList.end(); };
221  RegionList::iterator begin() { return _regionList.begin(); };
225  RegionList::iterator end() { return _regionList.end(); };
229  PTR(KernelImagesForRegion) front() { return _regionList.front(); };
233  PTR(KernelImagesForRegion) back() { return _regionList.back(); };
234  int getNX() const { return _nx; };
235  int getNY() const { return _ny; };
236  int getYInd() const { return _yInd; };
242  CONST_PTR(KernelImagesForRegion) getRegion(int ind) const { return _regionList.at(ind); };
243  bool hasData() const { return static_cast<bool>(_regionList[0]); };
244  bool isLastRow() const { return _yInd + 1 >= _ny; };
245  int incrYInd() { return ++_yInd; };
246 
247  private:
248  int _nx;
249  int _ny;
250  int _yInd;
252  };
253 
254  template <typename OutImageT, typename InImageT>
256  OutImageT &outImage,
257  InImageT const &inImage,
258  lsst::afw::math::Kernel const &kernel,
259  ConvolutionControl const &convolutionControl);
260 
265  public:
268  leftImage(dimensions),
269  rightImage(dimensions),
270  leftDeltaImage(dimensions),
271  rightDeltaImage(dimensions),
272  deltaImage(dimensions),
273  kernelImage(dimensions)
274  { }
281  };
282 
283  template <typename OutImageT, typename InImageT>
285  OutImageT &outImage,
286  InImageT const &inImage,
287  KernelImagesForRegion const &region,
289 }}}} // lsst::afw::math::detail
290 
291 /*
292  * Define inline functions
293  */
294 
303  int length,
304  int nDivisions)
305 {
306  return static_cast<int>(std::floor(0.5 +
307  (static_cast<double>(length) / static_cast<double>(nDivisions))));
308 }
309 
317  Location location,
318  ImagePtr imagePtr)
319 const {
320  if (imagePtr) {
321  if (_kernelPtr->getDimensions() != imagePtr->getDimensions()) {
322  std::ostringstream os;
323  os << "image dimensions = ( "
324  << imagePtr->getWidth() << ", " << imagePtr->getHeight()
325  << ") != (" << _kernelPtr->getWidth() << ", " << _kernelPtr->getHeight()
326  << ") = kernel dimensions";
327  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
328  }
329  _imagePtrList[location] = imagePtr;
330  }
331 }
332 
333 #endif // !defined(LSST_AFW_MATH_DETAIL_CONVOLVE_H)
lsst::afw::geom::Point2I getPixelIndex(Location location) const
Compute pixel index of a given location, relative to the parent image (thus offset by bottom left cor...
An include file to include the header files for lsst::afw::geom.
Declare the Kernel class and subclasses.
void _insertImage(Location location, ImagePtr imagePtr) const
Insert an image in the cache.
Definition: Convolve.h:316
RowOfKernelImagesForRegion(int nx, int ny)
Construct a RowOfKernelImagesForRegion.
bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const
Compute next row of subregions.
boost::shared_ptr< lsst::afw::math::Kernel const > KernelConstPtr
Definition: Convolve.h:114
void _computeImage(Location location) const
Compute image at a particular location.
bool getDoNormalize() const
Get the doNormalize parameter.
Definition: Convolve.h:164
boost::shared_ptr< KernelImagesForRegion > front()
Return the first region in the list.
Definition: Convolve.h:229
RegionList::const_iterator begin() const
Return the begin iterator for the list.
Definition: Convolve.h:213
Include files required for standard LSST Exception handling.
static int getMinInterpolationSize()
Get the minInterpolationSize class constant.
Definition: Convolve.h:176
void convolveRegionWithInterpolation(OutImageT &outImage, InImageT const &inImage, KernelImagesForRegion const &region, ConvolveWithInterpolationWorkingImages &workingImages)
Convolve a region of an Image or MaskedImage with a spatially varying Kernel using interpolation...
Parameters to control convolution.
Definition: ConvolveImage.h:57
std::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
boost::shared_ptr< KernelImagesForRegion const > getRegion(int ind) const
get the specified region (range-checked)
Definition: Convolve.h:242
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:983
Location
locations of various points in the region
Definition: Convolve.h:134
static std::vector< int > _computeSubregionLengths(int length, int nDivisions)
Compute length of each subregion for a region divided into nDivisions pieces of approximately equal l...
void convolveWithBruteForce(OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
Convolve an Image or MaskedImage with a Kernel by computing the kernel image at every point...
boost::shared_ptr< Image const > ImageConstPtr
Definition: Convolve.h:117
An integer coordinate rectangle.
Definition: Box.h:53
kernel images used by convolveRegionWithInterpolation
Definition: Convolve.h:264
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
std::vector< boost::shared_ptr< KernelImagesForRegion > > RegionList
Definition: Convolve.h:205
RegionList::const_iterator end() const
Return the end iterator for the list.
Definition: Convolve.h:217
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image
Definition: Convolve.h:266
afw::table::PointKey< int > dimensions
Definition: GaussianPsf.cc:42
void basicConvolve(OutImageT &convolvedImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, lsst::afw::math::ConvolutionControl const &convolutionControl)
Low-level convolution function that does not set edge pixels.
KernelConstPtr getKernel() const
Get the kernel (as a shared pointer to const)
Definition: Convolve.h:169
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:811
RegionList::iterator end()
Return the end iterator for the list.
Definition: Convolve.h:225
RegionList::iterator begin()
Return the begin iterator for the list.
Definition: Convolve.h:221
Support for 2-D images.
lsst::afw::geom::Box2I getBBox() const
Get the bounding box for the region.
Definition: Convolve.h:156
A row of KernelImagesForRegion.
Definition: Convolve.h:203
void _moveUp(bool isFirst, int newHeight)
Move the region up one segment.
void convolveWithInterpolation(OutImageT &outImage, InImageT const &inImage, lsst::afw::math::Kernel const &kernel, ConvolutionControl const &convolutionControl)
Convolve an Image or MaskedImage with a spatially varying Kernel using linear interpolation.
KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::afw::geom::Box2I const &bbox, lsst::afw::geom::Point2I const &xy0, bool doNormalize)
Construct a KernelImagesForRegion.
Convolve and convolveAtAPoint functions for Image and Kernel.
boost::shared_ptr< Image > ImagePtr
Definition: Convolve.h:116
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
ImagePtr getImage(Location location) const
Return the image and sum at the specified location.
boost::shared_ptr< KernelImagesForRegion const > ConstPtr
Definition: Convolve.h:118
Extent< int, N > floor(Extent< double, N > const &input)
Return the component-wise floor (round towards more negative).
static int _computeNextSubregionLength(int length, int nDivisions)
Compute length of next subregion if the region is to be divided into pieces of approximately equal le...
Definition: Convolve.h:302
boost::shared_ptr< KernelImagesForRegion > back()
Return the last region in the list.
Definition: Convolve.h:233
#define PTR(...)
Definition: base.h:41
ConvolveWithInterpolationWorkingImages(geom::Extent2I const &dimensions)
Definition: Convolve.h:267
lsst::afw::geom::Point2I getXY0() const
Get xy0 of the image.
Definition: Convolve.h:160
Base class for all persistable classes.
Definition: Persistable.h:74
Implementation of the Class MaskedImage.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:53
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:131
A collection of Kernel images for special locations on a rectangular region of an image...
Definition: Convolve.h:109
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:741