LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
LSSTDataManagementBasePackage
DeltaFunctionKernel.cc
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 #include <sstream>
25 #include <vector>
26 
27 #include "lsst/pex/exceptions.h"
28 #include "lsst/afw/math/Kernel.h"
30 #include "lsst/afw/table/io/Persistable.cc"
31 
33 
34 namespace lsst {
35 namespace afw {
36 
37 template std::shared_ptr<math::DeltaFunctionKernel> table::io::PersistableFacade<
38  math::DeltaFunctionKernel>::dynamicCast(std::shared_ptr<table::io::Persistable> const&);
39 
40 namespace math {
41 
43  : Kernel(width, height, 0), _pixel(point) {
44  if (point.getX() < 0 || point.getX() >= width || point.getY() < 0 || point.getY() >= height) {
46  os << "point (" << point.getX() << ", " << point.getY() << ") lies outside " << width << "x" << height
47  << " sized kernel";
49  }
50 }
51 
54  new DeltaFunctionKernel(this->getWidth(), this->getHeight(), this->_pixel));
55  retPtr->setCtr(this->getCtr());
56  return retPtr;
57 }
58 
60  int padX = width - getWidth();
61  int padY = height - getHeight();
62  if ((padX % 2) || (padY % 2)) {
64  os << "Cannot resize DeltaFunctionKernel from (" << getWidth() << ", " << getHeight() << ") to ("
65  << width << ", " << height << "), because at least one dimension would change by an odd value.";
67  }
68  int newPixelX = getPixel().getX() + padX / 2;
69  int newPixelY = getPixel().getY() + padY / 2;
71  std::make_shared<DeltaFunctionKernel>(width, height, lsst::geom::Point2I(newPixelX, newPixelY));
72  return retPtr;
73 }
74 
76  const int pixelX = getPixel().getX(); // active pixel in Kernel
77  const int pixelY = getPixel().getY();
78 
80  os << prefix << "DeltaFunctionKernel:" << std::endl;
81  os << prefix << "Pixel (c,r) " << pixelX << "," << pixelY << ")" << std::endl;
82  os << Kernel::toString(prefix + "\t");
83  return os.str();
84 }
85 
87  const int pixelX = getPixel().getX(); // active pixel in Kernel
88  const int pixelY = getPixel().getY();
89 
90  image = 0;
91  *image.xy_at(pixelX, pixelY) = 1;
92 
93  return 1;
94 }
95 
96 // ------ Persistence ---------------------------------------------------------------------------------------
97 
98 namespace {
99 
100 struct DeltaFunctionKernelPersistenceHelper : public Kernel::PersistenceHelper {
101  table::PointKey<int> pixel;
102 
103  static DeltaFunctionKernelPersistenceHelper const& get() {
104  static DeltaFunctionKernelPersistenceHelper const instance;
105  return instance;
106  }
107 
108  // No copying
109  DeltaFunctionKernelPersistenceHelper(const DeltaFunctionKernelPersistenceHelper&) = delete;
110  DeltaFunctionKernelPersistenceHelper& operator=(const DeltaFunctionKernelPersistenceHelper&) = delete;
111 
112  // No moving
113  DeltaFunctionKernelPersistenceHelper(DeltaFunctionKernelPersistenceHelper&&) = delete;
114  DeltaFunctionKernelPersistenceHelper& operator=(DeltaFunctionKernelPersistenceHelper&&) = delete;
115 
116 private:
117  explicit DeltaFunctionKernelPersistenceHelper()
118  : Kernel::PersistenceHelper(0),
119  pixel(table::PointKey<int>::addFields(schema, "pixel", "position of nonzero pixel", "pixel")) {
120  schema.getCitizen().markPersistent();
121  }
122 };
123 
124 } // namespace
125 
127 public:
129  CatalogVector const& catalogs) const override {
130  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
131  LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u);
132  DeltaFunctionKernelPersistenceHelper const& keys = DeltaFunctionKernelPersistenceHelper::get();
133  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
134  afw::table::BaseRecord const& record = catalogs.front().front();
136  new DeltaFunctionKernel(record.get(keys.dimensions.getX()),
137  record.get(keys.dimensions.getY()), record.get(keys.pixel)));
138  result->setCtr(record.get(keys.center));
139  return result;
140  }
141 
142  explicit Factory(std::string const& name) : afw::table::io::PersistableFactory(name) {}
143 };
144 
145 namespace {
146 
147 std::string getDeltaFunctionKernelPersistenceName() { return "DeltaFunctionKernel"; }
148 
149 DeltaFunctionKernel::Factory registration(getDeltaFunctionKernelPersistenceName());
150 
151 } // namespace
152 
154  return getDeltaFunctionKernelPersistenceName();
155 }
156 
158  DeltaFunctionKernelPersistenceHelper const& keys = DeltaFunctionKernelPersistenceHelper::get();
159  std::shared_ptr<afw::table::BaseRecord> record = keys.write(handle, *this);
160  record->set(keys.pixel, _pixel);
161 }
162 } // namespace math
163 } // namespace afw
164 } // namespace lsst
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
int getHeight() const
Return the Kernel&#39;s height.
Definition: Kernel.h:233
std::shared_ptr< Kernel > clone() const override
Return a pointer to a deep copy of this kernel.
An object passed to Persistable::write to allow it to persist itself.
T front(T... args)
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:228
T endl(T... args)
py::object result
Definition: schema.cc:284
static PointKey addFields(Schema &schema, std::string const &name, std::string const &doc, std::string const &unit)
Add a pair of _x, _y fields to a Schema, and return a PointKey that points to them.
Definition: aggregates.cc:36
std::string prefix
Definition: SchemaMapper.cc:79
STL class.
STL class.
A base class for image defects.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
T str(T... args)
std::string toString(std::string const &prefix="") const override
Return a string representation of the kernel.
table::Schema schema
Definition: Camera.cc:161
lsst::geom::Point2I getCtr() const
Return index of kernel&#39;s center.
Definition: Kernel.h:238
Point< int, 2 > Point2I
Definition: Point.h:321
int getWidth() const
Return the Kernel&#39;s width.
Definition: Kernel.h:228
T size(T... args)
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:29
Base class for all records.
Definition: BaseRecord.h:31
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:48
Reports invalid arguments.
Definition: Runtime.h:66
table::PointKey< int > pixel
std::shared_ptr< afw::table::io::Persistable > read(InputArchive const &archive, CatalogVector const &catalogs) const override
Construct a new object from the given InputArchive and vector of catalogs.
lsst::geom::Point2I getPixel() const
Definition: Kernel.h:708
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const override
Low-level version of computeImage.
DeltaFunctionKernel(int width, int height, lsst::geom::Point2I const &point)
Construct a spatially invariant DeltaFunctionKernel.
DeltaFunctionKernel & operator=(const DeltaFunctionKernel &)=delete
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:112
xy_locator xy_at(int x, int y) const
Return an xy_locator at the point (x, y) in the image.
Definition: ImageBase.h:443
std::shared_ptr< Kernel > resized(int width, int height) const override
Return a pointer to a clone with specified kernel dimensions.
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:204
std::ostream * os
Definition: Schema.cc:746