我在我的程序中使用 Activiz(c# library of vtk) 和 SimpleITK,
我尝试用 SimpleITK 加载 dicom 系列,然后将图像传输到 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();
我可以得到一个卷,但似乎这个卷已经被扭曲、切割、变形了。