[vtkusers] Problems with multi volume rendering with VTK.
Stephane
stephane.dallongeville at pasteur.fr
Fri Jan 15 11:47:40 EST 2010
Hello,
I'm new to VTK (using it with java) and i'm trying to do multiple volume rendering.
I've a 3D grid data structure which can be of any data type (char, short, int, float, double...) and with 1 or more component (usually 1 component represent one color, i called it 'band' in my code).
I tried severals methods to draw that dataset but none of them satisfy me.
With the following code, i'm creating severals volume when i've severals components / bands in my grid data structure. The problem is that depth intersection is wrong between different volumes. I tried to use multi component volume rendering but it doesn't work with some volume mappers (afaik it works only with the vtkFixedPointVolumeRayCastMapper mapper for me).
private final vtkRenderer renderer;
...
private void createVolumeFromSequence(boolean raytrace, int band)
{
vtkVolumeMapper volumeMapper;
vtkVolume volume = new vtkVolume();
vtkVolumeProperty volumeProperty = new vtkVolumeProperty();;
vtkImageData imageData = new vtkImageData();
if (raytrace)
{
// ACCURATE VISUALIZATION MODE
volumeMapper = new vtkFixedPointVolumeRayCastMapper();
((vtkFixedPointVolumeRayCastMapper) volumeMapper).IntermixIntersectingGeometryOn();
}
else
{
// FAST VISUALIZATION MODE
volumeMapper = new vtkOpenGLVolumeTextureMapper2D();
}
buildImageData(imageData, band);
setupColorProperties(volumeProperty, lut.getLutBand(band));
volumeMapper.SetInput(imageData);
volume.SetMapper(volumeMapper);
volume.SetProperty(volumeProperty);
renderer.AddVolume(volume);
}
private void buildImageData(vtkImageData imageData, int band)
{
final Sequence sequence = getSequence();
final int sizeX = sequence.getSizeX();
final int sizeY = sequence.getSizeY();
final int sizeZ = sequence.getSizeZ();
final int dataType = sequence.getDataType();
final int posT = getT();
imageData.SetDimensions(sizeX, sizeY, sizeZ);
imageData.SetNumberOfScalarComponents(1);
imageData.SetSpacing(1, 1, 5);
imageData.SetWholeExtent(0, sizeX - 1, 0, sizeY - 1, 0, sizeZ - 1);
switch (dataType)
{
case DataBuffer.TYPE_BYTE:
{
imageData.SetScalarTypeToUnsignedChar();
// pre-allocate data
imageData.AllocateScalars();
// get array structure
final vtkDataArray array = imageData.GetPointData().GetScalars();
// set frame sequence data in the array structure
((vtkUnsignedCharArray) array).SetJavaArray(sequence.getComponentDataAsByteArray(band));
break;
}
case DataBuffer.TYPE_SHORT:
{
imageData.SetScalarTypeToShort();
...
}
}
imageData.UpdateData();
imageData.UpdateInformation();
}
private void setupColorProperties(vtkVolumeProperty volumeProperty, LUTBand lutBand)
{
// volumeProperty.IndependentComponentsOn();
volumeProperty.SetInterpolationTypeToLinear();
volumeProperty.DisableGradientOpacityOn();
XXXToRGBColorMap colorMap = lutBand.getColorMap();
Scaler scaler = lutBand.getScaler();
// SCALAR COLOR FUNCTION
vtkColorTransferFunction ctf = new vtkColorTransferFunction();
ctf.SetRange(scaler.getMinIn(), scaler.getMaxIn());
for (int i = 0; i < XXXToRGBColorMap.COLORMAP_SIZE; i++)
ctf.AddRGBPoint(scaler.unscale(i), colorMap.rf[i], colorMap.gf[i], colorMap.bf[i]);
volumeProperty.SetColor(ctf);
// SCALAR OPACITY FUNCTION
vtkPiecewiseFunction pwf = new vtkPiecewiseFunction();
pwf.AddPoint(0, 0);
pwf.AddPoint(32, 0.02);
pwf.AddPoint(255, 0.4);
volumeProperty.SetScalarOpacity(pwf);
}
VTK seems to be a very powerful but also very complex visualization library when you discover it. I'm sure i'm doing things in the wrong way and but i can't find any examples of what i'm trying to do. Can someone give me some light on my problem please ? Thanks by advance =)
- Stephane
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100115/3ca402ec/attachment.htm>
More information about the vtkusers
mailing list