LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
FootprintFunctor.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_FUNCTOR_H)
24 #define LSST_DETECTION_FOOTPRINT_FUNCTOR_H
25 
28 
29 namespace lsst {
30 namespace afw {
31 namespace detection {
32 /************************************************************************************************************/
39 template <typename ImageT>
41 public:
42  FootprintFunctor(ImageT const& image
43  ) : _image(image) {}
44 
45  virtual ~FootprintFunctor() = 0;
46 
51  virtual void reset() {}
52  virtual void reset(Footprint const&) {}
53 
57  void apply(Footprint const& foot,
58  int const margin=0
59  ) {
60  reset();
61  reset(foot);
62 
63  if (foot.getSpans().empty()) {
64  return;
65  }
66 
67  geom::Box2I const bbox = foot.getBBox();
68  geom::Box2I region = foot.getRegion();
69  if (!region.isEmpty() &&
70  (!region.contains(bbox.getMin()) || !region.contains(bbox.getMax()))) {
71  throw LSST_EXCEPT(
72  lsst::pex::exceptions::LengthError,
73  (boost::format("Footprint with BBox (%d,%d) -- (%dx%d)"
74  "doesn't fit in image with BBox (%d,%d) -- (%dx%d)"
75  ) % bbox.getMinX() % bbox.getMinY()
76  % bbox.getMaxX() % bbox.getMaxY()
77  % region.getMinX() % region.getMinY()
78  % region.getMaxX() % region.getMaxY()
79  ).str()
80  );
81  }
82 
83  // Current position of the locator (in the SpanList loop)
84  int ox1 = 0, oy = 0;
85 
86  int const x0 = _image.getX0();
87  int const y0 = _image.getY0();
88 
89  typename ImageT::xy_locator loc = _image.xy_at(-x0, -y0); // Origin of the Image's pixels
90 
91  int const width = _image.getWidth();
92  int const height = _image.getHeight();
93  for (Footprint::SpanList::const_iterator siter = foot.getSpans().begin();
94  siter != foot.getSpans().end(); siter++) {
95  Span::Ptr const span = *siter;
96 
97  int const y = span->getY();
98  if (y - y0 < margin || y - y0 >= height - margin) {
99  continue;
100  }
101  int sx0 = span->getX0();
102  int sx1 = span->getX1();
103  if (sx0 - x0 < margin) {
104  sx0 = margin + x0;
105  }
106  if (sx1 - x0 >= width - margin) {
107  sx1 = width + x0 - margin - 1;
108  }
109 
110  loc += lsst::afw::image::pair2I(sx0 - ox1, y - oy);
111 
112  for (int x = sx0; x <= sx1; ++x, ++loc.x()) {
113  operator()(loc, x, y);
114  }
115 
116  ox1 = sx1 + 1; oy = y;
117  }
118  }
120  ImageT const& getImage() const { return _image; }
121 
126  virtual void operator()(typename ImageT::xy_locator loc, int x, int y) = 0;
127 private:
128  ImageT const _image; // The image that the Footprints live in
129 };
130 
136 template <typename ImageT>
138 
139 }}}
140 #endif
int y
int getMaxY() const
Definition: Box.h:129
Represent a set of pixels of an arbitrary shape and size.
bool contains(Point2I const &point) const
Return true if the box contains the point.
Point2I const getMax() const
Definition: Box.h:127
virtual void operator()(typename ImageT::xy_locator loc, int x, int y)=0
int const x0
Definition: saturated.cc:45
An integer coordinate rectangle.
Definition: Box.h:53
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
void ImageT ImageT int float saturatedPixelValue int const width
Definition: saturated.cc:44
int getMinY() const
Definition: Box.h:125
void apply(Footprint const &foot, int const margin=0)
Apply operator() to each pixel in the Footprint.
int getMinX() const
Definition: Box.h:124
ImageT const & getImage() const
Return the image.
double x
bool isEmpty() const
Return true if the box contains no points.
Definition: Box.h:166
A set of pixels in an Image.
Definition: Footprint.h:62
void ImageT ImageT int float saturatedPixelValue int const height
Definition: saturated.cc:44
#define LSST_EXCEPT(type,...)
Definition: Exception.h:46
Implementation of the Class MaskedImage.
int getMaxX() const
Definition: Box.h:128
Point2I const getMin() const
Definition: Box.h:123
int const y0
Definition: saturated.cc:45
A functor class to allow users to process all the pixels in a Footprint.
geom::Box2I const & getRegion() const
Return the corners of the MaskedImage the footprints live in.
Definition: Footprint.h:209
virtual void reset(Footprint const &)
geom::Box2I getBBox() const
Return the Footprint&#39;s bounding box.
Definition: Footprint.h:206