I want to evaluate the values of the surface to implement a marching tetrahedron algorithm, but I don't understand how to work with .raw unformatted data.
After loading a .raw file with a volume dataset into a 1D byte array, what arithmetic transformation should be applied to get the value associated to X,Y,Z from it? This is the only way I know to load .raw files, could I create a 3D byte array instead of this? How?
int XDIM=256, YDIM=256, ZDIM=256;
const int size = XDIM*YDIM*ZDIM;
bool LoadVolumeFromFile(const char* fileName) {
FILE *pFile = fopen(fileName,"rb");
if(NULL == pFile) {
return false;
}
GLubyte* pVolume=new GLubyte[size]; //<- here pVolume is a 1D byte array
fread(pVolume,sizeof(GLubyte),size,pFile);
fclose(pFile);
The way you'd index the datum at (x, y, z) is:
Behind the scenes, this is what the C compiler does for you if you write:
It only works that simply because C indexes from 0; if the language indexed from 1, you'd have to revise the calculation to achieve the net result obtained by subtracting one from each of x, y and z before doing the indexing.
Auxilliary Question
Given (where the numeric values don't really matter):
the datum at (x, y, z) in 1D array
pData
is found at:The value of DIMz serves primarily for validation:
0 <= z < DIMz
(using mathematical rather than C notation), and in parallel0 <= x < DIMx; 0 <= y <= DIMy
. The C notation forz
is0 <= z && z < DIMz
; repeat mutatis mutandis forx
andy
.