LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
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 boost { namespace serialization {
50  class access;
51 }}
52 
53 #ifndef SWIG
54 using boost::serialization::make_nvp;
55 #endif
56 
57 namespace lsst { namespace afw { namespace detection {
58 
59 using geom::Span;
60 
61 /************************************************************************************************************/
71  public afw::table::io::PersistableFacade<lsst::afw::detection::Footprint>,
73 {
74 public:
75  typedef boost::shared_ptr<Footprint> Ptr;
76  typedef boost::shared_ptr<const Footprint> ConstPtr;
77 
79  typedef std::vector<Span::Ptr> SpanList;
80  typedef std::vector<Peak::Ptr> PeakList;
81 
90  explicit Footprint(int nspan = 0, geom::Box2I const & region=geom::Box2I());
91 
95  explicit Footprint(geom::Box2I const & bbox, geom::Box2I const & region=geom::Box2I());
96  Footprint(geom::Point2I const & center, double const radius, geom::Box2I const & = geom::Box2I());
97  explicit Footprint(geom::ellipses::Ellipse const & ellipse, geom::Box2I const & region=geom::Box2I());
98 
99  explicit Footprint(SpanList const & spans, geom::Box2I const & region=geom::Box2I());
100 
105  Footprint(Footprint const & other);
106 
107  virtual ~Footprint();
108 
112  virtual bool isHeavy() const { return false; }
113 
115  int getId() const { return _fid; }
116 
118  SpanList& getSpans() { return _spans; }
119 
121  const SpanList& getSpans() const { return _spans; }
122 
129  PeakList & getPeaks() { return _peaks; }
130  const PeakList & getPeaks() const { return _peaks; }
131 
136  int getNpix() const { return _area; }
137 
138  int getArea() const { return _area; }
139 
145  geom::Point2D getCentroid() const;
146 
154 
158  const Span& addSpan(const int y, const int x0, const int x1);
162  const Span& addSpan(Span const& span);
166  const Span& addSpan(Span const& span, int dx, int dy);
167 
179  const Span& addSpanInSeries(const int y, const int x0, const int x1);
180 
187  void shift(int dx, int dy);
188  void shift(geom::ExtentI d) {shift(d.getX(), d.getY());}
189 
191  geom::Box2I getBBox() const { return _bbox; }
193  geom::Box2I & getBBox() { return _bbox; }
195  geom::Box2I const & getRegion() const { return _region; }
196 
198  void setRegion(geom::Box2I const & region) { _region = region; }
199 
200  void clipTo(geom::Box2I const & bbox);
201 
208  template<typename PixelT>
210 
214  bool contains(geom::Point2I const& pix) const;
215 
219  void normalize();
220  bool isNormalized() const {return _normalized;}
221 
230  template<typename PixelT>
231  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
232  boost::uint64_t const id,
233  geom::Box2I const& region=geom::Box2I()
234  ) const;
235 
249  template<typename PixelT>
250  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
251  boost::uint64_t const id,
252  bool const overwriteId, long const idMask,
253  typename std::set<boost::uint64_t> *oldIds,
254  geom::Box2I const& region=geom::Box2I()
255  ) const;
256 
260  Footprint & operator=(Footprint & other);
261 
270  template <typename MaskPixelT>
271  void intersectMask(
272  image::Mask<MaskPixelT> const & mask,
273  MaskPixelT bitmask=~0x0
274  );
275 
286  image::Wcs const & source,
287  image::Wcs const & target,
288  geom::Box2I const & region,
289  bool doClip=true
290  ) const;
291 
300  void include(std::vector<PTR(Footprint)> const & others);
301 
302  bool isPersistable() const { return true; }
303 
304 protected:
305 
306  virtual std::string getPersistenceName() const;
307 
308  virtual std::string getPythonModule() const;
309 
310  virtual void write(OutputArchiveHandle & handle) const;
311 
313  void readSpans(afw::table::BaseCatalog const & spanCat);
315  void readPeaks(afw::table::BaseCatalog const & peakCat);
317 
318  friend class FootprintFactory;
319 
320 private:
322  template <typename Archive>
323  void serialize(Archive & ar, const unsigned int version);
324 
325  static int id;
326  mutable int _fid;
327  int _area;
328 
333  bool _normalized;
334 };
335 
355 void nearestFootprint(std::vector<PTR(Footprint)> const& foots,
358 
366 PTR(Footprint) mergeFootprints(Footprint const& foot1, Footprint const& foot2);
367 
373 
377 PTR(Footprint) shrinkFootprint(Footprint const& foot, int nGrow, bool isotropic);
378 
382 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow, bool isotropic=true);
383 
387 PTR(Footprint) growFootprint(PTR(Footprint) const& foot, int nGrow, bool isotropic=true);
388 
398 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow,
399  bool left, bool right, bool up, bool down);
400 
407 std::vector<lsst::afw::geom::Box2I> footprintToBBoxList(Footprint const& foot);
408 
414 template<typename ImageT>
415 typename ImageT::Pixel setImageFromFootprint(ImageT *image,
416  Footprint const& footprint,
417  typename ImageT::Pixel const value);
418 
424 template<typename ImageT>
425 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
426  CONST_PTR(std::vector<PTR(Footprint)>) footprints,
427  typename ImageT::Pixel const value);
428 
434 template<typename ImageT>
435 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
436  std::vector<PTR(Footprint)> const& footprints,
437  typename ImageT::Pixel const value);
438 
444 template<typename MaskT>
445 MaskT setMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
446  Footprint const& footprint,
447  MaskT const bitmask);
448 
456 template<typename MaskT>
457 MaskT clearMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
458  Footprint const& footprint,
459  MaskT const bitmask);
460 
468 template <typename ImageOrMaskedImageT>
469 void copyWithinFootprint(Footprint const& foot,
470  PTR(ImageOrMaskedImageT) const input,
471  PTR(ImageOrMaskedImageT) output);
472 
473 /************************************************************************************************************/
479 template<typename MaskT>
480 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
481  std::vector<PTR(Footprint)> const& footprints,
482  MaskT const bitmask);
483 
489 template<typename MaskT>
490 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
491  CONST_PTR(std::vector<PTR(Footprint)>) const& footprints,
492  MaskT const bitmask);
493 
508 template<typename MaskT>
510  typename image::Mask<MaskT>::Ptr const& mask,
511  MaskT const bitmask);
512 
513 /************************************************************************************************************/
514 
515 }}} // namespace lsst::afw::detection
516 
517 #endif
int y
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
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:333
#define CONST_PTR(...)
Definition: base.h:47
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.
double dx
Definition: ImageUtils.cc:90
int _area
number of pixels in this Footprint (not the area of the bbox)
Definition: Footprint.h:327
Public header class for ellipse library.
std::vector< Peak::Ptr > PeakList
Definition: Footprint.h:80
void serialize(Archive &ar, const unsigned int version)
const SpanList & getSpans() const
Definition: Footprint.h:121
void clipTo(geom::Box2I const &bbox)
A custom container class for records, based on std::vector.
Definition: Catalog.h:94
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.
friend class boost::serialization::access
Definition: Footprint.h:321
void readSpans(afw::table::BaseCatalog const &spanCat)
Persistence implementation functions made available for derived classes.
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:114
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
geom::Point2D getCentroid() const
boost::shared_ptr< Footprint > Ptr
Definition: Footprint.h:75
#define PTR(...)
Definition: base.h:41
double dy
Definition: ImageUtils.cc:90
boost::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:418
int const x0
Definition: saturated.cc:45
virtual bool isHeavy() const
Definition: Footprint.h:112
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
int d
Definition: KDTree.cc:89
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:195
std::vector< Span::Ptr > SpanList
The Footprint&#39;s Span list.
Definition: Footprint.h:79
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
Definition: Footprint.h:302
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:191
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:188
A set of pixels in an Image.
Definition: Footprint.h:70
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:330
ImageT::Pixel setImageFromFootprint(ImageT *image, Footprint const &footprint, typename ImageT::Pixel const value)
Set all image pixels in a Footprint to a given value.
Support for peaks in images.
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:332
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:329
const PeakList & getPeaks() const
Definition: Footprint.h:130
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:198
PeakList _peaks
the Peaks lying in this footprint
Definition: Footprint.h:331
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:56
geom::Box2I & getBBox()
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:193
boost::shared_ptr< Footprint > mergeFootprints(Footprint const &foot1, Footprint const &foot2)
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
void include(std::vector< boost::shared_ptr< Footprint >> const &others)
Update the Footprint in-place to be the union of itself and all others provided.
boost::shared_ptr< const Footprint > ConstPtr
Definition: Footprint.h:76
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.