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)
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
lsst::afw::image::Image< Pixel > _image
virtual int getCacheSize() const
Get the current cache size (0 if none)
std::vector< double > _kernelY
bool isDeltaFunctionBasis() const
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.
friend class boost::serialization::access
std::vector< double > _kernelParams
An include file to include the header files for lsst::afw::geom.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
void load_construct_data(Archive &ar, lsst::meas::algorithms::DoubleGaussianPsf *p, unsigned int const )
int getWidth() const
Return the Kernel's width.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
boost::shared_ptr< lsst::afw::math::Function2< double > > SpatialFunctionPtr
void setKernelParametersFromSpatialModel(double x, double y) const
Set the kernel parameters from the spatial model (if any).
void setHeight(int height)
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual int getCacheSize() const
Get the current size of the kernel cache (0 if none or if caches not supported)
boost::shared_ptr< Kernel const > ConstPtr
virtual KernelList const & getKernelList() const
Get the fixed basis kernels.
void save_construct_data(Archive &ar, lsst::meas::algorithms::DoubleGaussianPsf const *p, unsigned int const )
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
int getHeight() const
Return the Kernel's height.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
virtual double getKernelParameter(unsigned int i) const
lsst::afw::geom::Point2I _pixel
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
bool _isDeltaFunctionBasis
void checkKernelList(const KernelList &kernelList) const
Check that all kernels have the same size and center and that none are spatially varying.
KernelFunctionPtr _kernelColFunctionPtr
std::vector< SpatialFunctionPtr > _spatialFunctionList
std::vector< double > _kernelSumList
sum of each basis kernel (a cache)
lsst::afw::geom::Box2I growBBox(lsst::afw::geom::Box2I const &bbox) const
A kernel described by a pair of functions: func(x, y) = colFunc(x) * rowFunc(y)
std::vector< SpatialFunctionPtr > getSpatialFunctionList() const
Return a list of clones of the spatial functions.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
void setCtrY(int ctrY)
Set y index of kernel's center.
unsigned int getNKernelParameters() const
Return the number of kernel parameters (0 if none)
int getNSpatialParameters() const
Return the number of spatial parameters (0 if not spatially varying)
std::vector< double > getKernelSumList() const
Get the sum of the pixels of each fixed basis kernel.
Traits to describe kernels, allowing for compile-time optimisation.
void _setKernelList(KernelList const &kernelList)
Set _kernelList by cloning each input kernel and update the kernel image cache.
io::OutputArchiveHandle OutputArchiveHandle
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
std::vector< Pixel > _localRowList
friend class boost::serialization::access
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
SpatialFunctionPtr getSpatialFunction(unsigned int index) const
Return a clone of the specified spatial function (one component of the spatial model) ...
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
A Function taking two arguments.
std::vector< std::vector< double > > _kernelColCache
bool isSpatiallyVarying() const
Return true iff the kernel is spatially varying (has a spatial function)
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) ...
An integer coordinate rectangle.
tbl::Key< int > cacheSize
table::Key< table::Array< Kernel::Pixel > > image
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
void serialize(Archive &ar, unsigned int const version)
A base class for objects that can be persisted via afw::table::io Archive classes.
void serialize(Archive &ar, unsigned int const version)
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
virtual void computeCache(int const cacheSize)
Compute a cache of Kernel values, if desired.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
a class used in function calls to indicate that no Function2 is being provided
virtual boost::shared_ptr< Kernel > clone() const =0
Return a pointer to a deep copy of this kernel.
std::vector< Pixel > _localColList
std::vector< double > _kernelX
A set of classes of general utility in connection with images.
std::vector< std::vector< double > > getSpatialParameters() const
Return the spatial parameters parameters (an empty vector if not spatially varying) ...
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
friend class boost::serialization::access
boost::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
boost::shared_ptr< Persistable > Ptr
A kernel that is a linear combination of fixed basis kernels.
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
virtual void computeCache(int const )
Compute a cache of Kernel values, if desired.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
A Function taking one argument.
virtual std::vector< double > getKernelParameters() const
Return the current kernel parameters.
std::vector< std::vector< double > > _kernelRowCache
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
void setKernelParameters(std::vector< double > const ¶ms)
Set the kernel parameters of a spatially invariant kernel.
KernelFunctionPtr _kernelFunctionPtr
void setCtr(lsst::afw::geom::Point2I ctr)
Set index of kernel's center.
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
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...
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
friend class boost::serialization::access
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
Interface for Persistable base class.
virtual void _setKernelXY()
int getNBasisKernels() const
Get the number of basis kernels.
lsst::afw::geom::Box2I getBBox() const
return parent bounding box, with XY0 = -center
virtual boost::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
#define LSST_PERSIST_FORMATTER(formatter...)
#define LSST_EXCEPT(type,...)
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const =0
Low-level version of computeImage.
Kernel has only one non-zero pixel.
table::Key< int > kernelFunction
KernelFunctionPtr getKernelColFunction() const
Get a deep copy of the col kernel function.
std::vector< boost::shared_ptr< lsst::afw::image::Image< Pixel > > > _kernelImagePtrList
image of each basis kernel (a cache)
lsst::afw::geom::Point2I getPixel() const
void computeKernelParametersFromSpatialModel(std::vector< double > &kernelParams, double x, double y) const
Compute the kernel parameters at a specified point.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
KernelFunctionPtr getKernelRowFunction() const
Get a deep copy of the row kernel function.
virtual Pixel getSum() const
Define the basic Function classes.
virtual void _setKernelXY()
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
unsigned int _nKernelParams
Point< double, 2 > Point2D
KernelList _kernelList
basis kernels
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) ...
Base class for all persistable classes.
KernelFunctionPtr _kernelRowFunctionPtr
boost::shared_ptr< KernelFunction > KernelFunctionPtr
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
std::vector< boost::shared_ptr< Kernel > > KernelList
void serialize(Archive &ar, unsigned int const version)
A kernel described by a function.
virtual bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
int getCtrY() const
Return y index of kernel's center.
void setCtrX(int ctrX)
Set x index of kernel's center.
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
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
friend class boost::serialization::access
void setDimensions(geom::Extent2I dims)
A CRTP facade class for subclasses of Persistable.
Kernels are used for convolution with MaskedImages and (eventually) Images.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Extent< int, 2 > Extent2I
void setSpatialParameters(const std::vector< std::vector< double > > params)
Set the parameters of all spatial functions.
A kernel that has only one non-zero pixel (of value 1)
void serialize(Archive &ar, unsigned int const version)
void setKernelParameters(std::pair< double, double > const ¶ms)
Set the kernel parameters of a 2-component spatially invariant kernel.
virtual double getKernelParameter(unsigned int i) const
void serialize(Archive &ar, unsigned int const version)
DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
Tags carrying information about Kernels Kernel with no special properties.
A kernel created from an Image.
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.
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.
int getCtrX() const
Return x index of kernel's center.