ome-files  0.5.0
Classes | Public Types | Public Member Functions | Static Protected Member Functions | Protected Attributes | Private Types | List of all members
ome::files::VariantPixelBuffer Class Reference

Buffer for all pixel types. More...

#include <ome/files/VariantPixelBuffer.h>

Classes

struct  make_buffer
 Convert T into a buffer. More...
 

Public Types

typedef boost::make_variant_over< pixel_buffer_types >::type variant_buffer_type
 Buffer type, allowing assignment of all buffer types.
 
typedef PixelProperties<::ome::xml::model::enums::PixelType::UINT8 >::std_type raw_type
 Raw pixel type used in public interfaces.
 
typedef boost::multi_array_types::size_type size_type
 Size type.
 
typedef std::array< boost::multi_array_types::index, PixelBufferBase::dimensionsindices_type
 Type used to index all dimensions in public interfaces.
 
typedef PixelBufferBase::storage_order_type storage_order_type
 Storage ordering type for controlling pixel memory layout.
 
typedef PixelBufferBase::range_type range_type
 Extent range type.
 

Public Member Functions

 VariantPixelBuffer ()
 Default constructor. More...
 
template<class ExtentList >
 VariantPixelBuffer (const ExtentList &extents, ::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, const storage_order_type &storage=PixelBufferBase::default_storage_order())
 Construct from extents (internal storage). More...
 
 VariantPixelBuffer (const range_type &range, ::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, const storage_order_type &storage=PixelBufferBase::default_storage_order())
 Construct from ranges (internal storage). More...
 
 VariantPixelBuffer (const VariantPixelBuffer &buffer)
 Copy constructor. More...
 
template<typename T >
 VariantPixelBuffer (std::shared_ptr< PixelBuffer< T >> &buffer)
 Construct from existing pixel buffer. More...
 
virtual ~VariantPixelBuffer ()
 Destructor.
 
variant_buffer_typevbuffer ()
 Get a reference to the variant buffer. More...
 
const variant_buffer_typevbuffer () const
 Get a reference to the variant buffer. More...
 
template<class ExtentList >
void setBuffer (const ExtentList &extents, ::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, const storage_order_type &storage=PixelBufferBase::default_storage_order())
 Set the buffer from extents (helper). More...
 
void setBuffer (const range_type &range, ::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, const storage_order_type &storage=PixelBufferBase::default_storage_order())
 Set the buffer from ranges (internal storage). More...
 
bool managed () const
 Check if the buffer is internally managed. More...
 
size_type num_elements () const
 Get the number of pixel elements in the multi-dimensional array. More...
 
size_type num_dimensions () const
 Get the number of dimensions in the multi-dimensional array. More...
 
const size_typeshape () const
 Get the shape of the multi-dimensional array. More...
 
const boost::multi_array_types::index * strides () const
 Get the strides of the multi-dimensional array. More...
 
const boost::multi_array_types::index * index_bases () const
 Get the index bases of the multi-dimensional array. More...
 
template<typename T >
const T * origin () const
 Get the origin of the array. More...
 
const storage_order_typestorage_order () const
 Get the array storage order. More...
 
::ome::xml::model::enums::PixelType pixelType () const
 Get the type of pixels stored in the buffer. More...
 
EndianType endianType () const
 Get the endianness of the pixel type stored in the buffer. More...
 
template<typename T >
PixelBuffer< T >::array_ref_type & array ()
 Get the pixel data. More...
 
template<typename T >
const PixelBuffer< T >::array_ref_type & array () const
 Get the pixel data. More...
 
raw_typedata ()
 Get raw buffered data. More...
 
const raw_typedata () const
 Get raw buffered data. More...
 
template<typename T >
T * data ()
 Get raw buffered data. More...
 
template<typename T >
const T * data () const
 Get raw buffered data. More...
 
bool valid () const
 Check the buffer validity. More...
 
VariantPixelBufferoperator= (const VariantPixelBuffer &rhs)
 Assign a pixel buffer. More...
 
bool operator== (const VariantPixelBuffer &rhs) const
 Compare a pixel buffer for equality. More...
 
bool operator!= (const VariantPixelBuffer &rhs) const
 Compare a pixel buffer for inequality. More...
 
template<typename InputIterator >
void assign (InputIterator begin, InputIterator end)
 Assign pixel values. More...
 
template<class charT , class traits >
void read (std::basic_istream< charT, traits > &stream)
 Read raw pixel data from a stream in physical storage order. More...
 
