template class sophus::MutImageView

Overview

View of a mutable image, which does not own the data. More…

#include <image_view.h>

template <class TPixel>
class MutImageView: public sophus::ImageView {
public:
    // construction

    MutImageView();
    MutImageView(ImageShape shape, TPixel* ptr);
    MutImageView(sophus::ImageSize image_size, TPixel* ptr);

    // methods

    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);
};

// direct descendants

template <
    class TPixel,
    template<class> class TAllocator = Eigen::aligned_allocator
    >
class MutImage;

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;

protected:
    // fields

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

    // methods

    void setViewToEmpty();

Detailed Documentation

View of a mutable image, which does not own the data.

The API of MutImageView allows for read and write access.

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

Details on equality comparison, the state of the object, and const-correctness.

MutImageView is a “shallow-compare type” similar to std::span<Pixel> and std::unique_ptr<Pixel>. As ImageView, its state consists of the image shape as well as the pointer address, and comparing those entities establishes equality comparisons. Furthermore, giving mutable access to pixels is considered a const operation, as in

TPixel& checkedMut(int u, int v) const

since this merely allows for changing a pixel value, but not its state (data location and layout).

Construction

MutImageView()

Default constructor creates an empty image.

MutImageView(ImageShape shape, TPixel* ptr)

Creates view from shape and pointer to first pixel.

MutImageView(sophus::ImageSize image_size, TPixel* ptr)

Creates view from image size and pointer to first pixel. The image is assumed to be contiguous and the pitch is set accordingly.

Methods

ImageView<TPixel> view() const

Returns ImageView(*this).

Returns non-mut version of view.

void copyDataFrom(ImageView<TPixel> view) const

Copies data from view into this.

Preconditions:

  • this-> isEmpty() == view.isEmpty()

  • this->size() == view.size()

No-op if view is empty.

TPixel* rowPtrMut(int v) const

Returns v-th row pointer of mutable pixel.

TPixel& checkedMut(int u, int v) const

Mutable accessor to pixel u, v.

Precondition: u must be in [0, width) and v must be in [0, height).

Note:

  • panics if u,v is invalid.

TPixel& uncheckedMut(int u, int v) const

Mutable accessor to pixel u, v.

Precondition: u must be in [0, width) and v must be in [0, height). Silent UB on failure.

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

Mutates each pixel of this with given unary operation.

Preconditions: this must not be empty.

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

For each pixel in this with coordinates (u,v), populates with the user provided function, evaluated as uv_op(u,v), where u and v are integers such that u in [0, width), v in [0, height)

Preconditions: this must not be empty.

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

Transforms view using unary operation and assigns result to this.

Preconditions:

  • this must not be empty.

  • this-> imageSize() == view.imageSize()

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

Transforms two views using binary operation and assigns result to this.

Preconditions:

  • this must not be empty.

  • this-> imageSize() == lhs.imageSize() == rhs.imageSize()

void fill(TPixel const& val) const

Populates every pixel of this with val.

Preconditions: this must not be empty.

TPixel* ptrMut() const

Returns pointer of mutable data to first pixel.

MutImageView mutSubview(Eigen::Vector2i uv, sophus::ImageSize size) const

Returns mutable subview.

static MutImageView unsafeConstCast(ImageView<TPixel> view)

Creates mutable view from view.

It is the user’s responsibility to make sure that the data owned by the view can be modified safely.