[vtkusers] Volume Rendering with multiple-array data

Randall Hand randall.hand at gmail.com
Wed Feb 16 12:29:16 EST 2005


I have a VTK Dataset with with multiple data values per point.  Each
data point in my rectilinear grid has both a scalar (fractional
occupancy) and a vector (flow velocity).  I want to generate a volume
rendering from this dataset of the scalar field, using the RayCast
volume code.

How do I get from the vtkDataSet that vtkDataSetReader outputs, to the
vtkImageData that the volume rendering routines want?  Currently I'm
using a GaussianSPlatter to convert to an imageData, & a
vtkImageShiftScale to convert from the 0-1float to a 0-255unsigned
char.

Here's an exerpt from my code:

***BEGIN***

    // Load model
    vtkDataSetReader *model = vtkDataSetReader::New();
    model->SetFileName(filename);
    model->Update();
    printf("File loaded\n");
    model->GetOutput()->GetPointData()->GetArray("Fraction")->GetRange(range,0);
    printf("* Range: %f - %f\n", range[0], range[1]);

    vtkMaskPoints *mask = vtkMaskPoints::New();
    mask->SetInput(model->GetOutput());
    mask->RandomModeOn();
    mask->SetMaximumNumberOfPoints(10);
    mask->Update();
    printf("Data Masked\n");
    mask->GetOutput()->GetPointData()->GetArray("Fraction")->GetRange(range,0);
    printf("* Range: %f - %f\n", range[0], range[1]);

    vtkGaussianSplatter *filter = vtkGaussianSplatter::New();
    filter->SetNullValue(0.0);
    filter->SetInput(mask->GetOutput());
    filter->Update();
    printf("Filter ran\n");

    vtkImageShiftScale *scaled = vtkImageShiftScale::New();
    scaled->SetInput(filter->GetOutput());
    scaled->SetScale(255.0);
    scaled->SetOutputScalarTypeToUnsignedChar();
    scaled->Update();
    printf("Data Scaled ran\n");
    printf("* Scaled data arrays:\n");
    vtkPointData *dataptr = scaled->GetOutput()->GetPointData();
    for(n=0; n< dataptr->GetNumberOfArrays(); n++) {
        printf("*   [%i] \"%s\"\n", n, dataptr->GetArrayName(n));
    }
    scaled->GetOutput()->GetPointData()->GetArray(0)->GetRange(range,0);
    printf("* Range: %f - %f\n", range[0], range[1]);
    vtkGaussianSplatter *filter = vtkGaussianSplatter::New();
    filter->SetNullValue(0.0);
    filter->SetInput(mask->GetOutput());
    filter->Update();
    printf("Filter ran\n");
    
    vtkImageShiftScale *scaled = vtkImageShiftScale::New();
    scaled->SetInput(filter->GetOutput());
    scaled->SetScale(255.0);
    scaled->SetOutputScalarTypeToUnsignedChar();
    scaled->Update();
    printf("Data Scaled ran\n");
    printf("* Scaled data arrays:\n");
    vtkPointData *dataptr = scaled->GetOutput()->GetPointData();
    for(n=0; n< dataptr->GetNumberOfArrays(); n++) {
        printf("*   [%i] \"%s\"\n", n, dataptr->GetArrayName(n));
    }
    scaled->GetOutput()->GetPointData()->GetArray(0)->GetRange(range,0);
    printf("* Range: %f - %f\n", range[0], range[1]);
    
    vtkVolumeRayCastCompositeFunction *compFunc =
                vtkVolumeRayCastCompositeFunction::New();
    compFunc->SetCompositeMethodToInterpolateFirst();
    
    vtkPiecewiseFunction *xf_Opacity = vtkPiecewiseFunction::New();
    xf_Opacity->AddPoint(0,0.0);
    xf_Opacity->AddPoint(255,1.0);
    
    vtkColorTransferFunction *xf_Color = vtkColorTransferFunction::New();
    xf_Color->AddRGBPoint(0, 0, 0, 1);
    xf_Color->AddRGBPoint(255, 0, 0, 1);
    
    vtkVolumeProperty *volProp = vtkVolumeProperty::New();
    volProp->SetColor(xf_Color);
    volProp->SetScalarOpacity(xf_Opacity);
    volProp->SetInterpolationTypeToLinear();
    
    modelMapper = vtkVolumeRayCastMapper::New();
    modelMapper->SetInput(scaled->GetOutput());
    modelMapper->SetVolumeRayCastFunction(compFunc);
//  modelMapper->Update();
    
    printf("Mapper updated\n");
    vtkVolume *volume = vtkVolume::New();
    volume->SetMapper(modelMapper);
    volume->SetProperty(volProp);
***END***

When I run this, tho, I get the following output:
=============== BEGIN OUTPUT ==============
Loading file test.vtk...
File loaded
* Range: 0.000000 - 1.000000
Data Masked
* Range: 0.000000 - 1.000000
Filter ran
Data Scaled ran
* Scaled data arrays:
*   [0] "(null)"
* Range: 0.000000 - 253.000000
Mapper updated
ERROR: In /viz/home/rhand/src/ezViz/Utilities/VTK/Filtering/vtkExecutive.cxx,
line 519
vtkStreamingDemandDrivenPipeline (0x109843b8): Non-forwarded requests
are not yet implemented.

Segmentation fault (core dumped)
================ END OUTPUT ============

Any ideas?
-- 
Randall Hand
http://www.yeraze.com



More information about the vtkusers mailing list