Beispiel #1
0
        public cVolumeRendering3D(vtkImageData imageData, cPoint3D Pos)
        {
            baseInit(null);

            vtk_volume = vtkVolume.New();
            // vtkFloatArray floatArray = vtkFloatArray.New();
            //vtkCharArray charArray = vtkCharArray.New();
              //  vtkUnsignedShortArray UshortArray = vtkUnsignedShortArray.New();

            vtkExtractVOI voi = vtkExtractVOI.New();
              //  vtkPiecewiseFunction opacityTransferFunction = vtkPiecewiseFunction.New();
            vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New();
            vtkVolumeProperty volumeProperty = vtkVolumeProperty.New();

               // imageData.GetPointData().SetScalars(UshortArray);

            voi = vtkExtractVOI.New();
            voi.SetInput(imageData);

            voi.SetVOI(0, imageData.GetDimensions()[0] - 1, 0, imageData.GetDimensions()[1] - 1, 0, imageData.GetDimensions()[2] - 1);
            voi.SetSampleRate(1, 1, 1);

            opacityTransferFunction = vtkPiecewiseFunction.New();

            range = imageData.GetScalarRange();
            opacityTransferFunction.AddPoint(100, 0.0);
            opacityTransferFunction.AddPoint(1000, 1);
            //opacityTransferFunction.AddPoint(range[0] + (range[1]-range[0])/2.0, 0.0);
            //opacityTransferFunction.AddPoint(range[1], 0.7);

            ////Scale the image between 0 and 1 using a lookup table
            //vtkLookupTable table = vtkLookupTable.New();
            //table.SetValueRange(0,1);
            //table.SetSaturationRange(0,0);
            //table.SetRange(range[0], range[1]); //shoul here not be the minimum/maximum possible of "data"?
            //table.SetRampToLinear();
            //table.Build();

            //vtkImageMapToColors color = vtkImageMapToColors.New();
            //color.SetLookupTable(table);
            //color.SetInputConnection(imageData.GetProducerPort());

            vtkColorTransferFunction ColorTransferFunction = vtkColorTransferFunction.New();
            ColorTransferFunction.AddRGBPoint(20.0, 0.0, 0.0, 1.0);
            ColorTransferFunction.AddRGBPoint(255.0, 1.0, 0.0, 0.0);
            //ColorTransferFunction.AddRGBPoint(1000.0, 0.8, 0.5, 0.0);

            //opacityTransferFunction.ClampingOff();

            volumeProperty = vtkVolumeProperty.New();
            volumeProperty.SetColor(colorTransferFunction);
            volumeProperty.SetScalarOpacity(opacityTransferFunction);
            volumeProperty.SetInterpolationTypeToLinear();
            volumeProperty.ShadeOn();
            volumeProperty.SetAmbient(0.6);
            volumeProperty.SetDiffuse(0.6);
            volumeProperty.SetSpecular(0.1);

            //volumeProperty.SetAmbient(0.1);
            //volumeProperty.SetDiffuse(0.9);
            //volumeProperty.SetSpecular(0.2);
            //volumeProperty.SetSpecularPower(10.0);
            //volumeProperty[band].SetScalarOpacityUnitDistance(0.8919);

            vtkVolumeTextureMapper3D volumeTextureMapper = vtkVolumeTextureMapper3D.New();
            ////volumeTextureMapper.SetInputConnection(color.GetOutputPort());
            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.PickableOff();

            vtk_volume.SetPosition(Pos.X, Pos.Y, Pos.Z);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }