[vtkusers] Volume Mapping
KK
krishna at lucidindia.net
Fri Apr 25 11:16:41 EDT 2003
hi all
please colud anybody llok into the following code and tell me where the error exactly is.
I took most of the following code from the Python example
vtk42\Examples\VolumeRendering\Python\SimpleRayCast.py
The only change is instead of vtkStructuredPointsReader i'm using vtkStructuredPoints
void VolumeMapper(void)
{
// Create the standard renderer, render window and interactor
vtkRenderer *ren = vtkRenderer::New();
vtkRenderWindow *renWin = vtkRenderWindow::New();
renWin->AddRenderer(ren);
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renWin);
vtkStructuredPoints *sp = vtkStructuredPoints::New();
sp->SetDimensions(5, 5, 5);
sp->SetOrigin(0, 0, 0);
sp->SetSpacing(2, 2, 2);
vtkUnsignedIntArray *scalars = vtkUnsignedIntArray::New();
scalars->SetNumberOfTuples(1);
scalars->SetNumberOfValues(64);
for (int i=0; i< 64; i++)
{
scalars->SetValue(i,125);
}
sp->GetCellData()->SetScalars(scalars);
// 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->ShadeOn();
//volumeProperty->SetInterpolationTypeToLinear();
// The mapper / ray cast function know how to render the data
vtkVolumeRayCastCompositeFunction *compositeFunction = vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
volumeMapper->SetVolumeRayCastFunction(compositeFunction);
volumeMapper->SetInput(sp); ----------------------------------->//here is the change from python code
// 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);
ren->AddVolume(volume);
ren->SetBackground(1, 1, 1);
//renWin->SetSize(600, 600);
//renWin->Render();
//renWin.AddObserver("AbortCheckEvent", CheckAbort)
//vtkActor *actor2 = vtkActor::New();
//actor2->SetMapper(volumeMapper);
//ren->AddActor(actor2);
int ipen = renWin->GetEventPending();
iren->Initialize();
renWin->Render();
iren->Start();
ren->Delete();
renWin->Delete();
iren->Delete();
opacityTransferFunction->Delete();
colorTransferFunction->Delete();
volumeProperty->Delete();
compositeFunction->Delete();
volumeMapper->Delete();
volume->Delete();
sp->Delete();
scalars->Delete();
}
thanks in advance
rgds
krishna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030425/2feca0fa/attachment.htm>
More information about the vtkusers
mailing list