문제

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?

enter image description here

도움이 되었습니까?

해결책

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?

By loading the image as a 3D array and indexing it. Not by loading it as an OpenGL texture.

Will glTexCoord3f give me its intensity on a given x,y,z?

No. As the documentation states, glTexCoord3f simply 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.

Is it better to do a x,y,z conversion from the pVolume array directly?

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.

다른 팁

I think you're confusing a few things here. OpenGL is not a image processing library. It's a rasterizer API. 3D Textures are not meant as something you load data to and are given arbitrary access. You load 3D textures to map them onto surfaces, or use them in direct volume rendering.

Extracting isosurfaces is outside the scope of OpenGL.

RAW file just means that there is no header and you must know the data layout before being able to do something with it. You need to know

  • width
  • height
  • depth
  • bytes per value The value(s) at x,y,z can then be found at the data offset

    (width*height*z + width*y + z)*(bytes)

Isovalue just means all pixels of the data set equal to a given value. Normally you're interested in pixels which are neighboured by each a pixel below and above isovalue. For efficient determination first determine the gradient of the scalar field for each pixel. Then you test the neighbour pixels along the gradient if they're above or below the isovalue. No OpenGL involved here!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top