LSSTApplications  16.0-1-gce273f5+15,16.0-1-gf77f410+8,16.0-10-g230e10e+8,16.0-10-g5a5abec+4,16.0-10-gc1446dd+8,16.0-11-g5cf5345,16.0-12-g1dc09ba+2,16.0-12-g726f8f3+6,16.0-13-g4c33ca5+8,16.0-13-g5f6c0b1+8,16.0-13-gd9b1b71+8,16.0-14-g71e547a+4,16.0-17-g0bdc215,16.0-17-g6a7bfb3b+8,16.0-18-g95848a16+2,16.0-2-g0febb12+12,16.0-2-g839ba83+46,16.0-2-g9d5294e+35,16.0-3-g404ea43+7,16.0-3-gbc759ec+6,16.0-3-gcfd6c53+33,16.0-4-g03cf288+24,16.0-4-g13a27c5+10,16.0-4-g2cc461c+3,16.0-4-g5f3a788+11,16.0-4-g8a0f11a+30,16.0-4-ga3eb747+1,16.0-43-gaa65a4573+4,16.0-5-g1991253+8,16.0-5-g865efd9+8,16.0-5-gb3f8a4b+40,16.0-5-gd0f1235+4,16.0-6-g316b399+8,16.0-6-gf0acd13+27,16.0-6-gf9cb114+9,16.0-7-ga8e1655+4,16.0-8-g23bbf3f+1,16.0-8-g4dec96c+21,16.0-8-gfd407c0,w.2018.39
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 
37 PYBIND11_MODULE(box, mod) {
38  py::object modCoordinates = py::module::import("lsst.geom.coordinates");
39 
40  /* Box2UI */
41 
42  PyBox2I clsBox2I(mod, "Box2I");
43 
44  clsBox2I.attr("Point") = modCoordinates.attr("Point2I");
45  clsBox2I.attr("Extent") = modCoordinates.attr("Extent2I");
46 
47  py::enum_<Box2I::EdgeHandlingEnum>(clsBox2I, "EdgeHandlingEnum")
48  .value("EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
49  .value("SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
50  .export_values();
51 
52  clsBox2I.def(py::init<>());
53  clsBox2I.def(py::init<Point2I const &, Point2I const &, bool>(), "minimum"_a, "maximum"_a,
54  "invert"_a = true);
55  clsBox2I.def(py::init<Point2I const &, Extent2I const &, bool>(), "corner"_a, "dimensions"_a,
56  "invert"_a = true);
57  clsBox2I.def(py::init<Box2D const &, Box2I::EdgeHandlingEnum>(), "other"_a,
58  "edgeHandling"_a = Box2I::EXPAND);
59  clsBox2I.def(py::init<Box2I const &>(), "other"_a);
60 
61  clsBox2I.def("__eq__", [](Box2I const &self, Box2I const &other) { return self == other; },
62  py::is_operator());
63  clsBox2I.def("__ne__", [](Box2I const &self, Box2I const &other) { return self != other; },
64  py::is_operator());
65 
66  clsBox2I.def_static("makeCenteredBox", &Box2I::makeCenteredBox, "center"_a, "size"_a);
67  clsBox2I.def("swap", &Box2I::swap);
68  clsBox2I.def("getMin", &Box2I::getMin);
69  clsBox2I.def("getMinX", &Box2I::getMinX);
70  clsBox2I.def("getMinY", &Box2I::getMinY);
71  clsBox2I.def("getMax", &Box2I::getMax);
72  clsBox2I.def("getMaxX", &Box2I::getMaxX);
73  clsBox2I.def("getMaxY", &Box2I::getMaxY);
74  clsBox2I.def("getBegin", &Box2I::getBegin);
75  clsBox2I.def("getBeginX", &Box2I::getBeginX);
76  clsBox2I.def("getBeginY", &Box2I::getBeginY);
77  clsBox2I.def("getEnd", &Box2I::getEnd);
78  clsBox2I.def("getEndX", &Box2I::getEndX);
79  clsBox2I.def("getEndY", &Box2I::getEndY);
80  clsBox2I.def("getDimensions", &Box2I::getDimensions);
81  clsBox2I.def("getWidth", &Box2I::getWidth);
82  clsBox2I.def("getHeight", &Box2I::getHeight);
83  clsBox2I.def("getArea", &Box2I::getArea);
84  clsBox2I.def("isEmpty", &Box2I::isEmpty);
85  clsBox2I.def("contains", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
86  clsBox2I.def("contains", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
87  clsBox2I.def("__contains__", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
88  clsBox2I.def("__contains__", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
89  clsBox2I.def("overlaps", &Box2I::overlaps);
90  clsBox2I.def("grow", (void (Box2I::*)(int)) & Box2I::grow);
91  clsBox2I.def("grow", (void (Box2I::*)(Extent2I const &)) & Box2I::grow);
92  clsBox2I.def("shift", &Box2I::shift);
93  clsBox2I.def("flipLR", &Box2I::flipLR);
94  clsBox2I.def("flipTB", &Box2I::flipTB);
95  clsBox2I.def("include", (void (Box2I::*)(Point2I const &)) & Box2I::include);
96  clsBox2I.def("include", (void (Box2I::*)(Box2I const &)) & Box2I::include);
97  clsBox2I.def("clip", &Box2I::clip);
98  clsBox2I.def("getCorners", &Box2I::getCorners);
99  clsBox2I.def("toString", &Box2I::toString);
100  clsBox2I.def("__repr__", [](Box2I const &self) {
101  return py::str("Box2I(minimum={}, dimensions={})")
102  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
103  });
104  clsBox2I.def("__str__", [](Box2I const &self) {
105  return py::str("(minimum={}, maximum={})")
106  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
107  });
108  clsBox2I.def("__reduce__", [clsBox2I](Box2I const &self) {
109  return py::make_tuple(clsBox2I, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
110  });
111  clsBox2I.def("getSlices", [](Box2I const &self) {
112  return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
113  py::slice(self.getBeginX(), self.getEndX(), 1));
114  });
115 
116  /* Box2D */
117 
118  PyBox2D clsBox2D(mod, "Box2D");
119 
120  clsBox2D.attr("Point") = modCoordinates.attr("Point2D");
121  clsBox2D.attr("Extent") = modCoordinates.attr("Extent2D");
122 
123  clsBox2D.attr("EPSILON") = py::float_(Box2D::EPSILON);
124  clsBox2D.attr("INVALID") = py::float_(Box2D::INVALID);
125 
126  clsBox2D.def(py::init<>());
127  clsBox2D.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
128  "invert"_a = true);
129  clsBox2D.def(py::init<Point2D const &, Extent2D const &, bool>(), "corner"_a, "dimensions"_a,
130  "invert"_a = true);
131  clsBox2D.def(py::init<Box2I const &>());
132  clsBox2D.def(py::init<Box2D const &>());
133 
134  clsBox2D.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
135  py::is_operator());
136  clsBox2D.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
137  py::is_operator());
138 
139  clsBox2D.def_static("makeCenteredBox", &Box2D::makeCenteredBox, "center"_a, "size"_a);
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 
188 } // namespace
189 } // namespace geom
190 } // 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:324
A base class for image defects.
Definition: cameraGeom.dox:3
PYBIND11_MODULE(cameraSys, mod)
Definition: cameraSys.cc:62
Point< int, 2 > Point2I
Definition: Point.h:321
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:473
Extent< int, 2 > Extent2I
Definition: Extent.h:393
ItemVariant const * other
Definition: Schema.cc:55
Extent< double, 2 > Extent2D
Definition: Extent.h:396