lsst.afw  14.0-25-g0e8fc950e+5
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"
33 #include "lsst/pex/policy/Policy.h"
35 #include "lsst/afw/image/Wcs.h"
37 #include "lsst/afw/geom/Span.h"
38 #include "lsst/afw/geom/SpanSet.h"
39 #include "lsst/afw/geom/Box.h"
40 #include "lsst/afw/geom/ellipses.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, geom::Box2I const & region=geom::Box2I());
82 
91  explicit Footprint(std::shared_ptr<geom::SpanSet> inputSpans, afw::table::Schema const & peakSchema,
92  geom::Box2I const & region=geom::Box2I());
93 
96  explicit Footprint()
97  : lsst::daf::base::Citizen(typeid(this)),
98  _spans(std::make_shared<geom::SpanSet>()),
99  _peaks(PeakTable::makeMinimalSchema()),
100  _region(geom::Box2I()) {}
101 
102  Footprint(Footprint const &other) = default;
103  Footprint(Footprint &&) = default;
104 
105  Footprint &operator=(Footprint const &other) = default;
106  Footprint &operator=(Footprint &&) = default;
107 
108  virtual ~Footprint() {}
109 
112  virtual bool isHeavy() const { return false; }
113 
116  std::shared_ptr<geom::SpanSet> getSpans() const { return _spans; }
117 
122  void setSpans(std::shared_ptr<geom::SpanSet> otherSpanSet);
123 
130  PeakCatalog &getPeaks() { return _peaks; }
131  const PeakCatalog &getPeaks() const { return _peaks; }
132 
139  std::shared_ptr<PeakRecord> addPeak(float fx, float fy, float value);
140 
150 
157  void setPeakSchema(afw::table::Schema const &peakSchema);
158 
167  void setPeakCatalog(PeakCatalog const &otherPeaks);
168 
174  std::size_t getArea() const { return _spans->getArea(); }
175 
181  geom::Point2D getCentroid() const { return _spans->computeCentroid(); }
182 
189  geom::ellipses::Quadrupole getShape() const { return _spans->computeShape(); }
190 
197  void shift(int dx, int dy);
198 
204  void shift(geom::ExtentI const &d) { shift(d.getX(), d.getY()); }
205 
209  geom::Box2I getBBox() const { return _spans->getBBox(); }
210 
214  geom::Box2I getRegion() const { return _region; }
215 
221  void setRegion(geom::Box2I const &region) { _region = region; }
222 
229  void clipTo(geom::Box2I const &bbox);
230 
236  bool contains(geom::Point2I const &pix) const;
237 
248  std::shared_ptr<image::Wcs> target, geom::Box2I const &region,
249  bool doClip = true) const;
250 
259  bool doClip = true) const;
260 
269  bool doClip = true) const;
270 
279  bool doClip = true) const;
280 
284  bool isPersistable() const override { return true; }
285 
295  void dilate(int r, geom::Stencil s = geom::Stencil::CIRCLE);
296 
305  void dilate(geom::SpanSet const &other);
306 
316  void erode(int r, geom::Stencil s = geom::Stencil::CIRCLE);
317 
326  void erode(geom::SpanSet const &other);
327 
331  void removeOrphanPeaks();
332 
336  bool isContiguous() const { return getSpans()->isContiguous(); };
337 
346 
352  bool operator==(Footprint const &other) const;
353 
354 protected:
358  std::string getPersistenceName() const override;
359 
363  inline std::string getPythonModule() const override { return "lsst.afw.detection"; }
364 
368  void write(OutputArchiveHandle &handle) const override;
369 
370  friend class FootprintFactory;
371 
380  static void readPeaks(afw::table::BaseCatalog const &, Footprint &);
381 
382 private:
383  friend class FootprintMerge;
384 
386  PeakCatalog _peaks;
387  geom::Box2I _region;
388 };
389 
395 std::shared_ptr<Footprint> mergeFootprints(Footprint const &footprint1, Footprint const &footprint2);
396 
406 }
407 }
408 } // Close namespace lsst::afw::detection
409 
410 #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:46
geom::Point2D getCentroid() const
Return the Footprint&#39;s centroid.
Definition: Footprint.h:181
Stencil
An enumeration class which describes the shapes.
Definition: SpanSet.h:64
std::vector< std::shared_ptr< Footprint > > split() const
Split a multi-component Footprint into a vector of contiguous Footprints.
Definition: Footprint.cc:137
An object passed to Persistable::write to allow it to persist itself.
A compact representation of a collection of pixels.
Definition: SpanSet.h:75
Table class for Peaks in Footprints.
Definition: Peak.h:86
void setPeakSchema(afw::table::Schema const &peakSchema)
Set the Schema used by the PeakCatalog (will throw if PeakCatalog is not empty).
Definition: Footprint.cc:409
void shift(geom::ExtentI const &d)
Shift a Footprint by a given extent.
Definition: Footprint.h:204
STL namespace.
bool isPersistable() const override
Report if this object is persistable.
Definition: Footprint.h:284
static void readPeaks(afw::table::BaseCatalog const &, Footprint &)
Static method used to unpersist the PeakCatalog member of the Footprint class.
Definition: Footprint.cc:291
Footprint & operator=(Footprint const &other)=default
An integer coordinate rectangle.
Definition: Box.h:55
STL class.
A base class for objects that can be persisted via afw::table::io Archive classes.
Definition: Persistable.h:73
A 2D linear coordinate transformation.
void clipTo(geom::Box2I const &bbox)
Clip the Footprint such that all values lie inside the supplied Bounding Box.
Definition: Footprint.cc:71
std::string getPythonModule() const override
Return the python module the object will live in.
Definition: Footprint.h:363
A base class for image defects.
std::shared_ptr< Footprint > transform(std::shared_ptr< image::Wcs > source, std::shared_ptr< image::Wcs > target, geom::Box2I const &region, bool doClip=true) const
Transform the footprint from one WCS to another.
Definition: Footprint.cc:78
An affine coordinate transformation consisting of a linear transformation and an offset.
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:267
void dilate(int r, geom::Stencil s=geom::Stencil::CIRCLE)
Dilate the Footprint with a defined kernel.
Definition: Footprint.cc:114
std::string getPersistenceName() const override
Return the name correspoinging ot the persistence type.
Definition: Footprint.cc:250
virtual bool isHeavy() const
Indicates if this object is a HeavyFootprint.
Definition: Footprint.h:112
std::size_t getArea() const
Return the number of pixels in this Footprint.
Definition: Footprint.h:174
void setSpans(std::shared_ptr< geom::SpanSet > otherSpanSet)
Sets the shared pointer to the SpanSet in the Footprint.
Definition: Footprint.cc:42
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:321
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:61
void setPeakCatalog(PeakCatalog const &otherPeaks)
Set the peakCatalog to a copy of the supplied catalog.
Definition: Footprint.cc:413
void setRegion(geom::Box2I const &region)
Set the corners of the MaskedImage wherein the footprints dwell.
Definition: Footprint.h:221
geom::ellipses::Quadrupole getShape() const
Return the Footprint&#39;s shape (interpreted as an ellipse)
Definition: Footprint.h:189
STL class.
void write(OutputArchiveHandle &handle) const override
Write an instance of a Footprint to an output Archive.
Definition: Footprint.cc:252
STL class.
bool isContiguous() const
Reports if the Footprint is simply connected or has multiple components.
Definition: Footprint.h:336
geom::Box2I getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:214
Citizen(const std::type_info &)
bool operator==(Footprint const &other) const
equality operator
Definition: Footprint.cc:154
Virtual base class for 2D transforms.
Definition: XYTransform.h:49
const PeakCatalog & getPeaks() const
Definition: Footprint.h:131
std::vector< lsst::afw::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:346
void sortPeaks(afw::table::Key< float > const &key=afw::table::Key< float >())
Sort Peaks from most positive value to most negative.
Definition: Footprint.cc:54
std::shared_ptr< PeakRecord > addPeak(float fx, float fy, float value)
Convenience function to add a peak.
Definition: Footprint.cc:44
std::shared_ptr< geom::SpanSet > getSpans() const
Return a shared pointer to the SpanSet.
Definition: Footprint.h:116
void removeOrphanPeaks()
Remove peaks from the PeakCatalog that fall outside the area of the Footprint.
Definition: Footprint.cc:128
geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:209
A multi-catalog archive object used to load table::io::Persistable objects.
Definition: InputArchive.h:31
void erode(int r, geom::Stencil s=geom::Stencil::CIRCLE)
Erode the Footprint with a defined kernel.
Definition: Footprint.cc:118
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:173
PeakCatalog & getPeaks()
Return the Peaks contained in this Footprint.
Definition: Footprint.h:130
bool contains(geom::Point2I const &pix) const
Tests if a pixel postion falls inside the Footprint.
Definition: Footprint.cc:76
Footprint()
Constructor of a empty Footprint object.
Definition: Footprint.h:96