LSSTApplications  17.0+11,17.0+34,17.0+56,17.0+57,17.0+59,17.0+7,17.0-1-g377950a+33,17.0.1-1-g114240f+2,17.0.1-1-g4d4fbc4+28,17.0.1-1-g55520dc+49,17.0.1-1-g5f4ed7e+52,17.0.1-1-g6dd7d69+17,17.0.1-1-g8de6c91+11,17.0.1-1-gb9095d2+7,17.0.1-1-ge9fec5e+5,17.0.1-1-gf4e0155+55,17.0.1-1-gfc65f5f+50,17.0.1-1-gfc6fb1f+20,17.0.1-10-g87f9f3f+1,17.0.1-11-ge9de802+16,17.0.1-16-ga14f7d5c+4,17.0.1-17-gc79d625+1,17.0.1-17-gdae4c4a+8,17.0.1-2-g26618f5+29,17.0.1-2-g54f2ebc+9,17.0.1-2-gf403422+1,17.0.1-20-g2ca2f74+6,17.0.1-23-gf3eadeb7+1,17.0.1-3-g7e86b59+39,17.0.1-3-gb5ca14a,17.0.1-3-gd08d533+40,17.0.1-30-g596af8797,17.0.1-4-g59d126d+4,17.0.1-4-gc69c472+5,17.0.1-6-g5afd9b9+4,17.0.1-7-g35889ee+1,17.0.1-7-gc7c8782+18,17.0.1-9-gc4bbfb2+3,w.2019.22
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 
63  public afw::table::io::PersistableFacade<lsst::afw::detection::Footprint>,
65 public:
66  /*
67  * As a note there is no constructor which accepts a unique_ptr to a SpanSet.
68  * If someone did have a unique_ptr to a SpanSet it is possible to wrap the
69  * unique_ptr in a std::move when calling the constructor of a Footprint and
70  * the compiler will implicitly turn the unique_ptr into a shared_ptr and use
71  * that to construct the Footprint.
72  */
73 
81  explicit Footprint(std::shared_ptr<geom::SpanSet> inputSpans,
83 
92  explicit Footprint(std::shared_ptr<geom::SpanSet> inputSpans, afw::table::Schema const &peakSchema,
94 
97  explicit Footprint()
98  : lsst::daf::base::Citizen(typeid(this)),
99  _spans(std::make_shared<geom::SpanSet>()),
100  _peaks(PeakTable::makeMinimalSchema()),
101  _region(lsst::geom::Box2I()) {}
102 
103  Footprint(Footprint const &other) = default;
104  Footprint(Footprint &&) = default;
105 
106  Footprint &operator=(Footprint const &other) = default;
107  Footprint &operator=(Footprint &&) = default;
108 
109  ~Footprint() override = default;
110 
113  virtual bool isHeavy() const { return false; }
114 
117  std::shared_ptr<geom::SpanSet> getSpans() const { return _spans; }
118 
123  void setSpans(std::shared_ptr<geom::SpanSet> otherSpanSet);
124 
131  PeakCatalog &getPeaks() { return _peaks; }
132  const PeakCatalog &getPeaks() const { return _peaks; }
133 
140  std::shared_ptr<PeakRecord> addPeak(float fx, float fy, float value);
141 
151 
158  void setPeakSchema(afw::table::Schema const &peakSchema);
159 
168  void setPeakCatalog(PeakCatalog const &otherPeaks);
169 
175  std::size_t getArea() const { return _spans->getArea(); }
176 
182  lsst::geom::Point2D getCentroid() const { return _spans->computeCentroid(); }
183 
190  geom::ellipses::Quadrupole getShape() const { return _spans->computeShape(); }
191 
198  void shift(int dx, int dy);
199 
205  void shift(lsst::geom::ExtentI const &d) { shift(d.getX(), d.getY()); }
206 
210  lsst::geom::Box2I getBBox() const { return _spans->getBBox(); }
211 
215  lsst::geom::Box2I getRegion() const { return _region; }
216 
222  void setRegion(lsst::geom::Box2I const &region) { _region = region; }
223 
230  void clipTo(lsst::geom::Box2I const &bbox);
231 
237  bool contains(lsst::geom::Point2I const &pix) const;
238 
250  lsst::geom::Box2I const &region, bool doClip = true) const;
251 
260  lsst::geom::Box2I const &region, bool doClip = true) const;
261 
270  lsst::geom::Box2I const &region, bool doClip = true) const;
271 
280  lsst::geom::Box2I const &region, bool doClip = true) const;
281 
285  bool isPersistable() const noexcept override { return true; }
286 
297 
306  void dilate(geom::SpanSet const &other);
307 
318 
327  void erode(geom::SpanSet const &other);
328 
332  void removeOrphanPeaks();
333 
337  bool isContiguous() const { return getSpans()->isContiguous(); };
338 
347 
353  bool operator==(Footprint const &other) const;
354 
355 protected:
359  std::string getPersistenceName() const override;
360 
364  inline std::string getPythonModule() const override { return "lsst.afw.detection"; }
365 
369  void write(OutputArchiveHandle &handle) const override;
370 
371  friend class FootprintFactory;
372 
381  static void readPeaks(afw::table::BaseCatalog const &, Footprint &);
382 
383 private:
384  friend class FootprintMerge;
385 
387  PeakCatalog _peaks;
388  lsst::geom::Box2I _region;
389 };
390 
396 std::shared_ptr<Footprint> mergeFootprints(Footprint const &footprint1, Footprint const &footprint2);
397 
407 } // namespace detection
408 } // namespace afw
409 } // namespace lsst
410 
411 #endif // LSST_DETECTION_FOOTPRINT_H
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:47
Defines the fields and offsets for a table.
Definition: Schema.h:50
Stencil
An enumeration class which describes the shapes.
Definition: SpanSet.h:66
bool isPersistable() const noexcept override
Report if this object is persistable.
Definition: Footprint.h:285
std::vector< std::shared_ptr< Footprint > > split() const
Split a multi-component Footprint into a vector of contiguous Footprints.
Definition: Footprint.cc:148
An object passed to Persistable::write to allow it to persist itself.
An affine coordinate transformation consisting of a linear transformation and an offset.
Basic LSST definitions.
A compact representation of a collection of pixels.
Definition: SpanSet.h:77
void setRegion(lsst::geom::Box2I const &region)
Set the corners of the MaskedImage wherein the footprints dwell.
Definition: Footprint.h:222
Table class for Peaks in Footprints.
Definition: Peak.h:102
void setPeakSchema(afw::table::Schema const &peakSchema)
Set the Schema used by the PeakCatalog (will throw if PeakCatalog is not empty).
Definition: Footprint.cc:421
STL namespace.
~Footprint() override=default
static void readPeaks(afw::table::BaseCatalog const &, Footprint &)
Static method used to unpersist the PeakCatalog member of the Footprint class.
Definition: Footprint.cc:302
Footprint & operator=(Footprint const &other)=default
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:74
lsst::geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:210
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:84
std::string getPythonModule() const override
Return the python module the object will live in.
Definition: Footprint.h:364
A base class for image defects.
void clipTo(lsst::geom::Box2I const &bbox)
Clip the Footprint such that all values lie inside the supplied Bounding Box.
Definition: Footprint.cc:77
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:278
void dilate(int r, geom::Stencil s=geom::Stencil::CIRCLE)
Dilate the Footprint with a defined kernel.
Definition: Footprint.cc:125
std::string getPersistenceName() const override
Return the name correspoinging ot the persistence type.
Definition: Footprint.cc:261
virtual bool isHeavy() const
Indicates if this object is a HeavyFootprint.
Definition: Footprint.h:113
std::size_t getArea() const
Return the number of pixels in this Footprint.
Definition: Footprint.h:175
void setSpans(std::shared_ptr< geom::SpanSet > otherSpanSet)
Sets the shared pointer to the SpanSet in the Footprint.
Definition: Footprint.cc:48
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:333
bool contains(lsst::geom::Point2I const &pix) const
Tests if a pixel postion falls inside the Footprint.
Definition: Footprint.cc:82
const char * source()
Source function that allows astChannel to source from a Stream.
Definition: Stream.h:224
table::Box2IKey bbox
Definition: Detector.cc:169
Key< Flag > const & target
solver_t * s
Class to describe the properties of a detected object from an image.
Definition: Footprint.h:62
void shift(int dx, int dy)
Shift a Footprint by (dx, dy)
Definition: Footprint.cc:67
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:358
void setPeakCatalog(PeakCatalog const &otherPeaks)
Set the peakCatalog to a copy of the supplied catalog.
Definition: Footprint.cc:425
geom::ellipses::Quadrupole getShape() const
Return the Footprint&#39;s shape (interpreted as an ellipse)
Definition: Footprint.h:190
STL class.
void write(OutputArchiveHandle &handle) const override
Write an instance of a Footprint to an output Archive.
Definition: Footprint.cc:263
STL class.
bool isContiguous() const
Reports if the Footprint is simply connected or has multiple components.
Definition: Footprint.h:337
Citizen(const std::type_info &)
Definition: Citizen.cc:163
Key< U > key
Definition: Schema.cc:281
bool operator==(Footprint const &other) const
equality operator
Definition: Footprint.cc:165
const PeakCatalog & getPeaks() const
Definition: Footprint.h:132
lsst::geom::Point2D getCentroid() const
Return the Footprint&#39;s centroid.
Definition: Footprint.h:182
void sortPeaks(afw::table::Key< float > const &key=afw::table::Key< float >())
Sort Peaks from most positive value to most negative.
Definition: Footprint.cc:60
std::shared_ptr< PeakRecord > addPeak(float fx, float fy, float value)
Convenience function to add a peak.
Definition: Footprint.cc:50
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition: Footprint.h:117
ItemVariant const * other
Definition: Schema.cc:56
void removeOrphanPeaks()
Remove peaks from the PeakCatalog that fall outside the area of the Footprint.
Definition: Footprint.cc:139
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
void shift(lsst::geom::ExtentI const &d)
Shift a Footprint by a given extent.
Definition: Footprint.h:205
void erode(int r, geom::Stencil s=geom::Stencil::CIRCLE)
Erode the Footprint with a defined kernel.
Definition: Footprint.cc:129
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
PeakCatalog & getPeaks()
Return the Peaks contained in this Footprint.
Definition: Footprint.h:131
An integer coordinate rectangle.
Definition: Box.h:54
lsst::geom::Box2I getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:215
Footprint()
Constructor of a empty Footprint object.
Definition: Footprint.h:97
A 2D linear coordinate transformation.
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint, using an AST mapping.
Definition: Transform.h:67