LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
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#include "pybind11/numpy.h"
24
25#include "lsst/sphgeom/python.h"
26
28#include "lsst/sphgeom/Box.h"
29#include "lsst/sphgeom/Box3d.h"
30#include "lsst/sphgeom/Circle.h"
33#include "lsst/sphgeom/LonLat.h"
35#include "lsst/sphgeom/Region.h"
37
40
41namespace py = pybind11;
42using namespace pybind11::literals;
43
44namespace lsst {
45namespace sphgeom {
46
47template <>
48void defineClass(py::class_<Box, std::unique_ptr<Box>, Region> &cls) {
49 cls.attr("TYPE_CODE") = py::int_(Box::TYPE_CODE);
50
51 cls.def_static("fromDegrees", &Box::fromDegrees, "lon1"_a, "lat1"_a,
52 "lon2"_a, "lat2"_a);
53 cls.def_static("fromRadians", &Box::fromRadians, "lon1"_a, "lat1"_a,
54 "lon2"_a, "lat2"_a);
55 cls.def_static("empty", &Box::empty);
56 cls.def_static("full", &Box::full);
57 cls.def_static("halfWidthForCircle", &Box::halfWidthForCircle, "radius"_a,
58 "lat"_a);
59 cls.def_static("allLongitudes", &Box::allLongitudes);
60 cls.def_static("allLatitudes", &Box::allLatitudes);
61
62 cls.def(py::init<>());
63 cls.def(py::init<LonLat const &>(), "point"_a);
64 cls.def(py::init<LonLat const &, LonLat const &>(), "point1"_a, "point2"_a);
65 cls.def(py::init<LonLat const &, Angle, Angle>(), "center"_a, "width"_a,
66 "height"_a);
67 cls.def(py::init<NormalizedAngleInterval const &, AngleInterval const &>(),
68 "lon"_a, "lat"_a);
69 cls.def(py::init<Box const &>(), "box"_a);
70
71 cls.def("__eq__", (bool (Box::*)(Box const &) const) & Box::operator==,
72 py::is_operator());
73 cls.def("__eq__", (bool (Box::*)(LonLat const &) const) & Box::operator==,
74 py::is_operator());
75 cls.def("__ne__", (bool (Box::*)(Box const &) const) & Box::operator!=,
76 py::is_operator());
77 cls.def("__ne__", (bool (Box::*)(LonLat const &) const) & Box::operator!=,
78 py::is_operator());
79 cls.def("__contains__",
80 (bool (Box::*)(LonLat const &) const) & Box::contains,
81 py::is_operator());
82 cls.def("__contains__", (bool (Box::*)(Box const &) const) & Box::contains,
83 py::is_operator());
84 // Rewrap this base class method since there are overloads in this subclass
85 cls.def("__contains__",
86 (bool (Box::*)(UnitVector3d const &) const) & Box::contains,
87 py::is_operator());
88
89 cls.def("getLon", &Box::getLon);
90 cls.def("getLat", &Box::getLat);
91 cls.def("isEmpty", &Box::isEmpty);
92 cls.def("isFull", &Box::isFull);
93 cls.def("getCenter", &Box::getCenter);
94 cls.def("getWidth", &Box::getWidth);
95 cls.def("getHeight", &Box::getHeight);
96 cls.def("contains", (bool (Box::*)(LonLat const &) const) & Box::contains);
97 cls.def("contains", (bool (Box::*)(Box const &) const) & Box::contains);
98 // Rewrap these base class methods since there are overloads in this subclass
99 cls.def("contains",
100 (bool (Box::*)(UnitVector3d const &) const) & Box::contains);
101 cls.def("contains", py::vectorize((bool (Box::*)(double, double, double) const)&Box::contains),
102 "x"_a, "y"_a, "z"_a);
103 cls.def("contains", py::vectorize((bool (Box::*)(double, double) const)&Box::contains),
104 "lon"_a, "lat"_a);
105 cls.def("isDisjointFrom",
106 (bool (Box::*)(LonLat const &) const) & Box::isDisjointFrom);
107 cls.def("isDisjointFrom",
108 (bool (Box::*)(Box const &) const) & Box::isDisjointFrom);
109 cls.def("intersects",
110 (bool (Box::*)(LonLat const &) const) & Box::intersects);
111 cls.def("intersects", (bool (Box::*)(Box const &) const) & Box::intersects);
112 cls.def("isWithin", (bool (Box::*)(LonLat const &) const) & Box::isWithin);
113 cls.def("isWithin", (bool (Box::*)(Box const &) const) & Box::isWithin);
114 cls.def("clipTo", (Box & (Box::*)(LonLat const &)) & Box::clipTo);
115 cls.def("clipTo", (Box & (Box::*)(Box const &)) & Box::clipTo);
116 cls.def("clippedTo", (Box(Box::*)(LonLat const &) const) & Box::clippedTo);
117 cls.def("clippedTo", (Box(Box::*)(Box const &) const) & Box::clippedTo);
118 cls.def("expandTo", (Box & (Box::*)(LonLat const &)) & Box::expandTo);
119 cls.def("expandTo", (Box & (Box::*)(Box const &)) & Box::expandTo);
120 cls.def("expandedTo",
121 (Box(Box::*)(LonLat const &) const) & Box::expandedTo);
122 cls.def("expandedTo", (Box(Box::*)(Box const &) const) & Box::expandedTo);
123 cls.def("dilateBy", (Box & (Box::*)(Angle)) & Box::dilateBy, "angle"_a);
124 cls.def("dilateBy", (Box & (Box::*)(Angle, Angle)) & Box::dilateBy,
125 "width"_a, "height"_a);
126 cls.def("dilatedBy", (Box(Box::*)(Angle) const) & Box::dilatedBy,
127 "angle"_a);
128 cls.def("dilatedBy", (Box(Box::*)(Angle, Angle) const) & Box::dilatedBy,
129 "width"_a, "height"_a);
130 cls.def("erodeBy", (Box & (Box::*)(Angle)) & Box::erodeBy, "angle"_a);
131 cls.def("erodeBy", (Box & (Box::*)(Angle, Angle)) & Box::erodeBy, "width"_a,
132 "height"_a);
133 cls.def("erodedBy", (Box(Box::*)(Angle) const) & Box::erodedBy, "angle"_a);
134 cls.def("erodedBy", (Box(Box::*)(Angle, Angle) const) & Box::erodedBy,
135 "width"_a, "height"_a);
136 cls.def("getArea", &Box::getArea);
137 cls.def("relate",
138 (Relationship(Box::*)(LonLat const &) const) & Box::relate,
139 "point"_a);
140 // Rewrap this base class method since there are overloads in this subclass
141 cls.def("relate",
142 (Relationship(Box::*)(Region const &) const) & Box::relate,
143 "region"_a);
144
145 // Note that the Region interface has already been wrapped.
146
147 cls.def("__str__", [](Box const &self) {
148 return py::str("Box({!s}, {!s})").format(self.getLon(), self.getLat());
149 });
150 cls.def("__repr__", [](Box const &self) {
151 return py::str("Box({!r}, {!r})").format(self.getLon(), self.getLat());
152 });
153 cls.def(py::pickle(&python::encode, &python::decode<Box>));
154}
155
156} // sphgeom
157} // 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 ℝ³.
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
Box clippedTo(LonLat const &x) const
clippedTo returns the intersection of this box and x.
Definition: Box.h:235
AngleInterval const & getLat() const
getLat returns the latitude interval of this box.
Definition: Box.h:148
Box dilatedBy(Angle r) const
Definition: Box.h:273
static NormalizedAngle halfWidthForCircle(Angle r, Angle lat)
halfWidthForCircle computes the half-width of bounding boxes for circles with radius r and centers at...
Definition: Box.cc:43
Box & erodeBy(Angle r)
Definition: Box.h:292
NormalizedAngle getWidth() const
getWidth returns the width in longitude angle of this box.
Definition: Box.h:165
double getArea() const
getArea returns the area of this box in steradians.
Definition: Box.cc:115
static Box fromRadians(double lon1, double lat1, double lon2, double lat2)
Definition: Box.h:64
Box expandedTo(LonLat const &x) const
Definition: Box.h:263
NormalizedAngleInterval const & getLon() const
getLon returns the longitude interval of this box.
Definition: Box.h:145
Relationship relate(LonLat const &p) const
Definition: Box.h:297
bool isDisjointFrom(LonLat const &x) const
Definition: Box.h:186
static Box empty()
Definition: Box.h:69
bool isFull() const
isFull returns true if this box contains all points on the unit sphere.
Definition: Box.h:155
static constexpr uint8_t TYPE_CODE
Definition: Box.h:56
Box & dilateBy(Angle r)
dilateBy minimally expands this Box to include all points within angular separation r of its boundary...
Definition: Box.cc:78
Angle getHeight() const
getHeight returns the height in latitude angle of this box.
Definition: Box.h:169
LonLat getCenter() const
getCenter returns the center of this box.
Definition: Box.h:159
static NormalizedAngleInterval allLongitudes()
allLongitudes returns a normalized angle interval containing all valid longitude angles.
Definition: Box.h:81
bool isWithin(LonLat const &x) const
Definition: Box.h:206
Box erodedBy(Angle r) const
Definition: Box.h:294
Box & expandTo(LonLat const &x)
Definition: Box.h:246
static AngleInterval allLatitudes()
allLatitudes returns an angle interval containing all valid latitude angles.
Definition: Box.h:87
bool contains(LonLat const &x) const
Definition: Box.h:174
static Box fromDegrees(double lon1, double lat1, double lon2, double lat2)
Definition: Box.h:59
bool isEmpty() const
isEmpty returns true if this box does not contain any points.
Definition: Box.h:151
Box & clipTo(LonLat const &x)
clipTo shrinks this box until it contains only x.
Definition: Box.h:217
static Box full()
Definition: Box.h:71
bool intersects(LonLat const &x) const
Definition: Box.h:194
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
pybind11::bytes encode(Region const &self)
Encode a Region as a pybind11 bytes object.
Definition: utils.h:53
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
void defineClass(Pybind11Class &cls)
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.