25#ifndef LSST_AFW_GEOM_SPANSET_H
26#define LSST_AFW_GEOM_SPANSET_H
55 bool operator()(T pixelValue) {
return pixelValue != 0; }
95 bool empty()
const {
return _spanVector.empty(); }
122 template <
typename iter>
125 if (_spanVector.size() == 0) {
126 _bbox = lsst::geom::Box2I();
174 size_type getArea()
const;
187 bool isContiguous()
const;
230 bool overlaps(
SpanSet const &other)
const;
236 bool contains(
SpanSet const &other)
const;
302 template <
typename Pixel,
int inN,
int inC>
303 ndarray::Array<typename std::remove_const<Pixel>::type, inN - 1, inN - 1>
flatten(
304 ndarray::Array<Pixel, inN, inC>
const &input,
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);
303 ndarray::Array<typename std::remove_const<Pixel>::type, inN - 1, inN - 1>
flatten( {
…}
335 template <
typename PixelIn,
typename PixelOut,
int inA,
int outC,
int inC>
336 void flatten(ndarray::Array<PixelOut, inA - 1, outC>
const &output,
337 ndarray::Array<PixelIn, inA, inC>
const &input,
336 void flatten(ndarray::Array<PixelOut, inA - 1, outC>
const &output, {
…}
359 template <
typename Pixel,
int inA,
int inC>
360 ndarray::Array<typename std::remove_const<Pixel>::type, inA + 1, inA + 1>
unflatten(
361 ndarray::Array<Pixel, inA, inC>
const &input)
const {
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;
360 ndarray::Array<typename std::remove_const<Pixel>::type, inA + 1, inA + 1>
unflatten( {
…}
396 template <
typename PixelIn,
typename PixelOut,
int inA,
int outC,
int inC>
397 void unflatten(ndarray::Array<PixelOut, inA + 1, outC>
const &output,
398 ndarray::Array<PixelIn, inA, inC>
const &input,
397 void unflatten(ndarray::Array<PixelOut, inA + 1, outC>
const &output, {
…}
415 template <
typename ImageT>
417 auto copyFunc = [](
lsst::geom::Point2I const &point, ImageT
const &srcPix, ImageT &destPix) {
432 template <
typename ImageT,
typename MaskT,
typename VarT>
435 auto copyFunc = [](
lsst::geom::Point2I const &point, ImageT
const &srcPix, MaskT
const &srcMask,
436 VarT
const &srcVar, ImageT &destPix, MaskT &destMask, VarT &destVar) {
441 applyFunctor(copyFunc, *(src.getImage()), *(src.getMask()), *(src.getVariance()), *(dest.
getImage()),
458 template <
typename ImageT>
507 template <
typename Functor,
typename... Args>
531 template <
typename T>
541 template <
typename T>
558 template <
typename T>
576 template <
typename T>
592 template <
typename T>
601 bool operator==(
SpanSet const &other)
const;
607 bool operator!=(
SpanSet const &other)
const;
643 template <
typename T,
typename UnaryPredicate = details::AnyBitSetFunctor<T>>
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;
663 for (
size_t x = 0; x < xDim; ++x) {
664 bool compareValue = comparator((*arrIter)[x]);
669 tempVec.
push_back(
Span(yWithOffset, start + minX, x - 1 + minX));
672 }
else if (compareValue) {
682 tempVec.
push_back(
Span(yWithOffset, start + minX, dimMinusOne + minX));
700 template <
typename T>
702 return fromMask(mask, [bitmask](T
const &bitPattern) {
return bitPattern & bitmask; });
728 void write(OutputArchiveHandle &handle)
const override;
736 void _runNormalize();
751 template <
typename F,
typename... T>
752 void applyFunctorImpl(F &&f, T... args)
const {
759 for (
auto const &spn : _spanVector) {
762 for (
int x = spn.getX0(); x <= spn.getX1(); ++x) {
764 f(point, args.get()...);
A range of pixels within one row of an Image.
A compact representation of a collection of pixels.
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.
SpanSet()
Default constructor.
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
Create a SpanSet from a mask.
const_iterator end() const
friend class SpansSetFactory
~SpanSet() override=default
void applyFunctor(Functor &&func, Args &&... args) const
Apply functor on individual elements from the supplied parameters.
const_reference front() const
std::vector< Span >::size_type size_type
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.
SpanSet(SpanSet &&other)=delete
const_iterator cbegin() const
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, T bitmask)
Create a SpanSet from a mask.
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.
const_iterator begin() const
SpanSet(SpanSet const &other)=delete
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
SpanSet & operator=(SpanSet const &)=default
std::vector< Span >::const_iterator const_iterator
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.
const_iterator cend() const
SpanSet & operator=(SpanSet &&other)
const value_type & const_reference
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.
SpanSet(iter begin, iter end, bool normalize=true)
Construct a SpanSet from an iterator.
std::string getPythonModule() const override
Return the fully-qualified Python module that should be imported to guarantee that its factory is reg...
static std::shared_ptr< geom::SpanSet > fromShape(geom::ellipses::Ellipse const &ellipse)
Factory function for creating SpanSets from an ellipse object.
const_reference back() const
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.
size_type getArea() const
Return the number of pixels in the SpanSet.
bool operator()(T pixelValue)
typename ndarray::Array< T, inA, inC >::Reference Reference
typename ndarray::Array< T, N, C >::Reference::Reference Reference
An ellipse core with quadrupole moments as parameters.
A class to represent a 2-dimensional array of pixels.
Represent a 2-dimensional array of bitmask pixels.
A class to manipulate images, masks, and variance as a single object.
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.
A CRTP facade class for subclasses of Persistable.
A base class for objects that can be persisted via afw::table::io Archive classes.
An integer coordinate rectangle.
void variadicSpanSetter(Span const spn, T &x)
void variadicIncrementPosition(T &x)
void variadicBoundChecker(lsst::geom::Box2I const box, int area, T const &x)
FlatNdGetter< T, inA, inC > makeGetter(FlatNdGetter< T, inA, inC > &getter)
Transform< Point2Endpoint, Point2Endpoint > TransformPoint2ToPoint2
Stencil
An enumeration class which describes the shapes.
Point< double, 2 > Point2D
Extent< int, 2 > Extent2I
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.
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.