[vtkusers] Volume Rendering using RayCastMapper
Prasenjit Roy
roy_prasenjit at yahoo.com
Wed Jan 11 12:33:59 EST 2006
dear vtkusers,
I am experiencing problem in volume rendeing using vtkvolumeRayCastMapper and using vtkVolumeRayCastCompositeFunction when I use a Color and opacity funtion to make most of my volume voxels transparent but viewing only some specific scalar range values. I am getting a "VTK RENDERING ERROR" and the execution time is terribly slow for a moderate size voxel (50,50,50).
I know that, I might be doing something wrong as it is very common to see a floating volume using VTK and also in VolView.
Please let me know your views. Any help is highly appreciated. Please find below the sample code.
Many Thanks.
Prasenjit Roy.
// Image Data 8bit [data8bit is an input]
vtkImageData *image3Ddata = vtkImageData::NEW;
image3Ddata->SetDimensions(dim[0],dim[1],dim[2]);
image3Ddata->SetOrigin(org[0],org[1],org[2]);
image3Ddata->SetSpacing(sp[0],sp[1],sp[2]);
image3Ddata->SetScalarTypeToUnsignedChar();
image3Ddata->SetNumberOfScalarComponents(1);
image3Ddata->AllocateScalars();
unsigned char *ptr8 = (unsigned char *) image3Ddata->GetScalarPointer();
ubound = (dim[0]*dim[1]*dim[2]);
for (k=0; k<ubound; k++)
{
*ptr8++ = (unsigned char) data8bit[k];
}
// Set Opacity
vtkPiecewiseFunction *opacityFn = vtkPiecewiseFunction::New();
opacityFn->RemoveAllPoints();
opacityFn->AddPoint(200,0.2); // Scalar value ranges from [0 to 255]-8bit image data
opacityFn->AddPoint(225,1);
opacityFn->AddPoint(255,0.2);
// Set Color
vtkColorTransferFunction *colorFn = vtkColorTransferFunction::New();
for(i=0;i<nColors;i++)
{
cgp3d_colorFn->AddRGBPoint(cValue[i],R[i],G[i],B[i]);
}
//Vol Property
vtkVolumeProperty *volProp = vtkVolumeProperty::New();
volProp->ShadeOn();
volProp->SetInterpolationTypeToLinear();
volProp->SetScalarOpacity(opacityFn);
volProp->SetColor(colorFn);
vtkVolumeRayCastCompositeFunction *raycastFn = vtkVolumeRayCastCompositeFunction::New();
raycastFn->SetCompositeMethodToClassifyFirst();
vtkVolumeRayCastMapper *volMapper = vtkVolumeRayCastMapper::New();
volMapper->AutoAdjustSampleDistancesOn();
volMapper->SetMinimumImageSampleDistance(1);
volMapper->IntermixIntersectingGeometryOn();
volMapper->SetVolumeRayCastFunction(cgp3d_raycastFn);
volMapper->SetInput(image3Ddata); // image3Ddata is vtkImageData
vtlVolume *volActor = vtkVolume::New();
volActor->SetMapper(volMapper);
volActor->SetProperty(volProp);
ren1->AddVolume(volActor);
Prasenjit Roy
Home Address:
1032 E Lindsey St, #H; Norman, OK-73071
Cell: 405-227-7463
Home: 405-366-8216
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20060111/25b2de60/attachment.htm>
More information about the vtkusers
mailing list