LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
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 
31 namespace pexExcept = lsst::pex::exceptions;
32 namespace afwMath = lsst::afw::math;
33 namespace afwImage = lsst::afw::image;
34 namespace afwGeom = lsst::afw::geom;
35 
37  int width,
38  int height,
39  afwGeom::Point2I const &point
40 ) :
41  Kernel(width, height, 0),
42  _pixel(point)
43 {
44  if (point.getX() < 0 || point.getX() >= width || point.getY() < 0 || point.getY() >= height) {
45  std::ostringstream os;
46  os << "point (" << point.getX() << ", " << point.getY() << ") lies outside "
47  << width << "x" << height << " sized kernel";
48  throw LSST_EXCEPT(pexExcept::InvalidParameterError, os.str());
49  }
50 }
51 
52 PTR(afwMath::Kernel) afwMath::DeltaFunctionKernel::clone() const {
53  PTR(afwMath::Kernel) retPtr(new afwMath::DeltaFunctionKernel(this->getWidth(), this->getHeight(),
54  this->_pixel));
55  retPtr->setCtr(this->getCtr());
56  return retPtr;
57 }
58 
59 std::string afwMath::DeltaFunctionKernel::toString(std::string const& prefix) const {
60  const int pixelX = getPixel().getX(); // active pixel in Kernel
61  const int pixelY = getPixel().getY();
62 
63  std::ostringstream os;
64  os << prefix << "DeltaFunctionKernel:" << std::endl;
65  os << prefix << "Pixel (c,r) " << pixelX << "," << pixelY << ")" << std::endl;
66  os << Kernel::toString(prefix + "\t");
67  return os.str();
68 }
69 
72  bool
73 ) const {
74  const int pixelX = getPixel().getX(); // active pixel in Kernel
75  const int pixelY = getPixel().getY();
76 
77  image = 0;
78  *image.xy_at(pixelX, pixelY) = 1;
79 
80  return 1;
81 }
82 
83 // ------ Persistence ---------------------------------------------------------------------------------------
84 
85 namespace lsst { namespace afw { namespace math {
86 
87 namespace {
88 
89 struct DeltaFunctionKernelPersistenceHelper : public Kernel::PersistenceHelper, private boost::noncopyable {
90  table::PointKey<int> pixel;
91 
92  static DeltaFunctionKernelPersistenceHelper const & get() {
93  static DeltaFunctionKernelPersistenceHelper const instance;
94  return instance;
95  }
96 
97 private:
98 
99  explicit DeltaFunctionKernelPersistenceHelper() :
100  Kernel::PersistenceHelper(0),
101  pixel(table::PointKey<int>::addFields(schema, "pixel", "position of nonzero pixel", "pixels"))
102  {
103  schema.getCitizen().markPersistent();
104  }
105 
106 };
107 
108 } // anonymous
109 
111 public:
112 
114  read(InputArchive const & archive, CatalogVector const & catalogs) const {
115  LSST_ARCHIVE_ASSERT(catalogs.size() == 1u);
116  LSST_ARCHIVE_ASSERT(catalogs.front().size() == 1u);
117  DeltaFunctionKernelPersistenceHelper const & keys = DeltaFunctionKernelPersistenceHelper::get();
118  LSST_ARCHIVE_ASSERT(catalogs.front().getSchema() == keys.schema);
119  afw::table::BaseRecord const & record = catalogs.front().front();
120  PTR(DeltaFunctionKernel) result(
121  new DeltaFunctionKernel(record.get(keys.dimensions.getX()), record.get(keys.dimensions.getY()),
122  record.get(keys.pixel))
123  );
124  result->setCtr(record.get(keys.center));
125  return result;
126  }
127 
128  explicit Factory(std::string const & name) : afw::table::io::PersistableFactory(name) {}
129 };
130 
131 namespace {
132 
133 std::string getDeltaFunctionKernelPersistenceName() { return "DeltaFunctionKernel"; }
134 
135 DeltaFunctionKernel::Factory registration(getDeltaFunctionKernelPersistenceName());
136 
137 } // anonymous
138 
140  return getDeltaFunctionKernelPersistenceName();
141 }
142 
144  DeltaFunctionKernelPersistenceHelper const & keys = DeltaFunctionKernelPersistenceHelper::get();
145  PTR(afw::table::BaseRecord) record = keys.write(handle, *this);
146  record->set(keys.pixel, _pixel);
147 }
148 
149 }}} // namespace lsst::afw::math
Declare the Kernel class and subclasses.
table::Key< std::string > name
Definition: ApCorrMap.cc:71
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.
afw::table::Schema schema
Definition: GaussianPsf.cc:41
Include files required for standard LSST Exception handling.
A base class for factory classes used to reconstruct objects from records.
Definition: Persistable.h:231
virtual std::string toString(std::string const &prefix="") const
Return a string representation of the kernel.
Definition: Kernel.cc:224
#define PTR(...)
Definition: base.h:41
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.
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:93
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
virtual double doComputeImage(lsst::afw::image::Image< Pixel > &image, bool doNormalize) const
Low-level version of computeImage.
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
Definition: Persistable.h:47
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
A vector of catalogs used by Persistable.
Definition: CatalogVector.h:26
Base class for all records.
Definition: BaseRecord.h:27
table::PointKey< int > pixel
xy_locator xy_at(int x, int y) const
Definition: Image.h:351
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:28
Kernels are used for convolution with MaskedImages and (eventually) Images.
Definition: Kernel.h:134
A kernel that has only one non-zero pixel (of value 1)
Definition: Kernel.h:744