public cVolumeRendering3D(cSingleChannelImage SingleChannelImage, cPoint3D Pos, byte[][] NewLUT, c3DNewWorld AssociatedWorld) { if (SingleChannelImage.Data == null) return; baseInit(AssociatedWorld); this.SetName("Volume 3D [" + SingleChannelImage.Name + "]"); this.LUT = NewLUT; vtk_volume = vtkVolume.New(); vtkImageData imageData = vtkImageData.New(); vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New(); voi = vtkExtractVOI.New(); ColorTransferFunction = vtkColorTransferFunction.New(); for (int i = 0; i < SingleChannelImage.Width * SingleChannelImage.Height * SingleChannelImage.Depth; i++) { UshortArray.InsertTuple1(i, (ushort)SingleChannelImage.Data[i]); // data are converted to UShort } imageData = vtkImageData.New(); imageData.SetDimensions(SingleChannelImage.Width, SingleChannelImage.Height, SingleChannelImage.Depth); imageData.SetOrigin(0, 0, 0); if ((SingleChannelImage.Resolution.X == 0) || (SingleChannelImage.Resolution.Y == 0) || (SingleChannelImage.Resolution.Z == 0)) imageData.SetSpacing(1.0, 1.0, 1.0); else imageData.SetSpacing(SingleChannelImage.Resolution.X, SingleChannelImage.Resolution.Y, SingleChannelImage.Resolution.Z); imageData.GetPointData().SetScalars(UshortArray); voi = vtkExtractVOI.New(); voi.SetInput(imageData); voi.SetVOI(0, SingleChannelImage.Width - 1, 0, SingleChannelImage.Height - 1, 0, SingleChannelImage.Depth - 1); voi.SetSampleRate(1, 1, 1); opacityTransferFunction = vtkPiecewiseFunction.New(); range = imageData.GetScalarRange(); opacityTransferFunction.AddPoint(range[0], 0.0); opacityTransferFunction.AddPoint(range[1], 0.3); //opacityTransferFunction.AddPoint(2000, 0.1); //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0); //opacityTransferFunction.AddPoint(range[1], 0.7); if (LUT == null) { //cLUT MyLut = new cLUT(); //LUT = MyLut.LUT_JET; ColorTransferFunction.AddRGBPoint(0, 0 , 0, 0); ColorTransferFunction.AddRGBPoint(1, 1, 1, 1); } //double LUTSize = LUT[0].Length; //for (int i = 0; i < (int)LUTSize; i++) //{ // colorTransferFunction.AddRGBPoint(i, LUT[0][i] / LUTSize, LUT[1][i] / LUTSize, LUT[2][i] / LUTSize); //} ColorTransferFunction.Build(); volumeProperty = vtkVolumeProperty.New(); volumeProperty.SetColor(ColorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.SetInterpolationTypeToNearest(); volumeProperty.ShadeOff(); vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New(); volumeTextureMapper.SetInputConnection(voi.GetOutputPort()); //vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New(); //vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New(); //volumeMapper.SetVolumeRayCastFunction(compositeFunction); //volumeMapper.SetInputConnection(voi.GetOutputPort()); vtk_volume = vtkVolume.New(); vtk_volume.SetMapper(volumeTextureMapper); vtk_volume.SetProperty(volumeProperty); vtk_volume.PickableOn(); vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z); }
public cVolumeRendering3D(cSingleChannelImage SingleChannelImage, cPoint3D Pos, byte[][] NewLUT) { this.LUT = NewLUT; vtk_volume = vtkVolume.New(); vtk_volume.PickableOn(); vtkImageData imageData = vtkImageData.New(); vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New(); vtkExtractVOI voi = vtkExtractVOI.New(); vtkPiecewiseFunction opacityTransferFunction = vtkPiecewiseFunction.New(); vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New(); vtkVolumeProperty volumeProperty = vtkVolumeProperty.New(); for (int i = 0; i < SingleChannelImage.Width * SingleChannelImage.Height * SingleChannelImage.Depth; i++) { UshortArray.InsertTuple1(i, (ushort)SingleChannelImage.Data[i]); } imageData = vtkImageData.New(); imageData.SetDimensions(SingleChannelImage.Width, SingleChannelImage.Height, SingleChannelImage.Depth); imageData.SetOrigin(0, 0, 0); if ((SingleChannelImage.Resolution.X == 0) || (SingleChannelImage.Resolution.Y == 0) || (SingleChannelImage.Resolution.Z == 0)) imageData.SetSpacing(1.0, 1.0, 1.0); else imageData.SetSpacing(SingleChannelImage.Resolution.X, SingleChannelImage.Resolution.Y, SingleChannelImage.Resolution.Z); imageData.GetPointData().SetScalars(UshortArray); voi = vtkExtractVOI.New(); voi.SetInput(imageData); voi.SetVOI(0, SingleChannelImage.Width - 1, 0, SingleChannelImage.Height - 1, 0, SingleChannelImage.Depth - 1); voi.SetSampleRate(1, 1, 1); opacityTransferFunction = vtkPiecewiseFunction.New(); range = imageData.GetScalarRange(); opacityTransferFunction.AddPoint(0, 0.0); opacityTransferFunction.AddPoint(255, 1); //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0); //opacityTransferFunction.AddPoint(range[1], 0.7); if (LUT == null) { cLUT MyLut = new cLUT(); LUT = MyLut.LUT_JET; } double LUTSize = LUT[0].Length; for (int i = 0; i < (int)LUTSize - 1; i++) { colorTransferFunction.AddRGBPoint(i, this.LUT[0][i] / LUTSize, this.LUT[1][i] / LUTSize, this.LUT[2][i] / LUTSize); } colorTransferFunction.Build(); volumeProperty = vtkVolumeProperty.New(); volumeProperty.SetColor(colorTransferFunction); volumeProperty.SetScalarOpacity(opacityTransferFunction); volumeProperty.SetInterpolationTypeToLinear(); volumeProperty.ShadeOff(); volumeProperty.SetAmbient(0.6); volumeProperty.SetDiffuse(0.6); volumeProperty.SetSpecular(0.1); vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New(); volumeTextureMapper.SetInputConnection(voi.GetOutputPort()); //vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New(); //vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New(); //volumeMapper.SetVolumeRayCastFunction(compositeFunction); //volumeMapper.SetInputConnection(voi.GetOutputPort()); vtk_volume = vtkVolume.New(); vtk_volume.SetMapper(volumeTextureMapper); vtk_volume.SetProperty(volumeProperty); vtk_volume.PickableOn(); vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z); }