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

960 {
961 // Use a lambda to clear bits in a mask at the locations given by SpanSet
962 auto targetArray = target.getArray();
963 auto xy0 = target.getBBox().getMin();
964 auto clearMaskFunctor = [](lsst::geom::Point2I const& point,
966 T bitmask) { maskVal &= ~bitmask; };
967 applyFunctor(clearMaskFunctor, ndarray::ndImage(targetArray, xy0), bitmask);
968}
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:949
Represent a 2-dimensional array of bitmask pixels.
Definition Mask.h:82

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

1046{ 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 971 of file SpanSet.cc.

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

◆ 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 otherBeginIter = other.begin();
731 for (auto const& spn : _spanVector) {
732 while(otherBeginIter != other.end() && otherBeginIter->getY() < spn.getY()) {
733 ++otherBeginIter;
734 }
735 for (auto otherIter = otherBeginIter; otherIter != other.end() && otherIter->getY() <= spn.getY(); ++otherIter) {
736 if (spansOverlap(spn, *otherIter)) {
737 auto newMin = std::max(spn.getMinX(), otherIter->getMinX());
738 auto newMax = std::min(spn.getMaxX(), otherIter->getMaxX());
739 auto newSpan = Span(spn.getY(), newMin, newMax);
740 tempVec.push_back(newSpan);
741 }
742 }
743 }
744 return std::make_shared<SpanSet>(std::move(tempVec));
745}
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 976 of file SpanSet.cc.

976 {
977 return maskIntersect<T, true>(*this, other, bitmask);
978}

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

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

927 {
929 if (region.isEmpty()) {
930 bbox = image.getBBox();
931 } else {
932 bbox = region;
933 }
934 auto setterFunc = [](lsst::geom::Point2I const& point, ImageT& out, ImageT in) { out = in; };
935 try {
936 if (doClip) {
937 auto tmpSpan = this->clippedTo(bbox);
938 tmpSpan->applyFunctor(setterFunc, image, val);
939 } else {
940 applyFunctor(setterFunc, image, val);
941 }
942 } catch (pex::exceptions::OutOfRangeError const&) {
943 throw LSST_EXCEPT(pex::exceptions::OutOfRangeError,
944 "Footprint Bounds Outside image, set doClip to true");
945 }
946}
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 949 of file SpanSet.cc.

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

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

849 {
850 // Transform points in SpanSet by the AffineTransform
851 return transformedBy(*makeTransform(t));
852}
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:844
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 844 of file SpanSet.cc.

844 {
845 // Transform points in SpanSet by the LinearTransform
847}
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 854 of file SpanSet.cc.

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

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

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

830 {
831 /* Simply include Spans from both SpanSets in a new vector and let the SpanSet
832 * constructor normalize any of the SpanSets which may be contiguous
833 */
834 std::size_t combineSize = size() + other.size();
835 std::vector<Span> tempVec;
836 tempVec.reserve(combineSize);
837 // Copy this
838 tempVec.insert(tempVec.end(), _spanVector.begin(), _spanVector.end());
839 // Copy other
840 tempVec.insert(tempVec.end(), other.begin(), other.end());
841 return std::make_shared<SpanSet>(std::move(tempVec));
842}
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 1048 of file SpanSet.cc.

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

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