[vtkusers] Volume Rendering problem
Anton Majourine
anton at gtsoft.spb.ru
Mon Mar 25 06:27:05 EST 2002
Hello vtkusers,
I am a beginner with VTK.
I use VTK volume rendering, but the frame rate is very slow.
VolView 1.3 operates with my dataset appr. 10 times faster.
Can anybody help?
System: Win2K, Radeon 8500 65K, MSVC++ 60
The code is:
CSize sz(366, 428);
int nFrames = 150;
vtkStructuredPoints* Points = vtkStructuredPoints::New();
// fill StructuredPoints
Points->SetDimensions(sz.cx, sz.cy, nFrames);
vtkUnsignedShortArray* scalars = vtkUnsignedShortArray::New();
scalars->Allocate(sz.cx * sz.cy * nFrames);
for(int k = 0; k < nFrames; k++)
{
int z = k * sz.cx * sz.cy;
for(int j = 0; j < sz.cy; j++)
{
int y = z + sz.cx * j;
for(int i = 0; i < sz.cx; i++)
{
scalars->InsertValue(y + i, ...);
}
}
}
Points->GetPointData()->SetScalars(scalars);
scalars->Delete();
//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);
volumeProperty->SetInterpolationTypeToNearest();
// The mapper / ray cast function know how to render the data
vtkVolumeRayCastCompositeFunction* compositeFunction = vtkVolumeRayCastCompositeFunction::New();
vtkOpenGLVolumeRayCastMapper* volumeMapper = vtkOpenGLVolumeRayCastMapper::New();
volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetInput(Points);
// create VolRen
vtkVolume* Vol = vtkVolume::New();
Vol->SetMapper(volumeMapper);
Vol->SetProperty(volumeProperty);
vtkRenderer *ren1= vtkRenderer::New();
ren1->SetBackground( 0.0, 0.0, 0.0 );
// set VolRen
ren1->AddVolume(Vol);
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->DoubleBufferOff();
renWin->AddRenderer( ren1 );
renWin->SetSize( 500, 500 );
renWin->StereoRenderOff();
vtkRenderWindowInteractor *Interactor = renWin->MakeRenderWindowInteractor();
renWin->Render();
Interactor->Start();
Best regards,
Anton
More information about the vtkusers
mailing list