17#ifndef __fixel_legacy_image_h__
18#define __fixel_legacy_image_h__
29#error File that #includes "fixel/legacy/image.h" must explicitly #include "image.h" beforehand
40 template <
typename DataType>
45 uint32_t size()
const {
return io.get_numel (
offsets.value()); }
47 void set_size (
const uint32_t n)
55 DataType& operator[] (
const size_t i)
57 uint8_t*
const ptr =
io.get (
offsets.value(), i);
58 return *(
reinterpret_cast<DataType* const
>(ptr));
60 const DataType& operator[] (
const size_t i)
const
62 const uint8_t*
const ptr =
io.get (
offsets.value(), i);
63 return *(
reinterpret_cast<const DataType* const
>(ptr));
69 set_size (that.size());
70 for (uint32_t i = 0; i != size(); ++i)
77 stream <<
"Position [ ";
78 for (
size_t n = 0; n <
value.offsets.ndim(); ++n)
79 stream <<
value.offsets.index(n) <<
" ";
80 stream <<
"], offset = " <<
value.offsets.value() <<
", " <<
value.size() <<
" elements";
98 template <
typename DataType>
102 Image (
const std::string& image_name) :
110 Image (
const std::string& image_name,
const Header& template_header) :
113 using value_type = uint64_t;
125 throw Exception (
"cannot create sparse image for image with no handler");
128 throw Exception (
"cannot create sparse image to access non-sparse data");
131 if (name_it ==
keyval().end())
132 throw Exception (
"cannot create sparse image without knowledge of underlying class type in the image header");
138 if (size_it ==
keyval().end())
139 throw Exception (
"cannot create sparse image without knowledge of underlying class size in the image header");
140 const size_t class_size = to<size_t>(size_it->second);
142 throw Exception (
"class size of sparse image does not match that in image header");
ImageIO::SparseLegacy * io
::MR::Image< uint64_t > & offsets
ImageIO::SparseLegacy & io
friend std::ostream & operator<<(std::ostream &stream, const Value &value)
const std::string & name() const
std::shared_ptr< Buffer > buffer
shared reference to header/buffer
const KeyValues & keyval() const
get generic key/value text attributes
VectorType::Scalar value(const VectorType &coefs, typename VectorType::Scalar cos_elevation, typename VectorType::Scalar cos_azimuth, typename VectorType::Scalar sin_azimuth, int lmax)
const std::string size_key("sparse_data_size")
const std::string name_key("sparse_data_name")
std::string str(const T &value, int precision=0)