LSST Applications g0b6bd0c080+a72a5dd7e6,g1182afd7b4+2a019aa3bb,g17e5ecfddb+2b8207f7de,g1d67935e3f+06cf436103,g38293774b4+ac198e9f13,g396055baef+6a2097e274,g3b44f30a73+6611e0205b,g480783c3b1+98f8679e14,g48ccf36440+89c08d0516,g4b93dc025c+98f8679e14,g5c4744a4d9+a302e8c7f0,g613e996a0d+e1c447f2e0,g6c8d09e9e7+25247a063c,g7271f0639c+98f8679e14,g7a9cd813b8+124095ede6,g9d27549199+a302e8c7f0,ga1cf026fa3+ac198e9f13,ga32aa97882+7403ac30ac,ga786bb30fb+7a139211af,gaa63f70f4e+9994eb9896,gabf319e997+ade567573c,gba47b54d5d+94dc90c3ea,gbec6a3398f+06cf436103,gc6308e37c7+07dd123edb,gc655b1545f+ade567573c,gcc9029db3c+ab229f5caf,gd01420fc67+06cf436103,gd877ba84e5+06cf436103,gdb4cecd868+6f279b5b48,ge2d134c3d5+cc4dbb2e3f,ge448b5faa6+86d1ceac1d,gecc7e12556+98f8679e14,gf3ee170dca+25247a063c,gf4ac96e456+ade567573c,gf9f5ea5b4d+ac198e9f13,gff490e6085+8c2580be5c,w.2022.27
LSST Data Management Base Package
Polygon.h
Go to the documentation of this file.
1// -*- LSST-C++ -*-
2
3/*
4 * LSST Data Management System
5 * Copyright 2008-2014 LSST Corporation.
6 *
7 * This product includes software developed by the
8 * LSST Project (http://www.lsst.org/).
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 LSST License Statement and
21 * the GNU General Public License along with this program. If not,
22 * see <http://www.lsstcorp.org/LegalNotices/>.
23 */
24
25#if !defined(LSST_AFW_GEOM_POLYGON_POLYGON_H)
26#define LSST_AFW_GEOM_POLYGON_POLYGON_H
27
28#include <vector>
29#include <utility> // for std::pair
30
31#include <memory>
32
33#include "lsst/base.h"
34#include "lsst/pex/exceptions.h"
35#include "lsst/geom/Box.h"
36#include "lsst/geom/Point.h"
42
43namespace lsst {
44namespace afw {
45namespace geom {
46namespace polygon {
47
54
58
60public:
63
67 explicit Polygon(Box const& box);
68
73
74 ~Polygon() override;
75
84 Polygon(Box const& box, TransformPoint2ToPoint2 const& transform);
85
96
98 explicit Polygon(std::vector<Point> const& vertices);
100
102 void swap(Polygon& other) noexcept { std::swap(this->_impl, other._impl); }
103
107 size_t getNumEdges() const;
108
110 Box getBBox() const;
111
112 Point calculateCenter() const;
113 double calculateArea() const;
114 double calculatePerimeter() const;
115
122
124
131
136
137 bool operator==(Polygon const& other) const;
138 bool operator!=(Polygon const& other) const { return !(*this == other); }
139
141 std::size_t hash_value() const noexcept override;
142
144 bool contains(Point const& point) const;
145
147
151 bool overlaps(Polygon const& other) const;
152 bool overlaps(Box const& box) const;
154
156
161 std::shared_ptr<Polygon> intersectionSingle(Polygon const& other) const;
162 std::shared_ptr<Polygon> intersectionSingle(Box const& box) const;
164
166
169 std::vector<std::shared_ptr<Polygon>> intersection(Polygon const& other) const;
170 std::vector<std::shared_ptr<Polygon>> intersection(Box const& box) const;
172
174
178 std::shared_ptr<Polygon> unionSingle(Polygon const& other) const;
179 std::shared_ptr<Polygon> unionSingle(Box const& box) const;
181
183
188 std::vector<std::shared_ptr<Polygon>> union_(Polygon const& other) const;
189 std::vector<std::shared_ptr<Polygon>> union_(Box const& box) const;
191
193
194 std::vector<std::shared_ptr<Polygon>> symDifference(Polygon const& other) const;
195 std::vector<std::shared_ptr<Polygon>> symDifference(Box const& box) const;
197
201 std::shared_ptr<Polygon> simplify(double const distance) const;
202
204
205 std::vector<std::shared_ptr<Polygon>> operator&(Polygon const& rhs) const { return intersection(rhs); }
208 std::vector<std::shared_ptr<Polygon>> operator|(Box const& rhs) const { return union_(rhs); }
212
215
217
224 ) const;
227 ) const;
229
231
234 std::shared_ptr<Polygon> subSample(size_t num) const;
235 std::shared_ptr<Polygon> subSample(double maxLength) const;
237
239
250 }
252
254 bool isPersistable() const noexcept override { return true; }
255
258
260 std::string toString() const override;
261
267 bool equals(typehandling::Storable const& other) const noexcept override;
268
269protected:
270 std::string getPersistenceName() const override;
271
272 void write(OutputArchiveHandle& handle) const override;
273
274private:
276
277 struct Impl;
279 Polygon(std::shared_ptr<Impl> impl) : _impl(impl) {}
281};
282
284std::ostream& operator<<(std::ostream& os, Polygon const& poly);
285} // namespace polygon
286} // namespace geom
287} // namespace afw
288} // namespace lsst
289
290namespace std {
291template <>
292struct hash<lsst::afw::geom::polygon::Polygon> {
295 size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
296};
297} // namespace std
298
299#endif
AmpInfoBoxKey bbox
Definition: Amplifier.cc:117
#define LSST_EXCEPTION_TYPE(t, b, c)
Macro used to define new types of exceptions without additional data.
Definition: Exception.h:69
afw::table::PointKey< double > vertices
Definition: Polygon.cc:530
std::ostream * os
Definition: Schema.cc:557
Basic LSST definitions.
Transform LSST spatial data, such as lsst::geom::Point2D and lsst::geom::SpherePoint,...
Definition: Transform.h:68
Cartesian polygons.
Definition: Polygon.h:59
lsst::geom::Point2D Point
Definition: Polygon.h:62
std::vector< std::shared_ptr< Polygon > > operator^(Polygon const &rhs) const
Definition: Polygon.h:209
std::shared_ptr< Polygon > unionSingle(Polygon const &other) const
Returns the union of two polygons.
Definition: Polygon.cc:378
std::vector< Point >::const_iterator begin() const
Iterator for vertices.
Definition: Polygon.cc:339
bool operator!=(Polygon const &other) const
Definition: Polygon.h:138
bool overlaps(Polygon const &other) const
Returns whether the polygons overlap each other.
Definition: Polygon.cc:358
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:404
std::vector< std::shared_ptr< Polygon > > operator|(Polygon const &rhs) const
Definition: Polygon.h:207
std::vector< std::pair< Point, Point > > getEdges() const
Get vector of edges.
Definition: Polygon.cc:326
std::vector< std::shared_ptr< Polygon > > operator|(Box const &rhs) const
Definition: Polygon.h:208
std::shared_ptr< Polygon > intersectionSingle(Polygon const &other) const
Returns the intersection of two polygons.
Definition: Polygon.cc:362
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Box2I const &bbox) const
Create image of polygon.
Definition: Polygon.cc:446
std::vector< std::shared_ptr< Polygon > > operator^(Box const &rhs) const
Definition: Polygon.h:210
Polygon(Box const &box)
Construct a rectangular Polygon whose vertices are the corners of a box.
Definition: Polygon.cc:288
std::shared_ptr< Polygon > subSample(size_t num) const
Sub-sample each edge.
Definition: Polygon.cc:424
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
Definition: Polygon.cc:370
size_t getNumEdges() const
Return number of edges.
Definition: Polygon.cc:309
std::shared_ptr< Polygon > transform(TransformPoint2ToPoint2 const &transform) const
Transform the polygon.
Definition: Polygon.cc:410
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new Polygon that is a copy of this one.
Definition: Polygon.cc:593
std::vector< Point > getVertices() const
Get vector of vertices.
Definition: Polygon.cc:337
std::shared_ptr< Polygon > simplify(double const distance) const
Return a simplified polygon.
Definition: Polygon.cc:398
std::vector< std::shared_ptr< Polygon > > operator&(Box const &rhs) const
Definition: Polygon.h:206
bool operator==(Polygon const &other) const
Definition: Polygon.cc:345
std::string toString() const override
Create a string representation of this object.
Definition: Polygon.cc:597
bool isPersistable() const noexcept override
Whether Polygon is persistable which is always true.
Definition: Polygon.h:254
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
Definition: Polygon.cc:384
std::size_t hash_value() const noexcept override
Return a hash of this object.
Definition: Polygon.cc:349
std::vector< std::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
Definition: Polygon.cc:390
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Extent2I const &extent) const
Definition: Polygon.h:248
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition: Polygon.cc:578
bool contains(Point const &point) const
Returns whether the polygon contains the point.
Definition: Polygon.cc:356
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
Definition: Polygon.cc:580
void swap(Polygon &other) noexcept
Swap two polygons.
Definition: Polygon.h:102
Polygon & operator=(Polygon const &)
Polygon & operator=(Polygon &&)
std::vector< Point >::const_iterator end() const
Definition: Polygon.cc:341
bool equals(typehandling::Storable const &other) const noexcept override
Compare this object to another Storable.
Definition: Polygon.cc:603
double calculatePerimeter() const
Definition: Polygon.cc:324
An exception that indicates the single-polygon assumption has been violated.
Definition: Polygon.h:53
A CRTP facade class for subclasses of Persistable.
Definition: Persistable.h:176
io::OutputArchiveHandle OutputArchiveHandle
Definition: Persistable.h:108
Interface supporting iteration over heterogenous containers.
Definition: Storable.h:58
An affine coordinate transformation consisting of a linear transformation and an offset.
A floating-point coordinate rectangle geometry.
Definition: Box.h:413
An integer coordinate rectangle.
Definition: Box.h:55
Reports errors that are due to events beyond the control of the program.
Definition: Runtime.h:104
std::ostream & operator<<(std::ostream &os, Polygon const &poly)
Stream polygon.
Definition: Polygon.cc:176
Low-level polynomials (including special polynomials) in C++.
Point< double, 2 > Point2D
Definition: Point.h:324
A base class for image defects.
STL namespace.
size_t operator()(argument_type const &obj) const noexcept
Definition: Polygon.h:295
T swap(T... args)