LSSTApplications  12.1-5-gbdcc3ab,15.0+10,15.0+24,15.0-1-g19261fa+15,15.0-1-g60afb23+24,15.0-1-g615e0bb+16,15.0-1-g6668b0b+6,15.0-1-g788a293+24,15.0-1-ga91101e+24,15.0-1-gae1598d+9,15.0-1-gd076f1f+22,15.0-1-gdf18595+3,15.0-1-gf4f1c34+9,15.0-11-g7db6e543+2,15.0-12-g3681e7a+2,15.0-13-g5992896b,15.0-13-g7441b25,15.0-2-g100d730+17,15.0-2-g1f9c9cf+2,15.0-2-gf38729e+19,15.0-27-g6268be7ac,15.0-3-g11fe1a0+11,15.0-3-g52118bc+2,15.0-3-g707930d+1,15.0-3-g7b706ea+2,15.0-3-g9103c06+9,15.0-3-gd3cbb57+1,15.0-4-g535e784+8,15.0-4-g92ca6c3+2,15.0-4-gf906033,15.0-5-g23e394c+12,15.0-5-g993f083+4,15.0-5-gf788cd9+2,15.0-6-gdf787ba+1,15.0-6-gfa9b38f+2,15.0-7-g949993c+1,15.0-7-gbf600c9+3,15.0-8-gc213bcc,w.2018.20
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 
38 
39 namespace py = pybind11;
40 using namespace pybind11::literals;
41 
42 namespace lsst {
43 namespace sphgeom {
44 namespace {
45 
47  uint8_t const *buffer = reinterpret_cast<uint8_t const *>(
48  PYBIND11_BYTES_AS_STRING(bytes.ptr()));
49  size_t n = static_cast<size_t>(PYBIND11_BYTES_SIZE(bytes.ptr()));
50  return Box::decode(buffer, n);
51 }
52 
54  py::module mod("box");
55  py::module::import("lsst.sphgeom.region");
56 
57  py::class_<Box, std::shared_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("__setstate__", [](Box &self, py::bytes bytes) {
166  new (&self) Box(*decode(bytes));
167  });
168 
169  return mod.ptr();
170 }
171 
172 } // <anonymous>
173 } // sphgeom
174 } // lsst
This file declares a class for representing circular regions on the unit sphere.
lsst::afw::geom::Angle Angle
Definition: misc.h:33
This file declares a class for representing longitude/latitude angle boxes 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.
PYBIND11_PLUGIN(_cameraSys)
Definition: cameraSys.cc:62
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.
Relationship relate(VertexIterator const begin, VertexIterator const end, Box const &b)
This file declares a class representing closed intervals of normalized angles, i.e.
This file defines a class for representing angle intervals.
STL class.
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.
table::Key< table::Array< std::uint8_t > > bytes
Definition: Transform.cc:197