LSSTApplications  18.1.0
LSSTDataManagementBasePackage
_Box.cc
Go to the documentation of this file.
1 /*
2  * Developed for the LSST Data Management System.
3  * This product includes software developed by the LSST Project
4  * (https://www.lsst.org).
5  * See the COPYRIGHT file at the top-level directory of this distribution
6  * for details of code ownership.
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 GNU General Public License
19  * along with this program. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #include "pybind11/pybind11.h"
23 #include "pybind11/stl.h"
24 
25 #include "lsst/geom/Box.h"
26 #include "lsst/utils/python.h"
27 
28 namespace py = pybind11;
29 using namespace py::literals;
30 
31 namespace lsst {
32 namespace geom {
33 
35  wrappers.wrapType(
36  py::class_<Box2I, std::shared_ptr<Box2I>>(wrappers.module, "Box2I"),
37  [](auto & mod, auto & cls) mutable {
38 
39  cls.attr("Point") = mod.attr("Point2I");
40  cls.attr("Extent") = mod.attr("Extent2I");
41 
42  py::enum_<Box2I::EdgeHandlingEnum>(cls, "EdgeHandlingEnum")
43  .value("EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
44  .value("SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
45  .export_values();
46 
47  cls.def(py::init<>());
48  cls.def(py::init<Point2I const &, Point2I const &, bool>(), "minimum"_a, "maximum"_a,
49  "invert"_a = true);
50  cls.def(py::init<Point2I const &, Extent2I const &, bool>(), "corner"_a, "dimensions"_a,
51  "invert"_a = true);
52  cls.def(py::init<Box2D const &, Box2I::EdgeHandlingEnum>(), "other"_a,
53  "edgeHandling"_a = Box2I::EXPAND);
54  cls.def(py::init<Box2I const &>(), "other"_a);
55 
56  cls.def("__eq__", [](Box2I const &self, Box2I const &other) { return self == other; },
57  py::is_operator());
58  cls.def("__ne__", [](Box2I const &self, Box2I const &other) { return self != other; },
59  py::is_operator());
60 
61  cls.def_static("makeCenteredBox", &Box2I::makeCenteredBox, "center"_a, "size"_a);
62  cls.def("swap", &Box2I::swap);
63  cls.def("getMin", &Box2I::getMin);
64  cls.def("getMinX", &Box2I::getMinX);
65  cls.def("getMinY", &Box2I::getMinY);
66  cls.def("getMax", &Box2I::getMax);
67  cls.def("getMaxX", &Box2I::getMaxX);
68  cls.def("getMaxY", &Box2I::getMaxY);
69  cls.def("getBegin", &Box2I::getBegin);
70  cls.def("getBeginX", &Box2I::getBeginX);
71  cls.def("getBeginY", &Box2I::getBeginY);
72  cls.def("getEnd", &Box2I::getEnd);
73  cls.def("getEndX", &Box2I::getEndX);
74  cls.def("getEndY", &Box2I::getEndY);
75  cls.def("getDimensions", &Box2I::getDimensions);
76  cls.def("getWidth", &Box2I::getWidth);
77  cls.def("getHeight", &Box2I::getHeight);
78  cls.def("getArea", &Box2I::getArea);
79  cls.def("getCenter", &Box2I::getCenter);
80  cls.def("getCenterX", &Box2I::getCenterX);
81  cls.def("getCenterY", &Box2I::getCenterY);
82  cls.def("isEmpty", &Box2I::isEmpty);
83  cls.def("contains", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
84  cls.def("contains", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
85  cls.def("__contains__", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
86  cls.def("__contains__", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
87  cls.def("overlaps", &Box2I::overlaps);
88  cls.def("grow", (void (Box2I::*)(int)) & Box2I::grow);
89  cls.def("grow", (void (Box2I::*)(Extent2I const &)) & Box2I::grow);
90  cls.def("shift", &Box2I::shift);
91  cls.def("flipLR", &Box2I::flipLR);
92  cls.def("flipTB", &Box2I::flipTB);
93  cls.def("include", (void (Box2I::*)(Point2I const &)) & Box2I::include);
94  cls.def("include", (void (Box2I::*)(Box2I const &)) & Box2I::include);
95  cls.def("clip", &Box2I::clip);
96  cls.def("getCorners", &Box2I::getCorners);
97  cls.def("toString", &Box2I::toString);
98  cls.def("__repr__", [](Box2I const &self) {
99  return py::str("Box2I(minimum={}, dimensions={})")
100  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
101  });
102  cls.def("__str__", [](Box2I const &self) {
103  return py::str("(minimum={}, maximum={})")
104  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
105  });
106  cls.def("__reduce__", [cls](Box2I const &self) {
107  return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
108  });
109  cls.def("getSlices", [](Box2I const &self) {
110  return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
111  py::slice(self.getBeginX(), self.getEndX(), 1));
112  });
113 
114  mod.attr("BoxI") = cls;
115  }
116  );
117 
118  wrappers.wrapType(
119  py::class_<Box2D, std::shared_ptr<Box2D>>(wrappers.module, "Box2D"),
120  [](auto & mod, auto & cls) mutable {
121 
122  cls.attr("Point") = mod.attr("Point2D");
123  cls.attr("Extent") = mod.attr("Extent2D");
124 
125  cls.attr("EPSILON") = py::float_(Box2D::EPSILON);
126  cls.attr("INVALID") = py::float_(Box2D::INVALID);
127 
128  cls.def(py::init<>());
129  cls.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
130  "invert"_a = true);
131  cls.def(py::init<Point2D const &, Extent2D const &, bool>(), "corner"_a, "dimensions"_a,
132  "invert"_a = true);
133  cls.def(py::init<Box2I const &>());
134  cls.def(py::init<Box2D const &>());
135 
136  cls.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
137  py::is_operator());
138  cls.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
139  py::is_operator());
140 
141  cls.def_static("makeCenteredBox", &Box2D::makeCenteredBox, "center"_a, "size"_a);
142  cls.def("swap", &Box2D::swap);
143  cls.def("getMin", &Box2D::getMin);
144  cls.def("getMinX", &Box2D::getMinX);
145  cls.def("getMinY", &Box2D::getMinY);
146  cls.def("getMax", &Box2D::getMax);
147  cls.def("getMaxX", &Box2D::getMaxX);
148  cls.def("getMaxY", &Box2D::getMaxY);
149  cls.def("getDimensions", &Box2D::getDimensions);
150  cls.def("getWidth", &Box2D::getWidth);
151  cls.def("getHeight", &Box2D::getHeight);
152  cls.def("getArea", &Box2D::getArea);
153  cls.def("getCenter", &Box2D::getCenter);
154  cls.def("getCenterX", &Box2D::getCenterX);
155  cls.def("getCenterY", &Box2D::getCenterY);
156  cls.def("isEmpty", &Box2D::isEmpty);
157  cls.def("contains", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
158  cls.def("contains", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
159  cls.def("__contains__", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
160  cls.def("__contains__", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
161  cls.def("overlaps", &Box2D::overlaps);
162  cls.def("grow", (void (Box2D::*)(double)) & Box2D::grow);
163  cls.def("grow", (void (Box2D::*)(Extent2D const &)) & Box2D::grow);
164  cls.def("overlaps", (void (Box2D::*)(Extent2D const &)) & Box2D::overlaps);
165  cls.def("shift", &Box2D::shift);
166  cls.def("flipLR", &Box2D::flipLR);
167  cls.def("flipTB", &Box2D::flipTB);
168  cls.def("include", (void (Box2D::*)(Point2D const &)) & Box2D::include);
169  cls.def("include", (void (Box2D::*)(Box2D const &)) & Box2D::include);
170  cls.def("clip", &Box2D::clip);
171  cls.def("getCorners", &Box2D::getCorners);
172  cls.def("toString", &Box2D::toString);
173  cls.def("__repr__", [](Box2D const &self) {
174  return py::str("Box2D(minimum={}, dimensions={})")
175  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
176  });
177  cls.def("__str__", [](Box2D const &self) {
178  return py::str("(minimum={}, maximum={})")
179  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
180  });
181  cls.def("__reduce__", [cls](Box2D const &self) {
182  return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
183  });
184 
185  mod.attr("BoxD") = cls;
186  }
187  );
188 }
189 
190 } // namespace geom
191 } // namespace lsst
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
A floating-point coordinate rectangle geometry.
Definition: Box.h:305
pybind11::module module
The module object passed to the PYBIND11_MODULE block that contains this WrapperCollection.
Definition: python.h:448
void wrapBox(utils::python::WrapperCollection &wrappers)
Definition: _Box.cc:34
A base class for image defects.
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:471
ItemVariant const * other
Definition: Schema.cc:56
A helper class for subdividing pybind11 module across multiple translation units (i.e.
Definition: python.h:242
An integer coordinate rectangle.
Definition: Box.h:54
PyType wrapType(PyType cls, ClassWrapperCallback function, bool setModuleName=true)
Add a type (class or enum) wrapper, deferring method and other attribute definitions until finish() i...
Definition: python.h:391