lsst.afw  14.0-34-g2d9284d60+1
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | List of all members
lsst::afw::geom::polygon::Polygon Class Reference

Cartesian polygons. More...

#include <Polygon.h>

Inheritance diagram for lsst::afw::geom::polygon::Polygon:
lsst::afw::table::io::PersistableFacade< Polygon > lsst::afw::table::io::Persistable

Public Types

typedef Box2D Box
 
typedef Point2D Point
 

Public Member Functions

 Polygon (Box const &box)
 Construct a rectangular Polygon whose vertices are the corners of a box. More...
 
 Polygon (Box const &box, TransformPoint2ToPoint2 const &transform)
 Construct a 4-sided Polygon from a transformed box. More...
 
 Polygon (Box const &box, std::shared_ptr< XYTransform const > const &transform)
 Construct a 4-sided Polygon from a transformed box. More...
 
 Polygon (Box const &box, AffineTransform const &transform)
 Construct a 4-sided Polygon from a transformed box. More...
 
 Polygon (std::vector< Point > const &vertices)
 Construct a Polygon from a list of vertices. More...
 
void swap (Polygon &other)
 Swap two polygons. More...
 
size_t getNumEdges () const
 Return number of edges. More...
 
Box getBBox () const
 Return bounding box. More...
 
Point calculateCenter () const
 
double calculateArea () const
 
double calculatePerimeter () const
 
std::vector< Point > getVertices () const
 Get vector of vertices. More...
 
std::vector< std::pair< Point, Point > > getEdges () const
 Get vector of edges. More...
 
bool operator== (Polygon const &other) const
 
bool operator!= (Polygon const &other) const
 
bool contains (Point const &point) const
 Returns whether the polygon contains the point. More...
 
std::shared_ptr< Polygon > simplify (double const distance) const
 Return a simplified polygon. More...
 
std::shared_ptr< Polygon > convexHull () const
 Produce a polygon from the convex hull. More...
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file. More...
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory. More...
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object. More...
 
std::vector< Point >::const_iterator begin () const
 Iterator for vertices. More...
 
std::vector< Point >::const_iterator end () const
 Iterator for vertices. More...
 
bool overlaps (Polygon const &other) const
 Returns whether the polygons overlap each other. More...
 
bool overlaps (Box const &box) const
 Returns whether the polygons overlap each other. More...
 
std::shared_ptr< Polygon > intersectionSingle (Polygon const &other) const
 Returns the intersection of two polygons. More...
 
std::shared_ptr< Polygon > intersectionSingle (Box const &box) const
 Returns the intersection of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > intersection (Polygon const &other) const
 Returns the intersection of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > intersection (Box const &box) const
 Returns the intersection of two polygons. More...
 
std::shared_ptr< Polygon > unionSingle (Polygon const &other) const
 Returns the union of two polygons. More...
 
std::shared_ptr< Polygon > unionSingle (Box const &box) const
 Returns the union of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > union_ (Polygon const &other) const
 Returns the union of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > union_ (Box const &box) const
 Returns the union of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > symDifference (Polygon const &other) const
 Return the symmetric difference of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > symDifference (Box const &box) const
 Return the symmetric difference of two polygons. More...
 
