[vtkusers] SimpleRayCast example in Java
Rodolfo Allendes Osorio
r.s.allendesosorio05 at leeds.ac.uk
Sun Jun 6 18:09:48 EDT 2010
Hi Everyone...
Does anyone have a working copy of the SimpleRayCast example that works on Java? I keep either getting the 'famous' EXCEPTION_ACCESS_VIOLATION error or a bad conversion error, type conversion fail (cant see anythin else, as the text dissapears after a few seconds and its covered by the frame)...
the code i'm using is
import vtk.*;
import javax.swing.*;
import java.awt.*;
/**
* This is a simple volume rendering example that uses a
* vtkVolumeRayCast mapper.
*/
public class SimpleRayCast{
static public void main(String []args) {
// Setup VTK rendering panel
vtkPanel renWin = new vtkPanel();
// Create the reader for the data
vtkStructuredPointsReader reader = new vtkStructuredPointsReader();
reader.SetFileName("ironProt.vtk");
// Create transfer mapping scalar value to opacity
vtkPiecewiseFunction opacityTransferFunction = new vtkPiecewiseFunction();
opacityTransferFunction.AddPoint(20, 0.0);
opacityTransferFunction.AddPoint(255, 0.2);
// Create transfer mapping scalar value to color
vtkColorTransferFunction colorTransferFunction = new vtkColorTransferFunction();
colorTransferFunction.AddRGBPoint(0.0, 0.0, 0.0, 0.0);
colorTransferFunction.AddRGBPoint(64.0, 1.0, 0.0, 0.0);
colorTransferFunction.AddRGBPoint(128.0, 0.0, 0.0, 1.0);
colorTransferFunction.AddRGBPoint(192.0, 0.0, 1.0, 0.0);
colorTransferFunction.AddRGBPoint(255.0, 0.0, 0.2, 0.0);
// The property describes how the data will look
vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
volumeProperty.SetColor(colorTransferFunction);
volumeProperty.SetScalarOpacity(opacityTransferFunction);
volumeProperty.ShadeOn();
volumeProperty.SetInterpolationTypeToLinear();
// The mapper / ray cast function know how to render the data
//vtkVolumeRayCastCompositeFunction compositeFunction = new vtkVolumeRayCastCompositeFunction();
vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper();
// un-comment this line to get both different errors
// volumeMapper.SetVolumeRayCastFunction(new vtkVolumeRayCastFunction());
volumeMapper.SetInput(reader.GetOutput());
// The volume holds the mapper and the property and
// can be used to position/orient the volume
vtkVolume volume = new vtkVolume();
volume.SetMapper(volumeMapper);
volume.SetProperty(volumeProperty);
renWin.GetRenderer().AddVolume(volume);
renWin.GetRenderer().SetBackground(1, 1, 1);
JFrame frame = new JFrame("SimpleRayCast");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add("Center", renWin);
frame.pack();
frame.setVisible(true);
}
}
More information about the vtkusers
mailing list