farm-ng-core
sophus::MutImageView< TPixel > Class Template Reference

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

#include <mut_image_view.h>

Inheritance diagram for sophus::MutImageView< TPixel >:
Collaboration diagram for sophus::MutImageView< TPixel >:

Public Member Functions

 MutImageView ()=default
 Default constructor creates an empty image. More...
 
 MutImageView (ImageLayout layout, TPixel *ptr) noexcept
 Creates view from layout and pointer to first pixel. More...
 
 MutImageView (sophus::ImageSize image_size, TPixel *ptr) noexcept
 Creates view from image size and pointer to first pixel. The image is assumed to be contiguous and the pitch is set accordingly. More...
 
auto view () const -> ImageView< TPixel >
 Returns ImageView(*this). More...
 
void copyDataFrom (ImageView< TPixel > view) const
 Copies data from view into this. More...
 
auto rowPtrMut (int v) const -> TPixel *
 Returns v-th row pointer of mutable pixel. More...
 
auto mut (int u, int v) const -> TPixel &
 Mutable accessor to pixel u, v. More...
 
auto mut (Eigen::Vector2i uv) const -> TPixel &
 
template<class TUnaryOperation >
void mutate (TUnaryOperation const &unary_op) const
 Mutates each pixel of this with given unary operation. More...
 
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) More...
 
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. More...
 
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. More...
 
void fill (TPixel const &val) const
 Populates every pixel of this with val. More...
 
auto ptrMut () const -> TPixel *
 Returns pointer of mutable data to first pixel. More...
 
auto mutSubview (Eigen::Vector2i uv, sophus::ImageSize size) const -> MutImageView
 Returns mutable subview. More...
 
- Public Member Functions inherited from sophus::ImageView< TPixel >
 ImageView ()=default
 Default constructor creates an empty image. More...
 
 ImageView (ImageLayout layout, TPixel const *ptr) noexcept
 Creates view from layout and pointer to first pixel. More...
 
 ImageView (sophus::ImageSize image_size, TPixel const *ptr) noexcept
 Creates view from image size and pointer to first pixel. The image is assumed to be contiguous and the pitch is set accordingly. More...
 
auto isEmpty () const -> bool
 Returns true if view is empty. More...
 
auto isContiguous () const -> bool
 Returns true if view is contiguous. More...
 
auto imageSize () const -> sophus::ImageSize const &
 Returns ImageSize. It is {0,0} if view is empty. More...
 
auto layout () const -> ImageLayout const &
 Returns ImageLayout. It is {{0,0}, 0} is view is empty. More...
 
auto area () const -> size_t
 
auto width () const -> int
 
auto height () const -> int
 
auto pitchBytes () const -> size_t
 
auto sizeBytes () const -> size_t
 
auto colInBounds (int u) const -> bool
 Returns true if u is in [0, width). More...
 
auto rowInBounds (int v) const -> bool
 Returns true if v is in [0, height). More...
 
auto rowPtr (int v) const -> TPixel const *
 Returns v-th row pointer. More...
 
auto operator() (int u, int v) const -> TPixel const &
 Returns pixel u, v. More...
 
auto operator() (Eigen::Vector2i uv) const -> TPixel const &
 
auto ptr () const -> TPixel const *
 Returns pointer to first pixel. More...
 
auto subview (Eigen::Vector2i uv, sophus::ImageSize size) const -> ImageView
 Returns subview. More...
 
template<class TFunc >
void visit (TFunc const &user_function) const
 Performs reduction / fold on image view. More...
 
template<class TReduceOp , class TVal >
auto reduce (TReduceOp const &reduce_op, TVal val=TVal{}) const -> TVal
 Performs reduction / fold on image view. More...
 
template<class TShortCircuitReduceOp , class TVal >
auto shortCircuitReduce (TShortCircuitReduceOp const &short_circuit_reduce_op, TVal val=TVal{}) const -> TVal
 Performs reduction / fold on image view with short circuit condition. More...
 
auto operator== (ImageView const &rhs) const -> bool=delete
 The equality operator is deleted to avoid confusion. Since ImageView is a "shallow-copy" type, a consistently defined equality would check for equality of its (shallow) state: More...
 
auto operator!= (ImageView const &rhs) const -> bool=delete
 The in-equality operator is deleted to avoid confusion. More...
 
auto hasSameData (ImageView const &rhs) const -> bool
 Returns true both views have the same size and contain the same data. More...
 

Static Public Member Functions

static auto unsafeConstCast (ImageView< TPixel > view) -> MutImageView
 Creates mutable view from view. More...
 

Additional Inherited Members

- Public Types inherited from sophus::ImageView< TPixel >
using Pixel = TPixel
 
- Protected Member Functions inherited from sophus::ImageView< TPixel >
void setViewToEmpty ()
 Resets view such that it is empty. More...
 
- Protected Attributes inherited from sophus::ImageView< TPixel >
ImageLayout layout_ = {}
 
TPixel const * ptr_ = nullptr
 

Detailed Description

template<class TPixel>
class sophus::MutImageView< TPixel >

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 layout 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& mut(int u, int v) const

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

Constructor & Destructor Documentation

◆ MutImageView() [1/3]

template<class TPixel >
sophus::MutImageView< TPixel >::MutImageView ( )
default

Default constructor creates an empty image.

◆ MutImageView() [2/3]

template<class TPixel >
sophus::MutImageView< TPixel >::MutImageView ( ImageLayout  layout,
TPixel *  ptr 
)
inlinenoexcept

Creates view from layout and pointer to first pixel.

◆ MutImageView() [3/3]

template<class TPixel >
sophus::MutImageView< TPixel >::MutImageView ( sophus::ImageSize  image_size,
TPixel *  ptr 
)
inlinenoexcept

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

Member Function Documentation

◆ copyDataFrom()

template<class TPixel >
void sophus::MutImageView< TPixel >::copyDataFrom ( ImageView< TPixel >  view) const
inline

Copies data from view into this.

Preconditions:

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

No-op if view is empty.

◆ fill()

template<class TPixel >
void sophus::MutImageView< TPixel >::fill ( TPixel const &  val) const
inline

Populates every pixel of this with val.

Preconditions: this must not be empty.

◆ generate()

template<class TPixel >
template<class TUVOperation >
void sophus::MutImageView< TPixel >::generate ( TUVOperation const &  uv_op) const
inline

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.

◆ mut() [1/2]

template<class TPixel >
auto sophus::MutImageView< TPixel >::mut ( Eigen::Vector2i  uv) const -> TPixel&
inline

◆ mut() [2/2]

template<class TPixel >
auto sophus::MutImageView< TPixel >::mut ( int  u,
int  v 
) const -> TPixel&
inline

Mutable accessor to pixel u, v.

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

◆ mutate()

template<class TPixel >
template<class TUnaryOperation >
void sophus::MutImageView< TPixel >::mutate ( TUnaryOperation const &  unary_op) const
inline

Mutates each pixel of this with given unary operation.

Preconditions: this must not be empty.

◆ mutSubview()

template<class TPixel >
auto sophus::MutImageView< TPixel >::mutSubview ( Eigen::Vector2i  uv,
sophus::ImageSize  size 
) const -> MutImageView
inline

Returns mutable subview.

◆ ptrMut()

template<class TPixel >
auto sophus::MutImageView< TPixel >::ptrMut ( ) const -> TPixel*
inline

Returns pointer of mutable data to first pixel.

◆ rowPtrMut()

template<class TPixel >
auto sophus::MutImageView< TPixel >::rowPtrMut ( int  v) const -> TPixel*
inline

Returns v-th row pointer of mutable pixel.

◆ transformFrom() [1/2]

template<class TPixel >
template<class TLhsPixel , class TRhsPixel , class TBinaryOperation >
void sophus::MutImageView< TPixel >::transformFrom ( ImageView< TLhsPixel >  lhs,
ImageView< TRhsPixel >  rhs,
TBinaryOperation const &  binary_op 
) const
inline

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

Preconditions:

  • this must not be empty.
  • this->imageSize() == lhs.imageSize() == rhs.imageSize()

◆ transformFrom() [2/2]

template<class TPixel >
template<class TOtherPixel , class TUnaryOperation >
void sophus::MutImageView< TPixel >::transformFrom ( ImageView< TOtherPixel >  view,
TUnaryOperation const &  unary_op 
) const
inline

Transforms view using unary operation and assigns result to this.

Preconditions:

  • this must not be empty.
  • this->imageSize() == view.imageSize()

◆ unsafeConstCast()

template<class TPixel >
static auto sophus::MutImageView< TPixel >::unsafeConstCast ( ImageView< TPixel >  view) -> MutImageView
inlinestatic

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.

◆ view()

template<class TPixel >
auto sophus::MutImageView< TPixel >::view ( ) const -> ImageView<TPixel>
inline

Returns ImageView(*this).

Returns non-mut version of view.


The documentation for this class was generated from the following file: