LSST Applications g0f08755f38+9c285cab97,g1635faa6d4+13f3999e92,g1653933729+a8ce1bb630,g1a0ca8cf93+bf6eb00ceb,g28da252d5a+0829b12dee,g29321ee8c0+5700dc9eac,g2bbee38e9b+9634bc57db,g2bc492864f+9634bc57db,g2cdde0e794+c2c89b37c4,g3156d2b45e+41e33cbcdc,g347aa1857d+9634bc57db,g35bb328faa+a8ce1bb630,g3a166c0a6a+9634bc57db,g3e281a1b8c+9f2c4e2fc3,g414038480c+077ccc18e7,g41af890bb2+fde0dd39b6,g5fbc88fb19+17cd334064,g781aacb6e4+a8ce1bb630,g80478fca09+55a9465950,g82479be7b0+d730eedb7d,g858d7b2824+9c285cab97,g9125e01d80+a8ce1bb630,g9726552aa6+10f999ec6a,ga5288a1d22+2a84bb7594,gacf8899fa4+c69c5206e8,gae0086650b+a8ce1bb630,gb58c049af0+d64f4d3760,gc28159a63d+9634bc57db,gcf0d15dbbd+4b7d09cae4,gda3e153d99+9c285cab97,gda6a2b7d83+4b7d09cae4,gdaeeff99f8+1711a396fd,ge2409df99d+5e831397f4,ge79ae78c31+9634bc57db,gf0baf85859+147a0692ba,gf3967379c6+41c94011de,gf3fb38a9a8+8f07a9901b,gfb92a5be7c+9c285cab97,w.2024.46
LSST Data Management Base Package
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Member Functions | Protected Types | Private Member Functions | Friends | List of all members
lsst::afw::geom::SpanSet Class Reference

A compact representation of a collection of pixels. More...

#include <SpanSet.h>

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

Public Types

using const_iterator = std::vector<Span>::const_iterator
 
using size_type = std::vector<Span>::size_type
 
using value_type = Span
 
using const_reference = const value_type &
 

Public Member Functions

const_iterator begin () const
 
const_iterator end () const
 
const_iterator cbegin () const
 
const_iterator cend () const
 
const_reference front () const
 
const_reference back () const
 
size_type size () const
 
bool empty () const
 
 SpanSet ()
 Default constructor.
 
 SpanSet (lsst::geom::Box2I const &box)
 Construct a SpanSet from a box.
 
template<typename iter >
 SpanSet (iter begin, iter end, bool normalize=true)
 Construct a SpanSet from an iterator.
 
 SpanSet (std::vector< Span > const &vec, bool normalize=true)
 Construct a SpanSet from a std vector by copying.
 
 SpanSet (std::vector< Span > &&vec, bool normalize=true)
 Construct a SpanSet from a std vector from a move.
 
 SpanSet (SpanSet const &other)=delete
 
 SpanSet (SpanSet &&other)=delete
 
 ~SpanSet () override=default
 
SpanSetoperator= (SpanSet const &)=default
 
SpanSetoperator= (SpanSet &&other)
 
size_type getArea () const
 Return the number of pixels in the SpanSet.
 
lsst::geom::Box2I getBBox () const
 Return a new integer box which is the minimum size to contain the pixels.
 
bool isContiguous () const
 Defines if the SpanSet is simply contiguous.
 
std::shared_ptr< SpanSetshiftedBy (int x, int y) const
 Return a new SpanSet shifted by specified amount.
 
std::shared_ptr< SpanSetshiftedBy (lsst::geom::Extent2I const &offset) const
 Return a new SpanSet shifted by specified amount.
 
std::shared_ptr< SpanSetclippedTo (lsst::geom::Box2I const &box) const
 Return a new SpanSet which has all pixel values inside specified box.
 
std::shared_ptr< SpanSettransformedBy (lsst::geom::LinearTransform const &t) const
 Return a new SpanSet who's pixels are the product of applying the specified transformation.
 
std::shared_ptr< SpanSettransformedBy (lsst::geom::AffineTransform const &t) const
 Return a new SpanSet who's pixels are the product of applying the specified transformation.
 
std::shared_ptr< SpanSettransformedBy (TransformPoint2ToPoint2 const &t) const
 Return a new SpanSet who's pixels are the product of applying the specified transformation.
 
bool overlaps (SpanSet const &other) const
 Specifies if this SpanSet overlaps with another SpanSet.
 
bool contains (SpanSet const &other) const
 Check if a SpanSet instance entirely contains another SpanSet.
 
bool contains (lsst::geom::Point2I const &point) const
 Check if a point is contained within the SpanSet instance.
 
lsst::geom::Point2D computeCentroid () const
 Compute the point about which the SpanSet's first moment is zero.
 
ellipses::Quadrupole computeShape () const
 Compute the shape parameters for the distribution of points in the SpanSet.
 
std::shared_ptr< SpanSetdilated (int r, Stencil s=Stencil::CIRCLE) const
 Perform a set dilation operation, and return a new object.
 
std::shared_ptr< SpanSetdilated (SpanSet const &other) const
 Perform a set dilation operation, and return a new object.
 
std::shared_ptr< SpanSeteroded (int r, Stencil s=Stencil::CIRCLE) const
 Perform a set erosion, and return a new object.
 
std::shared_ptr< SpanSeteroded (SpanSet const &other) const
 Perform a set erosion operation, and return a new object.
 
template<typename Pixel , int inN, int inC>
ndarray::Array< typename std::remove_const< Pixel >::type, inN - 1, inN - 1 > flatten (ndarray::Array< Pixel, inN, inC > const &input, lsst::geom::Point2I const &xy0=lsst::geom::Point2I()) const
 Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.
 
template<typename PixelIn , typename PixelOut , int inA, int outC, int inC>
void flatten (ndarray::Array< PixelOut, inA - 1, outC > const &output, ndarray::Array< PixelIn, inA, inC > const &input, lsst::geom::Point2I const &xy0=lsst::geom::Point2I()) const
 Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.
 
template<typename Pixel , int inA, int inC>
ndarray::Array< typename std::remove_const< Pixel >::type, inA+1, inA+1 > unflatten (ndarray::Array< Pixel, inA, inC > const &input) const
 Expand an array by one spatial dimension at points given by SpanSet.
 
template<typename PixelIn , typename PixelOut , int inA, int outC, int inC>
void unflatten (ndarray::Array< PixelOut, inA+1, outC > const &output, ndarray::Array< PixelIn, inA, inC > const &input, lsst::geom::Point2I const &xy0=lsst::geom::Point2I()) const
 Expand an array by one spatial dimension at points given by SpanSet.
 
template<typename ImageT >
void copyImage (image::Image< ImageT > const &src, image::Image< ImageT > &dest)
 Copy contents of source Image into destination image at the positions defined in the SpanSet.
 
template<typename ImageT , typename MaskT , typename VarT >
void copyMaskedImage (image::MaskedImage< ImageT, MaskT, VarT > const &src, image::MaskedImage< ImageT, MaskT, VarT > &dest)
 Copy contents of source MaskedImage into destination image at the positions defined in the SpanSet.
 
template<typename ImageT >
void setImage (image::Image< ImageT > &image, ImageT val, lsst::geom::Box2I const &region=lsst::geom::Box2I(), bool doClip=false) const
 Set the values of an Image at points defined by the SpanSet.
 
template<typename Functor , typename... Args>
void applyFunctor (Functor &&func, Args &&... args) const
 Apply functor on individual elements from the supplied parameters.
 
template<typename T >
void setMask (lsst::afw::image::Mask< T > &target, T bitmask) const
 Set a Mask at pixels defined by the SpanSet.
 
template<typename T >
void clearMask (lsst::afw::image::Mask< T > &target, T bitmask) const
 Unset a Mask at pixels defined by the SpanSet.
 
std::shared_ptr< SpanSetintersect (SpanSet const &other) const
 Determine the common points between two SpanSets, and create a new SpanSet.
 
template<typename T >
std::shared_ptr< SpanSetintersect (image::Mask< T > const &other, T bitmask) const
 Determine the common points between a SpanSet and a Mask with a given bit pattern.
 
std::shared_ptr< SpanSetintersectNot (SpanSet const &other) const
 Determine the common points between a SpanSet and the logical inverse of a second SpanSet and return them in a new SpanSet.
 
template<typename T >
std::shared_ptr< SpanSetintersectNot (image::Mask< T > const &other, T bitmask) const
 Determine the common points between a SpanSet and the logical inverse of a Mask for a given bit pattern.
 
std::shared_ptr< SpanSetunion_ (SpanSet const &other) const
 Create a new SpanSet that contains all points from two SpanSets.
 
template<typename T >
std::shared_ptr< SpanSetunion_ (image::Mask< T > const &other, T bitmask) const
 Determine the union between a SpanSet and a Mask for a given bit pattern.
 
bool operator== (SpanSet const &other) const
 Compute equality between two SpanSets.
 
bool operator!= (SpanSet const &other) const
 
std::vector< std::shared_ptr< geom::SpanSet > > split () const
 Split a discontinuous SpanSet into multiple SpanSets which are contiguous.
 
