25 #ifndef LSST_AFW_GEOM_SPANSET_H
26 #define LSST_AFW_GEOM_SPANSET_H
43 namespace lsst {
namespace afw {
namespace geom {
namespace details {
50 return pixelValue !=0;
58 namespace lsst {
namespace afw {
namespace geom {
87 template <
typename T,
typename UnaryPredicate = details::AnyBitSetFunctor<T>>
90 std::vector<Span> tempVec;
91 std::size_t startValue{0};
93 auto const & maskArray = mask.
getArray();
98 for (
size_t x = 0;
x < dimensions[1]; ++
x) {
101 if (p(maskArray[
y][
x]) && !started) {
107 else if (started && !p(maskArray[
y][x])) {
108 tempVec.push_back(
Span(
y, startValue, x-1));
115 if (started && x == dimensions[1]) {
116 tempVec.push_back(
Span(
y, startValue, x));
122 return std::make_shared<SpanSet>(std::move(tempVec));
175 template <
typename iter>
244 std::shared_ptr<SpanSet>
shiftedBy(
int x,
int y)
const;
320 std::shared_ptr<SpanSet>
dilate(
SpanSet const & other)
const;
338 std::shared_ptr<SpanSet>
erode(
SpanSet const & other)
const;
350 template <
typename Pixel,
int inC>
351 ndarray::Array<Pixel, 1, 1>
flatten(ndarray::Array<Pixel, 2, inC> &
input,
354 ndarray::Array<Pixel, 1, 1> outputArray = ndarray::allocate(ndarray::makeVector(
getArea()));
355 outputArray.deep() = 0;
356 flatten(outputArray, input, xy0);
374 template <
typename Pixel,
int outC,
int inC>
376 ndarray::Array<Pixel, 1, outC>
const & output,
377 ndarray::Array<Pixel, 2, inC>
const & input,
398 template <
typename Pixel,
int inC>
399 ndarray::Array<Pixel, 2, 2>
unflatten(ndarray::Array<Pixel, 1, inC> & input)
const {
403 outputArray.deep() = 0;
423 template <
typename Pixel,
int outC,
int inC>
425 ndarray::Array<Pixel, 1, inC> & input,
473 template <
typename Functor,
typename...Args>
497 template <
typename T>
500 auto targetArray = target.
getArray();
501 auto maskFunctor = []
505 {maskVal |= bitmask;};
516 template <
typename T>
519 auto targetArray = target.
getArray();
520 auto clearMaskFunctor = []
524 {maskVal &= ~bitmask;};
542 template <
typename T>
544 auto comparator = [bitmask]
546 {
return (pixelValue & bitmask) == bitmask;};
566 template <
typename T>
568 auto comparator = [bitmask]
570 {
return (pixelValue & bitmask) == bitmask;};
579 std::shared_ptr<SpanSet>
union_(
SpanSet const & other)
const;
589 template <
typename T>
591 auto comparator = [bitmask]
593 {
return (pixelValue & bitmask) == bitmask;};
595 return union_(*spanSetFromMask);
621 std::vector<std::shared_ptr<geom::SpanSet>>
split()
const;
653 void _label(
geom::Span const & spn, std::vector<std::size_t> & labelVector, std::size_t currentLabel)
const;
654 std::pair<std::vector<std::size_t>, std::size_t>
_makeLabels()
const;
689 std::shared_ptr<SpanSet>
makeShift(
int x,
int y)
const;
691 template <
typename F,
typename ...T>
702 for (
auto point : spn) {
703 f(point,
args.get()...);
721 #endif // LSST_AFW_GEOM_SPANSET_H
int getMinX() const
Minimum x-value.
static std::shared_ptr< geom::SpanSet > spanSetFromShape(int r, Stencil s=Stencil::CIRCLE)
Factory function for creating SpanSets from a Stencil.
An ellipse core with quadrupole moments as parameters.
void variadicSpanSetter(Span const spn, T &x)
Stencil
An enumeration class which describes the shapes.
std::pair< std::vector< std::size_t >, std::size_t > _makeLabels() const
std::shared_ptr< SpanSet > makeShift(int x, int y) const
typename ndarray::Array< T, N, C >::Reference::Reference Reference
Point2D computeCentroid() const
Compute the point about which the SpanSet is symmetrically distributed.
std::shared_ptr< SpanSet > union_(SpanSet const &other) const
Create a new SpanSet that contains all points from two SpanSets.
const_iterator end() const
A compact representation of a collection of pixels.
Include files required for standard LSST Exception handling.
A range of pixels within one row of an Image.
const_reference back() const
Box2I getBBox() const
Return a new integer box which is the minimum size to contain the pixels.
bool operator==(SpanSet const &other) const
Compute equality between two SpanSets.
void clearMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Unset a Maks at pixels defined by the SpanSet.
std::shared_ptr< SpanSet > intersect(image::Mask< T > const &other, T const &bitmask) const
Determine the common points between a SpanSet and a Mask with a given bit pattern.
const_iterator cbegin() const
io::OutputArchiveHandle OutputArchiveHandle
details::FlatNdGetter< T > 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.
void applyFunctorImpl(F f, T...args) const
int getY() const
Return the y-value.
const_reference front() const
bool operator()(T const &pixelValue)
SpanSet()
Default constructor.
void unflatten(ndarray::Array< Pixel, 2, outC > &output, ndarray::Array< Pixel, 1, inC > &input, Point2I const &xy0=Point2I()) const
Populate 2d array at points given by SpanSet.
void write(OutputArchiveHandle &handle) const override
Write the object to one or more catalogs.
bool spansContiguous(Span const &a, Span const &b, bool compareY=true) const
std::vector< Span >::size_type size_type
bool spansOverlap(Span const &a, Span const &b, bool compareY=true) const
An integer coordinate rectangle.
int getMaxX() const
Maximum x-value.
A base class for objects that can be persisted via afw::table::io Archive classes.
void flatten(ndarray::Array< Pixel, 1, outC > const &output, ndarray::Array< Pixel, 2, inC > const &input, Point2I const &xy0=Point2I()) const
Populate 1d array at points given by SpanSet.
afw::table::PointKey< int > dimensions
bool overlaps(SpanSet const &other) const
Specifies if this SpanSet overlaps with another SpanSet.
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 reg...
Represent a 2-dimensional array of bitmask pixels.
friend class SpansSetFactory
bool isPersistable() const
Return true if this particular object can be persisted using afw::table::io.
SpanSet(iter begin, iter end, bool normalize=true)
Construct a SpanSet from an iterator.
bool isContiguous() const
Defines if the SpanSet is simply contiguous.
std::shared_ptr< SpanSet > intersect(SpanSet const &other) const
Determine the common points between two SpanSets, and create a new SpanSet.
const_iterator begin() const
ndarray::Array< Pixel, 1, 1 > flatten(ndarray::Array< Pixel, 2, inC > &input, Point2I const &xy0=Point2I()) const
Create 1d array at points given by SpanSet.
void variadicBoundChecker(Box2I const box, int area, T const &x)
details::ImageNdGetter< T, inA, inB > ndImage(ndarray::Array< T, inA, inB > const &array, afwGeom::Point2I xy0=afwGeom::Point2I())
Marks a ndarray to be interpreted as an image when applying a functor from a SpanSet.
std::shared_ptr< SpanSet > intersectNot(image::Mask< T > const &other, T const &bitmask) const
Determine the common points between a SpanSet and the logical inverse of a Mask for a given bit patte...
ndarray::Array< Pixel, 2, 2 > unflatten(ndarray::Array< Pixel, 1, inC > &input) const
Create 2d array at pionts given by SpanSet.
void applyFunctor(Functor &&func, Args &&...args) const
Apply functor on individual elements from the supplied parameters.
value_type const & const_reference
std::vector< Span >::const_iterator const_iterator
std::shared_ptr< SpanSet > shiftedBy(int x, int y) const
Return a new SpanSet shifted by specified amount.
void variadicIncrementPosition(T &x)
std::vector< std::shared_ptr< geom::SpanSet > > split() const
Split a discontinuous SpanSet into multiple SpanSets which are contiguous.
void setMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Set a Mask at pixels defined by the SpanSet.
std::shared_ptr< SpanSet > clippedTo(Box2I const &box) const
Return a new SpanSet which has all pixel values inside specified box.
std::shared_ptr< SpanSet > transformedBy(LinearTransform const &t) const
Return a new SpanSet who's pixels are the product of applying the specified transformation.
typename ndarray::Array< T, 1, 1 >::Reference Reference
bool operator!=(SpanSet const &other) const
std::shared_ptr< SpanSet > dilate(int r, Stencil s=Stencil::CIRCLE) const
Perform a set dilation operation, and return a new object.
afw::table::Key< double > b
std::shared_ptr< SpanSet > union_(image::Mask< T > const &other, T const &bitmask) const
Determine the union between a SpanSet and a Mask for a given bit pattern.
FlatNdGetter< T > makeGetter(FlatNdGetter< T > &getter)
ellipses::Quadrupole computeShape() const
Compute the shape parameters for the distribution of points in the SpanSet.
Abstract base class for function objects.
size_type getArea() const
Return the number of pixels in the SpanSet.
std::shared_ptr< SpanSet > intersectNot(SpanSet const &other) const
Determine the common points between a SpanSet and the logical inverse of a second SpanSet and return ...
bool contains(SpanSet const &other) const
Check if a SpanSet instance entirely contains another SpanSet.
A CRTP facade class for subclasses of Persistable.
std::shared_ptr< SpanSet > erode(int r, Stencil s=Stencil::CIRCLE) const
Perform a set erosion, and return a new object.
std::shared_ptr< geom::SpanSet > maskToSpanSet(image::Mask< T > const &mask, UnaryPredicate p=details::AnyBitSetFunctor< T >())
Create a SpanSet from a mask.
const_iterator cend() const
std::vector< Span > _spanVector
void _label(geom::Span const &spn, std::vector< std::size_t > &labelVector, std::size_t currentLabel) const