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; }
283 return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
296 SpatialFunctionPtr getSpatialFunction(
unsigned int index)
const;
375 for (; spFuncIter != _spatialFunctionList.
end(); ++spFuncIter) {
376 spatialParams.
push_back((*spFuncIter)->getParameters());
378 return spatialParams;
393 if (this->isSpatiallyVarying()) {
396 const unsigned int nParams = this->getNKernelParameters();
397 if (nParams != params.
size()) {
399 (boost::format(
"Number of parameters is wrong, saw %d expected %d") % nParams %
403 for (
unsigned int ii = 0; ii < nParams; ++ii) {
404 this->setKernelParameter(ii, params[ii]);
415 this->setKernelParameter(0, params.first);
416 this->setKernelParameter(1, params.second);
435 void computeKernelParametersFromSpatialModel(
std::vector<double> &kernelParams,
double x,
double y)
const;
456 #if 0 // fails to compile with icc; is it actually used? 475 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
485 void setKernelParametersFromSpatialModel(
double x,
double y)
const;
509 unsigned int _nKernelParams;
512 virtual void _setKernelXY() {}
557 virtual Pixel
getSum()
const {
return _sum; }
574 friend class boost::serialization::access;
575 template <
class Archive>
576 void serialize(Archive &ar,
unsigned int const version) {
577 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
578 ar &make_nvp(
"img", _image);
579 ar &make_nvp(
"sum", _sum);
634 explicit AnalyticKernel(
int width,
int height, KernelFunction
const &kernelFunction,
669 double y = 0.0)
const;
676 virtual KernelFunctionPtr getKernelFunction()
const;
692 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
696 friend class boost::serialization::access;
697 template <
class Archive>
698 void serialize(Archive &ar,
unsigned int const version) {
699 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
700 ar &make_nvp(
"fn", _kernelFunctionPtr);
756 friend class boost::serialization::access;
757 template <
class Archive>
758 void serialize(Archive &ar,
unsigned int const version) {
759 boost::serialization::void_cast_register<DeltaFunctionKernel, Kernel>(
833 virtual KernelList
const &getKernelList()
const;
850 void checkKernelList(
const KernelList &kernelList)
const;
906 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
912 void _setKernelList(KernelList
const &kernelList);
914 KernelList _kernelList;
919 bool _isDeltaFunctionBasis;
921 friend class boost::serialization::access;
922 template <
class Archive>
923 void serialize(Archive &ar,
unsigned int const version) {
924 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
925 ar &make_nvp(
"klist", _kernelList);
926 ar &make_nvp(
"kimglist", _kernelImagePtrList);
927 ar &make_nvp(
"ksumlist", _kernelSumList);
928 ar &make_nvp(
"params", _kernelParams);
930 ar &make_nvp(
"deltaBasis", _isDeltaFunctionBasis);
931 }
else if (Archive::is_loading::value) {
932 _isDeltaFunctionBasis =
false;
972 explicit SeparableKernel(
int width,
int height, KernelFunction
const &kernelColFunction,
973 KernelFunction
const &kernelRowFunction,
989 explicit SeparableKernel(
int width,
int height, KernelFunction
const &kernelColFunction,
990 KernelFunction
const &kernelRowFunction,
1021 double x = 0.0,
double y = 0.0)
const;
1024 unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
1026 return _kernelColFunctionPtr->getParameter(i);
1029 return _kernelRowFunctionPtr->getParameter(i);
1037 KernelFunctionPtr getKernelColFunction()
const;
1042 KernelFunctionPtr getKernelRowFunction()
const;
1055 virtual void computeCache(
int const cacheSize);
1060 virtual int getCacheSize()
const;
1065 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
1082 bool doNormalize)
const;
1084 KernelFunctionPtr _kernelColFunctionPtr;
1085 KernelFunctionPtr _kernelRowFunctionPtr;
1096 friend class boost::serialization::access;
1097 template <
class Archive>
1098 void serialize(Archive &ar,
unsigned int const version) {
1099 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
1100 ar &make_nvp(
"colfn", _kernelColFunctionPtr);
1101 ar &make_nvp(
"rowfn", _kernelRowFunctionPtr);
1102 ar &make_nvp(
"cols", _localColList);
1103 ar &make_nvp(
"rows", _localRowList);
1104 ar &make_nvp(
"kernelX", _kernelX);
1105 ar &make_nvp(
"kernelY", _kernelY);
1108 virtual void _setKernelXY() {
1112 assert(dim[0] == static_cast<int>(_kernelX.
size()));
1113 for (
int i = 0; i != dim.getX(); ++i) {
1114 _kernelX[i] = i - ctr.getX();
1117 assert(dim[1] == static_cast<int>(_kernelY.
size()));
1118 for (
int i = 0; i != dim.getY(); ++i) {
1119 _kernelY[i] = i - ctr.getY();
1128 namespace serialization {
1130 template <
class Archive>
1132 unsigned int const file_version) {
1137 ar << make_nvp(
"width", width);
1138 ar << make_nvp(
"height", height);
1139 ar << make_nvp(
"pixX", x);
1140 ar << make_nvp(
"pixY", y);
1143 template <
class Archive>
1145 unsigned int const file_version) {
1150 ar >> make_nvp(
"width", width);
1151 ar >> make_nvp(
"height", height);
1152 ar >> make_nvp(
"pixX", x);
1153 ar >> make_nvp(
"pixY", y);
1161 #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
void setDimensions(geom::Extent2I dims)
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.
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
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.
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
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
Extent< int, 2 > Extent2I
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.
An integer coordinate rectangle.
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.
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.
generic_kernel_tag kernel_fill_factor
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel's center.
lsst::afw::geom::Point2I getPixel() const
int getWidth() const
Return the Kernel's width.
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
#define LSST_EXCEPT(type,...)
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) ...
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)
geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
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.