[vtkusers] Does vtkProbeFilter work on a vtkUnstructuredGrid?
Randy Hudson
hudson at mcs.anl.gov
Wed Jul 28 08:47:55 EDT 2004
I'm trying to sample a vtkUnstructuredGrid onto a vtkImageData with vtkProbeFilter, in order to volume render the data with vtkVolumeRayCastMapper.
QUESTION: Should I, in general, expect this to work?
DETAILS
-------
(Relevant code from my application is farther below.)
I use a vtkBoxWidget to define the bounds of the vtkImageData that's input to the probe filter. The box widget is initially set to coincide with the full data domain, and usually later scaled down to intersect with a proper subset of it. (The output of the volume ray caster, though lousy, (see links, below) is close enough to being correct to indicate that the widget does indeed intersect the data domain in this way.)
The data is originally stored, and later read into my app., with HDF5. My app. puts it into a vtkUnstructuredGrid, "UG", and passes that to a vtkAssignAttribute object, so that I can store several scalar variables in the same vtkUnstructuredGrid. The data is located at cell corners.
I use vtkImageCast to cast the float data to unsigned short.
I set the colors of the transfer function variously, but define opacity to be close to 0.0 for low data values, ramp pretty steeply to almost 1.0 somewhere in the middle of the value range, and stay high thereafter.
Here are two links to images of the volume rendering done in my app:
http://www-unix.mcs.anl.gov/~hudson/htmlbase/flashvis/fv_vren_dens_1.jpg The sampling grid for this image was 512x512x2 (to get detail in the two dimensions of the image, but minimmize the time to get a result).
http://www-unix.mcs.anl.gov/~hudson/htmlbase/flashvis/fv_vren_notright_polys.jpg The sampling grid for this image was on the order of 16^3 to 32^3.
Both images show inexplicable gaps in the data, though you have to look harder to find them in the first. Neither one shows any transparency, inspite of the opacity map.
Here's the code:
isoAttribute = vtkAssignAttribute::New();
isoAttribute->SetInput(UG);
isoAttribute->Assign(VariableName, 0, 0);
//
FindBoundsOfBoxwidget(bounds);
//
// Establish reses and cell sizes of regular sampling grid
SetSamplingGridResolution(regvolres);
CalcSpacing(spacing);
//
regvolume = vtkImageData::New();
regvolume->SetDimensions(regvolres[0], regvolres[1], regvolres[2]);
regvolume->SetSpacing(spacing[0], spacing[1], spacing[2]);
regvolume->SetOrigin(bounds[0], bounds[2], bounds[4]);
regvolume->SetNumberOfScalarComponents(1);
regvolume->AllocateScalars();
//
vol_probefilter = vtkProbeFilter::New();
vol_probefilter->SetInput(regvolume);
vol_probefilter->SetSource(isoAttribute->GetOutput());
//
probeout_typecast = vtkImageCast::New();
probeout_typecast->SetInput((vtkImageData*)vol_probefilter->GetOutput());
probeout_typecast->SetOutputScalarTypeToUnsignedShort();
//
vol_opacityxferfunc = vtkPiecewiseFunction::New();
vol_colorxferfunc = vtkColorTransferFunction::New();
vol_property = vtkVolumeProperty::New();
//
vol_compositefunc = vtkVolumeRayCastCompositeFunction::New();
vol_compositefunc->SetCompositeMethod(VTK_COMPOSITE_INTERPOLATE_FIRST);
//
vol_mapper = vtkVolumeRayCastMapper::New();
vol_mapper->IntermixIntersectingGeometryOn();
vol_mapper->SetVolumeRayCastFunction(vol_compositefunc);
vol_mapper->SetInput(probeout_typecast->GetOutput());
vol_mapper->SetSampleDistance(SmallestSpacing * 0.5);
volume = vtkVolume::New();
volume->SetMapper(vol_mapper);
volume->SetProperty(vol_property);
//
renderer->AddProp(volume);
//
DefineTransferFunctions();
vol_property->SetColor(vol_colorxferfunc);
vol_property->SetScalarOpacity(vol_opacityxferfunc);
volume->Update();
Randy Hudson.
More information about the vtkusers
mailing list