LSSTApplications  11.0-13-gbb96280,12.1+18,12.1+7,12.1-1-g14f38d3+72,12.1-1-g16c0db7+5,12.1-1-g5961e7a+84,12.1-1-ge22e12b+23,12.1-11-g06625e2+4,12.1-11-g0d7f63b+4,12.1-19-gd507bfc,12.1-2-g7dda0ab+38,12.1-2-gc0bc6ab+81,12.1-21-g6ffe579+2,12.1-21-gbdb6c2a+4,12.1-24-g941c398+5,12.1-3-g57f6835+7,12.1-3-gf0736f3,12.1-37-g3ddd237,12.1-4-gf46015e+5,12.1-5-g06c326c+20,12.1-5-g648ee80+3,12.1-5-gc2189d7+4,12.1-6-ga608fc0+1,12.1-7-g3349e2a+5,12.1-7-gfd75620+9,12.1-9-g577b946+5,12.1-9-gc4df26a+10
LSSTDataManagementBasePackage
Footprint.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2015 LSST Corporation.
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 <http://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #if !defined(LSST_DETECTION_FOOTPRINT_H)
24 #define LSST_DETECTION_FOOTPRINT_H
25 
32 #include <algorithm>
33 #include <list>
34 #include <set>
35 #include <cmath>
36 #include <cstdint>
37 #include <memory>
38 #include "ndarray.h"
39 #include "lsst/base.h"
40 #include "lsst/pex/policy/Policy.h"
42 #include "lsst/afw/image/Wcs.h"
44 #include "lsst/afw/geom.h"
45 #include "lsst/afw/geom/ellipses.h"
46 #include "lsst/afw/table/fwd.h"
48 
49 namespace lsst { namespace afw { namespace detection {
50 
51 using geom::Span;
52 
53 /************************************************************************************************************/
63  public afw::table::io::PersistableFacade<lsst::afw::detection::Footprint>,
65 {
66 public:
67  typedef std::shared_ptr<Footprint> Ptr;
68  typedef std::shared_ptr<const Footprint> ConstPtr;
69 
71  typedef std::vector<Span::Ptr> SpanList;
72 
81  explicit Footprint(int nspan = 0, geom::Box2I const & region=geom::Box2I());
82 
86  explicit Footprint(afw::table::Schema const & peakSchema, int nspan=0,
87  geom::Box2I const & region=geom::Box2I());
88 
89  explicit Footprint(geom::Box2I const & bbox, geom::Box2I const & region=geom::Box2I());
90  Footprint(geom::Point2I const & center, double const radius, geom::Box2I const & = geom::Box2I());
91  explicit Footprint(geom::ellipses::Ellipse const & ellipse, geom::Box2I const & region=geom::Box2I());
92 
93  explicit Footprint(SpanList const & spans, geom::Box2I const & region=geom::Box2I());
94 
99  Footprint(Footprint const & other);
100 
101  virtual ~Footprint();
102 
106  virtual bool isHeavy() const { return false; }
107 
109  int getId() const { return _fid; }
110 
112  SpanList& getSpans() { return _spans; }
113 
115  const SpanList& getSpans() const { return _spans; }
116 
123  PeakCatalog & getPeaks() { return _peaks; }
124  const PeakCatalog & getPeaks() const { return _peaks; }
125 
127  PTR(PeakRecord) addPeak(float fx, float fy, float value);
128 
134  void sortPeaks(afw::table::Key<float> const & key=afw::table::Key<float>());
135 
137  void setPeakSchema(afw::table::Schema const & peakSchema) {
138  if (!getPeaks().empty()) {
139  throw LSST_EXCEPT(
140  pex::exceptions::LogicError,
141  "Cannot change the PeakCatalog schema unless it is empty"
142  );
143  }
144  // this syntax doesn't work in Python, which is why this method has to exist
145  getPeaks() = PeakCatalog(peakSchema);
146  }
147 
152  size_t getNpix() const { return _area; }
153  size_t getArea() const { return _area; }
154 
160  geom::Point2D getCentroid() const;
161 
169 
173  const Span& addSpan(const int y, const int x0, const int x1);
177  const Span& addSpan(Span const& span);
181  const Span& addSpan(Span const& span, int dx, int dy);
182 
194  const Span& addSpanInSeries(const int y, const int x0, const int x1);
195 
202  void shift(int dx, int dy);
203  void shift(geom::ExtentI d) {shift(d.getX(), d.getY());}
204 
206  geom::Box2I getBBox() const { return _bbox; }
207 
209  geom::Box2I const & getRegion() const { return _region; }
210 
212  void setRegion(geom::Box2I const & region) { _region = region; }
213 
214  void clipTo(geom::Box2I const & bbox);
215 
222  template<typename PixelT>
224 
228  bool contains(geom::Point2I const& pix) const;
229 
233  void normalize();
234  bool isNormalized() const {return _normalized;}
235 
241  template<typename MaskT>
242  MaskT overlapsMask(typename image::Mask<MaskT> const& mask
243  ) const;
244 
253  template<typename PixelT>
254  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
255  std::uint64_t const id,
256  geom::Box2I const& region=geom::Box2I()
257  ) const;
258 
272  template<typename PixelT>
273  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
274  std::uint64_t const id,
275  bool const overwriteId, long const idMask,
276  typename std::set<std::uint64_t> *oldIds,
277  geom::Box2I const& region=geom::Box2I()
278  ) const;
279 
283  Footprint & operator=(Footprint & other);
284 
293  template <typename MaskPixelT>
294  void intersectMask(
295  image::Mask<MaskPixelT> const & mask,
296  MaskPixelT bitmask=~0x0
297  );
298 
309  image::Wcs const & source,
310  image::Wcs const & target,
311  geom::Box2I const & region,
312  bool doClip=true
313  ) const;
314 
320  PTR(Footprint) findEdgePixels() const;
321 
329  void include(std::vector<PTR(Footprint)> const & children, bool ignoreSelf=false);
330 
331  bool isPersistable() const { return true; }
332 
333 protected:
334 
335  virtual std::string getPersistenceName() const;
336 
337  virtual std::string getPythonModule() const;
338 
339  virtual void write(OutputArchiveHandle & handle) const;
340 
342  void readSpans(afw::table::BaseCatalog const & spanCat);
344  void readPeaks(afw::table::BaseCatalog const & peakCat);
346 
347  friend class FootprintFactory;
348 
349 private:
350 
351  friend class FootprintMerge;
352 
353  static int id;
354  mutable int _fid;
355  size_t _area;
356 
361  bool _normalized;
362 };
363 
383 void nearestFootprint(std::vector<PTR(Footprint)> const& foots,
386 
394 PTR(Footprint) mergeFootprints(Footprint const& foot1, Footprint const& foot2);
395 
401 
405 PTR(Footprint) shrinkFootprint(Footprint const& foot, int nGrow, bool isotropic);
406 
410 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow, bool isotropic=true);
411 
415 PTR(Footprint) growFootprint(PTR(Footprint) const& foot, int nGrow, bool isotropic=true);
416 
426 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow,
427  bool left, bool right, bool up, bool down);
428 
435 std::vector<lsst::afw::geom::Box2I> footprintToBBoxList(Footprint const& foot);
436 
442 template<typename ImageT>
443 typename ImageT::Pixel setImageFromFootprint(ImageT *image,
444  Footprint const& footprint,
445  typename ImageT::Pixel const value);
446 
452 template<typename ImageT>
453 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
454  CONST_PTR(std::vector<PTR(Footprint)>) footprints,
455  typename ImageT::Pixel const value);
456 
462 template<typename ImageT>
463 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
464  std::vector<PTR(Footprint)> const& footprints,
465  typename ImageT::Pixel const value);
466 
472 template<typename MaskT>
473 MaskT setMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
474  Footprint const& footprint,
475  MaskT const bitmask);
476 
484 template<typename MaskT>
485 MaskT clearMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
486  Footprint const& footprint,
487  MaskT const bitmask);
488 
502 template <typename ImageOrMaskedImageT>
503 void copyWithinFootprint(Footprint const& foot,
504  PTR(ImageOrMaskedImageT) const input,
505  PTR(ImageOrMaskedImageT) output);
506 
507 /************************************************************************************************************/
513 template<typename MaskT>
514 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
515  std::vector<PTR(Footprint)> const& footprints,
516  MaskT const bitmask);
517 
523 template<typename MaskT>
524 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
525  CONST_PTR(std::vector<PTR(Footprint)>) const& footprints,
526  MaskT const bitmask);
527 
542 template<typename MaskT>
544  typename image::Mask<MaskT>::Ptr const& mask,
545  MaskT const bitmask);
546 
547 /************************************************************************************************************/
548 
549 }}} // namespace lsst::afw::detection
550 
551 #endif
std::vector< Span::Ptr > SpanList
The Footprint&#39;s Span list.
Definition: Footprint.h:71
int y
Footprint(int nspan=0, geom::Box2I const &region=geom::Box2I())
Create a Footprint.
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
const SpanList & getSpans() const
Return the Spans contained in this Footprint.
Definition: Footprint.h:115
Defines the fields and offsets for a table.
Definition: Schema.h:44
const Span & addSpanInSeries(const int y, const int x0, const int x1)
Add a Span to a Footprint, where the Spans MUST be added in order (first in increasing y...
virtual bool isHeavy() const
Is this a HeavyFootprint?
Definition: Footprint.h:106
void readPeaks(afw::table::BaseCatalog const &peakCat)
Persistence implementation functions made available for derived classes.
const Span & addSpan(const int y, const int x0, const int x1)
Add a Span to a footprint, returning a reference to the new Span.
An include file to include the header files for lsst::afw::geom.
Public header class for ellipse library.
A range of pixels within one row of an Image.
Definition: Span.h:54
geom::Point2D getCentroid() const
Return the Footprint&#39;s centroid.
boost::shared_ptr< Footprint > footprintAndMask(boost::shared_ptr< Footprint > const &foot, typename image::Mask< MaskT >::Ptr const &mask, MaskT const bitmask)
Return a Footprint that&#39;s the intersection of a Footprint with a Mask.
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void setPeakSchema(afw::table::Schema const &peakSchema)
Set the Schema used by the PeakCatalog (will throw if PeakCatalog is not empty).
Definition: Footprint.h:137
const PeakCatalog & getPeaks() const
Definition: Footprint.h:124
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:112
std::shared_ptr< Footprint > Ptr
Definition: Footprint.h:67
void include(std::vector< boost::shared_ptr< Footprint >> const &children, bool ignoreSelf=false)
Update the Footprint in-place to be the union of itself and all others provided.
PeakCatalog _peaks
the Peaks lying in this footprint
Definition: Footprint.h:359
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
Forward declarations and typedefs for afw::table.
std::shared_ptr< const Footprint > ConstPtr
Definition: Footprint.h:68
Footprint & operator=(Footprint &other)
Assignment operator.
int const x0
Definition: saturated.cc:45
An integer coordinate rectangle.
Definition: Box.h:53
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
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:72
boost::shared_ptr< Footprint > shrinkFootprint(Footprint const &foot, int nGrow, bool isotropic)
Shrink a footprint isotropically by nGrow pixels, returning a new Footprint.
void clipTo(geom::Box2I const &bbox)
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool isotropic=true)
Grow a Footprint by nGrow pixels, returning a new Footprint.
afw::table::CatalogT< PeakRecord > PeakCatalog
Definition: Peak.h:225
void shift(geom::ExtentI d)
Definition: Footprint.h:203
geom::Box2I _region
The corners of the MaskedImage the footprints live in.
Definition: Footprint.h:360
geom::ellipses::Quadrupole getShape() const
Return the Footprint&#39;s shape (interpreted as an ellipse)
std::map< Citizen const *, CitizenInfo > table
Definition: Citizen.h:90
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:50
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Footprint.h:331
std::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:419
SpanList _spans
the Spans contained in this Footprint
Definition: Footprint.h:357
boost::shared_ptr< PeakRecord > addPeak(float fx, float fy, float value)
Convenience function to add a peak (since that&#39;d now be multiple lines without this function) ...
size_t _area
number of pixels in this Footprint (not the area of the bbox)
Definition: Footprint.h:355
A set of pixels in an Image.
Definition: Footprint.h:62
void shift(int dx, int dy)
Shift a Footprint by (dx, dy)
MaskT clearMaskFromFootprint(lsst::afw::image::Mask< MaskT > *mask, Footprint const &footprint, MaskT const bitmask)
(AND ~bitmask) all the Mask&#39;s pixels that are in the Footprint; that is, set to zero in the Mask-inte...
boost::shared_ptr< Footprint > transform(image::Wcs const &source, image::Wcs const &target, geom::Box2I const &region, bool doClip=true) const
Transform the footprint from one WCS to another.
void intersectMask(image::Mask< MaskPixelT > const &mask, MaskPixelT bitmask=~0x0)
Intersect the Footprint with a Mask.
void setRegion(geom::Box2I const &region)
Set the corners of the MaskedImage wherein the footprints dwell.
Definition: Footprint.h:212
ImageT::Pixel setImageFromFootprint(ImageT *image, Footprint const &footprint, typename ImageT::Pixel const value)
Set all image pixels in a Footprint to a given value.
size_t getNpix() const
Return the number of pixels in this Footprint (the real number of pixels, not the area of the bbox)...
Definition: Footprint.h:152
MaskT overlapsMask(typename image::Mask< MaskT > const &mask) const
Find the mask bit in the Mask that fall in the Footprint.
bool contains(geom::Point2I const &pix) const
Does this Footprint contain this pixel?
#define LSST_EXCEPT(type,...)
Create an exception with a given type and message and optionally other arguments (dependent on the ty...
Definition: Exception.h:46
std::vector< lsst::afw::geom::Box2I > footprintToBBoxList(Footprint const &foot)
Return a list of BBoxs, whose union contains exactly the pixels in foot, neither more nor less...
SpanList & getSpans()
Return the Spans contained in this Footprint.
Definition: Footprint.h:112
int getId() const
Return the Footprint&#39;s unique ID.
Definition: Footprint.h:109
void readSpans(afw::table::BaseCatalog const &spanCat)
Persistence implementation functions made available for derived classes.
geom::Box2I _bbox
the Footprint&#39;s bounding box
Definition: Footprint.h:358
#define PTR(...)
Definition: base.h:41
MaskT setMaskFromFootprint(lsst::afw::image::Mask< MaskT > *mask, Footprint const &footprint, MaskT const bitmask)
OR bitmask into all the Mask&#39;s pixels that are in the Footprint.
void normalize()
Normalise a Footprint, sorting spans and setting the BBox.
void sortPeaks(afw::table::Key< float > const &key=afw::table::Key< float >())
Sort Peaks from most positive value to most negative.
metadata input
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
Implementation of the Class MaskedImage.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:53
#define CONST_PTR(...)
A shared pointer to a const object.
Definition: base.h:47
boost::shared_ptr< Footprint > mergeFootprints(Footprint const &foot1, Footprint const &foot2)
Merges two Footprints – appends their peaks, and unions their spans, returning a new Footprint...
boost::shared_ptr< Footprint > findEdgePixels() const
Find edge pixels on the footprint.
Basic LSST definitions.
Record class that represents a peak in a Footprint.
Definition: Peak.h:40
bool _normalized
Are the spans sorted?
Definition: Footprint.h:361
void nearestFootprint(std::vector< boost::shared_ptr< Footprint >> const &foots, lsst::afw::image::Image< std::uint16_t >::Ptr argmin, lsst::afw::image::Image< std::uint16_t >::Ptr dist)
Given a vector of Footprints, fills the output &quot;argmin&quot; and &quot;dist&quot; images to contain the Manhattan di...
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:180
PeakCatalog & getPeaks()
Return the Peaks contained in this Footprint.
Definition: Footprint.h:123
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:416
geom::Box2I const & getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:209
void copyWithinFootprint(Footprint const &foot, boost::shared_ptr< ImageOrMaskedImageT > const input, boost::shared_ptr< ImageOrMaskedImageT > output)
Copies pixels from input image to output image within the Footprint&#39;s area.
ImageT::Pixel setImageFromFootprintList(ImageT *image, boost::shared_ptr< std::vector< boost::shared_ptr< Footprint >> const > footprints, typename ImageT::Pixel const value)
Set all image pixels in a set of Footprints to a given value.
MaskT setMaskFromFootprintList(lsst::afw::image::Mask< MaskT > *mask, std::vector< boost::shared_ptr< Footprint >> const &footprints, MaskT const bitmask)
OR bitmask into all the Mask&#39;s pixels which are in the set of Footprints.
geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:206
void clipToNonzero(lsst::afw::image::Image< PixelT > const &img)
Clips the given Footprint to the region in the Image containing non-zero values.
void insertIntoImage(typename lsst::afw::image::Image< PixelT > &idImage, std::uint64_t const id, geom::Box2I const &region=geom::Box2I()) const
Set the pixels in idImage that are in Footprint by adding the specified value to the Image...