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
HeavyFootprint.cc
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 /*****************************************************************************/
28 #include <cassert>
29 #include <string>
30 #include <typeinfo>
31 #include <algorithm>
32 #include "boost/format.hpp"
33 #include "lsst/pex/logging/Trace.h"
34 #include "lsst/pex/exceptions.h"
41 #include "lsst/afw/detection/FootprintArray.cc"
42 
43 namespace lsst {
44 namespace afw {
45 namespace detection {
46 namespace {
47  template<typename T>
48  struct setPixel {
49  setPixel(T val) : _val(val) {}
50 
51  T operator()(T) const {
52  return _val;
53  }
54  private:
55  T _val;
56  };
57 
58  template<>
59  struct setPixel<boost::uint16_t> {
60  typedef boost::uint16_t T;
61 
62  setPixel(T val) : _mask(~val) {}
63 
64  T operator()(T pix) const {
65  pix &= _mask;
66  return pix;
67  }
68  private:
69  T _mask;
70  };
71 }
72 
73 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
75  Footprint const& foot,
77  HeavyFootprintCtrl const *ctrl
78  ) : Footprint(foot),
79  _image(ndarray::allocate(ndarray::makeVector(foot.getNpix()))),
80  _mask(ndarray::allocate(ndarray::makeVector(foot.getNpix()))),
81  _variance(ndarray::allocate(ndarray::makeVector(foot.getNpix())))
82 {
83  HeavyFootprintCtrl ctrl_s = HeavyFootprintCtrl();
84 
85  if (!ctrl) {
86  ctrl = &ctrl_s;
87  }
88 
89  switch (ctrl->getModifySource()) {
91  flattenArray(*this, mimage.getImage()->getArray(), _image, mimage.getXY0());
92  flattenArray(*this, mimage.getMask()->getArray(), _mask, mimage.getXY0());
93  flattenArray(*this, mimage.getVariance()->getArray(), _variance, mimage.getXY0());
94  break;
96  {
97  ImagePixelT const ival = ctrl->getImageVal();
98  MaskPixelT const mval = ctrl->getMaskVal();
99  VariancePixelT const vval = ctrl->getVarianceVal();
100 
101  flattenArray(*this, mimage.getImage()->getArray(), _image,
102  setPixel<ImagePixelT>(ival), mimage.getXY0());
103  flattenArray(*this, mimage.getMask()->getArray(), _mask,
104  setPixel<MaskPixelT>(mval), mimage.getXY0());
105  flattenArray(*this, mimage.getVariance()->getArray(), _variance,
106  setPixel<VariancePixelT>(vval), mimage.getXY0());
107  break;
108  }
109  }
110 }
111 
112 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
114  Footprint const& foot,
115  HeavyFootprintCtrl const* ctrl)
116  : Footprint(foot),
117  _image (ndarray::allocate(ndarray::makeVector(foot.getNpix()))),
118  _mask (ndarray::allocate(ndarray::makeVector(foot.getNpix()))),
119  _variance(ndarray::allocate(ndarray::makeVector(foot.getNpix())))
120 {
121 }
122 
123 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
126  ) const
127 {
128  expandArray(*this, _image, mimage.getImage()->getArray(), mimage.getXY0());
129  expandArray(*this, _mask, mimage.getMask()->getArray(), mimage.getXY0());
130  expandArray(*this, _variance, mimage.getVariance()->getArray(), mimage.getXY0());
131 }
132 
133 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
136 {
137  expandArray(*this, _image, image.getArray(), image.getXY0());
138 }
139 
140 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
141 PTR(HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>)
142 mergeHeavyFootprints(HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT> const& h1,
143  HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT> const& h2)
144 {
145  // Merge the Footprints (by merging the Spans)
146  PTR(Footprint) foot = mergeFootprints(h1, h2);
147 
148  // Find the union bounding-box
149  geom::Box2I bbox(h1.getBBox());
150  bbox.include(h2.getBBox());
151 
152  // Create union-bb-sized images and insert the heavies
153  image::MaskedImage<ImagePixelT,MaskPixelT,VariancePixelT> im1(bbox);
154  image::MaskedImage<ImagePixelT,MaskPixelT,VariancePixelT> im2(bbox);
155  h1.insert(im1);
156  h2.insert(im2);
157  // Add the pixels
158  im1 += im2;
159 
160  // Build new HeavyFootprint from the merged spans and summed pixels.
161  return PTR(HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>)
162  (new HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>(*foot, im1));
163 }
164 
165 
166 /************************************************************************************************************/
167 //
168 // Explicit instantiations
169 // \cond
170 //
171 //
172 #define INSTANTIATE(TYPE) \
173  template class HeavyFootprint<TYPE>; \
174  template PTR(HeavyFootprint<TYPE>) mergeHeavyFootprints<TYPE>( \
175  HeavyFootprint<TYPE> const&, HeavyFootprint<TYPE> const&);
176 
177 INSTANTIATE(boost::uint16_t);
178 INSTANTIATE(double);
179 INSTANTIATE(float);
180 INSTANTIATE(int);
181 
182 }}}
183 // \endcond
void flattenArray(Footprint const &fp, ndarray::Array< T, N, C > const &src, ndarray::Array< U, N-1, D > const &dest, lsst::afw::geom::Point2I const &xy0=lsst::afw::geom::Point2I())
Flatten the first two dimensions of an array.
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s image.
Definition: MaskedImage.h:869
void insert(lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > &mimage) const
Represent a set of pixels of an arbitrary shape and size.
void expandArray(Footprint const &fp, ndarray::Array< T, N, C > const &src, ndarray::Array< U, N+1, D > const &dest, lsst::afw::geom::Point2I const &xy0=lsst::afw::geom::Point2I())
expand the first dimension of an array
lsst::afw::detection::Footprint Footprint
Definition: Source.h:61
definition of the Trace messaging facilities
Represent a set of pixels of an arbitrary shape and size, including values for those pixels; a HeavyF...
#define PTR(...)
Definition: base.h:41
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s variance.
Definition: MaskedImage.h:890
#define INSTANTIATE(TYPE)
Definition: ImagePca.cc:128
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:77
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
geom::Point2I getXY0() const
Definition: MaskedImage.h:929
detail::SimpleInitializer< N > allocate(Vector< int, N > const &shape)
Create an expression that allocates uninitialized memory for an array.
Support for peaks in images.
Control Footprint-related algorithms.
MaskPtr getMask(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage&#39;s mask.
Definition: MaskedImage.h:879
HeavyFootprint(Footprint const &foot, lsst::afw::image::MaskedImage< ImagePixelT, MaskPixelT, VariancePixelT > const &mimage, HeavyFootprintCtrl const *ctrl=NULL)
geom::Point2I getXY0() const
Definition: Image.h:264
Implementation of the Class MaskedImage.
boost::shared_ptr< Footprint > mergeFootprints(Footprint const &foot1, Footprint const &foot2)
ImageT val
Definition: CR.cc:154
Include files required for standard LSST Exception handling.
boost::shared_ptr< HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > mergeHeavyFootprints(HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h1, HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h2)