[vtkusers] Visualizing a 3D Array using Gray Scale

Dave Ardrey daveardrey at gmail.com
Tue Mar 13 12:46:53 EDT 2007


Hello all,

I am a relatively new VTK user.  I am attempting to visualize an array of
floats by displaying each of them as a cube with a gray-scale  values
spanning the range of the floats.  I was thinking about trying to manually
enter the data into a vtkImageData class which I have had success in working
with before.  However, I am having no luck with this, as it appears that all
the values are being mapped to 255 (the highest intensity value).

Any suggestions as to how I could proceed in this direction, or even
suggestions of a different method to try would be extremely helpful.  Links
to documentation or examples would also help.

I've attached my code below up through just before rendering.

Thanks!

Dave

  vtkImageData *realData = vtkImageData::New();
  //vtkFloatArray *scalars = vtkFloatArray::New();
  int dim[3];
  dim[0] = 255;
  dim[1] = 255;
  dim[2] = 255;

  float *temp;

  realData->SetDimensions(dim);
  realData->SetScalarTypeToFloat();
  realData->SetNumberOfScalarComponents(1);
  realData->AllocateScalars();

  float *ptr = (float *) realData->GetScalarPointer();
  for (int i = 0; i<255*255*255 ; i++)
  {
      *ptr++ = i;
  }
 //scalars->Delete();

vtkFixedPointVolumeRayCastMapper *volumeMapper =
vtkFixedPointVolumeRayCastMapper::New();
volumeMapper->SetInput(realData);

 vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
 volumeProperty->IndependentComponentsOff();
 volumeProperty->SetScalarOpacity(tfun);

 vtkVolume *newvol = vtkVolume::New();
 newvol->SetMapper(volumeMapper);
 newvol->SetProperty(volumeProperty);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20070313/61cb6f0a/attachment.htm>


More information about the vtkusers mailing list