LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
LSSTDataManagementBasePackage
Footprint.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 #if !defined(LSST_DETECTION_FOOTPRINT_H)
23 #define LSST_DETECTION_FOOTPRINT_H
24 
25 #include <algorithm>
26 #include <list>
27 #include <set>
28 #include <cmath>
29 #include <cstdint>
30 #include <memory>
31 #include "ndarray.h"
32 #include "lsst/base.h"
35 #include "lsst/afw/geom/Span.h"
36 #include "lsst/afw/geom/SpanSet.h"
37 #include "lsst/geom/Box.h"
38 #include "lsst/afw/geom/ellipses.h"
40 #include "lsst/afw/geom/SkyWcs.h"
42 #include "lsst/afw/table/fwd.h"
43 #include "lsst/afw/table/Schema.h"
44 #include "lsst/afw/table/Key.h"
47 
48 namespace lsst {
49 namespace afw {
50 namespace detection {
51 
62 class Footprint : public afw::table::io::PersistableFacade<lsst::afw::detection::Footprint>,
64 public:
65  /*
66  * As a note there is no constructor which accepts a unique_ptr to a SpanSet.
67  * If someone did have a unique_ptr to a SpanSet it is possible to wrap the
68  * unique_ptr in a std::move when calling the constructor of a Footprint and
69  * the compiler will implicitly turn the unique_ptr into a shared_ptr and use
70  * that to construct the Footprint.
71  */
72 
80  explicit Footprint(std::shared_ptr<geom::SpanSet> inputSpans,
81  lsst::geom::Box2I const &region = lsst::geom::Box2I());
82 
91  explicit Footprint(std::shared_ptr<geom::SpanSet> inputSpans, afw::table::Schema const &peakSchema,
92  lsst::geom::Box2I const &region = lsst::geom::Box2I());
93 
96  explicit Footprint()
97  : _spans(std::make_shared<geom::SpanSet>()),
98  _peaks(PeakTable::makeMinimalSchema()),
99  _region(lsst::geom::Box2I()) {}
100 
101  Footprint(Footprint const &other) = default;
102  Footprint(Footprint &&) = default;
103 
104  Footprint &operator=(Footprint const &other) = default;
105  Footprint &operator=(Footprint &&) = default;
106 
107  ~Footprint() override = default;
108 
111  virtual bool isHeavy() const { return false; }
112 
115  std::shared_ptr<geom::SpanSet> getSpans() const { return _spans; }
116 
121  void setSpans(std::shared_ptr<geom::SpanSet> otherSpanSet);
122 
129  PeakCatalog &getPeaks() { return _peaks; }
130  const PeakCatalog &getPeaks() const { return _peaks; }
131 
138  std::shared_ptr<PeakRecord> addPeak(float fx, float fy, float value);
139 
149 
156  void setPeakSchema(afw::table::Schema const &peakSchema);
157 
166  void setPeakCatalog(PeakCatalog const &otherPeaks);
167 
173  std::size_t getArea() const { return _spans->getArea(); }
174 
180  lsst::geom::Point2D getCentroid() const { return _spans->computeCentroid(); }
181 
188  geom::ellipses::Quadrupole getShape() const { return _spans->computeShape(); }
189 
196  void shift(int dx, int dy);
197 
203  void shift(lsst::geom::ExtentI const &d) { shift(d.getX(), d.getY()); }
204 
208  lsst::geom::Box2I getBBox() const { return _spans->getBBox(); }
209 
213  lsst::geom::Box2I getRegion() const { return _region; }
214 
220  void setRegion(lsst::geom::Box2I const &region) { _region = region; }
221 
228  void clipTo(lsst::geom::Box2I const &bbox);
229 
235  bool contains(lsst::geom::Point2I const &pix) const;
236 
248  lsst::geom::Box2I const &region, bool doClip = true) const;
249 
258  lsst::geom::Box2I const &region, bool doClip = true) const;
259 
268  lsst::geom::Box2I const &region, bool doClip = true) const;
269 
278  lsst::geom::Box2I const &region, bool doClip = true) const;
279 
283  bool isPersistable() const noexcept override { return true; }
284 
294  void dilate(int r, geom::Stencil s = geom::Stencil::CIRCLE);
295 
304  void dilate(geom::SpanSet const &other);
305 
315  void erode(int r, geom::Stencil s = geom::Stencil::CIRCLE);
316 
325  void erode(geom::SpanSet const &other);
326 
330  void removeOrphanPeaks();
331 
335  bool isContiguous() const { return getSpans()->isContiguous(); };
336 
345 
351  bool operator==(Footprint const &other) const;
352 
353 protected:
357  std::string getPersistenceName() const override;
358 
362  inline std::string getPythonModule() const override { return "lsst.afw.detection"; }
363 
367  void write(OutputArchiveHandle &handle) const override;
368 
369  friend class FootprintFactory;
370 
379  static void readPeaks(afw::table::BaseCatalog const &, Footprint &);
380 
381 private:
382  friend class FootprintMerge;
383 
385  PeakCatalog _peaks;
386  lsst::geom::Box2I _region;
387 };
388 
394 std::shared_ptr<Footprint> mergeFootprints(Footprint const &footprint1, Footprint const &footprint2);
395 
405 } // namespace detection
406 } // namespace afw
407 } // namespace lsst
408 
409 #endif // LSST_DETECTION_FOOTPRINT_H
lsst::afw::detection::Footprint::getBBox
lsst::geom::Box2I getBBox() const
Return the Footprint's bounding box.
Definition: Footprint.h:208
lsst::afw::detection::Footprint::operator==
bool operator==(Footprint const &other) const
equality operator
Definition: Footprint.cc:162
std::string
STL class.
std::shared_ptr< geom::SpanSet >
Persistable.h
lsst::afw::detection::Footprint::getPersistenceName
std::string getPersistenceName() const override
Return the name correspoinging ot the persistence type.
Definition: Footprint.cc:255
lsst::afw::detection::Footprint::getPeaks
PeakCatalog & getPeaks()
Return the Peaks contained in this Footprint.
Definition: Footprint.h:129
lsst::afw::detection::Footprint::dilate
void dilate(int r, geom::Stencil s=geom::Stencil::CIRCLE)
Dilate the Footprint with a defined kernel.
Definition: Footprint.cc:122
lsst::afw::detection::Footprint::getShape
geom::ellipses::Quadrupole getShape() const
Return the Footprint's shape (interpreted as an ellipse)
Definition: Footprint.h:188
Box.h
MaskedImage.h
std::vector
STL class.
lsst::geom::LinearTransform
A 2D linear coordinate transformation.
Definition: LinearTransform.h:69
lsst::afw::detection::Footprint::readSpanSet
static std::unique_ptr< Footprint > readSpanSet(afw::table::BaseCatalog const &, afw::table::io::InputArchive const &)
Static method used to unpersist the SpanSet member of the Footprint class.
Definition: Footprint.cc:272
lsst::afw
Definition: imageAlgorithm.dox:1
lsst::afw::table::io::InputArchive
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
lsst::afw::detection::Footprint::Footprint
Footprint()
Constructor of a empty Footprint object.
Definition: Footprint.h:96
lsst::afw::detection::Footprint::getSpans
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition: Footprint.h:115
ellipses.h
lsst::afw::detection::Footprint::setRegion
void setRegion(lsst::geom::Box2I const &region)
Set the corners of the MaskedImage wherein the footprints dwell.
Definition: Footprint.h:220
lsst::afw::detection::Footprint::shift
void shift(int dx, int dy)
Shift a Footprint by (dx, dy)
Definition: Footprint.cc:64
lsst::afw::detection::Footprint::operator=
Footprint & operator=(Footprint const &other)=default
fwd.h
SkyWcs.h
lsst::afw::table::Schema
Defines the fields and offsets for a table.
Definition: Schema.h:50
lsst::afw::detection::Footprint::getRegion
lsst::geom::Box2I getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:213
lsst::afw::detection::FootprintMerge
Definition: FootprintMerge.cc:34
lsst::afw::detection::Footprint::getCentroid
lsst::geom::Point2D getCentroid() const
Return the Footprint's centroid.
Definition: Footprint.h:180
lsst::geom::AffineTransform
An affine coordinate transformation consisting of a linear transformation and an offset.
Definition: AffineTransform.h:75
lsst::afw::detection::Footprint::getPythonModule
std::string getPythonModule() const override
Return the python module the object will live in.
Definition: Footprint.h:362
lsst::afw::detection::Footprint::sortPeaks
void sortPeaks(afw::table::Key< float > const &key=afw::table::Key< float >())
Sort Peaks from most positive value to most negative.
Definition: Footprint.cc:57
lsst::afw::detection::Footprint::contains
bool contains(lsst::geom::Point2I const &pix) const
Tests if a pixel postion falls inside the Footprint.
Definition: Footprint.cc:79
lsst::afw::detection::Footprint::removeOrphanPeaks
void removeOrphanPeaks()
Remove peaks from the PeakCatalog that fall outside the area of the Footprint.
Definition: Footprint.cc:136
lsst::afw::geom::SpanSet
A compact representation of a collection of pixels.
Definition: SpanSet.h:78
ast::detail::source
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
lsst::afw::detection::Footprint::Footprint
Footprint(Footprint &&)=default
lsst::afw::detection::Footprint::setPeakCatalog
void setPeakCatalog(PeakCatalog const &otherPeaks)
Set the peakCatalog to a copy of the supplied catalog.
Definition: Footprint.cc:419
base.h
lsst::afw::detection::footprintToBBoxList
std::vector< lsst::geom::Box2I > footprintToBBoxList(Footprint const &footprint)
Return a list of BBoxs, whose union contains exactly the pixels in the footprint, neither more nor le...
Definition: Footprint.cc:352
lsst::afw::detection::Footprint::write
void write(OutputArchiveHandle &handle) const override
Write an instance of a Footprint to an output Archive.
Definition: Footprint.cc:257
lsst::afw::detection::Footprint::readPeaks
static void readPeaks(afw::table::BaseCatalog const &, Footprint &)
Static method used to unpersist the PeakCatalog member of the Footprint class.
Definition: Footprint.cc:296
other
ItemVariant const * other
Definition: Schema.cc:56
lsst::afw::detection::Footprint::setSpans
void setSpans(std::shared_ptr< geom::SpanSet > otherSpanSet)
Sets the shared pointer to the SpanSet in the Footprint.
Definition: Footprint.cc:45
Span.h
lsst::afw::detection::Footprint::shift
void shift(lsst::geom::ExtentI const &d)
Shift a Footprint by a given extent.
Definition: Footprint.h:203
lsst::afw::geom::TransformPoint2ToPoint2
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition: Transform.h:300
lsst::afw::table::Key< float >
LinearTransform.h
Transform.h
lsst::afw::detection::Footprint::erode
void erode(int r, geom::Stencil s=geom::Stencil::CIRCLE)
Erode the Footprint with a defined kernel.
Definition: Footprint.cc:126
lsst::afw::detection::Footprint::getPeaks
const PeakCatalog & getPeaks() const
Definition: Footprint.h:130
lsst::afw::detection::Footprint::isHeavy
virtual bool isHeavy() const
Indicates if this object is a HeavyFootprint.
Definition: Footprint.h:111
lsst::afw::detection::FootprintFactory
Definition: Footprint.cc:232
lsst::afw::geom::Stencil::CIRCLE
@ CIRCLE
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
SpanSet.h
target
Key< Flag > const & target
Definition: BaseColumnView.cc:20
lsst::afw::detection::Footprint::getArea
std::size_t getArea() const
Return the number of pixels in this Footprint.
Definition: Footprint.h:173
lsst::afw::geom::ellipses::Quadrupole
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
lsst::geom
Definition: AffineTransform.h:36
lsst::afw::table::io::Persistable
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
Key.h
Peak.h
lsst::afw::detection::Footprint::addPeak
std::shared_ptr< PeakRecord > addPeak(float fx, float fy, float value)
Convenience function to add a peak.
Definition: Footprint.cc:47
lsst::afw::detection::Footprint::setPeakSchema
void setPeakSchema(afw::table::Schema const &peakSchema)
Set the Schema used by the PeakCatalog (will throw if PeakCatalog is not empty).
Definition: Footprint.cc:415
lsst::afw::detection::mergeFootprints
std::shared_ptr< Footprint > mergeFootprints(Footprint const &footprint1, Footprint const &footprint2)
Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint.
Definition: Footprint.cc:327
std
STL namespace.
lsst::afw::detection::Footprint::clipTo
void clipTo(lsst::geom::Box2I const &bbox)
Clip the Footprint such that all values lie inside the supplied Bounding Box.
Definition: Footprint.cc:74
key
Key< U > key
Definition: Schema.cc:281
lsst::geom::Point< double, 2 >
lsst::afw::detection::Footprint::Footprint
Footprint(Footprint const &other)=default
lsst::afw::table::io::PersistableFacade
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
lsst::geom::Box2I
An integer coordinate rectangle.
Definition: Box.h:55
lsst::afw::detection::Footprint::~Footprint
~Footprint() override=default
lsst::afw::detection::PeakTable
Table class for Peaks in Footprints.
Definition: Peak.h:102
lsst::afw::detection::Footprint::operator=
Footprint & operator=(Footprint &&)=default
InputArchive.h
std::size_t
Schema.h
lsst::afw::detection::Footprint::isPersistable
bool isPersistable() const noexcept override
Report if this object is persistable.
Definition: Footprint.h:283
lsst::afw::detection::Footprint
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:63
lsst::afw::detection::Footprint::isContiguous
bool isContiguous() const
Reports if the Footprint is simply connected or has multiple components.
Definition: Footprint.h:335
std::unique_ptr
STL class.
lsst::afw::detection::Footprint::transform
std::shared_ptr< Footprint > transform(std::shared_ptr< geom::SkyWcs > source, std::shared_ptr< geom::SkyWcs > target, lsst::geom::Box2I const &region, bool doClip=true) const
Transform the footprint from one WCS to another.
Definition: Footprint.cc:81
lsst::afw::table::io::Persistable::OutputArchiveHandle
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
lsst::afw::table::CatalogT< PeakRecord >
lsst::geom::Extent< int, 2 >
lsst::afw::geom::Stencil
Stencil
An enumeration class which describes the shapes.
Definition: SpanSet.h:66
bbox
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
lsst::afw::detection::Footprint::split
std::vector< std::shared_ptr< Footprint > > split() const
Split a multi-component Footprint into a vector of contiguous Footprints.
Definition: Footprint.cc:145