LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
Public Types | Public Member Functions | List of all members
lsst::afw::geom::polygon::Polygon Class Reference

#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

void swap (Polygon &other)
 Swap two polygons. More...
 
size_t getNumEdges () const
 
Box getBBox () const
 Return bounding box. More...
 
Point calculateCenter () const
 
double calculateArea () const
 
double calculatePerimeter () const
 
std::vector< PointgetVertices () const
 
std::vector< std::pair< Point,
Point > > 
getEdges () const
 
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...
 
boost::shared_ptr< Polygonsimplify (double const distance) const
 
boost::shared_ptr< PolygonconvexHull () const
 Produce a polygon from the convex hull. More...
 
 Polygon (Box const &box)
 Constructors. More...
 
 Polygon (Box const &box, boost::shared_ptr< XYTransform const > const &transform)
 Constructors. More...
 
 Polygon (Box const &box, AffineTransform const &transform)
 Constructors. More...
 
 Polygon (std::vector< Point > const &vertices)
 Constructors. More...
 
std::vector< Point >
::const_iterator 
begin () const
 
std::vector< Point >
::const_iterator 
end () const
 
bool overlaps (Polygon const &other) const
 
bool overlaps (Box const &box) const
 
boost::shared_ptr< PolygonintersectionSingle (Polygon const &other) const
 
boost::shared_ptr< PolygonintersectionSingle (Box const &box) const
 
std::vector< boost::shared_ptr
< Polygon > > 
intersection (Polygon const &other) const
 
std::vector< boost::shared_ptr
< Polygon > > 
intersection (Box const &box) const
 
boost::shared_ptr< PolygonunionSingle (Polygon const &other) const
 
boost::shared_ptr< PolygonunionSingle (Box const &box) const
 
std::vector< boost::shared_ptr
< Polygon > > 
union_ (Polygon const &other) const
 
std::vector< boost::shared_ptr
< Polygon > > 
union_ (Box const &box) const
 
std::vector< boost::shared_ptr
< Polygon > > 
symDifference (Polygon const &other) const
 Return the symmetric difference of two polygons. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
symDifference (Box const &box) const
 Return the symmetric difference of two polygons. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
