Demonstrate the use of FootprintFunctors to work with Footprints; the code's in footprintFunctor.cc.
Start by including needed headers and declaring namespace aliases
#include <cstdio>
namespace afwDetect = lsst::afw::detection;
namespace afwGeom = lsst::afw::geom;
We don't want our functor visible in the global namespace, or even outside this file, so put it in an anonymous namespace:
Declare our functor
FindSetBits
, it's parameterised over
MaskT
, and provide a constructor.
_bits
is the accumulator for Mask bits in the Footprint
template <typename MaskT>
public:
FindSetBits(MaskT const& mask
) : afwDetect::FootprintFunctor<MaskT>(mask),
_bits(0) {}
Define what it means to
apply
the functor; in this case, OR together the bits
void operator()(typename MaskT::xy_locator loc,
int,
int
) {
}
Return the desired value
typename MaskT::Pixel getBits()
const {
return _bits; }
Clear the accumulator between Footprints
void reset() {
_bits = 0; }
Define the private variable,
_bits
private:
typename MaskT::Pixel
_bits;
};
close our anonymous namespace
Now define a function, printBits
, to exercise the FindSetBits
. We'll pass it a Mask and a list of Footprints
Declare a FindSetBits,
count
, and tell it about our Mask
FindSetBits<afwImage::Mask<afwImage::MaskPixel> > count(mask);
Loop over all our Footprints
for (afwDetect::FootprintSet::FootprintList::const_iterator fiter =
feet.begin();
Clear the bitmask and OR together all the bits under the footprint (
*fiter
is a
Footprint::Ptr
, so
**fiter
is a Footprint)
fiter !=
feet.end(); ++fiter) {
count.apply(**fiter);
Print the result
printf("0x%x\n", count.getBits());
}
}
Just to show you this in action, let's make a MaskedImage and check its bits
(*mimage.getImage())(5, 6) = 100;
(*mimage.getImage())(5, 7) = 110;
*mimage.getMask() = 0x1;
(*mimage.getMask())(5, 6) |= 0x2;
(*mimage.getMask())(5, 7) |= 0x4;
printBits(*mimage.getMask(), *ds.getFootprints());
}
Running the example should print
0x7
.