LSSTApplications  12.1-5-gbdcc3ab+2,15.0+14,15.0+30,15.0-1-g19261fa+21,15.0-1-g417ea41,15.0-1-g60afb23+30,15.0-1-g615e0bb+22,15.0-1-g788a293+30,15.0-1-ga91101e+30,15.0-1-gae1598d+13,15.0-1-gd076f1f+28,15.0-1-gdf18595+5,15.0-12-g3681e7a+8,15.0-12-g7952b551+2,15.0-16-g6f0eb036+3,15.0-17-g076ea75+3,15.0-2-g100d730+23,15.0-2-g8aea5f4+1,15.0-2-gf38729e+25,15.0-2-gf60f3cf,15.0-3-g707930d+3,15.0-3-g9103c06+12,15.0-30-g9378914ca+1,15.0-4-g9ee0f43+3,15.0-4-gf6f1c6c+3,15.0-4-gf906033+2,15.0-5-g23e394c+18,15.0-5-g4be42a9+4,15.0-5-gae1eaf0+3,15.0-6-g09241ba+6,15.0-6-g69628aa+4,15.0-6-g81517ef+3,15.0-6-gc1213af+3,15.0-6-gfa9b38f+8,15.0-7-ged79c87+3,15.0-8-g13fca11+3,15.0-8-g67a62d3+5,15.0-8-gcf05001+5,15.0-9-g1e7c341+2,w.2018.25
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 
27 namespace py = pybind11;
28 using namespace py::literals;
29 
30 namespace lsst {
31 namespace geom {
32 namespace {
33 
34 using PyBox2I = py::class_<Box2I, std::shared_ptr<Box2I>>;
35 using PyBox2D = py::class_<Box2D, std::shared_ptr<Box2D>>;
36 
38  py::module mod("box");
39 
40  py::object modCoordinates = py::module::import("lsst.geom.coordinates");
41 
42  /* Box2UI */
43 
44  PyBox2I clsBox2I(mod, "Box2I");
45 
46  clsBox2I.attr("Point") = modCoordinates.attr("Point2I");
47  clsBox2I.attr("Extent") = modCoordinates.attr("Extent2I");
48 
49  py::enum_<Box2I::EdgeHandlingEnum>(clsBox2I, "EdgeHandlingEnum")
50  .value("EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
51  .value("SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
52  .export_values();
53 
54  clsBox2I.def(py::init<>());
55  clsBox2I.def(py::init<Point2I const &, Point2I const &, bool>(), "minimum"_a, "maximum"_a,
56  "invert"_a = true);
57  clsBox2I.def(py::init<Point2I const &, Extent2I const &, bool>(), "minimum"_a, "dimensions"_a,
58  "invert"_a = true);
59  clsBox2I.def(py::init<Box2D const &, Box2I::EdgeHandlingEnum>(), "other"_a,
60  "edgeHandling"_a = Box2I::EXPAND);
61  clsBox2I.def(py::init<Box2I const &>(), "other"_a);
62 
63  clsBox2I.def("__eq__", [](Box2I const &self, Box2I const &other) { return self == other; },
64  py::is_operator());
65  clsBox2I.def("__ne__", [](Box2I const &self, Box2I const &other) { return self != other; },
66  py::is_operator());
67 
68  clsBox2I.def("swap", &Box2I::swap);
69  clsBox2I.def("getMin", &Box2I::getMin);
70  clsBox2I.def("getMinX", &Box2I::getMinX);
71  clsBox2I.def("getMinY", &Box2I::getMinY);
72  clsBox2I.def("getMax", &Box2I::getMax);
73  clsBox2I.def("getMaxX", &Box2I::getMaxX);
74  clsBox2I.def("getMaxY", &Box2I::getMaxY);
75  clsBox2I.def("getBegin", &Box2I::getBegin);
76  clsBox2I.def("getBeginX", &Box2I::getBeginX);
77  clsBox2I.def("getBeginY", &Box2I::getBeginY);
78  clsBox2I.def("getEnd", &Box2I::getEnd);
79  clsBox2I.def("getEndX", &Box2I::getEndX);
80  clsBox2I.def("getEndY", &Box2I::getEndY);
81  clsBox2I.def("getDimensions", &Box2I::getDimensions);
82  clsBox2I.def("getWidth", &Box2I::getWidth);
83  clsBox2I.def("getHeight", &Box2I::getHeight);
84  clsBox2I.def("getArea", &Box2I::getArea);
85  clsBox2I.def("isEmpty", &Box2I::isEmpty);
86  clsBox2I.def("contains", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
87  clsBox2I.def("contains", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
88  clsBox2I.def("__contains__", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
89  clsBox2I.def("__contains__", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
90  clsBox2I.def("overlaps", &Box2I::overlaps);
91  clsBox2I.def("grow", (void (Box2I::*)(int)) & Box2I::grow);
92  clsBox2I.def("grow", (void (Box2I::*)(Extent2I const &)) & Box2I::grow);
93  clsBox2I.def("shift", &Box2I::shift);
94  clsBox2I.def("flipLR", &Box2I::flipLR);
95  clsBox2I.def("flipTB", &Box2I::flipTB);
96  clsBox2I.def("include", (void (Box2I::*)(Point2I const &)) & Box2I::include);
97  clsBox2I.def("include", (void (Box2I::*)(Box2I const &)) & Box2I::include);
98  clsBox2I.def("clip", &Box2I::clip);
99  clsBox2I.def("getCorners", &Box2I::getCorners);
100  clsBox2I.def("toString", &Box2I::toString);
101  clsBox2I.def("__repr__", [](Box2I const &self) {
102  return py::str("Box2I(minimum={}, dimensions={})")
103  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
104  });
105  clsBox2I.def("__str__", [](Box2I const &self) {
106  return py::str("(minimum={}, maximum={})")
107  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
108  });
109  clsBox2I.def("__reduce__", [clsBox2I](Box2I const &self) {
110  return py::make_tuple(clsBox2I, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
111  });
112  clsBox2I.def("getSlices", [](Box2I const &self) {
113  return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
114  py::slice(self.getBeginX(), self.getEndX(), 1));
115  });
116 
117  /* Box2D */
118 
119  PyBox2D clsBox2D(mod, "Box2D");
120 
121  clsBox2D.attr("Point") = modCoordinates.attr("Point2D");
122  clsBox2D.attr("Extent") = modCoordinates.attr("Extent2D");
123 
124  clsBox2D.attr("EPSILON") = py::float_(Box2D::EPSILON);
125  clsBox2D.attr("INVALID") = py::float_(Box2D::INVALID);
126 
127  clsBox2D.def(py::init<>());
128  clsBox2D.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
129  "invert"_a = true);
130  clsBox2D.def(py::init<Point2D const &, Extent2D const &, bool>(), "minimum"_a, "dimensions"_a,
131  "invert"_a = true);
132  clsBox2D.def(py::init<Box2I const &>());
133  clsBox2D.def(py::init<Box2D const &>());
134 
135  clsBox2D.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
136  py::is_operator());
137  clsBox2D.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
138  py::is_operator());
139 
140  clsBox2D.def("swap", &Box2D::swap);
141  clsBox2D.def("getMin", &Box2D::getMin);
142  clsBox2D.def("getMinX", &Box2D::getMinX);
143  clsBox2D.def("getMinY", &Box2D::getMinY);
144  clsBox2D.def("getMax", &Box2D::getMax);
145  clsBox2D.def("getMaxX", &Box2D::getMaxX);
146  clsBox2D.def("getMaxY", &Box2D::getMaxY);
147  clsBox2D.def("getDimensions", &Box2D::getDimensions);
148  clsBox2D.def("getWidth", &Box2D::getWidth);
149  clsBox2D.def("getHeight", &Box2D::getHeight);
150  clsBox2D.def("getArea", &Box2D::getArea);
151  clsBox2D.def("getCenter", &Box2D::getCenter);
152  clsBox2D.def("getCenterX", &Box2D::getCenterX);
153  clsBox2D.def("getCenterY", &Box2D::getCenterY);
154  clsBox2D.def("isEmpty", &Box2D::isEmpty);
155  clsBox2D.def("contains", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
156  clsBox2D.def("contains", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
157  clsBox2D.def("__contains__", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
158  clsBox2D.def("__contains__", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
159  clsBox2D.def("overlaps", &Box2D::overlaps);
160  clsBox2D.def("grow", (void (Box2D::*)(double)) & Box2D::grow);
161  clsBox2D.def("grow", (void (Box2D::*)(Extent2D const &)) & Box2D::grow);
162  clsBox2D.def("overlaps", (void (Box2D::*)(Extent2D const &)) & Box2D::overlaps);
163  clsBox2D.def("shift", &Box2D::shift);
164  clsBox2D.def("flipLR", &Box2D::flipLR);
165  clsBox2D.def("flipTB", &Box2D::flipTB);
166  clsBox2D.def("include", (void (Box2D::*)(Point2D const &)) & Box2D::include);
167  clsBox2D.def("include", (void (Box2D::*)(Box2D const &)) & Box2D::include);
168  clsBox2D.def("clip", &Box2D::clip);
169  clsBox2D.def("getCorners", &Box2D::getCorners);
170  clsBox2D.def("toString", &Box2D::toString);
171  clsBox2D.def("__repr__", [](Box2D const &self) {
172  return py::str("Box2D(minimum={}, dimensions={})")
173  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
174  });
175  clsBox2D.def("__str__", [](Box2D const &self) {
176  return py::str("(minimum={}, maximum={})")
177  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
178  });
179  clsBox2D.def("__reduce__", [clsBox2D](Box2D const &self) {
180  return py::make_tuple(clsBox2D, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
181  });
182 
183  /* module-level typedefs */
184  mod.attr("BoxI") = clsBox2I;
185  mod.attr("BoxD") = clsBox2D;
186 
187  return mod.ptr();
188 }
189 
190 } // namespace
191 } // namespace geom
192 } // namespace lsst
constexpr double EPSILON
Definition: constants.h:54
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
T make_tuple(T... args)
Point< double, 2 > Point2D
Definition: Point.h:300
PYBIND11_PLUGIN(_cameraSys)
Definition: cameraSys.cc:62
A base class for image defects.
Definition: cameraGeom.dox:3
Point< int, 2 > Point2I
Definition: Point.h:297
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:448
Extent< int, 2 > Extent2I
Definition: Extent.h:376
ItemVariant const * other
Definition: Schema.cc:55
Extent< double, 2 > Extent2D
Definition: Extent.h:379