LSSTApplications  10.0-2-g4f67435,11.0.rc2+1,11.0.rc2+12,11.0.rc2+3,11.0.rc2+4,11.0.rc2+5,11.0.rc2+6,11.0.rc2+7,11.0.rc2+8
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 <boost/cstdint.hpp>
37 #include <boost/shared_ptr.hpp>
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 boost::shared_ptr<Footprint> Ptr;
68  typedef boost::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  int getNpix() const { return _area; }
153  int 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 
244  template<typename PixelT>
245  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
246  boost::uint64_t const id,
247  geom::Box2I const& region=geom::Box2I()
248  ) const;
249 
263  template<typename PixelT>
264  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
265  boost::uint64_t const id,
266  bool const overwriteId, long const idMask,
267  typename std::set<boost::uint64_t> *oldIds,
268  geom::Box2I const& region=geom::Box2I()
269  ) const;
270 
274  Footprint & operator=(Footprint & other);
275 
284  template <typename MaskPixelT>
285  void intersectMask(
286  image::Mask<MaskPixelT> const & mask,
287  MaskPixelT bitmask=~0x0
288  );
289 
300  image::Wcs const & source,
301  image::Wcs const & target,
302  geom::Box2I const & region,
303  bool doClip=true
304  ) const;
305 
311  PTR(Footprint) findEdgePixels() const;
312 
320  void include(std::vector<PTR(Footprint)> const & children, bool ignoreSelf=false);
321 
322  bool isPersistable() const { return true; }
323 
324 protected:
325 
326  virtual std::string getPersistenceName() const;
327 
328  virtual std::string getPythonModule() const;
329 
330  virtual void write(OutputArchiveHandle & handle) const;
331 
333  void readSpans(afw::table::BaseCatalog const & spanCat);
335  void readPeaks(afw::table::BaseCatalog const & peakCat);
337 
338  friend class FootprintFactory;
339 
340 private:
341 
342  friend class FootprintMerge;
343 
344  static int id;
345  mutable int _fid;
346  int _area;
347 
352  bool _normalized;
353 };
354 
374 void nearestFootprint(std::vector<PTR(Footprint)> const& foots,
377 
385 PTR(Footprint) mergeFootprints(Footprint const& foot1, Footprint const& foot2);
386 
392 
396 PTR(Footprint) shrinkFootprint(Footprint const& foot, int nGrow, bool isotropic);
397 
401 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow, bool isotropic=true);
402 
406 PTR(Footprint) growFootprint(PTR(Footprint) const& foot, int nGrow, bool isotropic=true);
407 
417 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow,
418  bool left, bool right, bool up, bool down);
419 
426 std::vector<lsst::afw::geom::Box2I> footprintToBBoxList(Footprint const& foot);
427 
433 template<typename ImageT>
434 typename ImageT::Pixel setImageFromFootprint(ImageT *image,
435  Footprint const& footprint,
436  typename ImageT::Pixel const value);
437 
443 template<typename ImageT>
444 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
445  CONST_PTR(std::vector<PTR(Footprint)>) footprints,
446  typename ImageT::Pixel const value);
447 
453 template<typename ImageT>
454 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
455  std::vector<PTR(Footprint)> const& footprints,
456  typename ImageT::Pixel const value);
457 
463 template<typename MaskT>
464 MaskT setMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
465  Footprint const& footprint,
466  MaskT const bitmask);
467 
475 template<typename MaskT>
476 MaskT clearMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
477  Footprint const& footprint,
478  MaskT const bitmask);
479 
493 template <typename ImageOrMaskedImageT>
494 void copyWithinFootprint(Footprint const& foot,
495  PTR(ImageOrMaskedImageT) const input,
496  PTR(ImageOrMaskedImageT) output);
497 
498 /************************************************************************************************************/
504 template<typename MaskT>
505 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
506  std::vector<PTR(Footprint)> const& footprints,
507  MaskT const bitmask);
508 
514 template<typename MaskT>
515 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
516  CONST_PTR(std::vector<PTR(Footprint)>) const& footprints,
517  MaskT const bitmask);
518 
533 template<typename MaskT>
535  typename image::Mask<MaskT>::Ptr const& mask,
536  MaskT const bitmask);
537 
538 /************************************************************************************************************/
539 
540 }}} // namespace lsst::afw::detection
541 
542 #endif
int y
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
Defines the fields and offsets for a table.
Definition: Schema.h:46
void nearestFootprint(std::vector< boost::shared_ptr< Footprint >> const &foots, lsst::afw::image::Image< boost::uint16_t >::Ptr argmin, lsst::afw::image::Image< boost::uint16_t >::Ptr dist)
bool _normalized
Are the spans sorted?
Definition: Footprint.h:352
An include file to include the header files for lsst::afw::geom.
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
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.
int _area
number of pixels in this Footprint (not the area of the bbox)
Definition: Footprint.h:346
#define PTR(...)
Definition: base.h:41
Public header class for ellipse library.
const SpanList & getSpans() const
Definition: Footprint.h:115
void clipTo(geom::Box2I const &bbox)
A range of pixels within one row of an Image.
Definition: Span.h:54
const Span & addSpanInSeries(const int y, const int x0, const int x1)
void shift(int dx, int dy)
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.
#define CONST_PTR(...)
Definition: base.h:47
void readSpans(afw::table::BaseCatalog const &spanCat)
Persistence implementation functions made available for derived classes.
PeakCatalog & getPeaks()
Definition: Footprint.h:123
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:114
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
geom::Point2D getCentroid() const
afw::table::CatalogT< PeakRecord > PeakCatalog
Definition: Peak.h:225
boost::shared_ptr< Footprint > Ptr
Definition: Footprint.h:67
boost::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:418
PeakCatalog _peaks
the Peaks lying in this footprint
Definition: Footprint.h:350
boost::shared_ptr< Footprint > findEdgePixels() const
Find edge pixels on the footprint.
const PeakCatalog & getPeaks() const
Definition: Footprint.h:124
int const x0
Definition: saturated.cc:45
virtual bool isHeavy() const
Definition: Footprint.h:106
void sortPeaks(afw::table::Key< float > const &key=afw::table::Key< float >())
An integer coordinate rectangle.
Definition: Box.h:53
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
boost::shared_ptr< Footprint > shrinkFootprint(Footprint const &foot, int nGrow, bool isotropic)
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool isotropic=true)
geom::Box2I const & getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:209
std::vector< Span::Ptr > SpanList
The Footprint&#39;s Span list.
Definition: Footprint.h:71
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Footprint.h:322
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:93
geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:206
An ellipse defined by an arbitrary BaseCore and a center point.
Definition: Ellipse.h:50
virtual void write(OutputArchiveHandle &handle) const
Write the object to one or more catalogs.
geom::ellipses::Quadrupole getShape() const
void intersectMask(image::Mask< MaskPixelT > const &mask, MaskPixelT bitmask=~0x0)
Intersect the Footprint with a Mask.
Footprint(int nspan=0, geom::Box2I const &region=geom::Box2I())
void shift(geom::ExtentI d)
Definition: Footprint.h:203
A set of pixels in an Image.
Definition: Footprint.h:62
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) ...
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...
geom::Box2I _bbox
the Footprint&#39;s bounding box
Definition: Footprint.h:349
ImageT::Pixel setImageFromFootprint(ImageT *image, Footprint const &footprint, typename ImageT::Pixel const value)
Set all image pixels in a Footprint to a given value.
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.
geom::Box2I _region
The corners of the MaskedImage the footprints live in.
Definition: Footprint.h:351
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
std::vector< lsst::afw::geom::Box2I > footprintToBBoxList(Footprint const &foot)
bool contains(geom::Point2I const &pix) const
SpanList _spans
the Spans contained in this Footprint
Definition: Footprint.h:348
const Span & addSpan(const int y, const int x0, const int x1)
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 clipToNonzero(lsst::afw::image::Image< PixelT > const &img)
Implementation of the Class MaskedImage.
void setRegion(geom::Box2I const &region)
Set the corners of the MaskedImage wherein the footprints dwell.
Definition: Footprint.h:212
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
boost::shared_ptr< Footprint > mergeFootprints(Footprint const &foot1, Footprint const &foot2)
Record class that represents a peak in a Footprint.
Definition: Peak.h:40
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
boost::shared_ptr< const Footprint > ConstPtr
Definition: Footprint.h:68
void readPeaks(afw::table::BaseCatalog const &peakCat)
Persistence implementation functions made available for derived classes.
Footprint & operator=(Footprint &other)
void insertIntoImage(typename lsst::afw::image::Image< PixelT > &idImage, boost::uint64_t const id, geom::Box2I const &region=geom::Box2I()) const
virtual std::string getPythonModule() const
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
void copyWithinFootprint(Footprint const &foot, boost::shared_ptr< ImageOrMaskedImageT > const input, boost::shared_ptr< ImageOrMaskedImageT > output)
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.
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