template<class charT , class traits >
void write (std::basic_ostream< charT, traits > &stream) const
 Write raw pixel data to a stream in physical storage order. More...
 

Static Protected Member Functions

template<class T , class ExtentList >
static variant_buffer_type makeBuffer (const ExtentList &extents, const storage_order_type &storage, ::ome::xml::model::enums::PixelType pixeltype)
 Create buffer from extents (helper). More...
 
template<class T >
static variant_buffer_type makeBuffer (const range_type &range, const storage_order_type &storage, ::ome::xml::model::enums::PixelType pixeltype)
 Create buffer from ranges (helper). More...
 
template<class ExtentList >
static variant_buffer_type createBuffer (const ExtentList &extents, ::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, const storage_order_type &storage=PixelBufferBase::default_storage_order())
 Create buffer from extents (internal storage). More...
 
static variant_buffer_type createBuffer (const range_type &range, ::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, const storage_order_type &storage=PixelBufferBase::default_storage_order())
 Create buffer from ranges (helper). More...
 

Protected Attributes

variant_buffer_type buffer
 Pixel storage.
 

Private Types

typedef boost::mpl::vector< PixelProperties<::ome::xml::model::enums::PixelType::INT8 >, PixelProperties<::ome::xml::model::enums::PixelType::INT16 >, PixelProperties<::ome::xml::model::enums::PixelType::INT32 >, PixelProperties<::ome::xml::model::enums::PixelType::UINT8 >, PixelProperties<::ome::xml::model::enums::PixelType::UINT16 >, PixelProperties<::ome::xml::model::enums::PixelType::UINT32 >, PixelProperties<::ome::xml::model::enums::PixelType::BIT > > integer_pixel_types
 Integer pixel types.
 
typedef boost::mpl::vector< PixelProperties<::ome::xml::model::enums::PixelType::FLOAT >, PixelProperties<::ome::xml::model::enums::PixelType::DOUBLE >, PixelProperties<::ome::xml::model::enums::PixelType::COMPLEXFLOAT >, PixelProperties<::ome::xml::model::enums::PixelType::COMPLEXDOUBLE > > float_pixel_types
 Floating-point pixel types.
 
typedef boost::mpl::joint_view< integer_pixel_types, float_pixel_types >::type basic_pixel_types_view
 Aggregate view of all numeric types.
 
typedef boost::mpl::transform_view< basic_pixel_types_view, make_buffer< boost::mpl::_1 > >::type pixel_buffer_types_view
 Aggregate view of all buffer types.
 
typedef boost::mpl::vector empty_types
 Empty vector placeholder.
 
typedef boost::mpl::insert_range< empty_types, boost::mpl::end< empty_types >::type, pixel_buffer_types_view >::type pixel_buffer_types
 List of all pixel buffer types.
 

Detailed Description

Buffer for all pixel types.

The purpose of this class is to allow transfer of pixel data of any type and of any dimensionality.

This class uses Boost.Variant to support specializations of PixelBuffer for all combinations of pixel type (excluding endian variants).

For high performance access to the pixel data, use of a boost::static_visitor is recommended. This has the benefit of generalising the algorithm to operate on all PixelBuffer types, as well as allowing special casing for particular types (e.g. integer vs. float, signed vs. unsigned, simple vs. complex, or any other distinction which affects the algorithm). This will also allow subsetting of the data if required, again for all pixel types with special casing being possible.

Todo:
Add support for subsetting dimensions.

Constructor & Destructor Documentation

◆ VariantPixelBuffer() [1/5]

ome::files::VariantPixelBuffer::VariantPixelBuffer ( )
inlineexplicit

Default constructor.

This constructs a pixel buffer of unspecified type, of size 1 in all dimensions. The desired type and size should be set after construction.

Referenced by VariantPixelBuffer().

+ Here is the caller graph for this function:

◆ VariantPixelBuffer() [2/5]

template<class ExtentList >
ome::files::VariantPixelBuffer::VariantPixelBuffer ( const ExtentList &  extents,
::ome::xml::model::enums::PixelType  pixeltype = ::ome::xml::model::enums::PixelType::UINT8,
const storage_order_type storage = PixelBufferBase::default_storage_order() 
)
inlineexplicit

Construct from extents (internal storage).

Storage for the buffer will be allocated internally.

Parameters
extentsthe extent of each dimension.
storagethe storage ordering, defaulting to C array storage ordering.
pixeltypethe pixel type to store.

◆ VariantPixelBuffer() [3/5]

