27 #include "boost/format.hpp" 30 #pragma warning(disable : 444) 32 #include "boost/archive/text_oarchive.hpp" 59 : daf::base::Citizen(typeid(this)),
60 _spatialFunctionList(),
68 : daf::base::
Citizen(typeid(this)),
72 _ctrX((width - 1) / 2),
73 _ctrY((height - 1) / 2),
74 _nKernelParams(nKernelParams) {
75 if ((width < 1) || (height < 1)) {
77 os <<
"kernel height = " << height <<
" and/or width = " << width <<
" < 1";
80 if (dynamic_cast<const NullSpatialFunction *>(&spatialFunction)) {
83 if (nKernelParams == 0) {
86 for (
unsigned int ii = 0; ii < nKernelParams; ++ii) {
96 os <<
"image dimensions = ( " << image.
getWidth() <<
", " << image.
getHeight() <<
") != (" 100 image.
setXY0(-_ctrX, -_ctrY);
108 : daf::base::
Citizen(typeid(this)),
113 _nKernelParams(spatialFunctionList.size()) {
114 if ((width < 1) || (height < 1)) {
116 os <<
"kernel height = " << height <<
" and/or width = " << width <<
" < 1";
119 for (
unsigned int ii = 0; ii < spatialFunctionList.
size(); ++ii) {
131 if (params.size() != nKernelParams) {
134 (boost::format(
"params has %d entries instead of %d") % params.size() % nKernelParams).str());
137 for (
unsigned int ii = 0; ii < nKernelParams; ++ii) {
138 if (params[ii].size() != nSpatialParams) {
140 (boost::format(
"params[%d] has %d entries instead of %d") % ii %
141 params[ii].size() % nSpatialParams)
146 if (nSpatialParams > 0) {
147 for (
unsigned int ii = 0; ii < nKernelParams; ++ii) {
158 *paramIter = (*(*funcIter))(x, y);
179 spFuncCopyList.
push_back((**spFuncIter).clone());
181 return spFuncCopyList;
196 <<
") in one or both dimensions";
207 os << prefix <<
"..height, width: " << _height <<
", " << _width <<
std::endl;
208 os << prefix <<
"..ctr (X, Y): " << _ctrX <<
", " << _ctrY <<
std::endl;
209 os << prefix <<
"..nKernelParams: " << _nKernelParams <<
std::endl;
210 os << prefix <<
"..isSpatiallyVarying: " << (this->
isSpatiallyVarying() ?
"True" :
"False") << std::endl;
212 os << prefix <<
"..spatialFunctions:" <<
std::endl;
215 os << prefix <<
"...." << (*spFuncPtr)->toString() <<
std::endl;
221 #if 0 // This fails to compile with icc 224 boost::archive::text_oarchive oa(
os);
Extent2I const getDimensions() const noexcept
int getHeight() const
Return the Kernel's height.
int getCtrX() const
Return x index of kernel's center.
int getCtrY() const
Return y index of kernel's center.
int getHeight() const noexcept
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
int getHeight() const
Return the number of rows in the image.
static std::shared_ptr< T > dynamicCast(std::shared_ptr< Persistable > const &ptr)
Dynamically cast a shared_ptr.
virtual std::shared_ptr< Function2< ReturnT > > clone() const =0
Return a pointer to a deep copy of this function.
void setXY0(lsst::geom::Point2I const origin)
Set the ImageBase's origin.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
A Function taking two arguments.
Point2I const getMin() const noexcept
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
A base class for image defects.
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
lsst::geom::Box2I growBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for pixels one wishes to compute by convolving an image with this kernel...
deltafunction_kernel_tag deltafunction_kernel_tag_
Used as default value in argument lists.
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
int getWidth() const noexcept
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model) ...
double computeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize, double x=0.0, double y=0.0) const
Compute an image (pixellized representation of the kernel) in place.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
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.
lsst::geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
int getMinX() const noexcept
void setSpatialParameters(const std::vector< std::vector< double >> params)
Set the parameters of all spatial functions.
#define LSST_EXCEPT(type,...)
Extent< int, 2 > Extent2I
Kernel has only one non-zero pixel.
Citizen(const std::type_info &)
lsst::geom::Box2I shrinkBBox(lsst::geom::Box2I const &bbox) const
Given a bounding box for an image one wishes to convolve with this kernel, return the bounding box fo...
std::vector< SpatialFunctionPtr > _spatialFunctionList
int getWidth() const
Return the number of columns in the image.
Kernel()
Construct a null Kernel of size 0,0.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
generic_kernel_tag generic_kernel_tag_
Used as default value in argument lists.
lsst::geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
int getMinY() const noexcept
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Tags carrying information about Kernels Kernel with no special properties.