LSSTApplications  8.0.0.0+107,8.0.0.1+13,9.1+18,9.2,master-g084aeec0a4,master-g0aced2eed8+6,master-g15627eb03c,master-g28afc54ef9,master-g3391ba5ea0,master-g3d0fb8ae5f,master-g4432ae2e89+36,master-g5c3c32f3ec+17,master-g60f1e072bb+1,master-g6a3ac32d1b,master-g76a88a4307+1,master-g7bce1f4e06+57,master-g8ff4092549+31,master-g98e65bf68e,master-ga6b77976b1+53,master-gae20e2b580+3,master-gb584cd3397+53,master-gc5448b162b+1,master-gc54cf9771d,master-gc69578ece6+1,master-gcbf758c456+22,master-gcec1da163f+63,master-gcf15f11bcc,master-gd167108223,master-gf44c96c709
LSSTDataManagementBasePackage
Footprint.h
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008, 2009, 2010 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{
50 namespace serialization{
51  class access;
52 }}
53 
54 #ifndef SWIG
55 using boost::serialization::make_nvp;
56 #endif
57 
58 namespace lsst {
59 namespace afw {
60 namespace detection {
61 
62 using geom::Span;
63 
64 /************************************************************************************************************/
74  public afw::table::io::PersistableFacade<lsst::afw::detection::Footprint>,
76 {
77 public:
78  typedef boost::shared_ptr<Footprint> Ptr;
79  typedef boost::shared_ptr<const Footprint> ConstPtr;
80 
82  typedef std::vector<Span::Ptr> SpanList;
83  typedef std::vector<Peak::Ptr> PeakList;
84 
93  explicit Footprint(int nspan = 0, geom::Box2I const & region=geom::Box2I());
94 
98  explicit Footprint(geom::Box2I const & bbox, geom::Box2I const & region=geom::Box2I());
99  Footprint(geom::Point2I const & center, double const radius, geom::Box2I const & = geom::Box2I());
100  explicit Footprint(geom::ellipses::Ellipse const & ellipse, geom::Box2I const & region=geom::Box2I());
101 
102  explicit Footprint(SpanList const & spans, geom::Box2I const & region=geom::Box2I());
103 
108  Footprint(Footprint const & other);
109 
110  virtual ~Footprint();
111 
115  virtual bool isHeavy() const { return false; }
116 
118  int getId() const { return _fid; }
119 
121  SpanList& getSpans() { return _spans; }
122 
124  const SpanList& getSpans() const { return _spans; }
125 
132  PeakList & getPeaks() { return _peaks; }
133  const PeakList & getPeaks() const { return _peaks; }
134 
139  int getNpix() const { return _area; }
140 
141  int getArea() const { return _area; }
142 
148  geom::Point2D getCentroid() const;
149 
157 
161  const Span& addSpan(const int y, const int x0, const int x1);
165  const Span& addSpan(Span const& span);
169  const Span& addSpan(Span const& span, int dx, int dy);
170 
182  const Span& addSpanInSeries(const int y, const int x0, const int x1);
183 
190  void shift(int dx, int dy);
191  void shift(geom::ExtentI d) {shift(d.getX(), d.getY());}
192 
194  geom::Box2I getBBox() const { return _bbox; }
196  geom::Box2I & getBBox() { return _bbox; }
198  geom::Box2I const & getRegion() const { return _region; }
199 
201  void setRegion(geom::Box2I const & region) { _region = region; }
202 
203  void clipTo(geom::Box2I const & bbox);
204 
211  template<typename PixelT>
213 
217  bool contains(geom::Point2I const& pix) const;
218 
222  void normalize();
223  bool isNormalized() const {return _normalized;}
224 
233  template<typename PixelT>
234  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
235  boost::uint64_t const id,
236  geom::Box2I const& region=geom::Box2I()
237  ) const;
238 
253  template<typename PixelT>
254  void insertIntoImage(typename lsst::afw::image::Image<PixelT>& idImage,
255  boost::uint64_t const id,
256  bool const overwriteId, long const idMask,
257  typename std::set<boost::uint64_t> *oldIds,
258  geom::Box2I const& region=geom::Box2I()
259  ) const;
260 
264  Footprint & operator=(Footprint & other);
265 
274  template <typename MaskPixelT>
275  void intersectMask(
276  image::Mask<MaskPixelT> const & mask,
277  MaskPixelT bitmask=~0x0
278  );
279 
290  image::Wcs const & source,
291  image::Wcs const & target,
292  geom::Box2I const & region,
293  bool doClip=true
294  ) const;
295 
296  bool isPersistable() const { return true; }
297 
298 protected:
299 
300  virtual std::string getPersistenceName() const;
301 
302  virtual std::string getPythonModule() const;
303 
304  virtual void write(OutputArchiveHandle & handle) const;
305 
307  void readSpans(afw::table::BaseCatalog const & spanCat);
309  void readPeaks(afw::table::BaseCatalog const & peakCat);
311 
312  friend class FootprintFactory;
313 
314 private:
316  template <typename Archive>
317  void serialize(Archive & ar, const unsigned int version);
318 
319  static int id;
320  mutable int _fid;
321  int _area;
322 
327  bool _normalized;
328 };
329 
349 void nearestFootprint(std::vector<PTR(Footprint)> const& foots,
352 
360 PTR(Footprint) mergeFootprints(Footprint const& foot1, Footprint const& foot2);
361 
367 
371 PTR(Footprint) shrinkFootprint(Footprint const& foot, int nGrow, bool isotropic);
372 
376 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow, bool isotropic=true);
377 
381 PTR(Footprint) growFootprint(PTR(Footprint) const& foot, int nGrow, bool isotropic=true);
382 
392 PTR(Footprint) growFootprint(Footprint const& foot, int nGrow,
393  bool left, bool right, bool up, bool down);
394 
401 std::vector<lsst::afw::geom::Box2I> footprintToBBoxList(Footprint const& foot);
402 
408 template<typename ImageT>
409 typename ImageT::Pixel setImageFromFootprint(ImageT *image,
410  Footprint const& footprint,
411  typename ImageT::Pixel const value);
412 
418 template<typename ImageT>
419 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
420  CONST_PTR(std::vector<PTR(Footprint)>) footprints,
421  typename ImageT::Pixel const value);
422 
428 template<typename ImageT>
429 typename ImageT::Pixel setImageFromFootprintList(ImageT *image,
430  std::vector<PTR(Footprint)> const& footprints,
431  typename ImageT::Pixel const value);
432 
438 template<typename MaskT>
439 MaskT setMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
440  Footprint const& footprint,
441  MaskT const bitmask);
442 
450 template<typename MaskT>
451 MaskT clearMaskFromFootprint(lsst::afw::image::Mask<MaskT> *mask,
452  Footprint const& footprint,
453  MaskT const bitmask);
454 
462 template <typename ImageOrMaskedImageT>
463 void copyWithinFootprint(Footprint const& foot,
464  PTR(ImageOrMaskedImageT) const input,
465  PTR(ImageOrMaskedImageT) output);
466 
467 /************************************************************************************************************/
473 template<typename MaskT>
474 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
475  std::vector<PTR(Footprint)> const& footprints,
476  MaskT const bitmask);
477 
483 template<typename MaskT>
484 MaskT setMaskFromFootprintList(lsst::afw::image::Mask<MaskT> *mask,
485  CONST_PTR(std::vector<PTR(Footprint)>) const& footprints,
486  MaskT const bitmask);
487 
502 template<typename MaskT>
504  typename image::Mask<MaskT>::Ptr const& mask,
505  MaskT const bitmask);
506 
507 /************************************************************************************************************/
508 
509 }}}
510 
511 #endif
std::vector< Span::Ptr > SpanList
The Footprint&#39;s Span list.
Definition: Footprint.h:82
Footprint(int nspan=0, geom::Box2I const &region=geom::Box2I())
An ellipse core with quadrupole moments as parameters.
Definition: Quadrupole.h:45
const SpanList & getSpans() const
Definition: Footprint.h:124
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)
const Span & addSpanInSeries(const int y, const int x0, const int x1)
virtual bool isHeavy() const
Definition: Footprint.h:115
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)
An include file to include the header files for lsst::afw::geom.
#define PTR(...)
Definition: base.h:41
double dx
Definition: ImageUtils.cc:90
Public header class for ellipse library.
void serialize(Archive &ar, const unsigned int version)
boost::shared_ptr< Footprint > Ptr
Definition: Footprint.h:78
int y
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
geom::Point2D getCentroid() const
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...
friend class boost::serialization::access
Definition: Footprint.h:315
Implementation of the WCS standard for a any projection.
Definition: Wcs.h:107
std::vector< Peak::Ptr > PeakList
Definition: Footprint.h:83
double dy
Definition: ImageUtils.cc:90
boost::shared_ptr< const Footprint > ConstPtr
Definition: Footprint.h:79
Footprint & operator=(Footprint &other)
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
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)
void clipTo(geom::Box2I const &bbox)
boost::shared_ptr< Footprint > growFootprint(Footprint const &foot, int nGrow, bool isotropic=true)
void shift(geom::ExtentI d)
Definition: Footprint.h:191
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:93
geom::Box2I _region
The corners of the MaskedImage the footprints live in.
Definition: Footprint.h:326
geom::ellipses::Quadrupole getShape() const
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:296
boost::shared_ptr< Image< PixelT > > Ptr
Definition: Image.h:418
SpanList _spans
the Spans contained in this Footprint
Definition: Footprint.h:323
#define CONST_PTR(...)
Definition: base.h:47
A set of pixels in an Image.
Definition: Footprint.h:73
void shift(int dx, int 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:201
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.
bool contains(geom::Point2I const &pix) const
std::vector< lsst::afw::geom::Box2I > footprintToBBoxList(Footprint const &foot)
void readSpans(afw::table::BaseCatalog const &spanCat)
Persistence implementation functions made available for derived classes.
const PeakList & getPeaks() const
Definition: Footprint.h:133
geom::Box2I _bbox
the Footprint&#39;s bounding box
Definition: Footprint.h:324
int _area
number of pixels in this Footprint (not the area of the bbox)
Definition: Footprint.h:321
geom::Box2I & getBBox()
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:196
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.
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:114
virtual std::string getPersistenceName() const
Return the unique name used to persist this object and look up its factory.
void insertIntoImage(typename lsst::afw::image::Image< PixelT > &idImage, boost::uint64_t const id, geom::Box2I const &region=geom::Box2I()) const
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:56
PeakList _peaks
the Peaks lying in this footprint
Definition: Footprint.h:325
boost::shared_ptr< Footprint > mergeFootprints(Footprint const &foot1, Footprint const &foot2)
bool _normalized
Are the spans sorted?
Definition: Footprint.h:327
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:182
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:415
geom::Box2I const & getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:198
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.
geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:194
void clipToNonzero(lsst::afw::image::Image< PixelT > const &img)