LSST Applications g2079a07aa2+86d27d4dc4,g2305ad1205+a659bff248,g2bbee38e9b+3c60f8fe34,g337abbeb29+3c60f8fe34,g33d1c0ed96+3c60f8fe34,g3502564af9+d77d6d1350,g3a166c0a6a+3c60f8fe34,g487adcacf7+25d9892218,g4be5004598+d77d6d1350,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+4d81263f9a,g5cd07815a0+980d2b1c3b,g607f77f49a+d77d6d1350,g858d7b2824+d77d6d1350,g88963caddf+83e433e629,g99cad8db69+a4d3c48eeb,g9ddcbc5298+9a081db1e4,ga1e77700b3+bcf1af89ad,ga57fefb910+9a39d7b2d7,gae0086650b+585e252eca,gb065fddaf9+4f9fd82a2c,gb0e22166c9+60f28cb32d,gb363559e06+d84b1d3d07,gb3b7280ab2+4563d032e1,gb4b16eec92+babe958938,gba4ed39666+c2a2e4ac27,gbb8dafda3b+ed6854b564,gc120e1dc64+b72d212f87,gc28159a63d+3c60f8fe34,gc3e9b769f7+921dbcd359,gcf0d15dbbd+9a39d7b2d7,gdaeeff99f8+f9a426f77a,gddc38dedce+585e252eca,ge79ae78c31+3c60f8fe34,w.2024.21
LSST Data Management Base Package
Loading...
Searching...
No Matches
_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#include "pybind11/numpy.h"
25
26#include "lsst/geom/Box.h"
27#include "lsst/utils/python.h"
28
29namespace py = pybind11;
30using namespace py::literals;
31
32namespace lsst {
33namespace geom {
34
35void wrapBox(utils::python::WrapperCollection & wrappers) {
36 wrappers.wrapType(
37 py::class_<Box2I, std::shared_ptr<Box2I>>(wrappers.module, "Box2I"),
38 [](auto & mod, auto & cls) mutable {
39
40 cls.attr("Point") = mod.attr("Point2I");
41 cls.attr("Extent") = mod.attr("Extent2I");
42
43 py::enum_<Box2I::EdgeHandlingEnum>(cls, "EdgeHandlingEnum")
44 .value("EXPAND", Box2I::EdgeHandlingEnum::EXPAND)
45 .value("SHRINK", Box2I::EdgeHandlingEnum::SHRINK)
46 .export_values();
47
48 cls.def(py::init<>());
49 cls.def(py::init<Point2I const &, Point2I const &, bool>(), "minimum"_a, "maximum"_a,
50 "invert"_a = true);
51 cls.def(py::init<Point2I const &, Extent2I const &, bool>(), "corner"_a, "dimensions"_a,
52 "invert"_a = true);
53 cls.def(py::init<IntervalI const &, IntervalI const &>(), "x"_a, "y"_a);
54 cls.def(py::init<Box2D const &, Box2I::EdgeHandlingEnum>(), "other"_a,
55 "edgeHandling"_a = Box2I::EXPAND);
56 cls.def(py::init<Box2I const &>(), "other"_a);
57
58 cls.def("__eq__", [](Box2I const &self, Box2I const &other) { return self == other; },
59 py::is_operator());
60 cls.def("__ne__", [](Box2I const &self, Box2I const &other) { return self != other; },
61 py::is_operator());
62
63 cls.def_static("makeCenteredBox", &Box2I::makeCenteredBox, "center"_a, "size"_a);
64 cls.def("swap", &Box2I::swap);
65 cls.def("getMin", &Box2I::getMin);
66 cls.def("getMinX", &Box2I::getMinX);
67 cls.def("getMinY", &Box2I::getMinY);
68 cls.def("getMax", &Box2I::getMax);
69 cls.def("getMaxX", &Box2I::getMaxX);
70 cls.def("getMaxY", &Box2I::getMaxY);
71 cls.def_property_readonly("minX", &Box2I::getMinX);
72 cls.def_property_readonly("minY", &Box2I::getMinY);
73 cls.def_property_readonly("maxX", &Box2I::getMaxX);
74 cls.def_property_readonly("maxY", &Box2I::getMaxY);
75 cls.def("getBegin", &Box2I::getBegin);
76 cls.def("getBeginX", &Box2I::getBeginX);
77 cls.def("getBeginY", &Box2I::getBeginY);
78 cls.def("getEnd", &Box2I::getEnd);
79 cls.def("getEndX", &Box2I::getEndX);
80 cls.def("getEndY", &Box2I::getEndY);
81 cls.def_property_readonly("beginX", &Box2I::getBeginX);
82 cls.def_property_readonly("beginY", &Box2I::getBeginY);
83 cls.def_property_readonly("endX", &Box2I::getEndX);
84 cls.def_property_readonly("endY", &Box2I::getEndY);
85 cls.def("getDimensions", &Box2I::getDimensions);
86 cls.def("getWidth", &Box2I::getWidth);
87 cls.def("getHeight", &Box2I::getHeight);
88 cls.def("getArea", &Box2I::getArea);
89 cls.def_property_readonly("width", &Box2I::getWidth);
90 cls.def_property_readonly("height", &Box2I::getHeight);
91 cls.def_property_readonly("area", &Box2I::getArea);
92 cls.def("getCenter", &Box2I::getCenter);
93 cls.def("getCenterX", &Box2I::getCenterX);
94 cls.def("getCenterY", &Box2I::getCenterY);
95 cls.def_property_readonly("centerX", &Box2I::getCenterX);
96 cls.def_property_readonly("centerY", &Box2I::getCenterY);
97 cls.def("getX", &Box2I::getX);
98 cls.def("getY", &Box2I::getY);
99 cls.def_property_readonly("x", &Box2I::getX);
100 cls.def_property_readonly("y", &Box2I::getY);
101 cls.def("isEmpty", &Box2I::isEmpty);
102 cls.def("contains", py::overload_cast<Point2I const &>(&Box2I::contains, py::const_));
103 cls.def("contains", py::overload_cast<Box2I const &>(&Box2I::contains, py::const_));
104 cls.def("contains",
105 py::vectorize(static_cast<bool (Box2I::*)(int x, int y) const>(&Box2I::contains)),
106 "x"_a, "y"_a);
107 cls.def("__contains__", py::overload_cast<Point2I const &>(&Box2I::contains, py::const_));
108 cls.def("__contains__", py::overload_cast<Box2I const &>(&Box2I::contains, py::const_));
109 cls.def("overlaps", &Box2I::overlaps);
110 cls.def("intersects", &Box2I::intersects);
111 cls.def("isDisjointFrom", &Box2I::isDisjointFrom);
112 cls.def("grow", py::overload_cast<int>(&Box2I::grow));
113 cls.def("grow", py::overload_cast<Extent2I const &>(&Box2I::grow));
114 cls.def("shift", &Box2I::shift);
115 cls.def("flipLR", &Box2I::flipLR);
116 cls.def("flipTB", &Box2I::flipTB);
117 cls.def("include", py::overload_cast<Point2I const &>(&Box2I::include));
118 cls.def("include", py::overload_cast<Box2I const &>(&Box2I::include));
119 cls.def("clip", &Box2I::clip);
120 cls.def("dilatedBy", py::overload_cast<int>(&Box2I::dilatedBy, py::const_));
121 cls.def("dilatedBy", py::overload_cast<Extent2I const &>(&Box2I::dilatedBy, py::const_));
122 cls.def("erodedBy", py::overload_cast<int>(&Box2I::erodedBy, py::const_));
123 cls.def("erodedBy", py::overload_cast<Extent2I const &>(&Box2I::erodedBy, py::const_));
124 cls.def("shiftedBy", &Box2I::shiftedBy);
125 cls.def("reflectedAboutX", &Box2I::reflectedAboutX);
126 cls.def("reflectedAboutY", &Box2I::reflectedAboutY);
127 cls.def("expandedTo", py::overload_cast<Point2I const &>(&Box2I::expandedTo, py::const_));
128 cls.def("expandedTo", py::overload_cast<Box2I const &>(&Box2I::expandedTo, py::const_));
129 cls.def("clippedTo", &Box2I::clippedTo);
130 cls.def("getCorners", &Box2I::getCorners);
131 cls.def("toString", &Box2I::toString);
132 cls.def("__repr__", [](Box2I const &self) {
133 return py::str("Box2I(corner={}, dimensions={})")
134 .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
135 });
136 cls.def("__str__", [](Box2I const &self) {
137 return py::str("(minimum={}, maximum={})")
138 .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
139 });
140 cls.def("__reduce__", [cls](Box2I const &self) {
141 return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
142 });
143 auto getSlices = [](Box2I const &self) {
144 return py::make_tuple(py::slice(self.getBeginY(), self.getEndY(), 1),
145 py::slice(self.getBeginX(), self.getEndX(), 1));
146 };
147 cls.def("getSlices", getSlices);
148 cls.def_property_readonly("slices", getSlices);
149
150 mod.attr("BoxI") = cls;
151 }
152 );
153
154 wrappers.wrapType(
155 py::class_<Box2D, std::shared_ptr<Box2D>>(wrappers.module, "Box2D"),
156 [](auto & mod, auto & cls) mutable {
157
158 cls.attr("Point") = mod.attr("Point2D");
159 cls.attr("Extent") = mod.attr("Extent2D");
160
161 cls.attr("EPSILON") = py::float_(Box2D::EPSILON);
162 cls.attr("INVALID") = py::float_(Box2D::INVALID);
163
164 cls.def(py::init<>());
165 cls.def(py::init<Point2D const &, Point2D const &, bool>(), "minimum"_a, "maximum"_a,
166 "invert"_a = true);
167 cls.def(py::init<Point2D const &, Extent2D const &, bool>(), "corner"_a, "dimensions"_a,
168 "invert"_a = true);
169 cls.def(py::init<IntervalD const &, IntervalD const &>(), "x"_a, "y"_a);
170 cls.def(py::init<Box2I const &>());
171 cls.def(py::init<Box2D const &>());
172
173 cls.def("__eq__", [](Box2D const &self, Box2D const &other) { return self == other; },
174 py::is_operator());
175 cls.def("__ne__", [](Box2D const &self, Box2D const &other) { return self != other; },
176 py::is_operator());
177
178 cls.def_static("makeCenteredBox", &Box2D::makeCenteredBox, "center"_a, "size"_a);
179 cls.def("swap", &Box2D::swap);
180 cls.def("getMin", &Box2D::getMin);
181 cls.def("getMinX", &Box2D::getMinX);
182 cls.def("getMinY", &Box2D::getMinY);
183 cls.def("getMax", &Box2D::getMax);
184 cls.def("getMaxX", &Box2D::getMaxX);
185 cls.def("getMaxY", &Box2D::getMaxY);
186 cls.def_property_readonly("minX", &Box2D::getMinX);
187 cls.def_property_readonly("minY", &Box2D::getMinY);
188 cls.def_property_readonly("maxX", &Box2D::getMaxX);
189 cls.def_property_readonly("maxY", &Box2D::getMaxY);
190 cls.def("getDimensions", &Box2D::getDimensions);
191 cls.def("getWidth", &Box2D::getWidth);
192 cls.def("getHeight", &Box2D::getHeight);
193 cls.def("getArea", &Box2D::getArea);
194 cls.def_property_readonly("width", &Box2D::getWidth);
195 cls.def_property_readonly("height", &Box2D::getHeight);
196 cls.def_property_readonly("area", &Box2D::getArea);
197 cls.def("getX", &Box2D::getX);
198 cls.def("getY", &Box2D::getY);
199 cls.def_property_readonly("x", &Box2D::getX);
200 cls.def_property_readonly("y", &Box2D::getY);
201 cls.def("getCenter", &Box2D::getCenter);
202 cls.def("getCenterX", &Box2D::getCenterX);
203 cls.def("getCenterY", &Box2D::getCenterY);
204 cls.def_property_readonly("centerX", &Box2D::getCenterX);
205 cls.def_property_readonly("centerY", &Box2D::getCenterY);
206 cls.def("isEmpty", &Box2D::isEmpty);
207 cls.def("contains", py::overload_cast<Point2D const &>(&Box2D::contains, py::const_));
208 cls.def("contains", py::overload_cast<Box2D const &>(&Box2D::contains, py::const_));
209 cls.def("contains",
210 py::vectorize(static_cast<bool (Box2D::*)(double x, double y) const>(&Box2D::contains)),
211 "x"_a, "y"_a);
212 cls.def("__contains__", py::overload_cast<Point2D const &>(&Box2D::contains, py::const_));
213 cls.def("__contains__", py::overload_cast<Box2D const &>(&Box2D::contains, py::const_));
214 cls.def("intersects", &Box2D::intersects);
215 cls.def("isDisjointFrom", &Box2D::isDisjointFrom);
216 cls.def("overlaps", &Box2D::overlaps);
217 cls.def("grow", py::overload_cast<double>(&Box2D::grow));
218 cls.def("grow", py::overload_cast<Extent2D const &>(&Box2D::grow));
219 cls.def("shift", &Box2D::shift);
220 cls.def("flipLR", &Box2D::flipLR);
221 cls.def("flipTB", &Box2D::flipTB);
222 cls.def("include", py::overload_cast<Point2D const &>(&Box2D::include));
223 cls.def("include", py::overload_cast<Box2D const &>(&Box2D::include));
224 cls.def("clip", &Box2D::clip);
225 cls.def("dilatedBy", py::overload_cast<double>(&Box2D::dilatedBy, py::const_));
226 cls.def("dilatedBy", py::overload_cast<Extent2D const &>(&Box2D::dilatedBy, py::const_));
227 cls.def("erodedBy", py::overload_cast<double>(&Box2D::erodedBy, py::const_));
228 cls.def("erodedBy", py::overload_cast<Extent2D const &>(&Box2D::erodedBy, py::const_));
229 cls.def("shiftedBy", &Box2D::shiftedBy);
230 cls.def("reflectedAboutX", &Box2D::reflectedAboutX);
231 cls.def("reflectedAboutY", &Box2D::reflectedAboutY);
232 cls.def("expandedTo", py::overload_cast<Point2D const &>(&Box2D::expandedTo, py::const_));
233 cls.def("expandedTo", py::overload_cast<Box2D const &>(&Box2D::expandedTo, py::const_));
234 cls.def("clippedTo", &Box2D::clippedTo);
235 cls.def("getCorners", &Box2D::getCorners);
236 cls.def("toString", &Box2D::toString);
237 cls.def("__repr__", [](Box2D const &self) {
238 return py::str("Box2D(corner={}, dimensions={})")
239 .format(py::repr(py::cast(self.getMin())), py::repr(py::cast(self.getDimensions())));
240 });
241 cls.def("__str__", [](Box2D const &self) {
242 return py::str("(minimum={}, maximum={})")
243 .format(py::str(py::cast(self.getMin())), py::str(py::cast(self.getMax())));
244 });
245 cls.def("__reduce__", [cls](Box2D const &self) {
246 return py::make_tuple(cls, make_tuple(py::cast(self.getMin()), py::cast(self.getMax())));
247 });
248
249 mod.attr("BoxD") = cls;
250 }
251 );
252}
253
254} // namespace geom
255} // namespace lsst
int y
Definition SpanSet.cc:48
double getMaxY() const noexcept
Definition Box.h:519
void swap(Box2D &other) noexcept
Definition Box.h:498
Point2D const getMax() const noexcept
Definition Box.h:517
double getMaxX() const noexcept
Definition Box.h:518
Box2D dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
Definition Box.cc:438
Extent2D const getDimensions() const noexcept
1-d interval accessors
Definition Box.h:528
void shift(Extent2D const &offset)
Shift the position of the box by the given offset.
Definition Box.cc:350
double getMinY() const noexcept
Definition Box.h:515
void clip(Box2D const &other) noexcept
Shrink this to ensure that other.contains(*this).
Definition Box.cc:416
double getWidth() const noexcept
1-d interval accessors
Definition Box.h:529
static Box2D makeCenteredBox(Point2D const &center, Extent const &size) noexcept
Create a box centered on a particular point.
Definition Box.cc:316
Box2D erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object).
Definition Box.h:671
Point2D const getCenter() const noexcept
Return true if the box contains no points.
Definition Box.h:549
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition Box.h:557
Point2D const getMin() const noexcept
Definition Box.h:513
double getMinX() const noexcept
Definition Box.h:514
bool isDisjointFrom(Box2D const &other) const noexcept
Return true if there are no points in both this and other.
Definition Box.cc:339
Interval getY() const
1-d interval accessors
Definition Box.h:540
void grow(double buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition Box.h:594
Box2D reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
Definition Box.cc:453
void flipLR(float xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
Definition Box.cc:356
void flipTB(float yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Definition Box.cc:368
Interval getX() const
1-d interval accessors
Definition Box.h:539
Box2D reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
Definition Box.cc:448
double getCenterX() const noexcept
Return true if the box contains no points.
Definition Box.h:552
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
Definition Box.cc:380
bool contains(Point2D const &point) const noexcept
Return true if the box contains the point.
Definition Box.cc:322
bool overlaps(Box2D const &other) const noexcept
Return true if any points in other are also in this.
Definition Box.cc:332
bool intersects(Box2D const &other) const noexcept
Return true if the box contains no points.
Definition Box.h:579
double getArea() const noexcept
1-d interval accessors
Definition Box.h:531
Box2D clippedTo(Box2D const &other) const
Shrink a box to ensure that it is contained by other (returning a new object).
Definition Box.cc:471
static double const EPSILON
Value the maximum coordinate is multiplied by to increase it by the smallest possible amount.
Definition Box.h:425
Box2D expandedTo(Point const &other) const
Expand a box to ensure that contains(other) is true (returning a new object).
Definition Box.cc:458
std::vector< Point2D > getCorners() const
Get the corner points.
Definition Box.cc:496
Box2D shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Definition Box.cc:443
double getHeight() const noexcept
1-d interval accessors
Definition Box.h:530
std::string toString() const
Return true if the box contains no points.
Definition Box.h:761
static double const INVALID
Value used to specify undefined coordinate values.
Definition Box.h:428
double getCenterY() const noexcept
Return true if the box contains no points.
Definition Box.h:553
An integer coordinate rectangle.
Definition Box.h:55
int getBeginX() const noexcept
Definition Box.h:172
void clip(Box2I const &other) noexcept
Shrink this to ensure that other.contains(*this).
Definition Box.cc:189
int getMinY() const noexcept
Definition Box.h:158
bool isDisjointFrom(Box2I const &other) const noexcept
Return true if there are no points in both this and other.
Definition Box.cc:126
bool overlaps(Box2I const &other) const noexcept
Return true if any points in other are also in this.
Definition Box.cc:122
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
Definition Box.cc:152
int getHeight() const noexcept
Definition Box.h:188
Box2I expandedTo(Point const &other) const
Expand the box to ensure that contains(other) is true (returning a new object).
Definition Box.cc:233
Point2I const getMin() const noexcept
Definition Box.h:156
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition Box.h:213
Point2I const getMax() const noexcept
Definition Box.h:160
int getEndY() const noexcept
Definition Box.h:177
Box2I clippedTo(Box2I const &other) const noexcept
Shrink an interval to ensure that it is contained by other (returning a new object).
Definition Box.cc:243
void grow(int buffer)
Increase the size of the box by the given buffer amount in all directions.
Definition Box.h:249
Box2I erodedBy(Extent const &buffer) const
Decrease the size of the box by the given amount(s) on all sides (returning a new object).
Definition Box.h:312
Point2I const getBegin() const noexcept
Definition Box.h:171
Box2I dilatedBy(Extent const &buffer) const
Increase the size of the box by the given amount(s) on all sides (returning a new object).
Definition Box.cc:213
int getMinX() const noexcept
Definition Box.h:157
static Box2I makeCenteredBox(Point2D const &center, Extent const &size)
Create a box centered as closely as possible on a particular point.
Definition Box.cc:97
int getWidth() const noexcept
Definition Box.h:187
int getArea() const
Definition Box.h:189
int getBeginY() const noexcept
Definition Box.h:173
int getMaxX() const noexcept
Definition Box.h:161
Interval getX() const
1-d interval accessors
Definition Box.h:205
std::vector< Point2I > getCorners() const
Get the corner points.
Definition Box.cc:261
Box2I reflectedAboutX(Element x) const
Reflect the box about a vertical line (returning a new object).
Definition Box.cc:223
bool contains(Point2I const &point) const noexcept
Return true if the box contains the point.
Definition Box.cc:114
void shift(Extent2I const &offset)
Shift the position of the box by the given offset.
Definition Box.cc:134
std::string toString() const
1-d interval accessors
Definition Box.h:385
void flipTB(int yExtent)
Flip a bounding box about the x-axis given a parent box of extent (yExtent).
Definition Box.cc:145
void swap(Box2I &other) noexcept
Definition Box.h:141
int getMaxY() const noexcept
Definition Box.h:162
double getCenterY() const noexcept
1-d interval accessors
Definition Box.h:200
Box2I reflectedAboutY(Element y) const
Reflect the box about a horizontal line (returning a new object).
Definition Box.cc:228
Point2I const getEnd() const noexcept
Definition Box.h:175
Interval getY() const
1-d interval accessors
Definition Box.h:206
Extent2I const getDimensions() const noexcept
Definition Box.h:186
double getCenterX() const noexcept
1-d interval accessors
Definition Box.h:199
bool intersects(Box2I const &other) const noexcept
1-d interval accessors
Definition Box.h:235
Box2I shiftedBy(Extent const &offset) const
Shift the position of the box by the given offset (returning a new object).
Definition Box.cc:218
Point2D const getCenter() const noexcept
1-d interval accessors
Definition Box.cc:93
void flipLR(int xExtent)
Flip a bounding box about the y-axis given a parent box of extent (xExtent).
Definition Box.cc:138
int getEndX() const noexcept
Definition Box.h:176
T make_tuple(T... args)
void wrapBox(utils::python::WrapperCollection &wrappers)
Definition _Box.cc:35