LSST Applications  21.0.0+3c14b91618,21.0.0+9f51b1e3f7,21.0.0-1-ga51b5d4+6691386486,21.0.0-10-g2408eff+1a328412bf,21.0.0-10-g560fb7b+52fd22d7b4,21.0.0-10-g8d1d15d+2f9043cae0,21.0.0-10-gcf60f90+d15de71c48,21.0.0-11-g25eff31+d43066e4ef,21.0.0-15-g490e301a+a676f0d5cf,21.0.0-2-g103fe59+4758c8ef83,21.0.0-2-g1367e85+a9f57e981a,21.0.0-2-g45278ab+9f51b1e3f7,21.0.0-2-g5242d73+a9f57e981a,21.0.0-2-g7f82c8f+1bcc828e4f,21.0.0-2-g8f08a60+e6fd6d9ff9,21.0.0-2-ga326454+1bcc828e4f,21.0.0-2-gde069b7+66c51b65da,21.0.0-2-gecfae73+251b9830c3,21.0.0-2-gfc62afb+a9f57e981a,21.0.0-20-g09baf175d+e1e7d1c708,21.0.0-3-g357aad2+854c3902c3,21.0.0-3-g4be5c26+a9f57e981a,21.0.0-3-g65f322c+feaa1990e9,21.0.0-3-g7d9da8d+3c14b91618,21.0.0-3-ge02ed75+bda8df9b93,21.0.0-4-g591bb35+bda8df9b93,21.0.0-4-g65b4814+52fd22d7b4,21.0.0-4-g88306b8+656365ce3f,21.0.0-4-gccdca77+86bf7a300d,21.0.0-4-ge8a399c+b99e86088e,21.0.0-5-gd00fb1e+6a0dc09319,21.0.0-51-gd3b42663+bf9f0d1c8b,21.0.0-6-g2d4f3f3+9f51b1e3f7,21.0.0-7-g04766d7+ee2ae02087,21.0.0-7-g98eecf7+3609eddee2,21.0.0-7-gde99fe0+bda8df9b93,21.0.0-8-gd70ce6f+79e45e76e4,master-gac4afde19b+bda8df9b93,w.2021.10
LSST Data Management Base Package
_box.cc
Go to the documentation of this file.
1 /*
2  * LSST Data Management System
3  * See COPYRIGHT file at the top of the source tree.
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 #include "pybind11/pybind11.h"
23 
24 #include "lsst/sphgeom/python.h"
25 
27 #include "lsst/sphgeom/Box.h"
28 #include "lsst/sphgeom/Box3d.h"
29 #include "lsst/sphgeom/Circle.h"
31 #include "lsst/sphgeom/Ellipse.h"
32 #include "lsst/sphgeom/LonLat.h"
34 #include "lsst/sphgeom/Region.h"
36 
39 
40 namespace py = pybind11;
41 using namespace pybind11::literals;
42 
43 namespace lsst {
44 namespace sphgeom {
45 
46 namespace {
48  uint8_t const *buffer = reinterpret_cast<uint8_t const *>(
49  PYBIND11_BYTES_AS_STRING(bytes.ptr()));
50  size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
51  return Box::decode(buffer, n);
52 }
53 }
54 
55 template <>
56 void defineClass(py::class_<Box, std::unique_ptr<Box>, Region> &cls) {
57  cls.attr("TYPE_CODE") = py::int_(Box::TYPE_CODE);
58 
59  cls.def_static("fromDegrees", &Box::fromDegrees, "lon1"_a, "lat1"_a,
60  "lon2"_a, "lat2"_a);
61  cls.def_static("fromRadians", &Box::fromRadians, "lon1"_a, "lat1"_a,
62  "lon2"_a, "lat2"_a);
63  cls.def_static("empty", &Box::empty);
64  cls.def_static("full", &Box::full);
65  cls.def_static("halfWidthForCircle", &Box::halfWidthForCircle, "radius"_a,
66  "lat"_a);
67  cls.def_static("allLongitudes", &Box::allLongitudes);
68  cls.def_static("allLatitudes", &Box::allLatitudes);
69 
70  cls.def(py::init<>());
71  cls.def(py::init<LonLat const &>(), "point"_a);
72  cls.def(py::init<LonLat const &, LonLat const &>(), "point1"_a, "point2"_a);
73  cls.def(py::init<LonLat const &, Angle, Angle>(), "center"_a, "width"_a,
74  "height"_a);
75  cls.def(py::init<NormalizedAngleInterval const &, AngleInterval const &>(),
76  "lon"_a, "lat"_a);
77  cls.def(py::init<Box const &>(), "box"_a);
78 
79  cls.def("__eq__", (bool (Box::*)(Box const &) const) & Box::operator==,
80  py::is_operator());
81  cls.def("__eq__", (bool (Box::*)(LonLat const &) const) & Box::operator==,
82  py::is_operator());
83  cls.def("__ne__", (bool (Box::*)(Box const &) const) & Box::operator!=,
84  py::is_operator());
85  cls.def("__ne__", (bool (Box::*)(LonLat const &) const) & Box::operator!=,
86  py::is_operator());
87  cls.def("__contains__",
88  (bool (Box::*)(LonLat const &) const) & Box::contains,
89  py::is_operator());
90  cls.def("__contains__", (bool (Box::*)(Box const &) const) & Box::contains,
91  py::is_operator());
92  // Rewrap this base class method since there are overloads in this subclass
93  cls.def("__contains__",
94  (bool (Box::*)(UnitVector3d const &) const) & Box::contains,
95  py::is_operator());
96 
97  cls.def("getLon", &Box::getLon);
98  cls.def("getLat", &Box::getLat);
99  cls.def("isEmpty", &Box::isEmpty);
100  cls.def("isFull", &Box::isFull);
101  cls.def("getCenter", &Box::getCenter);
102  cls.def("getWidth", &Box::getWidth);
103  cls.def("getHeight", &Box::getHeight);
104  cls.def("contains", (bool (Box::*)(LonLat const &) const) & Box::contains);
105  cls.def("contains", (bool (Box::*)(Box const &) const) & Box::contains);
106  // Rewrap this base class method since there are overloads in this subclass
107  cls.def("contains",
108  (bool (Box::*)(UnitVector3d const &) const) & Box::contains);
109  cls.def("isDisjointFrom",
110  (bool (Box::*)(LonLat const &) const) & Box::isDisjointFrom);
111  cls.def("isDisjointFrom",
112  (bool (Box::*)(Box const &) const) & Box::isDisjointFrom);
113  cls.def("intersects",
114  (bool (Box::*)(LonLat const &) const) & Box::intersects);
115  cls.def("intersects", (bool (Box::*)(Box const &) const) & Box::intersects);
116  cls.def("isWithin", (bool (Box::*)(LonLat const &) const) & Box::isWithin);
117  cls.def("isWithin", (bool (Box::*)(Box const &) const) & Box::isWithin);
118  cls.def("clipTo", (Box & (Box::*)(LonLat const &)) & Box::clipTo);
119  cls.def("clipTo", (Box & (Box::*)(Box const &)) & Box::clipTo);
120  cls.def("clippedTo", (Box(Box::*)(LonLat const &) const) & Box::clippedTo);
121  cls.def("clippedTo", (Box(Box::*)(Box const &) const) & Box::clippedTo);
122  cls.def("expandTo", (Box & (Box::*)(LonLat const &)) & Box::expandTo);
123  cls.def("expandTo", (Box & (Box::*)(Box const &)) & Box::expandTo);
124  cls.def("expandedTo",
125  (Box(Box::*)(LonLat const &) const) & Box::expandedTo);
126  cls.def("expandedTo", (Box(Box::*)(Box const &) const) & Box::expandedTo);
127  cls.def("dilateBy", (Box & (Box::*)(Angle)) & Box::dilateBy, "angle"_a);
128  cls.def("dilateBy", (Box & (Box::*)(Angle, Angle)) & Box::dilateBy,
129  "width"_a, "height"_a);
130  cls.def("dilatedBy", (Box(Box::*)(Angle) const) & Box::dilatedBy,
131  "angle"_a);
132  cls.def("dilatedBy", (Box(Box::*)(Angle, Angle) const) & Box::dilatedBy,
133  "width"_a, "height"_a);
134  cls.def("erodeBy", (Box & (Box::*)(Angle)) & Box::erodeBy, "angle"_a);
135  cls.def("erodeBy", (Box & (Box::*)(Angle, Angle)) & Box::erodeBy, "width"_a,
136  "height"_a);
137  cls.def("erodedBy", (Box(Box::*)(Angle) const) & Box::erodedBy, "angle"_a);
138  cls.def("erodedBy", (Box(Box::*)(Angle, Angle) const) & Box::erodedBy,
139  "width"_a, "height"_a);
140  cls.def("getArea", &Box::getArea);
141  cls.def("relate",
142  (Relationship(Box::*)(LonLat const &) const) & Box::relate,
143  "point"_a);
144  // Rewrap this base class method since there are overloads in this subclass
145  cls.def("relate",
146  (Relationship(Box::*)(Region const &) const) & Box::relate,
147  "region"_a);
148 
149  // Note that the Region interface has already been wrapped.
150 
151  // The lambda is necessary for now; returning the unique pointer
152  // directly leads to incorrect results and crashes.
153  cls.def_static("decode",
154  [](py::bytes bytes) { return decode(bytes).release(); },
155  "bytes"_a);
156 
157  cls.def("__str__", [](Box const &self) {
158  return py::str("Box({!s}, {!s})").format(self.getLon(), self.getLat());
159  });
160  cls.def("__repr__", [](Box const &self) {
161  return py::str("Box({!r}, {!r})").format(self.getLon(), self.getLat());
162  });
163  cls.def(py::pickle(
164  [](const Box &self) { return python::encode(self); },
165  [](py::bytes bytes) { return decode(bytes).release(); }));
166 }
167 
168 } // sphgeom
169 } // lsst
This file defines a class for representing angle intervals.
This file declares a class for representing axis-aligned bounding boxes in ℝ³.
This file declares a class for representing circular regions on the unit sphere.
This file declares a class for representing convex polygons with great circle edges on the unit spher...
This file contains a class representing spherical coordinates.
This file declares a class representing closed intervals of normalized angles, i.e.
This file defines an interface for spherical regions.
This file declares a class for representing unit vectors in ℝ³.
table::Key< table::Array< std::uint8_t > > bytes
Definition: python.h:135
Angle represents an angle in radians.
Definition: Angle.h:43
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition: Box.h:54
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition: LonLat.h:48
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition: Region.h:79
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Definition: UnitVector3d.h:55
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
void defineClass(py::class_< Box, std::unique_ptr< Box >, Region > &cls)
Definition: _box.cc:56
A base class for image defects.
This file declares a class for representing longitude/latitude angle boxes on the unit sphere.
This file declares a class for representing elliptical regions on the unit sphere.