LSSTApplications  18.1.0
LSSTDataManagementBasePackage
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 
38 template <typename PixelT, typename PyClass>
39 void declareMakeHeavy(PyClass &cls) {
40  // cls.def("makeHeavy", [](FootprintSet & self, image::MaskedImage<PixelT, image::MaskPixel> const&
41  // mimg) {
42  // return self.makeHeavy(mimg);
43  // });
44  // cls.def("makeHeavy", [](FootprintSet & self, image::MaskedImage<PixelT, image::MaskPixel> const&
45  // mimg, HeavyFootprintCtrl const* ctrl) {
46  // return self.makeHeavy(mimg, ctrl);
47  // });
48  cls.def("makeHeavy", (void (FootprintSet::*)(image::MaskedImage<PixelT, image::MaskPixel> const &,
49  HeavyFootprintCtrl const *)) &
50  FootprintSet::makeHeavy<PixelT, image::MaskPixel>,
51  "mimg"_a, "ctrl"_a = nullptr);
52 }
53 
54 template <typename PixelT, typename PyClass>
55 void declareSetMask(PyClass &cls) {
56  cls.def("setMask", (void (FootprintSet::*)(image::Mask<PixelT> *, std::string const &)) &
57  FootprintSet::setMask<PixelT>,
58  "mask"_a, "planeName"_a);
59 }
60 
61 template <typename PixelT, typename PyClass>
62 void declareTemplatedMembers(PyClass &cls) {
63  /* Constructors */
64  cls.def(py::init<image::Image<PixelT> const &, Threshold const &, int const, bool const>(), "img"_a,
65  "threshold"_a, "npixMin"_a = 1, "setPeaks"_a = true);
66  cls.def(py::init<image::MaskedImage<PixelT, image::MaskPixel> const &, Threshold const &,
67  std::string const &, int const, bool const>(),
68  "img"_a, "threshold"_a, "planeName"_a = "", "npixMin"_a = 1, "setPeaks"_a = true);
69 
70  /* Members */
71  declareMakeHeavy<int>(cls);
72  declareMakeHeavy<float>(cls);
73  declareMakeHeavy<double>(cls);
74  declareMakeHeavy<std::uint16_t>(cls);
75  // declareMakeHeavy<std::uint64_t>(cls);
76  declareSetMask<image::MaskPixel>(cls);
77 }
78 } // namespace
79 
81  py::module::import("lsst.afw.detection.footprint");
82 
83  py::class_<FootprintSet, std::shared_ptr<FootprintSet>, lsst::daf::base::Citizen> clsFootprintSet(
84  mod, "FootprintSet");
85 
86  declareTemplatedMembers<std::uint16_t>(clsFootprintSet);
87  declareTemplatedMembers<int>(clsFootprintSet);
88  declareTemplatedMembers<float>(clsFootprintSet);
89  declareTemplatedMembers<double>(clsFootprintSet);
90 
91  clsFootprintSet.def(py::init<image::Mask<image::MaskPixel> const &, Threshold const &, int const>(),
92  "img"_a, "threshold"_a, "npixMin"_a = 1);
93 
94  /* Members */
95  clsFootprintSet.def(py::init<lsst::geom::Box2I>(), "region"_a);
96  clsFootprintSet.def(py::init<FootprintSet const &>(), "set"_a);
97  clsFootprintSet.def(py::init<FootprintSet const &, int, FootprintControl const &>(), "set"_a, "rGrow"_a,
98  "ctrl"_a);
99  clsFootprintSet.def(py::init<FootprintSet const &, int, bool>(), "set"_a, "rGrow"_a, "isotropic"_a);
100  clsFootprintSet.def(py::init<FootprintSet const &, FootprintSet const &, bool>(), "footprints1"_a,
101  "footprints2"_a, "includePeaks"_a);
102 
103  clsFootprintSet.def("swap", &FootprintSet::swap);
104  // setFootprints takes shared_ptr<FootprintList> and getFootprints returns it,
105  // but pybind11 can't handle that type, so use a custom getter and setter
106  clsFootprintSet.def("setFootprints", [](FootprintSet &self, FootprintSet::FootprintList footList) {
107  self.setFootprints(std::make_shared<FootprintSet::FootprintList>(std::move(footList)));
108  });
109  clsFootprintSet.def("getFootprints", [](FootprintSet &self) { return *(self.getFootprints()); });
110  clsFootprintSet.def("makeSources", &FootprintSet::makeSources);
111  clsFootprintSet.def("setRegion", &FootprintSet::setRegion);
112  clsFootprintSet.def("getRegion", &FootprintSet::getRegion);
113  clsFootprintSet.def("insertIntoImage", &FootprintSet::insertIntoImage);
114  clsFootprintSet.def("setMask", (void (FootprintSet::*)(image::Mask<lsst::afw::image::MaskPixel> *,
115  std::string const &)) &
116  FootprintSet::setMask<lsst::afw::image::MaskPixel>);
117  clsFootprintSet.def("setMask",
119  std::string const &)) &
120  FootprintSet::setMask<lsst::afw::image::MaskPixel>);
121  clsFootprintSet.def("merge", &FootprintSet::merge, "rhs"_a, "tGrow"_a = 0, "rGrow"_a = 0,
122  "isotropic"_a = true);
123 
124  /* Module level */
125 
126  /* Member types and enums */
127 }
128 }
129 }
130 } // lsst::afw::detection
def init()
Definition: tests.py:75
A Threshold is used to pass a threshold value to detection algorithms.
Definition: Threshold.h:43
STL class.
A base class for image defects.
Represent a 2-dimensional array of bitmask pixels.
Definition: Mask.h:78
PYBIND11_MODULE(footprintSet, mod)
Definition: footprintSet.cc:80
A class to manipulate images, masks, and variance as a single object.
Definition: MaskedImage.h:74
T move(T... args)
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:471
A set of Footprints, associated with a MaskedImage.
Definition: FootprintSet.h:53
STL class.
Citizen is a class that should be among all LSST classes base classes, and handles basic memory manag...
Definition: Citizen.h:55
A class to represent a 2-dimensional array of pixels.
Definition: Image.h:59