private vtkUnsignedShortArray BuildVolumeImageData() { ushort[] volumeData = new ushort[this.SizeInVoxels]; int imageIndex = 0; if (IsDataUnsigned()) { foreach (IImageGraphicProvider slice in _displaySet.PresentationImages) { AddUnsignedSliceToVolume(volumeData, slice, imageIndex); imageIndex++; } } else { FindMinimumPixelValue(); foreach (IImageGraphicProvider slice in _displaySet.PresentationImages) { AddSignedSliceToVolume(volumeData, slice, imageIndex); imageIndex++; } } vtkUnsignedShortArray vtkVolumeData = new vtkUnsignedShortArray(); vtkVolumeData.SetArray(volumeData, new VtkIdType(volumeData.Length), 1); return vtkVolumeData; }
public static vtkUnsignedShortArray ConvertToVtkUnsignedShortArray(ushort[] ushortArray) { vtkUnsignedShortArray vtkUnsignedShortArray = new vtkUnsignedShortArray(); vtkUnsignedShortArray.SetArray(ushortArray, (VtkIdType) ushortArray.Length, 1); return vtkUnsignedShortArray; }
private static vtkImageData CreateVtkVolume(Volume volume) { var vtkVolume = new vtkImageData(); vtkVolume.RegisterVtkErrorEvents(); vtkVolume.SetDimensions(volume.ArrayDimensions.Width, volume.ArrayDimensions.Height, volume.ArrayDimensions.Depth); vtkVolume.SetOrigin(0, 0, 0); vtkVolume.SetSpacing(volume.VoxelSpacing.X, volume.VoxelSpacing.Y, volume.VoxelSpacing.Z); if (volume.BitsPerVoxel == 16) { if (!volume.Signed) { using (var array = new vtkUnsignedShortArray()) { array.SetArray((ushort[]) volume.Array, (VtkIdType) volume.ArrayLength, 1); vtkVolume.SetScalarTypeToUnsignedShort(); vtkVolume.GetPointData().SetScalars(array); } } else { using (var array = new vtkShortArray()) { array.SetArray((short[]) volume.Array, (VtkIdType) volume.ArrayLength, 1); vtkVolume.SetScalarTypeToShort(); vtkVolume.GetPointData().SetScalars(array); } } } else if (volume.BitsPerVoxel == 8) { if (!volume.Signed) { using (var array = new vtkUnsignedCharArray()) { array.SetArray((byte[]) volume.Array, (VtkIdType) volume.ArrayLength, 1); vtkVolume.SetScalarTypeToUnsignedChar(); vtkVolume.GetPointData().SetScalars(array); } } else { using (var array = new vtkSignedCharArray()) { array.SetArray((sbyte[]) volume.Array, (VtkIdType) volume.ArrayLength, 1); vtkVolume.SetScalarTypeToSignedChar(); vtkVolume.GetPointData().SetScalars(array); } } } else { throw new NotSupportedException("Unsupported volume scalar type."); } // This call is necessary to ensure vtkImageData data's info is correct (e.g. updates WholeExtent values) vtkVolume.UpdateInformation(); return vtkVolume; }