[vtkusers] Using a VTK file (volume rendering)

Guilherme Ferraz de Arruda guiep at yahoo.com.br
Thu Oct 1 00:05:11 EDT 2009


Hi, I read this piece of code in C++, it works ok, but i can't
understand exactly why i use vtkPiecewiseFunction in a
vtkVolumeProperty->SetColor and vtkVolumeProperty->SetScalarOpacity.
The code is:

	vtkRenderer *aren = vtkRenderer::New();
	vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->AddRenderer(aren);
	vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
    iren->SetRenderWindow(renWin);

	aren->SetBackground(0.8, 0.8, 0.8);

	vtkDataSetReader *reader = vtkDataSetReader::New();
	reader->DebugOn();
    reader->SetFileName("heart.vtk");
	reader->Update();
	
	vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
	oTFun->AddSegment(80, 0.0, 255, 1.0);
	oTFun->AddSegment(0, 255, 0, 0);

	vtkPiecewiseFunction *gTFun = vtkPiecewiseFunction::New();
	gTFun->AddSegment(80, 0.0, 255, 1.0);
	gTFun->AddSegment(0, 255, 0, 0);

	vtkVolumeProperty *volProperty = vtkVolumeProperty::New();
	volProperty->SetColor(gTFun);
	volProperty->SetScalarOpacity(oTFun);
	volProperty->SetInterpolationTypeToLinear();
	volProperty->ShadeOn();

	vtkVolumeRayCastCompositeFunction *cpf =
vtkVolumeRayCastCompositeFunction::New();

	vtkVolumeRayCastMapper *volmap = vtkVolumeRayCastMapper::New();
	volmap->SetInput(reader->GetOutput());
	volmap->SetVolumeRayCastFunction(cpf);

	vtkVolume *vol = vtkVolume::New();
	vol->SetMapper(volmap);
	vol->SetProperty(volProperty);

	aren->AddVolume(vol);

	iren->Initialize();
	iren->Start();


I'm new with VTK, sugestions are welcome,
The problem is how to visualize an VTK file, with volume rendering.

Thanks for all!



More information about the vtkusers mailing list