31 #include "lsst/afw/table/io/Persistable.cc" 45 _kernelColFunctionPtr(),
46 _kernelRowFunctionPtr(),
59 :
Kernel(width, height, kernelColFunction.getNParameters() + kernelRowFunction.getNParameters(),
61 _kernelColFunctionPtr(kernelColFunction.
clone()),
62 _kernelRowFunctionPtr(kernelRowFunction.
clone()),
64 _localRowList(height),
75 :
Kernel(width, height, spatialFunctionList),
76 _kernelColFunctionPtr(kernelColFunction.
clone()),
77 _kernelRowFunctionPtr(kernelRowFunction.
clone()),
79 _localRowList(height),
85 spatialFunctionList.
size()) {
87 os <<
"kernelColFunction.getNParameters() + kernelRowFunction.getNParameters() = " 89 <<
" != " << spatialFunctionList.
size() <<
" = " 90 <<
"spatialFunctionList.size()";
104 *(this->_kernelRowFunctionPtr)));
106 retPtr->setCtr(this->
getCtr());
114 retPtr = std::make_shared<SeparableKernel>(width, height, *_kernelColFunctionPtr,
117 retPtr = std::make_shared<SeparableKernel>(width, height, *_kernelColFunctionPtr,
118 *_kernelRowFunctionPtr);
124 bool doNormalize,
double x,
double y)
const {
125 if (static_cast<int>(colList.
size()) != this->
getWidth() ||
128 os <<
"colList.size(), rowList.size() = (" << colList.
size() <<
", " << rowList.
size() <<
") != (" 130 <<
"kernel dimensions";
137 return basicComputeVectors(colList, rowList, doNormalize);
141 return _kernelColFunctionPtr->clone();
145 return _kernelRowFunctionPtr->clone();
150 os << prefix <<
"SeparableKernel:" <<
std::endl;
152 <<
"..x (width) function: " << (_kernelColFunctionPtr ? _kernelColFunctionPtr->toString() :
"None")
155 <<
"..y (rows) function: " << (_kernelRowFunctionPtr ? _kernelRowFunctionPtr->toString() :
"None")
173 double imSum = basicComputeVectors(_localColList, _localRowList, doNormalize);
178 ++colIter, ++imPtr) {
179 *imPtr = (*colIter) * _localRowList[
y];
187 unsigned int const nColParams = _kernelColFunctionPtr->getNParameters();
188 if (ind < nColParams) {
189 _kernelColFunctionPtr->setParameter(ind, value);
191 _kernelRowFunctionPtr->setParameter(ind - nColParams, value);
200 bool doNormalize)
const {
202 if (_kernelColCache.
empty()) {
203 for (
unsigned int i = 0; i != colList.
size(); ++i) {
204 double colFuncValue = (*_kernelColFunctionPtr)(_kernelX[i]);
205 colList[i] = colFuncValue;
206 colSum += colFuncValue;
214 for (
unsigned int i = 0; i != colList.
size(); ++i) {
215 double colFuncValue = cachedValues[i];
216 colList[i] = colFuncValue;
217 colSum += colFuncValue;
222 if (_kernelRowCache.
empty()) {
223 for (
unsigned int i = 0; i != rowList.
size(); ++i) {
224 double rowFuncValue = (*_kernelRowFunctionPtr)(_kernelY[i]);
225 rowList[i] = rowFuncValue;
226 rowSum += rowFuncValue;
234 for (
unsigned int i = 0; i != rowList.
size(); ++i) {
235 double rowFuncValue = cachedValues[i];
236 rowList[i] = rowFuncValue;
237 rowSum += rowFuncValue;
240 if (indx == cacheSize/2) {
241 if (::fabs(rowFuncValue - (*_kernelRowFunctionPtr)(_kernelX[i])) > 1e-2) {
243 << rowFuncValue <<
" " 244 << (*_kernelRowFunctionPtr)(_kernelX[i])
252 double imSum = colSum * rowSum;
254 if ((colSum == 0) || (rowSum == 0)) {
275 if (cacheSize <= 0) {
276 kernelCache->erase(kernelCache->begin(), kernelCache->end());
280 if (kernelCache[0].size() != x.
size()) {
281 kernelCache->erase(kernelCache->begin(), kernelCache->end());
284 int const old_cacheSize = kernelCache->size();
286 if (cacheSize == old_cacheSize) {
290 if (cacheSize < old_cacheSize) {
291 kernelCache->erase(kernelCache->begin() +
cacheSize, kernelCache->end());
293 kernelCache->resize(cacheSize);
294 for (
int i = old_cacheSize; i !=
cacheSize; ++i) {
295 (*kernelCache)[i].resize(x.
size());
302 func->setParameter(0, (i + 0.5) / static_cast<double>(cacheSize));
303 for (
unsigned int j = 0; j != x.
size(); ++j) {
304 (*kernelCache)[i][j] = (*func)(x[j]);
314 _computeCache(cacheSize, _kernelY, func, &_kernelColCache);
317 _computeCache(cacheSize, _kernelX, func, &_kernelRowCache);
int getHeight() const
Return the Kernel's height.
unsigned int getNParameters() const noexcept
Return the number of function parameters.
afw::table::Key< int > cacheSize
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
int getHeight() const
Return the number of rows in the image.
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
double getKernelParameter(unsigned int i) const override
Return a particular Kernel Parameter (no bounds checking).
A Function taking two arguments.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
double computeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize, double x=0.0, double y=0.0) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) ...
A base class for image defects.
Reports when the result of an arithmetic operation is too large for the destination type...
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
A Function taking one argument.
SeparableKernel()
Construct an empty spatially invariant SeparableKernel of size 0x0.
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
int getCacheSize() const override
Get the current cache size (0 if none)
void computeCache(int const cacheSize) override
Compute a cache of Kernel values, if desired.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
int getWidth() const
Return the Kernel's width.
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
T back_inserter(T... args)
std::vector< SpatialFunctionPtr > _spatialFunctionList
Reports invalid arguments.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
Kernels are used for convolution with MaskedImages and (eventually) Images.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.