LSSTApplications  19.0.0-14-gb0260a2+72efe9b372,20.0.0+7927753e06,20.0.0+8829bf0056,20.0.0+995114c5d2,20.0.0+b6f4b2abd1,20.0.0+bddc4f4cbe,20.0.0-1-g253301a+8829bf0056,20.0.0-1-g2b7511a+0d71a2d77f,20.0.0-1-g5b95a8c+7461dd0434,20.0.0-12-g321c96ea+23efe4bbff,20.0.0-16-gfab17e72e+fdf35455f6,20.0.0-2-g0070d88+ba3ffc8f0b,20.0.0-2-g4dae9ad+ee58a624b3,20.0.0-2-g61b8584+5d3db074ba,20.0.0-2-gb780d76+d529cf1a41,20.0.0-2-ged6426c+226a441f5f,20.0.0-2-gf072044+8829bf0056,20.0.0-2-gf1f7952+ee58a624b3,20.0.0-20-geae50cf+e37fec0aee,20.0.0-25-g3dcad98+544a109665,20.0.0-25-g5eafb0f+ee58a624b3,20.0.0-27-g64178ef+f1f297b00a,20.0.0-3-g4cc78c6+e0676b0dc8,20.0.0-3-g8f21e14+4fd2c12c9a,20.0.0-3-gbd60e8c+187b78b4b8,20.0.0-3-gbecbe05+48431fa087,20.0.0-38-ge4adf513+a12e1f8e37,20.0.0-4-g97dc21a+544a109665,20.0.0-4-gb4befbc+087873070b,20.0.0-4-gf910f65+5d3db074ba,20.0.0-5-gdfe0fee+199202a608,20.0.0-5-gfbfe500+d529cf1a41,20.0.0-6-g64f541c+d529cf1a41,20.0.0-6-g9a5b7a1+a1cd37312e,20.0.0-68-ga3f3dda+5fca18c6a4,20.0.0-9-g4aef684+e18322736b,w.2020.45
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
Ellipse.h
This file declares a class for representing elliptical regions on the unit sphere.
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
Box.h
This file declares a class for representing longitude/latitude angle boxes on the unit sphere.
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
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::sphgeom::Relationship
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
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....
bytes
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199
AngleInterval.h
This file defines a class for representing angle intervals.
LonLat.h
This file contains a class representing spherical coordinates.
relationship.h
utils.h
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...