[vtkusers] Visualizing a 3D Array using Grey Scale Values

Dave Ardrey daveardrey at gmail.com
Tue Feb 6 10:06:14 EST 2007


Hello all,

I am a relatively new VTK user.  I am attempting to visualize an array of
floats by manually entering them into a vtkImageData class.  I have made a
test program, but it appears that all the values are being mapped to 255
(the highest intensity value).  I see that in the vtkImageData there is a
vtkDataSet which has a ScalarRange which has the max and min set to 1.0 and
0.0.  Do I need to change this somehow to match my data?  And if so, how
would I go about it?

Any help would be greatly appreciated.  I have attached my code up to right
before rendering below.

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/20070206/62eeae7f/attachment.htm>


More information about the vtkusers mailing list