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>
std::shared_ptr<ImageView>
diskImageView()
{
auto image = ImageViewFactory::createOnDisk(shape, dt);
std::vector<double> lineBuffer(shape[0]);
std::cout << "Writing data slice by slice, line by line" << std::endl;
double valueInit = 0;
for (size_t i = 0; i < shape[2]; ++i)
{
for (size_t j = 0; j < shape[1]; ++j)
{
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;
std::cout << "Last Sample Value: " << value << std::endl;
return EXIT_SUCCESS;
}
Stores information about a data type.
Definition DataType.h:162
A Region using dynamic vectors.
Definition RegionX.h:14
A dynamically sized arithmetic vector.
Definition VectorX.h:18
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8