[vtkusers] How to render this simple .vtk file as volume

Yaoyu Hu huyaoyu1986 at gmail.com
Fri Jun 24 10:35:03 EDT 2011


Hi everybody,

My name is Yaoyu Hu, I'm new here.
I got some problem while I was tring to render a simple .vtk file as volume.
The .vtk file is as follows (volume_test.vtk)
===================BEGIN====================
# vtk DataFile Version 2.0
Volume_example

ASCII

DATASET STRUCTURED_POINTS
DIMENSIONS 3 4 6
ASPECT_RATIO 1 1 1
ORIGIN 0.0 0.0 0.0

POINT_DATA 72

SCALARS vs unsigned_short 1
LOOKUP_TABLE lt
0.0 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
0.0 5.0  10.0 15.0 20.0 25.0 25.0 20.0 15.0 10.0 5.0  0.0
0.0 10.0 20.0 30.0 40.0 50.0 50.0 40.0 30.0 20.0 10.0 0.0
0.0 10.0 20.0 30.0 40.0 50.0 50.0 40.0 30.0 20.0 10.0 0.0
0.0 5.0  10.0 15.0 20.0 25.0 25.0 20.0 15.0 10.0 5.0  0.0
0.0 0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0  0.0
LOOKUP_TABLE lt 72
0.5 0.0 0.0 0.5
0.5 0.0 0.0 0.5
...(There are 70 more lines of "0.5 0.0 0.0 0.5"s )

=================END=====================================
I studied the example for "ironProt.vtk" of the user guide and wrote the
follows codes.
The ironProt.vtk file was rendered correctly, buy the way.
================BEGIN====================================
        vtkStructuredPointsReader *vreader =
vtkStructuredPointsReader::New();
vreader->SetFileName(("volume_test.vtk"));

vtkPiecewiseFunction *opacityTransferFunction = vtkPiecewiseFunction::New();
opacityTransferFunction->AddPoint(10,0.0);
opacityTransferFunction->AddPoint(50,0.2);
vtkColorTransferFunction *colorTransferFunction =
vtkColorTransferFunction::New();
colorTransferFunction->AddRGBPoint(  0.0,0.1,0.0,0.0);
colorTransferFunction->AddRGBPoint( 10.0,1.0,0.0,0.0);
colorTransferFunction->AddRGBPoint( 20.0,0.0,0.0,1.0);
colorTransferFunction->AddRGBPoint( 30.0,0.0,2.0,0.0);
colorTransferFunction->AddRGBPoint( 50.0,1.0,0.2,0.0);

vtkVolumeProperty *volumeProperty = vtkVolumeProperty::New();
volumeProperty->SetColor(colorTransferFunction);
volumeProperty->SetScalarOpacity(opacityTransferFunction);
 vtkVolumeRayCastCompositeFunction *compositeFunction =
vtkVolumeRayCastCompositeFunction::New();
vtkVolumeRayCastMapper *volumeMapper = vtkVolumeRayCastMapper::New();
volumeMapper->SetVolumeRayCastFunction(compositeFunction);

volumeMapper->SetInputConnection(vreader->GetOutputPort()); //NOTE

vtkVolume *vvolume = vtkVolume::New();
vvolume->SetMapper(volumeMapper);
(the other codes have no relation to the .vtk file)
===============END=====================================
However, I got this warning from the renderer when I was tring to debug the
program.
And there was a cube of black and white surfaces.
==============BEGIN=====================================
Generic Warning: In ..\..\IO\vtkDataReader.cxx, line 1382
Error reading ascii data. Possible mismatch of datasize with declaration.
===============END===================================
When I read in the same .vtk file(volume_test.vtk) on paraView,
the same warining showed up.
If I turn the volume rendering up, paraView shows the right volume
rendering
result with colors and opacity.

How can I render it file as volume in vtk?
Do I have to write a lookup table if I am using "vtkColorTransferFunction"?

I am running vtk 5.6 on Windows 7 64bit with Visual Studio 2008. VTK
is compiled and installed from source codes.

Thank you all!!

---------------
Yaoyu Hu (from China)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110624/3caffcae/attachment.htm>


More information about the vtkusers mailing list