LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 <sstream>
37 
38 #include "boost/shared_ptr.hpp"
39 
40 #include "lsst/pex/exceptions.h"
41 #include "lsst/afw/geom.h"
42 #include "lsst/afw/image/Image.h"
44 #include "lsst/afw/math/Kernel.h"
47 
48 #define IS_INSTANCE(A, B) (dynamic_cast<B const*>(&(A)) != NULL)
49 
50 namespace lsst {
51 namespace afw {
52 namespace math {
53 
54 namespace detail {
55  template <typename OutImageT, typename InImageT>
56  void basicConvolve(
57  OutImageT& convolvedImage,
58  InImageT const& inImage,
59  lsst::afw::math::Kernel const& kernel,
60  lsst::afw::math::ConvolutionControl const& convolutionControl);
61 
62  template <typename OutImageT, typename InImageT>
63  void basicConvolve(
64  OutImageT& convolvedImage,
65  InImageT const& inImage,
68 
69  template <typename OutImageT, typename InImageT>
70  void basicConvolve(
71  OutImageT& convolvedImage,
72  InImageT const& inImage,
74  lsst::afw::math::ConvolutionControl const& convolutionControl);
75 
76  template <typename OutImageT, typename InImageT>
77  void basicConvolve(
78  OutImageT& convolvedImage,
79  InImageT const& inImage,
81  lsst::afw::math::ConvolutionControl const& convolutionControl);
82 
83  template <typename OutImageT, typename InImageT>
85  OutImageT &convolvedImage,
86  InImageT const& inImage,
87  lsst::afw::math::Kernel const& kernel,
88  lsst::afw::math::ConvolutionControl const& convolutionControl);
89 
90  // I would prefer this to be nested in KernelImagesForRegion but SWIG doesn't support that
91  class RowOfKernelImagesForRegion;
92 
114  {
115  public:
117  typedef lsst::afw::image::Image<lsst::afw::math::Kernel::Pixel> Image;
118  typedef PTR(Image) ImagePtr;
119  typedef CONST_PTR(Image) ImageConstPtr;
122 
136  enum Location {
138  };
139 
141  KernelConstPtr kernelPtr,
142  lsst::afw::geom::Box2I const &bbox,
143  lsst::afw::geom::Point2I const &xy0,
144  bool doNormalize);
146  KernelConstPtr kernelPtr,
147  lsst::afw::geom::Box2I const &bbox,
148  lsst::afw::geom::Point2I const &xy0,
149  bool doNormalize,
150  ImagePtr bottomLeftImagePtr,
151  ImagePtr bottomRightImagePtr,
152  ImagePtr topLeftImagePtr,
153  ImagePtr topRightImagePtr);
154 
158  lsst::afw::geom::Box2I getBBox() const { return _bbox; };
162  lsst::afw::geom::Point2I getXY0() const { return _xy0; };
166  bool getDoNormalize() const { return _doNormalize; };
167  ImagePtr getImage(Location location) const;
171  KernelConstPtr getKernel() const { return _kernelPtr; };
173  bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const;
174 
179  private:
180  typedef std::vector<Location> LocationList;
181 
182  void _computeImage(Location location) const;
183  inline void _insertImage(Location location, ImagePtr imagePtr) const;
184  void _moveUp(bool isFirst, int newHeight);
185 
186  // static helper functions
187  static inline int _computeNextSubregionLength(int length, int nDivisions);
188  static std::vector<int> _computeSubregionLengths(int length, int nDivisions);
189 
190  // member variables
195  mutable std::vector<ImagePtr> _imagePtrList;
196 
197  static int const _MinInterpolationSize;
198  };
199 
206  public:
207  typedef std::vector<PTR(KernelImagesForRegion)> RegionList;
208  typedef RegionList::iterator Iterator;
209  typedef RegionList::const_iterator ConstIterator;
210 
211  RowOfKernelImagesForRegion(int nx, int ny);
215  RegionList::const_iterator begin() const { return _regionList.begin(); };
219  RegionList::const_iterator end() const { return _regionList.end(); };
223  RegionList::iterator begin() { return _regionList.begin(); };
227  RegionList::iterator end() { return _regionList.end(); };
231  PTR(KernelImagesForRegion) front() { return _regionList.front(); };
235  PTR(KernelImagesForRegion) back() { return _regionList.back(); };
236  int getNX() const { return _nx; };
237  int getNY() const { return _ny; };
238  int getYInd() const { return _yInd; };
244  CONST_PTR(KernelImagesForRegion) getRegion(int ind) const { return _regionList.at(ind); };
245  bool hasData() const { return static_cast<bool>(_regionList[0]); };
246  bool isLastRow() const { return _yInd + 1 >= _ny; };
247  int incrYInd() { return ++_yInd; };
248 
249  private:
250  int _nx;
251  int _ny;
252  int _yInd;
254  };
255 
256  template <typename OutImageT, typename InImageT>
258  OutImageT &outImage,
259  InImageT const &inImage,
260  lsst::afw::math::Kernel const &kernel,
261  ConvolutionControl const &convolutionControl);
262 
267  public:
270  leftImage(dimensions),
271  rightImage(dimensions),
272  leftDeltaImage(dimensions),
273  rightDeltaImage(dimensions),
274  deltaImage(dimensions),
275  kernelImage(dimensions)
276  { }
283  };
284 
285  template <typename OutImageT, typename InImageT>
287  OutImageT &outImage,
288  InImageT const &inImage,
289  KernelImagesForRegion const &region,
291 }}}} // lsst::afw::math::detail
292 
293 /*
294  * Define inline functions
295  */
296 
305  int length,
306  int nDivisions)
307 {
308  return static_cast<int>(std::floor(0.5 +
309  (static_cast<double>(length) / static_cast<double>(nDivisions))));
310 }
311 
319  Location location,
320  ImagePtr imagePtr)
321 const {
322  if (imagePtr) {
323  if (_kernelPtr->getDimensions() != imagePtr->getDimensions()) {
324  std::ostringstream os;
325  os << "image dimensions = ( "
326  << imagePtr->getWidth() << ", " << imagePtr->getHeight()
327  << ") != (" << _kernelPtr->getWidth() << ", " << _kernelPtr->getHeight()
328  << ") = kernel dimensions";
329  throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError, os.str());
330  }
331  _imagePtrList[location] = imagePtr;
332  }
333 }
334 
335 #endif // !defined(LSST_AFW_MATH_DETAIL_CONVOLVE_H)
std::vector< Location > LocationList
Definition: Convolve.h:178
An include file to include the header files for lsst::afw::geom.
Declare the Kernel class and subclasses.
#define PTR(...)
Definition: base.h:41
boost::shared_ptr< KernelImagesForRegion > back()
Return the last region in the list.
Definition: Convolve.h:235
boost::shared_ptr< Image > ImagePtr
Definition: Convolve.h:118
boost::shared_ptr< KernelImagesForRegion const > ConstPtr
Definition: Convolve.h:120
additional GPU exceptions
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< lsst::afw::math::Kernel const > KernelConstPtr
Definition: Convolve.h:116
#define CONST_PTR(...)
Definition: base.h:47
lsst::afw::geom::Box2I getBBox() const
Definition: Convolve.h:158
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
Definition: Kernel.h:986
ImagePtr getImage(Location location) const
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< KernelImagesForRegion > front()
Return the first region in the list.
Definition: Convolve.h:231
std::vector< ImagePtr > _imagePtrList
Definition: Convolve.h:195
An integer coordinate rectangle.
Definition: Box.h:53
kernel images used by convolveRegionWithInterpolation
Definition: Convolve.h:266
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image
Definition: Convolve.h:268
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
afw::table::PointKey< int > dimensions
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.
RegionList::const_iterator end() const
Return the end iterator for the list.
Definition: Convolve.h:219
std::vector< boost::shared_ptr< KernelImagesForRegion > > RegionList
Definition: Convolve.h:207
boost::shared_ptr< Persistable > Ptr
Definition: Persistable.h:76
lsst::afw::geom::Point2I getXY0() const
Definition: Convolve.h:162
A kernel that is a linear combination of fixed basis kernels.
Definition: Kernel.h:814
void _moveUp(bool isFirst, int newHeight)
Move the region up one segment.
Support for 2-D images.
static std::vector< int > _computeSubregionLengths(int length, int nDivisions)
A row of KernelImagesForRegion.
Definition: Convolve.h:205
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.
bool computeNextRow(RowOfKernelImagesForRegion &regionRow) const
Compute next row of subregions.
static int _computeNextSubregionLength(int length, int nDivisions)
Definition: Convolve.h:304
Convolve and convolveAtAPoint functions for Image and Kernel.
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
RegionList::const_iterator begin() const
Return the begin iterator for the list.
Definition: Convolve.h:215
Extent< int, N > floor(Extent< double, N > const &input)
lsst::afw::geom::Point2I getPixelIndex(Location location) const
boost::shared_ptr< KernelImagesForRegion const > getRegion(int ind) const
get the specified region (range-checked)
Definition: Convolve.h:244
ConvolveWithInterpolationWorkingImages(geom::Extent2I const &dimensions)
Definition: Convolve.h:269
Base class for all persistable classes.
Definition: Persistable.h:74
Implementation of the Class MaskedImage.
RegionList::const_iterator ConstIterator
Definition: Convolve.h:209
void _insertImage(Location location, ImagePtr imagePtr) const
Definition: Convolve.h:318
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
RegionList::iterator begin()
Return the begin iterator for the list.
Definition: Convolve.h:223
KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::afw::geom::Box2I const &bbox, lsst::afw::geom::Point2I const &xy0, bool doNormalize)
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
RowOfKernelImagesForRegion(int nx, int ny)
Construct a RowOfKernelImagesForRegion.
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:744
boost::shared_ptr< Image const > ImageConstPtr
Definition: Convolve.h:119
RegionList::iterator end()
Return the end iterator for the list.
Definition: Convolve.h:227
Include files required for standard LSST Exception handling.