LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | Static Public Member Functions | List of all members
lsst::afw::math::detail::KernelImagesForRegion Class Reference

A collection of Kernel images for special locations on a rectangular region of an image. More...

#include <Convolve.h>

Public Types

enum  Location { BOTTOM_LEFT , BOTTOM_RIGHT , TOP_LEFT , TOP_RIGHT }
 locations of various points in the region More...
 
using KernelConstPtr = std::shared_ptr< const lsst::afw::math::Kernel >
 
using Image = lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel >
 
using ImagePtr = std::shared_ptr< Image >
 
using ImageConstPtr = std::shared_ptr< const Image >
 

Public Member Functions

 KernelImagesForRegion (KernelConstPtr kernelPtr, lsst::geom::Box2I const &bbox, lsst::geom::Point2I const &xy0, bool doNormalize)
 Construct a KernelImagesForRegion. More...
 
 KernelImagesForRegion (KernelConstPtr kernelPtr, lsst::geom::Box2I const &bbox, lsst::geom::Point2I const &xy0, bool doNormalize, ImagePtr bottomLeftImagePtr, ImagePtr bottomRightImagePtr, ImagePtr topLeftImagePtr, ImagePtr topRightImagePtr)
 Construct a KernelImagesForRegion with some or all corner images. More...
 
lsst::geom::Box2I getBBox () const
 Get the bounding box for the region. More...
 
lsst::geom::Point2I getXY0 () const
 Get xy0 of the image. More...
 
bool getDoNormalize () const
 Get the doNormalize parameter. More...
 
ImagePtr getImage (Location location) const
 Return the image and sum at the specified location. More...
 
KernelConstPtr getKernel () const
 Get the kernel (as a shared pointer to const) More...
 
lsst::geom::Point2I getPixelIndex (Location location) const
 Compute pixel index of a given location, relative to the parent image (thus offset by bottom left corner of bounding box) More...
 
bool computeNextRow (RowOfKernelImagesForRegion &regionRow) const
 Compute next row of subregions. More...
 

Static Public Member Functions

static int getMinInterpolationSize ()
 Get the minInterpolationSize class constant. More...
 

Detailed Description

A collection of Kernel images for special locations on a rectangular region of an image.

See the Location enum for a list of those special locations.

Warning
The kernel images along the top and right edges are computed one row or column past the bounding box. This allows abutting KernelImagesForRegion to share corner and edge kernel images, which is useful when dividing a KernelImagesForRegion into subregions.
The bounding box for the region applies to the parent image.

This is a low-level helper class for recursive convolving with interpolation. Many of these objects may be created during a convolution, and many will share kernel images. It uses shared pointers to kernels and kernel images for increased speed and decreased memory usage (at the expense of safety). Note that null pointers are NOT acceptable for the constructors!

Also note that it uses lazy evaluation: images are computed when they are wanted.

Definition at line 172 of file Convolve.h.

Member Typedef Documentation

◆ Image

Definition at line 175 of file Convolve.h.

◆ ImageConstPtr

Definition at line 177 of file Convolve.h.

◆ ImagePtr

Definition at line 176 of file Convolve.h.

◆ KernelConstPtr

Definition at line 174 of file Convolve.h.

Member Enumeration Documentation

◆ Location

locations of various points in the region

RIGHT and TOP are one column/row beyond the region's bounding box. Thus adjacent regions share corner images.

The posiitions are: BOTTOM_LEFT, BOTTOM_RIGHT, TOP_LEFT, TOP_RIGHT

These locations always refer to the center of a pixel. Thus if the region has an odd size along an axis (so that the span to the top and right, which are one beyond, is even), the middle pixel will be 1/2 pixel off from the true center along that axis (in an unspecified direction).

Enumerator
BOTTOM_LEFT 
BOTTOM_RIGHT 
TOP_LEFT 
TOP_RIGHT 

Definition at line 192 of file Convolve.h.

Constructor & Destructor Documentation

◆ KernelImagesForRegion() [1/2]

lsst::afw::math::detail::KernelImagesForRegion::KernelImagesForRegion ( KernelConstPtr  kernelPtr,
lsst::geom::Box2I const &  bbox,
lsst::geom::Point2I const &  xy0,
bool  doNormalize 
)

Construct a KernelImagesForRegion.

Parameters
kernelPtrkernel
bboxbounding box of region of an image for which we want to compute kernel images (inclusive and relative to parent image)
xy0xy0 of image for which we want to compute kernel images
doNormalizenormalize the kernel images?
Exceptions
lsst::pex::exceptions::InvalidParameterErrorif kernelPtr is null

Definition at line 45 of file KernelImagesForRegion.cc.

47  : _kernelPtr(kernelPtr), _bbox(bbox), _xy0(xy0), _doNormalize(doNormalize), _imagePtrList(4) {
48  if (!_kernelPtr) {
49  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "kernelPtr is null");
50  }
51  LOGL_DEBUG("TRACE5.lsst.afw.math.convolve.KernelImagesForRegion",
52  "KernelImagesForRegion(bbox(minimum=(%d, %d), extent=(%d, %d)), xy0=(%d, %d), doNormalize=%d, "
53  "images...)",
54  _bbox.getMinX(), _bbox.getMinY(), _bbox.getWidth(), _bbox.getHeight(), _xy0[0], _xy0[1],
55  _doNormalize);
56 }
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
#define LOGL_DEBUG(logger, message...)
Log a debug-level message using a varargs/printf style interface.
Definition: Log.h:515
int getMinY() const noexcept
Definition: Box.h:158
int getHeight() const noexcept
Definition: Box.h:188
int getMinX() const noexcept
Definition: Box.h:157
int getWidth() const noexcept
Definition: Box.h:187
Reports invalid arguments.
Definition: Runtime.h:66

◆ KernelImagesForRegion() [2/2]

lsst::afw::math::detail::KernelImagesForRegion::KernelImagesForRegion ( KernelConstPtr  kernelPtr,
lsst::geom::Box2I const &  bbox,
lsst::geom::Point2I const &  xy0,
bool  doNormalize,
ImagePtr  bottomLeftImagePtr,
ImagePtr  bottomRightImagePtr,
ImagePtr  topLeftImagePtr,
ImagePtr  topRightImagePtr 
)

Construct a KernelImagesForRegion with some or all corner images.

Null corner image pointers are ignored.

Parameters
kernelPtrkernel
bboxbounding box of region of an image for which we want to compute kernel images (inclusive and relative to parent image)
xy0xy0 of image
doNormalizenormalize the kernel images?
bottomLeftImagePtrkernel image and sum at bottom left of region
bottomRightImagePtrkernel image and sum at bottom right of region
topLeftImagePtrkernel image and sum at top left of region
topRightImagePtrkernel image and sum at top right of region
Exceptions
lsst::pex::exceptions::InvalidParameterErrorif kernelPtr is null
lsst::pex::exceptions::InvalidParameterErrorif an image has the wrong dimensions
Warning
: if any images are incorrect you will get a mess.

Definition at line 58 of file KernelImagesForRegion.cc.

62  : _kernelPtr(kernelPtr), _bbox(bbox), _xy0(xy0), _doNormalize(doNormalize), _imagePtrList(4) {
63  if (!_kernelPtr) {
64  throw LSST_EXCEPT(pexExcept::InvalidParameterError, "kernelPtr is null");
65  }
66  _insertImage(BOTTOM_LEFT, bottomLeftImagePtr);
67  _insertImage(BOTTOM_RIGHT, bottomRightImagePtr);
68  _insertImage(TOP_LEFT, topLeftImagePtr);
69  _insertImage(TOP_RIGHT, topRightImagePtr);
70  LOGL_DEBUG("TRACE5.lsst.afw.math.convolve.KernelImagesForRegion",
71  "KernelImagesForRegion(bbox(minimum=(%d, %d), extent=(%d, %d)), xy0=(%d, %d), doNormalize=%d, "
72  "images...)",
73  _bbox.getMinX(), _bbox.getMinY(), _bbox.getWidth(), _bbox.getHeight(), _xy0[0], _xy0[1],
74  _doNormalize);
75 }

Member Function Documentation

◆ computeNextRow()

bool lsst::afw::math::detail::KernelImagesForRegion::computeNextRow ( RowOfKernelImagesForRegion regionRow) const

Compute next row of subregions.

For the first row call with a new RowOfKernelImagesForRegion (with the desired number of columns and rows). Every subequent call updates the data in the RowOfKernelImagesForRegion.

Parameters
[in,out]regionRowRowOfKernelImagesForRegion object
Returns
true if a new row was computed, false if supplied RowOfKernelImagesForRegion is for the last row.

Definition at line 110 of file KernelImagesForRegion.cc.

