LSSTApplications  16.0-1-gce273f5+15,16.0-1-gf77f410+8,16.0-10-g230e10e+8,16.0-10-g5a5abec+4,16.0-10-gc1446dd+8,16.0-11-g5cf5345,16.0-12-g1dc09ba+2,16.0-12-g726f8f3+6,16.0-13-g4c33ca5+8,16.0-13-g5f6c0b1+8,16.0-13-gd9b1b71+8,16.0-14-g71e547a+4,16.0-17-g0bdc215,16.0-17-g6a7bfb3b+8,16.0-18-g95848a16+2,16.0-2-g0febb12+12,16.0-2-g839ba83+46,16.0-2-g9d5294e+35,16.0-3-g404ea43+7,16.0-3-gbc759ec+6,16.0-3-gcfd6c53+33,16.0-4-g03cf288+24,16.0-4-g13a27c5+10,16.0-4-g2cc461c+3,16.0-4-g5f3a788+11,16.0-4-g8a0f11a+30,16.0-4-ga3eb747+1,16.0-43-gaa65a4573+4,16.0-5-g1991253+8,16.0-5-g865efd9+8,16.0-5-gb3f8a4b+40,16.0-5-gd0f1235+4,16.0-6-g316b399+8,16.0-6-gf0acd13+27,16.0-6-gf9cb114+9,16.0-7-ga8e1655+4,16.0-8-g23bbf3f+1,16.0-8-g4dec96c+21,16.0-8-gfd407c0,w.2018.39
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 <memory>
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 namespace {
46 
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 PYBIND11_MODULE(box, mod) {
55  py::module::import("lsst.sphgeom.region");
56 
57  py::class_<Box, std::unique_ptr<Box>, Region> cls(mod, "Box");
58 
59  cls.attr("TYPE_CODE") = py::int_(Box::TYPE_CODE);
60 
61  cls.def_static("fromDegrees", &Box::fromDegrees, "lon1"_a, "lat1"_a,
62  "lon2"_a, "lat2"_a);
63  cls.def_static("fromRadians", &Box::fromRadians, "lon1"_a, "lat1"_a,
64  "lon2"_a, "lat2"_a);
65  cls.def_static("empty", &Box::empty);
66  cls.def_static("full", &Box::full);
67  cls.def_static("halfWidthForCircle", &Box::halfWidthForCircle, "radius"_a,
68  "lat"_a);
69  cls.def_static("allLongitudes", &Box::allLongitudes);
70  cls.def_static("allLatitudes", &Box::allLatitudes);
71 
72  cls.def(py::init<>());
73  cls.def(py::init<LonLat const &>(), "point"_a);
74  cls.def(py::init<LonLat const &, LonLat const &>(), "point1"_a, "point2"_a);
75  cls.def(py::init<LonLat const &, Angle, Angle>(), "center"_a, "width"_a,
76  "height"_a);
77  cls.def(py::init<NormalizedAngleInterval const &, AngleInterval const &>(),
78  "lon"_a, "lat"_a);
79  cls.def(py::init<Box const &>(), "box"_a);
80 
81  cls.def("__eq__", (bool (Box::*)(Box const &) const) & Box::operator==,
82  py::is_operator());
83  cls.def("__eq__", (bool (Box::*)(LonLat const &) const) & Box::operator==,
84  py::is_operator());
85  cls.def("__ne__", (bool (Box::*)(Box const &) const) & Box::operator!=,
86  py::is_operator());
87  cls.def("__ne__", (bool (Box::*)(LonLat const &) const) & Box::operator!=,
88  py::is_operator());
89  cls.def("__contains__",
90  (bool (Box::*)(LonLat const &) const) & Box::contains,
91  py::is_operator());
92  cls.def("__contains__", (bool (Box::*)(Box const &) const) & Box::contains,
93  py::is_operator());
94  // Rewrap this base class method since there are overloads in this subclass
95  cls.def("__contains__",
96  (bool (Box::*)(UnitVector3d const &) const) & Box::contains,
97  py::is_operator());
98 
99  cls.def("getLon", &Box::getLon);
100  cls.def("getLat", &Box::getLat);
101  cls.def("isEmpty", &Box::isEmpty);
102  cls.def("isFull", &Box::isFull);
103  cls.def("getCenter", &Box::getCenter);
104  cls.def("getWidth", &Box::getWidth);
105  cls.def("getHeight", &Box::getHeight);
106  cls.def("contains", (bool (Box::*)(LonLat const &) const) & Box::contains);
107  cls.def("contains", (bool (Box::*)(Box const &) const) & Box::contains);
108  // Rewrap this base class method since there are overloads in this subclass
109  cls.def("contains",
110  (bool (Box::*)(UnitVector3d const &) const) & Box::contains);
111  cls.def("isDisjointFrom",
112  (bool (Box::*)(LonLat const &) const) & Box::isDisjointFrom);
113  cls.def("isDisjointFrom",
114  (bool (Box::*)(Box const &) const) & Box::isDisjointFrom);
115  cls.def("intersects",
116  (bool (Box::*)(LonLat const &) const) & Box::intersects);
117  cls.def("intersects", (bool (Box::*)(Box const &) const) & Box::intersects);
118  cls.def("isWithin", (bool (Box::*)(LonLat const &) const) & Box::isWithin);
119  cls.def("isWithin", (bool (Box::*)(Box const &) const) & Box::isWithin);
120  cls.def("clipTo", (Box & (Box::*)(LonLat const &)) & Box::clipTo);
121  cls.def("clipTo", (Box & (Box::*)(Box const &)) & Box::clipTo);
122  cls.def("clippedTo", (Box(Box::*)(LonLat const &) const) & Box::clippedTo);
123  cls.def("clippedTo", (Box(Box::*)(Box const &) const) & Box::clippedTo);
124  cls.def("expandTo", (Box & (Box::*)(LonLat const &)) & Box::expandTo);
125  cls.def("expandTo", (Box & (Box::*)(Box const &)) & Box::expandTo);
126  cls.def("expandedTo",
127  (Box(Box::*)(LonLat const &) const) & Box::expandedTo);
128  cls.def("expandedTo", (Box(Box::*)(Box const &) const) & Box::expandedTo);
129  cls.def("dilateBy", (Box & (Box::*)(Angle)) & Box::dilateBy, "angle"_a);
130  cls.def("dilateBy", (Box & (Box::*)(Angle, Angle)) & Box::dilateBy,
131  "width"_a, "height"_a);
132  cls.def("dilatedBy", (Box(Box::*)(Angle) const) & Box::dilatedBy,
133  "angle"_a);
134  cls.def("dilatedBy", (Box(Box::*)(Angle, Angle) const) & Box::dilatedBy,
135  "width"_a, "height"_a);
136  cls.def("erodeBy", (Box & (Box::*)(Angle)) & Box::erodeBy, "angle"_a);
137  cls.def("erodeBy", (Box & (Box::*)(Angle, Angle)) & Box::erodeBy, "width"_a,
138  "height"_a);
139  cls.def("erodedBy", (Box(Box::*)(Angle) const) & Box::erodedBy, "angle"_a);
140  cls.def("erodedBy", (Box(Box::*)(Angle, Angle) const) & Box::erodedBy,
141  "width"_a, "height"_a);
142  cls.def("getArea", &Box::getArea);
143  cls.def("relate",
144  (Relationship(Box::*)(LonLat const &) const) & Box::relate,
145  "point"_a);
146  // Rewrap this base class method since there are overloads in this subclass
147  cls.def("relate",
148  (Relationship(Box::*)(Region const &) const) & Box::relate,
149  "region"_a);
150 
151  // Note that the Region interface has already been wrapped.
152 
153  // The lambda is necessary for now; returning the unique pointer
154  // directly leads to incorrect results and crashes.
155  cls.def_static("decode",
156  [](py::bytes bytes) { return decode(bytes).release(); },
157  "bytes"_a);
158 
159  cls.def("__str__", [](Box const &self) {
160  return py::str("Box({!s}, {!s})").format(self.getLon(), self.getLat());
161  });
162  cls.def("__repr__", [](Box const &self) {
163  return py::str("Box({!r}, {!r})").format(self.getLon(), self.getLat());
164  });
165  cls.def(py::pickle(
166  [](const Box &self) { return python::encode(self); },
167  [](py::bytes bytes) { return decode(bytes).release(); }));
168 }
169 
170 } // <anonymous>
171 } // sphgeom
172 } // lsst
This file declares a class for representing circular regions on the unit sphere.
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
std::bitset< 3 > Relationship
Relationship describes how two sets are related.
Definition: Relationship.h:35
This file declares a class for representing axis-aligned bounding boxes in ℝ³.
This file declares a class for representing elliptical regions on the unit sphere.
This file declares a class for representing unit vectors in ℝ³.
A base class for image defects.
Definition: cameraGeom.dox:3
This file defines an interface for spherical regions.
PYBIND11_MODULE(cameraSys, mod)
Definition: cameraSys.cc:62
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
This file declares a class for representing longitude/latitude angle boxes on the unit sphere...
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:199
This file declares a class representing closed intervals of normalized angles, i.e.
This file defines a class for representing angle intervals.
STL class.
lsst::geom::Angle Angle
Definition: misc.h:33
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.