This code demonstrates how to create a vertical gradient image with values between 0.0 and 5.0.
This code demonstrates how to create a vertical gradient image with values between 0.0 and 5.0.Lines are written one by one from the bottom to the top.
#include <iomanip>
#include <iostream>
#include <vector>
#include <iolink/view/ImageViewFactory.h>
std::shared_ptr<ImageView>
{
std::shared_ptr<ImageView> image = ImageViewFactory::allocate(shape, dt);
std::vector<float> lineBuffer(shape[0]);
std::cout << "Writing data line by line" << std::endl;
const float stepLine = 5.0f / shape[1];
float valueInit = 0;
float valueToSet = valueInit;
for (size_t j = 0; j < shape[1]; ++j)
{
std::fill(lineBuffer.begin(), lineBuffer.end(), valueToSet);
image->writeRegion(lineRegion, lineBuffer.data());
valueToSet = valueInit + j * stepLine;
}
std::cout << "Writing completed" << std::endl;
return image;
}
static void
displayImageContent(std::shared_ptr<ImageView> image)
{
RegionXu64 fullRegion = RegionXu64::createFullRegion(image->shape());
image->readRegion(fullRegion, buffer.data());
std::cout << "Image content: " << std::endl;
for (size_t j = 0; j < shape[1]; ++j)
{
for (size_t i = 0; i < shape[0]; ++i)
{
std::cout << std::setw(8) << buffer[i + j * shape[0]] << " ";
}
std::cout << std::endl;
}
std::cout << std::endl;
}
int
main(int argc, char** argv)
{
std::shared_ptr<ImageView> image = gradientFloatImage({5, 30});
std::cout << "Shape of created image: " << image->shape() << std::endl;
displayImageContent(image);
return EXIT_SUCCESS;
}
Stores information about a data type.
Definition DataType.h:162
A Region using dynamic vectors.
Definition RegionX.h:14
size_t elementCount() const
Returns the number of cells in this region.
A dynamically sized arithmetic vector.
Definition VectorX.h:18
All IOLink symbols are enclosed in this namespace.
Definition ArrayX.h:8