[vtkusers] greyscale/color
Chunyan Jiang
jiang at TI.FhG.DE
Mon Oct 28 05:37:58 EST 2002
Dear VTK friends,
I import the greyscale image data from memery to vtkImageImport, then
transform the vtkImageImport to vtkStructuredPoints by
vtkImageToStructuredPoints. After that I use vtkVolumeRayCastMapper to
render the volume. It works now, however, the greyscale image changes to
color image. How can I render grey image? I attach the code below. Is there
something wrong? Any help is appreciated.
Code:
vtkImageImport *importer = vtkImageImport::New();
importer->SetWholeExtent(1,dimensions[0],1,dimensions[1],1,dimensions[2]);
importer->SetDataExtentToWholeExtent();
importer->SetDataScalarTypeToUnsignedChar();
importer->SetDataOrigin(0,0,0);
importer->SetDataSpacing(1,1,1);
importer->SetImportVoidPointer(data);//data is unsigned char* that storing
greyscale images data
vtkStructuredPoints* structPts= vtkStructuredPoints::New();
vtkImageToStructuredPoints* its=vtkImageToStructuredPoints::New();
its->SetInput(importer->GetOutput());
structPts=its->GetOutput();
// Create transfer mapping scalar value to opacity
vtkPiecewiseFunction *opacityTransferFunction =
vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint(20, 0.0);
opacityTransferFunction->AddPoint(255, 0.2);
// Create transfer mapping scalar value to color
vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(0.0, 0.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(64.0, 1.0, 0.0, 0.0);
colorTransferFunction->AddRGBPoint(128.0, 0.0, 0.0, 1.0);
colorTransferFunction->AddRGBPoint(192.0, 0.0, 1.0, 0.0);
colorTransferFunction->AddRGBPoint(255.0, 0.0, 0.2, 0.0);
// The property describes how the data will look
vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
// The mapper / ray cast function know how to render the data
vtkVolumeRayCastCompositeFunction *compositeFunction=
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetInput(structPts);//sp reader->GetOutput()
// The volume holds the mapper and the property and can be used to
position/orient the volume
vtkVolume *volume = vtkVolume::New();
volume->SetMapper(volumeMapper);
volume->SetProperty(volumeProperty);
renderer->AddActor(volume);
// interact with data
renWin->Render();
***********************************************************************
Chunyan Jiang, Dipl.-Inform.,
Institut for Telematic
Bahnhofstrasse 30-32, D-54292 Trier, Germany
Phone: (+49) (0)651-97551-34
Fax: (+49) (0)651-97551-12
***********************************************************************
More information about the vtkusers
mailing list