X
2853

IDLgrVolume - cube example

A volume object represents a mapping from a three-dimensional array of data to a three-dimensional array of voxel colors, which, when drawn, are projected to two dimensions. 

You can use the IDLgrVolume object, which is an atomic graphic object and one of the basic drawable elements of the IDL Object Graphics system, to create volumes.  Below is a code example on how to create a cubic volume and manipulate the portions of the cube that are and are not seen.
 

pro obj_volume

  data = BYTARR(64, 64, 64)
 
  for ii = 0B, 63 do begin
    data[*, ii, *] = ii*20B
  endfor
  zeroIndex = WHERE(data EQ 0, count)
  IF (count NE 0) THEN data[zeroIndex]=255B
 
  MasterData = data
  data[31:63, 32:63, 32:63]=0
 
  LOADCT, 5
  TVLCT, r, g, b, /get
  ctable = bytarr(256, 3)
  ctable[*, 0] = r
  ctable[*, 1] = g
  ctable[*, 2] = b
 
  opacTbl = bytarr(256) + 255B
  opacTbl[0] = 0
 
  ;create volume object
  oVol = obj_new("IDLgrVolume", data, $
    DEPTH_CUE=[-.5, 1], $
    RGB_TABLE0=ctable, $
    OPACITY_TABLE0 = opacTbl, $
    /ZERO_OPACITY_SKIP)
   
  oVol -> GetProperty, XRANGE=xr, YRANGE=yr, ZRANGE=zr
  oVol -> SetProperty, xcoord_conv = [ -.5, 1/(xr[1]-xr[0]) ], $
    ycoord_conv = [ -.5, 1/(yr[1]-yr[0]) ], $
    zcoord_conv = [ -.5, 1/(zr[1]-zr[0]) ]
   
  ; Create a model for the sphere.
  oModel = OBJ_NEW('IDLgrModel')
  ; Create a view in which to place the model.
  ;
  oView = OBJ_NEW('IDLgrView', VIEWPLANE_RECT = [-1,-1,2,2], $
    Location = [-1, -1], ZCLIP = [1,-1])
   
  oModel->Add, oVol
  oView->Add, oModel
 
  oWindow = OBJ_NEW('IDLgrWindow', DIMENSIONS = [300,300], $
    TITLE = 'Volume Example', renderer = 0);, RETAIN = 2)
  ; Render the volume with various cutting planes.
  ;
  ; None.
  ;
  oModel->Rotate, [0,1,0], -30
  oModel->Rotate, [1,0,0], 20
  oWindow->Draw, oView
  WAIT, 1
 
  data = MasterData
  data[31:63, 0:31, 32:63]=0
 
  oVol-> SetProperty, data0 = data
  oWindow->draw, oView
  wait, 1
 
  data = MasterData
  data[15:45, 32:63, 32:63]=0
 
  oVol-> SetProperty, data0 = data
  oWindow->draw, oView
  wait, 1
 
  data = MasterData
  data[15:45, 32:63, 15:63]=0
  data[15:63, 32:63, 15:45]=0
  oVol-> SetProperty, data0 = data
  oWindow->draw, oView
 
end

The resulting volume should look like the following:

Review on 12/31/2013 MM