private void Window_Activated(object sender, EventArgs e)
        {
            // 一定要先 vtkformhost.Child = vtkControl;下面三条顺序不能乱 否则报错 切记!
            vtkformhost.Child = vtkControl;
            vtkRenderWindow renWin    = vtkControl.RenderWindow;
            vtkRenderer     aRenderer = renWin.GetRenderers().GetFirstRenderer();

            renWin.AddRenderer(aRenderer);

            Marshal.Copy(ys1, 0, temp128, imgLine * imgPixel * imgNum);


            temp.SetArray(temp128, imgLine * imgPixel * imgNum, 1);

            testimgdata.SetDimensions(imgLine, imgPixel, imgNum);
            testimgdata.SetSpacing(1, 1, 4);
            testimgdata.SetScalarTypeToUnsignedChar();
            testimgdata.SetNumberOfScalarComponents(1);
            testimgdata.AllocateScalars();
            testimgdata.GetPointData().SetScalars(temp);
            testimgdata.Modified();

            VtkSetColor();
            VtkSetOpacity();

            volumeProperty.SetColor(colorTransferFunction);
            volumeProperty.SetScalarOpacity(opacityTransferFunction);
            volumeProperty.ShadeOn();
            volumeProperty.SetInterpolationTypeToLinear();

            volumeMapper.SetVolumeRayCastFunction(compositeFunction);
            volumeMapper.SetInput(testimgdata);

            volume.SetMapper(volumeMapper);
            volume.SetProperty(volumeProperty);

            aCamera.SetViewUp(0, -1, 0);
            aCamera.SetPosition(-1, 0, 1);
            aCamera.ComputeViewPlaneNormal();

            aRenderer.AddVolume(volume);
            aRenderer.SetBackground(0, 0, 0.6);
            aRenderer.SetActiveCamera(aCamera);
            aRenderer.ResetCamera();
            renWin.SetSize(800, 800);
            renWin.Render();
        }
Пример #2
0
        private vtkProp CreateVolumeRendering()
        {
            _opacityTransferFunction = new vtkPiecewiseFunction();
            _opacityTransferFunction.ClampingOff();

            _colorTransferFunction = new vtkColorTransferFunction();
            _colorTransferFunction.SetColorSpaceToRGB();
            _colorTransferFunction.ClampingOff();

            SetOpacityTransferFunction();
            SetColorTransferFunction();

            vtkVolumeProperty volumeProperty = new vtkVolumeProperty();

            volumeProperty.ShadeOn();
            volumeProperty.SetInterpolationTypeToLinear();
            volumeProperty.SetColor(_colorTransferFunction);
            volumeProperty.SetScalarOpacity(_opacityTransferFunction);
            volumeProperty.SetDiffuse(0.7);
            volumeProperty.SetAmbient(0.1);
            volumeProperty.SetSpecular(.3);
            volumeProperty.SetSpecularPower(20);

            //vtkOpenGLVolumeTextureMapper2D volumeMapper = new vtkOpenGLVolumeTextureMapper2D();
            //vtkOpenGLVolumeTextureMapper3D volumeMapper = new vtkOpenGLVolumeTextureMapper3D();
            //volumeMapper.SetPreferredMethodToNVidia();
            //volumeMapper.SetSampleDistance(1.0f);
            //int supported = volumeMapper.IsRenderSupported(volumeProperty);

            vtkFixedPointVolumeRayCastMapper volumeMapper = new vtkFixedPointVolumeRayCastMapper();

            //vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper();
            volumeMapper.SetInput(_volumeLayer.GetImageData());
            ////vtkVolumeRayCastCompositeFunction rayCastFunction = new vtkVolumeRayCastCompositeFunction();
            ////volumeMapper.SetVolumeRayCastFunction(rayCastFunction);
            //vtkVolumeRayCastIsosurfaceFunction rayCastFunction = new vtkVolumeRayCastIsosurfaceFunction();
            //volumeMapper.SetVolumeRayCastFunction(rayCastFunction);

            _vtkVolume = new vtkVolume();
            _vtkVolume.SetMapper(volumeMapper);
            _vtkVolume.SetProperty(volumeProperty);

            return(_vtkVolume);
        }
