Как конвертировать изображение Simpleitk в VTK в проекте CSHARP? - PullRequest
0 голосов
/ 07 июня 2019

Я использую Activiz (c # библиотека vtk) и SimpleITK в моей программе,

Я попытался загрузить серии dicom с помощью SimpleITK, затем передать изображение в Activiz ,, а затем создать том с помощью vtkVolumeRayCastMapper

ImageSeriesReader imageSeriesReader = new ImageSeriesReader();

VectorString dicomNames = ImageSeriesReader.GetGDCMSeriesFileNames(@"E:\VTK3d\王社教阅片端 - 复件\王社教阅片端\Data\PV");
imageSeriesReader.SetFileNames(dicomNames);
Image image = imageSeriesReader.Execute();

VectorDouble spacing= image.GetSpacing();
image = SimpleITK.Cast(image, PixelIDValueEnum.sitkVectorUInt8);
VectorUInt32 size = image.GetSize();
int len = 1;
for (int dim = 0; dim < image.GetDimension(); dim++)
{
    len *= (int)size[dim];
}


IntPtr ptr= image.GetBufferAsUInt8();

int[] bufferAsArray = new int[len];

//Marshal.Copy(ptr, bufferAsArray, 0, len);
int max = bufferAsArray.Max();
int min = bufferAsArray.Min();
vtkImageImport dataImporter = new vtkImageImport();
dataImporter.CopyImportVoidPointer(ptr, len);
dataImporter.SetDataScalarTypeToUnsignedChar();

dataImporter.SetDataExtent(0, (int)size[0], 0, (int)size[1], 0, 100);
dataImporter.SetWholeExtent(0, (int)size[0], 0, (int)size[1], 0, 100);
dataImporter.SetDataSpacing(spacing[0], spacing[1], spacing[2]);

vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper();

vtkPiecewiseFunction volumeScalarOpacity = new vtkPiecewiseFunction();
volumeScalarOpacity.AddPoint(-260, 0.00);
//volumeScalarOpacity.AddPoint(500, 0.15);
//volumeScalarOpacity.AddPoint(1000, 0.15);
volumeScalarOpacity.AddPoint(340, 0.85);

vtkColorTransferFunction volumeColor = new vtkColorTransferFunction();
volumeColor.AddRGBPoint(-260, 0.0, 0.0, 0.0);
//volumeColor.AddRGBPoint(500, 1.0, 0.5, 0.3);
//volumeColor.AddRGBPoint(1000, 1.0, 0.5, 0.3);
volumeColor.AddRGBPoint(340, 1.0, 1.0, 0.9);

//vtkPiecewiseFunction volumeGradientOpacity = new vtkPiecewiseFunction();
//volumeGradientOpacity.AddPoint(0, 0.0);
//volumeGradientOpacity.AddPoint(90, 0.5);
//volumeGradientOpacity.AddPoint(100, 1.0);
vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
volumeProperty.SetColor(volumeColor);
volumeProperty.SetScalarOpacity(volumeScalarOpacity);
// volumeProperty.SetGradientOpacity(volumeGradientOpacity);
//volumeProperty.SetInterpolationTypeToLinear();
//volumeProperty.ShadeOn();
//volumeProperty.SetAmbient(0.4);
//volumeProperty.SetDiffuse(0.6);
//volumeProperty.SetSpecular(0.2);
vtkVolumeRayCastCompositeFunction compositeFunction = new vtkVolumeRayCastCompositeFunction();
volumeMapper.SetVolumeRayCastFunction(compositeFunction);
volumeMapper.SetInputConnection(dataImporter.GetOutputPort());
vtkVolume volume = new vtkVolume();
volume.SetProperty(volumeProperty);
volume.SetMapper(volumeMapper);
volume.SetScale(0.3);
double[] c = new double[3];
c = volume.GetCenter();
renderer.AddVolume(volume);
renderer.Render();

Я могу получить объем, но кажется, что этот объем был искажен, обрезан, деформирован.

1 Ответ

0 голосов
/ 07 июня 2019

Я думаю, что у вас есть ошибка off-1, когда вы вызываете dataImporter.SetDataExtent и dataImporter.SetWholeExtent. Максимальные значения должны быть размером [0] -1, размером [1] -1 и 99.

...