25 #ifndef LSST_AFW_GEOM_SPANSET_H
26 #define LSST_AFW_GEOM_SPANSET_H
95 bool empty()
const {
return _spanVector.empty(); }
122 template <
typename iter>
125 if (_spanVector.size() == 0) {
302 template <
typename Pixel,
int inN,
int inC>
304 ndarray::Array<Pixel, inN, inC>
const &input,
307 auto outputShape = ndarray::concatenate(ndarray::makeVector(
getArea()),
308 input.getShape().template last<inN - 2>());
310 ndarray::allocate(outputShape);
311 outputArray.deep() = 0;
312 flatten(outputArray, input, xy0);
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,
359 template <
typename Pixel,
int inA,
int inC>
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>());
371 ndarray::allocate(outputShape);
372 outputArray.deep() = 0;
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,
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) {
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>
643 template <
typename T,
typename UnaryPredicate = details::AnyBitSetFunctor<T>>
650 auto const maskArray =
mask.getArray();
651 auto const minPoint =
mask.getBBox().getMin();
653 auto const minY = minPoint.getY();
654 auto const minX = minPoint.getX();
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]);
672 }
else if (compareValue) {
682 tempVec.
push_back(
Span(yWithOffset, start + minX, dimMinusOne + minX));
688 return std::make_shared<SpanSet>(
std::move(tempVec),
false);
700 template <
typename T>
702 return fromMask(
mask, [bitmask](
T const &bitPattern) {
return bitPattern & bitmask; });
724 inline std::string getPythonModule()
const override {
return "lsst.afw.geom"; }
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()...);
Key< Flag > const & target
afw::table::PointKey< int > dimensions
std::shared_ptr< RecordT > src
A range of pixels within one row of an Image.
A compact representation of a collection of pixels.
bool isContiguous() const
Defines if the SpanSet is simply contiguous.
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.
std::shared_ptr< SpanSet > shiftedBy(int x, int y) const
Return a new SpanSet shifted by specified amount.
SpanSet & operator=(SpanSet const &)=default
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.
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.
void setImage(image::Image< ImageT > &image, ImageT val, lsst::geom::Box2I const ®ion=lsst::geom::Box2I(), bool doClip=false) const
Set the values of an Image at points defined by the SpanSet.
std::shared_ptr< SpanSet > union_(SpanSet const &other) const
Create a new SpanSet that contains all points from two SpanSets.
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.
std::shared_ptr< SpanSet > clippedTo(lsst::geom::Box2I const &box) const
Return a new SpanSet which has all pixel values inside specified box.
SpanSet & operator=(SpanSet &&other)
const_iterator end() const
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.
friend class SpansSetFactory
std::shared_ptr< SpanSet > intersect(SpanSet const &other) const
Determine the common points between two SpanSets, and create a new SpanSet.
~SpanSet() override=default
void applyFunctor(Functor &&func, Args &&... args) const
Apply functor on individual elements from the supplied parameters.
std::shared_ptr< SpanSet > eroded(int r, Stencil s=Stencil::CIRCLE) const
Perform a set erosion, and return a new object.
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, T bitmask)
Create a SpanSet from a mask.
lsst::geom::Box2I getBBox() const
Return a new integer box which is the minimum size to contain the pixels.
std::shared_ptr< SpanSet > dilated(int r, Stencil s=Stencil::CIRCLE) const
Perform a set dilation operation, and return a new object.
const_reference front() const
void setMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Set a Mask at pixels defined by the SpanSet.
std::vector< std::shared_ptr< geom::SpanSet > > split() const
Split a discontinuous SpanSet into multiple SpanSets which are contiguous.
std::vector< Span >::size_type size_type
SpanSet(SpanSet &&other)=delete
const_iterator cbegin() const
bool overlaps(SpanSet const &other) const
Specifies if this SpanSet overlaps with another SpanSet.
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
bool operator!=(SpanSet const &other) const
SpanSet(SpanSet const &other)=delete
void clearMask(lsst::afw::image::Mask< T > &target, T bitmask) const
Unset a Mask at pixels defined by the SpanSet.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
std::vector< Span >::const_iterator const_iterator
const_iterator cend() const
lsst::geom::Point2D computeCentroid() const
Compute the point about which the SpanSet's first moment is zero.
bool contains(SpanSet const &other) const
Check if a SpanSet instance entirely contains another SpanSet.
std::shared_ptr< geom::SpanSet > findEdgePixels() const
Select pixels within the SpanSet which touch its edge.
ellipses::Quadrupole computeShape() const
Compute the shape parameters for the distribution of points in the SpanSet.
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.
bool operator==(SpanSet const &other) const
Compute equality between two SpanSets.
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 ...
const_reference back() const
static std::shared_ptr< geom::SpanSet > fromMask(image::Mask< T > const &mask, UnaryPredicate comparator=details::AnyBitSetFunctor< T >())
Create a SpanSet from a mask.
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 defined by an arbitrary BaseCore and a center point.
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.
io::OutputArchiveHandle OutputArchiveHandle
An integer coordinate rectangle.
int getMinY() const noexcept
int getHeight() const noexcept
int getMinX() const noexcept
int getWidth() const noexcept
void variadicSpanSetter(Span const spn, T &x)
FlatNdGetter< T, inA, inC > makeGetter(FlatNdGetter< T, inA, inC > &getter)
void variadicIncrementPosition(T &x)
void variadicBoundChecker(lsst::geom::Box2I const box, int area, T const &x)
Stencil
An enumeration class which describes the shapes.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
A base class for image defects.
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.
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.