LSST Applications 26.0.0,g0265f82a02+6660c170cc,g07994bdeae+30b05a742e,g0a0026dc87+17526d298f,g0a60f58ba1+17526d298f,g0e4bf8285c+96dd2c2ea9,g0ecae5effc+c266a536c8,g1e7d6db67d+6f7cb1f4bb,g26482f50c6+6346c0633c,g2bbee38e9b+6660c170cc,g2cc88a2952+0a4e78cd49,g3273194fdb+f6908454ef,g337abbeb29+6660c170cc,g337c41fc51+9a8f8f0815,g37c6e7c3d5+7bbafe9d37,g44018dc512+6660c170cc,g4a941329ef+4f7594a38e,g4c90b7bd52+5145c320d2,g58be5f913a+bea990ba40,g635b316a6c+8d6b3a3e56,g67924a670a+bfead8c487,g6ae5381d9b+81bc2a20b4,g93c4d6e787+26b17396bd,g98cecbdb62+ed2cb6d659,g98ffbb4407+81bc2a20b4,g9ddcbc5298+7f7571301f,ga1e77700b3+99e9273977,gae46bcf261+6660c170cc,gb2715bf1a1+17526d298f,gc86a011abf+17526d298f,gcf0d15dbbd+96dd2c2ea9,gdaeeff99f8+0d8dbea60f,gdb4ec4c597+6660c170cc,ge23793e450+96dd2c2ea9,gf041782ebf+171108ac67
LSST Data Management Base Package
Loading...
Searching...
No Matches
_polygon.cc
Go to the documentation of this file.
1/*
2 * This file is part of afw.
3 *
4 * Developed for the LSST Data Management System.
5 * This product includes software developed by the LSST Project
6 * (https://www.lsst.org).
7 * See the COPYRIGHT file at the top-level directory of this distribution
8 * for details of code ownership.
9 *
10 * This program is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#include <memory>
25
26#include <pybind11/pybind11.h>
27#include <pybind11/numpy.h>
28#include <lsst/utils/python.h>
29
30#include <pybind11/stl.h>
31
34#include "lsst/geom/Box.h"
35#include "lsst/geom/Point.h"
40#include "lsst/afw/table/io/python.h" // for addPersistableMethods
41
42namespace py = pybind11;
43using namespace py::literals;
44
45namespace lsst {
46namespace afw {
47namespace geom {
48namespace polygon {
49namespace {
50void declarePolygon(lsst::utils::python::WrapperCollection &wrappers) {
51 wrappers.wrapType(
52 py::class_<Polygon, std::shared_ptr<Polygon>, typehandling::Storable>(wrappers.module, "Polygon"),
53 [](auto &mod, auto &cls) {
54 /* Constructors */
55 cls.def(py::init<Polygon::Box const &>());
56 cls.def(py::init<Polygon::Box const &, TransformPoint2ToPoint2 const &>());
57 cls.def(py::init<Polygon::Box const &, lsst::geom::AffineTransform const &>());
58 cls.def(py::init<std::vector<Polygon::Point> const &>());
59
60 table::io::python::addPersistableMethods<Polygon>(cls);
61
62 /* Operators */
63 cls.def(
64 "__eq__", [](Polygon const &self, Polygon const &other) { return self == other; },
65 py::is_operator());
66 cls.def(
67 "__ne__", [](Polygon const &self, Polygon const &other) { return self != other; },
68 py::is_operator());
69
70 /* Members */
71 cls.def("getNumEdges", &Polygon::getNumEdges);
72 cls.def("getBBox", &Polygon::getBBox);
73 cls.def("calculateCenter", &Polygon::calculateCenter);
74 cls.def("calculateArea", &Polygon::calculateArea);
75 cls.def("calculatePerimeter", &Polygon::calculatePerimeter);
76 cls.def("getVertices", &Polygon::getVertices);
77 cls.def("getEdges", &Polygon::getEdges);
78
79 cls.def("contains", (bool (Polygon::*)(Polygon::Point const&) const) &Polygon::contains);
80 cls.def("contains", (std::vector<bool> (Polygon::*)(std::vector<Polygon::Point> const&) const) &Polygon::contains);
81 cls.def("contains", (std::vector<bool> (Polygon::*)(std::vector<lsst::geom::Point2I> const&) const) &Polygon::contains);
82 cls.def("contains", py::vectorize((bool (Polygon::*)(double x, double y) const) &Polygon::contains<double, double>));
83 cls.def("contains", py::vectorize((bool (Polygon::*)(float x, float y) const) &Polygon::contains<float, float>));
84 cls.def("contains", py::vectorize((bool (Polygon::*)(int x, int y) const) &Polygon::contains<int, int>));
85
86 cls.def("overlaps", (bool (Polygon::*)(Polygon const &) const) & Polygon::overlaps);
87 cls.def("overlaps", (bool (Polygon::*)(Polygon::Box const &) const) & Polygon::overlaps);
88 cls.def("intersectionSingle", (std::shared_ptr<Polygon>(Polygon::*)(Polygon const &) const) &
89 Polygon::intersectionSingle);
90 cls.def("intersectionSingle",
91 (std::shared_ptr<Polygon>(Polygon::*)(Polygon::Box const &) const) &
92 Polygon::intersectionSingle);
93 cls.def("intersection",
94 (std::vector<std::shared_ptr<Polygon>>(Polygon::*)(Polygon const &) const) &
95 Polygon::intersection);
96 cls.def("intersection",
97 (std::vector<std::shared_ptr<Polygon>>(Polygon::*)(Polygon::Box const &) const) &
98 Polygon::intersection);
99 cls.def("unionSingle",
100 (std::shared_ptr<Polygon>(Polygon::*)(Polygon const &) const) & Polygon::unionSingle);
101 cls.def("unionSingle", (std::shared_ptr<Polygon>(Polygon::*)(Polygon::Box const &) const) &
102 Polygon::unionSingle);
103
104 // Wrap Polygon::union_ (C++) as Polygon.union (Python)
105 cls.def("union", (std::vector<std::shared_ptr<Polygon>>(Polygon::*)(Polygon const &) const) &
106 Polygon::union_);
107 cls.def("union",
108 (std::vector<std::shared_ptr<Polygon>>(Polygon::*)(Polygon::Box const &) const) &
109 Polygon::union_);
110 cls.def("symDifference",
111 (std::vector<std::shared_ptr<Polygon>>(Polygon::*)(Polygon const &) const) &
112 Polygon::symDifference);
113 cls.def("symDifference",
114 (std::vector<std::shared_ptr<Polygon>>(Polygon::*)(Polygon::Box const &) const) &
115 Polygon::symDifference);
116 // cls.def("simplify", &Polygon::simplify);
117 cls.def("convexHull", &Polygon::convexHull);
118 cls.def("transform",
119 (std::shared_ptr<Polygon>(Polygon::*)(TransformPoint2ToPoint2 const &) const) &
120 Polygon::transform);
121 cls.def("transform",
122 (std::shared_ptr<Polygon>(Polygon::*)(lsst::geom::AffineTransform const &) const) &
123 Polygon::transform);
124 cls.def("subSample",
125 (std::shared_ptr<Polygon>(Polygon::*)(size_t) const) & Polygon::subSample);
126 cls.def("subSample",
127 (std::shared_ptr<Polygon>(Polygon::*)(double) const) & Polygon::subSample);
128 cls.def("createImage", (std::shared_ptr<afw::image::Image<float>>(Polygon::*)(
129 lsst::geom::Box2I const &) const) &
130 Polygon::createImage);
131 cls.def("createImage", (std::shared_ptr<afw::image::Image<float>>(Polygon::*)(
132 lsst::geom::Extent2I const &) const) &
133 Polygon::createImage);
134 });
135}
136} // namespace
137void wrapPolygon(lsst::utils::python::WrapperCollection &wrappers) {
138 wrappers.addInheritanceDependency("lsst.pex.exceptions");
139 wrappers.addInheritanceDependency("lsst.afw.typehandling");
140 wrappers.addSignatureDependency("lsst.afw.table.io");
141 wrappers.wrapException<SinglePolygonException, pex::exceptions::RuntimeError>("SinglePolygonException",
142 "RuntimeError");
143 declarePolygon(wrappers);
144}
145} // namespace polygon
146} // namespace geom
147} // namespace afw
148} // namespace lsst
int y
Definition SpanSet.cc:48
table::Key< int > transform
Box getBBox() const
Return bounding box.
Definition Polygon.cc:314
std::shared_ptr< Polygon > convexHull() const
Produce a polygon from the convex hull.
Definition Polygon.cc:420
std::vector< std::pair< Point, Point > > getEdges() const
Get vector of edges.
Definition Polygon.cc:326
size_t getNumEdges() const
Return number of edges.
Definition Polygon.cc:309
std::vector< Point > getVertices() const
Get vector of vertices.
Definition Polygon.cc:337
An exception that indicates the single-polygon assumption has been violated.
Definition Polygon.h:53
Reports errors that are due to events beyond the control of the program.
Definition Runtime.h:104
void wrapPolygon(lsst::utils::python::WrapperCollection &)
Definition _polygon.cc:137
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Definition Transform.h:300
Extent< int, 2 > Extent2I
Definition Extent.h:397
Point< int, 2 > Point2I
Definition Point.h:321
STL namespace.