38 #ifndef OME_FILES_PIXELBUFFER_H
39 #define OME_FILES_PIXELBUFFER_H
51 #define BOOST_DISABLE_ASSERTS 1
52 #include <boost/multi_array.hpp>
54 #include <ome/files/PixelProperties.h>
58 #include <ome/xml/model/enums/DimensionOrder.h>
113 typedef boost::multi_array_types::index
index;
116 typedef std::array<boost::multi_array_types::index,
123 typedef boost::detail::multi_array::extent_gen<dimensions>
range_type;
135 pixeltype(pixeltype),
136 endiantype(endiantype)
252 typedef boost::multi_array<value_type, dimensions>
array_type;
277 template<
class ExtentList>
301 template<
class ExtentList>
304 const ExtentList& extents,
403 return array().data();
417 return array().data();
433 bool is_valid =
true;
439 catch (
const std::runtime_error&)
457 return (boost::get<std::shared_ptr<array_type>>(&
multiarray) !=
nullptr);
468 return array().num_elements();
479 return array().num_dimensions();
492 return array().shape();
502 const boost::multi_array_types::index *
505 return array().strides();
516 const boost::multi_array_types::index *
519 return array().index_bases();
535 return array().origin();
546 return array().storage_order();
604 return array() == rhs;
628 return array() != rhs;
652 return array() < rhs;
676 return array() <= rhs;
700 return array() > rhs;
724 return array() >= rhs;
735 template <
typename InputIterator>
740 array().assign(begin, end);
756 return array()(indices);
772 return array()(indices);
785 template<
class charT,
class traits>
787 read(std::basic_istream<charT,traits>& stream)
789 stream.read(reinterpret_cast<char *>(
data()),
803 template<
class charT,
class traits>
805 write(std::basic_ostream<charT,traits>& stream)
const
807 stream.write(reinterpret_cast<const char *>(
data()),
827 boost::variant<std::shared_ptr<array_type>,
844 template <
typename U>
849 throw std::runtime_error(
"Null array type");
864 template <
typename U>
869 throw std::runtime_error(
"Null array type");
877 typename PixelBuffer<T>::array_ref_type&
881 return *(boost::apply_visitor(v, multiarray));
889 return *(boost::apply_visitor(v, multiarray));
905 template<
typename T,
class charT,
class traits>
906 inline std::basic_istream<charT,traits>&
907 operator>> (std::basic_istream<charT,traits>& is,
921 template<
typename T,
class charT,
class traits>
922 inline std::basic_ostream<charT,traits>&
923 operator<< (std::basic_ostream<charT,traits>& os,
924 const ::ome::files::PixelBuffer<T>& buf)
932 #endif // OME_FILES_PIXELBUFFER_H
EndianType endianType() const
Get the endian type in use.
Definition: PixelBuffer.h:161
const PixelBuffer< T >::array_ref_type * operator()(U &v) const
PixelBuffer of any type.
Definition: PixelBuffer.h:866
boost::multi_array_ref< value_type, dimensions > array_ref_type
Type for multi-dimensional pixel array view referencing external data.
Definition: PixelBuffer.h:246
Buffer for a specific pixel type.
Definition: PixelBuffer.h:235
void assign(InputIterator begin, InputIterator end)
Assign pixel values.
Definition: PixelBuffer.h:737
size_type num_elements() const
Get the number of pixel elements in the multi-dimensional array.
Definition: PixelBuffer.h:466
virtual ~PixelBuffer()
Destructor.
Definition: PixelBuffer.h:371
const size_type * shape() const
Get the shape of the multi-dimensional array.
Definition: PixelBuffer.h:490
Spatial y dimension (Y).
Definition: PixelBuffer.h:81
value_type * data()
Get the raw data.
Definition: PixelBuffer.h:401
boost::variant< std::shared_ptr< array_type >, std::shared_ptr< array_ref_type > > multiarray
Multi-dimensional pixel array.
Definition: PixelBuffer.h:828
const value_type * origin() const
Get the origin of the array.
Definition: PixelBuffer.h:533
bool valid() const
Check the buffer validity.
Definition: PixelBuffer.h:431
const boost::multi_array_types::index * index_bases() const
Get the index bases of the multi-dimensional array.
Definition: PixelBuffer.h:517
boost::multi_array_types::index index
Index type.
Definition: PixelBuffer.h:113
void write(std::basic_ostream< charT, traits > &stream) const
Write raw pixel data to a stream in physical storage order.
Definition: PixelBuffer.h:805
Base class for all PixelBuffer types.
Definition: PixelBuffer.h:103
Logical subdivision of the temporal t dimension (t).
Definition: PixelBuffer.h:87
value_type & at(const indices_type &indices)
Get the pixel value at an index.
Definition: PixelBuffer.h:754
PixelBufferBase(::ome::xml::model::enums::PixelType pixeltype, EndianType endiantype)
Constructor.
Definition: PixelBuffer.h:133
PixelBuffer(value_type *pixeldata, const ExtentList &extents,::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, EndianType endiantype=ENDIAN_NATIVE, const storage_order_type &storage=PixelBufferBase::default_storage_order())
Construct from extents (external storage).
Definition: PixelBuffer.h:303
Logical subdivision of the logical channel dimension (c).
Definition: PixelBuffer.h:88
::ome::xml::model::enums::PixelType pixelType() const
Get the pixel type in use.
Definition: PixelBuffer.h:150
Spatial x dimension (X).
Definition: PixelBuffer.h:80
const storage_order_type & storage_order() const
Get the array storage order.
Definition: PixelBuffer.h:544
boost::general_storage_order< dimensions > storage_order_type
Storage ordering type for controlling pixel memory layout.
Definition: PixelBuffer.h:120
PixelBuffer(value_type *pixeldata, const range_type &range,::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, EndianType endiantype=ENDIAN_NATIVE, const storage_order_type &storage=PixelBufferBase::default_storage_order())
Construct from ranges (external storage).
Definition: PixelBuffer.h:347
Native endian.
Definition: Types.h:71
Find a PixelBuffer data array of a specific pixel type.
Definition: PixelBuffer.h:836
static storage_order_type make_storage_order(ome::xml::model::enums::DimensionOrder order, bool interleaved)
Generate storage ordering for a given dimension order.
Definition: PixelBuffer.cpp:54
size_type num_dimensions() const
Get the number of dimensions in the multi-dimensional array.
Definition: PixelBuffer.h:477
bool operator>(const PixelBuffer &rhs) const
Greater than comparison with a pixel buffer.
Definition: PixelBuffer.h:686
bool operator!=(const PixelBuffer &rhs) const
Compare a pixel buffer for inequality.
Definition: PixelBuffer.h:614
virtual ~PixelBufferBase()
Destructor.
Definition: PixelBuffer.h:141
EndianType
Endianness.
Definition: Types.h:67
bool operator<(const PixelBuffer &rhs) const
Less than comparison with a pixel buffer.
Definition: PixelBuffer.h:638
const value_type & at(const indices_type &indices) const
Get the pixel value at an index.
Definition: PixelBuffer.h:770
void read(std::basic_istream< charT, traits > &stream)
Read raw pixel data from a stream in physical storage order.
Definition: PixelBuffer.h:787
bool managed() const
Check if the buffer is internally managed.
Definition: PixelBuffer.h:455
PixelBuffer(const range_type &range,::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, EndianType endiantype=ENDIAN_NATIVE, const storage_order_type &storage=PixelBufferBase::default_storage_order())
Construct from ranges (internal storage).
Definition: PixelBuffer.h:324
Temporal t dimension (T).
Definition: PixelBuffer.h:83
const boost::multi_array_types::index * strides() const
Get the strides of the multi-dimensional array.
Definition: PixelBuffer.h:503
Dimensions
Dimensions.
Definition: PixelBuffer.h:78
PixelBuffer & operator=(const PixelBuffer &rhs)
Assign a pixel buffer.
Definition: PixelBuffer.h:560
Find a PixelBuffer data array of a specific pixel type.
Definition: PixelBuffer.h:856
bool operator>=(const PixelBuffer &rhs) const
Greater than or equal comparison with a pixel buffer.
Definition: PixelBuffer.h:710
PixelBuffer< T >::array_ref_type * operator()(U &v) const
PixelBuffer of any type.
Definition: PixelBuffer.h:846
boost::detail::multi_array::extent_gen< dimensions > range_type
Extent range type.
Definition: PixelBuffer.h:123
bool operator==(const PixelBuffer &rhs) const
Compare a pixel buffer for equality.
Definition: PixelBuffer.h:590
boost::multi_array_types::size_type size_type
Size type.
Definition: PixelBuffer.h:110
PixelBuffer(const PixelBuffer &buffer)
Copy constructor.
Definition: PixelBuffer.h:365
array_ref_type & array()
Get the pixel data.
Definition: PixelBuffer.h:878
const ::ome::xml::model::enums::PixelType pixeltype
Pixel type stored in this buffer.
Definition: PixelBuffer.h:195
static const uint16_t dimensions
Total number of supported dimensions.
Definition: PixelBuffer.h:107
PixelBuffer()
Default constructor.
Definition: PixelBuffer.h:260
Spatial z dimension (Z).
Definition: PixelBuffer.h:82
boost::multi_array< value_type, dimensions > array_type
Type for multi-dimensional pixel array view.
Definition: PixelBuffer.h:252
PixelBuffer(const ExtentList &extents,::ome::xml::model::enums::PixelType pixeltype=::ome::xml::model::enums::PixelType::UINT8, EndianType endiantype=ENDIAN_NATIVE, const storage_order_type &storage=PixelBufferBase::default_storage_order())
Construct from extents (internal storage).
Definition: PixelBuffer.h:279
static storage_order_type default_storage_order()
Generate default storage ordering.
Definition: PixelBuffer.cpp:133
const EndianType endiantype
Endian type stored in this buffer.
Definition: PixelBuffer.h:198
std::array< boost::multi_array_types::index, PixelBufferBase::dimensions > indices_type
Type used to index all dimensions in public interfaces.
Definition: PixelBuffer.h:117
Logical subdivision of the spatial z dimension (z).
Definition: PixelBuffer.h:86
Logical channel (typically detectors of specific wavelengths) (C).
Definition: PixelBuffer.h:84
bool operator<=(const PixelBuffer &rhs) const
Less than or equal comparison with a pixel buffer.
Definition: PixelBuffer.h:662
T value_type
Pixel value type.
Definition: PixelBuffer.h:239
const value_type * data() const
Get the raw data.
Definition: PixelBuffer.h:415
Logical sub-channel (typically used for RGB channel sub-components) (S).
Definition: PixelBuffer.h:85