LSSTApplications  11.0-24-g0a022a1,12.1-4-g110c6f4+31,15.0+14,15.0+9,15.0-1-g19261fa+6,15.0-1-g60afb23+14,15.0-1-g615e0bb+6,15.0-1-g6668b0b+5,15.0-1-g788a293+14,15.0-1-ga91101e+14,15.0-1-gae1598d+8,15.0-1-gd076f1f+13,15.0-1-gdf18595+2,15.0-1-gf4f1c34+8,15.0-2-g100d730+7,15.0-2-g18f3f21+8,15.0-2-g20c4630+2,15.0-2-g35685a8+9,15.0-2-g5dfaa72+2,15.0-2-gf38729e+8,15.0-23-g309a1dfe0,15.0-3-g150fc43+17,15.0-3-g6f085af+7,15.0-3-g707930d,15.0-3-g9103c06+8,15.0-3-ga03b4ca+20,15.0-3-gaec6799+5,15.0-4-g45f767a+8,15.0-4-g5589a47,15.0-4-g654b129+12,15.0-4-gff20472+17,15.0-5-g0db841d+1,15.0-5-g23e394c+1,15.0-6-g86eaddf,15.0-6-g9a9df217+9,15.0-8-g11095dd,15.0-8-g306a5613
LSSTDataManagementBasePackage
box.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * Copyright 2008-2016 AURA/LSST.
4  *
5  * This product includes software developed by the
6  * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
19  * the GNU General Public License along with this program. If not,
20  * see <https://www.lsstcorp.org/LegalNotices/>.
21  */
22 
23 #include "pybind11/pybind11.h"
24 #include "pybind11/stl.h"
25 
26 #include "lsst/afw/geom/Box.h"
27 
28 namespace py = pybind11;
29 using namespace py::literals;
30 
31 namespace lsst {
32 namespace afw {
33 namespace geom {
34 namespace {
35 
36 using PyBox2I = py::class_<Box2I, std::shared_ptr<Box2I>>;
37 using PyBox2D = py::class_<Box2D, std::shared_ptr<Box2D>>;
38 
40  py::module mod("box");
41 
42  py::object modCoordinates = py::module::import("lsst.afw.geom.coordinates");
43 
44  /* Box2UI */
45 
46  PyBox2I clsBox2I(mod, "Box2I");
47 
48  clsBox2I.attr("Point") = modCoordinates.attr("Point2I");
49  clsBox2I.attr("Extent") = modCoordinates.attr("Extent2I");
50 
51  py::enum_<Box2I::EdgeHandlingEnum>(clsBox2I, "EdgeHandlingEnum")
52  .value("EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
53  .value("SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
54  .export_values();
55 
56  clsBox2I.def(py::init<>());
57  clsBox2I.def(py::init<Point2I const &, Point2I const &, bool>(), "minimum"_a, "maximum"_a,
58  "invert"_a = true);
59  clsBox2I.def(py::init<Point2I const &, Extent2I const &, bool>(), "minimum"_a, "dimensions"_a,
60  "invert"_a = true);
61  clsBox2I.def(py::init<Box2D const &, Box2I::EdgeHandlingEnum>(), "other"_a,
62  "edgeHandling"_a = Box2I::EXPAND);
63  clsBox2I.def(py::init<Box2I const &>(), "other"_a);
64 
65  clsBox2I.def("__eq__", [](Box2I const &self, Box2I const &other) { return self == other; },
66  py::is_operator());
67  clsBox2I.def("__ne__", [](Box2I const &self, Box2I const &other) { return self != other; },
68  py::is_operator());
69 
70  clsBox2I.def("swap", &Box2I::swap);
71  clsBox2I.def("getMin", &Box2I::getMin);
72  clsBox2I.def("getMinX", &Box2I::getMinX);
73  clsBox2I.def("getMinY", &Box2I::getMinY);
74  clsBox2I.def("getMax", &Box2I::getMax);
75  clsBox2I.def("getMaxX", &Box2I::getMaxX);
76  clsBox2I.def("getMaxY", &Box2I::getMaxY);
77  clsBox2I.def("getBegin", &Box2I::getBegin);
78  clsBox2I.def("getBeginX", &Box2I::getBeginX);
79  clsBox2I.def("getBeginY", &Box2I::getBeginY);
80  clsBox2I.def("getEnd", &Box2I::getEnd);
81  clsBox2I.def("getEndX", &Box2I::getEndX);
82  clsBox2I.def("getEndY", &Box2I::getEndY);
83  clsBox2I.def("getDimensions", &Box2I::getDimensions);
84  clsBox2I.def("getWidth", &Box2I::getWidth);
85  clsBox2I.def("getHeight", &Box2I::getHeight);
86  clsBox2I.def("getArea", &Box2I::getArea);
87  clsBox2I.def("isEmpty", &Box2I::isEmpty);
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("__contains__", (bool (Box2I::*)(Point2I const &) const) & Box2I::contains);
91  clsBox2I.def("__contains__", (bool (Box2I::*)(Box2I const &) const) & Box2I::contains);
92  clsBox2I.def("overlaps", &Box2I::overlaps);
93  clsBox2I.def("grow", (void (Box2I::*)(int)) & Box2I::grow);
94  clsBox2I.def("grow", (void (Box2I::*)(Extent2I const &)) & Box2I::grow);
95  clsBox2I.def("shift", &Box2I::shift);
96  clsBox2I.def("flipLR", &Box2I::flipLR);
97  clsBox2I.def("flipTB", &Box2I::flipTB);
98  clsBox2I.def("include", (void (Box2I::*)(Point2I const &)) & Box2I::include);
99  clsBox2I.def("include", (void (Box2I::*)(Box2I const &)) & Box2I::include);
100  clsBox2I.def("clip", &Box2I::clip);
101  clsBox2I.def("getCorners", &Box2I::getCorners);
102  clsBox2I.def("toString", &Box2I::toString);
103  clsBox2I.def("__repr__", [](Box2I const &self) {
104  return py::str("Box2I(minimum={}, dimensions={})")
105  .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
106  });
107  clsBox2I.def("__str__", [](Box2I const &self) {
108  return py::str("(minimum={}, maximum={})")
109  .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
110  });
111  clsBox2I.def("__reduce__", [clsBox2I](Box2I const &self) {
112  return py::make_tuple(clsBox2I, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
113  });
114  clsBox2I.def("getSlices", [](Box2I const &self) {
115  return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
116  py::slice(self.getBeginX(), self.getEndX(), 1));
117  });
118 
119  /* Box2D */
120 
121  PyBox2D clsBox2D(mod, "Box2D");
122 
123  clsBox2D.attr("Point") = modCoordinates.attr("Point2D");
124  clsBox2D.attr("Extent") = modCoordinates.attr("Extent2D");
125 
126  clsBox2D.attr("EPSILON") = py::float_(Box2D::EPSILON);
127  clsBox2D.attr("INVALID") = py::float_(Box2D::INVALID);
128 
129  clsBox2D.def(py::init<>());
130  clsBox2D.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
131  "invert"_a = true);
132  clsBox2D.def(py::init<Point2D const &, Extent2D const &, bool>(), "minimum"_a, "dimensions"_a,
133  "invert"_a = true);
134  clsBox2D.def(py::init<Box2I const &>());
135  clsBox2D.def(py::init<Box2D const &>());
136 
137  clsBox2D.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
138  py::is_operator());
139  clsBox2D.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
140  py::is_operator());
141 
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 }
193 }
194 } // namespace lsst::afw::geom::<anonymous>
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
Extent< double, 2 > Extent2D
Definition: Extent.h:383
T make_tuple(T... args)
Extent< int, 2 > Extent2I
Definition: Extent.h:380
PYBIND11_PLUGIN(_cameraSys)
Definition: cameraSys.cc:62
A base class for image defects.
Definition: cameraGeom.dox:3
Point< double, 2 > Point2D
Definition: Point.h:304
void swap(Image< PixelT > &a, Image< PixelT > &b)
Definition: Image.cc:458
ItemVariant const * other
Definition: Schema.cc:55
Point< int, 2 > Point2I
Definition: Point.h:301