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());
217 double y = 0.0)
const;
225 _width = dims.getX();
226 _height = dims.getY();
228 inline void setWidth(
int width) { _width = width; }
277 return this->isSpatiallyVarying() ? _spatialFunctionList[0]->getNParameters() : 0;
290 SpatialFunctionPtr getSpatialFunction(
unsigned int index)
const;
369 for (; spFuncIter != _spatialFunctionList.
end(); ++spFuncIter) {
370 spatialParams.
push_back((*spFuncIter)->getParameters());
372 return spatialParams;
387 if (this->isSpatiallyVarying()) {
390 const unsigned int nParams = this->getNKernelParameters();
391 if (nParams != params.
size()) {
393 (boost::format(
"Number of parameters is wrong, saw %d expected %d") % nParams %
397 for (
unsigned int ii = 0; ii < nParams; ++ii) {
398 this->setKernelParameter(ii, params[ii]);
409 this->setKernelParameter(0, params.first);
410 this->setKernelParameter(1, params.second);
429 void computeKernelParametersFromSpatialModel(
std::vector<double> &kernelParams,
double x,
double y)
const;
450 #if 0 // fails to compile with icc; is it actually used? 469 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
479 void setKernelParametersFromSpatialModel(
double x,
double y)
const;
503 unsigned int _nKernelParams;
509 virtual void _setKernelXY() {}
549 virtual Pixel
getSum()
const {
return _sum; }
566 friend class boost::serialization::access;
567 template <
class Archive>
568 void serialize(Archive &ar,
unsigned int const version) {
569 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
570 ar &make_nvp(
"img", _image);
571 ar &make_nvp(
"sum", _sum);
626 explicit AnalyticKernel(
int width,
int height, KernelFunction
const &kernelFunction,
656 double y = 0.0)
const;
663 virtual KernelFunctionPtr getKernelFunction()
const;
679 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
683 friend class boost::serialization::access;
684 template <
class Archive>
685 void serialize(Archive &ar,
unsigned int const version) {
686 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
687 ar &make_nvp(
"fn", _kernelFunctionPtr);
738 friend class boost::serialization::access;
739 template <
class Archive>
740 void serialize(Archive &ar,
unsigned int const version) {
741 boost::serialization::void_cast_register<DeltaFunctionKernel, Kernel>(
810 virtual KernelList
const &getKernelList()
const;
827 void checkKernelList(
const KernelList &kernelList)
const;
883 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
889 void _setKernelList(KernelList
const &kernelList);
891 KernelList _kernelList;
896 bool _isDeltaFunctionBasis;
898 friend class boost::serialization::access;
899 template <
class Archive>
900 void serialize(Archive &ar,
unsigned int const version) {
901 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
902 ar &make_nvp(
"klist", _kernelList);
903 ar &make_nvp(
"kimglist", _kernelImagePtrList);
904 ar &make_nvp(
"ksumlist", _kernelSumList);
905 ar &make_nvp(
"params", _kernelParams);
907 ar &make_nvp(
"deltaBasis", _isDeltaFunctionBasis);
908 }
else if (Archive::is_loading::value) {
909 _isDeltaFunctionBasis =
false;
949 explicit SeparableKernel(
int width,
int height, KernelFunction
const &kernelColFunction,
950 KernelFunction
const &kernelRowFunction,
966 explicit SeparableKernel(
int width,
int height, KernelFunction
const &kernelColFunction,
967 KernelFunction
const &kernelRowFunction,
992 double x = 0.0,
double y = 0.0)
const;
995 unsigned int const ncol = _kernelColFunctionPtr->getNParameters();
997 return _kernelColFunctionPtr->getParameter(i);
1000 return _kernelRowFunctionPtr->getParameter(i);
1008 KernelFunctionPtr getKernelColFunction()
const;
1013 KernelFunctionPtr getKernelRowFunction()
const;
1026 virtual void computeCache(
int const cacheSize);
1031 virtual int getCacheSize()
const;
1036 virtual void setKernelParameter(
unsigned int ind,
double value)
const;
1053 bool doNormalize)
const;
1055 KernelFunctionPtr _kernelColFunctionPtr;
1056 KernelFunctionPtr _kernelRowFunctionPtr;
1067 friend class boost::serialization::access;
1068 template <
class Archive>
1069 void serialize(Archive &ar,
unsigned int const version) {
1070 ar &make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
1071 ar &make_nvp(
"colfn", _kernelColFunctionPtr);
1072 ar &make_nvp(
"rowfn", _kernelRowFunctionPtr);
1073 ar &make_nvp(
"cols", _localColList);
1074 ar &make_nvp(
"rows", _localRowList);
1075 ar &make_nvp(
"kernelX", _kernelX);
1076 ar &make_nvp(
"kernelY", _kernelY);
1079 virtual void _setKernelXY() {
1083 assert(dim[0] == static_cast<int>(_kernelX.
size()));
1084 for (
int i = 0; i != dim.getX(); ++i) {
1085 _kernelX[i] = i - ctr.getX();
1088 assert(dim[1] == static_cast<int>(_kernelY.
size()));
1089 for (
int i = 0; i != dim.getY(); ++i) {
1090 _kernelY[i] = i - ctr.getY();
1099 namespace serialization {
1101 template <
class Archive>
1103 unsigned int const file_version) {
1108 ar << make_nvp(
"width", width);
1109 ar << make_nvp(
"height", height);
1110 ar << make_nvp(
"pixX", x);
1111 ar << make_nvp(
"pixY", y);
1114 template <
class Archive>
1116 unsigned int const file_version) {
1121 ar >> make_nvp(
"width", width);
1122 ar >> make_nvp(
"height", height);
1123 ar >> make_nvp(
"pixX", x);
1124 ar >> make_nvp(
"pixY", y);
1132 #endif // !defined(LSST_AFW_MATH_KERNEL_H) virtual ~SeparableKernel()
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
virtual ~LinearCombinationKernel()
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
#define LSST_PERSIST_FORMATTER(formatter...)
virtual ~AnalyticKernel()
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
virtual ~DeltaFunctionKernel()
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.