25 #ifndef LSST_AFW_MATH_KERNEL_H
26 #define LSST_AFW_MATH_KERNEL_H
37 #include <type_traits>
41 #include "boost/mpl/or.hpp"
43 #include "boost/serialization/shared_ptr.hpp"
44 #include "boost/serialization/vector.hpp"
45 #include "boost/serialization/export.hpp"
60 namespace formatters {
61 class KernelFormatter;
67 using boost::serialization::make_nvp;
165 unsigned int nKernelParams,
166 SpatialFunction const &spatialFunction=NullSpatialFunction()
180 const std::vector<SpatialFunctionPtr> spatialFunctionList
388 std::vector<std::vector<double> > spatialParams;
391 spatialParams.push_back((*spFuncIter)->getParameters());
393 return spatialParams;
411 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
412 "Kernel is spatially varying");
415 if (nParams != params.size()) {
416 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
417 (
boost::format(
"Number of parameters is wrong, saw %d expected %d") %
418 nParams % params.size()).str());
420 for (
unsigned int ii = 0; ii < nParams; ++ii) {
453 std::vector<double> &kernelParams,
double x,
double y)
const;
458 virtual std::string
toString(std::string
const& prefix=
"")
const;
475 #if 0 // fails to compile with icc; is it actually used?
476 virtual void toFile(std::string fileName)
const;
479 struct PersistenceHelper;
534 Kernel& operator=(const Kernel&);
561 explicit FixedKernel(
568 explicit FixedKernel(
569 lsst::afw::math::
Kernel const& kernel,
570 lsst::afw::geom::
Point2D const& pos
573 virtual ~FixedKernel() {}
577 virtual std::
string toString(std::
string const& prefix = "") const;
602 template <
class Archive>
603 void serialize(Archive& ar,
unsigned int const version) {
605 boost::serialization::base_object<Kernel>(*
this));
606 ar & make_nvp(
"img",
_image);
607 ar & make_nvp(
"sum",
_sum);
642 explicit AnalyticKernel(
658 explicit AnalyticKernel(
661 KernelFunction const &kernelFunction,
666 virtual ~AnalyticKernel() {}
703 virtual std::
string toString(std::
string const& prefix="") const;
725 template <
class Archive>
726 void serialize(Archive& ar,
unsigned int const version) {
728 boost::serialization::base_object<Kernel>(*
this));
758 lsst::afw::geom::
Point2I const &point
767 virtual std::string
toString(std::string
const& prefix=
"")
const;
787 template <
class Archive>
788 void serialize(Archive& ar,
unsigned int const version) {
789 boost::serialization::void_cast_register<
791 static_cast<DeltaFunctionKernel*
>(0),
792 static_cast<Kernel*>(0));
826 explicit LinearCombinationKernel(
828 std::vector<
double> const &kernelParameters
835 explicit LinearCombinationKernel(
847 explicit LinearCombinationKernel(
853 virtual ~LinearCombinationKernel() {}
922 virtual std::
string toString(std::
string const& prefix="") const;
954 template <
class Archive>
955 void serialize(Archive& ar,
unsigned int const version) {
956 ar & make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
964 else if (Archive::is_loading::value) {
999 explicit SeparableKernel(
1002 KernelFunction const& kernelColFunction,
1003 KernelFunction const& kernelRowFunction,
1015 explicit SeparableKernel(
1018 KernelFunction const& kernelColFunction,
1019 KernelFunction const& kernelRowFunction,
1023 virtual ~SeparableKernel() {}
1039 std::vector<
Pixel> &colList,
1040 std::vector<
Pixel> &rowList,
1067 virtual std::string
toString(std::string
const& prefix=
"")
const;
1105 std::vector<Pixel> &colList,
1106 std::vector<Pixel> &rowList,
1123 template <
class Archive>
1126 boost::serialization::base_object<Kernel>(*
this));
1131 ar & make_nvp(
"kernelX",
_kernelX);
1132 ar & make_nvp(
"kernelY",
_kernelY);
1139 assert (dim[0] == static_cast<int>(
_kernelX.size()));
1140 for (
int i = 0; i != dim.getX(); ++i) {
1144 assert (dim[1] == static_cast<int>(
_kernelY.size()));
1145 for (
int i = 0; i != dim.getY(); ++i) {
1154 namespace serialization {
1156 template <
class Archive>
1159 unsigned int const file_version) {
1164 ar << make_nvp(
"width", width);
1165 ar << make_nvp(
"height", height);
1166 ar << make_nvp(
"pixX", x);
1167 ar << make_nvp(
"pixY", y);
1170 template <
class Archive>
1173 unsigned int const file_version) {
1178 ar >> make_nvp(
"width", width);
1179 ar >> make_nvp(
"height", height);
1180 ar >> make_nvp(
"pixX", x);
1181 ar >> make_nvp(
"pixY", y);
1192 #endif // !defined(LSST_AFW_MATH_KERNEL_H)
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
friend class boost::serialization::access
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
An include file to include the header files for lsst::afw::geom.
bool _isDeltaFunctionBasis
virtual int getCacheSize() const
Get the current cache size (0 if none)
geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
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::vector< std::vector< double > > _kernelRowCache
boost::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
#define LSST_PERSIST_FORMATTER(formatter...)
Macro used to connect the persistable class with the Formatter and boost::serialization.
KernelFunctionPtr _kernelRowFunctionPtr
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
boost::shared_ptr< Kernel > refactor() const
Refactor the kernel as a linear combination of N bases where N is the number of parameters for the sp...
void setDimensions(geom::Extent2I dims)
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
KernelList _kernelList
basis kernels
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
lsst::afw::geom::Box2I growBBox(lsst::afw::geom::Box2I const &bbox) const
Given a bounding box for pixels one wishes to compute by convolving an image with this kernel...
int getCtrY() const
Return y index of kernel's center.
void setKernelParameters(std::vector< double > const ¶ms)
Set the kernel parameters of a spatially invariant kernel.
std::shared_ptr< Persistable > Ptr
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
void serialize(Archive &ar, unsigned int const version)
io::OutputArchiveHandle OutputArchiveHandle
std::vector< Pixel > _localColList
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
A set of classes of general utility in connection with images.
Traits to describe kernels, allowing for compile-time optimisation.
void setHeight(int height)
void serialize(Archive &ar, unsigned int const version)
boost::shared_ptr< KernelFunction > KernelFunctionPtr
int getCtrX() const
Return x index of kernel's center.
friend class boost::serialization::access
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
A Function taking two arguments.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
lsst::afw::geom::Point2I _pixel
std::vector< Pixel > _localRowList
bool isDeltaFunctionBasis() const
Return true if all basis kernels are instances of DeltaFunctionKernel.
An integer coordinate rectangle.
tbl::Key< int > cacheSize
int getHeight() const
Return the Kernel's height.
std::vector< double > _kernelX
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
table::Key< table::Array< Kernel::Pixel > > image
A base class for objects that can be persisted via afw::table::io Archive classes.
double basicComputeVectors(std::vector< Pixel > &colList, std::vector< Pixel > &rowList, bool doNormalize) const
Compute the column and row arrays in place, where kernel(col, row) = colList(col) * rowList(row) ...
int getWidth() const
Return the Kernel's width.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
void serialize(Archive &ar, unsigned int const version)
a class used in function calls to indicate that no Function2 is being provided
boost::shared_ptr< Kernel const > ConstPtr
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
void serialize(Archive &ar, unsigned int const version)
void setCtrY(int ctrY)
Set y index of kernel's center.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual double getKernelParameter(unsigned int i) const
Return a particular Kernel Parameter (no bounds checking).
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
KernelFunctionPtr _kernelFunctionPtr
void ImageT ImageT int float saturatedPixelValue int const width
friend class boost::serialization::access
int getNBasisKernels() const
Get the number of basis kernels.
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
std::vector< double > _kernelParams
Interface for Persistable base class.
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
void setCtrX(int ctrX)
Set x index of kernel's center.
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
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.
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.
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)
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
A Function taking one argument.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
unsigned int _nKernelParams
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel's center.
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
void ImageT ImageT int float saturatedPixelValue int const height
virtual boost::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
friend class boost::serialization::access
void setSpatialParameters(const std::vector< std::vector< double > > params)
Set the parameters of all spatial functions.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
std::vector< std::vector< double > > _kernelColCache
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
void serialize(Archive &ar, unsigned int const version)
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
virtual void computeCache(int const cacheSize)
Compute a cache of Kernel values, if desired.
Kernel has only one non-zero pixel.
lsst::afw::geom::Point2I getPixel() const
table::Key< int > kernelFunction
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model) ...
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
KernelFunctionPtr _kernelColFunctionPtr
std::vector< SpatialFunctionPtr > _spatialFunctionList
Define the basic Function classes.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
virtual Pixel getSum() const
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
Point< double, 2 > Point2D
std::vector< double > _kernelY
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
Base class for all persistable classes.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
#define CONST_PTR(...)
A shared pointer to a const object.
virtual void _setKernelXY()
A kernel described by a function.
lsst::afw::image::Image< Pixel > _image
virtual void _setKernelXY()
friend class boost::serialization::access
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
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)
Extent< int, 2 > Extent2I
A kernel that has only one non-zero pixel (of value 1)
virtual void computeCache(int const )
Compute a cache of Kernel values, if desired.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
lsst::afw::geom::Box2I shrinkBBox(lsst::afw::geom::Box2I const &bbox) const
Given a bounding box for an image one wishes to convolve with this kernel, return the bounding box fo...
Tags carrying information about Kernels Kernel with no special properties.
A kernel created from an Image.
std::vector< boost::shared_ptr< Kernel > > KernelList
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)