[vtkusers] 3D volume rendering
Artem Babayan
artem.paraview at googlemail.com
Sat May 1 10:23:31 EDT 2010
Hello,
I am trying to obtain rendering of 3D concentration data defined on
structured grid. An objective is to get semi-transparent 3D volume.
For some reasons what I am apparently getting is the slice of data on
some surface (??) (see attached screenshots). I am surely doing
something wrong, but what? The source code is below.
Thank you for any help
Best wishes
Artem
//read the volume from file
vtkSmartPointer<vtkStructuredPointsReader> reader_conc=
vtkSmartPointer<vtkStructuredPointsReader>::New();
reader_conc->SetFileName("conc_3d.vtk");
//Create a mapper
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper> mapper_conc =
vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
mapper_conc->SetInput(reader_conc->GetOutput());
//create volume
vtkSmartPointer<vtkVolume> volume =
vtkSmartPointer<vtkVolume>::New();
//let it be semitransparent for all data
vtkPiecewiseFunction *oTFun = vtkPiecewiseFunction::New();
oTFun->AddPoint(0., 0.5, 0.5, 1.0);
oTFun->AddPoint(1.5, 0.5, 0.5, 1.0);
//color transfer function -- blue for empty and red for high concentration
vtkColorTransferFunction *cTFun = vtkColorTransferFunction::New();
cTFun->AddRGBPoint( 0.0, 0.0, 0.0, 1 );
cTFun->AddRGBPoint( 1e-25, .0, .1, .8 );
cTFun->AddRGBPoint( 1e-15, .1, .3, 0.6 );
cTFun->AddRGBPoint( 1.3, 1.0, .0, 0.0 );
//set volume property
vtkVolumeProperty *property = vtkVolumeProperty::New();
property->SetScalarOpacity(oTFun);
property->SetColor(cTFun);
property->SetInterpolationTypeToLinear();
property->SetScalarOpacityUnitDistance(2.0);
volume->SetMapper(mapper_conc);
volume->SetProperty(property);
// a renderer and render window
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
renderer->SetBackground(0.9, 0.9, 0.9);
renderer->ResetCamera();
renderer->GetActiveCamera()->Dolly(1);
renderer->ResetCameraClippingRange();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->SetSize(900, 600);
renderWindow->AddRenderer(renderer);
// add the volume to renderer
renderer->AddVolume(volume);
// an interactor
vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
iren->SetRenderWindow(renderWindow);
renderWindow->Render();
// begin mouse interaction
iren->Start();
return 0;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pic_0.png
Type: image/png
Size: 13430 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100501/a7f7ae6e/attachment.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pic_1.png
Type: image/png
Size: 13799 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100501/a7f7ae6e/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pic_2.png
Type: image/png
Size: 15956 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100501/a7f7ae6e/attachment-0002.png>
More information about the vtkusers
mailing list