ome::files::VariantPixelBuffer::VariantPixelBuffer ( const range_type range,
::ome::xml::model::enums::PixelType  pixeltype = ::ome::xml::model::enums::PixelType::UINT8,
const storage_order_type storage = PixelBufferBase::default_storage_order() 
)
inlineexplicit

Construct from ranges (internal storage).

Storage for the buffer will be allocated internally.

Parameters
rangethe range of each dimension.
storagethe storage ordering, defaulting to C array storage ordering.
pixeltypethe pixel type to store.

References buffer, and VariantPixelBuffer().

◆ VariantPixelBuffer() [4/5]

ome::files::VariantPixelBuffer::VariantPixelBuffer ( const VariantPixelBuffer buffer)
explicit

Copy constructor.

Note that due to the use of shared pointers this only performs a shallow copy.

Parameters
bufferthe buffer to copy.

References buffer.

◆ VariantPixelBuffer() [5/5]

template<typename T >
ome::files::VariantPixelBuffer::VariantPixelBuffer ( std::shared_ptr< PixelBuffer< T >> &  buffer)
inlineexplicit

Construct from existing pixel buffer.

Use for referencing external data.

Parameters
bufferthe buffer to contain.

Member Function Documentation

◆ array() [1/2]

template<typename T >
PixelBuffer< T >::array_ref_type & ome::files::VariantPixelBuffer::array ( )
inline

Get the pixel data.

Get the pixel data.

Returns
the multidimensional pixel data array; this value will never be null.
Exceptions
ifthe contained PixelBuffer is not of the specified type.
Returns
the multidimensional pixel data array; this value will never be null.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ array() [2/2]

template<typename T >
const PixelBuffer< T >::array_ref_type & ome::files::VariantPixelBuffer::array ( ) const
inline

Get the pixel data.

Get the pixel data.

Returns
the multidimensional pixel data array; this value will never be null.
Exceptions
ifthe contained PixelBuffer is not of the specified type.
Returns
the multidimensional pixel data array; this value will never be null.

◆ assign()

template<typename InputIterator >
void ome::files::VariantPixelBuffer::assign ( InputIterator  begin,
InputIterator  end 
)
inline

Assign pixel values.

Assign all pixel values from an input iterator.

Note that the range to assign must be equal to num_elements().

Parameters
beginthe start of the range to assign.
endthe end of the range to assign.
beginthe start of input.
endthe end of input.
Exceptions
ifthe PixelBuffer is null or the PixelBuffer's data array is null.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ createBuffer() [1/2]

template<class ExtentList >
static variant_buffer_type ome::files::VariantPixelBuffer::createBuffer ( const ExtentList &  extents,
::ome::xml::model::enums::PixelType  pixeltype = ::ome::xml::model::enums::PixelType::UINT8,
const storage_order_type storage = PixelBufferBase::default_storage_order() 
)
inlinestaticprotected

Create buffer from extents (internal storage).

Storage for the buffer will be allocated internally.

Parameters
extentsthe extent of each dimension.
pixeltypethe pixel type to store.
storagethe storage ordering, defaulting to C array storage ordering.
Returns
the new buffer contained in a variant.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ createBuffer() [2/2]

static variant_buffer_type ome::files::VariantPixelBuffer::createBuffer ( const range_type range,
::ome::xml::model::enums::PixelType  pixeltype = ::ome::xml::model::enums::PixelType::UINT8,
const storage_order_type storage = PixelBufferBase::default_storage_order() 
)
inlinestaticprotected

Create buffer from ranges (helper).

Storage for the buffer will be allocated internally.

Parameters
rangethe range of each dimension.
pixeltypethe pixel type to store.
storagethe storage ordering, defaulting to C array storage ordering.
Returns
the new buffer contained in a variant.

◆ data() [1/4]

VariantPixelBuffer::raw_type * ome::files::VariantPixelBuffer::data ( )

Get raw buffered data.

Returns
a pointer to the buffer start address.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ data() [2/4]

const VariantPixelBuffer::raw_type * ome::files::VariantPixelBuffer::data ( ) const

Get raw buffered data.

Returns
a pointer to the buffer start address.

References buffer.

◆ data() [3/4]

template<typename T >
T * ome::files::VariantPixelBuffer::data ( )
inline

Get raw buffered data.

Returns
a pointer to the buffer start address.
Exceptions
ifthe contained PixelBuffer is not of the specified type.

◆ data() [4/4]

template<typename T >
const T * ome::files::VariantPixelBuffer::data ( ) const
inline

Get raw buffered data.

Returns
a pointer to the buffer start address.
Exceptions
ifthe contained PixelBuffer is not of the specified type.

◆ endianType()

EndianType ome::files::VariantPixelBuffer::endianType ( ) const

Get the endianness of the pixel type stored in the buffer.

Returns
the endian type.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ index_bases()

const boost::multi_array_types::index * ome::files::VariantPixelBuffer::index_bases ( ) const

Get the index bases of the multi-dimensional array.

The index bases are the numeric index of the first element for each array dimension of the multi-dimensional array.

Returns
an array of index bases (size is the dimension size).

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ makeBuffer() [1/2]

template<class T , class ExtentList >
static variant_buffer_type ome::files::VariantPixelBuffer::makeBuffer ( const ExtentList &  extents,
const storage_order_type storage,
::ome::xml::model::enums::PixelType  pixeltype 
)
inlinestaticprotected

Create buffer from extents (helper).

Storage for the buffer will be allocated internally.

Parameters
extentsthe extent of each dimension.
storagethe storage ordering, defaulting to C array storage ordering.
pixeltypethe pixel type to store.
Returns
the new buffer contained in a variant.

References ome::files::ENDIAN_NATIVE.

◆ makeBuffer() [2/2]

template<class T >
static variant_buffer_type ome::files::VariantPixelBuffer::makeBuffer ( const range_type range,
const storage_order_type storage,
::ome::xml::model::enums::PixelType  pixeltype 
)
inlinestaticprotected

Create buffer from ranges (helper).

Storage for the buffer will be allocated internally.

Parameters
rangethe range of each dimension.
storagethe storage ordering, defaulting to C array storage ordering.
pixeltypethe pixel type to store.
Returns
the new buffer contained in a variant.

References ome::files::ENDIAN_NATIVE.

◆ managed()

bool ome::files::VariantPixelBuffer::managed ( ) const

Check if the buffer is internally managed.

Returns
true if the MultiArray data is managed internally (i.e. is a multi_array) or false if not managed (i.e. is a multi_array_ref).

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ num_dimensions()

boost::multi_array_types::size_type ome::files::VariantPixelBuffer::num_dimensions ( ) const

Get the number of dimensions in the multi-dimensional array.

Returns
the number of dimensions.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ num_elements()

boost::multi_array_types::size_type ome::files::VariantPixelBuffer::num_elements ( ) const

Get the number of pixel elements in the multi-dimensional array.

Returns
the number of elements.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ operator!=()

bool ome::files::VariantPixelBuffer::operator!= ( const VariantPixelBuffer rhs) const

Compare a pixel buffer for inequality.

Parameters
rhsthe pixel buffer to compare with.
Returns
true if not equal, false if equal.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ operator=()

VariantPixelBuffer & ome::files::VariantPixelBuffer::operator= ( const VariantPixelBuffer rhs)

Assign a pixel buffer.

The dimension extents must be compatible, but the storage ordering does not. The buffer contents will be assigned in the logical order rather than the storage order.

Parameters
rhsthe pixel buffer to assign.
Returns
the assigned buffer.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ operator==()

bool ome::files::VariantPixelBuffer::operator== ( const VariantPixelBuffer rhs) const

Compare a pixel buffer for equality.

Parameters
rhsthe pixel buffer to compare with.
Returns
true if equal, false if not equal.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ origin()

template<typename T >
const T * ome::files::VariantPixelBuffer::origin ( ) const
inline

Get the origin of the array.

This is the address of the element at [0][0][0][0][0][0][0][0][0]. Note that this is not always the buffer start address, depending upon the dimension ordering.

Returns
the address of the array origin.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ pixelType()

PixelType ome::files::VariantPixelBuffer::pixelType ( ) const

Get the type of pixels stored in the buffer.

Returns
the pixel type.

References buffer.

Referenced by ome::files::tiff::IFD::readImage(), ome::files::detail::FormatReader::readPlane(), setBuffer(), and ome::files::tiff::IFD::writeImage().

+ Here is the caller graph for this function:

◆ read()

template<class charT , class traits >
void ome::files::VariantPixelBuffer::read ( std::basic_istream< charT, traits > &  stream)
inline

Read raw pixel data from a stream in physical storage order.

Note that the pixels will be read in the physical storage order. This will typically be a contiguous read, but this is not guaranteed. The current implementation iterates over each pixel and so may be slower than strictly necessary.

Parameters
streamthe stream to read from.

Referenced by setBuffer(), and write().

+ Here is the caller graph for this function:

◆ setBuffer() [1/2]

template<class ExtentList >
void ome::files::VariantPixelBuffer::setBuffer ( const ExtentList &  extents,
::ome::xml::model::enums::PixelType  pixeltype = ::ome::xml::model::enums::PixelType::UINT8,
const storage_order_type storage = PixelBufferBase::default_storage_order() 
)
inline

Set the buffer from extents (helper).

Storage for the buffer will be allocated internally.

Parameters
extentsthe extent of each dimension.
pixeltypethe pixel type to store.
storagethe storage ordering, defaulting to C array storage ordering.

References createBuffer().

Referenced by ome::files::detail::CopySubchannelVisitor::operator()(), ome::files::tiff::IFD::readImage(), ome::files::tiff::IFD::readLookupTable(), and ome::files::detail::FormatReader::readPlane().

+ Here is the caller graph for this function:

◆ setBuffer() [2/2]

void ome::files::VariantPixelBuffer::setBuffer ( const range_type range,
::ome::xml::model::enums::PixelType  pixeltype = ::ome::xml::model::enums::PixelType::UINT8,
const storage_order_type storage = PixelBufferBase::default_storage_order() 
)
inline

Set the buffer from ranges (internal storage).

Storage for the buffer will be allocated internally.

Parameters
rangethe range of each dimension.
pixeltypethe pixel type to store.
storagethe storage ordering, defaulting to C array storage ordering.

References array(), assign(), createBuffer(), data(), endianType(), index_bases(), managed(), num_dimensions(), num_elements(), operator!=(), operator=(), operator==(), origin(), pixelType(), read(), shape(), storage_order(), strides(), valid(), and write().

◆ shape()

const boost::multi_array_types::size_type * ome::files::VariantPixelBuffer::shape ( ) const

Get the shape of the multi-dimensional array.

The shape is the extent of each array dimension.

Returns
an array of extents (size is the dimension size).

References buffer.

Referenced by ome::files::tiff::IFD::readImage(), ome::files::detail::FormatReader::readPlane(), setBuffer(), and ome::files::tiff::IFD::writeImage().

+ Here is the caller graph for this function:

◆ storage_order()

const VariantPixelBuffer::storage_order_type & ome::files::VariantPixelBuffer::storage_order ( ) const

Get the array storage order.

Returns
the storage order.

References buffer.

Referenced by ome::files::tiff::IFD::readImage(), ome::files::detail::FormatReader::readPlane(), setBuffer(), and ome::files::tiff::IFD::writeImage().

+ Here is the caller graph for this function:

◆ strides()

const boost::multi_array_types::index * ome::files::VariantPixelBuffer::strides ( ) const

Get the strides of the multi-dimensional array.

The strides are the stride associated with each array dimension.

Returns
an array of strides (size is the dimension size).

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ valid()

bool ome::files::VariantPixelBuffer::valid ( ) const

Check the buffer validity.

This tests if the MultiArray is not null, and hence safe to use. Note that this is not a guarantee of safety in the case of using an externally managed data buffer, in which case the external buffer must still be valid in addition.

Returns
true if not null, false if null.

References buffer.

Referenced by setBuffer().

+ Here is the caller graph for this function:

◆ vbuffer() [1/2]

variant_buffer_type& ome::files::VariantPixelBuffer::vbuffer ( )
inline

Get a reference to the variant buffer.

Returns
a reference to the buffer.

References buffer.

Referenced by ome::files::detail::CopySubchannelVisitor::operator()(), ome::files::detail::MergeSubchannelVisitor::operator()(), ome::files::tiff::IFD::readImage(), ome::files::tiff::IFD::readLookupTable(), ome::files::detail::FormatReader::readPlane(), and ome::files::tiff::IFD::writeImage().

+ Here is the caller graph for this function:

◆ vbuffer() [2/2]

const variant_buffer_type& ome::files::VariantPixelBuffer::vbuffer ( ) const
inline

Get a reference to the variant buffer.

Returns
a reference to the buffer.

References buffer.

◆ write()

template<class charT , class traits >
void ome::files::VariantPixelBuffer::write ( std::basic_ostream< charT, traits > &  stream) const
inline

Write raw pixel data to a stream in physical storage order.

Note that the pixels will be written in the physical storage order. This will typically be a contiguous read, but this is not guaranteed. The current implementation iterates over each pixel and so may be slower than strictly necessary.

Parameters
streamthe stream to write to.

References read(), and write().

Referenced by setBuffer(), and write().

+ Here is the caller graph for this function:

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