110  {
111  if (regionRow.isLastRow()) {
112  return false;
113  }
114 
115  bool hasData = regionRow.hasData();
116  int startY;
117  if (hasData) {
118  startY = regionRow.front()->getBBox().getMaxY() + 1;
119  } else {
120  startY = this->_bbox.getMinY();
121  }
122 
123  int yInd = regionRow.incrYInd();
124  int remHeight = 1 + this->_bbox.getMaxY() - startY;
125  int remYDiv = regionRow.getNY() - yInd;
126  int height = _computeNextSubregionLength(remHeight, remYDiv);
127 
128  if (hasData) {
129  // Move each region up one segment
130  bool isFirst = true;
131  for (auto & rgnIter : regionRow) {
132  rgnIter->_moveUp(isFirst, height);
133  isFirst = false;
134  }
135 
136  } else {
137  ImagePtr blImagePtr = getImage(BOTTOM_LEFT);
138  ImagePtr brImagePtr;
139  ImagePtr tlImagePtr;
140  ImagePtr const trImageNullPtr;
141 
142  lsst::geom::Point2I blCorner = lsst::geom::Point2I(this->_bbox.getMinX(), startY);
143 
144  int remWidth = this->_bbox.getWidth();
145  int remXDiv = regionRow.getNX();
146  for (auto & rgnIter : regionRow) {
147  int width = _computeNextSubregionLength(remWidth, remXDiv);
148  --remXDiv;
149  remWidth -= width;
150 
152  _kernelPtr, lsst::geom::Box2I(blCorner, lsst::geom::Extent2I(width, height)), _xy0,
153  _doNormalize, blImagePtr, brImagePtr, tlImagePtr, trImageNullPtr));
154  rgnIter = regionPtr;
155 
156  if (!tlImagePtr) {
157  regionPtr->getImage(TOP_LEFT);
158  }
159 
160  blCorner += lsst::geom::Extent2I(width, 0);
161  blImagePtr = regionPtr->getImage(BOTTOM_RIGHT);
162  tlImagePtr = regionPtr->getImage(TOP_RIGHT);
163  }
164  }
165  return true;
166 }
KernelImagesForRegion(KernelConstPtr kernelPtr, lsst::geom::Box2I const &bbox, lsst::geom::Point2I const &xy0, bool doNormalize)
Construct a KernelImagesForRegion.
ImagePtr getImage(Location location) const
Return the image and sum at the specified location.
An integer coordinate rectangle.
Definition: Box.h:55
int getMaxY() const noexcept
Definition: Box.h:162
Extent< int, 2 > Extent2I
Definition: Extent.h:397
Point< int, 2 > Point2I
Definition: Point.h:321

◆ getBBox()

lsst::geom::Box2I lsst::afw::math::detail::KernelImagesForRegion::getBBox ( ) const
inline

Get the bounding box for the region.

Definition at line 234 of file Convolve.h.

234 { return _bbox; };

◆ getDoNormalize()

bool lsst::afw::math::detail::KernelImagesForRegion::getDoNormalize ( ) const
inline

Get the doNormalize parameter.

Definition at line 242 of file Convolve.h.

242 { return _doNormalize; };

◆ getImage()

KernelImagesForRegion::ImagePtr lsst::afw::math::detail::KernelImagesForRegion::getImage ( Location  location) const

Return the image and sum at the specified location.

If the image has not yet been computed, it is computed at this time.

Parameters
locationlocation of image

Definition at line 77 of file KernelImagesForRegion.cc.

77  {
78  if (_imagePtrList[location]) {
79  return _imagePtrList[location];
80  }
81 
82  ImagePtr imagePtr(new Image(_kernelPtr->getDimensions()));
83  _imagePtrList[location] = imagePtr;
84  _computeImage(location);
85  return imagePtr;
86 }
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
Definition: Kernel.h:212
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image
Definition: Convolve.h:175

◆ getKernel()

KernelConstPtr lsst::afw::math::detail::KernelImagesForRegion::getKernel ( ) const
inline

Get the kernel (as a shared pointer to const)

Definition at line 254 of file Convolve.h.

254 { return _kernelPtr; };

◆ getMinInterpolationSize()

static int lsst::afw::math::detail::KernelImagesForRegion::getMinInterpolationSize ( )
inlinestatic

Get the minInterpolationSize class constant.

Definition at line 278 of file Convolve.h.

278 { return _MinInterpolationSize; };

◆ getPixelIndex()

lsst::geom::Point2I lsst::afw::math::detail::KernelImagesForRegion::getPixelIndex ( Location  location) const

Compute pixel index of a given location, relative to the parent image (thus offset by bottom left corner of bounding box)

Parameters
locationlocation for which to return pixel index

Definition at line 88 of file KernelImagesForRegion.cc.

88  {
89  switch (location) {
90  case BOTTOM_LEFT:
91  return _bbox.getMin();
92  break; // paranoia
93  case BOTTOM_RIGHT:
94  return lsst::geom::Point2I(_bbox.getMaxX() + 1, _bbox.getMinY());
95  break; // paranoia
96  case TOP_LEFT:
97  return lsst::geom::Point2I(_bbox.getMinX(), _bbox.getMaxY() + 1);
98  break; // paranoia
99  case TOP_RIGHT:
100  return lsst::geom::Point2I(_bbox.getMaxX() + 1, _bbox.getMaxY() + 1);
101  break; // paranoia
102  default: {
104  os << "Bug: unhandled location = " << location;
106  }
107  }
108 }
std::ostream * os
Definition: Schema.cc:557
Point2I const getMin() const noexcept
Definition: Box.h:156
int getMaxX() const noexcept
Definition: Box.h:161

◆ getXY0()

lsst::geom::Point2I lsst::afw::math::detail::KernelImagesForRegion::getXY0 ( ) const
inline

Get xy0 of the image.

Definition at line 238 of file Convolve.h.

238 { return _xy0; };

The documentation for this class was generated from the following files: