farm-ng-core
sophus::ImageView< TPixel > Struct Template Reference

A view of an (immutable) image, which does not own the data. More...

#include <image_view.h>

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

Public Types

using Pixel = TPixel
 

Public Member Functions

 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...
 

Protected Member Functions

void setViewToEmpty ()
 Resets view such that it is empty. More...
 

Protected Attributes

ImageLayout layout_ = {}
 
TPixel const * ptr_ = nullptr
 

Friends

template<class TT , class TAllocator >
class MutImage
 
template<class TT , class TAllocator >
class Image
 

Detailed Description

template<class TPixel>
struct sophus::ImageView< TPixel >

A view of an (immutable) image, which does not own the data.

The API of ImageView allows for read-only access. There is an escape hook for write access, see MutImageView::unsafeConstCast below.

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

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

ImageView is a "shallow-compare type" similar to std::span<Pixel const> and std::unique_ptr<Pixel const>. In particular, we define that the state of an ImageView instance consists of the layout of the image layout_ (see ImageLayout) and the pointer address to the first pixel ptr_. No public member method can change the pointer nor the layout, hence they are all marked const.

Member Typedef Documentation

◆ Pixel

template<class TPixel >
using sophus::ImageView< TPixel >::Pixel = TPixel

Constructor & Destructor Documentation

◆ ImageView() [1/3]

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

Default constructor creates an empty image.

◆ ImageView() [2/3]

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

Creates view from layout and pointer to first pixel.

◆ ImageView() [3/3]

template<class TPixel >
sophus::ImageView< TPixel >::ImageView ( sophus::ImageSize  image_size,
TPixel const *  ptr 
)
inlineexplicitnoexcept

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

◆ area()

template<class TPixel >
auto sophus::ImageView< TPixel >::area ( ) const -> size_t
inline

◆ colInBounds()

template<class TPixel >
auto sophus::ImageView< TPixel >::colInBounds ( int  u) const -> bool
inline

Returns true if u is in [0, width).

◆ hasSameData()

template<class TPixel >
auto sophus::ImageView< TPixel >::hasSameData ( ImageView< TPixel > const &  rhs) const -> bool
inline

Returns true both views have the same size and contain the same data.

◆ height()

template<class TPixel >
auto sophus::ImageView< TPixel >::height ( ) const -> int
inline

◆ imageSize()

template<class TPixel >
auto sophus::ImageView< TPixel >::imageSize ( ) const -> sophus::ImageSize const&
inline

Returns ImageSize. It is {0,0} if view is empty.

◆ isContiguous()

template<class TPixel >
auto sophus::ImageView< TPixel >::isContiguous ( ) const -> bool
inline

Returns true if view is contiguous.

◆ isEmpty()

template<class TPixel >
auto sophus::ImageView< TPixel >::isEmpty ( ) const -> bool
inline

Returns true if view is empty.

◆ layout()

template<class TPixel >
auto sophus::ImageView< TPixel >::layout ( ) const -> ImageLayout const&
inline

Returns ImageLayout. It is {{0,0}, 0} is view is empty.

◆ operator!=()

template<class TPixel >
auto sophus::ImageView< TPixel >::operator!= ( ImageView< TPixel > const &  rhs) const -> bool=delete
delete

The in-equality operator is deleted to avoid confusion.

◆ operator()() [1/2]

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

◆ operator()() [2/2]

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

Returns pixel u, v.

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

Note:

  • No panic if u.v is invalid,

This is not the most necessarily the efficient function to call - e.g. when iterating over the whole image. Use the following instead:

for (int v=0; v<view.layout().height(); ++v) { TPixel const* row = img.rowPtr(v); for (int u=0; u<view.layout().width(); ++u) { PixetT p = row[u]; } }

◆ operator==()

template<class TPixel >
auto sophus::ImageView< TPixel >::operator== ( ImageView< TPixel > const &  rhs) const -> bool=delete
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:

this->layout_ == rhs.layout() && this->ptr_ == rhs.ptr_`

However, some users might expect that equality would check for pixel values equality and return true for identical copies of data blocks.

Here we follow std::span which also does not offer equality comparisons.

◆ pitchBytes()

template<class TPixel >
auto sophus::ImageView< TPixel >::pitchBytes ( ) const -> size_t
inline

◆ ptr()

template<class TPixel >
auto sophus::ImageView< TPixel >::ptr ( ) const -> TPixel const*
inline

Returns pointer to first pixel.

◆ reduce()

template<class TPixel >
template<class TReduceOp , class TVal >
auto sophus::ImageView< TPixel >::reduce ( TReduceOp const &  reduce_op,
TVal  val = TVal{} 
) const -> TVal
inline

Performs reduction / fold on image view.

◆ rowInBounds()

template<class TPixel >
auto sophus::ImageView< TPixel >::rowInBounds ( int  v) const -> bool
inline

Returns true if v is in [0, height).

◆ rowPtr()

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

Returns v-th row pointer.

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

◆ setViewToEmpty()

template<class TPixel >
void sophus::ImageView< TPixel >::setViewToEmpty ( )
inlineprotected

Resets view such that it is empty.

◆ shortCircuitReduce()

template<class TPixel >
template<class TShortCircuitReduceOp , class TVal >
auto sophus::ImageView< TPixel >::shortCircuitReduce ( TShortCircuitReduceOp const &  short_circuit_reduce_op,
TVal  val = TVal{} 
) const -> TVal
inline

Performs reduction / fold on image view with short circuit condition.

◆ sizeBytes()

template<class TPixel >
auto sophus::ImageView< TPixel >::sizeBytes ( ) const -> size_t
inline

◆ subview()

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

Returns subview.

◆ visit()

template<class TPixel >
template<class TFunc >
void sophus::ImageView< TPixel >::visit ( TFunc const &  user_function) const
inline

Performs reduction / fold on image view.

◆ width()

template<class TPixel >
auto sophus::ImageView< TPixel >::width ( ) const -> int
inline

Friends And Related Function Documentation

◆ Image

template<class TPixel >
template<class TT , class TAllocator >
friend class Image
friend

◆ MutImage

template<class TPixel >
template<class TT , class TAllocator >
friend class MutImage
friend

Member Data Documentation

◆ layout_

template<class TPixel >
ImageLayout sophus::ImageView< TPixel >::layout_ = {}
protected

◆ ptr_

template<class TPixel >
TPixel const* sophus::ImageView< TPixel >::ptr_ = nullptr
protected

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