LSSTApplications  15.0+21,16.0+1,16.0+10,16.0+3,16.0+4,16.0-1-g2115a9e+4,16.0-1-g4515a79+8,16.0-1-g7bb14cc,16.0-1-g80120d7+6,16.0-1-g98efed3+6,16.0-1-gb7f560d+3,16.0-18-g7a076d417,16.0-2-g2ed7261+3,16.0-2-g311bfd2,16.0-2-g568a347+5,16.0-2-g7adb079,16.0-2-gd4c87cb+5,16.0-3-g099ede0,16.0-3-g150e024+5,16.0-3-g1f513a6+2,16.0-3-g958ce35,16.0-3-gc6a11d1,16.0-4-g84f75fb+7,16.0-4-gcfd1396+6,16.0-4-gde8cee2,16.0-5-g7bc0afb+5,16.0-5-g81851deb,16.0-5-g82b7855+1,16.0-5-gd32631f,16.0-5-gf14cb0b,16.0-6-g2dd73041+6,16.0-6-gcf12234+1,16.0-7-g95fb7bf+2,16.0-7-gc37dbc2+6,w.2018.28
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>(), "corner"_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_static("makeCenteredBox", &Box2I::makeCenteredBox, "center"_a, "size"_a);
69  clsBox2I.def("swap", &Box2I::swap);
70  clsBox2I.def("getMin", &Box2I::getMin);
71  clsBox2I.def("getMinX", &Box2I::getMinX);
72  clsBox2I.def("getMinY", &Box2I::getMinY);
73  clsBox2I.def("getMax", &Box2I::getMax);
74  clsBox2I.def("getMaxX", &Box2I::getMaxX);
75  clsBox2I.def("getMaxY", &Box2I::getMaxY);
76  clsBox2I.def("getBegin", &Box2I::getBegin);
77  clsBox2I.def("getBeginX", &Box2I::getBeginX);
78  clsBox2I.def("getBeginY", &Box2I::getBeginY);
79  clsBox2I.def("getEnd", &Box2I::getEnd);
80  clsBox2I.def("getEndX", &Box2I::getEndX);
81  clsBox2I.def("getEndY", &Box2I::getEndY);
82  clsBox2I.def("getDimensions", &Box2I::getDimensions);
83  clsBox2I.def("getWidth", &Box2I::getWidth);
84  clsBox2I.def("getHeight", &Box2I::getHeight);
85  clsBox2I.def("getArea", &Box2I::getArea);
86  clsBox2I.def("isEmpty", &Box2I::isEmpty);
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("__contains__", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
90  clsBox2I.def("__contains__", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
91  clsBox2I.def("overlaps", &Box2I::overlaps);
92  clsBox2I.def("grow", (void (Box2I::*)(int)) & Box2I::grow);
93  clsBox2I.def("grow", (void (Box2I::*)(Extent2I const &)) & Box2I::grow);
94  clsBox2I.def("shift", &Box2I::shift);
95  clsBox2I.def("flipLR", &Box2I::flipLR);
96  clsBox2I.def("flipTB", &Box2I::flipTB);
97  clsBox2I.def("include", (void (Box2I::*)(Point2I const &)) & Box2I::include);
98  clsBox2I.def("include", (void (Box2I::*)(Box2I const &)) & Box2I::include);
99  clsBox2I.def("clip", &Box2I::clip);
100  clsBox2I.def("getCorners", &Box2I::getCorners);
101  clsBox2I.def("toString", &Box2I::toString);
102  clsBox2I.def("__repr__", [](Box2I const &self) {
103  return py::str("Box2I(minimum={}, dimensions={})")
104  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
105  });
106  clsBox2I.def("__str__", [](Box2I const &self) {
107  return py::str("(minimum={}, maximum={})")
108  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
109  });
110  clsBox2I.def("__reduce__", [clsBox2I](Box2I const &self) {
111  return py::make_tuple(clsBox2I, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
112  });
113  clsBox2I.def("getSlices", [](Box2I const &self) {
114  return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
115  py::slice(self.getBeginX(), self.getEndX(), 1));
116  });
117 
118  /* Box2D */
119 
120  PyBox2D clsBox2D(mod, "Box2D");
121 
122  clsBox2D.attr("Point") = modCoordinates.attr("Point2D");
123  clsBox2D.attr("Extent") = modCoordinates.attr("Extent2D");
124 
125  clsBox2D.attr("EPSILON") = py::float_(Box2D::EPSILON);
126  clsBox2D.attr("INVALID") = py::float_(Box2D::INVALID);
127 
128  clsBox2D.def(py::init<>());
129  clsBox2D.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
130  "invert"_a = true);
131  clsBox2D.def(py::init<Point2D const &, Extent2D const &, bool>(), "corner"_a, "dimensions"_a,
132  "invert"_a = true);
133  clsBox2D.def(py::init<Box2I const &>());
134  clsBox2D.def(py::init<Box2D const &>());
135 
136  clsBox2D.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
137  py::is_operator());
138  clsBox2D.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
139  py::is_operator());
140 
141  clsBox2D.def_static("makeCenteredBox", &Box2D::makeCenteredBox, "center"_a, "size"_a);
142  clsBox2D.def("swap", &Box2D::swap);
143  clsBox2D.def("getMin", &Box2D::getMin);
144  clsBox2D.def("getMinX", &Box2D::getMinX);
145  clsBox2D.def("getMinY", &Box2D::getMinY);
146  clsBox2D.def("getMax", &Box2D::getMax);
147  clsBox2D.def("getMaxX", &Box2D::getMaxX);
148  clsBox2D.def("getMaxY", &Box2D::getMaxY);
149  clsBox2D.def("getDimensions", &Box2D::getDimensions);
150  clsBox2D.def("getWidth", &Box2D::getWidth);
151  clsBox2D.def("getHeight", &Box2D::getHeight);
152  clsBox2D.def("getArea", &Box2D::getArea);
153  clsBox2D.def("getCenter", &Box2D::getCenter);
154  clsBox2D.def("getCenterX", &Box2D::getCenterX);
155  clsBox2D.def("getCenterY", &Box2D::getCenterY);
156  clsBox2D.def("isEmpty", &Box2D::isEmpty);
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("__contains__", (bool (Box2D::*)(Point2D const &) const) & Box2D::contains);
160  clsBox2D.def("__contains__", (bool (Box2D::*)(Box2D const &) const) & Box2D::contains);
161  clsBox2D.def("overlaps", &Box2D::overlaps);
162  clsBox2D.def("grow", (void (Box2D::*)(double)) & Box2D::grow);
163  clsBox2D.def("grow", (void (Box2D::*)(Extent2D const &)) & Box2D::grow);
164  clsBox2D.def("overlaps", (void (Box2D::*)(Extent2D const &)) & Box2D::overlaps);
165  clsBox2D.def("shift", &Box2D::shift);
166  clsBox2D.def("flipLR", &Box2D::flipLR);
167  clsBox2D.def("flipTB", &Box2D::flipTB);
168  clsBox2D.def("include", (void (Box2D::*)(Point2D const &)) & Box2D::include);
169  clsBox2D.def("include", (void (Box2D::*)(Box2D const &)) & Box2D::include);
170  clsBox2D.def("clip", &Box2D::clip);
171  clsBox2D.def("getCorners", &Box2D::getCorners);
172  clsBox2D.def("toString", &Box2D::toString);
173  clsBox2D.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  clsBox2D.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  clsBox2D.def("__reduce__", [clsBox2D](Box2D const &self) {
182  return py::make_tuple(clsBox2D, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
183  });
184 
185  /* module-level typedefs */
186  mod.attr("BoxI") = clsBox2I;
187  mod.attr("BoxD") = clsBox2D;
188 
189  return mod.ptr();
190 }
191 
192 } // namespace
193 } // namespace geom
194 } // 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
PYBIND11_PLUGIN(cameraSys)
Definition: cameraSys.cc:62
A base class for image defects.
Definition: cameraGeom.dox:3
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