Пример #3
0
		private vtkProp CreateVolumeRendering()
		{
			_opacityTransferFunction = new vtkPiecewiseFunction();
			_opacityTransferFunction.ClampingOff();

			_colorTransferFunction = new vtkColorTransferFunction();
			_colorTransferFunction.SetColorSpaceToRGB();
			_colorTransferFunction.ClampingOff();

			SetOpacityTransferFunction();
			SetColorTransferFunction();

			vtkVolumeProperty volumeProperty = new vtkVolumeProperty();
			volumeProperty.ShadeOn();
			volumeProperty.SetInterpolationTypeToLinear();
			volumeProperty.SetColor(_colorTransferFunction);
			volumeProperty.SetScalarOpacity(_opacityTransferFunction);
			volumeProperty.SetDiffuse(0.7);
			volumeProperty.SetAmbient(0.1);
			volumeProperty.SetSpecular(.3);
			volumeProperty.SetSpecularPower(20);

			//vtkOpenGLVolumeTextureMapper2D volumeMapper = new vtkOpenGLVolumeTextureMapper2D();
			//vtkOpenGLVolumeTextureMapper3D volumeMapper = new vtkOpenGLVolumeTextureMapper3D();
			//volumeMapper.SetPreferredMethodToNVidia();
			//volumeMapper.SetSampleDistance(1.0f);
			//int supported = volumeMapper.IsRenderSupported(volumeProperty);

			vtkFixedPointVolumeRayCastMapper volumeMapper = new vtkFixedPointVolumeRayCastMapper();
			//vtkVolumeRayCastMapper volumeMapper = new vtkVolumeRayCastMapper();
			volumeMapper.SetInput(_volumeLayer.GetImageData());
			////vtkVolumeRayCastCompositeFunction rayCastFunction = new vtkVolumeRayCastCompositeFunction();
			////volumeMapper.SetVolumeRayCastFunction(rayCastFunction);
			//vtkVolumeRayCastIsosurfaceFunction rayCastFunction = new vtkVolumeRayCastIsosurfaceFunction();
			//volumeMapper.SetVolumeRayCastFunction(rayCastFunction);

			_vtkVolume = new vtkVolume();
			_vtkVolume.SetMapper(volumeMapper);
			_vtkVolume.SetProperty(volumeProperty);

			return _vtkVolume;
		}
