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() ||
126 static_cast<int>(rowList.
size()) != this->getHeight()) {
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();
152 <<
"..x (width) function: " << (_kernelColFunctionPtr ? _kernelColFunctionPtr->
toString() :
"None")
155 <<
"..y (rows) function: " << (_kernelRowFunctionPtr ? _kernelRowFunctionPtr->
toString() :
"None")
173 double imSum = basicComputeVectors(_localColList, _localRowList, doNormalize);
175 for (
int y = 0;
y !=
image.getHeight(); ++
y) {
178 ++colIter, ++imPtr) {
179 *imPtr = (*colIter) * _localRowList[
y];
187 unsigned int const nColParams = _kernelColFunctionPtr->
getNParameters();
188 if (ind < nColParams) {
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;
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)) {
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();
291 kernelCache->erase(kernelCache->begin() +
cacheSize, kernelCache->end());
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);
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
T back_inserter(T... args)
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
A Function taking one argument.
std::string toString(std::string const &prefix="") const override
Return a string representation of the function.
virtual std::shared_ptr< Function1< ReturnT > > clone() const =0
Return a pointer to a deep copy of this function.
A Function taking two arguments.
std::vector< double > const & getParameters() const noexcept
Return all function parameters.
void setParameter(unsigned int ind, double newValue)
Set one function parameter without range checking.
unsigned int getNParameters() const noexcept
Return the number of function parameters.
Kernels are used for convolution with MaskedImages and (eventually) Images.
std::vector< SpatialFunctionPtr > _spatialFunctionList
int getHeight() const
Return the Kernel's height.
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
int getWidth() const
Return the Kernel's width.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
std::vector< double > getKernelParameters() const override
Return the current kernel parameters.
double getKernelParameter(unsigned int i) const override
Return a particular Kernel Parameter (no bounds checking).
int getCacheSize() const override
Get the current cache size (0 if none)
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
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)
std::shared_ptr< KernelFunction > KernelFunctionPtr
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
virtual void _setKernelXY() override
void setKernelParameter(unsigned int ind, double value) const override
Set one kernel parameter.
SeparableKernel()
Construct an empty spatially invariant SeparableKernel of size 0x0.
void computeCache(int const cacheSize) override
Compute a cache of Kernel values, if desired.
Reports invalid arguments.
Reports when the result of an arithmetic operation is too large for the destination type.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
A base class for image defects.
afw::table::Key< int > cacheSize