LSST Applications 24.1.6,g063fba187b+e7121a6b04,g0f08755f38+4e0faf0f7f,g12f32b3c4e+7915c4de30,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g28da252d5a+94d9f37a33,g2bbee38e9b+ae03bbfc84,g2bc492864f+ae03bbfc84,g3156d2b45e+6e55a43351,g347aa1857d+ae03bbfc84,g35bb328faa+a8ce1bb630,g3a166c0a6a+ae03bbfc84,g3e281a1b8c+c5dd892a6c,g414038480c+6b9177ef31,g41af890bb2+9e154f3e8d,g6b1c1869cb+adc49b6f1a,g781aacb6e4+a8ce1bb630,g7af13505b9+3363a39af3,g7f202ee025+406ba613a5,g80478fca09+8fbba356e2,g82479be7b0+0d223595df,g858d7b2824+4e0faf0f7f,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,g9726552aa6+414189b318,ga5288a1d22+32d6120315,gacef1a1666+7f85da65db,gb58c049af0+d64f4d3760,gbcfae0f0a0+a8c62e8bb6,gc28159a63d+ae03bbfc84,gcf0d15dbbd+412a8a6f35,gda6a2b7d83+412a8a6f35,gdaeeff99f8+1711a396fd,ge79ae78c31+ae03bbfc84,gf0baf85859+c1f95f4921,gfa517265be+4e0faf0f7f,gfa999e8aa5+17cd334064,gfb92a5be7c+4e0faf0f7f
LSST Data Management Base Package
Loading...
Searching...
No Matches
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
95 Polygon(Box const& box, lsst::geom::AffineTransform const& transform);
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
128 std::vector<Point>::const_iterator begin() const;
129 std::vector<Point>::const_iterator end() const;
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
148 std::vector<bool> contains(std::vector<Point> const &points) const;
149 std::vector<bool> contains(std::vector<lsst::geom::Point2I> const &points) const;
151
153 template <typename Xtype, typename Ytype>
154 bool contains(Xtype x, Ytype y) const {
155 Point point(x, y);
156 return contains(point);
157 }
158
160
164 bool overlaps(Polygon const& other) const;
165 bool overlaps(Box const& box) const;
167
169
175 std::shared_ptr<Polygon> intersectionSingle(Box const& box) const;
177
179
185
187
191 std::shared_ptr<Polygon> unionSingle(Polygon const& other) const;
192 std::shared_ptr<Polygon> unionSingle(Box const& box) const;
194
196
202 std::vector<std::shared_ptr<Polygon>> union_(Box const& box) const;
204
206
210
214 std::shared_ptr<Polygon> simplify(double const distance) const;
215
217
221 std::vector<std::shared_ptr<Polygon>> operator|(Box const& rhs) const { return union_(rhs); }
225
228
230
235 std::shared_ptr<Polygon> transform(
236 TransformPoint2ToPoint2 const& transform
237 ) const;
238 std::shared_ptr<Polygon> transform(
239 lsst::geom::AffineTransform const& transform
240 ) const;
242
244
247 std::shared_ptr<Polygon> subSample(size_t num) const;
248 std::shared_ptr<Polygon> subSample(double maxLength) const;
250
252
265
267 bool isPersistable() const noexcept override { return true; }
268
271
273 std::string toString() const override;
274
280 bool equals(typehandling::Storable const& other) const noexcept override;
281
282protected:
283 std::string getPersistenceName() const override;
284
285 void write(OutputArchiveHandle& handle) const override;
286
287private:
289
290 struct Impl;
292 Polygon(std::shared_ptr<Impl> impl) : _impl(impl) {}
294};
296template bool Polygon::contains<double, double>(double, double) const;
297template bool Polygon::contains<float, float>(float, float) const;
298template bool Polygon::contains<int, int>(int, int) const;
300
302std::ostream& operator<<(std::ostream& os, Polygon const& poly);
303} // namespace polygon
304} // namespace geom
305} // namespace afw
306} // namespace lsst
307
308namespace std {
309template <>
313 size_t operator()(argument_type const& obj) const noexcept { return obj.hash_value(); }
314};
315} // namespace std
316
317#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:546
int y
Definition SpanSet.cc:48
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:222
std::shared_ptr< Polygon > unionSingle(Polygon const &other) const
Returns the union of two polygons.
Definition Polygon.cc:394
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:374
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::shared_ptr< Polygon > > operator|(Polygon const &rhs) const
Definition Polygon.h:220
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:221
std::shared_ptr< Polygon > intersectionSingle(Polygon const &other) const
Returns the intersection of two polygons.
Definition Polygon.cc:378
std::vector< std::shared_ptr< Polygon > > operator&(Polygon const &rhs) const
Operators for syntactic sugar.
Definition Polygon.h:218
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Box2I const &bbox) const
Create image of polygon.
Definition Polygon.cc:462
std::vector< std::shared_ptr< Polygon > > operator^(Box const &rhs) const
Definition Polygon.h:223
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:440
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
Definition Polygon.cc:386
size_t getNumEdges() const
Return number of edges.
Definition Polygon.cc:309
std::shared_ptr< typehandling::Storable > cloneStorable() const override
Create a new Polygon that is a copy of this one.
Definition Polygon.cc:609
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:414
std::vector< std::shared_ptr< Polygon > > operator&(Box const &rhs) const
Definition Polygon.h:219
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:613
bool isPersistable() const noexcept override
Whether Polygon is persistable which is always true.
Definition Polygon.h:267
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
Definition Polygon.cc:400
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:406
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Extent2I const &extent) const
Definition Polygon.h:261
std::string getPersistenceName() const override
Return the unique name used to persist this object and look up its factory.
Definition Polygon.cc:594
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:596
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:619
An exception that indicates the single-polygon assumption has been violated.
Definition Polygon.h:53
A CRTP facade class for subclasses of Persistable.
io::OutputArchiveHandle OutputArchiveHandle
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
DOXYGEN_IGNORE 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
STL namespace.
size_t operator()(argument_type const &obj) const noexcept
Definition Polygon.h:313
T swap(T... args)