34 #include "boost/assign/list_of.hpp"
36 #include "lsst/pex/exceptions.h"
37 #include "lsst/log/Log.h"
42 namespace pexExcept = lsst::pex::exceptions;
51 : daf::base::Citizen(typeid(this)),
52 _kernelPtr(kernelPtr),
55 _doNormalize(doNormalize),
58 throw LSST_EXCEPT(pexExcept::InvalidParameterError,
"kernelPtr is null");
60 LOGL_DEBUG(
"TRACE5.afw.math.convolve.KernelImagesForRegion",
61 "KernelImagesForRegion(bbox(minimum=(%d, %d), extent=(%d, %d)), xy0=(%d, %d), doNormalize=%d, "
71 : daf::base::Citizen(typeid(this)),
72 _kernelPtr(kernelPtr),
75 _doNormalize(doNormalize),
78 throw LSST_EXCEPT(pexExcept::InvalidParameterError,
"kernelPtr is null");
82 _insertImage(
TOP_LEFT, topLeftImagePtr);
83 _insertImage(
TOP_RIGHT, topRightImagePtr);
84 LOGL_DEBUG(
"TRACE5.afw.math.convolve.KernelImagesForRegion",
85 "KernelImagesForRegion(bbox(minimum=(%d, %d), extent=(%d, %d)), xy0=(%d, %d), doNormalize=%d, "
92 if (_imagePtrList[location]) {
93 return _imagePtrList[location];
97 _imagePtrList[location] = imagePtr;
98 _computeImage(location);
117 std::ostringstream os;
118 os <<
"Bug: unhandled location = " << location;
119 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
129 bool hasData = regionRow.
hasData();
132 startY = regionRow.
front()->getBBox().getMaxY() + 1;
134 startY = this->_bbox.
getMinY();
138 int remHeight = 1 + this->_bbox.
getMaxY() - startY;
139 int remYDiv = regionRow.
getNY() - yInd;
140 int height = _computeNextSubregionLength(remHeight, remYDiv);
146 rgnIter != rgnEnd; ++rgnIter) {
147 (*rgnIter)->_moveUp(isFirst, height);
159 int remWidth = this->_bbox.
getWidth();
160 int remXDiv = regionRow.
getNX();
162 rgnIter != rgnEnd; ++rgnIter) {
163 int width = _computeNextSubregionLength(remWidth, remXDiv);
169 blImagePtr, brImagePtr, tlImagePtr, trImageNullPtr));
170 *rgnIter = regionPtr;
178 tlImagePtr = regionPtr->getImage(
TOP_RIGHT);
184 void KernelImagesForRegion::_computeImage(Location location)
const {
185 ImagePtr imagePtr = _imagePtrList[location];
187 std::ostringstream os;
188 os <<
"Null imagePtr at location " << location;
189 throw LSST_EXCEPT(pexExcept::NotFoundError, os.str());
197 std::vector<int> KernelImagesForRegion::_computeSubregionLengths(
int length,
int nDivisions) {
198 if ((nDivisions > length) || (nDivisions < 1)) {
199 std::ostringstream os;
200 os <<
"nDivisions = " << nDivisions <<
" not in range [1, " << length <<
" = length]";
201 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
203 std::vector<int> regionLengths;
204 int remLength = length;
205 for (
int remNDiv = nDivisions; remNDiv > 0; --remNDiv) {
206 int subLength = _computeNextSubregionLength(remLength, remNDiv);
208 std::ostringstream os;
209 os <<
"Bug! _computeSubregionLengths(length=" << length <<
", nDivisions=" << nDivisions
210 <<
") computed sublength = " << subLength <<
" < 0; remLength = " << remLength;
211 throw LSST_EXCEPT(pexExcept::RuntimeError, os.str());
213 regionLengths.push_back(subLength);
214 remLength -= subLength;
216 return regionLengths;
219 void KernelImagesForRegion::_moveUp(
bool isFirst,
int newHeight) {
229 _computeImage(TOP_RIGHT);
231 _computeImage(TOP_LEFT);
235 int const KernelImagesForRegion::_MinInterpolationSize = 10;
238 : _nx(nx), _ny(ny), _yInd(-1), _regionList(nx) {
239 if ((nx < 1) || (ny < 1)) {
240 std::ostringstream os;
241 os <<
"nx = " << nx <<
" and/or ny = " << ny <<
" < 1";
242 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
std::shared_ptr< Image > ImagePtr
double indexToPosition(double ind)
Convert image index to image position.
RegionList::const_iterator begin() const
Return the begin iterator for the list.
Location
locations of various points in the region
RegionList::iterator Iterator
std::shared_ptr< KernelImagesForRegion > front()
Return the first region in the list.
RegionList::const_iterator end() const
Return the end iterator for the list.
Extent< int, 2 > Extent2I
An integer coordinate rectangle.
ImagePtr getImage(Location location) const
Return the image and sum at the specified location.
geom::Box2I const & _bbox
std::shared_ptr< lsst::afw::math::Kernel const > KernelConstPtr
A row of KernelImagesForRegion.
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...
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)
Construct a KernelImagesForRegion.
Point2I const getMin() const
bool computeNextRow(RowOfKernelImagesForRegion ®ionRow) const
Compute next row of subregions.
lsst::afw::image::Image< lsst::afw::math::Kernel::Pixel > Image