//普通模式_绘制
        private void DrawMode_Normal()
        {
            #region 体属性 vtkVolumeProperty
            //设定体数据的属性:不透明性和颜色值映射标量值
            vtkVolumeProperty volumeProperty = vtkVolumeProperty.New();
            volumeProperty.SetColor(m_ColorTransferFunction);
            volumeProperty.SetScalarOpacity(m_PiecewiseFunction);
            //设置插值类型
            volumeProperty.SetInterpolationTypeToNearest();
            volumeProperty.SetDiffuse(0.7);
            volumeProperty.SetAmbient(0.01);
            volumeProperty.SetSpecular(0.5);
            volumeProperty.SetSpecularPower(100);
            #endregion

            //绘制方法:体射线投射
            vtkVolumeRayCastCompositeFunction compositeFunction = vtkVolumeRayCastCompositeFunction.New();

            #region 体数据映射器 vtkVolumeRayCastMapper
            //体数据映射器
            vtkVolumeRayCastMapper volumeMapper = vtkVolumeRayCastMapper.New();
            volumeMapper.SetInput(m_ImageData);
            volumeMapper.SetVolumeRayCastFunction(compositeFunction);
            #endregion

            #region 体 vtkVolume
            //体
            vtkVolume volume = vtkVolume.New();
            volume.SetMapper(volumeMapper);
            volume.SetProperty(volumeProperty);
            #endregion

            //模型体放入Renerer
            m_Renderer.AddVolume(volume);
        }
        /// <summary>
        /// 进行可视化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void VisiualizeSlicesWnd_Load(object sender, EventArgs e)
        {
            vtkRenderer renderer = rwcShowSlices.RenderWindow.GetRenderers().GetFirstRenderer();

            renderer.SetBackground(1, 1, 1);
            //CuteTools.ShowImageSeries(fnFormat, height, width, startIndex, endIndex, renderer);
            //return;

            vtkBMPReader reader = vtkBMPReader.New();

            reader.SetFilePattern(fnFormat);

            reader.SetDataExtent(0, height - 1, 0, width - 1, startIndex, endIndex);

            reader.SetDataScalarTypeToUnsignedChar();
            reader.Update();

            vol = vtkVolume.New();

            vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New();

            texMapper.SetInput(reader.GetOutput());
            vol.SetMapper(texMapper);

            colorTransferFunction = vtkColorTransferFunction.New();
            colorTransferFunction.AddRGBPoint(0, tbR1.Value * 1.0 / 255, tbG1.Value * 1.0 / 255, tbB1.Value * 1.0 / 255);
            colorTransferFunction.AddRGBPoint(1, tbR2.Value * 1.0 / 255, tbG2.Value * 1.0 / 255, tbB2.Value * 1.0 / 255);
            colorTransferFunction.ClampingOn();

            vpro = vtkVolumeProperty.New();
            vtkPiecewiseFunction compositeOpacity = vtkPiecewiseFunction.New();

            compositeOpacity.AddPoint(0, 0);
            //compositeOpacity.AddPoint(120.0, 0.5);
            compositeOpacity.AddPoint(255.0, 1);
            compositeOpacity.ClampingOn();
            vpro.SetScalarOpacity(compositeOpacity);
            vpro.SetColor(colorTransferFunction);
            //vpro.SetInterpolationTypeToLinear();
            vpro.SetInterpolationTypeToNearest();
            //vpro.ShadeOn();
            vol.SetProperty(vpro);


            //画轴距图
            vol.SetOrientation(45, 45, 0);


            //rwcShowSlices.RenderWindow.GetRenderers().GetFirstRenderer().AddVolume( vol );

            rwcShowSlices.Refresh();
        }
Exemplo n.º 3
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);
        }