I want to create a 3D visualizer of .raw volume medical datasets using marching tetrahedra.
I found this implementation on GPL license that looks nice and is based on the info by Paul Bourke, but I don’t know how to make work with a .raw file, which I’ve found people load as a 3d texture.
//assuming that the data at hand is a 256x256x256 unsigned byte data
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);
// now pVolume is passed to a 3d texture
//load data into a 3D texture
glGenTextures(1, &textureID);
glBindTexture(GL_TEXTURE_3D, textureID);
// set the texture parameters
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexImage3D(GL_TEXTURE_3D,0,GL_INTENSITY,XDIM,YDIM,ZDIM,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,pVolume);
delete [] pVolume;
return true;
}
I don’t know if I should either:
a) access the values directly from pValue
b) access them after loading them to a 3D texture
I have no idea of how I’m supposed to index pVolume to get the isosurface intensity at each x,y,z. if pVolume is a 1D array. I know x,y coordinates are mapped from a 1D array using a divide and a module, but how would I map x,y,z?
On the other hand, If I load the .raw file as a 3d texture would
glTexCoord3f
give me the isovalue at a given x,y,z?
Clarification: The question isn’t “can OpenGL draw an isosurface directly from this?” the question is how to index the isolevels on the .raw geometry, which is needed to evaluate each tetrahedron properly. On the image one can see that each tetrahedron case is marked based on whether the isosurface is above or below it. The isosurface is indexed on it’s x,y,z coordinates on the .raw file, how can I access it for each x,y,z on the dataset? Will glTexCoord3f give me its intensity on a given x,y,z? Is it better to do a x,y,z conversion from the pVolume array directly?

By loading the image as a 3D array and indexing it. Not by loading it as an OpenGL texture.
No. As the documentation states,
glTexCoord3fsimply provides a set of texture coordinates to the next vertex to be issued. It returns nothing, it doesn’t cause anything to happen yet. All it does is set state within OpenGL.Yes. Information in OpenGL should generally travel in one direction: from the user to the screen. OpenGL functions exist for you to feed OpenGL information that it will use to render something. That’s how OpenGL works best.
Any kind of back-tracking (reading images back to the CPU, etc) is a slow path.