LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Protected Member Functions | Static Protected Member Functions | Related Symbols | List of all members
lsst::afw::geom::polygon::Polygon Class Referencefinal

Cartesian polygons. More...

#include <Polygon.h>

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

Classes

struct  Impl
 

Public Types

using Box = lsst::geom::Box2D
 
using Point = lsst::geom::Point2D
 

Public Member Functions

 Polygon (Box const &box)
 Construct a rectangular Polygon whose vertices are the corners of a box.
 
 Polygon (Polygon const &)
 
 Polygon (Polygon &&)
 
Polygonoperator= (Polygon const &)
 
Polygonoperator= (Polygon &&)
 
 ~Polygon () override
 
 Polygon (Box const &box, TransformPoint2ToPoint2 const &transform)
 Construct a 4-sided Polygon from a transformed box.
 
 Polygon (Box const &box, lsst::geom::AffineTransform const &transform)
 Construct a 4-sided Polygon from a transformed box.
 
 Polygon (std::vector< Point > const &vertices)
 Construct a Polygon from a list of vertices.
 
void swap (Polygon &other) noexcept
 Swap two polygons.
 
size_t getNumEdges () const
 Return number of edges.
 
Box getBBox () const
 Return bounding box.
 
Point calculateCenter () const
 
double calculateArea () const
 
double calculatePerimeter () const
 
std::vector< PointgetVertices () const
 Get vector of vertices.
 
std::vector< Point >::const_iterator begin () const
 Iterator for vertices.
 
std::vector< Point >::const_iterator end () const
 
std::vector< std::pair< Point, Point > > getEdges () const
 Get vector of edges.
 
bool operator== (Polygon const &other) const
 
bool operator!= (Polygon const &other) const
 
std::size_t hash_value () const noexcept override
 Return a hash of this object.
 
bool contains (Point const &point) const
 Returns whether the polygon contains the point.
 
std::vector< bool > contains (std::vector< Point > const &points) const
 Returns whether the polygon contains the vector of points.
 
std::vector< bool > contains (std::vector< lsst::geom::Point2I > const &points) const
 
template<typename Xtype , typename Ytype >
bool contains (Xtype x, Ytype y) const
 Returns whether the polygon contains the x, y pair.
 
bool overlaps (Polygon const &other) const
 Returns whether the polygons overlap each other.
 
bool overlaps (Box const &box) const
 
std::shared_ptr< PolygonintersectionSingle (Polygon const &other) const
 Returns the intersection of two polygons.
 
std::shared_ptr< PolygonintersectionSingle (Box const &box) const
 
std::vector< std::shared_ptr< Polygon > > intersection (Polygon const &other) const
 Returns the intersection of two polygons.
 
std::vector< std::shared_ptr< Polygon > > intersection (Box const &box) const
 
std::shared_ptr< PolygonunionSingle (Polygon const &other) const
 Returns the union of two polygons.
 
std::shared_ptr< PolygonunionSingle (Box const &box) const
 
std::vector< std::shared_ptr< Polygon > > union_ (Polygon const &other) const
 Returns the union of two polygons.
 
std::vector< std::shared_ptr< Polygon > > union_ (Box const &box) const
 
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
 
std::shared_ptr< Polygonsimplify (double const distance) const
 Return a simplified polygon.
 
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
 
std::shared_ptr< PolygonconvexHull () const
 Produce a polygon from the convex hull.
 
std::shared_ptr< Polygontransform (TransformPoint2ToPoint2 const &transform) const
 Transform the polygon.
 
std::shared_ptr< Polygontransform (lsst::geom::AffineTransform const &transform) const
 
std::shared_ptr< PolygonsubSample (size_t num) const
 Sub-sample each edge.
 
std::shared_ptr< PolygonsubSample (double maxLength) const
 
std::shared_ptr< afw::image::Image< float > > createImage (lsst::geom::Box2I const &bbox) const
 Create image of polygon.
 
std::shared_ptr< afw::image::Image< float > > createImage (lsst::geom::Extent2I const &extent) const
 
bool isPersistable () const noexcept override
 Whether Polygon is persistable which is always true.
 
std::shared_ptr< typehandling::StorablecloneStorable () const override
 Create a new Polygon that is a copy of this one.
 
std::string toString () const override
 Create a string representation of this object.
 
bool equals (typehandling::Storable const &other) const noexcept override
 Compare this object to another Storable.
 
 __repr__ (self)
 
 __reduce__ (self)
 
 __iter__ (self)
 
 __getitem__ (self, i)
 
 __len__ (self)
 
 __contains__ (self, point)
 
 display (self, xy0=None, frame=1, ctype=None)
 
 plot (self, axes=None, **kwargs)
 
void writeFits (std::string const &fileName, std::string const &mode="w") const
 Write the object to a regular FITS file.
 
void writeFits (fits::MemFileManager &manager, std::string const &mode="w") const
 Write the object to a FITS image in memory.
 
void writeFits (fits::Fits &fitsfile) const
 Write the object to an already-open FITS object.
 

Static Public Member Functions

static std::shared_ptr< PolygonreadFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object.
 
static std::shared_ptr< PolygonreadFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 Read an object from a regular FITS file.
 
static std::shared_ptr< PolygonreadFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 Read an object from a FITS file in memory.
 
static std::shared_ptr< PolygondynamicCast (std::shared_ptr< Persistable > const &ptr)
 Dynamically cast a shared_ptr.
 

Protected Types

using OutputArchiveHandle = io::OutputArchiveHandle
 

Protected Member Functions

std::string getPersistenceName () const override
 Return the unique name used to persist this object and look up its factory.
 
void write (OutputArchiveHandle &handle) const override
 Write the object to one or more catalogs.
 
virtual std::string getPythonModule () const
 Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.
 

Static Protected Member Functions

template<class T >
static bool singleClassEquals (T const &lhs, Storable const &rhs)
 Test if a Storable is of a particular class and equal to another object.
 

Related Symbols

(Note that these are not member symbols.)

std::ostreamoperator<< (std::ostream &os, Storable const &storable)
 Output operator for Storable.
 

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

using lsst::afw::table::io::Persistable::OutputArchiveHandle = io::OutputArchiveHandle
protectedinherited

Definition at line 108 of file Persistable.h.

◆ Point

Definition at line 62 of file Polygon.h.

Constructor & Destructor Documentation

◆ Polygon() [1/6]

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

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

Definition at line 288 of file Polygon.cc.

288: _impl(new Polygon::Impl(box)) {}

◆ Polygon() [2/6]

lsst::afw::geom::polygon::Polygon::Polygon ( Polygon const & )
default

◆ Polygon() [3/6]

lsst::afw::geom::polygon::Polygon::Polygon ( Polygon && )
default

◆ ~Polygon()

lsst::afw::geom::polygon::Polygon::~Polygon ( )
overridedefault

◆ Polygon() [4/6]

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

Definition at line 292 of file Polygon.cc.

293 : _impl(new Polygon::Impl()) {
294 auto corners = transform.applyForward(boxToCorners(box));
295 boost::geometry::assign(_impl->poly, corners);
296 _impl->check();
297}
std::shared_ptr< Polygon > transform(TransformPoint2ToPoint2 const &transform) const
Transform the polygon.
Definition Polygon.cc:426

◆ Polygon() [5/6]

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

Definition at line 299 of file Polygon.cc.

300 : _impl(new Polygon::Impl()) {
301 std::vector<LsstPoint> corners = boxToCorners(box);
302 for (auto & corner : corners) {
303 corner = transform(corner);
304 }
305 boost::geometry::assign(_impl->poly, corners);
306 _impl->check();
307}

◆ Polygon() [6/6]

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

Construct a Polygon from a list of vertices.

Definition at line 290 of file Polygon.cc.

290: _impl(new Polygon::Impl(vertices)) {}
afw::table::PointKey< double > vertices
Definition Polygon.cc:546

Member Function Documentation

◆ __contains__()

lsst.afw.geom.polygon.Polygon.__contains__ ( self,
point )
point in polygon?

Definition at line 47 of file polygon.py.

47 def __contains__(self, point):
48 """point in polygon?"""
49 return self.contains(point)
50

◆ __getitem__()

lsst.afw.geom.polygon.Polygon.__getitem__ ( self,
i )

Definition at line 41 of file polygon.py.

41 def __getitem__(self, i):
42 return [pt for pt in self][i]
43

◆ __iter__()

lsst.afw.geom.polygon.Polygon.__iter__ ( self)
Iterator over vertices

Definition at line 36 of file polygon.py.

36 def __iter__(self):
37 """Iterator over vertices"""
38 vertices = self.getVertices()
39 return iter(vertices)
40

◆ __len__()

lsst.afw.geom.polygon.Polygon.__len__ ( self)

Definition at line 44 of file polygon.py.

44 def __len__(self):
45 return self.getNumEdges()
46

◆ __reduce__()

lsst.afw.geom.polygon.Polygon.__reduce__ ( self)

Definition at line 33 of file polygon.py.

33 def __reduce__(self):
34 return self.__class__, (self.getVertices(),)
35

◆ __repr__()

lsst.afw.geom.polygon.Polygon.__repr__ ( self)

Definition at line 30 of file polygon.py.

30 def __repr__(self):
31 return f"{self.__class__.__name__}({[p for p in self.getVertices()]})"
32

◆ begin()

std::vector< LsstPoint >::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").

Definition at line 339 of file Polygon.cc.

339{ return _impl->poly.outer().begin(); }

◆ calculateArea()

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

Definition at line 322 of file Polygon.cc.

322{ return boost::geometry::area(_impl->poly); }

◆ calculateCenter()

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

Definition at line 318 of file Polygon.cc.

318 {
319 return boost::geometry::return_centroid<LsstPoint>(_impl->poly);
320}

◆ calculatePerimeter()

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

Definition at line 324 of file Polygon.cc.

324{ return boost::geometry::perimeter(_impl->poly); }

◆ cloneStorable()

std::shared_ptr< typehandling::Storable > lsst::afw::geom::polygon::Polygon::cloneStorable ( ) const
overridevirtual

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

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 609 of file Polygon.cc.

609 {
610 return std::make_unique<Polygon>(*this);
611}

◆ contains() [1/4]

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

Returns whether the polygon contains the point.

Definition at line 356 of file Polygon.cc.

356{ return boost::geometry::within(point, _impl->poly); }

◆ contains() [2/4]

std::vector< bool > lsst::afw::geom::polygon::Polygon::contains ( std::vector< lsst::geom::Point2I > const & points) const

Definition at line 366 of file Polygon.cc.

366 {
367 std::vector<bool> results;
368 for (lsst::geom::PointI const & p : points) {
369 results.push_back(contains(Point(p)));
370 }
371 return results;
372}
lsst::geom::Point2D Point
Definition Polygon.h:62
bool contains(Point const &point) const
Returns whether the polygon contains the point.
Definition Polygon.cc:356
T push_back(T... args)

◆ contains() [3/4]

std::vector< bool > lsst::afw::geom::polygon::Polygon::contains ( std::vector< Point > const & points) const

Returns whether the polygon contains the vector of points.

Definition at line 358 of file Polygon.cc.

358 {
359 std::vector<bool> results;
360 for (Point const & p : points) {
361 results.push_back(contains(p));
362 }
363 return results;
364}

◆ contains() [4/4]

template<typename Xtype , typename Ytype >
bool lsst::afw::geom::polygon::Polygon::contains ( Xtype x,
Ytype y ) const
inline

Returns whether the polygon contains the x, y pair.

Definition at line 154 of file Polygon.h.

154 {
155 Point point(x, y);
156 return contains(point);
157 }
int y
Definition SpanSet.cc:48

◆ convexHull()

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

Produce a polygon from the convex hull.

Definition at line 420 of file Polygon.cc.

420 {
421 BoostPolygon hull;
422 boost::geometry::convex_hull(_impl->poly, hull);
423 return std::shared_ptr<Polygon>(new Polygon(std::make_shared<Impl>(hull)));
424}
boost::geometry::model::polygon< LsstPoint > BoostPolygon
Definition Polygon.cc:20
Polygon(Box const &box)
Construct a rectangular Polygon whose vertices are the corners of a box.
Definition Polygon.cc:288

◆ createImage() [1/2]

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

Definition at line 462 of file Polygon.cc.

462 {
463 using Image = afw::image::Image<float>;
464 std::shared_ptr<Image> image = std::make_shared<Image>(bbox);
465 image->setXY0(bbox.getMin());
466 *image = 0.0;
467 lsst::geom::Box2D bounds = getBBox(); // Polygon bounds
468 int xMin = std::max(static_cast<int>(bounds.getMinX()), bbox.getMinX());
469 int xMax = std::min(static_cast<int>(::ceil(bounds.getMaxX())), bbox.getMaxX());
470 int yMin = std::max(static_cast<int>(bounds.getMinY()), bbox.getMinY());
471 int yMax = std::min(static_cast<int>(::ceil(bounds.getMaxY())), bbox.getMaxY());
472 for (int y = yMin; y <= yMax; ++y) {
473 double const yPixelMin = (double)y - 0.5, yPixelMax = (double)y + 0.5;
474 BoostPolygon row; // A polygon of row y
475 boost::geometry::assign(
476 row, LsstBox(lsst::geom::Point2D(xMin, yPixelMin), lsst::geom::Point2D(xMax, yPixelMax)));
477 std::vector<BoostPolygon> intersections;
478 boost::geometry::intersection(_impl->poly, row, intersections);
479
480 if (intersections.size() == 1 && boost::geometry::num_points(intersections[0]) == 5) {
481 // This row is fairly tame, and should have a long run of pixels within the polygon
482 BoostPolygon const& row = intersections[0];
483 std::vector<double> top, bottom;
484 top.reserve(2);
485 bottom.reserve(2);
486 bool failed = false;
487 for (std::vector<Point>::const_iterator i = row.outer().begin(); i != row.outer().end() - 1;
488 ++i) {
489 double const xCoord = i->getX(), yCoord = i->getY();
490 if (yCoord == yPixelMin) {
491 bottom.push_back(xCoord);
492 } else if (yCoord == yPixelMax) {
493 top.push_back(xCoord);
494 } else {
495 failed = true;
496 break;
497 }
498 }
499 if (!failed && top.size() == 2 && bottom.size() == 2) {
500 std::sort(top.begin(), top.end());
501 std::sort(bottom.begin(), bottom.end());
502 int const xMin = std::min(top[0], bottom[0]);
503 int const xStart = ::ceil(std::max(top[0], bottom[0])) + 1;
504 int const xStop = std::min(top[1], bottom[1]) - 1;
505 int const xMax = ::ceil(std::max(top[1], bottom[1]));
506 pixelRowOverlap(image, _impl->poly, std::max(xMin, bbox.getMinX()),
507 std::min(xStart, bbox.getMaxX()), y);
508 int x = xStart;
509 for (Image::x_iterator i = image->x_at(std::max(xStart, bbox.getMinX()) - image->getX0(),
510 y - image->getY0());
511 x <= std::min(xStop, bbox.getMaxX()); ++i, ++x) {
512 *i = 1.0;
513 }
514 pixelRowOverlap(image, _impl->poly, std::max(xStop, bbox.getMinX()),
515 std::min(xMax, bbox.getMaxX()), y);
516 continue;
517 }
518 }
519
520 // Last resort: do each pixel independently...
521 for (auto const &intersection : intersections) {
522 double xMinRow = xMax, xMaxRow = xMin;
524 for (auto const &vertice : vertices) {
525 double const x = vertice.getX();
526 if (x < xMinRow) xMinRow = x;
527 if (x > xMaxRow) xMaxRow = x;
528 }
529
530 pixelRowOverlap(image, _impl->poly, std::max(static_cast<int>(xMinRow), bbox.getMinX()),
531 std::min(static_cast<int>(::ceil(xMaxRow)), bbox.getMaxX()), y);
532 }
533 }
534 return image;
535}
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
lsst::afw::geom::polygon::Polygon::Box LsstBox
Definition Polygon.cc:18
T begin(T... args)
Box getBBox() const
Return bounding box.
Definition Polygon.cc:314
std::vector< std::shared_ptr< Polygon > > intersection(Polygon const &other) const
Returns the intersection of two polygons.
Definition Polygon.cc:386
A floating-point coordinate rectangle geometry.
Definition Box.h:413
double getMaxY() const noexcept
Definition Box.h:519
double getMaxX() const noexcept
Definition Box.h:518
double getMinY() const noexcept
Definition Box.h:515
double getMinX() const noexcept
Definition Box.h:514
T end(T... args)
T max(T... args)
T min(T... args)
T reserve(T... args)
T size(T... args)
T sort(T... args)
int row
Definition CR.cc:145
g2d::python::Image< double > Image
Definition test_image.cc:14

◆ createImage() [2/2]

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

Definition at line 261 of file Polygon.h.

261 {
263 }
std::shared_ptr< afw::image::Image< float > > createImage(lsst::geom::Box2I const &bbox) const
Create image of polygon.
Definition Polygon.cc:462
An integer coordinate rectangle.
Definition Box.h:55

◆ display()

lsst.afw.geom.polygon.Polygon.display ( self,
xy0 = None,
frame = 1,
ctype = None )
Display polygon on existing frame

Definition at line 51 of file polygon.py.

51 def display(self, xy0=None, frame=1, ctype=None):
52 """Display polygon on existing frame"""
53 import lsst.geom
54 import lsst.afw.display as afwDisplay
55 xy0 = lsst.geom.Extent2D(0, 0) if xy0 is None else lsst.geom.Extent2D(xy0)
56 disp = afwDisplay.Display(frame=frame)
57 with disp.Buffering():
58 for p1, p2 in self.getEdges():
59 disp.line((p1 - xy0, p2 - xy0), ctype=ctype)
60

◆ dynamicCast()

Dynamically cast a shared_ptr.

Dynamically cast a shared pointer and raise on failure.

You must provide an explicit template instantiation in the .cc file for each class that inherits from PersistableFacade. Designed to work around RTTI issues on macOS with hidden symbols;

Exceptions
lsst::pex::exceptions::LogicErrorif the cast fails

param[in] ptr The pointer to be cast.

Returns
The cast pointer.
Exceptions
lsst::pex::exceptions::TypeErrorIf the dynamic cast fails.

Definition at line 218 of file Persistable.cc.

◆ end()

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

Definition at line 341 of file Polygon.cc.

341 {
342 return _impl->poly.outer().end() - 1; // Note removal of final "closed" point
343}

◆ equals()

bool lsst::afw::geom::polygon::Polygon::equals ( typehandling::Storable const & other) const
overridevirtualnoexcept

Compare this object to another Storable.

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

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 619 of file Polygon.cc.

619 {
620 return singleClassEquals(*this, other);
621}
static bool singleClassEquals(T const &lhs, Storable const &rhs)
Test if a Storable is of a particular class and equal to another object.
Definition Storable.h:151

◆ getBBox()

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

Return bounding box.

Definition at line 314 of file Polygon.cc.

314 {
315 return boostBoxToLsst(boost::geometry::return_envelope<BoostBox>(_impl->poly));
316}

◆ getEdges()

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

Get vector of edges.

Returns edges, as pairs of vertices.

Definition at line 326 of file Polygon.cc.

326 {
329 edges.reserve(getNumEdges());
330 for (std::vector<LsstPoint>::const_iterator i = vertices.begin(), j = vertices.begin() + 1;
331 j != vertices.end(); ++i, ++j) {
332 edges.emplace_back(*i, *j);
333 }
334 return edges;
335}
size_t getNumEdges() const
Return number of edges.
Definition Polygon.cc:309
std::vector< Point > getVertices() const
Get vector of vertices.
Definition Polygon.cc:337
T emplace_back(T... args)

◆ getNumEdges()

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

Return number of edges.

Identical with the number of points

Definition at line 309 of file Polygon.cc.

309 {
310 // boost::geometry::models::polygon uses a "closed" polygon: the start/end point is included twice
311 return boost::geometry::num_points(_impl->poly) - 1;
312}

◆ getPersistenceName()

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

Return the unique name used to persist this object and look up its factory.

Must be less than ArchiveIndexSchema::MAX_NAME_LENGTH characters.

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

Definition at line 594 of file Polygon.cc.

594{ return getPolygonPersistenceName(); }

◆ getPythonModule()

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

Return the fully-qualified Python module that should be imported to guarantee that its factory is registered.

Must be less than ArchiveIndexSchema::MAX_MODULE_LENGTH characters.

Will be ignored if empty.

Reimplemented in lsst::afw::image::FilterLabel, lsst::afw::cameraGeom::Detector, lsst::afw::cameraGeom::DetectorCollection, lsst::afw::cameraGeom::TransformMap, lsst::afw::detection::Footprint, lsst::afw::detection::GaussianPsf, lsst::afw::geom::SkyWcs, lsst::afw::geom::SpanSet, lsst::afw::geom::Transform< FromEndpoint, ToEndpoint >, lsst::afw::geom::Transform< afw::geom::Point2Endpoint, afw::geom::GenericEndpoint >, lsst::afw::image::ApCorrMap, lsst::afw::image::CoaddInputs, lsst::afw::image::TransmissionCurve, lsst::afw::math::ChebyshevBoundedField, lsst::afw::math::Function< double >, lsst::afw::math::Function< Kernel::Pixel >, lsst::afw::math::Function< Pixel >, lsst::afw::math::Function< ReturnT >, lsst::afw::math::Kernel, lsst::afw::math::PixelAreaBoundedField, lsst::afw::math::ProductBoundedField, lsst::afw::math::TransformBoundedField, lsst::afw::math::LanczosWarpingKernel, lsst::afw::math::BilinearWarpingKernel, lsst::afw::math::NearestWarpingKernel, lsst::afw::math::WarpingControl, lsst::afw::typehandling::StorableHelper< Base >, lsst::meas::algorithms::CoaddBoundedField, lsst::meas::algorithms::CoaddPsf, lsst::meas::algorithms::KernelPsf, lsst::meas::algorithms::WarpedPsf, lsst::meas::extensions::psfex::PsfexPsf, and lsst::meas::modelfit::Mixture.

Definition at line 36 of file Persistable.cc.

36{ return std::string(); }

◆ getVertices()

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

Definition at line 337 of file Polygon.cc.

337{ return _impl->poly.outer(); }

◆ hash_value()

std::size_t lsst::afw::geom::polygon::Polygon::hash_value ( ) const
overridevirtualnoexcept

Return a hash of this object.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 349 of file Polygon.cc.

349 {
350 // boost::hash allows hash functions to throw, but the container hashes throw
351 // only if the element [geom::Point] has a throwing hash
352 static boost::hash<BoostPolygon::ring_type> polygonHash;
353 return polygonHash(_impl->poly.outer());
354}

◆ intersection() [1/2]

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

Definition at line 390 of file Polygon.cc.

390 {
391 return _impl->intersection(box);
392}
std::vector< std::shared_ptr< Polygon > > intersection(PolyT const &other) const
Definition Polygon.cc:249

◆ intersection() [2/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.

Definition at line 386 of file Polygon.cc.

386 {
387 return _impl->intersection(other._impl->poly);
388}

◆ intersectionSingle() [1/2]

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

Definition at line 382 of file Polygon.cc.

382 {
383 return _impl->intersectionSingle(box);
384}
std::shared_ptr< Polygon > intersectionSingle(PolyT const &other) const
Definition Polygon.cc:234

◆ intersectionSingle() [2/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.

Definition at line 378 of file Polygon.cc.

378 {
379 return _impl->intersectionSingle(other._impl->poly);
380}

◆ isPersistable()

bool lsst::afw::geom::polygon::Polygon::isPersistable ( ) const
inlineoverridevirtualnoexcept

Whether Polygon is persistable which is always true.

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

Definition at line 267 of file Polygon.h.

267{ return true; }

◆ operator!=()

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

Definition at line 138 of file Polygon.h.

138{ return !(*this == other); }

◆ operator&() [1/2]

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

Definition at line 219 of file Polygon.h.

219{ return intersection(rhs); }

◆ operator&() [2/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 218 of file Polygon.h.

218{ return intersection(rhs); }

◆ operator=() [1/2]

Polygon & lsst::afw::geom::polygon::Polygon::operator= ( Polygon && )
default

◆ operator=() [2/2]

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

◆ operator==()

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

Definition at line 345 of file Polygon.cc.

345 {
346 return boost::geometry::equals(_impl->poly, other._impl->poly);
347}

◆ operator^() [1/2]

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

Definition at line 223 of file Polygon.h.

223{ return symDifference(rhs); }
std::vector< std::shared_ptr< Polygon > > symDifference(Polygon const &other) const
Return the symmetric difference of two polygons.
Definition Polygon.cc:406

◆ operator^() [2/2]

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

Definition at line 222 of file Polygon.h.

222{ return symDifference(rhs); }

◆ operator|() [1/2]

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

Definition at line 221 of file Polygon.h.

221{ return union_(rhs); }
std::vector< std::shared_ptr< Polygon > > union_(Polygon const &other) const
Returns the union of two polygons.
Definition Polygon.cc:400

◆ operator|() [2/2]

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

Definition at line 220 of file Polygon.h.

220{ return union_(rhs); }

◆ overlaps() [1/2]

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

Definition at line 376 of file Polygon.cc.

376{ return _impl->overlaps(box); }
bool overlaps(PolyT const &other) const
Definition Polygon.cc:200

◆ overlaps() [2/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.

Definition at line 374 of file Polygon.cc.

374{ return _impl->overlaps(other._impl->poly); }

◆ plot()

lsst.afw.geom.polygon.Polygon.plot ( self,
axes = None,
** kwargs )
Plot polygon with matplotlib

Parameters
----------
axes : `matplotlib.axes.Axes`
    Matplotlib axes to use, or None
kwargs : any
    Additional arguments to `matplotlib.axes.Axes.plot`
    or `matplotlib.axes.Axes.scatter`.

Returns
-------
axes : `matplotlib.axes.Axes`
    The axes used to make the plot (same as ``axes``, if provided).

Definition at line 61 of file polygon.py.

61 def plot(self, axes=None, **kwargs):
62 """Plot polygon with matplotlib
63
64 Parameters
65 ----------
66 axes : `matplotlib.axes.Axes`
67 Matplotlib axes to use, or None
68 kwargs : any
69 Additional arguments to `matplotlib.axes.Axes.plot`
70 or `matplotlib.axes.Axes.scatter`.
71
72 Returns
73 -------
74 axes : `matplotlib.axes.Axes`
75 The axes used to make the plot (same as ``axes``, if provided).
76 """
77 import numpy
78 if axes is None:
79 import matplotlib.pyplot as plt
80 plt.figure()
81 axes = plt.axes()
82 for p1, p2 in self.getEdges():
83 x = (p1.getX(), p2.getX())
84 y = (p1.getY(), p2.getY())
85 axes.plot(x, y, **kwargs)
86 vertices = self.getVertices()
87 x = numpy.array([p[0] for p in vertices])
88 y = numpy.array([p[1] for p in vertices])
89 axes.scatter(x, y, **kwargs)
90 return axes

◆ 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 183 of file Persistable.h.

◆ readFits() [2/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 205 of file Persistable.h.

◆ readFits() [3/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 194 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).

Definition at line 414 of file Polygon.cc.

414 {
416 boost::geometry::simplify(_impl->poly, result, distance);
417 return std::shared_ptr<Polygon>(new Polygon(std::make_shared<Impl>(result)));
418}
py::object result
Definition _schema.cc:429

◆ singleClassEquals()

template<class T >
static bool lsst::afw::typehandling::Storable::singleClassEquals ( T const & lhs,
Storable const & rhs )
inlinestaticprotectedinherited

Test if a Storable is of a particular class and equal to another object.

This method template simplifies implementations of equals that delegate to operator== without supporting cross-class comparisons.

Template Parameters
TThe class expected of the two objects to be compared.
Parameters
lhs,rhsThe objects to compare. Note that rhs need not be a T, while lhs must be.
Returns
true if rhs is a T and lhs == rhs; false otherwise.
Exception Safety
Provides the same level of exception safety as operator==. Most implementations of operator== do not throw.
Note
This method template calls operator== with both arguments of compile-time type T const&. Its use is not recommended if there would be any ambiguity as to which operator== gets picked by overload resolution.

This method template is typically called from equals as:

bool MyType::equals(Storable const& other) const noexcept {
    return singleClassEquals(*this, other);
}

Definition at line 151 of file Storable.h.

151 {
152 auto typedRhs = dynamic_cast<T const*>(&rhs);
153 if (typedRhs != nullptr) {
154 return lhs == *typedRhs;
155 } else {
156 return false;
157 }
158 }

◆ subSample() [1/2]

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

Definition at line 450 of file Polygon.cc.

450 {
451 std::vector<LsstPoint> vertices; // New vertices
452 vertices.reserve(getNumEdges() + static_cast<size_t>(::ceil(calculatePerimeter() / maxLength)));
454 for (auto const &edge : edges) {
455 Point const &p1 = edge.first, p2 = edge.second;
456 double const dist = ::sqrt(p1.distanceSquared(p2));
457 addSubSampledEdge(vertices, p1, p2, static_cast<size_t>(::ceil(dist / maxLength)));
458 }
459 return std::shared_ptr<Polygon>(new Polygon(std::make_shared<Impl>(vertices)));
460}
std::vector< std::pair< Point, Point > > getEdges() const
Get vector of edges.
Definition Polygon.cc:326

◆ subSample() [2/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.

Definition at line 440 of file Polygon.cc.

440 {
441 std::vector<LsstPoint> vertices; // New vertices
444 for (auto const &edge : edges) {
445 addSubSampledEdge(vertices, edge.first, edge.second, num);
446 }
447 return std::shared_ptr<Polygon>(new Polygon(std::make_shared<Impl>(vertices)));
448}

◆ swap()

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

Swap two polygons.

Definition at line 102 of file Polygon.h.

102{ std::swap(this->_impl, other._impl); }
T swap(T... args)

◆ symDifference() [1/2]

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

Definition at line 410 of file Polygon.cc.

410 {
411 return _impl->symDifference(box);
412}
std::vector< std::shared_ptr< Polygon > > symDifference(PolyT const &other) const
Definition Polygon.cc:275

◆ symDifference() [2/2]

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

Return the symmetric difference of two polygons.

Definition at line 406 of file Polygon.cc.

406 {
407 return _impl->symDifference(other._impl->poly);
408}

◆ toString()

std::string lsst::afw::geom::polygon::Polygon::toString ( ) const
overridevirtual

Create a string representation of this object.

Reimplemented from lsst::afw::typehandling::Storable.

Definition at line 613 of file Polygon.cc.

613 {
614 std::stringstream buffer;
615 buffer << "Polygon(" << this->getVertices() << ")";
616 return buffer.str();
617}
T str(T... args)

◆ transform() [1/2]

std::shared_ptr< Polygon > lsst::afw::geom::polygon::Polygon::transform ( lsst::geom::AffineTransform const & transform) const
Parameters
transformTransform from original to target frame

Definition at line 431 of file Polygon.cc.

431 {
432 std::vector<LsstPoint> vertices; // New vertices
434 for (auto const &i : _impl->poly.outer()) {
435 vertices.push_back(transform(i));
436 }
437 return std::shared_ptr<Polygon>(new Polygon(std::make_shared<Impl>(vertices)));
438}
Low-level polynomials (including special polynomials) in C++.

◆ transform() [2/2]

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

Definition at line 426 of file Polygon.cc.

426 {
427 auto newVertices = transform.applyForward(getVertices());
428 return std::shared_ptr<Polygon>(new Polygon(std::make_shared<Impl>(newVertices)));
429}

◆ union_() [1/2]

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

Definition at line 404 of file Polygon.cc.

404{ return _impl->union_(box); }
std::vector< std::shared_ptr< Polygon > > union_(PolyT const &other) const
Definition Polygon.cc:268

◆ union_() [2/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.

Definition at line 400 of file Polygon.cc.

400 {
401 return _impl->union_(other._impl->poly);
402}

◆ unionSingle() [1/2]

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

Definition at line 398 of file Polygon.cc.

398{ return _impl->unionSingle(box); }
std::shared_ptr< Polygon > unionSingle(PolyT const &other) const
Definition Polygon.cc:256

◆ unionSingle() [2/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.

Definition at line 394 of file Polygon.cc.

394 {
395 return _impl->unionSingle(other._impl->poly);
396}

◆ write()

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

Write the object to one or more catalogs.

The handle object passed to this function provides an interface for adding new catalogs and adding nested objects to the same archive (while checking for duplicates). See OutputArchiveHandle for more information.

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

Definition at line 596 of file Polygon.cc.

596 {
597 static PolygonSchema const& keys = PolygonSchema::get();
598 afw::table::BaseCatalog catalog = handle.makeCatalog(keys.schema);
599
601 for (auto const &vertice : vertices) {
602 std::shared_ptr<afw::table::BaseRecord> record = catalog.addNew();
603 record->set(keys.vertices, vertice);
604 }
605
606 handle.saveCatalog(catalog);
607}
CatalogT< BaseRecord > BaseCatalog
Definition fwd.h:72

◆ writeFits() [1/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.

Definition at line 18 of file Persistable.cc.

18 {
19 OutputArchive archive;
20 archive.put(this);
21 archive.writeFits(fitsfile);
22}

◆ 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.

Definition at line 29 of file Persistable.cc.

29 {
30 fits::Fits fitsfile(manager, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
31 writeFits(fitsfile);
32}
void writeFits(std::string const &fileName, std::string const &mode="w") const
Write the object to a regular FITS file.

◆ writeFits() [3/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.

Definition at line 24 of file Persistable.cc.

24 {
25 fits::Fits fitsfile(fileName, mode, fits::Fits::AUTO_CLOSE | fits::Fits::AUTO_CHECK);
26 writeFits(fitsfile);
27}

Friends And Related Symbol Documentation

◆ operator<<()

std::ostream & operator<< ( std::ostream & os,
Storable const & storable )
related

Output operator for Storable.

Parameters
osthe desired output stream
storablethe object to print
Returns
a reference to os
Exceptions
UnsupportedOperationExceptionThrown if storable does not have an implementation of Storable::toString.

Definition at line 174 of file Storable.h.

174 {
175 return os << storable.toString();
176}

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