ifm3d
ifm3d::Buffer Class Reference

The class Buffer represent a STL container to store data from the ifm devices in 2 dimension and supports multiple channel. More...

#include <ifm3d/fg/buffer.h>

Classes

struct  Iterator
 

Public Member Functions

 Buffer ()
 These are various constructors that form a Buffer. More...
 
 Buffer (const std::uint32_t cols, const std::uint32_t rows, const std::uint32_t nchannel, ifm3d::pixel_format format, std::optional< ifm3d::json > metadata=std::nullopt)
 
 Buffer (Buffer &&)=default
 
Bufferoperator= (Buffer &&)=default
 
 Buffer (const Buffer &)=default
 
Bufferoperator= (const Buffer &)=default
 
void create (const std::uint32_t cols, const std::uint32_t rows, const std::uint32_t nchannel, ifm3d::pixel_format format)
 
Buffer clone () const
 Creates a full copy of the array and the underlying data.
 
std::uint32_t height () const
 
std::uint32_t width () const
 
std::uint32_t nchannels () const
 
ifm3d::pixel_format dataFormat () const
 
ifm3d::json metadata () const
 
size_t size () const
 Return the size of the buffer in bytes.
 
template<typename T = std::uint8_t>
T * ptr (const std::uint32_t row)
 returns a pointer to the specified Buffer row. More...
 
template<typename T = std::uint8_t>
T const * ptr (const std::uint32_t row) const
 returns a pointer to the specified Buffer row. More...
 
template<typename T = std::uint8_t>
T * ptr (const std::uint32_t row, const std::uint32_t col)
 Pointer to the Pixel at row,col. More...
 
template<typename T = std::uint8_t>
T const * ptr (const std::uint32_t row, const std::uint32_t col) const
 Pointer to the Pixel at row,col. More...
 
template<typename T >
T & at (const std::size_t index)
 
template<typename T >
T & at (const std::uint32_t row, const std::uint32_t col)
 
template<typename T >
T const & at (const std::size_t index) const
 
template<typename T >
T const & at (const std::uint32_t row, const std::uint32_t col) const
 
template<typename T >
void setTo (const T val, const ifm3d::Buffer &mask)
 
template<typename T >
Iterator< T > begin ()
 
template<typename T >
Iterator< T > end ()
 

Detailed Description

The class Buffer represent a STL container to store data from the ifm devices in 2 dimension and supports multiple channel.

Data stored in sequential memory layout and class provides function template to access the pixel. Creating an Buffer object :

  • Use the Create(cols, rows, nchannel, ifm3d::pixel_format ) method or the similar Buffer(cols, rows, nchannel, type) constructor.

For example, FORMAT_8U means a 8-bit array, FORMAT_32F floating-point array, and so on.

//a 100 x 100 Buffer of type 8U
ifm3d::Buffer image(100,100,1,ifm3d::FORMAT_8U);
// and now turn image to a 10 x10 3-channel 8-bit matrix.
// The old content will be deallocated
image.create(10,10,3,ifm3d::FORMAT_8U);

note: create() allocates new memory.

  • Accessing the pixels use at<T>(index) or at<T>(i,j) to access the pixel this return the reference to the pixel. A pixel is defined as structure of n-channel values at a given index or pixel position in 2D array

to access a pixel in Buffer I ( 100,100,1,ifm3d::FORMAT_8U) at 50,50 position

auto pixel = I<uint8_t>(50,50);
// if working as Index array then
auto index = 50*100 + 50 ;
auto pixel = I<uint8_t>(index);

changing the pixel value can be done as follow : writing 100 at pixel postion 50,50

I<uint8_t>(50,50) = 100;
I<uint8_t>(index) = 100;

to access a pixel in n-channel Buffer I ( 100,100,3,ifm3d::FORMAT_8U) at 50,50 position This will be the case accessing the values for 3 channel Buffer as pixel is structure of the values of n-chanel at given position.

auto pixel = I<Point3D<uint8_t>>(50,50);
//now individual channel values can be access with
val[0], val[1] , val[2]
  • Processing the whole array If you need to process a whole image, the most efficient way is to get the pointer to the row first, and then just use the plain C operator[] :
    Buffer I(100,100,1,FORMAT_8U);
    for(int i = 0; i < I.height(); i++)
    {
    const uint8_t* rowi = M.ptr<uint8_t>(i);
    for(int j = 0; j < I.width(); j++)
    {
    //some operation here
    }
    }

One can also use range based for loops with adapter explained in ifm3d::IteratorAdapter section

Constructor & Destructor Documentation

◆ Buffer()

ifm3d::Buffer::Buffer ( )

These are various constructors that form a Buffer.

default constructor for forming a Buffer. User further needs to call create Method to actually allocates the memory

Member Function Documentation

◆ ptr() [1/4]

template<typename T = std::uint8_t>
T* ifm3d::Buffer::ptr ( const std::uint32_t  row)

returns a pointer to the specified Buffer row.

Parameters
rownumber

◆ ptr() [2/4]

template<typename T = std::uint8_t>
T const* ifm3d::Buffer::ptr ( const std::uint32_t  row) const

returns a pointer to the specified Buffer row.

Parameters
rownumber

◆ ptr() [3/4]

template<typename T = std::uint8_t>
T* ifm3d::Buffer::ptr ( const std::uint32_t  row,
const std::uint32_t  col 
)

Pointer to the Pixel at row,col.

Parameters
row1st dimension index
col2nd dimension index

◆ ptr() [4/4]

template<typename T = std::uint8_t>
T const* ifm3d::Buffer::ptr ( const std::uint32_t  row,
const std::uint32_t  col 
) const

Pointer to the Pixel at row,col.

Parameters
row1st dimension index
col2nd dimension index

The documentation for this class was generated from the following file:
ifm3d::Buffer
The class Buffer represent a STL container to store data from the ifm devices in 2 dimension and supp...
Definition: buffer.h:98
ifm3d::Buffer::Buffer
Buffer()
These are various constructors that form a Buffer.