LSSTApplications  16.0-10-g0ee56ad+5,16.0-11-ga33d1f2+5,16.0-12-g3ef5c14+3,16.0-12-g71e5ef5+18,16.0-12-gbdf3636+3,16.0-13-g118c103+3,16.0-13-g8f68b0a+3,16.0-15-gbf5c1cb+4,16.0-16-gfd17674+3,16.0-17-g7c01f5c+3,16.0-18-g0a50484+1,16.0-20-ga20f992+8,16.0-21-g0e05fd4+6,16.0-21-g15e2d33+4,16.0-22-g62d8060+4,16.0-22-g847a80f+4,16.0-25-gf00d9b8+1,16.0-28-g3990c221+4,16.0-3-gf928089+3,16.0-32-g88a4f23+5,16.0-34-gd7987ad+3,16.0-37-gc7333cb+2,16.0-4-g10fc685+2,16.0-4-g18f3627+26,16.0-4-g5f3a788+26,16.0-5-gaf5c3d7+4,16.0-5-gcc1f4bb+1,16.0-6-g3b92700+4,16.0-6-g4412fcd+3,16.0-6-g7235603+4,16.0-69-g2562ce1b+2,16.0-8-g14ebd58+4,16.0-8-g2df868b+1,16.0-8-g4cec79c+6,16.0-8-gadf6c7a+1,16.0-8-gfc7ad86,16.0-82-g59ec2a54a+1,16.0-9-g5400cdc+2,16.0-9-ge6233d7+5,master-g2880f2d8cf+3,v17.0.rc1
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("isEmpty", &Box2I::isEmpty);
80  cls.def("contains", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
81  cls.def("contains", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
82  cls.def("__contains__", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
83  cls.def("__contains__", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
84  cls.def("overlaps", &Box2I::overlaps);
85  cls.def("grow", (void (Box2I::*)(int)) & Box2I::grow);
86  cls.def("grow", (void (Box2I::*)(Extent2I const &)) & Box2I::grow);
87  cls.def("shift", &Box2I::shift);
88  cls.def("flipLR", &Box2I::flipLR);
89  cls.def("flipTB", &Box2I::flipTB);
90  cls.def("include", (void (Box2I::*)(Point2I const &)) & Box2I::include);
91  cls.def("include", (void (Box2I::*)(Box2I const &)) & Box2I::include);
92  cls.def("clip", &Box2I::clip);
93  cls.def("getCorners", &Box2I::getCorners);
94  cls.def("toString", &Box2I::toString);
95  cls.def("__repr__", [](Box2I const &self) {
96  return py::str("Box2I(minimum={}, dimensions={})")
97  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
98  });
99  cls.def("__str__", [](Box2I const &self) {
100  return py::str("(minimum={}, maximum={})")
101  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
102  });
103  cls.def("__reduce__", [cls](Box2I const &self) {
104  return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
105  });
106  cls.def("getSlices", [](Box2I const &self) {
107  return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
108  py::slice(self.getBeginX(), self.getEndX(), 1));
109  });
110 
111  mod.attr("BoxI") = cls;
112  }
113  );
114 
115  wrappers.wrapType(
116  py::class_<Box2D, std::shared_ptr<Box2D>>(wrappers.module, "Box2D"),
117  [](auto & mod, auto & cls) mutable {
118 
119  cls.attr("Point") = mod.attr("Point2D");
120  cls.attr("Extent") = mod.attr("Extent2D");
121 
122  cls.attr("EPSILON") = py::float_(Box2D::EPSILON);
123  cls.attr("INVALID") = py::float_(Box2D::INVALID);
124 
125  cls.def(py::init<>());
126  cls.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
127  "invert"_a = true);
128  cls.def(py::init<Point2D const &, Extent2D const &, bool>(), "corner"_a, "dimensions"_a,
129  "invert"_a = true);
130  cls.def(py::init<Box2I const &>());
131  cls.def(py::init<Box2D const &>());
132 
133  cls.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
134  py::is_operator());
135  cls.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
136  py::is_operator());
137 
138  cls.def_static("makeCenteredBox", &Box2D::makeCenteredBox, "center"_a, "size"_a);
139  cls.def("swap", &Box2D::swap);
140  cls.def("getMin", &Box2D::getMin);
141  cls.def("getMinX", &Box2D::getMinX);
142  cls.def("getMinY", &Box2D::getMinY);
143  cls.def("getMax", &Box2D::getMax);
144  cls.def("getMaxX", &Box2D::getMaxX);
145  cls.def("getMaxY", &Box2D::getMaxY);
146  cls.def("getDimensions", &Box2D::getDimensions);
147  cls.def("getWidth", &Box2D::getWidth);
148  cls.def("getHeight", &Box2D::getHeight);
149  cls.def("getArea", &Box2D::getArea);
150  cls.def("getCenter", &Box2D::getCenter);
151  cls.def("getCenterX", &Box2D::getCenterX);
152  cls.def("getCenterY", &Box2D::getCenterY);
153  cls.def("isEmpty", &Box2D::isEmpty);
154  cls.def("contains", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
155  cls.def("contains", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
156  cls.def("__contains__", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
157  cls.def("__contains__", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
158  cls.def("overlaps", &Box2D::overlaps);
159  cls.def("grow", (void (Box2D::*)(double)) & Box2D::grow);
160  cls.def("grow", (void (Box2D::*)(Extent2D const &)) & Box2D::grow);
161  cls.def("overlaps", (void (Box2D::*)(Extent2D const &)) & Box2D::overlaps);
162  cls.def("shift", &Box2D::shift);
163  cls.def("flipLR", &Box2D::flipLR);
164  cls.def("flipTB", &Box2D::flipTB);
165  cls.def("include", (void (Box2D::*)(Point2D const &)) & Box2D::include);
166  cls.def("include", (void (Box2D::*)(Box2D const &)) & Box2D::include);
167  cls.def("clip", &Box2D::clip);
168  cls.def("getCorners", &Box2D::getCorners);
169  cls.def("toString", &Box2D::toString);
170  cls.def("__repr__", [](Box2D const &self) {
171  return py::str("Box2D(minimum={}, dimensions={})")
172  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
173  });
174  cls.def("__str__", [](Box2D const &self) {
175  return py::str("(minimum={}, maximum={})")
176  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
177  });
178  cls.def("__reduce__", [cls](Box2D const &self) {
179  return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
180  });
181 
182  mod.attr("BoxD") = cls;
183  }
184  );
185 }
186 
187 } // namespace geom
188 } // namespace lsst
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
A floating-point coordinate rectangle geometry.
Definition: Box.h:294
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:465
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