Пример #4
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVgaussian(String [] argv)
    {
        //Prefix Content is: ""

          ren1 = vtkRenderer.New();
          renWin = vtkRenderWindow.New();
          renWin.AddRenderer((vtkRenderer)ren1);
          renWin.SetSize((int)300,(int)300);
          iren = new vtkRenderWindowInteractor();
          iren.SetRenderWindow((vtkRenderWindow)renWin);
          camera = new vtkCamera();
          camera.ParallelProjectionOn();
          camera.SetViewUp((double)0,(double)1,(double)0);
          camera.SetFocalPoint((double)12,(double)10.5,(double)15);
          camera.SetPosition((double)-70,(double)15,(double)34);
          camera.ComputeViewPlaneNormal();
          ren1.SetActiveCamera((vtkCamera)camera);
          // Create the reader for the data[]
          //vtkStructuredPointsReader reader[]
          reader = new vtkGaussianCubeReader();
          reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube");
          reader.SetHBScale((double)1.1);
          reader.SetBScale((double)10);
          reader.Update();
          range = reader.GetGridOutput().GetPointData().GetScalars().GetRange();
          min = (double)(lindex(range,0));
          max = (double)(lindex(range,1));
          readerSS = new vtkImageShiftScale();
          readerSS.SetInput((vtkDataObject)reader.GetGridOutput());
          readerSS.SetShift((double)min*-1);
          readerSS.SetScale((double)255/(max-min));
          readerSS.SetOutputScalarTypeToUnsignedChar();
          bounds = new vtkOutlineFilter();
          bounds.SetInput((vtkDataObject)reader.GetGridOutput());
          boundsMapper = vtkPolyDataMapper.New();
          boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort());
          boundsActor = new vtkActor();
          boundsActor.SetMapper((vtkMapper)boundsMapper);
          boundsActor.GetProperty().SetColor((double)0,(double)0,(double)0);
          contour = new vtkContourFilter();
          contour.SetInput((vtkDataObject)reader.GetGridOutput());
          contour.GenerateValues((int)5,(double)0,(double).05);
          contourMapper = vtkPolyDataMapper.New();
          contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
          contourMapper.SetScalarRange((double)0,(double).1);
          ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32,0);
          contourActor = new vtkActor();
          contourActor.SetMapper((vtkMapper)contourMapper);
          contourActor.GetProperty().SetOpacity((double).5);
          // Create transfer mapping scalar value to opacity[]
          opacityTransferFunction = new vtkPiecewiseFunction();
          opacityTransferFunction.AddPoint((double)0,(double)0.01);
          opacityTransferFunction.AddPoint((double)255,(double)0.35);
          opacityTransferFunction.ClampingOn();
          // Create transfer mapping scalar value to color[]
          colorTransferFunction = new vtkColorTransferFunction();
          colorTransferFunction.AddHSVPoint((double)0.0,(double)0.66,(double)1.0,(double)1.0);
          colorTransferFunction.AddHSVPoint((double)50.0,(double)0.33,(double)1.0,(double)1.0);
          colorTransferFunction.AddHSVPoint((double)100.0,(double)0.00,(double)1.0,(double)1.0);
          // The property describes how the data will look[]
          volumeProperty = new vtkVolumeProperty();
          volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction);
          volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction);
          volumeProperty.SetInterpolationTypeToLinear();
          // The mapper / ray cast function know how to render the data[]
          compositeFunction = new vtkVolumeRayCastCompositeFunction();
          volumeMapper = new vtkVolumeRayCastMapper();
          //vtkVolumeTextureMapper2D volumeMapper[]
          volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction);
          volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort());
          // The volume holds the mapper and the property and[]
          // can be used to position/orient the volume[]
          volume = new vtkVolume();
          volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper);
          volume.SetProperty((vtkVolumeProperty)volumeProperty);
          ren1.AddVolume((vtkProp)volume);
          //ren1 AddActor contourActor[]
          ren1.AddActor((vtkProp)boundsActor);
          //#####################################################################[]
          Sphere = new vtkSphereSource();
          Sphere.SetCenter((double)0,(double)0,(double)0);
          Sphere.SetRadius((double)1);
          Sphere.SetThetaResolution((int)16);
          Sphere.SetStartTheta((double)0);
          Sphere.SetEndTheta((double)360);
          Sphere.SetPhiResolution((int)16);
          Sphere.SetStartPhi((double)0);
          Sphere.SetEndPhi((double)180);
          Glyph = new vtkGlyph3D();
          Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          Glyph.SetOrient((int)1);
          Glyph.SetColorMode((int)1);
          //Glyph ScalingOn[]
          Glyph.SetScaleMode((int)2);
          Glyph.SetScaleFactor((double).6);
          Glyph.SetSource((vtkPolyData)Sphere.GetOutput());
          AtomsMapper = vtkPolyDataMapper.New();
          AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort());
          AtomsMapper.SetImmediateModeRendering((int)1);
          AtomsMapper.UseLookupTableScalarRangeOff();
          AtomsMapper.SetScalarVisibility((int)1);
          AtomsMapper.SetScalarModeToDefault();
          Atoms = new vtkActor();
          Atoms.SetMapper((vtkMapper)AtomsMapper);
          Atoms.GetProperty().SetRepresentationToSurface();
          Atoms.GetProperty().SetInterpolationToGouraud();
          Atoms.GetProperty().SetAmbient((double)0.15);
          Atoms.GetProperty().SetDiffuse((double)0.85);
          Atoms.GetProperty().SetSpecular((double)0.1);
          Atoms.GetProperty().SetSpecularPower((double)100);
          Atoms.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Atoms.GetProperty().SetColor((double)1,(double)1,(double)1);
          Tube = new vtkTubeFilter();
          Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
          Tube.SetNumberOfSides((int)16);
          Tube.SetCapping((int)0);
          Tube.SetRadius((double)0.2);
          Tube.SetVaryRadius((int)0);
          Tube.SetRadiusFactor((double)10);
          BondsMapper = vtkPolyDataMapper.New();
          BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort());
          BondsMapper.SetImmediateModeRendering((int)1);
          BondsMapper.UseLookupTableScalarRangeOff();
          BondsMapper.SetScalarVisibility((int)1);
          BondsMapper.SetScalarModeToDefault();
          Bonds = new vtkActor();
          Bonds.SetMapper((vtkMapper)BondsMapper);
          Bonds.GetProperty().SetRepresentationToSurface();
          Bonds.GetProperty().SetInterpolationToGouraud();
          Bonds.GetProperty().SetAmbient((double)0.15);
          Bonds.GetProperty().SetDiffuse((double)0.85);
          Bonds.GetProperty().SetSpecular((double)0.1);
          Bonds.GetProperty().SetSpecularPower((double)100);
          Bonds.GetProperty().SetSpecularColor((double)1,(double)1,(double)1);
          Bonds.GetProperty().SetColor((double)1,(double)1,(double)1);
          ren1.AddActor((vtkProp)Bonds);
          ren1.AddActor((vtkProp)Atoms);
          //###################################################[]
          ren1.SetBackground((double)1,(double)1,(double)1);
          ren1.ResetCamera();
          renWin.Render();
          //method moved

          renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute);
          iren.Initialize();

        //deleteAllVTKObjects();
    }
