LSSTApplications  1.1.2+25,10.0+13,10.0+132,10.0+133,10.0+224,10.0+41,10.0+8,10.0-1-g0f53050+14,10.0-1-g4b7b172+19,10.0-1-g61a5bae+98,10.0-1-g7408a83+3,10.0-1-gc1e0f5a+19,10.0-1-gdb4482e+14,10.0-11-g3947115+2,10.0-12-g8719d8b+2,10.0-15-ga3f480f+1,10.0-2-g4f67435,10.0-2-gcb4bc6c+26,10.0-28-gf7f57a9+1,10.0-3-g1bbe32c+14,10.0-3-g5b46d21,10.0-4-g027f45f+5,10.0-4-g86f66b5+2,10.0-4-gc4fccf3+24,10.0-40-g4349866+2,10.0-5-g766159b,10.0-5-gca2295e+25,10.0-6-g462a451+1
LSSTDataManagementBasePackage
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_H)
26 #define LSST_AFW_GEOM_POLYGON_H
27 
28 #include <vector>
29 #include <utility> // for std::pair
30 
31 #include "boost/make_shared.hpp"
32 
33 #include "lsst/base.h"
34 #include "lsst/pex/exceptions.h"
35 #include "lsst/afw/geom/Box.h"
36 #include "lsst/afw/geom/Point.h"
39 #include "lsst/afw/image/Image.h"
41 
42 namespace lsst { namespace afw { namespace geom {
43 
48 LSST_EXCEPTION_TYPE(SinglePolygonException, lsst::pex::exceptions::RuntimeError,
49  lsst::afw::geom::SinglePolygonException);
50 
54 class Polygon {
55 public:
56  typedef Box2D Box;
57  typedef Point2D Point;
58 
60  explicit Polygon(Box const& box);
62  Polygon(Box const& box,
64  );
65  Polygon(Box const& box,
67  );
68  explicit Polygon(std::vector<Point> const& vertices);
70 
72  void swap(Polygon& other) {
73  std::swap(this->_impl, other._impl);
74  }
75 
79  size_t getNumEdges() const;
80 
82  Box getBBox() const;
83 
84  Point calculateCenter() const;
85  double calculateArea() const;
86  double calculatePerimeter() const;
87 
93  std::vector<Point> getVertices() const;
94 
96  std::vector<Point>::const_iterator begin() const;
101  std::vector<Point>::const_iterator end() const;
103 
107  std::vector<std::pair<Point, Point> > getEdges() const;
108 
109  bool operator==(Polygon const& other) const;
110  bool operator!=(Polygon const& other) const { return !(*this == other); }
111 
113  bool contains(Point const& point) const;
114 
116  bool overlaps(Polygon const& other) const;
118  bool overlaps(Box const& box) const;
120 
122  Polygon intersectionSingle(Polygon const& other) const;
128  Polygon intersectionSingle(Box const& box) const;
130 
132  std::vector<Polygon> intersection(Polygon const& other) const;
136  std::vector<Polygon> intersection(Box const& box) const;
138 
140  Polygon unionSingle(Polygon const& other) const;
145  Polygon unionSingle(Box const& box) const;
147 
149  std::vector<Polygon> union_(Polygon const& other) const;
155  std::vector<Polygon> union_(Box const& box) const;
157 
159  std::vector<Polygon> operator&(Polygon const& rhs) const { return intersection(rhs); }
161  std::vector<Polygon> operator&(Box const& rhs) const { return intersection(rhs); }
162  std::vector<Polygon> operator|(Polygon const& rhs) const { return union_(rhs); }
163  std::vector<Polygon> operator|(Box const& rhs) const { return union_(rhs); }
165 
167  Polygon convexHull() const;
168 
177  ) const;
179  AffineTransform const& transform
180  ) const;
182 
184  Polygon subSample(size_t num) const;
188  Polygon subSample(double maxLength) const;
190 
192  PTR(afw::image::Image<float>) createImage(Box2I const& bbox) const;
201  PTR(afw::image::Image<float>) createImage(Extent2I const& extent) const {
202  return createImage(Box2I(Point2I(0, 0), extent));
203  }
205 
206 private:
208  struct Impl;
210  PTR(Impl) _impl;
211  Polygon(PTR(Impl) impl) : _impl(impl) {}
213 };
214 
216 std::ostream& operator<<(std::ostream& os, Polygon const& poly);
217 
218 }}} // namespace lsst::afw::geom
219 
220 #endif
#define CONST_PTR(...)
Definition: base.h:47
Polygon intersectionSingle(Polygon const &other) const
std::vector< Polygon > union_(Polygon const &other) const
Polygon unionSingle(Polygon const &other) const
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
std::vector< Polygon > operator&(Polygon const &rhs) const
Operators for syntactic sugar.
Definition: Polygon.h:160
std::ostream & operator<<(std::ostream &os, lsst::afw::geom::AffineTransform const &transform)
Point calculateCenter() const
void swap(Polygon &other)
Swap two polygons.
Definition: Polygon.h:72
std::vector< Point >::const_iterator begin() const
#define PTR(...)
Definition: base.h:41
Point< int, 2 > Point2I
Definition: PSF.h:39
Box getBBox() const
Return bounding box.
std::vector< std::pair< Point, Point > > getEdges() const
An integer coordinate rectangle.
Definition: Box.h:53
boost::shared_ptr< Impl > _impl
Definition: Polygon.h:209
table::Key< table::Array< Kernel::Pixel > > image
Definition: FixedKernel.cc:117
std::vector< Polygon > operator|(Polygon const &rhs) const
Operators for syntactic sugar.
Definition: Polygon.h:162
An affine coordinate transformation consisting of a linear transformation and an offset.
LSST_EXCEPTION_TYPE(SinglePolygonException, lsst::pex::exceptions::RuntimeError, lsst::afw::geom::SinglePolygonException)
std::vector< Point > getVertices() const
Support for 2-D images.
std::vector< Polygon > intersection(Polygon const &other) const
Polygon transform(boost::shared_ptr< XYTransform const > const &transform) const
Polygon(Box const &box)
Constructors.
std::vector< Polygon > operator|(Box const &rhs) const
Operators for syntactic sugar.
Definition: Polygon.h:163
A coordinate class intended to represent absolute positions.
bool contains(Point const &point) const
Returns whether the polygon contains the point.
std::vector< Point >::const_iterator end() const
double calculateArea() const
Virtual base class for 2D transforms.
Definition: XYTransform.h:48
bool overlaps(Polygon const &other) const
Returns whether the polygons overlap each other.
bool operator!=(Polygon const &other) const
Definition: Polygon.h:110
bool operator==(Polygon const &other) const
Implementation of the Class MaskedImage.
A floating-point coordinate rectangle geometry.
Definition: Box.h:271
Include files required for standard LSST Exception handling.
Class representing an invertible 2D transform.
size_t getNumEdges() const
double calculatePerimeter() const
Polygon convexHull() const
Produce a polygon from the convex hull.
std::vector< Polygon > operator&(Box const &rhs) const
Operators for syntactic sugar.
Definition: Polygon.h:161
Polygon subSample(size_t num) const
boost::shared_ptr< afw::image::Image< float > > createImage(Box2I const &bbox) const