25 #ifndef LSST_AFW_MATH_KERNEL_H 26 #define LSST_AFW_MATH_KERNEL_H 31 #include <type_traits> 35 #include "boost/mpl/or.hpp" 37 #include "boost/serialization/shared_ptr.hpp" 38 #include "boost/serialization/vector.hpp" 39 #include "boost/serialization/export.hpp" 54 namespace formatters {
55 class KernelFormatter;
60 using boost::serialization::make_nvp;
156 explicit Kernel(
int width,
int height,
unsigned int nKernelParams,
157 SpatialFunction
const &spatialFunction = NullSpatialFunction());
178 virtual ~
Kernel() =
default;
223 double y = 0.0)
const;
231 _width = dims.getX();
232 _height = dims.getY();
234 inline void setWidth(
int width) { _width = width; }
282 return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
295 SpatialFunctionPtr getSpatialFunction(
unsigned int index)
const;
374 for (; spFuncIter != _spatialFunctionList.
end(); ++spFuncIter) {
375 spatialParams.
push_back((*spFuncIter)->getParameters());
377 return spatialParams;
392 if (this->isSpatiallyVarying()) {
395 const unsigned int nParams = this->getNKernelParameters();
396 if (nParams != params.
size()) {
398 (boost::format(
"Number of parameters is wrong, saw %d expected %d") % nParams %
402 for (
unsigned int ii = 0; ii < nParams; ++ii) {
403 this->setKernelParameter(ii, params[ii]);
414 this->setKernelParameter(0, params.first);
415 this->setKernelParameter(1, params.second);
434 void computeKernelParametersFromSpatialModel(
std::vector<double> &kernelParams,
double x,
double y)
const;
455 #if 0 // fails to compile with icc; is it actually used? 474 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
484 void setKernelParametersFromSpatialModel(
double x,
double y)
const;
508 unsigned int _nKernelParams;
511 virtual void _setKernelXY() {}
556 virtual Pixel
getSum()
const {
return _sum; }
573 friend class boost::serialization::access;
574 template <
class Archive>
575 void serialize(Archive &ar,
unsigned int const version) {
576 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
577 ar &make_nvp(
"img", _image);
578 ar &make_nvp(
"sum", _sum);
633 explicit AnalyticKernel(
int width,
int height, KernelFunction
const &kernelFunction,
668 double y = 0.0)
const;
675 virtual KernelFunctionPtr getKernelFunction()
const;
691 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
695 friend class boost::serialization::access;
696 template <
class Archive>
698 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
699 ar &make_nvp(
"fn", _kernelFunctionPtr);
755 friend class boost::serialization::access;
756 template <
class Archive>
757 void serialize(Archive &ar,
unsigned int const version) {
758 boost::serialization::void_cast_register<DeltaFunctionKernel, Kernel>(
832 virtual KernelList
const &getKernelList()
const;
849 void checkKernelList(
const KernelList &kernelList)
const;
905 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
911 void _setKernelList(KernelList
const &kernelList);
913 KernelList _kernelList;
918 bool _isDeltaFunctionBasis;
920 friend class boost::serialization::access;
921 template <
class Archive>
922 void serialize(Archive &ar,
unsigned int const version) {
923 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
924 ar &make_nvp(
"klist", _kernelList);
925 ar &make_nvp(
"kimglist", _kernelImagePtrList);
926 ar &make_nvp(
"ksumlist", _kernelSumList);
927 ar &make_nvp(
"params", _kernelParams);
929 ar &make_nvp(
"deltaBasis", _isDeltaFunctionBasis);
930 }
else if (Archive::is_loading::value) {
931 _isDeltaFunctionBasis =
false;
971 explicit SeparableKernel(
int width,
int height, KernelFunction
const &kernelColFunction,
972 KernelFunction
const &kernelRowFunction,
988 explicit SeparableKernel(
int width,
int height, KernelFunction
const &kernelColFunction,
989 KernelFunction
const &kernelRowFunction,
1020 double x = 0.0,
double y = 0.0)
const;
1023 unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
1025 return _kernelColFunctionPtr->getParameter(i);
1028 return _kernelRowFunctionPtr->getParameter(i);
1036 KernelFunctionPtr getKernelColFunction()
const;
1041 KernelFunctionPtr getKernelRowFunction()
const;
1054 virtual void computeCache(
int const cacheSize);
1059 virtual int getCacheSize()
const;
1064 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
1081 bool doNormalize)
const;
1083 KernelFunctionPtr _kernelColFunctionPtr;
1084 KernelFunctionPtr _kernelRowFunctionPtr;
1095 friend class boost::serialization::access;
1096 template <
class Archive>
1097 void serialize(Archive &ar,
unsigned int const version) {
1098 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
1099 ar &make_nvp(
"colfn", _kernelColFunctionPtr);
1100 ar &make_nvp(
"rowfn", _kernelRowFunctionPtr);
1101 ar &make_nvp(
"cols", _localColList);
1102 ar &make_nvp(
"rows", _localRowList);
1103 ar &make_nvp(
"kernelX", _kernelX);
1104 ar &make_nvp(
"kernelY", _kernelY);
1107 virtual void _setKernelXY() {
1111 assert(dim[0] == static_cast<int>(_kernelX.
size()));
1112 for (
int i = 0; i != dim.getX(); ++i) {
1113 _kernelX[i] = i - ctr.getX();
1116 assert(dim[1] == static_cast<int>(_kernelY.
size()));
1117 for (
int i = 0; i != dim.getY(); ++i) {
1118 _kernelY[i] = i - ctr.getY();
1127 namespace serialization {
1129 template <
class Archive>
1131 unsigned int const file_version) {
1136 ar << make_nvp(
"width", width);
1137 ar << make_nvp(
"height", height);
1138 ar << make_nvp(
"pixX", x);
1139 ar << make_nvp(
"pixY", y);
1142 template <
class Archive>
1144 unsigned int const file_version) {
1149 ar >> make_nvp(
"width", width);
1150 ar >> make_nvp(
"height", height);
1151 ar >> make_nvp(
"pixX", x);
1152 ar >> make_nvp(
"pixY", y);
1160 #endif // !defined(LSST_AFW_MATH_KERNEL_H) virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
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.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
std::shared_ptr< KernelFunction > KernelFunctionPtr
virtual Pixel getSum() const
virtual void computeCache(int const)
Compute a cache of Kernel values, if desired.
An object passed to Persistable::write to allow it to persist itself.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
lsst::afw::math::Function1< Pixel > KernelFunction
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
void setKernelParameters(std::vector< double > const ¶ms)
Set the kernel parameters of a spatially invariant kernel.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
void serialize(Archive &ar, unsigned int const version)
std::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
void setHeight(int height)
bool isDeltaFunctionBasis() const
Return true if all basis kernels are instances of DeltaFunctionKernel.
lsst::afw::math::NullFunction2< double > NullSpatialFunction
lsst::afw::math::Function2< double > SpatialFunction
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
A Function taking two arguments.
int getNBasisKernels() const
Get the number of basis kernels.
A base class for objects that can be persisted via afw::table::io Archive classes.
a class used in function calls to indicate that no Function2 is being provided
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
void setCtrY(int ctrY)
Set y index of kernel's center.
KernelFunctionPtr _kernelFunctionPtr
A base class for image defects.
lsst::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
void setCtrX(int ctrX)
Set x index of kernel's center.
A kernel that is a linear combination of fixed basis kernels.
void setKernelParameters(std::pair< double, double > const ¶ms)
Set the kernel parameters of a 2-component spatially invariant kernel.
void load_construct_data(Archive &ar, lsst::afw::math::DeltaFunctionKernel *k, unsigned int const file_version)
A Function taking one argument.
lsst::geom::Point2I getCtr() const
Return index of kernel's center.
void setDimensions(lsst::geom::Extent2I dims)
void setCtr(lsst::geom::Point2I ctr)
Set index of kernel's center.
generic_kernel_tag kernel_fill_factor
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)
#define LSST_EXCEPT(type,...)
Extent< int, 2 > Extent2I
Kernel has only one non-zero pixel.
table::Key< int > kernelFunction
std::vector< std::shared_ptr< Kernel > > KernelList
std::vector< SpatialFunctionPtr > _spatialFunctionList
lsst::afw::math::Function2< Pixel > KernelFunction
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
#define LSST_PERSIST_FORMATTER(formatter...)
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
lsst::geom::Point2I getPixel() const
deltafunction_kernel_tag kernel_fill_factor
A kernel described by a function.
std::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
A CRTP facade class for subclasses of Persistable.
Kernels are used for convolution with MaskedImages and (eventually) Images.
void save_construct_data(Archive &ar, lsst::afw::math::DeltaFunctionKernel const *k, unsigned int const file_version)
A kernel that has only one non-zero pixel (of value 1)
Tags carrying information about Kernels Kernel with no special properties.
A kernel created from an Image.