Пример #5
0
    /// <summary>
    /// The main entry method called by the CSharp driver
    /// </summary>
    /// <param name="argv"></param>
    public static void AVgaussian(String [] argv)
    {
        //Prefix Content is: ""

        ren1   = vtkRenderer.New();
        renWin = vtkRenderWindow.New();
        renWin.SetMultiSamples(0);
        renWin.AddRenderer((vtkRenderer)ren1);
        renWin.SetSize((int)300, (int)300);
        iren = new vtkRenderWindowInteractor();
        iren.SetRenderWindow((vtkRenderWindow)renWin);
        camera = new vtkCamera();
        camera.ParallelProjectionOn();
        camera.SetViewUp((double)0, (double)1, (double)0);
        camera.SetFocalPoint((double)12, (double)10.5, (double)15);
        camera.SetPosition((double)-70, (double)15, (double)34);
        camera.ComputeViewPlaneNormal();
        ren1.SetActiveCamera((vtkCamera)camera);
        // Create the reader for the data[]
        //vtkStructuredPointsReader reader[]
        reader = new vtkGaussianCubeReader();
        reader.SetFileName((string)"" + (VTK_DATA_ROOT.ToString()) + "/Data/m4_TotalDensity.cube");
        reader.SetHBScale((double)1.1);
        reader.SetBScale((double)10);
        reader.Update();
        range    = reader.GetGridOutput().GetPointData().GetScalars().GetRange();
        min      = (double)(lindex(range, 0));
        max      = (double)(lindex(range, 1));
        readerSS = new vtkImageShiftScale();
        readerSS.SetInputData((vtkDataObject)reader.GetGridOutput());
        readerSS.SetShift((double)min * -1);
        readerSS.SetScale((double)255 / (max - min));
        readerSS.SetOutputScalarTypeToUnsignedChar();
        bounds = new vtkOutlineFilter();
        bounds.SetInputData((vtkDataObject)reader.GetGridOutput());
        boundsMapper = vtkPolyDataMapper.New();
        boundsMapper.SetInputConnection((vtkAlgorithmOutput)bounds.GetOutputPort());
        boundsActor = new vtkActor();
        boundsActor.SetMapper((vtkMapper)boundsMapper);
        boundsActor.GetProperty().SetColor((double)0, (double)0, (double)0);
        contour = new vtkContourFilter();
        contour.SetInputData((vtkDataObject)reader.GetGridOutput());
        contour.GenerateValues((int)5, (double)0, (double).05);
        contourMapper = vtkPolyDataMapper.New();
        contourMapper.SetInputConnection((vtkAlgorithmOutput)contour.GetOutputPort());
        contourMapper.SetScalarRange((double)0, (double).1);
        ((vtkLookupTable)contourMapper.GetLookupTable()).SetHueRange(0.32, 0);
        contourActor = new vtkActor();
        contourActor.SetMapper((vtkMapper)contourMapper);
        contourActor.GetProperty().SetOpacity((double).5);
        // Create transfer mapping scalar value to opacity[]
        opacityTransferFunction = new vtkPiecewiseFunction();
        opacityTransferFunction.AddPoint((double)0, (double)0.01);
        opacityTransferFunction.AddPoint((double)255, (double)0.35);
        opacityTransferFunction.ClampingOn();
        // Create transfer mapping scalar value to color[]
        colorTransferFunction = new vtkColorTransferFunction();
        colorTransferFunction.AddHSVPoint((double)0.0, (double)0.66, (double)1.0, (double)1.0);
        colorTransferFunction.AddHSVPoint((double)50.0, (double)0.33, (double)1.0, (double)1.0);
        colorTransferFunction.AddHSVPoint((double)100.0, (double)0.00, (double)1.0, (double)1.0);
        // The property describes how the data will look[]
        volumeProperty = new vtkVolumeProperty();
        volumeProperty.SetColor((vtkColorTransferFunction)colorTransferFunction);
        volumeProperty.SetScalarOpacity((vtkPiecewiseFunction)opacityTransferFunction);
        volumeProperty.SetInterpolationTypeToLinear();
        // The mapper / ray cast function know how to render the data[]
        compositeFunction = new vtkVolumeRayCastCompositeFunction();
        volumeMapper      = new vtkVolumeRayCastMapper();
        //vtkVolumeTextureMapper2D volumeMapper[]
        volumeMapper.SetVolumeRayCastFunction((vtkVolumeRayCastFunction)compositeFunction);
        volumeMapper.SetInputConnection((vtkAlgorithmOutput)readerSS.GetOutputPort());
        // The volume holds the mapper and the property and[]
        // can be used to position/orient the volume[]
        volume = new vtkVolume();
        volume.SetMapper((vtkAbstractVolumeMapper)volumeMapper);
        volume.SetProperty((vtkVolumeProperty)volumeProperty);
        ren1.AddVolume((vtkProp)volume);
        //ren1 AddActor contourActor[]
        ren1.AddActor((vtkProp)boundsActor);
        //#####################################################################[]
        Sphere = new vtkSphereSource();
        Sphere.SetCenter((double)0, (double)0, (double)0);
        Sphere.SetRadius((double)1);
        Sphere.SetThetaResolution((int)16);
        Sphere.SetStartTheta((double)0);
        Sphere.SetEndTheta((double)360);
        Sphere.SetPhiResolution((int)16);
        Sphere.SetStartPhi((double)0);
        Sphere.SetEndPhi((double)180);
        Glyph = new vtkGlyph3D();
        Glyph.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        Glyph.SetOrient((int)1);
        Glyph.SetColorMode((int)1);
        //Glyph ScalingOn[]
        Glyph.SetScaleMode((int)2);
        Glyph.SetScaleFactor((double).6);
        Glyph.SetSourceConnection(Sphere.GetOutputPort());
        AtomsMapper = vtkPolyDataMapper.New();
        AtomsMapper.SetInputConnection((vtkAlgorithmOutput)Glyph.GetOutputPort());
        AtomsMapper.SetImmediateModeRendering((int)1);
        AtomsMapper.UseLookupTableScalarRangeOff();
        AtomsMapper.SetScalarVisibility((int)1);
        AtomsMapper.SetScalarModeToDefault();
        Atoms = new vtkActor();
        Atoms.SetMapper((vtkMapper)AtomsMapper);
        Atoms.GetProperty().SetRepresentationToSurface();
        Atoms.GetProperty().SetInterpolationToGouraud();
        Atoms.GetProperty().SetAmbient((double)0.15);
        Atoms.GetProperty().SetDiffuse((double)0.85);
        Atoms.GetProperty().SetSpecular((double)0.1);
        Atoms.GetProperty().SetSpecularPower((double)100);
        Atoms.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Atoms.GetProperty().SetColor((double)1, (double)1, (double)1);
        Tube = new vtkTubeFilter();
        Tube.SetInputConnection((vtkAlgorithmOutput)reader.GetOutputPort());
        Tube.SetNumberOfSides((int)16);
        Tube.SetCapping((int)0);
        Tube.SetRadius((double)0.2);
        Tube.SetVaryRadius((int)0);
        Tube.SetRadiusFactor((double)10);
        BondsMapper = vtkPolyDataMapper.New();
        BondsMapper.SetInputConnection((vtkAlgorithmOutput)Tube.GetOutputPort());
        BondsMapper.SetImmediateModeRendering((int)1);
        BondsMapper.UseLookupTableScalarRangeOff();
        BondsMapper.SetScalarVisibility((int)1);
        BondsMapper.SetScalarModeToDefault();
        Bonds = new vtkActor();
        Bonds.SetMapper((vtkMapper)BondsMapper);
        Bonds.GetProperty().SetRepresentationToSurface();
        Bonds.GetProperty().SetInterpolationToGouraud();
        Bonds.GetProperty().SetAmbient((double)0.15);
        Bonds.GetProperty().SetDiffuse((double)0.85);
        Bonds.GetProperty().SetSpecular((double)0.1);
        Bonds.GetProperty().SetSpecularPower((double)100);
        Bonds.GetProperty().SetSpecularColor((double)1, (double)1, (double)1);
        Bonds.GetProperty().SetColor((double)1, (double)1, (double)1);
        ren1.AddActor((vtkProp)Bonds);
        ren1.AddActor((vtkProp)Atoms);
        //###################################################[]
        ren1.SetBackground((double)1, (double)1, (double)1);
        ren1.ResetCamera();
        renWin.Render();
        //method moved

        renWin.AbortCheckEvt += new Kitware.VTK.vtkObject.vtkObjectEventHandler(TkCheckAbort_Command.Execute);
        iren.Initialize();

//deleteAllVTKObjects();
    }
