30 namespace pexExcept = lsst::pex::exceptions;
31 namespace afwGeom = lsst::afw::geom;
32 namespace afwMath = lsst::afw::math;
47 Kernel(width, height, kernelFunction.getNParameters(), spatialFunction),
48 _kernelFunctionPtr(kernelFunction.clone())
55 std::vector<Kernel::SpatialFunctionPtr>
const &spatialFunctionList
57 Kernel(width, height, spatialFunctionList),
58 _kernelFunctionPtr(kernelFunction.clone())
60 if (kernelFunction.
getNParameters() != spatialFunctionList.size()) {
61 std::ostringstream os;
62 os <<
"kernelFunction.getNParameters() = " << kernelFunction.
getNParameters()
63 <<
" != " << spatialFunctionList.size() <<
" = " <<
"spatialFunctionList.size()";
64 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
70 if (this->isSpatiallyVarying()) {
72 *(this->_kernelFunctionPtr), this->_spatialFunctionList));
75 *(this->_kernelFunctionPtr)));
77 retPtr->setCtr(this->getCtr());
89 if (this->isSpatiallyVarying()) {
90 this->setKernelParametersFromSpatialModel(x, y);
92 return doComputeImage(image, doNormalize);
97 return _kernelFunctionPtr->clone();
101 std::ostringstream os;
102 os << prefix <<
"AnalyticKernel:" << std::endl;
103 os << prefix <<
"..function: " << (_kernelFunctionPtr ? _kernelFunctionPtr->toString() :
"None")
110 return _kernelFunctionPtr->getParameters();
124 for (
int x = 0;
x != image.
getWidth(); ++
x, ++ptr) {
126 Pixel const pixelVal = (*_kernelFunctionPtr)(fx, fy);
132 if (doNormalize && (imSum != 1)) {
134 throw LSST_EXCEPT(pexExcept::OverflowError,
"Cannot normalize; kernel sum is 0");
144 _kernelFunctionPtr->setParameter(ind, value);
149 namespace lsst {
namespace afw {
namespace math {
156 explicit AnalyticKernelPersistenceHelper(
int nSpatialFunctions) :
157 Kernel::PersistenceHelper(nSpatialFunctions),
160 "kernelfunction",
"archive ID for analytic function used to produce kernel images"
165 explicit AnalyticKernelPersistenceHelper(table::Schema
const & schema_) :
166 Kernel::PersistenceHelper(schema_),
180 AnalyticKernelPersistenceHelper
const keys(catalogs.front().getSchema());
185 if (keys.spatialFunctions.isValid()) {
186 result = boost::make_shared<AnalyticKernel>(
187 record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()), *
kernelFunction,
188 keys.readSpatialFunctions(archive, record)
191 result = boost::make_shared<AnalyticKernel>(
192 record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()), *
kernelFunction
195 result->setCtr(record.get(keys.center));
204 std::string getAnalyticKernelPersistenceName() {
return "AnalyticKernel"; }
206 AnalyticKernel::Factory registration(getAnalyticKernelPersistenceName());
213 AnalyticKernelPersistenceHelper
const keys(_spatialFunctionList.size());
215 record->set(keys.kernelFunction, handle.
put(_kernelFunctionPtr.get()));
void setXY0(geom::Point2I const origin)
Declare the Kernel class and subclasses.
boost::shared_ptr< lsst::afw::math::Function2< Pixel > > KernelFunctionPtr
int put(Persistable const *obj, bool permissive=false)
Save a nested Persistable to the same archive.
table::Key< std::string > name
An object passed to Persistable::write to allow it to persist itself.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
afw::table::Schema schema
Include files required for standard LSST Exception handling.
A base class for factory classes used to reconstruct objects from records.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
double indexToPosition(double ind, lsst::afw::image::xOrY const xy) const
Convert image index to image position.
A Function taking two arguments.
std::map< Citizen const *, CitizenInfo > table
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.
virtual void setKernelParameter(unsigned int ind, double value) const
Set one kernel parameter.
void ImageT ImageT int float saturatedPixelValue int const width
geom::Extent2I getDimensions() const
Return the image's size; useful for passing to constructors.
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 void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
int getHeight() const
Return the number of rows in the image.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
void ImageT ImageT int float saturatedPixelValue int const height
virtual KernelFunctionPtr getKernelFunction() const
Get a deep copy of the kernel function.
#define LSST_EXCEPT(type,...)
A vector of catalogs used by Persistable.
unsigned int getNParameters() const
Return the number of function parameters.
Factory(std::string const &name)
Base class for all records.
table::Key< int > kernelFunction
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
AnalyticKernel()
Construct an empty spatially invariant AnalyticKernel of size 0x0.
x_iterator row_begin(int y) const
A kernel described by a function.
int getWidth() const
Return the number of columns in the image.
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.