LSSTApplications  21.0.0+75b29a8a7f,21.0.0+e70536a077,21.0.0-1-ga51b5d4+62c747d40b,21.0.0-11-ga6ea59e8e+47cba9fc36,21.0.0-2-g103fe59+914993bf7c,21.0.0-2-g1367e85+e2614ded12,21.0.0-2-g45278ab+e70536a077,21.0.0-2-g4bc9b9f+7b2b5f8678,21.0.0-2-g5242d73+e2614ded12,21.0.0-2-g54e2caa+6403186824,21.0.0-2-g7f82c8f+3ac4acbffc,21.0.0-2-g8dde007+04a6aea1af,21.0.0-2-g8f08a60+9402881886,21.0.0-2-ga326454+3ac4acbffc,21.0.0-2-ga63a54e+81dd751046,21.0.0-2-gc738bc1+5f65c6e7a9,21.0.0-2-gde069b7+26c92b3210,21.0.0-2-gecfae73+0993ddc9bd,21.0.0-2-gfc62afb+e2614ded12,21.0.0-21-gba890a8+5a4f502a26,21.0.0-23-g9966ff26+03098d1af8,21.0.0-3-g357aad2+8ad216c477,21.0.0-3-g4be5c26+e2614ded12,21.0.0-3-g6d51c4a+4d2fe0280d,21.0.0-3-g7d9da8d+75b29a8a7f,21.0.0-3-gaa929c8+522e0f12c2,21.0.0-3-ge02ed75+4d2fe0280d,21.0.0-4-g3300ddd+e70536a077,21.0.0-4-gc004bbf+eac6615e82,21.0.0-4-gccdca77+f94adcd104,21.0.0-4-gd1c1571+18b81799f9,21.0.0-5-g7b47fff+4d2fe0280d,21.0.0-5-gb155db7+d2632f662b,21.0.0-5-gdf36809+637e4641ee,21.0.0-6-g722ad07+28c848f42a,21.0.0-7-g959bb79+522e0f12c2,21.0.0-7-gfd72ab2+cf01990774,21.0.0-9-g87fb7b8d+e2ab11cdd6,w.2021.04
LSSTDataManagementBasePackage
_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 <>
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
Region.h
This file defines an interface for spherical regions.
Box3d.h
This file declares a class for representing axis-aligned bounding boxes in ℝ³.
lsst::sphgeom::Region
Region is a minimal interface for 2-dimensional regions on the unit sphere.
Definition: Region.h:79
UnitVector3d.h
This file declares a class for representing unit vectors in ℝ³.
lsst::sphgeom::LonLat
LonLat represents a spherical coordinate (longitude/latitude angle) pair.
Definition: LonLat.h:48
lsst::sphgeom::Box
Box represents a rectangle in spherical coordinate space that contains its boundary.
Definition: Box.h:54
bytes
table::Key< table::Array< std::uint8_t > > bytes
Definition: python.h:135
python.h
Circle.h
This file declares a class for representing circular regions on the unit sphere.
lsst::afw::geom.transform.transformContinued.cls
cls
Definition: transformContinued.py:33
lsst::sphgeom::UnitVector3d
UnitVector3d is a unit vector in ℝ³ with components stored in double precision.
Definition: UnitVector3d.h:55
lsst::sphgeom::defineClass
void defineClass(py::class_< Box, std::unique_ptr< Box >, Region > &cls)
Definition: _box.cc:56
astshim.fitsChanContinued.contains
def contains(self, name)
Definition: fitsChanContinued.py:127
lsst::sphgeom::detail::relate
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
Definition: ConvexPolygonImpl.h:258
lsst.pipe.tasks.cli.cmd.commands.str
str
Definition: commands.py:50
utils.h
lsst::sphgeom::Relationship
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
Box.h
This file declares a class for representing longitude/latitude angle boxes on the unit sphere.
lsst
A base class for image defects.
Definition: imageAlgorithm.dox:1
NormalizedAngleInterval.h
This file declares a class representing closed intervals of normalized angles, i.e.
AngleInterval.h
This file defines a class for representing angle intervals.
LonLat.h
This file contains a class representing spherical coordinates.
relationship.h
Ellipse.h
This file declares a class for representing elliptical regions on the unit sphere.
pybind11
Definition: _GenericMap.cc:40
lsst::sphgeom::Angle
Angle represents an angle in radians.
Definition: Angle.h:43
std::unique_ptr
STL class.
ConvexPolygon.h
This file declares a class for representing convex polygons with great circle edges on the unit spher...