25 #ifndef LSST_AFW_GEOM_SPANSET_H
26 #define LSST_AFW_GEOM_SPANSET_H
33 #include "lsst/pex/exceptions.h"
53 bool operator()(T pixelValue) {
return pixelValue != 0; }
93 bool empty()
const {
return _spanVector.empty(); }
120 template <
typename iter>
123 if (_spanVector.size() == 0) {
145 explicit SpanSet(std::vector<Span>
const &vec,
bool normalize =
true);
158 explicit SpanSet(std::vector<Span> &&vec,
bool normalize =
true);
187 std::shared_ptr<SpanSet>
shiftedBy(
int x,
int y)
const;
295 template <
typename Pixel,
int inN,
int inC>
296 ndarray::Array<typename std::remove_const<Pixel>::type, inN - 1, inN - 1>
flatten(
299 auto outputShape = ndarray::concatenate(ndarray::makeVector(
getArea()),
300 input.getShape().template last<inN - 2>());
301 ndarray::Array<typename std::remove_const<Pixel>::type, inN - 1, inN - 1> outputArray =
302 ndarray::allocate(outputShape);
303 outputArray.deep() = 0;
304 flatten(outputArray, input, xy0);
327 template <
typename PixelIn,
typename PixelOut,
int inA,
int outC,
int inC>
328 void flatten(ndarray::Array<PixelOut, inA - 1, outC>
const &output,
329 ndarray::Array<PixelIn, inA, inC>
const &input,
Point2I const &xy0 =
Point2I())
const {
330 auto ndAssigner = [](
Point2I const &point,
350 template <
typename Pixel,
int inA,
int inC>
351 ndarray::Array<typename std::remove_const<Pixel>::type, inA + 1, inA + 1>
unflatten(
352 ndarray::Array<Pixel, inA, inC>
const &input)
const {
356 auto existingShape = input.getShape();
357 typename decltype(existingShape)::Element height = _bbox.
getHeight();
358 typename decltype(existingShape)::Element width = _bbox.
getWidth();
359 auto outputShape = ndarray::concatenate(ndarray::makeVector(height, width),
360 input.getShape().template last<inA - 1>());
361 ndarray::Array<typename std::remove_const<Pixel>::type, inA + 1, inA + 1> outputArray =
362 ndarray::allocate(outputShape);
363 outputArray.deep() = 0;
387 template <
typename PixelIn,
typename PixelOut,
int inA,
int outC,
int inC>
388 void unflatten(ndarray::Array<PixelOut, inA + 1, outC>
const &output,
389 ndarray::Array<PixelIn, inA, inC>
const &input,
Point2I const &xy0 =
Point2I())
const {
392 auto ndAssigner = [](
Point2I const &point,
405 template <
typename ImageT>
422 template <
typename ImageT,
typename MaskT,
typename VarT>
426 VarT
const &srcVar, ImageT &destPix, MaskT &destMask, VarT &destVar) {
448 template <
typename ImageT>
450 bool doClip =
false)
const;
497 template <
typename Functor,
typename... Args>
521 template <
typename T>
531 template <
typename T>
548 template <
typename T>
566 template <
typename T>
582 template <
typename T>
633 template <
typename T,
typename UnaryPredicate = details::AnyBitSetFunctor<T>>
636 std::vector<Span> tempVec;
637 std::size_t startValue{0};
638 bool started =
false;
639 auto const maskArray = mask.
getArray();
640 auto const minPoint = mask.
getBBox().getMin();
645 for (
size_t x = 0;
x < dimensions[1]; ++
x) {
648 if (comparator(maskArray[y][
x]) && !started) {
655 else if (started && !comparator(maskArray[y][x])) {
657 Span(y + minPoint.getY(), startValue + minPoint.getX(), x - 1 + minPoint.getX()));
665 if (started && x == dimensions[1] - 1) {
667 Span(y + minPoint.getY(), startValue + minPoint.getX(), x + minPoint.getX()));
673 return std::make_shared<SpanSet>(std::move(tempVec));
685 template <
typename T>
687 return fromMask(mask, [bitmask](T
const &bitPattern) {
return bitPattern & bitmask; });
692 std::vector<std::shared_ptr<geom::SpanSet>>
split()
const;
705 std::string getPersistenceName()
const override;
709 inline std::string getPythonModule()
const override {
return "lsst.afw.geom"; }
721 void _runNormalize();
730 void _label(
geom::Span const &spn, std::vector<std::size_t> &labelVector, std::size_t currentLabel)
const;
731 std::pair<std::vector<std::size_t>, std::size_t> _makeLabels()
const;
733 std::shared_ptr<SpanSet> makeShift(
int x,
int y)
const;
735 template <
typename F,
typename... T>
736 void applyFunctorImpl(F &&f, T... args)
const {
743 for (
auto const &spn : _spanVector) {
746 for (
int x = spn.getX0();
x <= spn.getX1(); ++
x) {
748 f(point, args.get()...);
755 std::vector<Span> _spanVector;
767 #endif // LSST_AFW_GEOM_SPANSET_H
An ellipse core with quadrupole moments as parameters.
afw::table::PointKey< int > dimensions
std::shared_ptr< geom::SpanSet > findEdgePixels() const
Select pixels within the SpanSet which touch its edge.
void variadicSpanSetter(Span const spn, T &x)
const_iterator cend() const
std::shared_ptr< SpanSet > shiftedBy(int x, int y) const
Return a new SpanSet shifted by specified amount.
Stencil
An enumeration class which describes the shapes.
const_iterator end() const
static std::shared_ptr< geom::SpanSet > fromShape(int r, Stencil s=Stencil::CIRCLE, Point2I offset=Point2I())
Factory function for creating SpanSets from a Stencil.
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
void clearMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Unset a Mask at pixels defined by the SpanSet.
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
Create a SpanSet from a mask.
A compact representation of a collection of pixels.
A range of pixels within one row of an Image.
void setImage(image::Image< ImageT > &image, ImageT val, geom::Box2I const ®ion=geom::Box2I(), bool doClip=false) const
Set the values of an Image at points defined by the SpanSet.
void flatten(ndarray::Array< PixelOut, inA-1, outC > const &output, ndarray::Array< PixelIn, inA, inC > const &input, Point2I const &xy0=Point2I()) const
Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.
typename ndarray::Array< T, N, C >::Reference::Reference Reference
typename ndarray::Array< T, inA, inC >::Reference Reference
geom::Box2I getBBox(ImageOrigin origin=PARENT) const
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
bool contains(SpanSet const &other) const
Check if a SpanSet instance entirely contains another SpanSet.
bool overlaps(SpanSet const &other) const
Specifies if this SpanSet overlaps with another SpanSet.
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...
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, T bitmask)
Create a SpanSet from a mask.
std::shared_ptr< SpanSet > clippedTo(Box2I const &box) const
Return a new SpanSet which has all pixel values inside specified box.
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.
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
std::shared_ptr< SpanSet > eroded(int r, Stencil s=Stencil::CIRCLE) const
Perform a set erosion, and return a new object.
void applyFunctor(Functor &&func, Args &&...args) const
Apply functor on individual elements from the supplied parameters.
An integer coordinate rectangle.
A base class for objects that can be persisted via afw::table::io Archive classes.
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...
value_type const & const_reference
size_type getArea() const
Return the number of pixels in the SpanSet.
bool operator==(SpanSet const &other) const
Compute equality between two SpanSets.
const_iterator begin() const
bool operator!=(SpanSet const &other) const
Represent a 2-dimensional array of bitmask pixels.
friend class SpansSetFactory
An ellipse defined by an arbitrary BaseCore and a center point.
geom::Box2I const & _bbox
Box2I getBBox() const
Return a new integer box which is the minimum size to contain the pixels.
A class to manipulate images, masks, and variance as a single object.
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.
const_reference back() const
FlatNdGetter< T, inA, inC > makeGetter(FlatNdGetter< T, inA, inC > &getter)
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 ...
SpanSet(iter begin, iter end, bool normalize=true)
Construct a SpanSet from an iterator.
ndarray::Array< typename std::remove_const< Pixel >::type, inN-1, inN-1 > flatten(ndarray::Array< Pixel, inN, inC > const &input, Point2I const &xy0=Point2I()) const
Reduce the pixel dimensionality from 2 to 1 of an array at points given by SpanSet.
void variadicBoundChecker(Box2I const box, int area, T const &x)
const_iterator cbegin() const
std::shared_ptr< SpanSet > intersect(SpanSet const &other) const
Determine the common points between two SpanSets, and create a new SpanSet.
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 > union_(SpanSet const &other) const
Create a new SpanSet that contains all points from two SpanSets.
void unflatten(ndarray::Array< PixelOut, inA+1, outC > const &output, ndarray::Array< PixelIn, inA, inC > const &input, Point2I const &xy0=Point2I()) const
Expand an array by one spatial dimension at points given by SpanSet.
ellipses::Quadrupole computeShape() const
Compute the shape parameters for the distribution of points in the SpanSet.
SpanSet()
Default constructor.
bool operator()(T pixelValue)
std::vector< Span >::const_iterator const_iterator
void variadicIncrementPosition(T &x)
std::vector< Span >::size_type size_type
bool isPersistable() const override
Return true if this particular object can be persisted using afw::table::io.
void setMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Set a Mask at pixels defined by the SpanSet.
const_reference front() const
io::OutputArchiveHandle OutputArchiveHandle
std::shared_ptr< SpanSet > dilated(int r, Stencil s=Stencil::CIRCLE) const
Perform a set dilation operation, and return a new object.
bool isContiguous() const
Defines if the SpanSet is simply contiguous.
Point2D computeCentroid() const
Compute the point about which the SpanSet's first moment is zero.
Abstract base class for function objects.
std::shared_ptr< SpanSet > transformedBy(LinearTransform const &t) const
Return a new SpanSet who's pixels are the product of applying the specified transformation.
A CRTP facade class for subclasses of Persistable.
A class to represent a 2-dimensional array of pixels.
std::vector< std::shared_ptr< geom::SpanSet > > split() const
Split a discontinuous SpanSet into multiple SpanSets which are contiguous.