23 #include "pybind11/pybind11.h" 24 #include "pybind11/stl.h" 28 namespace py = pybind11;
36 using PyBox2I = py::class_<Box2I, std::shared_ptr<Box2I>>;
37 using PyBox2D = py::class_<Box2D, std::shared_ptr<Box2D>>;
40 py::module mod(
"box");
42 py::object modCoordinates = py::module::import(
"lsst.afw.geom.coordinates");
46 PyBox2I clsBox2I(mod,
"Box2I");
48 clsBox2I.attr(
"Point") = modCoordinates.attr(
"Point2I");
49 clsBox2I.attr(
"Extent") = modCoordinates.attr(
"Extent2I");
51 py::enum_<Box2I::EdgeHandlingEnum>(clsBox2I,
"EdgeHandlingEnum")
52 .value(
"EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
53 .value(
"SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
56 clsBox2I.def(py::init<>());
57 clsBox2I.def(py::init<Point2I const &, Point2I const &, bool>(),
"minimum"_a,
"maximum"_a,
59 clsBox2I.def(py::init<Point2I const &, Extent2I const &, bool>(),
"minimum"_a,
"dimensions"_a,
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);
65 clsBox2I.def(
"__eq__", [](Box2I
const &
self, Box2I
const &other) {
return self == other; },
67 clsBox2I.def(
"__ne__", [](Box2I
const &
self, Box2I
const &other) {
return self != other; },
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(
"Box2D(minimum={}, dimensions={})")
105 .format(py::repr(py::cast(
self.getMin())), py::repr(py::cast(
self.getDimensions())));
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())));
111 clsBox2I.def(
"__reduce__", [clsBox2I](Box2I
const &
self) {
112 return py::make_tuple(clsBox2I, make_tuple(py::cast(
self.getMin()), py::cast(
self.getMax())));
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));
121 PyBox2D clsBox2D(mod,
"Box2D");
123 clsBox2I.attr(
"Point") = modCoordinates.attr(
"Point2D");
124 clsBox2I.attr(
"Extent") = modCoordinates.attr(
"Extent2D");
126 clsBox2D.attr(
"EPSILON") = py::float_(Box2D::EPSILON);
127 clsBox2D.attr(
"INVALID") = py::float_(Box2D::INVALID);
129 clsBox2D.def(py::init<>());
130 clsBox2D.def(py::init<Point2D const &, Point2D const &, bool>(),
"minimum"_a,
"maximum"_a,
132 clsBox2D.def(py::init<Point2D const &, Extent2D const &, bool>(),
"minimum"_a,
"dimensions"_a,
134 clsBox2D.def(py::init<Box2I const &>());
135 clsBox2D.def(py::init<Box2D const &>());
137 clsBox2D.def(
"__eq__", [](Box2D
const &
self, Box2D
const &other) {
return self == other; },
139 clsBox2D.def(
"__ne__", [](Box2D
const &
self, Box2D
const &other) {
return self != other; },
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())));
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())));
181 clsBox2D.def(
"__reduce__", [clsBox2D](Box2D
const &
self) {
182 return py::make_tuple(clsBox2D, make_tuple(py::cast(
self.getMin()), py::cast(
self.getMax())));
186 mod.attr(
"BoxI") = clsBox2I;
187 mod.attr(
"BoxD") = clsBox2D;
Extent< double, 2 > Extent2D
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Extent< int, 2 > Extent2I
PYBIND11_PLUGIN(_cameraPoint)
A base class for image defects.
Point< double, 2 > Point2D