operator& (Polygon const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
operator& (Box const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
operator| (Polygon const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
operator| (Box const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
operator^ (Polygon const &rhs) const
 Operators for syntactic sugar. More...
 
std::vector< boost::shared_ptr
< Polygon > > 
operator^ (Box const &rhs) const
 Operators for syntactic sugar. More...
 
boost::shared_ptr< Polygontransform (boost::shared_ptr< XYTransform const > const &transform) const
 
boost::shared_ptr< Polygontransform (AffineTransform const &transform) const
 
boost::shared_ptr< PolygonsubSample (size_t num) const
 
boost::shared_ptr< PolygonsubSample (double maxLength) const
 
boost::shared_ptr
< afw::image::Image< float > > 
createImage (Box2I const &bbox) const
 
boost::shared_ptr
< afw::image::Image< float > > 
createImage (Extent2I const &extent) const
 
- Public Member Functions inherited from lsst::afw::table::io::Persistable
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...
 
virtual ~Persistable ()
 
boost::shared_ptr< Impl > _impl
 Whether Polygon is persistable which is always true. 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...
 
 Polygon (boost::shared_ptr< Impl > impl)
 Whether Polygon is persistable which is always true. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from lsst::afw::table::io::PersistableFacade< Polygon >
static boost::shared_ptr< Polygon > readFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object. More...
 
static boost::shared_ptr< Polygon > readFits (std::string const &fileName, int hdu=0)
 Read an object from a regular FITS file. More...
 
static boost::shared_ptr< Polygon > readFits (fits::MemFileManager &manager, int hdu=0)
 Read an object from a FITS file in memory. More...
 
- Protected Types inherited from lsst::afw::table::io::Persistable
typedef io::OutputArchiveHandle OutputArchiveHandle
 
- Protected Member Functions inherited from lsst::afw::table::io::Persistable
virtual std::string getPythonModule () const
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered. More...
 
 Persistable ()
 
 Persistable (Persistable const &other)
 
void operator= (Persistable const &other)
 

Detailed Description

Cartesian polygons

Polygons are defined by a set of vertices

Definition at line 55 of file Polygon.h.

Member Typedef Documentation

Definition at line 57 of file Polygon.h.

Definition at line 58 of file Polygon.h.

Constructor & Destructor Documentation

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

Constructors.

lsst::afw::geom::polygon::Polygon::Polygon ( Box const &  box,
boost::shared_ptr< XYTransform const > const &  transform 
)

Constructors.

Parameters
boxBox to convert to polygon
transformTransform from original to target frame
lsst::afw::geom::polygon::Polygon::Polygon ( Box const &  box,
AffineTransform const &  transform 
)

Constructors.

Parameters
boxBox to convert to polygon
transformTransform from original to target frame
lsst::afw::geom::polygon::Polygon::Polygon ( std::vector< Point > const &  vertices)
explicit

Constructors.

lsst::afw::geom::polygon::Polygon::Polygon ( boost::shared_ptr< Impl >  impl)
inlineprivate

Whether Polygon is persistable which is always true.

Definition at line 239 of file Polygon.h.

239 : _impl(impl) {}
boost::shared_ptr< Impl > _impl
Whether Polygon is persistable which is always true.
Definition: Polygon.h:237

Member Function Documentation

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").

double lsst::afw::geom::polygon::Polygon::calculateArea ( ) const
Point lsst::afw::geom::polygon::Polygon::calculateCenter ( ) const
double lsst::afw::geom::polygon::Polygon::calculatePerimeter ( ) const
bool lsst::afw::geom::polygon::Polygon::contains ( Point const &  point) const

Returns whether the polygon contains the point.

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

Produce a polygon from the convex hull.

boost::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.

boost::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 219 of file Polygon.h.

219  {
220  return createImage(Box2I(Point2I(0, 0), extent));
221  }
boost::shared_ptr< afw::image::Image< float > > createImage(Box2I const &bbox) const
Point< int, 2 > Point2I
Definition: Point.h:283
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").

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

Return bounding box.

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

Get vector of edges

Returns edges, as pairs of vertices.

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

Return number of edges

Identical with the number of points

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.

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.

std::vector<boost::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.

std::vector<boost::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.

boost::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.

boost::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.

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 226 of file Polygon.h.

226 { return true; }
bool lsst::afw::geom::polygon::Polygon::operator!= ( Polygon const &  other) const
inline

Definition at line 112 of file Polygon.h.

112 { return !(*this == other); }
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::operator& ( Polygon const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 176 of file Polygon.h.

176 { return intersection(rhs); }
std::vector< boost::shared_ptr< Polygon > > intersection(Polygon const &other) const
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::operator& ( Box const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 177 of file Polygon.h.

177 { return intersection(rhs); }
std::vector< boost::shared_ptr< Polygon > > intersection(Polygon const &other) const
bool lsst::afw::geom::polygon::Polygon::operator== ( Polygon const &  other) const
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::operator^ ( Polygon const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 180 of file Polygon.h.

180 { return symDifference(rhs); }
std::vector< boost::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::operator^ ( Box const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 181 of file Polygon.h.

181 { return symDifference(rhs); }
std::vector< boost::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::operator| ( Polygon const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 178 of file Polygon.h.

178 { return union_(rhs); }
std::vector< boost::shared_ptr< Polygon > > union_(Polygon const &other) const
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::operator| ( Box const &  rhs) const
inline

Operators for syntactic sugar.

Definition at line 179 of file Polygon.h.

179 { return union_(rhs); }
std::vector< boost::shared_ptr< Polygon > > union_(Polygon const &other) const
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.

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.

boost::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).

boost::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.

boost::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.

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

Swap two polygons.

Definition at line 74 of file Polygon.h.

74  {
75  std::swap(this->_impl, other._impl);
76  }
void swap(ImageBase< PixelT > &a, ImageBase< PixelT > &b)
Definition: Image.cc:291
boost::shared_ptr< Impl > _impl
Whether Polygon is persistable which is always true.
Definition: Polygon.h:237
std::vector<boost::shared_ptr< Polygon > > lsst::afw::geom::polygon::Polygon::symDifference ( Polygon const &  other) const

Return the symmetric difference of two polygons.

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

Return the symmetric difference of two polygons.

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

std::vector<boost::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.

boost::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.

boost::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.

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.

Member Data Documentation

boost::shared_ptr< Impl > lsst::afw::geom::polygon::Polygon::_impl
private

Whether Polygon is persistable which is always true.

Definition at line 237 of file Polygon.h.


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