I'm debugging some volumetric data in c++ and would like to visualise it.
Say I have a double array in c++, how can I write it as a binary file and read it from numpy as a 3D array? I'd like to stick to the standard c++ library.
double myArr[1000];
// ...Set values of myArr
std::ofstream outFile;
std::open("myfile.bin");
for (int i = 0; i < 10; i++) {
for (int j = 0; j < 10; j++) {
for (int k = 0; k < 10; k++) {
outFile << myArr[k + j*10 + i*100];
}
outFile << "some way to declare the next slice";
}
outFile << "some way to declare the next slice";
}
outFile.close();
In python I would like to read this array like this so it would appear as a 3D array:
numpy.fromfile("myfile.bin", dtype=np.float)
I read this Writing binary in c++ and read in python which works for 1d int but not sure how to create 3D double. ie. what do I need to write to the array to tell it to shift by 1 along each dimension? I don't want to use numpy to reshape the array as the dimension output by c++ can vary.