3D pointcloud visualisation of DICOM Images with VTK in C#

586 views Asked by At

my task is to visualize a grayscale pointcloud which I can found in a DICOM series. I found this tutorial https://pyscience.wordpress.com/2014/09/11/surface-extraction-creating-a-mesh-from-pixel-data-using-python-and-vtk/ which shows how to visualize bones in 3D by meching them. I could transfer it to c# and it work, but I need just a 3D point cloud where I can define the object by thresholding the grayscale. Hope u understand what I mean. So I tried this:

// read file
string pathDicom = @"...\dicomDirectory";
vtkDICOMImageReader reader = new Kitware.VTK.vtkDICOMImageReader();
reader.SetDirectoryName(pathDicom);
reader.Update();

// convert HU value
vtkImageShiftScale shiftScale = vtkImageShiftScale.New();
shiftScale.SetScale(reader.GetRescaleSlope());
shiftScale.SetShift(reader.GetRescaleOffset());
shiftScale.SetInputConnection(reader.GetOutputPort());
shiftScale.Update();

// Visualize
vtkPolyDataMapper mapper = vtkPolyDataMapper.New();
mapper.SetInputConnection(shiftScale.GetOutputPort());

vtkActor actor = vtkActor.New();
actor.SetMapper(mapper);
actor.GetProperty().SetPointSize(4);

vtkRenderWindow renderWindow = renderWindowControl1.RenderWindow;
vtkRenderer renderer = renderWindow.GetRenderers().GetFirstRenderer();
renderer.SetBackground(0.2, 0.3, 0.4);
renderer.AddActor(actor);

When I start this I alwas get the same error

vtkStreamingDemandDrivenPipline (09366B85)

and Visual Studio tell me

System.AccessViolationException

It's kind of memory error.

So my question is where is my mistake? During debugging I found out that the error begun when I set the mapper for the actor. But I now that this code is the normal way to display everything in vtk. I think the problem is that I don't really get the points out of the array but the imageData should contain all pixels of the series.

Hope u can help me.

0

There are 0 answers