#include <string>
#include "lsst/utils/Utils.h"
#include "lsst/pex/exceptions.h"
#include "lsst/daf/base.h"
#include "testSpatialCell.h"
namespace afwDetect = lsst::afw::detection;
namespace afwMath = lsst::afw::math;
namespace afwGeom = lsst::afw::geom;
typedef float PixelT;
std::pair<std::shared_ptr<afwImage::MaskedImage<PixelT>>, std::shared_ptr<afwDetect::FootprintSet>>
readImage();
void SpatialCellSetDemo() {
std::shared_ptr<afwImage::MaskedImage<PixelT>> im;
std::shared_ptr<afwDetect::FootprintSet> fs;
boost::tie(im, fs) = readImage();
for (afwDetect::FootprintSet::FootprintList::iterator ptr = fs->getFootprints()->begin(),
end = fs->getFootprints()->end();
ptr != end; ++ptr) {
std::shared_ptr<ExampleCandidate> tc(new ExampleCandidate(xc, yc, im, bbox));
cellSet.insertCandidate(tc);
}
ExampleCandidateVisitor visitor;
cellSet.visitCandidates(&visitor);
std::cout << boost::format("There are %d candidates\n") % visitor.getN();
for (unsigned int i = 0; i != cellSet.getCellList().size(); ++i) {
std::shared_ptr<afwMath::SpatialCell> cell = cellSet.getCellList()[i];
candidate != candidateEnd; ++candidate) {
afwGeom::Box2I box =
dynamic_cast<ExampleCandidate *
>((*candidate).get())->getBBox();
#if 0
std::cout << boost::format("%d %5.2f %5.2f %d\n")
% i % (*candidate)->getXCenter() % (*candidate)->getYCenter() % (w*h);
#endif
}
}
}
for (unsigned int i = 0; i != cellSet.getCellList().size(); ++i) {
std::shared_ptr<afwMath::SpatialCell> cell = cellSet.getCellList()[i];
cell->visitCandidates(&visitor);
cell->setIgnoreBad(false);
std::cout << boost::format("%s nobj=%d N_good=%d NPix_good=%d\n") % cell->getLabel() % cell->size() %
visitor.getN() % visitor.getNPix();
}
cellSet.setIgnoreBad(true);
cellSet.visitCandidates(&visitor);
std::cout << boost::format("There are %d good candidates\n") % visitor.getN();
}
std::pair<std::shared_ptr<afwImage::MaskedImage<PixelT>>, std::shared_ptr<afwDetect::FootprintSet>>
readImage() {
std::shared_ptr<afwImage::MaskedImage<PixelT>> mi;
try {
std::string dataDir = lsst::utils::getPackageDir("afwdata");
std::string filename = dataDir + "/CFHT/D4/cal-53535-i-797722_1.fits";
std::shared_ptr<lsst::daf::base::PropertySet> md;
} catch (lsst::pex::exceptions::NotFoundError &e) {
std::cerr << e << std::endl;
exit(1);
}
bctrl.setNxSample(mi->getWidth() / 256 + 1);
bctrl.setNySample(mi->getHeight() / 256 + 1);
bctrl.getStatisticsControl()->setNumSigmaClip(3.0);
bctrl.getStatisticsControl()->setNumIter(2);
std::shared_ptr<afwImage::Image<PixelT>> im = mi->getImage();
try {
} catch (std::exception &) {
}
int npixMin = 5;
std::shared_ptr<afwDetect::FootprintSet> fs(
new afwDetect::FootprintSet(*mi, threshold, "DETECTED", npixMin));
int const grow = 1;
bool const isotropic = false;
std::shared_ptr<afwDetect::FootprintSet> grownFs(new afwDetect::FootprintSet(*fs, grow, isotropic));
grownFs->setMask(mi->getMask(), "DETECTED");
return std::make_pair(mi, grownFs);
}
int main() {
std::pair<std::shared_ptr<afwImage::MaskedImage<PixelT>>, std::shared_ptr<afwDetect::FootprintSet>> data =
readImage();
assert(data.first != NULL);
SpatialCellSetDemo();
}