template class sophus::MutImage

Overview

A image with write access to pixels and exclusive ownership. There is no copy constr / copy assignment, but move constr / assignment. More…

#include <image.h>

template <
    class TPixel,
    template<class> class TAllocator = Eigen::aligned_allocator
    >
class MutImage: public sophus::MutImageView {
public:
    // structs

    struct Deleter;
    struct TypedDeleterImpl;

    // construction

    MutImage();
    MutImage(ImageShape shape);
    MutImage(sophus::ImageSize size);
    MutImage(MutImage<TPixel> const& other);
    MutImage(MutImage&& img);

    // methods

    MutImage& operator=(MutImage const&);
    MutImage& operator=(MutImage&& img);
    MutImageView<TPixel> viewMut() const;
    void swap(MutImage& img);
    void reset();
    static MutImage makeCopyFrom(ImageView<TPixel> const& view);

    template <class TOtherPixel, class TUnaryOperation>
    static MutImage makeFromTransform(
        ImageView<TOtherPixel> view,
        TUnaryOperation const& unary_op
        );

    template <class TLhsPixel, class TRhsPixel, class TBinaryOperation>
    static MutImage makeFromTransform(
        ImageView<TLhsPixel> lhs,
        ImageView<TRhsPixel> rhs,
        TBinaryOperation const& binary_op
        );

protected:
    // fields

    std::shared_ptr<uint8_t> shared_;

    // methods

    Deleter leakAndReturnDeleter();
};

Inherited Members

public:
    // typedefs

    using PixelType = TPixel ;

    // methods

    bool isEmpty() const;
    bool isContiguous() const;
    sophus::ImageSize const& imageSize() const;
    ImageShape const& shape() const;
    int width() const;
    int height() const;
    size_t pitchBytes() const;
    bool colInBounds(int u) const;
    bool rowInBounds(int v) const;
    TPixel const* rowPtr(int v) const;
    TPixel const& checked(int u, int v) const;
    TPixel const& checked(Eigen::Vector2i uv) const;
    TPixel const& unchecked(int u, int v) const;
    TPixel const& unchecked(Eigen::Vector2i uv) const;
    TPixel const* ptr() const;
    ImageView subview(Eigen::Vector2i uv, sophus::ImageSize size) const;

    template <class TFunc>
    void visit(TFunc const& user_function) const;

    template <class TReduceOp, class TVal>
    TVal reduce(
        TReduceOp const& reduce_op,
        TVal val = TVal{}
        ) const;

    template <class TShortCircuitReduceOp, class TVal>
    TVal shortCircuitReduce(
        TShortCircuitReduceOp const& short_circuit_reduce_op,
        TVal val = TVal{}
        ) const;

    bool operator==(ImageView const& rhs) const;
    bool operator!=(ImageView const& rhs) const;
    bool hasSameData(ImageView const& rhs) const;
    ImageView<TPixel> view() const;
    void copyDataFrom(ImageView<TPixel> view) const;
    TPixel* rowPtrMut(int v) const;
    TPixel& checkedMut(int u, int v) const;
    TPixel& checkedMut(Eigen::Vector2i uv) const;
    TPixel& uncheckedMut(int u, int v) const;
    TPixel& uncheckedMut(Eigen::Vector2i uv) const;

    template <class TUnaryOperation>
    void mutate(TUnaryOperation const& unary_op) const;

    template <class TUVOperation>
    void generate(TUVOperation const& uv_op) const;

    template <class TOtherPixel, class TUnaryOperation>
    void transformFrom(
        ImageView<TOtherPixel> view,
        TUnaryOperation const& unary_op
        ) const;

    template <class TLhsPixel, class TRhsPixel, class TBinaryOperation>
    void transformFrom(
        ImageView<TLhsPixel> lhs,
        ImageView<TRhsPixel> rhs,
        TBinaryOperation const& binary_op
        ) const;

    void fill(TPixel const& val) const;
    TPixel* ptrMut() const;
    MutImageView mutSubview(Eigen::Vector2i uv, sophus::ImageSize size) const;
    static MutImageView unsafeConstCast(ImageView<TPixel> view);

protected:
    // fields

    ImageShape shape_ = {};
    TPixel const* ptr_ = nullptr;

    // methods

    void setViewToEmpty();

Detailed Documentation

A image with write access to pixels and exclusive ownership. There is no copy constr / copy assignment, but move constr / assignment.

Content from a MutImage can be moved into an Image.

Type is nullable. In that case this->isEmpty() is true.

Similar to Pangolin::ManagedImage.

Fields

std::shared_ptr<uint8_t> shared_

MutImage has unique ownership, and hence behaves like a unique_ptr. As an implementation detail, we use a shared_ptr here, so it will be easy to support moving a Image with unique ownership at runtime into a MutImage. Class invariant: shared_.use_count() == 0 || shared_.use_count() == 1.

Construction

MutImage()

Constructs empty image.

MutImage(ImageShape shape)

Creates new image with given shape.

If shape is not empty, memory allocation will happen.

MutImage(sophus::ImageSize size)

Creates new contiguous image with given size.

If shape is not empty, memory allocation will happen.

MutImage(MutImage<TPixel> const& other)

Not copy constructable.

MutImage(MutImage&& img)

Move constructor - is cheap - no memory allocations.

Methods

MutImage& operator=(MutImage const&)

Not copy assignable.

MutImage& operator=(MutImage&& img)

Move assignment.

void swap(MutImage& img)

Swaps img and this.

void reset()

Clears image.

If image was not empty, memory deallocations will happen.

static MutImage makeCopyFrom(ImageView<TPixel> const& view)

Creates contiguous copy from view.

If view is not empty, memory allocation will happen.

template <class TOtherPixel, class TUnaryOperation>
static MutImage makeFromTransform(
    ImageView<TOtherPixel> view,
    TUnaryOperation const& unary_op
    )

Creates new MutImage given view and unary transform function.

mut_image(u, v) = unary_op(view(u, v));

template <class TLhsPixel, class TRhsPixel, class TBinaryOperation>
static MutImage makeFromTransform(
    ImageView<TLhsPixel> lhs,
    ImageView<TRhsPixel> rhs,
    TBinaryOperation const& binary_op
    )

Creates new MutImage given two views and binary transform function.

mut_image(u, v) = binary_op(lhs(u, v), rhs(u, v));

Deleter leakAndReturnDeleter()

Leaks memory and returns deleter.