std::vector< std::shared_ptr< Polygon > > operator & (Polygon const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< std::shared_ptr< Polygon > > operator & (Box const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< std::shared_ptr< Polygon > > operator| (Polygon const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< std::shared_ptr< Polygon > > operator| (Box const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< std::shared_ptr< Polygon > > operator^ (Polygon const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< std::shared_ptr< Polygon > > operator^ (Box const &rhs) const
 Operators for syntactic sugar. More...
 
std::shared_ptr< Polygon > transform (TransformPoint2ToPoint2 const &transform) const
 Transform the polygon. More...
 
std::shared_ptr< Polygon > transform (std::shared_ptr< XYTransform const > const &transform) const
 Transform the polygon. More...
 
std::shared_ptr< Polygon > transform (AffineTransform const &transform) const
 Transform the polygon. More...
 
std::shared_ptr< Polygon > subSample (size_t num) const
 Sub-sample each edge. More...
 
std::shared_ptr< Polygon > subSample (double maxLength) const
 Sub-sample each edge. More...
 
std::shared_ptr< afw::image::Image< float > > createImage (Box2I const &bbox) const
 Create image of polygon. More...
 
std::shared_ptr< afw::image::Image< float > > createImage (Extent2I const &extent) const
 Create image of polygon. More...
 

Static Public Member Functions

static std::shared_ptr< Polygon > readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static std::shared_ptr< Polygon > readFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 Read an object from a regular FITS file. More...
 
static std::shared_ptr< Polygon > readFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 Read an object from a FITS file in memory. More...
 

Protected Types

typedef io::OutputArchiveHandle OutputArchiveHandle
 

Protected Member Functions

virtual std::string getPythonModule () const
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
virtual bool isPersistable () const
 Whether Polygon is persistable which is always true. More...
 
virtual std::string getPersistenceName () const
 Whether Polygon is persistable which is always true. More...
 
virtual void write (OutputArchiveHandle &handle) const
 Whether Polygon is persistable which is always true. More...
 

Detailed Description

Cartesian polygons.

Polygons are defined by a set of vertices

Definition at line 59 of file Polygon.h.

Member Typedef Documentation

◆ Box

Definition at line 61 of file Polygon.h.

◆ OutputArchiveHandle

typedef io::OutputArchiveHandle lsst::afw::table::io::Persistable::OutputArchiveHandle
protectedinherited

Definition at line 108 of file Persistable.h.

◆ Point

Definition at line 62 of file Polygon.h.

Constructor & Destructor Documentation

◆ Polygon() [1/5]

lsst::afw::geom::polygon::Polygon::Polygon ( Box const &  box)
explicit

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

◆ Polygon() [2/5]

lsst::afw::geom::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]boxInitial box
[in]transformCoordinate transform

◆ Polygon() [3/5]

lsst::afw::geom::polygon::Polygon::Polygon ( Box const &  box,
std::shared_ptr< XYTransform const > 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 in the forward direction

Parameters
[in]boxInitial box
[in]transformCoordinate transform

◆ Polygon() [4/5]

lsst::afw::geom::polygon::Polygon::Polygon ( Box const &  box,
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]boxInitial box
[in]transformCoordinate transform

◆ Polygon() [5/5]

lsst::afw::geom::polygon::Polygon::Polygon ( std::vector< Point > const &  vertices)
explicit

Construct a Polygon from a list of vertices.

Member Function Documentation

◆ begin()

std::vector<Point>::const_iterator lsst::afw::geom::polygon::Polygon::begin ( ) const

Iterator for vertices.

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

◆ calculateArea()

double lsst::afw::geom::polygon::Polygon::calculateArea ( ) const

◆ calculateCenter()

Point lsst::afw::geom::polygon::Polygon::calculateCenter ( ) const

◆ calculatePerimeter()

double lsst::afw::geom::polygon::Polygon::calculatePerimeter ( ) const

◆ contains()

bool lsst::afw::geom::polygon::Polygon::contains ( Point const &  point) const

Returns whether the polygon contains the point.

◆ convexHull()

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::convexHull ( ) const

Produce a polygon from the convex hull.

◆ createImage() [1/2]

std::shared_ptr<afw::image::Image<float> > lsst::afw::geom::polygon::Polygon::createImage ( 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.

◆ createImage() [2/2]

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

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.

Definition at line 259 of file Polygon.h.

◆ end()

std::vector<Point>::const_iterator lsst::afw::geom::polygon::Polygon::end ( ) const

Iterator for vertices.

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

◆ getBBox()

Box lsst::afw::geom::polygon::Polygon::getBBox ( ) const

Return bounding box.

◆ getEdges()

std::vector<std::pair<Point, Point> > lsst::afw::geom::polygon::Polygon::getEdges ( ) const

Get vector of edges.

Returns edges, as pairs of vertices.

◆ getNumEdges()

size_t lsst::afw::geom::polygon::Polygon::getNumEdges ( ) const

Return number of edges.

Identical with the number of points

◆ getPersistenceName()

virtual std::string lsst::afw::geom::polygon::Polygon::getPersistenceName ( ) const
protectedvirtual

Whether Polygon is persistable which is always true.

Reimplemented from lsst::afw::table::io::Persistable.

◆ getPythonModule()

virtual std::string lsst::afw::table::io::Persistable::getPythonModule ( ) const
protectedvirtualinherited

◆ getVertices()

std::vector<Point> lsst::afw::geom::polygon::Polygon::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.

◆ intersection() [1/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::intersection ( Polygon const &  other) const

Returns the intersection of two polygons.

Handles the full range of possibilities.

◆ intersection() [2/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::intersection ( Box const &  box) const

Returns the intersection of two polygons.

Handles the full range of possibilities.

◆ intersectionSingle() [1/2]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::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.

◆ intersectionSingle() [2/2]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::intersectionSingle ( Box const &  box) 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.

◆ isPersistable()

virtual bool lsst::afw::geom::polygon::Polygon::isPersistable ( ) const
inlinevirtual

Whether Polygon is persistable which is always true.

Reimplemented from lsst::afw::table::io::Persistable.

Definition at line 266 of file Polygon.h.

◆ operator &() [1/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::operator& ( Polygon const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 213 of file Polygon.h.

◆ operator &() [2/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::operator& ( Box const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 214 of file Polygon.h.

◆ operator!=()

bool lsst::afw::geom::polygon::Polygon::operator!= ( Polygon const &  other) const
inline

Definition at line 149 of file Polygon.h.

◆ operator==()

bool lsst::afw::geom::polygon::Polygon::operator== ( Polygon const &  other) const

◆ operator^() [1/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::operator^ ( Polygon const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 217 of file Polygon.h.

◆ operator^() [2/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::operator^ ( Box const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 218 of file Polygon.h.

◆ operator|() [1/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::operator| ( Polygon const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 215 of file Polygon.h.

◆ operator|() [2/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::operator| ( Box const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 216 of file Polygon.h.

◆ overlaps() [1/2]

bool lsst::afw::geom::polygon::Polygon::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.

◆ overlaps() [2/2]

bool lsst::afw::geom::polygon::Polygon::overlaps ( Box const &  box) const

Returns whether the polygons overlap each other.

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

◆ readFits() [1/3]

static std::shared_ptr<Polygon > lsst::afw::table::io::PersistableFacade< Polygon >::readFits ( fits::Fits &  fitsfile)
inlinestaticinherited

Read an object from an already open FITS object.

Parameters
[in]fitsfileFITS object to read from, already positioned at the desired HDU.

Definition at line 181 of file Persistable.h.

◆ readFits() [2/3]

static std::shared_ptr<Polygon > lsst::afw::table::io::PersistableFacade< Polygon >::readFits ( std::string const &  fileName,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a regular FITS file.

Parameters
[in]fileNameName of the file to read.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 192 of file Persistable.h.

◆ readFits() [3/3]

static std::shared_ptr<Polygon > lsst::afw::table::io::PersistableFacade< Polygon >::readFits ( fits::MemFileManager &  manager,
int  hdu = fits::DEFAULT_HDU 
)
inlinestaticinherited

Read an object from a FITS file in memory.

Parameters
[in]managerManager for the memory to read from.
[in]hduHDU to read, where 0 is the primary. The special value of afw::fits::DEFAULT_HDU skips the primary HDU if it is empty.

Definition at line 203 of file Persistable.h.

◆ simplify()

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::simplify ( double const  distance) const

Return a simplified polygon.

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

◆ subSample() [1/2]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::subSample ( size_t  num) const

Sub-sample each edge.

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

◆ subSample() [2/2]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::subSample ( double  maxLength) const

Sub-sample each edge.

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

◆ swap()

void lsst::afw::geom::polygon::Polygon::swap ( Polygon &  other)
inline

Swap two polygons.

Definition at line 113 of file Polygon.h.

◆ symDifference() [1/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::symDifference ( Polygon const &  other) const

Return the symmetric difference of two polygons.

◆ symDifference() [2/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::symDifference ( Box const &  box) const

Return the symmetric difference of two polygons.

◆ transform() [1/3]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::transform ( TransformPoint2ToPoint2 const &  transform) const

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.

Parameters
transformTransform from original to target frame

◆ transform() [2/3]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::transform ( std::shared_ptr< XYTransform const > const &  transform) const

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.

Parameters
transformTransform from original to target frame

◆ transform() [3/3]

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

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.

Parameters
transformTransform from original to target frame

◆ union_() [1/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::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.

◆ union_() [2/2]

std::vector<std::shared_ptr<Polygon> > lsst::afw::geom::polygon::Polygon::union_ ( Box const &  box) 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.

◆ unionSingle() [1/2]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::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.

◆ unionSingle() [2/2]

std::shared_ptr<Polygon> lsst::afw::geom::polygon::Polygon::unionSingle ( Box const &  box) const

Returns the union of two polygons.

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

◆ write()

virtual void lsst::afw::geom::polygon::Polygon::write ( OutputArchiveHandle &  handle) const
protectedvirtual

Whether Polygon is persistable which is always true.

Reimplemented from lsst::afw::table::io::Persistable.

◆ writeFits() [1/3]

void lsst::afw::table::io::Persistable::writeFits ( std::string const &  fileName,
std::string const &  mode = "w" 
) const
inherited

Write the object to a regular FITS file.

Parameters
[in]fileNameName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

◆ writeFits() [2/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::MemFileManager &  manager,
std::string const &  mode = "w" 
) const
inherited

Write the object to a FITS image in memory.

Parameters
[in]managerName of the file to write to.
[in]modeIf "w", any existing file with the given name will be overwritten. If "a", new HDUs will be appended to an existing file.

◆ writeFits() [3/3]

void lsst::afw::table::io::Persistable::writeFits ( fits::Fits &  fitsfile) const
inherited

Write the object to an already-open FITS object.

Parameters
[in]fitsfileOpen FITS object to write to.

The documentation for this class was generated from the following file: