LSST Applications  21.0.0-172-gfb10e10a+18fedfabac,22.0.0+297cba6710,22.0.0+80564b0ff1,22.0.0+8d77f4f51a,22.0.0+a28f4c53b1,22.0.0+dcf3732eb2,22.0.1-1-g7d6de66+2a20fdde0d,22.0.1-1-g8e32f31+297cba6710,22.0.1-1-geca5380+7fa3b7d9b6,22.0.1-12-g44dc1dc+2a20fdde0d,22.0.1-15-g6a90155+515f58c32b,22.0.1-16-g9282f48+790f5f2caa,22.0.1-2-g92698f7+dcf3732eb2,22.0.1-2-ga9b0f51+7fa3b7d9b6,22.0.1-2-gd1925c9+bf4f0e694f,22.0.1-24-g1ad7a390+a9625a72a8,22.0.1-25-g5bf6245+3ad8ecd50b,22.0.1-25-gb120d7b+8b5510f75f,22.0.1-27-g97737f7+2a20fdde0d,22.0.1-32-gf62ce7b1+aa4237961e,22.0.1-4-g0b3f228+2a20fdde0d,22.0.1-4-g243d05b+871c1b8305,22.0.1-4-g3a563be+32dcf1063f,22.0.1-4-g44f2e3d+9e4ab0f4fa,22.0.1-42-gca6935d93+ba5e5ca3eb,22.0.1-5-g15c806e+85460ae5f3,22.0.1-5-g58711c4+611d128589,22.0.1-5-g75bb458+99c117b92f,22.0.1-6-g1c63a23+7fa3b7d9b6,22.0.1-6-g50866e6+84ff5a128b,22.0.1-6-g8d3140d+720564cf76,22.0.1-6-gd805d02+cc5644f571,22.0.1-8-ge5750ce+85460ae5f3,master-g6e05de7fdc+babf819c66,master-g99da0e417a+8d77f4f51a,w.2021.48
LSST Data Management Base Package
Public Types | Public Member Functions | List of all members
lsst::afw::geom::ellipses::PixelRegion Class Referencefinal

A pixelized region containing all pixels whose centers are within an Ellipse. More...

#include <PixelRegion.h>

Public Types

using Iterator = std::vector< Span >::const_iterator
 Iterator type used by begin() and end(). More...
 

Public Member Functions

 PixelRegion (Ellipse const &ellipse)
 Construct a PixelRegion from an Ellipse. More...
 
 PixelRegion (PixelRegion const &)=default
 PixelRegion is copy and move constructable and assignable. More...
 
 PixelRegion (PixelRegion &&)=default
 
PixelRegionoperator= (PixelRegion const &)=default
 
PixelRegionoperator= (PixelRegion &&)=default
 
 ~PixelRegion ()=default
 
Iterator begin () const
 Iterator range over Spans whose pixels are within the Ellipse. More...
 
Iterator end () const
 
lsst::geom::Box2I const & getBBox () const
 Return the bounding box of the pixel region. More...
 
Span const getSpanAt (int y) const
 Return the span at the given y coordinate value. More...
 

Detailed Description

A pixelized region containing all pixels whose centers are within an Ellipse.

The pixel region for an ellipse may be larger or smaller in area than the ellipse itself, depending on the details of where pixel centers land, and it may be empty even if the area of the ellipse is nonzero.

Definition at line 46 of file PixelRegion.h.

Member Typedef Documentation

◆ Iterator

Iterator type used by begin() and end().

Definition at line 50 of file PixelRegion.h.

Constructor & Destructor Documentation

◆ PixelRegion() [1/3]

lsst::afw::geom::ellipses::PixelRegion::PixelRegion ( Ellipse const &  ellipse)
explicit

Construct a PixelRegion from an Ellipse.

Definition at line 100 of file PixelRegion.cc.

101  : _bbox(ellipse.computeBBox(), lsst::geom::Box2I::EXPAND)
102 {
103  // Initial temporary bounding box that may be larger than the final one.
104  lsst::geom::Box2I envelope(ellipse.computeBBox(), lsst::geom::Box2I::EXPAND);
105 
106  if (envelope.isEmpty()) {
107  // If the outer bbox is empty, we know there can't be any spans that
108  // contain ellipse pixels.
109  return;
110  }
111 
112  // Helper class that does the hard work: compute the boundary points of the
113  // ellipse in x that intersect a horizontal line at some given y.
114  EllipseHorizontalLineIntersection intersection(ellipse);
115 
116  // Iterate over pixel rows in the bounding box, computing the intersection
117  // of the ellipse with that y coordinate.
118  int const yEnd = envelope.getEndY();
119  for (int y = envelope.getBeginY(); y != yEnd; ++y) {
120  auto x = intersection.xAt(y);
121  if (x) {
122  int xMin = std::ceil(x->first);
123  int xMax = std::floor(x->second);
124  if (xMax < xMin) continue;
125  _spans.emplace_back(y, xMin, xMax);
126  _bbox.include(lsst::geom::Point2I(xMin, y));
127  _bbox.include(lsst::geom::Point2I(xMax, y));
128  }
129  }
130 }
double x
int y
Definition: SpanSet.cc:48
T ceil(T... args)
An integer coordinate rectangle.
Definition: Box.h:55
void include(Point2I const &point)
Expand this to ensure that this->contains(point).
Definition: Box.cc:152
T floor(T... args)

◆ PixelRegion() [2/3]

lsst::afw::geom::ellipses::PixelRegion::PixelRegion ( PixelRegion const &  )
default

PixelRegion is copy and move constructable and assignable.

◆ PixelRegion() [3/3]

lsst::afw::geom::ellipses::PixelRegion::PixelRegion ( PixelRegion &&  )
default

◆ ~PixelRegion()

lsst::afw::geom::ellipses::PixelRegion::~PixelRegion ( )
default

Member Function Documentation

◆ begin()

Iterator lsst::afw::geom::ellipses::PixelRegion::begin ( ) const
inline

Iterator range over Spans whose pixels are within the Ellipse.

Definition at line 68 of file PixelRegion.h.

68 { return _spans.begin(); }

◆ end()

Iterator lsst::afw::geom::ellipses::PixelRegion::end ( ) const
inline

Definition at line 69 of file PixelRegion.h.

69 { return _spans.end(); }

◆ getBBox()

lsst::geom::Box2I const& lsst::afw::geom::ellipses::PixelRegion::getBBox ( ) const
inline

Return the bounding box of the pixel region.

This is guaranteed to be the smallest box that includes all Spans. It has no guaranteed relationship with the Ellipse's direct (floating-point) bounding box as computed by Ellipse::computeBBox(), and may be empty even if the Ellipse's bounding box is not.

Definition at line 80 of file PixelRegion.h.

80 { return _bbox; }

◆ getSpanAt()

Span const lsst::afw::geom::ellipses::PixelRegion::getSpanAt ( int  y) const

Return the span at the given y coordinate value.

Exceptions
lsst::pex::exceptions::OutOfRangeErrorThrown if y is not within the y bounds of getBBox().

Definition at line 132 of file PixelRegion.cc.

132  {
133  if (_bbox.isEmpty()) {
134  throw LSST_EXCEPT(
135  pex::exceptions::OutOfRangeError,
136  "PixelRegion is empty."
137  );
138  }
139  if (y < _bbox.getMinY() || y > _bbox.getMaxY()) {
140  throw LSST_EXCEPT(
141  pex::exceptions::OutOfRangeError,
142  (boost::format("No span at y=%s in pixel region with rows between y=%s and y=%s")
143  % y % _bbox.getMinY() % _bbox.getMaxY()).str()
144  );
145  }
146  return _spans[y - _bbox.getBeginY()];
147 }
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition: Exception.h:48
int getMinY() const noexcept
Definition: Box.h:158
bool isEmpty() const noexcept
Return true if the box contains no points.
Definition: Box.h:213
int getBeginY() const noexcept
Definition: Box.h:173
int getMaxY() const noexcept
Definition: Box.h:162
def format(config, name=None, writeSourceLine=True, prefix="", verbose=False)
Definition: history.py:174

◆ operator=() [1/2]

PixelRegion& lsst::afw::geom::ellipses::PixelRegion::operator= ( PixelRegion &&  )
default

◆ operator=() [2/2]

PixelRegion& lsst::afw::geom::ellipses::PixelRegion::operator= ( PixelRegion const &  )
default

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