32 #include "boost/format.hpp"
41 #include "lsst/afw/detection/FootprintArray.cc"
52 setPixel(T
val) : _val(val) {}
54 T operator()(T)
const {
62 struct setPixel<boost::uint16_t> {
63 typedef boost::uint16_t T;
65 setPixel(T
val) : _mask(~val) {}
67 T operator()(T pix)
const {
76 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
80 HeavyFootprintCtrl
const *ctrl
86 HeavyFootprintCtrl ctrl_s = HeavyFootprintCtrl();
92 switch (ctrl->getModifySource()) {
100 ImagePixelT
const ival = ctrl->getImageVal();
101 MaskPixelT
const mval = ctrl->getMaskVal();
102 VariancePixelT
const vval = ctrl->getVarianceVal();
105 setPixel<ImagePixelT>(ival), mimage.
getXY0());
107 setPixel<MaskPixelT>(mval), mimage.
getXY0());
109 setPixel<VariancePixelT>(vval), mimage.
getXY0());
115 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
118 HeavyFootprintCtrl
const* ctrl)
126 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
136 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
143 template<
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
144 PTR(HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>)
146 HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT> const& h2)
152 geom::Box2I bbox(h1.getBBox());
153 bbox.include(h2.getBBox());
156 image::MaskedImage<ImagePixelT,MaskPixelT,VariancePixelT> im1(bbox);
157 image::MaskedImage<ImagePixelT,MaskPixelT,VariancePixelT> im2(bbox);
164 return
PTR(HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>)
165 (new HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>(*foot, im1));
169 template<typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
171 HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT>::
dot(
172 HeavyFootprint<ImagePixelT, MaskPixelT, VariancePixelT> const& rhs
176 assert(isNormalized());
177 assert(rhs.isNormalized());
181 ArrayIter lhsArray = getImageArray().begin(), rhsArray = rhs.getImageArray().begin();
182 SpanList::const_iterator lhsIter = getSpans().begin(), rhsIter = rhs.getSpans().begin();
183 SpanList::const_iterator
const lhsEnd = getSpans().end(), rhsEnd = rhs.getSpans().end();
185 while (lhsIter != lhsEnd && rhsIter != rhsEnd) {
186 Span
const& lhsSpan = **lhsIter, rhsSpan = **rhsIter;
187 int const yLhs = lhsSpan.getY(), yRhs = rhsSpan.getY();
189 int const x0Lhs = lhsSpan.getX0(), x1Lhs = lhsSpan.getX1();
190 int const x0Rhs = rhsSpan.getX0(), x1Rhs = rhsSpan.getX1();
191 int const xMin = std::max(x0Lhs, x0Rhs), xMax = std::min(x1Lhs, x1Rhs);
193 lhsArray += xMin - x0Lhs;
194 rhsArray += xMin - x0Rhs;
195 for (
int x = xMin;
x <= xMax; ++
x, ++lhsArray, ++rhsArray) {
196 sum += (*lhsArray)*(*rhsArray);
199 lhsArray -= xMax + 1 - x0Lhs;
200 rhsArray -= xMax + 1 - x0Rhs;
202 if (x1Lhs <= x1Rhs) {
203 lhsArray += lhsSpan.getWidth();
206 rhsArray += rhsSpan.getWidth();
210 }
else if (yLhs < yRhs) {
211 while (lhsIter != lhsEnd && (*lhsIter)->getY() < yRhs) {
212 lhsArray += (*lhsIter)->getWidth();
217 while (rhsIter != rhsEnd && (*rhsIter)->getY() < yLhs) {
218 rhsArray += (*rhsIter)->getWidth();
236 template <
typename ImagePixelT,
239 struct HeavyFootprintPersistenceHelper {
240 afw::table::Schema
schema;
241 afw::table::Key< afw::table::Array<ImagePixelT> >
image;
242 afw::table::Key< afw::table::Array<MaskPixelT> > mask;
243 afw::table::Key< afw::table::Array<VariancePixelT> > variance;
245 static HeavyFootprintPersistenceHelper
const &
get() {
246 static HeavyFootprintPersistenceHelper
const instance;
252 HeavyFootprintPersistenceHelper() :
254 image(
schema.addField< afw::table::Array<ImagePixelT> >(
255 "image",
"image pixels for HeavyFootprint",
"dn"
257 mask(
schema.addField< afw::table::Array<MaskPixelT> >(
258 "mask",
"mask pixels for HeavyFootprint"
260 variance(
schema.addField< afw::table::Array<VariancePixelT> >(
261 "variance",
"variance pixels for HeavyFootprint",
"dn^2"
264 schema.getCitizen().markPersistent();
274 template <
typename ImagePixelT,
277 struct ComputeSuffix;
278 template <>
struct ComputeSuffix<boost::uint16_t> {
static std::string apply() {
return "U"; } };
279 template <>
struct ComputeSuffix<float> {
static std::string apply() {
return "F"; } };
280 template <>
struct ComputeSuffix<double> {
static std::string apply() {
return "D"; } };
281 template <>
struct ComputeSuffix<int> {
static std::string apply() {
return "I"; } };
285 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
287 return "HeavyFootprint" + ComputeSuffix<ImagePixelT,MaskPixelT,VariancePixelT>::apply();
290 template <
typename ImagePixelT,
typename MaskPixelT,
typename VariancePixelT>
292 HeavyFootprintPersistenceHelper<ImagePixelT,MaskPixelT,VariancePixelT>
const & keys =
293 HeavyFootprintPersistenceHelper<ImagePixelT,MaskPixelT,VariancePixelT>::get();
298 PTR(afw::table::BaseRecord) record = cat.addNew();
302 record->set(keys.image, ndarray::
const_array_cast<ImagePixelT>(getImageArray()));
303 record->set(keys.mask, ndarray::
const_array_cast<MaskPixelT>(getMaskArray()));
304 record->set(keys.variance, ndarray::
const_array_cast<VariancePixelT>(getVarianceArray()));
305 handle.saveCatalog(cat);
308 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
309 class HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>::Factory :
310 public afw::table::io::PersistableFactory
314 explicit Factory(std::string
const &
name) : afw::table::io::PersistableFactory(name) {}
316 virtual PTR(afw::table::io::Persistable)
317 read(InputArchive const & archive, CatalogVector const & catalogs)
const {
318 HeavyFootprintPersistenceHelper<ImagePixelT,MaskPixelT,VariancePixelT>
const & keys =
319 HeavyFootprintPersistenceHelper<ImagePixelT,MaskPixelT,VariancePixelT>::get();
321 PTR(HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>) result(
322 new HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>()
324 result->readSpans(catalogs[0]);
325 result->readPeaks(catalogs[1]);
326 afw::table::BaseRecord const & record = catalogs[2].front();
327 result->_image = ndarray::
const_array_cast<ImagePixelT>(record.get(keys.image));
328 result->_mask = ndarray::
const_array_cast<MaskPixelT>(record.get(keys.mask));
329 result->_variance = ndarray::
const_array_cast<VariancePixelT>(record.get(keys.variance));
333 static Factory registration;
338 template <typename ImagePixelT, typename MaskPixelT, typename VariancePixelT>
339 typename HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>::Factory
340 HeavyFootprint<ImagePixelT,MaskPixelT,VariancePixelT>::Factory::registration(
341 "HeavyFootprint" + ComputeSuffix<ImagePixelT,MaskPixelT,VariancePixelT>::apply()
350 #define INSTANTIATE(TYPE) \
351 template class HeavyFootprint<TYPE>; \
352 template PTR(HeavyFootprint<TYPE>) mergeHeavyFootprints<TYPE>( \
353 HeavyFootprint<TYPE> const&, HeavyFootprint<TYPE> const&);
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.
table::Key< std::string > name
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
CatalogT< BaseRecord > BaseCatalog
Array< T_, N, C > const_array_cast(Array< T, N, C > const &array)
afw::table::Schema schema
Include files required for standard LSST Exception handling.
boost::uint16_t MaskPixel
#define INSTANTIATE(MATCH)
definition of the Trace messaging facilities
ImagePtr getImage(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's image.
boost::enable_if< typename ExpressionTraits< Scalar >::IsScalar, Scalar >::type sum(Scalar const &scalar)
VariancePtr getVariance(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's variance.
table::Key< table::Array< Kernel::Pixel > > image
geom::Point2I getXY0() const
MaskPtr getMask(bool const noThrow=false) const
Return a (Ptr to) the MaskedImage's mask.
A class to manipulate images, masks, and variance as a single object.
Vector< T, N > makeVector(T v1, T v2,..., T vN)
Variadic constructor for Vector.
#define LSST_ARCHIVE_ASSERT(EXPR)
An assertion macro used to validate the structure of an InputArchive.
detail::SimpleInitializer< N > allocate(Vector< int, N > const &shape)
Create an expression that allocates uninitialized memory for an array.
geom::Point2I getXY0() const
lsst::afw::detection::Footprint Footprint
Implementation of the Class MaskedImage.
ExpressionTraits< Derived >::Iterator Iterator
Nested expression or element iterator.
boost::shared_ptr< Footprint > mergeFootprints(Footprint const &foot1, Footprint const &foot2)
float VariancePixel
! default type for Masks and MaskedImage Masks
boost::shared_ptr< HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > > mergeHeavyFootprints(HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h1, HeavyFootprint< ImagePixelT, MaskPixelT, VariancePixelT > const &h2)