Class Polygon

Inheritance Relationships

Base Types

Class Documentation

class Polygon : public lsst::afw::table::io::PersistableFacade<Polygon>, public Storable

Cartesian polygons

Polygons are defined by a set of vertices

Unnamed Group

std::vector<Point>::const_iterator begin() const

Iterator for vertices

Iterates only over the “open” polygon vertices (i.e., same number as returned by “getNumEdges”).

std::vector<Point>::const_iterator end() const

Unnamed Group

bool overlaps(Polygon const &other) const

Returns whether the polygons overlap each other

Note that there may be no intersection if the polygons only share a boundary.

bool overlaps(Box const &box) const

Unnamed Group

std::shared_ptr<Polygon> intersectionSingle(Polygon const &other) const

Returns the intersection of two polygons

Does not handle non-convex polygons (which might have multiple independent intersections), and is provided as a convenience for when the polygons are known to be convex (e.g., image borders) and overlapping.

std::shared_ptr<Polygon> intersectionSingle(Box const &box) const

Unnamed Group

std::vector<std::shared_ptr<Polygon>> intersection(Polygon const &other) const

Returns the intersection of two polygons

Handles the full range of possibilities.

std::vector<std::shared_ptr<Polygon>> intersection(Box const &box) const

Unnamed Group

std::shared_ptr<Polygon> unionSingle(Polygon const &other) const

Returns the union of two polygons

Does not handle non-overlapping polygons, the union of which would be disjoint.

std::shared_ptr<Polygon> unionSingle(Box const &box) const

Unnamed Group

std::vector<std::shared_ptr<Polygon>> union_(Polygon const &other) const

Returns the union of two polygons

Handles the full range of possibilities.

Note the trailing underscore in C++, due to “union” being a reserved word.

std::vector<std::shared_ptr<Polygon>> union_(Box const &box) const

Unnamed Group

std::vector<std::shared_ptr<Polygon>> symDifference(Polygon const &other) const

Return the symmetric difference of two polygons.

std::vector<std::shared_ptr<Polygon>> symDifference(Box const &box) const

Unnamed Group

std::vector<std::shared_ptr<Polygon>> operator&(Polygon const &rhs) const

Operators for syntactic sugar.

std::vector<std::shared_ptr<Polygon>> operator&(Box const &rhs) const
std::vector<std::shared_ptr<Polygon>> operator|(Polygon const &rhs) const
std::vector<std::shared_ptr<Polygon>> operator|(Box const &rhs) const
std::vector<std::shared_ptr<Polygon>> operator^(Polygon const &rhs) const
std::vector<std::shared_ptr<Polygon>> operator^(Box const &rhs) const

Unnamed Group

std::shared_ptr<Polygon> transform(TransformPoint2ToPoint2 const &transform) const

Parameters
  • transform: Transform from original to target frame

Transform the polygon

The transformation is only applied to the vertices. If the transformation is non-linear, the edges will not reflect that, but simply join the vertices. Greater fidelity might be achieved by using “subSample” before transforming.

std::shared_ptr<Polygon> transform(lsst::geom::AffineTransform const &transform) const

Parameters
  • transform: Transform from original to target frame

Unnamed Group

std::shared_ptr<Polygon> subSample(size_t num) const

Sub-sample each edge

This should provide greater fidelity when transforming with a non-linear transform.

std::shared_ptr<Polygon> subSample(double maxLength) const

Unnamed Group

std::shared_ptr<afw::image::Image<float>> createImage(lsst::geom::Box2I const &bbox) const

Create image of polygon

Pixels entirely contained within the polygon receive value unity, pixels entirely outside the polygon receive value zero, and pixels on the border receive a value equal to the fraction of the pixel within the polygon.

Note that the center of the lower-left pixel is 0,0.

std::shared_ptr<afw::image::Image<float>> createImage(lsst::geom::Extent2I const &extent) const

Public Types

typedef lsst::geom::Box2D Box
typedef lsst::geom::Point2D Point

Public Functions

Polygon(Box const &box)

Construct a rectangular Polygon whose vertices are the corners of a box

Polygon(Polygon const&)
Polygon(Polygon&&)
Polygon &operator=(Polygon const&)
Polygon &operator=(Polygon&&)
~Polygon()
Polygon(Box const &box, TransformPoint2ToPoint2 const &transform)

Construct a 4-sided Polygon from a transformed box

The resulting polygon has 4 vertices: transform.applyForward(bbox.getCorners())

Parameters
  • [in] box: Initial box

  • [in] transform: Coordinate transform

Polygon(Box const &box, lsst::geom::AffineTransform const &transform)

Construct a 4-sided Polygon from a transformed box

The resulting polygon has 4 vertices: the corners of the box transformed by transform

Parameters
  • [in] box: Initial box

  • [in] transform: Coordinate transform

Polygon(std::vector<Point> const &vertices)

Construct a Polygon from a list of vertices.

void swap(Polygon &other)

Swap two polygons.

size_t getNumEdges() const

Return number of edges

Identical with the number of points

Box getBBox() const

Return bounding box.

Point calculateCenter() const
double calculateArea() const
double calculatePerimeter() const
std::vector<Point> getVertices() const

Get vector of vertices

Note that the “closed” polygon vertices are returned, so the first and last vertex are identical and there is one more vertex than otherwise expected.

std::vector<std::pair<Point, Point>> getEdges() const

Get vector of edges

Returns edges, as pairs of vertices.

bool operator==(Polygon const &other) const
bool operator!=(Polygon const &other) const
std::size_t hash_value() const

Return a hash of this object.

bool contains(Point const &point) const

Returns whether the polygon contains the point.

std::shared_ptr<Polygon> simplify(double const distance) const

Return a simplified polygon

Removes unnecessary points (using the Douglas-Peucker algorithm).

std::shared_ptr<Polygon> convexHull() const

Produce a polygon from the convex hull.

bool isPersistable() const

Whether Polygon is persistable which is always true.

std::shared_ptr<typehandling::Storable> cloneStorable() const

Create a new Polygon that is a copy of this one.

std::string toString() const

Create a string representation of this object.

bool equals(typehandling::Storable const &other) const

Compare this object to another Storable.

Return

*this == other if other is a Polygon; otherwise false.

Protected Functions

std::string getPersistenceName() const
void write(OutputArchiveHandle &handle) const