lsst.afw  13.0-98-g5a654715e+2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
footprintSet.cc
Go to the documentation of this file.
1 /*
2 * LSST Data Management System
3 * Copyright 2008-2016 AURA/LSST.
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 <https://www.lsstcorp.org/LegalNotices/>.
21 */
22 
23 #include <pybind11/pybind11.h>
24 //#include <pybind11/operators.h>
25 #include <pybind11/stl.h>
26 
28 
29 namespace py = pybind11;
30 using namespace py::literals;
31 
32 namespace lsst {
33 namespace afw {
34 namespace detection {
35 
36 namespace {
37 template <typename PixelT, typename PyClass>
38 void declareMakeHeavy(PyClass &cls) {
39  // cls.def("makeHeavy", [](FootprintSet & self, image::MaskedImage<PixelT, image::MaskPixel> const&
40  // mimg) {
41  // return self.makeHeavy(mimg);
42  // });
43  // cls.def("makeHeavy", [](FootprintSet & self, image::MaskedImage<PixelT, image::MaskPixel> const&
44  // mimg, HeavyFootprintCtrl const* ctrl) {
45  // return self.makeHeavy(mimg, ctrl);
46  // });
47  cls.def("makeHeavy", (void (FootprintSet::*)(image::MaskedImage<PixelT, image::MaskPixel> const &,
48  HeavyFootprintCtrl const *)) &
49  FootprintSet::makeHeavy<PixelT, image::MaskPixel>,
50  "mimg"_a, "ctrl"_a = nullptr);
51 }
52 
53 template <typename PixelT, typename PyClass>
54 void declareSetMask(PyClass &cls) {
55  cls.def("setMask", (void (FootprintSet::*)(image::Mask<PixelT> *, std::string const &)) &
56  FootprintSet::setMask<PixelT>,
57  "mask"_a, "planeName"_a);
58 }
59 
60 template <typename PixelT, typename PyClass>
61 void declareTemplatedMembers(PyClass &cls) {
62  /* Constructors */
63  cls.def(py::init<image::Image<PixelT> const &, Threshold const &, int const, bool const>(), "img"_a,
64  "threshold"_a, "npixMin"_a = 1, "setPeaks"_a = true);
65  cls.def(py::init<image::MaskedImage<PixelT, image::MaskPixel> const &, Threshold const &,
66  std::string const &, int const, bool const>(),
67  "img"_a, "threshold"_a, "planeName"_a = "", "npixMin"_a = 1, "setPeaks"_a = true);
68 
69  /* Members */
70  declareMakeHeavy<int>(cls);
71  declareMakeHeavy<float>(cls);
72  declareMakeHeavy<double>(cls);
73  declareMakeHeavy<std::uint16_t>(cls);
74  // declareMakeHeavy<std::uint64_t>(cls);
75  declareSetMask<image::MaskPixel>(cls);
76 }
77 } // namespace
78 
79 PYBIND11_PLUGIN(_footprintSet) {
80  py::module mod("_footprintSet", "Python wrapper for afw _footprintSet library");
81 
82  py::class_<FootprintSet, std::shared_ptr<FootprintSet>, lsst::daf::base::Citizen> clsFootprintSet(
83  mod, "FootprintSet");
84 
85  declareTemplatedMembers<std::uint16_t>(clsFootprintSet);
86  declareTemplatedMembers<int>(clsFootprintSet);
87  declareTemplatedMembers<float>(clsFootprintSet);
88  declareTemplatedMembers<double>(clsFootprintSet);
89 
90  clsFootprintSet.def(py::init<image::Mask<image::MaskPixel> const &, Threshold const &, int const>(),
91  "img"_a, "threshold"_a, "npixMin"_a = 1);
92 
93  /* Members */
94  clsFootprintSet.def(py::init<geom::Box2I>(), "region"_a);
95  clsFootprintSet.def(py::init<FootprintSet const &>(), "set"_a);
96  clsFootprintSet.def(py::init<FootprintSet const &, int, FootprintControl const &>(), "set"_a, "rGrow"_a,
97  "ctrl"_a);
98  clsFootprintSet.def(py::init<FootprintSet const &, int, bool>(), "set"_a, "rGrow"_a, "isotropic"_a);
99  clsFootprintSet.def(py::init<FootprintSet const &, FootprintSet const &, bool>(), "footprints1"_a,
100  "footprints2"_a, "includePeaks"_a);
101 
102  clsFootprintSet.def("swap", &FootprintSet::swap);
103  // clsFootprintSet.def("swapFootprintList", &FootprintSet::swapFootprintList);
104  // The pybind11 wrapped getFootprints dereferences the shared pointer to the std::vector of Footprints
105  // held by the FootprintSet when returning to python to work around an STL caster issue. However this
106  // creates a problem for the setter that now expects a shared pointer, making the setter unable to
107  // operate on the output from the getter. Below defines two overrides for the setter function, one
108  // that can handle a shared pointer (in case somewhere else in the stack has one somehow) and one
109  // that will accept a standard vector of Footprints, which will be internally placed in a shared
110  // pointer to match the underlying C++ function signature
111  clsFootprintSet.def("setFootprints",
112  [](FootprintSet &self, std::shared_ptr<FootprintSet::FootprintList> footListPtr) {
113  self.setFootprints(footListPtr);
114  });
115  clsFootprintSet.def("setFootprints", [](FootprintSet &self, FootprintSet::FootprintList footList) {
116  self.setFootprints(std::make_shared<FootprintSet::FootprintList>(footList));
117  });
118  // getFootprints returns shared_ptr<FootprintList>, but stl caster can't handle this
119  clsFootprintSet.def("getFootprints", [](FootprintSet &self) { return *(self.getFootprints()); });
120  clsFootprintSet.def("makeSources", &FootprintSet::makeSources);
121  clsFootprintSet.def("setRegion", &FootprintSet::setRegion);
122  clsFootprintSet.def("getRegion", &FootprintSet::getRegion);
123  clsFootprintSet.def("insertIntoImage", &FootprintSet::insertIntoImage);
124  clsFootprintSet.def("setMask", (void (FootprintSet::*)(image::Mask<lsst::afw::image::MaskPixel> *,
125  std::string const &)) &
126  FootprintSet::setMask<lsst::afw::image::MaskPixel>);
127  clsFootprintSet.def("setMask",
128  (void (FootprintSet::*)(std::shared_ptr<image::Mask<lsst::afw::image::MaskPixel>>,
129  std::string const &)) &
130  FootprintSet::setMask<lsst::afw::image::MaskPixel>);
131  clsFootprintSet.def("merge", &FootprintSet::merge, "rhs"_a, "tGrow"_a = 0, "rGrow"_a = 0,
132  "isotropic"_a = true);
133 
134  /* Module level */
135 
136  /* Member types and enums */
137 
138  return mod.ptr();
139 }
140 }
141 }
142 } // lsst::afw::detection
std::vector< std::shared_ptr< Footprint > > FootprintList
The FootprintSet&#39;s set of Footprints.
Definition: FootprintSet.h:56
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:43
PYBIND11_PLUGIN(_cameraPoint)
Definition: cameraPoint.cc:35
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:83
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:81
double const _a
Definition: RandomImage.cc:77
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:442
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:68