27 #include "lsst/pex/exceptions.h"
31 namespace pexExcept = lsst::pex::exceptions;
40 :
Kernel(image.getWidth(), image.getHeight(), 0), _image(image, true), _sum(0) {
43 for (
int y = 0; y != image.
getHeight(); ++y) {
44 for (XIter imPtr = image.
row_begin(y), imEnd = image.
row_end(y); imPtr != imEnd; ++imPtr) {
52 :
Kernel(kernel.getWidth(), kernel.getHeight(), 0), _image(kernel.getDimensions()), _sum(0) {
53 _sum = kernel.
computeImage(_image,
false, pos[0], pos[1]);
57 std::shared_ptr<Kernel> retPtr(
new FixedKernel(_image));
58 retPtr->setCtr(this->
getCtr());
63 double multFactor = 1.0;
64 double imSum = this->_sum;
67 throw LSST_EXCEPT(pexExcept::OverflowError,
"Cannot normalize; kernel sum is 0");
69 multFactor = 1.0 /
static_cast<double>(this->_sum);
75 for (
int y = 0; y != this->
getHeight(); ++y) {
77 imPtr != imEnd; ++imPtr, ++kPtr) {
78 imPtr[0] = multFactor * kPtr[0];
86 std::ostringstream os;
87 os << prefix <<
"FixedKernel:" << std::endl;
88 os << prefix <<
"..sum: " << _sum << std::endl;
98 table::Key<table::Array<Kernel::Pixel> >
image;
101 : Kernel::PersistenceHelper(0),
102 image(
schema.addField<table::Array<Kernel::Pixel> >(
"image",
"pixel values (row-major)",
103 dimensions.getX() * dimensions.getY())) {}
105 explicit FixedKernelPersistenceHelper(table::Schema
const& schema_)
106 : Kernel::PersistenceHelper(schema_),
image(
schema[
"image"]) {}
117 FixedKernelPersistenceHelper
const keys(catalogs.front().getSchema());
120 ndarray::flatten<1>(ndarray::static_dimension_cast<2>(image.
getArray())) = record[keys.image];
121 std::shared_ptr<FixedKernel>
result = std::make_shared<FixedKernel>(
image);
122 result->setCtr(record.get(keys.center));
131 std::string getFixedKernelPersistenceName() {
return "FixedKernel"; }
133 FixedKernel::Factory registration(getFixedKernelPersistenceName());
141 std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *
this);
142 (*record)[keys.image] = ndarray::flatten<1>(ndarray::copy(_image.
getArray()));
afw::table::PointKey< int > dimensions
geom::Extent2I const getDimensions() const
Return the Kernel's dimensions (width, height)
PersistableFactory(std::string const &name)
Constructor for the factory.
An object passed to Persistable::write to allow it to persist itself.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
A base class for factory classes used to reconstruct objects from records.
_view_t::x_iterator x_iterator
An iterator for traversing the pixels in a row.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Extent< int, 2 > Extent2I
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
int getHeight() const
Return the Kernel's height.
FixedKernel()
Construct an empty FixedKernel of size 0x0.
x_iterator row_end(int y) const
Return an x_iterator to the end of the y'th row.
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.
table::Key< std::string > name
int getHeight() const
Return the number of rows in the image.
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
virtual std::shared_ptr< afw::table::io::Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const
Construct a new object from the given InputArchive and vector of catalogs.
A vector of catalogs used by Persistable.
Base class for all records.
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
x_iterator row_begin(int y) const
Return an x_iterator to the start of the y'th row.
Kernels are used for convolution with MaskedImages and (eventually) Images.
afw::table::Schema schema
Factory(std::string const &name)