[vtkusers] ray casting by VTK
zahra sahaf
sce2020sahaf at yahoo.com
Fri Nov 8 04:38:56 EST 2013
I am actually new to VTK. As a course project, I am going to implement a simple ray caster which could reads raw file and render that, my code is as follows: (unfortunately I did not get result, I don't know what's the problem) Please help me :(
Any help would be appreciated.
vtkRenderer ren1 = vtkRenderer.New();
vtkRenderWindow renwin = vtkRenderWindow.New();
vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New();
iren.SetRenderWindow(renwin);
ren1.SetBackground(0, 0, 0);
renwin.SetSize(600, 600);
/////////// Read in data and add extract filters
string filePath = System.IO.Path.GetFullPath(@"C:\Users\Sepid\Desktop\data\MRI-woman.raw");
Debug.WriteLine(filePath);
vtkImageReader reader = vtkImageReader.New();
Debug.Write(filePath);
reader.SetFileName(filePath);
reader.SetDataScalarTypeToUnsignedChar();
reader.SetDataByteOrderToLittleEndian();
reader.SetDataOrigin(0, 0, 0);
reader.SetFileDimensionality(3);
reader.SetDataSpacing(1, 1.5, 1);
reader.SetDataExtent(0, 255, 0, 108, 0, 255);
reader.Update();
//////////////////////////////////////////////////
vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New();
volumeMapper.SetInputConnection(reader.GetOutputPort());
vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New();
volumeMapper.SetVolumeRayCastFunction(compositeFunction);
volumeMapper.SetSampleDistance(0.25);
//////////////////////////////////////////////////
vtkPiecewiseFunction opacityTransferFunction = new vtkPiecewiseFunction();
opacityTransferFunction.AddPoint(1000, 0);
opacityTransferFunction.AddPoint(1500, 0.2);
opacityTransferFunction.AddPoint(2000, 0);
////////////////////////////////////////////////////
vtkColorTransferFunction colorTransferFunction = new vtkColorTransferFunction();
colorTransferFunction.AddRGBPoint(1000, 0, 0, 0);
colorTransferFunction.AddRGBPoint(1500, 1, 0.5, 0.5);
///////////////////////////////////////////////////
vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
volumeProperty.SetColor(colorTransferFunction);
volumeProperty.SetScalarOpacity(opacityTransferFunction);
///////////////////////////////////////////////////
vtkVolume volume = new vtkVolume();
volume.SetMapper(volumeMapper);
volume.SetProperty(volumeProperty);
ren1.AddVolume(volume);
// ren1.AddViewProp(volume);
iren.Initialize();
iren.Start();
renwin.Render();
Bests,
Zahra
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20131108/5b0194f5/attachment.htm>
More information about the vtkusers
mailing list