LSSTApplications  11.0-13-gbb96280,12.1.rc1,12.1.rc1+1,12.1.rc1+2,12.1.rc1+5,12.1.rc1+8,12.1.rc1-1-g06d7636+1,12.1.rc1-1-g253890b+5,12.1.rc1-1-g3d31b68+7,12.1.rc1-1-g3db6b75+1,12.1.rc1-1-g5c1385a+3,12.1.rc1-1-g83b2247,12.1.rc1-1-g90cb4cf+6,12.1.rc1-1-g91da24b+3,12.1.rc1-2-g3521f8a,12.1.rc1-2-g39433dd+4,12.1.rc1-2-g486411b+2,12.1.rc1-2-g4c2be76,12.1.rc1-2-gc9c0491,12.1.rc1-2-gda2cd4f+6,12.1.rc1-3-g3391c73+2,12.1.rc1-3-g8c1bd6c+1,12.1.rc1-3-gcf4b6cb+2,12.1.rc1-4-g057223e+1,12.1.rc1-4-g19ed13b+2,12.1.rc1-4-g30492a7
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"
46 
47 #define IS_INSTANCE(A, B) (dynamic_cast<B const*>(&(A)) != NULL)
48 
49 namespace lsst {
50 namespace afw {
51 namespace math {
52 
53 namespace detail {
54  template <typename OutImageT, typename InImageT>
55  void basicConvolve(
56  OutImageT& convolvedImage,
57  InImageT const& inImage,
58  lsst::afw::math::Kernel const& kernel,
59  lsst::afw::math::ConvolutionControl const& convolutionControl);
60 
61  template <typename OutImageT, typename InImageT>
62  void basicConvolve(
63  OutImageT& convolvedImage,
64  InImageT const& inImage,
67 
68  template <typename OutImageT, typename InImageT>
69  void basicConvolve(
70  OutImageT& convolvedImage,
71  InImageT const& inImage,
73  lsst::afw::math::ConvolutionControl const& convolutionControl);
74 
75  template <typename OutImageT, typename InImageT>
76  void basicConvolve(
77  OutImageT& convolvedImage,
78  InImageT const& inImage,
80  lsst::afw::math::ConvolutionControl const& convolutionControl);
81 
82  template <typename OutImageT, typename InImageT>
84  OutImageT &convolvedImage,
85  InImageT const& inImage,
86  lsst::afw::math::Kernel const& kernel,
87  lsst::afw::math::ConvolutionControl const& convolutionControl);
88 
89  // I would prefer this to be nested in KernelImagesForRegion but SWIG doesn't support that
90  class RowOfKernelImagesForRegion;
91 
113  {
114  public:
116  typedef lsst::afw::image::Image<lsst::afw::math::Kernel::Pixel> Image;
117  typedef PTR(Image) ImagePtr;
118  typedef CONST_PTR(Image) ImageConstPtr;
121 
135  enum Location {
137  };
138 
140  KernelConstPtr kernelPtr,
141  lsst::afw::geom::Box2I const &bbox,
142  lsst::afw::geom::Point2I const &xy0,
143  bool doNormalize);
145  KernelConstPtr kernelPtr,
146  lsst::afw::geom::Box2I const &bbox,
147  lsst::afw::geom::Point2I const &xy0,
148  bool doNormalize,
149  ImagePtr bottomLeftImagePtr,
150  ImagePtr bottomRightImagePtr,
151  ImagePtr topLeftImagePtr,
152  ImagePtr topRightImagePtr);
153 
157  lsst::afw::geom::Box2I getBBox() const { return _bbox; };
161  lsst::afw::geom::Point2I getXY0() const { return _xy0; };
165  bool getDoNormalize() const { return _doNormalize; };
166  ImagePtr getImage(Location location) const;
170  KernelConstPtr getKernel() const { return _kernelPtr; };
172  bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const;
173 
178  private:
179  typedef std::vector<Location> LocationList;
180 
181  void _computeImage(Location location) const;
182  inline void _insertImage(Location location, ImagePtr imagePtr) const;
183  void _moveUp(bool isFirst, int newHeight);
184 
185  // static helper functions
186  static inline int _computeNextSubregionLength(int length, int nDivisions);
187  static std::vector<int> _computeSubregionLengths(int length, int nDivisions);
188 
189  // member variables
194  mutable std::vector<ImagePtr> _imagePtrList;
195 
196  static int const _MinInterpolationSize;
197  };
198 
205  public:
206  typedef std::vector<PTR(KernelImagesForRegion)> RegionList;
207  typedef RegionList::iterator Iterator;
208  typedef RegionList::const_iterator ConstIterator;
209 
210  RowOfKernelImagesForRegion(int nx, int ny);
214  RegionList::const_iterator begin() const { return _regionList.begin(); };
218  RegionList::const_iterator end() const { return _regionList.end(); };
222  RegionList::iterator begin() { return _regionList.begin(); };
226  RegionList::iterator end() { return _regionList.end(); };
230  PTR(KernelImagesForRegion) front() { return _regionList.front(); };
234  PTR(KernelImagesForRegion) back() { return _regionList.back(); };
235  int getNX() const { return _nx; };
236  int getNY() const { return _ny; };
237  int getYInd() const { return _yInd; };
243  CONST_PTR(KernelImagesForRegion) getRegion(int ind) const { return _regionList.at(ind); };
244  bool hasData() const { return static_cast<bool>(_regionList[0]); };
245  bool isLastRow() const { return _yInd + 1 >= _ny; };
246  int incrYInd() { return ++_yInd; };
247 
248  private:
249  int _nx;
250  int _ny;
251  int _yInd;
253  };
254 
255  template <typename OutImageT, typename InImageT>
257  OutImageT &outImage,
258  InImageT const &inImage,
259  lsst::afw::math::Kernel const &kernel,
260  ConvolutionControl const &convolutionControl);
261 
266  public:
269  leftImage(dimensions),
270  rightImage(dimensions),
271  leftDeltaImage(dimensions),
272  rightDeltaImage(dimensions),
273  deltaImage(dimensions),
274  kernelImage(dimensions)
275  { }
282  };
283 
284  template <typename OutImageT, typename InImageT>
286  OutImageT &outImage,
287  InImageT const &inImage,
288  KernelImagesForRegion const &region,
290 }}}} // lsst::afw::math::detail
291 
292 /*
293  * Define inline functions
294  */
295 
304  int length,
305  int nDivisions)
306 {
307  return static_cast<int>(std::floor(0.5 +
308  (static_cast<double>(length) / static_cast<double>(nDivisions))));
309 }
310 
318  Location location,
319  ImagePtr imagePtr)
320 const {
321  if (imagePtr) {
322  if (_kernelPtr->getDimensions() != imagePtr->getDimensions()) {
323  std::ostringstream os;
324  os << "image dimensions = ( "
325  << imagePtr->getWidth() << ", " << imagePtr->getHeight()
326  << ") != (" << _kernelPtr->getWidth() << ", " << _kernelPtr->getHeight()
327  << ") = kernel dimensions";
328  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
329  }
330  _imagePtrList[location] = imagePtr;
331  }
332 }
333 
334 #endif // !defined(LSST_AFW_MATH_DETAIL_CONVOLVE_H)
boost::shared_ptr< KernelImagesForRegion const > getRegion(int ind) const
get the specified region (range-checked)
Definition: Convolve.h:243
An include file to include the header files for lsst::afw::geom.
Declare the Kernel class and subclasses.
lsst::afw::geom::Box2I getBBox() const
Definition: Convolve.h:157
boost::shared_ptr< Image > ImagePtr
Definition: Convolve.h:117
lsst::afw::geom::Point2I getXY0() const
Definition: Convolve.h:161
RegionList::const_iterator begin() const
Return the begin iterator for the list.
Definition: Convolve.h:214
void _moveUp(bool isFirst, int newHeight)
Move the region up one segment.
additional GPU exceptions
boost::shared_ptr< lsst::afw::math::Kernel const > KernelConstPtr
Definition: Convolve.h:115
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:58
boost::shared_ptr< Image const > ImageConstPtr
Definition: Convolve.h:118
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:983
RegionList::iterator begin()
Return the begin iterator for the list.
Definition: Convolve.h:222
RegionList::const_iterator end() const
Return the end iterator for the list.
Definition: Convolve.h:218
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...
RegionList::iterator end()
Return the end iterator for the list.
Definition: Convolve.h:226
#define CONST_PTR(...)
Definition: base.h:47
An integer coordinate rectangle.
Definition: Box.h:53
boost::shared_ptr< KernelImagesForRegion > front()
Return the first region in the list.
Definition: Convolve.h:230
kernel images used by convolveRegionWithInterpolation
Definition: Convolve.h:265
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
void _insertImage(Location location, ImagePtr imagePtr) const
Definition: Convolve.h:317
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.
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image
Definition: Convolve.h:267
boost::shared_ptr< KernelImagesForRegion const > ConstPtr
Definition: Convolve.h:119
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:811
lsst::afw::geom::Point2I getPixelIndex(Location location) const
Support for 2-D images.
A row of KernelImagesForRegion.
Definition: Convolve.h:204
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.
static std::vector< int > _computeSubregionLengths(int length, int nDivisions)
Convolve and convolveAtAPoint functions for Image and Kernel.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Extent< int, N > floor(Extent< double, N > const &input)
std::vector< boost::shared_ptr< KernelImagesForRegion > > RegionList
Definition: Convolve.h:206
#define PTR(...)
Definition: base.h:41
ConvolveWithInterpolationWorkingImages(geom::Extent2I const &dimensions)
Definition: Convolve.h:268
RowOfKernelImagesForRegion(int nx, int ny)
Construct a RowOfKernelImagesForRegion.
KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::afw::geom::Box2I const &bbox, lsst::afw::geom::Point2I const &xy0, bool doNormalize)
std::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
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
Include files required for standard LSST Exception handling.
bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const
Compute next row of subregions.
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:131
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:741
boost::shared_ptr< KernelImagesForRegion > back()
Return the last region in the list.
Definition: Convolve.h:234
static int _computeNextSubregionLength(int length, int nDivisions)
Definition: Convolve.h:303