CVB++ 14.0
Block< T, ACCESSTRAIT > Class Template Referencefinal

Non-owning view on a 2d-plane of data. More...

#include <cvb/block.hpp>

Inherits BlockBase< ACCESSTRAIT >.

Classes

class  Column
 A single column. More...
 
class  Row
 A single row. More...
 

Public Member Functions

 Block (ACCESSTRAIT access, Cvb::Size2D< int > size)
 
 Block (const Block &other) noexcept=default
 Copy ctor. More...
 
Blockoperator= (const Block &other) noexcept=default
 Copy operator. More...
 
 ~Block ()=default
 Default dtor.
 
auto SubBlock (Cvb::Rect< int > aoi) const -> Block< T, decltype(this->Access().NewMoved(Cvb::Rect< int >{}))>
 Creates a new sub Block from this block. More...
 
CVB_FORCE_INLINE const PixelType & operator() (int x, int y) const noexcept
 Coordinate pixel access operator. More...
 
CVB_FORCE_INLINE PixelType & operator() (int x, int y) noexcept
 Coordinate pixel access operator. More...
 
template<class FromPixelType >
CVB_FORCE_INLINE auto Set (int x, int y, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
 Coordinate setter. More...
 
CVB_FORCE_INLINE void Set (int x, int y, const PixelType &value) noexcept
 Coordinate setter. More...
 
CVB_FORCE_INLINE const PixelType & operator[] (int idx) const noexcept
 Index pixel access operator. More...
 
CVB_FORCE_INLINE PixelType & operator[] (int idx) noexcept
 Coordinate pixel access operator. More...
 
template<class FromPixelType >
CVB_FORCE_INLINE auto Set (int idx, const FromPixelType &value) noexcept -> std::enable_if_t<!std::is_convertible< remove_cvref_t< FromPixelType >, remove_cvref_t< PixelType > >::value, void >
 Index setter. More...
 
CVB_FORCE_INLINE void Set (int idx, const PixelType &value) noexcept
 Index setter. More...
 
Row RowAt (int y) const noexcept
 Gets the Block::Row at y. More...
 
Column ColumnAt (int x) const noexcept
 Gets the Block::Column at x. More...
 
- Public Member Functions inherited from BlockBase< ACCESSTRAIT >
CVB_FORCE_INLINE const ACCESSTRAIT & Access () const noexcept
 Gets the pixel access. More...
 
CVB_FORCE_INLINE ACCESSTRAIT & Access () noexcept
 Gets the pixel access. More...
 
CVB_FORCE_INLINE size_t Length () const noexcept
 Gets the total number of pixels in this block. More...
 
CVB_FORCE_INLINE Size2D< int > Size () const noexcept
 Gets the size of this block. More...
 
CVB_FORCE_INLINE int Width () const noexcept
 Gets the width of this block. More...
 
CVB_FORCE_INLINE int Height () const noexcept
 Gets the height of this block. More...
 
bool Valid () const noexcept
 Gets whether this block is valid. More...
 

Static Public Attributes

static constexpr const bool IsPixelTypeMutable = true
 ! Indicates whether the returned values of operator(x,y) or operator[idx] are mutable.
 

Related Functions

(Note that these are not member functions.)

template<class T >
using ArrayPlaneBlock = Block< T, ArrayAccess >
 A Cvb::Block of a contiguous plane. More...
 
template<class T >
using LinearPlaneBlock = Block< T, LinearAccess >
 A Cvb::Block of a linear plane. More...
 
template<class T >
using VpatPlaneBlock = Block< T, VpatAccess >
 A Cvb::Block of a VPAT plane. More...
 
template<class T , size_t K>
using ScatterBlock = Block< T, ScatterAccess< K > >
 A Cvb::Block of variant planes. More...
 
template<class VISITOR , class PLANE_T , class... PLANEARGS, std::enable_if_t< std::is_same< typename PlaneTraits< PLANE_T >::PlaneT, PLANE_T >::value, int > = 0>
auto Visit (VISITOR &&visitor, const PLANE_T &plane, const PLANEARGS &... planes)
 Creates a Cvb::Block based on the plane and planes objects' access traits and pixel type and calls the given visitor with it. More...
 
template<class T , class VISITOR , class PLANE_T , class... PLANEARGS, std::enable_if_t< std::is_same< typename PlaneTraits< PLANE_T >::PlaneT, PLANE_T >::value, int > = 0>
auto VisitAs (VISITOR &&visitor, const PLANE_T &plane, const PLANEARGS &... planes)
 Creates Cvb::Blocks based on the planes objects' access traits and T and calls the given visitor with them. When the T is compile-time known, this variant is useful to avoid unnecessary template instantiations. More...
 

Detailed Description

template<class T, class ACCESSTRAIT>
class Cvb::Block< T, ACCESSTRAIT >

Non-owning view on a 2d-plane of data.

Template Parameters
TPlane value type.
ACCESSTRAITAccess Trait to access a coordinate.

Constructor & Destructor Documentation

◆ Block() [1/2]

Block ( ACCESSTRAIT  access,
Cvb::Size2D< int >  size 
)
inlineexplicit

◆ Block() [2/2]

Block ( const Block< T, ACCESSTRAIT > &  other)
defaultnoexcept

Copy ctor.

Parameters
[in]otherObject to copy.

Member Function Documentation

◆ ColumnAt()

Column ColumnAt ( int  x) const
inlinenoexcept

Gets the Block::Column at x.

Precondition
x must be between 0 and less than the allowed width.
Parameters
[in]xPixel column.
Returns
Column object at line x.

◆ operator()() [1/2]

CVB_FORCE_INLINE const PixelType & operator() ( int  x,
int  y 
) const
inlinenoexcept

Coordinate pixel access operator.

Precondition
x and y inside Size()
Valid() == true
Parameters
[in]xX coordinate coefficient in pixels.
[in]yY coordinate coefficient in pixels.
Returns
Const reference to pixel value.

◆ operator()() [2/2]

CVB_FORCE_INLINE PixelType & operator() ( int  x,
int  y 
)
inlinenoexcept

Coordinate pixel access operator.

Precondition
x and y inside Size()
Valid() == true
Parameters
[in]xX coordinate coefficient in pixels.
[in]yY coordinate coefficient in pixels.
Returns
Mutable reference to pixel value.

◆ operator=()

Block & operator= ( const Block< T, ACCESSTRAIT > &  other)
defaultnoexcept

Copy operator.

Parameters
[in]otherObject to copy.
Returns
Reference to this object.

◆ operator[]() [1/2]

CVB_FORCE_INLINE const PixelType & operator[] ( int  idx) const
inlinenoexcept

Index pixel access operator.

Precondition
idx between 0..Size().Width()*Size().Height()
Valid() == true
Parameters
[in]idxPixel index in pixels.
Returns
Const reference to pixel value.

◆ operator[]() [2/2]

CVB_FORCE_INLINE PixelType & operator[] ( int  idx)
inlinenoexcept

Coordinate pixel access operator.

Precondition
idx between 0..Size().Width()*Size().Height()
Valid() == true
Parameters
[in]idxPixel index in pixels.
Returns
Mutable reference to pixel value.

◆ RowAt()

Row RowAt ( int  y) const
inlinenoexcept

Gets the Block::Row at y.

Precondition
y must be between 0 and less than the allowed height.
Parameters
[in]yPixel row.
Returns
Row object at line y.

◆ Set() [1/4]

CVB_FORCE_INLINE auto Set ( int  idx,
const FromPixelType &  value 
) -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value, void>
inlinenoexcept

Index setter.

Supports any input type for value for which get<I>() is overloaded and has sufficiently many values.

Precondition
idx between 0..Size().Width()*Size().Height()
Valid() == true
Parameters
[in]idxPixel index in pixels.
[in]valueNew pixel value.

◆ Set() [2/4]

CVB_FORCE_INLINE void Set ( int  idx,
const PixelType &  value 
)
inlinenoexcept

Index setter.

Supports any input type for value for which get<I>() is overloaded and has sufficiently many values.

Precondition
idx between 0..Size().Width()*Size().Height()
Valid() == true
Parameters
[in]idxPixel index in pixels.
[in]valueNew pixel value.

◆ Set() [3/4]

CVB_FORCE_INLINE auto Set ( int  x,
int  y,
const FromPixelType &  value 
) -> std::enable_if_t<!std::is_convertible<remove_cvref_t<FromPixelType>, remove_cvref_t<PixelType>>::value, void>
inlinenoexcept

Coordinate setter.

Supports any input type for value for which get<I>() is overloaded and has sufficiently many values.

Precondition
x and y inside Size()
Valid() == true
Parameters
[in]xX coordinate coefficient in pixels.
[in]yY coordinate coefficient in pixels.
[in]valueNew pixel value.

◆ Set() [4/4]

CVB_FORCE_INLINE void Set ( int  x,
int  y,
const PixelType &  value 
)
inlinenoexcept

Coordinate setter.

Supports any input type for value for which get<I>() is overloaded and has sufficiently many values.

Precondition
x and y inside Size()
Valid() == true
Parameters
[in]xX coordinate coefficient in pixels.
[in]yY coordinate coefficient in pixels.
[in]valueNew pixel value.

◆ SubBlock()

auto SubBlock ( Cvb::Rect< int >  aoi) const -> Block<T, decltype(this->Access().NewMoved(Cvb::Rect<int>{}))>
inline

Creates a new sub Block from this block.

Precondition
Valid() == true aoi is inside Size() and not empty
Parameters
[in]aoiArea of interest of this block.
Returns
New Block object of the given aoi.
Exceptions
std::logic_errorif this not Valid().
std::length_errorif aoi is outside bounds.

Friends And Related Function Documentation

◆ ArrayPlaneBlock

using ArrayPlaneBlock = Block<T, ArrayAccess>
related

A Cvb::Block of a contiguous plane.

Template Parameters
TPlane value type.

◆ LinearPlaneBlock

using LinearPlaneBlock = Block<T, LinearAccess>
related

A Cvb::Block of a linear plane.

Template Parameters
TPlane value type.

◆ ScatterBlock

using ScatterBlock = Block<T, ScatterAccess<K> >
related

A Cvb::Block of variant planes.

Template Parameters
TPlane value type.

◆ Visit()

auto Visit ( VISITOR &&  visitor,
const PLANE_T &  plane,
const PLANEARGS &...  planes 
)
related

Creates a Cvb::Block based on the plane and planes objects' access traits and pixel type and calls the given visitor with it.

Remarks
If more than one plane is given, the visitor must either be callable with a single Block or with exactly as many Blocks as there are plane arguments. In the single argument case, the Block will either be a ArrayPlaneBlock<LinearValue<T, NumPlanes>>, LinearPlaneBlock<LinearValue<T, NumPlanes>> or a ScatterBlock<T, NumPlanes>. In the multiple argument case, the Blocks will all either be ArrayPlaneBlock<T> or LinearPlaneBlock<T> depending on whether all the planes' memory is continuous or not. If PlaneTraits<PLANE_T>::HasVpat is true, VpatPlaneBlock<LinearValue<T, NumPlanes> or VpatPlaneBlock<T> are additionally possible block types.
If the planes are interleaved in the argument order, a ArrayPlaneBlock<LinearValue<T, NumPlanes>>, LinearPlaneBlock<LinearValue<T, NumPlanes>> or VpatPlaneBlock<LinearValue<T, NumPlanes> is used, providing performance benefits. If the planes are not interleaved ScatterBlock<RefValue<T, NumPlanes>, NumPlanes> is used.
The possible element types T are taken from PlaneTraits<PLANE_T>::TypeList.
Template Parameters
VISITORThe visitor functor.
Parameters
[in]visitorThe visiting functor. May either have one argument or exactly as many arguments as planes are given.
[in]planeThe first plane to visit.
[in]planesMore planes to visit.
Returns
Whatever visitor returns.
Exceptions
std::domain_errorif properties of the planes differ.

◆ VisitAs()

auto VisitAs ( VISITOR &&  visitor,
const PLANE_T &  plane,
const PLANEARGS &...  planes 
)
related

Creates Cvb::Blocks based on the planes objects' access traits and T and calls the given visitor with them. When the T is compile-time known, this variant is useful to avoid unnecessary template instantiations.

Remarks
If the planes are interleaved in the argument order, a ArrayPlaneBlock<PointT> or LinearPlaneBlock<PointT> is used, providing performance benefits. If PlaneTraits<PLANE_T>::HasVpat is true and any plane does not provide Cvb::LinearAccess, Cvb::VpatPlaneBlock is used. If the planes are not interleaved ScatterBlock<PointT, N> is used.
If T is an arithmetic type, the behavior is equivalent to Visit, except the component type is not dispatched and instead T is used. In this case, PointT will be LinearValue<T, NumPlanes> or RefValue<T, NumPlanes>. Otherwise T will be used as PointT directly.
Template Parameters
TThe element type of the planes.
VISITORThe visitor functor.
Parameters
[in]visitorThe visiting functor. May either have one argument or exactly as many arguments as planes are given.
[in]planeThe first plane to visit.
[in]planesMore planes to visit.
Returns
Whatever visitor returns.
Exceptions
std::runtime_errorif no pixel type could be matched
std::domain_errorif properties of the planes differ.

◆ VpatPlaneBlock

using VpatPlaneBlock = Block<T, VpatAccess>
related

A Cvb::Block of a VPAT plane.

Template Parameters
TPlane value type.