[vtkusers] Creating volume data "manually"

Teccie ikdemichel at hotmail.com
Wed Feb 20 03:43:40 EST 2008


Hello,

I'm new to VTK, and I've been struggling to read a file with volume data and
displaying it using VTK. I have searched for examples for this, but haven't
been able to find them, I could only find examples for .vtk and folders with
raw files. Can someone help me, by telling me what I'm doing wrong? I'm
using the managed wrappers for vtk

This is how I create my vtkImageData:

imageData = new vtkImageData();
imageData.SetDimensions(width, height, slices);
imageData.SetScalarTypeToUnsignedShort();
imageData.SetSpacing(voxelsize_x, voxelsize_y, voxelsize_z);
imageData.SetOrigin(0, 0, 0);
imageData.AllocateScalars();

int nrVoxels = width * height * slices;
int nrBytes = width * height * 2;

byte[] pixelData = new byte[nrBytes];

for (int k = 0; k < slices; k++)
{
	stream.Read(pixelData, 0, nrBytes);

	Marshal.Copy(pixelData, 0, imageData.GetScalarPointer(0, 0, k), nrBytes);
}

stream.Close();

Then, I try to initialize my renderwindow like this:

vtkPiecewiseFunction functionPoints = new vtkPiecewiseFunction();
functionPoints.AddPoint(250, 0);
functionPoints.AddPoint(500, 0);
functionPoints.AddPoint(750, 0);

vtkColorTransferFunction functionColors = new vtkColorTransferFunction();
functionColors.AddRGBPoint
(
	0.0f,
	1.0f,
	0.6f,
	0.2f
);	

functionColors.AddRGBPoint
(
	0.8f,
	1.0f,
	0.9f,
	0.7f
);

functionColors.AddRGBPoint
(
	1,
	1,
	1,
	1
);

vtkVolumeRayCastCompositeFunction
	    compositeFunction = new vtkVolumeRayCastCompositeFunction();
				
vtkVolumeRayCastMapper mapper = new vtkVolumeRayCastMapper();
mapper.SetInput(imageData);
mapper.SetVolumeRayCastFunction(compositeFunction);
				
vtkVolumeProperty property = new vtkVolumeProperty();
property.SetColor(functionColors);
property.SetScalarOpacity(functionPoints);
property.SetInterpolationTypeToLinear();
property.ShadeOn();
				
vtkVolume volume = new vtkVolume();
volume.SetMapper(mapper);
volume.SetProperty(property);

vtkRenderer ren = new vtkRenderer();
renWin.AddRenderer(ren);
ren.SetBackground(0, 0, 0);
ren.AddVolume(volume);
ren.Render();
				
vtk.vtkRenderWindowInteractor iren = renWin.GetInteractor();
{
	m_boxWidget = new vtk.vtkBoxWidget();
	m_boxWidget.SetInteractor(iren);
	m_boxWidget.SetPlaceFactor(1.25f);
	m_boxWidget.SetProp3D(volume);
	m_boxWidget.PlaceWidget();
	m_boxWidget.AddObserver((uint)vtk.EventIds.InteractionEvent,
		new vtk.vtkDotNetCallback(myCallback));

	m_boxWidget.On();
}


Can anyone help me? I've been stuck with this for a while now... Thanks in
advance!
Greets,
Michel

-- 
View this message in context: http://www.nabble.com/Creating-volume-data-%22manually%22-tp15560780p15560780.html
Sent from the VTK - Users mailing list archive at Nabble.com.




More information about the vtkusers mailing list