CVB++ 14.1
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)
 Base class for all typed Cvb::Block types. More...
 
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 >
auto Visit (VISITOR &&visitor, const PointCloud &cloud)
 Creates a Cvb::Block based on the cloud object's access trait and pixel type and calls the given visitor with it. More...
 
template<class T , class VISITOR >
auto VisitAs (VISITOR &&visitor, const PointCloud &cloud)
 Creates a Cvb::Block based on the cloud object's access trait and given pixel type T and calls the given visitor with it. More...
 
template<class VISITOR , class... PLNS>
auto Visit (VISITOR &&visitor, const Plane &plane, const PLNS &... 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... PLNS>
auto VisitAs (VISITOR &&visitor, const Plane &plane, const PLNS &... planes)
 Creates a Cvb::Block based on the plane and planes objects' access traits and given pixel type T and calls the given visitor with it. More...
 
template<class VISITOR , class... PLANEARGS>
auto Visit (VISITOR &&visitor, const ImagePlane &plane, const PLANEARGS &... planes)
 Creates Cvb::Blocks based on the planes objects' access traits and pixel type, and calls the given visitor with them. More...
 
template<class PIXEL_TYPE , class VISITOR , class... PLANEARGS>
auto VisitAs (VISITOR &&visitor, const ImagePlane &plane, const PLANEARGS &... planes)
 Creates Cvb::Blocks based on the planes objects' access traits and PIXEL_TYPE and calls the given visitor with them. When the PIXEL_TYPE is compile-time known, this overload is useful to avoid unnecessary template instantiations. 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()

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

Base class for all typed Cvb::Block types.

This base class contains the common, untyped methods of the Cvb::Block to reduce binary size.

Template Parameters
AccessTraitTrait to access a coordinate.

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[]() [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() [1/4]

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

Creates Cvb::Blocks based on the planes objects' access traits and pixel type, and calls the given visitor with them.

ImagePlane

The planes must have the same pixel type. If all planes support Cvb::ArrayAccess, then all blocks forwarded to the visitor are of type Cvb::ArrayPlaneBlock, if all are of Cvb::LinearAccess, all blocks will be of type Cvb::LinearPlaneBlock, otherwise of type Cvb::VpatPlaneBlock.

Template Parameters
VISITORCallable that is called with the typed Cvb::Block.
Parameters
[in]visitorCallable of signature auto(Block<T,ACCESS_TRAIT>, ...).
[in]planeThe first plane to visit.
[in]planesPlanes to create typed Cvb::Blocks for that will be forwarded to the visitor.
Returns
Whatever visitor returns.
Exceptions
std::runtime_errorif no pixel type could be matched.
std::domain_errorif properties of the planes differ.

◆ Visit() [2/4]

auto Visit ( VISITOR &&  visitor,
const Plane plane,
const PLNS &...  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.

Plane

Remarks
Currently only point clouds are supported, where LinearAccess is supported. If only a single plane is given, either a ArrayPlaneBlock<T> or a LinearPlaneBlock<T> is given as argument to the visitor.
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 the planes are interleaved in the argument order, a ArrayPlaneBlock<LinearValue<T, NumPlanes>> or LinearPlaneBlock<LinearValue<T, NumPlanes>> is used, providing performance optimizations. Otherwise ScatterBlock<RefValue<T, NumPlanes>, NumPlanes> is used.
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.

◆ Visit() [3/4]

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.

◆ Visit() [4/4]

auto Visit ( VISITOR &&  visitor,
const PointCloud cloud 
)
related

Creates a Cvb::Block based on the cloud object's access trait and pixel type and calls the given visitor with it.

PointCloud

Remarks
Currently only point clouds are supported, where LinearAccess is supported. The block will either be a ArrayPlaneBlock<LinearValue<T, 3>>, LinearPlaneBlock<LinearValue<T, 3>> or a ScatterBlock<T, 3>. If the x, y and z planes are interleaved in this order, a ArrayPlaneBlock<LinearValue<T, 3>> or LinearPlaneBlock<LinearValue<T, 3>> is used, providing performance optimizations. Otherwise ScatterBlock<T, 3> is used.
Template Parameters
VISITORCallable that is called with the typed CvbConcepts::Block.
Parameters
[in]visitorCallable of signature auto(Block<T,ACCESS_TRAIT>).
[in]cloudPointCloud to create typed CvbConcepts::Block for.
Returns
Whatever visitor returns.
Exceptions
std::runtime_errorif no pixel type could be matched.
std::domain_errorif properties of the planes differ.

◆ VisitAs() [1/4]

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

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

ImagePlane

The planes must have the same pixel type. If all planes support Cvb::ArrayAccess, then all blocks forwarded to the visitor are of type Cvb::ArrayPlaneBlock, if all are of Cvb::LinearAccess, all blocks will be of type Cvb::LinearPlaneBlock, otherwise of type Cvb::VpatPlaneBlock.

Template Parameters
PIXEL_TYPEThe pixel type of the planes.
VISITORCallable that is called with the typed Cvb::Block.
Parameters
[in]visitorCallable of signature auto(Block<PIXEL_TYPE,ACCESS_TRAIT>, ...).
[in]planeThe first plane to visit.
[in]planesPlanes to create typed Cvb::Blocks for that will be forwarded to the visitor.
Returns
Whatever visitor returns.
Exceptions
std::runtime_errorif no pixel type could be matched
std::domain_errorif properties of the planes differ.

◆ VisitAs() [2/4]

auto VisitAs ( VISITOR &&  visitor,
const Plane plane,
const PLNS &...  planes 
)
related

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

Plane

Remarks
Currently only point clouds are supported, where LinearAccess is supported. The visitor must be callable with a single Block<PointT, AccessTrait> as argument.
If the planes are interleaved in the argument order, a ArrayPlaneBlock<PointT> or LinearPlaneBlock<PointT> is used, providing performance optimizations. Otherwise 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
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() [3/4]

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.

◆ VisitAs() [4/4]

auto VisitAs ( VISITOR &&  visitor,
const PointCloud cloud 
)
related

Creates a Cvb::Block based on the cloud object's access trait and given pixel type T and calls the given visitor with it.

PointCloud

Remarks
Currently only point clouds are supported, where LinearAccess is supported. The block will either be a ArrrayPlaneBlock<PointT>, LinearPlaneBlock<PointT> or a ScatterBlock<PointT, 3>. If the x, y and z planes are interleaved in this order, a ArrayPlaneBlock<PointT> or LinearPlaneBlock<PointT> is used, providing superior performance. Otherwise ScatterBlock<PointT, 3> 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, 3> or RefValue<T, 3>. Otherwise T will be used as PointT directly.
Template Parameters
TType of the pixel, that can be accessed through the Block.
VISITORCallable that is called with the typed CvbConcepts::Block.
Parameters
[in]visitorCallable of signature auto(Block<T,ACCESS_TRAIT>).
[in]cloudPointCloud to create typed CvbConcepts::Block for.
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.