IOLink 1.11.0
Loading...
Searching...
No Matches
DiskImageView.cpp

This code demonstrates how to create an image view on disk and write/read data to/from it.

This code demonstrates how to create an image view on disk and write/read data to/from it.The code creates a 3D image of size 100x100x100 without allocating any CPU memory, and writes a line of data in each slice. Finally, it then reads and prints the value of the last written sample .

#include <iostream>
#include <vector>
#include <iolink/view/ImageViewFactory.h>
using namespace iolink;
std::shared_ptr<ImageView>
diskImageView()
{
const VectorXu64 shape = VectorXu64{100, 100, 100};
const DataType dt = DataTypeId::DOUBLE;
// create an image view on disk
auto image = ImageViewFactory::createOnDisk(shape, dt);
std::vector<double> lineBuffer(shape[0]);
const VectorXu64 lineSize{shape[0], 1, 1};
std::cout << "Writing data slice by slice, line by line" << std::endl;
// write data slice by slice, line by line with a growing value
double valueInit = 0;
for (size_t i = 0; i < shape[2]; ++i)
{
for (size_t j = 0; j < shape[1]; ++j)
{
const RegionXu64 lineRegion(VectorXu64{0, j, i}, lineSize);
std::fill(lineBuffer.begin(), lineBuffer.end(), valueInit);
image->writeRegion(lineRegion, lineBuffer.data());
valueInit++;
}
}
std::cout << "Writing completed" << std::endl;
return image;
}
int
main(int argc, char** argv)
{
auto image = diskImageView();
std::cout << "Reading Last Sample" << std::endl;
double value;
image->read(VectorXu64{99, 99, 99}, &value);
std::cout << "Last Sample Value: " << value << std::endl;
return EXIT_SUCCESS;
}