[vtkusers] Volume rendering example

Lodron, Gerald Gerald.Lodron at joanneum.at
Wed Oct 28 05:13:03 EDT 2009


Hi,
 
I want to render a volume using VTK but i have some problems, may anyone can help me a little bit: 
I have a 3d volume of a human CT scan, the range is in hountsfield units so we have signed char. I want to render it like in "The Visualization Toolkit - Will Schroeder, Ken Martin, Bill Lorensen" book on page 233 but the author does not provide any code of his results (also not on the CD). 
 
//First get the range of my image
double *range = data->GetScalarRange();
//Scale the image between 0 and 1 using a lookup table
vtkLookupTable *table = vtkLookupTable::New();
table->SetValueRange(0,1);
table->SetSaturationRange(0,0);
table->SetRange(range[0], range[1]); //shoul here not be the minimum/maximum possible of "data"?
table->SetRampToLinear();
table->Build();

// Map the image through the lookup table
vtkImageMapToColors *color = vtkImageMapToColors::New();
color->SetLookupTable(table);
color->SetInputConnection(data->GetProducerPort());

//The opacity function should map the data from invisible to visible
vtkPiecewiseFunction *opacityTransferFunction=vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint(0,0.0);
opacityTransferFunction->AddPoint(1,0.2);	//should it be (1,0.2) or (255, 0.2)? Shouldnt it be like table->SetValueRange(0,1)?

//Color the image from black to white, does anybody has some good color functions for me??
vtkColorTransferFunction *colorTransferFunction = vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(0,0.0,0.0,0.0);
colorTransferFunction->AddRGBPoint(1,1.0,1.0,1.0);

//Generate a volume Property
vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
volumeProperty->SetInterpolationTypeToLinear();

//I do not exactly know what this stuff does but it renders:
vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volumeMapper=vtkVolumeRayCastMapper::New();
volumeMapper->SetInputConnection(color->GetOutputPort());
volumeMapper->SetVolumeRayCastFunction(compositeFunction);

vtkLODProp3D *prop = vtkLODProp3D::New();
prop->AddLOD(volumeMapper,volumeProperty, 0.0);
m_Renderer->AddViewProp(prop);

m_Renderer->Render();

Does this code seems right? I only see a strange cube




More information about the vtkusers mailing list