Пример #6
0
        /// <summary>
        ///
        /// <summary>
        /// 用体绘制的方法绘制一系列的图像
        /// </summary>
        /// <param name="format">图像文件的字符串格式</param>
        /// <param name="height">一幅图像的高度</param>
        /// <param name="width">高度</param>
        /// <param name="startIndex">起始index</param>
        /// <param name="endIndex">末尾index</param>
        /// <param name="r">renderer,如果非空,则将其体绘制结果添加到这里面来</param>
        /// example:
        ///     CuteTools.ShowImageSeries(@"initial/%03d.bmp",64, 64, 0, 62);
        public static void ShowImageSeries(string format, int height, int width, int startIndex, int endIndex, vtkRenderer r = null)
        {
            if (format == null || format.Count() <= 4 || (!format.Substring(format.Count() - 3, 3).Equals("bmp")))
            {
                Console.WriteLine("image filename is not correct!!");
                return;
            }

            vtkBMPReader reader = vtkBMPReader.New();

            reader.SetFilePattern(format);

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

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

            vtkVolume vol = vtkVolume.New();

            vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New();

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

            vtkColorTransferFunction colorTransferFunction = vtkColorTransferFunction.New();

            colorTransferFunction.AddRGBPoint(0.0, 0.0, 255.0, 0.0);
            //colorTransferFunction.AddRGBPoint(120.0, 0.0, 0.0, 1.0);
            //colorTransferFunction.AddRGBPoint(160.0, 1.0, 0.0, 0.0);
            //colorTransferFunction.AddRGBPoint(200.0, 0.0, 1.0, 0.0);
            colorTransferFunction.AddRGBPoint(255, 0, 0, 1.0);
            colorTransferFunction.ClampingOn();

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

            compositeOpacity.AddPoint(80, 1);
            compositeOpacity.AddPoint(120, 0.2);
            compositeOpacity.AddPoint(255, 0);
            compositeOpacity.ClampingOn();
            vpro.SetScalarOpacity(compositeOpacity);
            //vpro.SetColor( colorTransferFunction );
            vpro.SetInterpolationTypeToLinear();
            //vpro.ShadeOn();
            vol.SetProperty(vpro);

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

            if (r != null)
            {
                r.AddVolume(vol);
            }
            else
            {
                vtkRenderer render = vtkRenderer.New();
                render.AddVolume(vol);
                render.SetBackground(1, 1, 1);

                vtkRenderWindow wnd = vtkRenderWindow.New();
                wnd.AddRenderer(render);

                vtkRenderWindowInteractor inter = vtkRenderWindowInteractor.New();
                inter.SetRenderWindow(wnd);

                inter.Initialize();
                inter.Start();
            }
        }
Пример #7
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);
        }