25 #ifndef LSST_AFW_MATH_KERNEL_H
26 #define LSST_AFW_MATH_KERNEL_H
39 #include "boost/mpl/or.hpp"
40 #include "boost/shared_ptr.hpp"
41 #include "boost/make_shared.hpp"
42 #include "boost/static_assert.hpp"
43 #include "boost/type_traits/is_same.hpp"
44 #include "boost/type_traits/is_base_and_derived.hpp"
46 #include "boost/serialization/shared_ptr.hpp"
47 #include "boost/serialization/vector.hpp"
48 #include "boost/serialization/export.hpp"
63 namespace formatters {
64 class KernelFormatter;
70 using boost::serialization::make_nvp;
168 unsigned int nKernelParams,
169 SpatialFunction const &spatialFunction=NullSpatialFunction()
183 const std::vector<SpatialFunctionPtr> spatialFunctionList
391 std::vector<std::vector<double> > spatialParams;
394 spatialParams.push_back((*spFuncIter)->getParameters());
396 return spatialParams;
414 throw LSST_EXCEPT(lsst::pex::exceptions::RuntimeError,
415 "Kernel is spatially varying");
418 if (nParams != params.size()) {
419 throw LSST_EXCEPT(lsst::pex::exceptions::InvalidParameterError,
420 (
boost::format(
"Number of parameters is wrong, saw %d expected %d") %
421 nParams % params.size()).str());
423 for (
unsigned int ii = 0; ii < nParams; ++ii) {
456 std::vector<double> &kernelParams,
double x,
double y)
const;
461 virtual std::string
toString(std::string
const& prefix=
"")
const;
478 #if 0 // fails to compile with icc; is it actually used?
479 virtual void toFile(std::string fileName)
const;
482 struct PersistenceHelper;
537 Kernel& operator=(const Kernel&);
564 explicit FixedKernel(
571 explicit FixedKernel(
572 lsst::afw::math::
Kernel const& kernel,
573 lsst::afw::geom::
Point2D const& pos
576 virtual ~FixedKernel() {}
580 virtual std::
string toString(std::
string const& prefix = "") const;
605 template <
class Archive>
606 void serialize(Archive& ar,
unsigned int const version) {
608 boost::serialization::base_object<Kernel>(*
this));
609 ar & make_nvp(
"img",
_image);
610 ar & make_nvp(
"sum",
_sum);
645 explicit AnalyticKernel(
661 explicit AnalyticKernel(
664 KernelFunction const &kernelFunction,
669 virtual ~AnalyticKernel() {}
706 virtual std::
string toString(std::
string const& prefix="") const;
728 template <
class Archive>
729 void serialize(Archive& ar,
unsigned int const version) {
731 boost::serialization::base_object<Kernel>(*
this));
761 lsst::afw::geom::
Point2I const &point
770 virtual std::string
toString(std::string
const& prefix=
"")
const;
790 template <
class Archive>
791 void serialize(Archive& ar,
unsigned int const version) {
792 boost::serialization::void_cast_register<
794 static_cast<DeltaFunctionKernel*
>(0),
795 static_cast<Kernel*>(0));
829 explicit LinearCombinationKernel(
831 std::vector<
double> const &kernelParameters
838 explicit LinearCombinationKernel(
850 explicit LinearCombinationKernel(
856 virtual ~LinearCombinationKernel() {}
925 virtual std::
string toString(std::
string const& prefix="") const;
957 template <
class Archive>
958 void serialize(Archive& ar,
unsigned int const version) {
959 ar & make_nvp(
"k", boost::serialization::base_object<Kernel>(*
this));
967 else if (Archive::is_loading::value) {
1002 explicit SeparableKernel(
1005 KernelFunction const& kernelColFunction,
1006 KernelFunction const& kernelRowFunction,
1018 explicit SeparableKernel(
1021 KernelFunction const& kernelColFunction,
1022 KernelFunction const& kernelRowFunction,
1026 virtual ~SeparableKernel() {}
1042 std::vector<
Pixel> &colList,
1043 std::vector<
Pixel> &rowList,
1070 virtual std::string
toString(std::string
const& prefix=
"")
const;
1108 std::vector<Pixel> &colList,
1109 std::vector<Pixel> &rowList,
1126 template <
class Archive>
1129 boost::serialization::base_object<Kernel>(*
this));
1134 ar & make_nvp(
"kernelX",
_kernelX);
1135 ar & make_nvp(
"kernelY",
_kernelY);
1142 assert (dim[0] == static_cast<int>(
_kernelX.size()));
1143 for (
int i = 0; i != dim.getX(); ++i) {
1147 assert (dim[1] == static_cast<int>(
_kernelY.size()));
1148 for (
int i = 0; i != dim.getY(); ++i) {
1157 namespace serialization {
1159 template <
class Archive>
1162 unsigned int const file_version) {
1167 ar << make_nvp(
"width", width);
1168 ar << make_nvp(
"height", height);
1169 ar << make_nvp(
"pixX", x);
1170 ar << make_nvp(
"pixY", y);
1173 template <
class Archive>
1176 unsigned int const file_version) {
1181 ar >> make_nvp(
"width", width);
1182 ar >> make_nvp(
"height", height);
1183 ar >> make_nvp(
"pixX", x);
1184 ar >> make_nvp(
"pixY", y);
1195 #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
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
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.
A set of classes of general utility in connection with images.
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
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.
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)
Point< double, 2 > Point2D
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) ...
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.
Extent< int, 2 > Extent2I
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
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)
boost::shared_ptr< Kernel > Ptr
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
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
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.
#define LSST_PERSIST_FORMATTER(formatter...)
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
Interface for Persistable base class.
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,...)
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)
io::OutputArchiveHandle OutputArchiveHandle
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.
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...
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)
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
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)