VolumeRendering
Cross Section Example
← Axis-Aligned Cross Sections | ● | Cutting Planes →
Let (x,y) be the intersection point of two axis-aligned vertical planes and n be the uniform size of the 3D texture (in voxels), then the OpenGL code to render those is given as follows:
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glTranslated(0.5/n,0.5/n,0.5/n);
glScaled((n-1.0)/n,(n-1.0)/n,(n-1.0)/n);
glTranslated(0.5,0.5,0.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(...);
glRotated(90,1,0,0);
glBegin(GL_QUADS);
glTexCoord3d(x,-0.5,-0.5);
glVertex3d(x,-0.5,-0.5);
glTexCoord3d(x,0.5,-0.5);
glVertex3d(x,0.5,-0.5);
glTexCoord3d(x,0.5,0.5);
glVertex3d(x,0.5,0.5);
glTexCoord3d(x,-0.5,0.5);
glVertex3d(x,-0.5,0.5);
glTexCoord3d(-0.5,y,-0.5);
glVertex3d(-0.5,y,-0.5);
glTexCoord3d(0.5,y,-0.5);
glVertex3d(0.5,y,-0.5);
glTexCoord3d(0.5,y,0.5);
glVertex3d(0.5,y,0.5);
glTexCoord3d(-0.5,y,0.5);
glVertex3d(-0.5,y,0.5);
glEnd();
glLoadIdentity();
glTranslated(0.5/n,0.5/n,0.5/n);
glScaled((n-1.0)/n,(n-1.0)/n,(n-1.0)/n);
glTranslated(0.5,0.5,0.5);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(...);
glRotated(90,1,0,0);
glBegin(GL_QUADS);
glTexCoord3d(x,-0.5,-0.5);
glVertex3d(x,-0.5,-0.5);
glTexCoord3d(x,0.5,-0.5);
glVertex3d(x,0.5,-0.5);
glTexCoord3d(x,0.5,0.5);
glVertex3d(x,0.5,0.5);
glTexCoord3d(x,-0.5,0.5);
glVertex3d(x,-0.5,0.5);
glTexCoord3d(-0.5,y,-0.5);
glVertex3d(-0.5,y,-0.5);
glTexCoord3d(0.5,y,-0.5);
glVertex3d(0.5,y,-0.5);
glTexCoord3d(0.5,y,0.5);
glVertex3d(0.5,y,0.5);
glTexCoord3d(-0.5,y,0.5);
glVertex3d(-0.5,y,0.5);
glEnd();