bool isPersistable () const noexcept override
 Return true if this particular object can be persisted using afw::table::io.
 
std::shared_ptr< geom::SpanSet > findEdgePixels () const
 Select pixels within the SpanSet which touch its edge.
 
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< geom::SpanSet > fromShape (int r, Stencil s=Stencil::CIRCLE, lsst::geom::Point2I offset=lsst::geom::Point2I())
 Factory function for creating SpanSets from a Stencil.
 
static std::shared_ptr< geom::SpanSet > fromShape (geom::ellipses::Ellipse const &ellipse)
 Factory function for creating SpanSets from an ellipse object.
 
template<typename T , typename UnaryPredicate = details::AnyBitSetFunctor<T>>
static std::shared_ptr< geom::SpanSet > fromMask (image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
 Create a SpanSet from a mask.
 
template<typename T >
static std::shared_ptr< geom::SpanSet > fromMask (image::Mask< T > const &mask, T bitmask)
 Create a SpanSet from a mask.
 
static std::shared_ptr< lsst::afw::geom::SpanSetreadFits (fits::Fits &fitsfile)
 Read an object from an already open FITS object.
 
static std::shared_ptr< lsst::afw::geom::SpanSetreadFits (std::string const &fileName, int hdu=fits::DEFAULT_HDU)
 Read an object from a regular FITS file.
 
static std::shared_ptr< lsst::afw::geom::SpanSetreadFits (fits::MemFileManager &manager, int hdu=fits::DEFAULT_HDU)
 Read an object from a FITS file in memory.
 
static std::shared_ptr< lsst::afw::geom::SpanSetdynamicCast (std::shared_ptr< Persistable > const &ptr)
 Dynamically cast a shared_ptr.
 

Protected Types

using OutputArchiveHandle = io::OutputArchiveHandle
 

Private Member Functions

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

Friends

class SpansSetFactory
 

Detailed Description

A compact representation of a collection of pixels.

A SpanSet is a collection of Span classes. As each Span encodes a range of pixels on a given row, a SpanSet represents an arbitrary collection of pixels on an image. The SpanSet class also contains mathematical set style operators, for working with the collection of pixels, and helper functions which make use of the area defined to perform localized actions

Definition at line 77 of file SpanSet.h.

Member Typedef Documentation

◆ const_iterator

Definition at line 80 of file SpanSet.h.

◆ const_reference

Definition at line 83 of file SpanSet.h.

◆ OutputArchiveHandle

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

Definition at line 108 of file Persistable.h.

◆ size_type

Definition at line 81 of file SpanSet.h.

◆ value_type

Definition at line 82 of file SpanSet.h.

Constructor & Destructor Documentation

◆ SpanSet() [1/7]

lsst::afw::geom::SpanSet::SpanSet ( )

Default constructor.

Construct a null SpanSet, with zero size. This is useful as a placeholder

Definition at line 177 of file SpanSet.cc.

177: _spanVector(), _bbox(), _area(0) {}

◆ SpanSet() [2/7]

lsst::afw::geom::SpanSet::SpanSet ( lsst::geom::Box2I const & box)
explicit

Construct a SpanSet from a box.

Parameters
boxA integer box that defines the shape for which a span set should be created

Definition at line 180 of file SpanSet.cc.

180 : _bbox(box), _area(box.getArea()) {
181 int beginY = box.getMinY();
182
183 int beginX = box.getMinX();
184 int maxX = box.getMaxX();
185
186 for (int i = beginY; i < _bbox.getEndY(); ++i) {
187 _spanVector.emplace_back(i, beginX, maxX);
188 }
189}
int getEndY() const noexcept
Definition Box.h:177

◆ SpanSet() [3/7]

template<typename iter >
lsst::afw::geom::SpanSet::SpanSet ( iter begin,
iter end,
bool normalize = true )
inline

Construct a SpanSet from an iterator.

This constructor accepts the begin and end points of an arbitrary iterator of a container which contains previously created Spans. These Spans are used to construct the SpanSet.

Parameters
beginBeginning iterator of a container of Spans
endEnd iterator of a container of Spans
normalizeControls if the constructor attempts to merge connected or overlapping spans. Defaults to true. Set to false to save computational time when the container is sure to already be normalized.

Definition at line 123 of file SpanSet.h.

123 : _spanVector(begin, end) {
124 // Return a null SpanSet if spanVector is 0
125 if (_spanVector.size() == 0) {
126 _bbox = lsst::geom::Box2I();
127 _area = 0;
128 } else {
129 if (normalize) {
130 _runNormalize();
131 }
132 _initialize();
133 }
134 }
const_iterator end() const
Definition SpanSet.h:89
const_iterator begin() const
Definition SpanSet.h:88
An integer coordinate rectangle.
Definition Box.h:55

◆ SpanSet() [4/7]

lsst::afw::geom::SpanSet::SpanSet ( std::vector< Span > const & vec,
bool normalize = true )
explicit

Construct a SpanSet from a std vector by copying.

This constructor accepts a standard vector which contains already created Spans. These Spans are copied into the internal container of spans.

Parameters
vecStandard vector containing Spans
normalizeControls if the constructor attempts to merge connected or overlapping spans. Defaults to true. Set to false to save computational time when the container is sure to already be normalized.

Definition at line 192 of file SpanSet.cc.

192 : _spanVector(vec) {
193 // If the incoming vector is zero, should create an empty spanSet
194 if (_spanVector.empty()) {
195 _bbox = lsst::geom::Box2I();
196 _area = 0;
197 } else {
198 if (normalize) {
199 _runNormalize();
200 }
201 _initialize();
202 }
203}

◆ SpanSet() [5/7]

lsst::afw::geom::SpanSet::SpanSet ( std::vector< Span > && vec,
bool normalize = true )
explicit

Construct a SpanSet from a std vector from a move.

This constructor accepts a standard vector r-reference which contains already created Spans. These Spans become the internal container of spans.

Parameters
vecStandard vector containing Spans
normalizeControls if the constructor attempts to merge connected or overlapping spans. Defaults to true. Set to false to save computational time when the container is sure to already be normalized.

Definition at line 206 of file SpanSet.cc.

206 : _spanVector(std::move(vec)) {
207 // If the incoming vector is zero, should create an empty SpanSet
208 if (_spanVector.size() == 0) {
209 _bbox = lsst::geom::Box2I();
210 _area = 0;
211 } else {
212 if (normalize) {
213 _runNormalize();
214 }
215 _initialize();
216 }
217}
T move(T... args)

◆ SpanSet() [6/7]

lsst::afw::geom::SpanSet::SpanSet ( SpanSet const & other)
delete

◆ SpanSet() [7/7]

lsst::afw::geom::SpanSet::SpanSet ( SpanSet && other)
delete

◆ ~SpanSet()

lsst::afw::geom::SpanSet::~SpanSet ( )
overridedefault

Member Function Documentation

◆ applyFunctor()

template<typename Functor , typename... Args>
void lsst::afw::geom::SpanSet::applyFunctor ( Functor && func,
Args &&... args ) const
inline

Apply functor on individual elements from the supplied parameters.

Use a variadic template to take a functor object, and an arbitrary number of parameters. Parameters may be of type(s) Image, MakedImage, ndarray, numeric value and generic iterators. For most of these types bound checking is done to ensure execution safety, but because a generic iterator can have any behavior, bounds checking is not possible. As such the iterator must be valid for at least the number of pixels contained in the SpanSet. Numeric values are also different in that they will not be iterated but the value will be passed to the functor for each point in the SpanSet.

Because a ndarray can either be interpreted as either a two dimensional image, or a one dimensional vector a user must break the ambiguity by using the functions ndarray::ndImage, or ndarray::ndFlat respectively.

The functor object must operate in-place on any data, no return values are captured. No exceptions are handled, if a functor throws one it will propagate back out of the applyFunctor call, possibly leaving the output array in an incomplete state. The first argument of the functor must be a lsst::geom::Point2I which will be the point in the SpanSet where the operation is occurring. All the remaining arguments to the functor will be individual values generated from the input arguments. For two dimensional types (Image, MaskedImage, ndarray) arguments will be the value taken from the input type at the location given by the SpanSet. I.e. if the SpanSet has the point (2,3) in it, then a 2 dimensional ndarray will have ndarray[2][3] passed to the functor. Thus all SpanSet coordinates must be addressable in two dimensional types. For one dimensional types (ndarray, iterator) arguments will correspond to the value at the location defined by number of pixels which have been iterated over. I.e. if there are 3 pixels defined in the SpanSet a one dimensional ndarray will have the value ndarray[0] passed to the functor on on the first functor call, ndarray[1] passed on the second call, and ndarray[2] passed on the last functor call. The total length of a one dimensional type will be equal to the area of the SpanSet, and therefore the data-type must be at least that length. The order of the parameters supplied to the functor will be the same order as they are passed to the applyFunctor method.

Template Parameters
...ArgsVariadic type specification
Parameters
funcFunctor that is to be applied on each of the values taken from ...args.
...argsVariadic arguments, may be of type Image, MaskedImage, ndarrays, numeric values and iterators. ndarrays must be specified as either image or vector with the ndarray::ndImage or ndarray::ndFlat functions

Definition at line 512 of file SpanSet.h.

512 {
513 /* Use a variadic template to take a functor object, and an arbitrary number
514 of parameters. For each of the arguments, construct a Getter class using
515 a function (makeGetter) which is overloaded to all the types applyFunctorImpl
516 supports: Images, MaskedImages, Exposures, ndarrays, numeric values, and
517 iterators. The functor and the getters are then passed to the implementation of
518 applyFunctor where the values of the input arguments are intelligently
519 generated at each point in SpanSet, and passed to the functor object for evaluation.
520 */
521 applyFunctorImpl(func, details::makeGetter(args)...);
522 }
FlatNdGetter< T, inA, inC > makeGetter(FlatNdGetter< T, inA, inC > &getter)

◆ back()

const_reference lsst::afw::geom::SpanSet::back ( ) const
inline

Definition at line 93 of file SpanSet.h.

93{ return const_cast<geom::Span &>(_spanVector.back()); }

◆ begin()

const_iterator lsst::afw::geom::SpanSet::begin ( ) const
inline

Definition at line 88 of file SpanSet.h.

88{ return _spanVector.cbegin(); }

◆ cbegin()

const_iterator lsst::afw::geom::SpanSet::cbegin ( ) const
inline

Definition at line 90 of file SpanSet.h.

90{ return _spanVector.cbegin(); }

◆ cend()

const_iterator lsst::afw::geom::SpanSet::cend ( ) const
inline

Definition at line 91 of file SpanSet.h.

91{ return _spanVector.cend(); }

◆ clearMask()

template<typename T >
void lsst::afw::geom::SpanSet::clearMask ( lsst::afw::image::Mask< T > & target,
T bitmask ) const

Unset a Mask at pixels defined by the SpanSet.

Template Parameters
Tdata-type of a pixel in the Mask plane
Parameters
[in,out]targetMask in which a bit pattern will be unset
[in]bitmaskThe bit pattern to clear in the mask

Definition at line 956 of file SpanSet.cc.

956 {
957 // Use a lambda to clear bits in a mask at the locations given by SpanSet
958 auto targetArray = target.getArray();
959 auto xy0 = target.getBBox().getMin();
960 auto clearMaskFunctor = [](lsst::geom::Point2I const& point,
962 T bitmask) { maskVal &= ~bitmask; };
963 applyFunctor(clearMaskFunctor, ndarray::ndImage(targetArray, xy0), bitmask);
964}
Key< Flag > const & target
void applyFunctor(Functor &&func, Args &&... args) const
Apply functor on individual elements from the supplied parameters.
Definition SpanSet.h:512
details::ImageNdGetter< T, inA, inB > ndImage(ndarray::Array< T, inA, inB > const &array, lsst::geom::Point2I xy0=lsst::geom::Point2I())
Marks a ndarray to be interpreted as an image when applying a functor from a SpanSet.

◆ clippedTo()

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::clippedTo ( lsst::geom::Box2I const & box) const

Return a new SpanSet which has all pixel values inside specified box.

Parameters
boxInteger box specifying the bounds for which all pixels must be within

Definition at line 439 of file SpanSet.cc.

439 {
440 /* Return a copy of the current SpanSet but only with values which are contained within
441 * the supplied box
442 */
443 std::vector<Span> tempVec;
444 for (auto const& spn : _spanVector) {
445 if (spn.getY() >= box.getMinY() && spn.getY() <= box.getMaxY() &&
446 spansOverlap(spn, Span(spn.getY(), box.getMinX(), box.getMaxX()))) {
447 tempVec.emplace_back(spn.getY(), std::max(box.getMinX(), spn.getMinX()),
448 std::min(box.getMaxX(), spn.getMaxX()));
449 }
450 }
451 return std::make_shared<SpanSet>(std::move(tempVec), false);
452}
T emplace_back(T... args)
T max(T... args)
T min(T... args)

◆ computeCentroid()

lsst::geom::Point2D lsst::afw::geom::SpanSet::computeCentroid ( ) const

Compute the point about which the SpanSet's first moment is zero.

Definition at line 502 of file SpanSet.cc.

502 {
503 // Find the centroid of the SpanSet
504 std::size_t n = 0;
505 double xc = 0, yc = 0;
506 for (auto const& spn : _spanVector) {
507 int const y = spn.getY();
508 int const x0 = spn.getMinX();
509 int const x1 = spn.getMaxX();
510 int const npix = x1 - x0 + 1;
511
512 n += npix;
513 xc += npix * 0.5 * (x1 + x0);
514 yc += npix * y;
515 }
516 assert(n == _area);
517
518 return lsst::geom::Point2D(xc / _area, yc / _area);
519}
int y
Definition SpanSet.cc:48
Point< double, 2 > Point2D
Definition Point.h:324

◆ computeShape()

ellipses::Quadrupole lsst::afw::geom::SpanSet::computeShape ( ) const

Compute the shape parameters for the distribution of points in the SpanSet.

Definition at line 521 of file SpanSet.cc.

521 {
522 // Compute the shape of the SpanSet
524 double const xc = cen.getX();
525 double const yc = cen.getY();
526
527 double sumxx = 0, sumxy = 0, sumyy = 0;
528 for (auto const& spn : _spanVector) {
529 int const y = spn.getY();
530 int const x0 = spn.getX0();
531 int const x1 = spn.getX1();
532 int const npix = x1 - x0 + 1;
533
534 for (int x = x0; x <= x1; ++x) {
535 sumxx += (x - xc) * (x - xc);
536 }
537 sumxy += npix * (0.5 * (x1 + x0) - xc) * (y - yc);
538 sumyy += npix * (y - yc) * (y - yc);
539 }
540
541 return ellipses::Quadrupole(sumxx / _area, sumyy / _area, sumxy / _area);
542}
lsst::geom::Point2D computeCentroid() const
Compute the point about which the SpanSet's first moment is zero.
Definition SpanSet.cc:502

◆ contains() [1/2]

bool lsst::afw::geom::SpanSet::contains ( lsst::geom::Point2I const & point) const

Check if a point is contained within the SpanSet instance.

Parameters
pointAn integer point object for which membership is to be tested

Definition at line 492 of file SpanSet.cc.

492 {
493 // Check to see if a given point is found within any spans in this
494 for (auto& spn : _spanVector) {
495 if (spn.contains(point)) {
496 return true;
497 }
498 }
499 return false;
500}

◆ contains() [2/2]

bool lsst::afw::geom::SpanSet::contains ( SpanSet const & other) const

Check if a SpanSet instance entirely contains another SpanSet.

Parameters
otherThe SpanSet who's membership is to be tested for

Definition at line 466 of file SpanSet.cc.

466 {
467 // Handle null SpanSet passed as other
468 if (other.empty()) {
469 return false;
470 }
471 // Function to check if a SpanSet is entirely contained within this
472 for (auto const& otherSpn : other) {
473 std::size_t counter = 0;
474 for (auto const& spn : _spanVector) {
475 // Check that the end points of the span from other are contained in the
476 // span from this
477 if (spn.contains(lsst::geom::Point2I(otherSpn.getMinX(), otherSpn.getY())) &&
478 spn.contains(lsst::geom::Point2I(otherSpn.getMaxX(), otherSpn.getY()))) {
479 ++counter;
480 }
481 }
482 // if counter is equal to zero, then the current span from other is not
483 // contained in any span in this, and the function should return false
484 // short circuiting any other spans from other
485 if (counter == 0) {
486 return false;
487 }
488 }
489 return true;
490}

◆ copyImage()

template<typename ImageT >
void lsst::afw::geom::SpanSet::copyImage ( image::Image< ImageT > const & src,
image::Image< ImageT > & dest )
inline

Copy contents of source Image into destination image at the positions defined in the SpanSet.

Template Parameters
ImageTThe pixel type of the Image
Parameters
[in]srcThe Image that pixel values will be taken from
[out]destThe Image where pixels will be copied

Definition at line 416 of file SpanSet.h.

416 {
417 auto copyFunc = [](lsst::geom::Point2I const &point, ImageT const &srcPix, ImageT &destPix) {
418 destPix = srcPix;
419 };
420 applyFunctor(copyFunc, src, dest);
421 }
std::shared_ptr< RecordT > src
Definition Match.cc:48

◆ copyMaskedImage()

template<typename ImageT , typename MaskT , typename VarT >
void lsst::afw::geom::SpanSet::copyMaskedImage ( image::MaskedImage< ImageT, MaskT, VarT > const & src,
image::MaskedImage< ImageT, MaskT, VarT > & dest )
inline

Copy contents of source MaskedImage into destination image at the positions defined in the SpanSet.

Template Parameters
ImageTThe pixel type of the MaskedImage's Image
MaskTThe pixel type of the MaskedImage's Mask
VarTThe Pixel type of the MaskedImage's Variance Image
Parameters
[in]srcThe MaskedImage that pixel values will be taken from
[out]destThe MaskedImage where pixels will be copied

Definition at line 433 of file SpanSet.h.

434 {
435 auto copyFunc = [](lsst::geom::Point2I const &point, ImageT const &srcPix, MaskT const &srcMask,
436 VarT const &srcVar, ImageT &destPix, MaskT &destMask, VarT &destVar) {
437 destPix = srcPix;
438 destMask = srcMask;
439 destVar = srcVar;
440 };
441 applyFunctor(copyFunc, *(src.getImage()), *(src.getMask()), *(src.getVariance()), *(dest.getImage()),
442 *(dest.getMask()), *(dest.getVariance()));
443 }
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.

◆ dilated() [1/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::dilated ( int r,
Stencil s = Stencil::CIRCLE ) const

Perform a set dilation operation, and return a new object.

Dilate a SpanSet with a kernel specified with the stencil parameter

Parameters
rradius of the stencil, the length is inclusive i.e. 3 ranges from -3 to 3
smust be an enumeration of type geom::Stencil. Specifies the shape of the dilation kernel. May be CIRCLE, MANHATTAN, or BOX

Definition at line 544 of file SpanSet.cc.

544 {
545 // Return a dilated SpanSet made with the given stencil, by creating a SpanSet
546 // from the stencil and forwarding to the appropriate overloaded method
547 std::shared_ptr<SpanSet> stencilToSpanSet = fromShape(r, s);
548 return dilated(*stencilToSpanSet);
549}
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, lsst::geom::Point2I offset=lsst::geom::Point2I())
Factory function for creating SpanSets from a Stencil.
Definition SpanSet.cc:688
std::shared_ptr< SpanSet > dilated(int r, Stencil s=Stencil::CIRCLE) const
Perform a set dilation operation, and return a new object.
Definition SpanSet.cc:544

◆ dilated() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::dilated ( SpanSet const & other) const

Perform a set dilation operation, and return a new object.

Dilate a SpanSet with a kernel specified by another SpanSet

Parameters
otherA SpanSet which specifies the kernel to use for dilation

Definition at line 551 of file SpanSet.cc.

551 {
552 // Handle a null SpanSet nothing should be dilated
553 if (other.size() == 0) {
554 return std::make_shared<SpanSet>(_spanVector.begin(), _spanVector.end(), false);
555 }
556
557 // Return a dilated Spanset by the given SpanSet
558 std::vector<Span> tempVec;
559
560 for (auto const& spn : _spanVector) {
561 for (auto const& otherSpn : other) {
562 int const xmin = spn.getMinX() + otherSpn.getMinX();
563 int const xmax = spn.getMaxX() + otherSpn.getMaxX();
564 int const yval = spn.getY() + otherSpn.getY();
565 tempVec.emplace_back(yval, xmin, xmax);
566 }
567 }
568 // Allow constructor to handle merging adjacent and overlapping spans
569 return std::make_shared<SpanSet>(std::move(tempVec));
570}
int xmax
Definition SpanSet.cc:48
int xmin
Definition SpanSet.cc:48

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

◆ empty()

bool lsst::afw::geom::SpanSet::empty ( ) const
inline

Definition at line 95 of file SpanSet.h.

95{ return _spanVector.empty(); }

◆ end()

const_iterator lsst::afw::geom::SpanSet::end ( ) const
inline

Definition at line 89 of file SpanSet.h.

89{ return _spanVector.cend(); }

◆ eroded() [1/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::eroded ( int r,
Stencil s = Stencil::CIRCLE ) const

Perform a set erosion, and return a new object.

Erode a SpanSet with a kernel specified with the stencil parameter

Parameters
rradius of the stencil, the length is inclusive i.e. 3 ranges from -3 to 3
smust be an enumeration of type geom::Stencil. Specifies the shape of the erosion kernel. May be CIRCLE, MANHATTAN, or BOX

Definition at line 572 of file SpanSet.cc.

572 {
573 // Return an eroded SpanSet made with the given stencil, by creating a SpanSet
574 // from the stencil and forwarding to the appropriate overloaded method
575 std::shared_ptr<SpanSet> stencilToSpanSet = fromShape(r, s);
576 return eroded(*stencilToSpanSet);
577}
std::shared_ptr< SpanSet > eroded(int r, Stencil s=Stencil::CIRCLE) const
Perform a set erosion, and return a new object.
Definition SpanSet.cc:572

◆ eroded() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::eroded ( SpanSet const & other) const

Perform a set erosion operation, and return a new object.

Erode a SpanSet with a kernel specified by another SpanSet

Parameters
otherA SpanSet which specifies the kernel to use for erosion

Definition at line 579 of file SpanSet.cc.

579 {
580 // Handle a null SpanSet nothing should be eroded
581 if (other.size() == 0 || this->size() == 0) {
582 return std::make_shared<SpanSet>(_spanVector.begin(), _spanVector.end(), false);
583 }
584
585 // Return a SpanSet eroded by the given SpanSet
586 std::vector<Span> tempVec;
587
588 // Calculate all possible primary runs.
589 std::vector<PrimaryRun> primaryRuns;
590 for (auto const& spn : _spanVector) {
591 int m = 0;
592 for (auto const& otherSpn : other) {
593 if ((otherSpn.getMaxX() - otherSpn.getMinX()) <= (spn.getMaxX() - spn.getMinX())) {
594 int xmin = spn.getMinX() - otherSpn.getMinX();
595 int xmax = spn.getMaxX() - otherSpn.getMaxX();
596 int y = spn.getY() - otherSpn.getY();
597 primaryRuns.push_back(PrimaryRun({m, y, xmin, xmax}));
598 }
599 ++m;
600 }
601 }
602
603 // Iterate over the primary runs in such a way that we consider all values of m
604 // for a given y, then all m for y+1 etc.
605 std::sort(primaryRuns.begin(), primaryRuns.end(), comparePrimaryRun);
606
607 for (int y = primaryRuns.front().y; y <= primaryRuns.back().y; ++y) {
608 auto yRange = std::equal_range(primaryRuns.begin(), primaryRuns.end(), y, ComparePrimaryRunY());
609
610 /* Discard runs for any value of y for which we find fewer groups than M,
611 * the total Y range of the structuring element. This is step 3.1 of the
612 * Kim et al. algorithm.
613 */
614 // Plus one because end points are inclusive
615 auto otherYRange = other.back().getY() - other.front().getY() + 1;
616 if (std::distance(yRange.first, yRange.second) < otherYRange) {
617 continue;
618 }
619
620 /* "good" runs are those which are covered by each value of m, ie by each
621 * row in the structuring element. Our algorithm will consider each value
622 * of m in turn, gradually whittling down the list of good runs, then
623 * finally convert the remainder into Spans.
624 */
625 std::list<PrimaryRun> goodRuns;
626
627 for (int m = 0; m < otherYRange; ++m) {
628 auto mRange = std::equal_range(yRange.first, yRange.second, m, ComparePrimaryRunM());
629 if ((mRange.first == mRange.second)) {
630 // If a particular m is missing, we known that this y contains
631 // no good runs; this is equivalent to Kim et al. step 3.2.
632 goodRuns.clear();
633 } else {
634 // Consolidate all primary runs at this m so that they don't overlap.
635 std::list<PrimaryRun> candidateRuns;
636 int startX = mRange.first->xmin;
637 int endX = mRange.first->xmax;
638 for (auto run = mRange.first + 1; run != mRange.second; ++run) {
639 if (run->xmin > endX) {
640 // Start of a new run
641 candidateRuns.push_back(PrimaryRun{m, y, startX, endX});
642 startX = run->xmin;
643 endX = run->xmax;
644 } else {
645 // Continuation of an existing run
646 endX = run->xmax;
647 }
648 }
649 candidateRuns.push_back(PrimaryRun{m, y, startX, endX});
650
651 // Otherwise, calculate the intersection of candidate runs at
652 // this m with good runs from all previous m.
653 if (m == 0) {
654 // For m = 0 we have nothing to compare to; all runs are accepted
655 std::swap(goodRuns, candidateRuns);
656 } else {
657 std::list<PrimaryRun> newlist;
658 for (auto& good : goodRuns) {
659 for (auto& cand : candidateRuns) {
660 int start = std::max(good.xmin, cand.xmin);
661 int end = std::min(good.xmax, cand.xmax);
662 if (end >= start) {
663 newlist.push_back(PrimaryRun({m, y, start, end}));
664 }
665 }
666 }
667 std::swap(newlist, goodRuns);
668 }
669 }
670 }
671 for (auto& run : goodRuns) {
672 tempVec.emplace_back(run.y, run.xmin, run.xmax);
673 }
674 }
675 return std::make_shared<SpanSet>(std::move(tempVec));
676}
int m
Definition SpanSet.cc:48
T back(T... args)
T begin(T... args)
T clear(T... args)
T distance(T... args)
T end(T... args)
T equal_range(T... args)
T front(T... args)
T push_back(T... args)
T sort(T... args)
T swap(T... args)

◆ findEdgePixels()

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::findEdgePixels ( ) const

Select pixels within the SpanSet which touch its edge.

Definition at line 411 of file SpanSet.cc.

411 {
413 setMask(tempMask, static_cast<image::MaskPixel>(1));
414 auto erodedSpanSet = eroded(1, Stencil::CIRCLE);
415 erodedSpanSet->clearMask(tempMask, static_cast<image::MaskPixel>(1));
416 return SpanSet::fromMask(tempMask);
417}
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
Create a SpanSet from a mask.
Definition SpanSet.h:644
lsst::geom::Box2I getBBox() const
Return a new integer box which is the minimum size to contain the pixels.
Definition SpanSet.cc:286
void setMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Set a Mask at pixels defined by the SpanSet.
Definition SpanSet.cc:945
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:81

◆ flatten() [1/2]

template<typename Pixel , int inN, int inC>
ndarray::Array< typename std::remove_const< Pixel >::type, inN - 1, inN - 1 > lsst::afw::geom::SpanSet::flatten ( ndarray::Array< Pixel, inN, inC > const & input,
lsst::geom::Point2I const & xy0 = lsst::geom::Point2I() ) const
inline

Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.

Take values from an array at points defined by SpanSet and use them to populate a new array where the x,y coordinates of the SpanSet have been flattened to one dimension. First two dimensions of the input array must be the h,w which correspond to the SpanSet coordinates. Any number of remaining dimensions is permissible.

Template Parameters
PixelThe datatype for the ndarray
inNThe number of dimensions in the array object
inCNumber of guaranteed row-major contiguous dimensions, starting from the end
Parameters
inputThe ndarray from which the values will be taken
xy0A point object with is used as the origin point for the SpanSet coordinate system

Definition at line 303 of file SpanSet.h.

305 {
306 // Populate a lower dimensional array with the values from input taken at the points of SpanSet
307 auto outputShape = ndarray::concatenate(ndarray::makeVector(getArea()),
308 input.getShape().template last<inN - 2>());
309 ndarray::Array<typename std::remove_const<Pixel>::type, inN - 1, inN - 1> outputArray =
310 ndarray::allocate(outputShape);
311 outputArray.deep() = 0;
312 flatten(outputArray, input, xy0);
313 return outputArray;
314 }
ndarray::Array< typename std::remove_const< Pixel >::type, inN - 1, inN - 1 > flatten(ndarray::Array< Pixel, inN, inC > const &input, lsst::geom::Point2I const &xy0=lsst::geom::Point2I()) const
Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.
Definition SpanSet.h:303
size_type getArea() const
Return the number of pixels in the SpanSet.
Definition SpanSet.cc:283

◆ flatten() [2/2]

template<typename PixelIn , typename PixelOut , int inA, int outC, int inC>
void lsst::afw::geom::SpanSet::flatten ( ndarray::Array< PixelOut, inA - 1, outC > const & output,
ndarray::Array< PixelIn, inA, inC > const & input,
lsst::geom::Point2I const & xy0 = lsst::geom::Point2I() ) const
inline

Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.

Take values from an array at points defined by SpanSet and use them to populate a new array where the x,y coordinates of the SpanSet have been flattened to one dimension. First two dimensions of the input array must be the h,w which correspond to the SpanSet coordinates. Any number of remaining dimensions is permissible.

Template Parameters
PixelOutThe data-type for the output ndarray
PixelInThe data-type for the input ndarray
inAThe number of dimensions in the input array
outCNumber of guaranteed row-major contiguous dimensions in the output array, starting from the end
inCNumber of guaranteed row-major contiguous dimensions in the input array, starting from the end
Parameters
[out]outputThe 1d ndarray which will be populated with output parameters, will happen in place
[in]inputThe ndarray from which the values will be taken
[in]xy0A point object which is used as the origin point for the SpanSet coordinate system

Definition at line 336 of file SpanSet.h.

338 {
339 auto ndAssigner = [](lsst::geom::Point2I const &point,
340 typename details::FlatNdGetter<PixelOut, inA - 1, outC>::Reference out,
342 // Populate array output with values from input at positions given by SpanSet
343 applyFunctor(ndAssigner, ndarray::ndFlat(output), ndarray::ndImage(input, xy0));
344 }
details::FlatNdGetter< T, inA, inB > ndFlat(ndarray::Array< T, inA, inB > const &array)
Marks a ndarray to be interpreted as a 1D vector when applying a functor from a SpanSet.

◆ fromMask() [1/2]

template<typename T >
static std::shared_ptr< geom::SpanSet > lsst::afw::geom::SpanSet::fromMask ( image::Mask< T > const & mask,
T bitmask )
inlinestatic

Create a SpanSet from a mask.

Create a SpanSet from a Mask at pixels with the specified bit pattern

Template Parameters
TPixel type of the Mask
Parameters
maskmask to convert to a SpanSet
bitmaskbit pattern used to specify which pixel to include

Definition at line 701 of file SpanSet.h.

701 {
702 return fromMask(mask, [bitmask](T const &bitPattern) { return bitPattern & bitmask; });
703 }
afw::table::Key< afw::table::Array< MaskPixelT > > mask

◆ fromMask() [2/2]

template<typename T , typename UnaryPredicate = details::AnyBitSetFunctor<T>>
static std::shared_ptr< geom::SpanSet > lsst::afw::geom::SpanSet::fromMask ( image::Mask< T > const & mask,
UnaryPredicate comparator = details::AnyBitSetFunctor<T>() )
inlinestatic

Create a SpanSet from a mask.

Create a SpanSet from a class. The default behavior is to include any pixels which have any bits set. More complex selection/filtering of bit patterns can be done by supplying a comparator function.

Template Parameters
TPixel type of the Mask
FType of the functor
Parameters
maskmask to convert to a SpanSet
comparatorFunctor object to use in the decision to include pixel in SpanSet. Should return true when a given pixel in the mask should be part of the SpanSet, and false otherwise. The functor takes a single value taken from the mask at the pixel under consideration. Defaults to evaluating true if the mask has bits set, and false otherwise.

Definition at line 644 of file SpanSet.h.

645 {
646 // Create a vector which will hold all the spans created from the mask
647 std::vector<Span> tempVec;
648 // Grab some variables that will be used in the loop, so that they do not need to be fetched
649 // every iteration.
650 auto const maskArray = mask.getArray();
651 auto const minPoint = mask.getBBox().getMin();
652 auto const dimensions = maskArray.getShape();
653 auto const minY = minPoint.getY();
654 auto const minX = minPoint.getX();
655 auto const dimMinusOne = dimensions[1] - 1;
656 auto const yDim = dimensions[0];
657 auto const xDim = dimensions[1];
658 auto arrIter = maskArray.begin();
659 for (size_t y = 0; y < yDim; ++y) {
660 auto yWithOffset = y + minY;
661 bool inSpan = false; // are we currently in a span of interest?
662 std::size_t start; // starting x value of span we're currently in
663 for (size_t x = 0; x < xDim; ++x) {
664 bool compareValue = comparator((*arrIter)[x]);
665 if (inSpan) {
666 // If we were in a span but now the condition isn't satisfied, it means the Span stops
667 // at the previous pixel.
668 if (!compareValue) {
669 tempVec.push_back(Span(yWithOffset, start + minX, x - 1 + minX));
670 inSpan = false;
671 }
672 } else if (compareValue) {
673 // If we weren't in a span but now the condition is satisfied, we start a new span.
674 inSpan = true;
675 start = x;
676 }
677 }
678 // Since the x loop is over, if we're still in a span, this means the Span was not
679 // closed out and added to the vector. The last pixel should be included in the Span
680 // and the Span should be closed and added to the vector of spans.
681 if (inSpan) {
682 tempVec.push_back(Span(yWithOffset, start + minX, dimMinusOne + minX));
683 }
684 ++arrIter;
685 }
686
687 // construct a SpanSet from the spans determined above
688 return std::make_shared<SpanSet>(std::move(tempVec), false);
689 }

◆ fromShape() [1/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::fromShape ( geom::ellipses::Ellipse const & ellipse)
static

Factory function for creating SpanSets from an ellipse object.

Parameters
ellipseAn ellipse defining the region to create a SpanSet from

Definition at line 715 of file SpanSet.cc.

715 {
716 ellipses::PixelRegion pr(ellipse);
717 return std::make_shared<SpanSet>(pr.begin(), pr.end());
718}

◆ fromShape() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::fromShape ( int r,
Stencil s = Stencil::CIRCLE,
lsst::geom::Point2I offset = lsst::geom::Point2I() )
static

Factory function for creating SpanSets from a Stencil.

Parameters
rradius of the stencil, the length is inclusive i.e. 3 ranges from -3 to 3
smust be an enumeration of type geom::Stencil. Specifies the shape of the newly created SpanSet. May be CIRCLE, MANHATTAN, or BOX
offsetThis function usually creates a SpanSet centered about zero. This parameter is a point2I object which specifies an offset from zero to apply when creating the SpanSet.

Definition at line 688 of file SpanSet.cc.

688 {
689 // Create a SpanSet from a given Stencil
690 std::vector<Span> tempVec;
691 tempVec.reserve(2 * r + 1);
692 switch (s) {
693 case Stencil::CIRCLE:
694 for (auto dy = -r; dy <= r; ++dy) {
695 int dx = static_cast<int>(sqrt(r * r - dy * dy));
696 tempVec.emplace_back(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX());
697 }
698 break;
700 for (auto dy = -r; dy <= r; ++dy) {
701 int dx = r - abs(dy);
702 tempVec.emplace_back(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX());
703 }
704 break;
705 case Stencil::BOX:
706 for (auto dy = -r; dy <= r; ++dy) {
707 int dx = r;
708 tempVec.emplace_back(dy + offset.getY(), -dx + offset.getX(), dx + offset.getX());
709 }
710 break;
711 }
712 return std::make_shared<SpanSet>(std::move(tempVec), false);
713}
Angle abs(Angle const &a)
Definition Angle.h:113
T reserve(T... args)

◆ front()

const_reference lsst::afw::geom::SpanSet::front ( ) const
inline

Definition at line 92 of file SpanSet.h.

92{ return const_cast<geom::Span &>(_spanVector.front()); }

◆ getArea()

std::size_t lsst::afw::geom::SpanSet::getArea ( ) const

Return the number of pixels in the SpanSet.

Definition at line 283 of file SpanSet.cc.

283{ return _area; }

◆ getBBox()

lsst::geom::Box2I lsst::afw::geom::SpanSet::getBBox ( ) const

Return a new integer box which is the minimum size to contain the pixels.

Definition at line 286 of file SpanSet.cc.

286{ return _bbox; }

◆ getPersistenceName()

std::string lsst::afw::geom::SpanSet::getPersistenceName ( ) const
overrideprivatevirtual

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 1042 of file SpanSet.cc.

1042{ return getSpanSetPersistenceName(); }

◆ getPythonModule()

std::string lsst::afw::geom::SpanSet::getPythonModule ( ) const
inlineoverrideprivatevirtual

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 from lsst::afw::table::io::Persistable.

Definition at line 724 of file SpanSet.h.

724{ return "lsst.afw.geom"; }

◆ intersect() [1/2]

template<typename T >
std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::intersect ( image::Mask< T > const & other,
T bitmask ) const

Determine the common points between a SpanSet and a Mask with a given bit pattern.

Template Parameters
TPixel type of the Mask
Parameters
otherMask with which to calculate intersection
bitmaskThe bit value to consider when intersecting

Definition at line 967 of file SpanSet.cc.

967 {
968 return maskIntersect<T, false>(*this, other, bitmask);
969}

◆ intersect() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::intersect ( SpanSet const & other) const

Determine the common points between two SpanSets, and create a new SpanSet.

Parameters
otherThe other SpanSet with which to intersect with

Definition at line 720 of file SpanSet.cc.

720 {
721 // Check if the bounding boxes overlap, if not return null SpanSet
722 if (!_bbox.overlaps(other.getBBox())) {
723 return std::make_shared<SpanSet>();
724 }
725 // Handel intersecting a SpanSet with itself
726 if (other == *this) {
727 return std::make_shared<SpanSet>(this->_spanVector);
728 }
729 std::vector<Span> tempVec;
730 auto otherIter = other.begin();
731 for (auto const& spn : _spanVector) {
732 while (otherIter != other.end() && otherIter->getY() <= spn.getY()) {
733 if (spansOverlap(spn, *otherIter)) {
734 auto newMin = std::max(spn.getMinX(), otherIter->getMinX());
735 auto newMax = std::min(spn.getMaxX(), otherIter->getMaxX());
736 auto newSpan = Span(spn.getY(), newMin, newMax);
737 tempVec.push_back(newSpan);
738 }
739 ++otherIter;
740 }
741 }
742 return std::make_shared<SpanSet>(std::move(tempVec));
743}
bool overlaps(Box2I const &other) const noexcept
Return true if any points in other are also in this.
Definition Box.cc:122

◆ intersectNot() [1/2]

template<typename T >
std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::intersectNot ( image::Mask< T > const & other,
T bitmask ) const

Determine the common points between a SpanSet and the logical inverse of a Mask for a given bit pattern.

Parameters
otherMask with which to calculate intersection
bitmaskThe bit value to consider when intersecting
Template Parameters
TPixel type of the Mask

Definition at line 972 of file SpanSet.cc.

972 {
973 return maskIntersect<T, true>(*this, other, bitmask);
974}

◆ intersectNot() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::intersectNot ( SpanSet const & other) const

Determine the common points between a SpanSet and the logical inverse of a second SpanSet and return them in a new SpanSet.

Parameters
otherThe spanset which will be logically inverted when computing the intersection

Definition at line 745 of file SpanSet.cc.

745 {
746 // Check if the bounding boxes overlap, if not simply return a copy of this
747 if (!getBBox().overlaps(other.getBBox())) {
748 return std::make_shared<SpanSet>(this->begin(), this->end());
749 }
750 // Handle calling a SpanSet's intersectNot with itself as an argument
751 if (other == *this) {
752 return std::make_shared<SpanSet>();
753 }
754 /* This function must find all the areas in this and not in other. These SpanSets
755 * may be overlapping with this less than other a1| b1| a2| b2|,
756 * with this greater than other b1| a1| b2| a2|,
757 * with this containing other a1| b1| b2| a2|,
758 * or with other containing this b1| a1| a2| b2|
759 */
760 std::vector<Span> tempVec;
761 auto otherIter = other.begin();
762 for (auto const& spn : _spanVector) {
763 bool added = false;
764 bool spanStarted = false;
765 int spanBottom = 0;
766 while (otherIter != other.end() && otherIter->getY() <= spn.getY()) {
767 if (spansOverlap(spn, *otherIter)) {
768 added = true;
769 /* To handle one span containing the other, the spans will be added
770 * piecewise, and let the SpanSet constructor normalize spans which
771 * end up contiguous. In the case where this is contained in other,
772 * these statements will all be false, and nothing will be added,
773 * which is the expected behavior.
774 *
775 * Intersection with the logical not of another SpanSet requires that the Intersection
776 * be tested against the condition that multiple Spans may be present in the other
777 * SpanSet at the same Y coordinate. I.E. If one row in *this would contain two
778 * disconnected Spans in other, the result should be three new Spans.
779 */
780 // Check if a span is in the process of being created
781 if (!spanStarted) {
782 // If the minimum value of the Span in *this is less than that of other, add a new Span
783 if (spn.getMinX() < otherIter->getMinX()) {
784 tempVec.emplace_back(spn.getY(), spn.getMinX(), otherIter->getMinX() - 1);
785 }
786 // Conversely if the maximum value of the Span in *this is greater than that of other,
787 // Start a new span, and record what the minimum value of that span should be. This is
788 // because SpanSets can be disconnected, and the function must check if there are any
789 // additional Spans which fall in the same row
790 if (spn.getMaxX() > otherIter->getMaxX()) {
791 spanStarted = true;
792 spanBottom = otherIter->getMaxX() + 1;
793 }
794 } else {
795 // A span is in the process of being created and should be finished and added
796 tempVec.emplace_back(spn.getY(), spanBottom, std::min(spn.getMaxX(), otherIter->getMinX() - 1));
797 spanStarted = false;
798 // Check if the span in *this extends past that of the Span from other, if so
799 // begin a new Span
800 if (spn.getMaxX() > otherIter->getMaxX()) {
801 spanStarted = true;
802 spanBottom = otherIter->getMaxX() + 1;
803 }
804 }
805 }
806 if (otherIter->getMaxX() > spn.getMaxX()) {
807 break;
808 }
809 ++otherIter;
810 }
811 // Check if a span has been started but not finished, if that is the case that means there are
812 // no further spans on this row to consider and the span should be closed and added
813 if (spanStarted) {
814 tempVec.emplace_back(spn.getY(), spanBottom, spn.getMaxX());
815 }
816 /* If added is still zero, that means it did not overlap any of the spans in other
817 * and should be included in the new span
818 */
819 if (!added) {
820 tempVec.emplace_back(spn);
821 }
822 }
823 return std::make_shared<SpanSet>(std::move(tempVec));
824}
bool overlaps(SpanSet const &other) const
Specifies if this SpanSet overlaps with another SpanSet.
Definition SpanSet.cc:454

◆ isContiguous()

bool lsst::afw::geom::SpanSet::isContiguous ( ) const

Defines if the SpanSet is simply contiguous.

If the pixels can be traversed in such a way that every pixel can be reached without going over a pixel not contained in the SpanSet this method will return true. If the SpanSet is disjoint aka the above is not true and there is more than one region, returns false.

Definition at line 373 of file SpanSet.cc.

373 {
374 auto labeledPair = _makeLabels();
375 // Here we want to check if there is only one label. Since _makeLabels always increments
376 // at the end of each loop, we need to compare against the number 2. I.e. if everything
377 // gets labeled 1, the label counter will increment to 2, and the if statement will always
378 // be false and _makeLabels will fall through to the end and return to here.
379 return labeledPair.second <= 2;
380}

◆ isPersistable()

bool lsst::afw::geom::SpanSet::isPersistable ( ) const
inlineoverridevirtualnoexcept

Return true if this particular object can be persisted using afw::table::io.

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

Definition at line 709 of file SpanSet.h.

709{ return true; }

◆ operator!=()

bool lsst::afw::geom::SpanSet::operator!= ( SpanSet const & other) const

Definition at line 683 of file SpanSet.cc.

683 {
684 // Check the equivalence of this SpanSet with another
685 return _spanVector != other._spanVector;
686}

◆ operator=() [1/2]

SpanSet & lsst::afw::geom::SpanSet::operator= ( SpanSet && other)
inline

Definition at line 169 of file SpanSet.h.

169{ return *this = other; }

◆ operator=() [2/2]

SpanSet & lsst::afw::geom::SpanSet::operator= ( SpanSet const & )
default

◆ operator==()

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

Compute equality between two SpanSets.

Parameters
otherThe SpanSet for which equality will be computed

Definition at line 678 of file SpanSet.cc.

678 {
679 // Check the equivalence of this SpanSet with another
680 return _spanVector == other._spanVector;
681}

◆ overlaps()

bool lsst::afw::geom::SpanSet::overlaps ( SpanSet const & other) const

Specifies if this SpanSet overlaps with another SpanSet.

Parameters
otherA SpanSet for which overlapping comparison will be made

Definition at line 454 of file SpanSet.cc.

454 {
455 // Function to check if two SpanSets overlap
456 for (auto const& otherSpan : other) {
457 for (auto const& spn : _spanVector) {
458 if (spansOverlap(otherSpan, spn)) {
459 return true;
460 }
461 }
462 }
463 return false;
464}

◆ readFits() [1/3]

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< lsst::afw::geom::SpanSet > lsst::afw::table::io::PersistableFacade< lsst::afw::geom::SpanSet >::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< lsst::afw::geom::SpanSet > lsst::afw::table::io::PersistableFacade< lsst::afw::geom::SpanSet >::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.

◆ setImage()

template<typename ImageT >
template void lsst::afw::geom::SpanSet::setImage< double > ( image::Image< ImageT > & image,
ImageT val,
lsst::geom::Box2I const & region = lsst::geom::Box2I(),
bool doClip = false ) const

Set the values of an Image at points defined by the SpanSet.

Template Parameters
ImageTThe pixel type of the Image to be set
Parameters
[out]imageThe Image in which pixels will be set
[in]valThe value to set
[in]regionA bounding box limiting the scope of the SpanSet, points defined in the SpanSet which fall outside this box will be ignored if the doClip parameter is set to true, defaults to the bounding box of the image
[in]doClipLimit the copy operation to pixels in the SpanSet that lie within the region parameter defaults to false

Definition at line 922 of file SpanSet.cc.

923 {
925 if (region.isEmpty()) {
926 bbox = image.getBBox();
927 } else {
928 bbox = region;
929 }
930 auto setterFunc = [](lsst::geom::Point2I const& point, ImageT& out, ImageT in) { out = in; };
931 try {
932 if (doClip) {
933 auto tmpSpan = this->clippedTo(bbox);
934 tmpSpan->applyFunctor(setterFunc, image, val);
935 } else {
936 applyFunctor(setterFunc, image, val);
937 }
938 } catch (pex::exceptions::OutOfRangeError const&) {
939 throw LSST_EXCEPT(pex::exceptions::OutOfRangeError,
940 "Footprint Bounds Outside image, set doClip to true");
941 }
942}
AmpInfoBoxKey bbox
Definition Amplifier.cc:117
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Definition Exception.h:48
std::shared_ptr< SpanSet > clippedTo(lsst::geom::Box2I const &box) const
Return a new SpanSet which has all pixel values inside specified box.
Definition SpanSet.cc:439
ImageT val
Definition CR.cc:146

◆ setMask()

template<typename T >
void lsst::afw::geom::SpanSet::setMask ( lsst::afw::image::Mask< T > & target,
T bitmask ) const

Set a Mask at pixels defined by the SpanSet.

Template Parameters
Tdata-type of a pixel in the Mask plane
Parameters
[in,out]targetMask in which values will be set
[in]bitmaskThe bit pattern to set in the mask

Definition at line 945 of file SpanSet.cc.

945 {
946 // Use a lambda to set bits in a mask at the locations given by SpanSet
947 auto targetArray = target.getArray();
948 auto xy0 = target.getBBox().getMin();
949 auto maskFunctor = [](lsst::geom::Point2I const& point,
951 T bitmask) { maskVal |= bitmask; };
952 applyFunctor(maskFunctor, ndarray::ndImage(targetArray, xy0), bitmask);
953}

◆ shiftedBy() [1/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::shiftedBy ( int x,
int y ) const

Return a new SpanSet shifted by specified amount.

Parameters
xnumber of pixels to shift in x dimension
ynumber of pixels to shift in y dimension

Definition at line 419 of file SpanSet.cc.

419 {
420 // Function to create a new SpanSet which is a copy of this, shifted by x and y
421 return makeShift(x, y);
422}

◆ shiftedBy() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::shiftedBy ( lsst::geom::Extent2I const & offset) const

Return a new SpanSet shifted by specified amount.

Parameters
offsetinteger extent which specifies amount to offset in x and y

Definition at line 424 of file SpanSet.cc.

424 {
425 // Function to create a new SpanSet which is a copy of this, shifted by an extent object
426 return makeShift(offset.getX(), offset.getY());
427}

◆ size()

size_type lsst::afw::geom::SpanSet::size ( ) const
inline

Definition at line 94 of file SpanSet.h.

94{ return _spanVector.size(); }

◆ split()

std::vector< std::shared_ptr< SpanSet > > lsst::afw::geom::SpanSet::split ( ) const

Split a discontinuous SpanSet into multiple SpanSets which are contiguous.

Definition at line 382 of file SpanSet.cc.

382 {
383 auto labeledPair = _makeLabels();
384 auto labels = labeledPair.first;
385 auto numberOfLabels = labeledPair.second;
387 // As the number of labels is known, the number of SpanSets to be created is also known
388 // make a vector of vectors to hold the Spans which will correspond to each SpanSet
389 std::vector<std::vector<Span>> subSpanLists(numberOfLabels - 1);
390
391 // if numberOfLabels is 1, that means a null SpanSet is being operated on,
392 // and we should return like
393 if (numberOfLabels == 1) {
394 subRegions.push_back(std::make_shared<SpanSet>());
395 return subRegions;
396 }
397 subRegions.reserve(numberOfLabels - 1);
398
399 // loop over the current SpanSet's spans sorting each of the spans according to the label
400 // that was assigned
401 for (std::size_t i = 0; i < _spanVector.size(); ++i) {
402 subSpanLists[labels[i] - 1].push_back(_spanVector[i]);
403 }
404 // Transform each of the vectors of Spans into a SpanSet
405 for (std::size_t i = 0; i < numberOfLabels - 1; ++i) {
406 subRegions.push_back(std::make_shared<SpanSet>(subSpanLists[i]));
407 }
408 return subRegions;
409}

◆ transformedBy() [1/3]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::transformedBy ( lsst::geom::AffineTransform const & t) const

Return a new SpanSet who's pixels are the product of applying the specified transformation.

Parameters
tAn affine transform object which will be used to map the pixels

Definition at line 845 of file SpanSet.cc.

845 {
846 // Transform points in SpanSet by the AffineTransform
847 return transformedBy(*makeTransform(t));
848}
std::shared_ptr< SpanSet > transformedBy(lsst::geom::LinearTransform const &t) const
Return a new SpanSet who's pixels are the product of applying the specified transformation.
Definition SpanSet.cc:840
std::shared_ptr< TransformPoint2ToPoint2 > makeTransform(lsst::geom::AffineTransform const &affine)
Wrap an lsst::geom::AffineTransform as a Transform.

◆ transformedBy() [2/3]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::transformedBy ( lsst::geom::LinearTransform const & t) const

Return a new SpanSet who's pixels are the product of applying the specified transformation.

Parameters
tA linear transform object which will be used to map the pixels

Definition at line 840 of file SpanSet.cc.

840 {
841 // Transform points in SpanSet by the LinearTransform
843}
An affine coordinate transformation consisting of a linear transformation and an offset.

◆ transformedBy() [3/3]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::transformedBy ( TransformPoint2ToPoint2 const & t) const

Return a new SpanSet who's pixels are the product of applying the specified transformation.

Parameters
tA 2-D transform which will be used to map the pixels

Definition at line 850 of file SpanSet.cc.

850 {
851 // If the SpanSet is empty, its bounding box corners are not
852 // meaningful and cannot be transformed.
853 if (_spanVector.empty()) {
854 return std::make_shared<SpanSet>();
855 }
856
857 // Transform points in SpanSet by Transform<Point2Endpoint, Point2Endpoint>
858 // Transform the original bounding box
859 lsst::geom::Box2D newBBoxD;
861 fromCorners.reserve(4);
862 for (auto const& fc : _bbox.getCorners()) {
863 fromCorners.emplace_back(lsst::geom::Point2D(fc));
864 }
865 auto toPoints = t.applyForward(fromCorners);
866
867 // Check that this was a valid transformation.
868 // Inverses should be good to floating point precision, this is just
869 // a very rough check.
870 auto fromToPoints = t.applyInverse(toPoints);
871 for (int i = 0; i < 4; ++i) {
872 if ((std::abs(fromToPoints[i].getX() - fromCorners[i].getX()) > 1.0) ||
873 (std::abs(fromToPoints[i].getY() - fromCorners[i].getY()) > 1.0)) {
874 return std::make_shared<SpanSet>();
875 }
876 }
877
878 for (auto const& tc : toPoints) {
879 newBBoxD.include(tc);
880 }
881
882 lsst::geom::Box2I newBBoxI(newBBoxD);
883
885 newBoxPoints.reserve(newBBoxI.getWidth());
886 std::vector<Span> tempVec;
887 for (int y = newBBoxI.getBeginY(); y < newBBoxI.getEndY(); ++y) {
888 bool inSpan = false; // Are we in a span?
889 int start = -1; // Start of span
890
891 // vectorize one row at a time (vectorizing the whole bbox would further improve performance
892 // but could lead to memory issues for very large bounding boxes)
893 newBoxPoints.clear();
894 for (int x = newBBoxI.getBeginX(); x < newBBoxI.getEndX(); ++x) {
895 newBoxPoints.emplace_back(lsst::geom::Point2D(x, y));
896 }
897 auto oldBoxPoints = t.applyInverse(newBoxPoints);
898 auto oldBoxPointIter = oldBoxPoints.cbegin();
899 for (int x = newBBoxI.getBeginX(); x < newBBoxI.getEndX(); ++x, ++oldBoxPointIter) {
900 auto p = *oldBoxPointIter;
901 int const xSource = std::floor(0.5 + p.getX());
902 int const ySource = std::floor(0.5 + p.getY());
903
904 if (contains(lsst::geom::Point2I(xSource, ySource))) {
905 if (!inSpan) {
906 inSpan = true;
907 start = x;
908 }
909 } else if (inSpan) {
910 inSpan = false;
911 tempVec.emplace_back(y, start, x - 1);
912 }
913 }
914 if (inSpan) {
915 tempVec.emplace_back(y, start, newBBoxI.getMaxX());
916 }
917 }
918 return std::make_shared<SpanSet>(std::move(tempVec));
919}
bool contains(SpanSet const &other) const
Check if a SpanSet instance entirely contains another SpanSet.
Definition SpanSet.cc:466
A floating-point coordinate rectangle geometry.
Definition Box.h:413
void include(Point2D const &point) noexcept
Expand this to ensure that this->contains(point).
Definition Box.cc:380
T floor(T... args)

◆ unflatten() [1/2]

template<typename Pixel , int inA, int inC>
ndarray::Array< typename std::remove_const< Pixel >::type, inA+1, inA+1 > lsst::afw::geom::SpanSet::unflatten ( ndarray::Array< Pixel, inA, inC > const & input) const
inline

Expand an array by one spatial dimension at points given by SpanSet.

Take values from a lower dimensional array and insert them in an output array with one additional dimension at points defined by the SpanSet, offset by the lower left hand corner of the bounding box of the SpanSet. The first two dimensions of the output array will correspond to the y,x dimensions of the SpanSet

Template Parameters
PixelThe data-type for the ndarray
inANumber of dimension of the input array
inCNumber of guaranteed row-major contiguous dimensions, starting from the end
Parameters
inputThe ndarray from which the values will be taken

Definition at line 360 of file SpanSet.h.

361 {
362 // Create a higher dimensional array the size of the bounding box and extra dimensions of input.
363 // Populate values from input, placed at locations corresponding to SpanSet, offset by the
364 // lower corner of the bounding box
365 auto existingShape = input.getShape();
366 typename decltype(existingShape)::Element height = _bbox.getHeight();
367 typename decltype(existingShape)::Element width = _bbox.getWidth();
368 auto outputShape = ndarray::concatenate(ndarray::makeVector(height, width),
369 input.getShape().template last<inA - 1>());
370 ndarray::Array<typename std::remove_const<Pixel>::type, inA + 1, inA + 1> outputArray =
371 ndarray::allocate(outputShape);
372 outputArray.deep() = 0;
373 unflatten(outputArray, input, lsst::geom::Point2I(_bbox.getMinX(), _bbox.getMinY()));
374 return outputArray;
375 }
ndarray::Array< typename std::remove_const< Pixel >::type, inA+1, inA+1 > unflatten(ndarray::Array< Pixel, inA, inC > const &input) const
Expand an array by one spatial dimension at points given by SpanSet.
Definition SpanSet.h:360
int getMinY() const noexcept
Definition Box.h:158
int getHeight() const noexcept
Definition Box.h:188
int getMinX() const noexcept
Definition Box.h:157
int getWidth() const noexcept
Definition Box.h:187

◆ unflatten() [2/2]

template<typename PixelIn , typename PixelOut , int inA, int outC, int inC>
void lsst::afw::geom::SpanSet::unflatten ( ndarray::Array< PixelOut, inA+1, outC > const & output,
ndarray::Array< PixelIn, inA, inC > const & input,
lsst::geom::Point2I const & xy0 = lsst::geom::Point2I() ) const
inline

Expand an array by one spatial dimension at points given by SpanSet.

Take values from a lower dimensional array and insert them in an output array with one additional dimension at points defined by the SpanSet, offset by the lower left hand corner of the bounding box of the SpanSet. The first two dimensions of the output array will correspond to the y,x dimensions of the SpanSet

Template Parameters
PixelOutThe datatype for the output ndarray
PixelInThe datatype for the input ndarray
inANumber of dimensions of the input ndarray
outCNumber of guaranteed row-major contiguous dimensions in the output array, starting from the end
inCNumber of guaranteed row-major contiguous dimensions in the input array, starting from the end
Parameters
[out]outputThe 1d ndarray which will be populated with output parameters, will happen in place
[in]inputThe ndarray from which the values will be taken
[in]xy0A point object with is used as the origin point for the SpanSet coordinate system

Definition at line 397 of file SpanSet.h.

399 {
400 // Populate 2D ndarray output with values from input, at locations defined by SpanSet, optionally
401 // offset by xy0
402 auto ndAssigner = [](lsst::geom::Point2I const &point,
405 applyFunctor(ndAssigner, ndarray::ndImage(output, xy0), ndarray::ndFlat(input));
406 }

◆ union_() [1/2]

template<typename T >
std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::union_ ( image::Mask< T > const & other,
T bitmask ) const

Determine the union between a SpanSet and a Mask for a given bit pattern.

Template Parameters
TPixel type of the Mask
Parameters
otherMask with which to calculate intersection
bitmaskThe bit value to consider when intersecting

Definition at line 977 of file SpanSet.cc.

977 {
978 auto comparator = [bitmask](T pixelValue) { return (pixelValue & bitmask); };
979 auto spanSetFromMask = fromMask(other, comparator);
980 return union_(*spanSetFromMask);
981}
std::shared_ptr< SpanSet > union_(SpanSet const &other) const
Create a new SpanSet that contains all points from two SpanSets.
Definition SpanSet.cc:826

◆ union_() [2/2]

std::shared_ptr< SpanSet > lsst::afw::geom::SpanSet::union_ ( SpanSet const & other) const

Create a new SpanSet that contains all points from two SpanSets.

Parameters
otherThe SpanSet from which the union will be calculated

Definition at line 826 of file SpanSet.cc.

826 {
827 /* Simply include Spans from both SpanSets in a new vector and let the SpanSet
828 * constructor normalize any of the SpanSets which may be contiguous
829 */
830 std::size_t combineSize = size() + other.size();
831 std::vector<Span> tempVec;
832 tempVec.reserve(combineSize);
833 // Copy this
834 tempVec.insert(tempVec.end(), _spanVector.begin(), _spanVector.end());
835 // Copy other
836 tempVec.insert(tempVec.end(), other.begin(), other.end());
837 return std::make_shared<SpanSet>(std::move(tempVec));
838}
size_type size() const
Definition SpanSet.h:94
T insert(T... args)

◆ write()

void lsst::afw::geom::SpanSet::write ( OutputArchiveHandle & handle) const
overrideprivatevirtual

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 1044 of file SpanSet.cc.

1044 {
1045 auto const& keys = SpanSetPersistenceHelper::get();
1046 auto spanCat = handle.makeCatalog(keys.spanSetSchema);
1047 spanCat.reserve(size());
1048 for (auto const& val : *this) {
1049 auto record = spanCat.addNew();
1050 record->set(keys.spanY, val.getY());
1051 record->set(keys.spanX0, val.getX0());
1052 record->set(keys.spanX1, val.getX1());
1053 }
1054 handle.saveCatalog(spanCat);
1055}

◆ 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

◆ SpansSetFactory

friend class SpansSetFactory
friend

Definition at line 732 of file SpanSet.h.


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