LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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
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
Extent< int, 2 > Extent2I
Definition Extent.h:397
Point< int, 2 > Point2I
Definition Point.h:321
STL namespace.