Finisher001
Finisher001

Reputation: 455

Use c# byte[] image data in vtk

I am using Kitware.VTK toolkit to show 2d images in 3d.

I have image in byte[]. I want to display it in renderviewcontrol of Kitware.VTK using vtkImageviewer. I dont have much idea about VTK.

Is there anyother way to perform the task? Can anybody help me for this?

Upvotes: 2

Views: 1353

Answers (1)

JohnnyQ
JohnnyQ

Reputation: 1611

You can copy your byte array into the VTK world and create a vktImageData object to use it as InputConnection.

vtkUnsignedCharArray myCharArray = vtkUnsignedCharArray.New();
GCHandle myPinnedArray = GCHandle.Alloc(myByteArray, GCHandleType.Pinned);
myCharArray.SetArray(myPinnedArray.AddrOfPinnedObject(), myData.Width * myData.Height * myData.Depth, 1);

vtkImageData myVtkImageData = vtkImageData.New();
myVtkImageData.GetPointData().SetScalars(myCharArray);
myVtkImageData.SetScalarTypeToUnsignedChar();

myVtkImageData.SetExtent(0, myData.Width - 1, 0, myData.Height - 1, myData.Depth -1);

myVtkImageData.Update();

The myData is just a information about the image dimension of your byte array. You should also make sure that the GCHandle and vtkImageData object is not cleared by the GC.

Depending on your data it's probably necessary to set Origin and Spacing.

Upvotes: 3

Related Questions