26 #include <pybind11/pybind11.h> 
   27 #include <pybind11/stl.h> 
   34 using namespace pybind11::literals;
 
   45 void wrapSpatialCellCandidate(
py::module &mod) {
 
   46     py::class_<SpatialCellCandidate, std::shared_ptr<SpatialCellCandidate>> 
cls(mod, 
"SpatialCellCandidate");
 
   48     py::enum_<SpatialCellCandidate::Status>(
cls, 
"Status")
 
   49             .value(
"BAD", SpatialCellCandidate::Status::BAD)
 
   50             .value(
"GOOD", SpatialCellCandidate::Status::GOOD)
 
   51             .value(
"UNKNOWN", SpatialCellCandidate::Status::UNKNOWN)
 
   54     cls.def(
"getXCenter", &SpatialCellCandidate::getXCenter);
 
   55     cls.def(
"getYCenter", &SpatialCellCandidate::getYCenter);
 
   56     cls.def(
"instantiate", &SpatialCellCandidate::instantiate);
 
   57     cls.def(
"getCandidateRating", &SpatialCellCandidate::getCandidateRating);
 
   58     cls.def(
"setCandidateRating", &SpatialCellCandidate::setCandidateRating);
 
   59     cls.def(
"getId", &SpatialCellCandidate::getId);
 
   60     cls.def(
"getStatus", &SpatialCellCandidate::getStatus);
 
   61     cls.def(
"setStatus", &SpatialCellCandidate::setStatus);
 
   62     cls.def(
"isBad", &SpatialCellCandidate::isBad);
 
   66 void wrapSpatialCellCandidateIterator(
py::module &mod) {
 
   67     py::class_<SpatialCellCandidateIterator> 
cls(mod, 
"SpatialCellCandidateIterator");
 
   68     cls.def(
"__incr__", &SpatialCellCandidateIterator::operator++, py::is_operator());
 
   72     cls.def(
"__eq__", &SpatialCellCandidateIterator::operator==, py::is_operator());
 
   73     cls.def(
"__ne__", &SpatialCellCandidateIterator::operator!=, py::is_operator());
 
   74     cls.def(
"__sub__", &SpatialCellCandidateIterator::operator-, py::is_operator());
 
   79     py::class_<SpatialCell, std::shared_ptr<SpatialCell>> 
cls(mod, 
"SpatialCell");
 
   81     cls.def(py::init<std::string const &, lsst::geom::Box2I const &, CandidateList const &>(), 
"label"_a,
 
   84     cls.def(
"empty", &SpatialCell::empty);
 
   85     cls.def(
"size", &SpatialCell::size);
 
   86     cls.def(
"__len__", &SpatialCell::size);
 
   87     cls.def(
"getLabel", &SpatialCell::getLabel);
 
   88     cls.def(
"begin", (SpatialCellCandidateIterator (SpatialCell::*)()) & SpatialCell::begin);
 
   89     cls.def(
"begin", (SpatialCellCandidateIterator (SpatialCell::*)(
bool)) & SpatialCell::begin);
 
   92     cls.def(
"insertCandidate", &SpatialCell::insertCandidate);
 
   93     cls.def(
"removeCandidate", &SpatialCell::removeCandidate);
 
   94     cls.def(
"setIgnoreBad", &SpatialCell::setIgnoreBad, 
"ignoreBad"_a);
 
   95     cls.def(
"getIgnoreBad", &SpatialCell::getIgnoreBad);
 
   96     cls.def(
"getCandidateById", &SpatialCell::getCandidateById, 
"id"_a, 
"noThrow"_a = 
false);
 
   97     cls.def(
"getLabel", &SpatialCell::getLabel);
 
   98     cls.def(
"getBBox", &SpatialCell::getBBox);
 
   99     cls.def(
"sortCandidates", &SpatialCell::sortCandidates);
 
  100     cls.def(
"visitCandidates",
 
  101             (
void (SpatialCell::*)(CandidateVisitor *, 
int const, 
bool const, 
bool const)) &
 
  102                     SpatialCell::visitCandidates,
 
  103             "visitor"_a, 
"nMaxPerCell"_a = -1, 
"ignoreExceptions"_a = 
false, 
"reset"_a = 
true);
 
  104     cls.def(
"visitAllCandidates", (
void (SpatialCell::*)(CandidateVisitor *, 
bool const, 
bool const)) &
 
  105                                           SpatialCell::visitAllCandidates,
 
  106             "visitor"_a, 
"ignoreExceptions"_a = 
false, 
"reset"_a = 
true);
 
  111     py::class_<SpatialCellSet, std::shared_ptr<SpatialCellSet>> 
cls(mod, 
"SpatialCellSet");
 
  113     cls.def(py::init<lsst::geom::Box2I const &, int, int>(), 
"region"_a, 
"xSize"_a, 
"ySize"_a = 0);
 
  115     cls.def(
"getCellList", &SpatialCellSet::getCellList);
 
  116     cls.def(
"getBBox", &SpatialCellSet::getBBox);
 
  117     cls.def(
"insertCandidate", &SpatialCellSet::insertCandidate);
 
  118     cls.def(
"sortCandidates", &SpatialCellSet::sortCandidates);
 
  119     cls.def(
"visitCandidates", (
void (SpatialCellSet::*)(CandidateVisitor *, 
int const, 
bool const)) &
 
  120                                        SpatialCellSet::visitCandidates,
 
  121             "visitor"_a, 
"nMaxPerCell"_a = -1, 
"ignoreExceptions"_a = 
false);
 
  122     cls.def(
"visitAllCandidates",
 
  123             (
void (SpatialCellSet::*)(CandidateVisitor *, 
bool const)) & SpatialCellSet::visitAllCandidates,
 
  124             "visitor"_a, 
"ignoreExceptions"_a = 
false);
 
  125     cls.def(
"getCandidateById", &SpatialCellSet::getCandidateById, 
"id"_a, 
"noThrow"_a = 
false);
 
  126     cls.def(
"setIgnoreBad", &SpatialCellSet::setIgnoreBad, 
"ignoreBad"_a);
 
  131     py::class_<CandidateVisitor, std::shared_ptr<CandidateVisitor>> 
cls(mod, 
"CandidateVisitor");
 
  133     cls.def(py::init<>());
 
  135     cls.def(
"reset", &CandidateVisitor::reset);
 
  136     cls.def(
"processCandidate", &CandidateVisitor::processCandidate);
 
  140 void wrapSpatialCellImageCandidate(
py::module &mod) {
 
  141     py::class_<SpatialCellImageCandidate, std::shared_ptr<SpatialCellImageCandidate>, SpatialCellCandidate>
 
  142             cls(mod, 
"SpatialCellImageCandidate");
 
  144     cls.def_static(
"setWidth", &SpatialCellImageCandidate::setWidth, 
"width"_a);
 
  145     cls.def_static(
"getWidth", &SpatialCellImageCandidate::getWidth);
 
  146     cls.def_static(
"setHeight", &SpatialCellImageCandidate::setHeight, 
"height"_a);
 
  147     cls.def_static(
"getHeight", &SpatialCellImageCandidate::getHeight);
 
  148     cls.def(
"setChi2", &SpatialCellImageCandidate::setChi2, 
"chi2"_a);
 
  149     cls.def(
"getChi2", &SpatialCellImageCandidate::getChi2);
 
  162         TestCandidate(
float const xCenter,  
 
  169         virtual double getCandidateRating()
 const { 
return _flux; }
 
  170         virtual void setCandidateRating(
double flux) { _flux = flux; }
 
  182         void reset() { _n = 0; }
 
  187         int getN()
 const { 
return _n; }
 
  197         TestImageCandidate(
float const xCenter,  
 
  204         double getCandidateRating()
 const { 
return _flux; }
 
  210                 *_image->getImage() = _flux;
 
  220     py::class_<TestCandidate, std::shared_ptr<TestCandidate>, 
SpatialCellCandidate> clsTestCandidate(
 
  221             mod, (
"TestCandidate"));
 
  222     clsTestCandidate.def(py::init<float const, float const, float const>());
 
  223     clsTestCandidate.def(
"getCandidateRating", &TestCandidate::getCandidateRating);
 
  224     clsTestCandidate.def(
"setCandidateRating", &TestCandidate::setCandidateRating);
 
  226     py::class_<TestCandidateVisitor, std::shared_ptr<TestCandidateVisitor>, 
CandidateVisitor>
 
  227             clsTestCandidateVisitor(mod, (
"TestCandidateVisitor"));
 
  228     clsTestCandidateVisitor.def(py::init<>());
 
  229     clsTestCandidateVisitor.def(
"getN", &TestCandidateVisitor::getN);
 
  232             clsTestImageCandidate(mod, 
"TestImageCandidate");
 
  233     clsTestImageCandidate.def(py::init<float const, float const, float const>(), 
"xCenter"_a, 
"yCenter"_a,
 
  235     clsTestImageCandidate.def(
"getCandidateRating", &TestImageCandidate::getCandidateRating);
 
  236     clsTestImageCandidate.def(
"getMaskedImage", &TestImageCandidate::getMaskedImage);
 
  240     wrapSpatialCellCandidate(mod);
 
  241     wrapSpatialCellCandidateIterator(mod);
 
  242     wrapSpatialCell(mod);
 
  243     wrapSpatialCellSet(mod);
 
  244     wrapCandidateVisitor(mod);
 
  245     wrapSpatialCellImageCandidate(mod);