lsst.afw  13.0-49-g6f23dda
 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  clsFootprintSet.def("setFootprints", &FootprintSet::setFootprints);
105  // getFootprints returns shared_ptr<FootprintList>, but stl caster can't handle this
106  clsFootprintSet.def("getFootprints", [](FootprintSet &self) { return *(self.getFootprints()); });
107  clsFootprintSet.def("makeSources", &FootprintSet::makeSources);
108  clsFootprintSet.def("setRegion", &FootprintSet::setRegion);
109  clsFootprintSet.def("getRegion", &FootprintSet::getRegion);
110  clsFootprintSet.def("insertIntoImage", &FootprintSet::insertIntoImage);
111  clsFootprintSet.def("setMask", (void (FootprintSet::*)(image::Mask<lsst::afw::image::MaskPixel> *,
112  std::string const &)) &
113  FootprintSet::setMask<lsst::afw::image::MaskPixel>);
114  clsFootprintSet.def("setMask",
115  (void (FootprintSet::*)(std::shared_ptr<image::Mask<lsst::afw::image::MaskPixel>>,
116  std::string const &)) &
117  FootprintSet::setMask<lsst::afw::image::MaskPixel>);
118  clsFootprintSet.def("merge", &FootprintSet::merge, "rhs"_a, "tGrow"_a = 0, "rGrow"_a = 0,
119  "isotropic"_a = true);
120 
121  /* Module level */
122 
123  /* Member types and enums */
124 
125  return mod.ptr();
126 }
127 }
128 }
129 } // lsst::afw::detection
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:227
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
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:486