27 #include "lsst/pex/exceptions.h"
31 namespace pexExcept = lsst::pex::exceptions;
38 :
Kernel(width, height, 0), _pixel(point) {
39 if (point.getX() < 0 || point.getX() >= width || point.getY() < 0 || point.getY() >= height) {
40 std::ostringstream os;
41 os <<
"point (" << point.getX() <<
", " << point.getY() <<
") lies outside " << width <<
"x" << height
43 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
48 std::shared_ptr<Kernel> retPtr(
50 retPtr->setCtr(this->
getCtr());
57 if ((padX % 2) || (padY % 2)) {
58 std::ostringstream os;
59 os <<
"Cannot resize DeltaFunctionKernel from (" <<
getWidth() <<
", " <<
getHeight() <<
") to ("
60 << width <<
", " << height <<
"), because at least one dimension would change by an odd value.";
61 throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
63 int newPixelX =
getPixel().getX() + padX/2;
64 int newPixelY =
getPixel().getY() + padY/2;
65 std::shared_ptr<Kernel> retPtr = std::make_shared<DeltaFunctionKernel>(
71 const int pixelX =
getPixel().getX();
72 const int pixelY =
getPixel().getY();
74 std::ostringstream os;
75 os << prefix <<
"DeltaFunctionKernel:" << std::endl;
76 os << prefix <<
"Pixel (c,r) " << pixelX <<
"," << pixelY <<
")" << std::endl;
82 const int pixelX =
getPixel().getX();
83 const int pixelY =
getPixel().getY();
86 *image.
xy_at(pixelX, pixelY) = 1;
98 static DeltaFunctionKernelPersistenceHelper
const&
get() {
99 static DeltaFunctionKernelPersistenceHelper
const instance;
104 DeltaFunctionKernelPersistenceHelper(
const DeltaFunctionKernelPersistenceHelper&) =
delete;
105 DeltaFunctionKernelPersistenceHelper& operator=(
const DeltaFunctionKernelPersistenceHelper&) =
delete;
108 DeltaFunctionKernelPersistenceHelper(DeltaFunctionKernelPersistenceHelper&&) =
delete;
109 DeltaFunctionKernelPersistenceHelper& operator=(DeltaFunctionKernelPersistenceHelper&&) =
delete;
112 explicit DeltaFunctionKernelPersistenceHelper()
113 : Kernel::PersistenceHelper(0),
114 pixel(table::PointKey<int>::addFields(
schema,
"pixel",
"position of nonzero pixel",
"pixel")) {
115 schema.getCitizen().markPersistent();
127 DeltaFunctionKernelPersistenceHelper
const& keys = DeltaFunctionKernelPersistenceHelper::get();
130 std::shared_ptr<DeltaFunctionKernel>
result(
132 record.get(keys.dimensions.getY()), record.get(keys.pixel)));
133 result->setCtr(record.get(keys.center));
142 std::string getDeltaFunctionKernelPersistenceName() {
return "DeltaFunctionKernel"; }
144 DeltaFunctionKernel::Factory registration(getDeltaFunctionKernelPersistenceName());
149 return getDeltaFunctionKernelPersistenceName();
153 DeltaFunctionKernelPersistenceHelper
const& keys = DeltaFunctionKernelPersistenceHelper::get();
154 std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *
this);
155 record->set(keys.pixel, _pixel);
virtual std::shared_ptr< Kernel > clone() const
Return a pointer to a deep copy of this kernel.
Factory(std::string const &name)
PersistableFactory(std::string const &name)
Constructor for the factory.
An object passed to Persistable::write to allow it to persist itself.
DeltaFunctionKernel(int width, int height, lsst::afw::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
#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.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
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.
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.
int getHeight() const
Return the Kernel's height.
int getWidth() const
Return the Kernel's width.
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
table::Key< std::string > name
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
lsst::afw::geom::Point2I getCtr() const
Return index of kernel's center.
virtual std::shared_ptr< Kernel > resized(int width, int height) const
Return a pointer to a clone with specified kernel dimensions.
A vector of catalogs used by Persistable.
lsst::afw::geom::Point2I getPixel() const
Base class for all records.
table::PointKey< int > pixel
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y) in the image.
Kernels are used for convolution with MaskedImages and (eventually) Images.
afw::table::Schema schema