25 #ifndef LSST_AFW_GEOM_SPANSET_H 26 #define LSST_AFW_GEOM_SPANSET_H 55 bool operator()(T pixelValue) {
return pixelValue != 0; }
88 const_iterator
begin()
const {
return _spanVector.cbegin(); }
89 const_iterator
end()
const {
return _spanVector.cend(); }
90 const_iterator
cbegin()
const {
return _spanVector.cbegin(); }
91 const_iterator
cend()
const {
return _spanVector.cend(); }
92 const_reference
front()
const {
return const_cast<geom::Span &
>(_spanVector.front()); }
93 const_reference
back()
const {
return const_cast<geom::Span &
>(_spanVector.back()); }
94 size_type
size()
const {
return _spanVector.size(); }
95 bool empty()
const {
return _spanVector.empty(); }
122 template <
typename iter>
123 SpanSet(iter begin, iter
end,
bool normalize =
true) : _spanVector(begin, end) {
125 if (_spanVector.size() == 0) {
174 size_type getArea()
const;
187 bool isContiguous()
const;
230 bool overlaps(
SpanSet const &other)
const;
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>
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) {
420 applyFunctor(copyFunc, src, dest);
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>
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();
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]);
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));
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"; }
732 friend class SpansSetFactory;
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()...);
783 #endif // LSST_AFW_GEOM_SPANSET_H An ellipse core with quadrupole moments as parameters.
VariancePtr getVariance() const
Return a (shared_ptr to) the MaskedImage's variance.
afw::table::PointKey< int > dimensions
void variadicSpanSetter(Span const spn, T &x)
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.
Stencil
An enumeration class which describes the shapes.
bool contains(VertexIterator const begin, VertexIterator const end, UnitVector3d const &v)
const_iterator end() const
An object passed to Persistable::write to allow it to persist itself.
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 applyFunctor(Functor &&func, Args &&... args) const
Apply functor on individual elements from the supplied parameters.
typename ndarray::Array< T, N, C >::Reference::Reference Reference
const_iterator cbegin() const
typename ndarray::Array< T, inA, inC >::Reference Reference
const_iterator begin() const
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.
ImagePtr getImage() const
Return a (shared_ptr to) the MaskedImage's image.
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...
Point2I const getMin() const noexcept
value_type const & const_reference
const_iterator cend() const
A base class for image defects.
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
Represent a 2-dimensional array of bitmask pixels.
An ellipse defined by an arbitrary BaseCore and a center point.
A class to manipulate images, masks, and variance as a single object.
void variadicBoundChecker(lsst::geom::Box2I const box, int area, T const &x)
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.
FlatNdGetter< T, inA, inC > makeGetter(FlatNdGetter< T, inA, inC > &getter)
const_reference front() const
Key< Flag > const & target
SpanSet(iter begin, iter end, bool normalize=true)
Construct a SpanSet from an iterator.
std::shared_ptr< RecordT > src
SpanSet & operator=(SpanSet &&other)
MaskPtr getMask() const
Return a (shared_ptr to) the MaskedImage's mask.
bool isPersistable() const noexcept override
Return true if this particular object can be persisted using afw::table::io.
bool operator()(T pixelValue)
std::vector< Span >::const_iterator const_iterator
void variadicIncrementPosition(T &x)
std::vector< Span >::size_type size_type
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.
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.
const_reference back() const
ItemVariant const * other
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...
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.
A CRTP facade class for subclasses of Persistable.
An integer coordinate rectangle.
A class to represent a 2-dimensional array of pixels.
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.