Volume Object


Introduction

A Volume object is used to display 3D voxel data. Although there are many methods in volume rendering, the methods used in View3D are limited by the OpenGL capabilities. There are two methods used in View3D. One is the point_base algorithm and the other is using the OpenGL 3D texture extension. The second method generates a much faster and better quality volume than the first one, but it requires the texture map hardware. The Volume object can be generated by calling the function
XintView3DCreateVolume. Unlike other types of objects, it only required a single color material for outline color. Also, the material editor will not work with the volume object.

Limitations

A Volume object has the following limitations when using the render method XintVRM_3D_TEXTURE. Currently only 8-bit voxel data is supported. It can only be used on a machine with texture map hardware. The dimensions of the voxel data must be a power of 2.

Example

The following code example (see file volume_demo.c in example directory) illustrates how to create a Volume object with the render method, XintVRM_3D_TEXTURE.

   ... 
   unsigned char *voxel;
   unsigned char *color_table;
   float *alpha_table;
   int x_dim, y_dim, z_dim;

   voxel = read_seismic("../Data/data0.vol", &x_dim, &y_dim, &z_dim);

   /* alpha and color tables */
   alpha_table = (float *)malloc(256 * sizeof(float));
   *color_table = (unsigned char *)malloc(256 * 3 * sizeof(unsigned char));
   for (i = 0; i < 256; i++) {
        color_table[i*3] = i
        color_table[i*3+1] = i;
        color_table[i*3+2] = i;
        alpha_table[i] = (float)i/255.0;
   }

   /* Create a volume object */
   volume = XintView3DCreateVolume("volumeObject",  
                                  XintVF_I,        
                                  XintVD_UCHAR,    
                                  XintVAM_COLOR_TABLE,    
                                  alpha_table,    
                                  256,               
                                  XintVCM_COLOR_TABLE,    
                                  color_table,       
                                  256*3,               
                                  0,
                                  255,             
                                  0.0,             
                                  1.0, 
                                  x_dim,           
                                  y_dim,           
                                  z_dim,           
                                  (unsigned char *)voxel,
                                  XintVRM_3D_TEXTURE,
                                  NULL);                 

   XintView3DSetColor4ByName(view3d, "Green", color.single);
   material = XintView3DCreateMaterial(NULL, XintMATERIAL_SINGLE_COLOR,
                                       &color, 0, NULL);
                                        
   XintView3DAddObjectAndMaterial(view3d, volume, material, NULL);

The output of example volume_demo.c is shown below.

Figure 18: Volume example