Пример #1
0
        private void RenderVTI()
        {
            // reader
            // Read all the data from the file
            vtkXMLImageDataReader reader = vtkXMLImageDataReader.New();

            if (reader.CanReadFile(m_FileName) == 0)
            {
                MessageBox.Show("Cannot read file \"" + m_FileName + "\"", "Error", MessageBoxButtons.OK);
                return;
            }
            vtkVolume vol = vtkVolume.New();
            vtkColorTransferFunction ctf  = vtkColorTransferFunction.New();
            vtkPiecewiseFunction     spwf = vtkPiecewiseFunction.New();
            vtkPiecewiseFunction     gpwf = vtkPiecewiseFunction.New();

            reader.SetFileName(m_FileName);
            reader.Update(); // here we read the file actually

            // mapper
            vtkFixedPointVolumeRayCastMapper mapper = vtkFixedPointVolumeRayCastMapper.New();

            mapper.SetInputConnection(reader.GetOutputPort());

            // actor
            vtkActor actor = vtkActor.New();

            //actor.SetMapper(mapper);
            actor.GetProperty().SetRepresentationToWireframe();

            // add our actor to the renderer
            //Set the color curve for the volume
            ctf.AddHSVPoint(0, .67, .07, 1);
            ctf.AddHSVPoint(94, .67, .07, 1);
            ctf.AddHSVPoint(139, 0, 0, 0);
            ctf.AddHSVPoint(160, .28, .047, 1);
            ctf.AddHSVPoint(254, .38, .013, 1);

            //Set the opacity curve for the volume
            spwf.AddPoint(84, 0);
            spwf.AddPoint(151, .1);
            spwf.AddPoint(255, 1);

            //Set the gradient curve for the volume
            gpwf.AddPoint(0, .2);
            gpwf.AddPoint(10, .2);
            gpwf.AddPoint(25, 1);

            vol.GetProperty().SetColor(ctf);
            vol.GetProperty().SetScalarOpacity(spwf);
            vol.GetProperty().SetGradientOpacity(gpwf);

            vol.SetMapper(mapper);

            //Go through the Graphics Pipeline
            m_Renderer.AddVolume(vol);
            m_Renderer.ResetCamera();
            //renderer.AddActor(actor);
            RenderSlicer();
        }
Пример #2
0
        /// <summary>
        /// Reads new preset, updating color and opacity function from it.
        /// </summary>
        /// <param name="presetName">Name of choosen preset.</param>
        public void ChangeColorAndOpacityFunction(string presetName)
        {
            vtkColorTransferFunction ctf  = vtkColorTransferFunction.New();
            vtkPiecewiseFunction     spwf = vtkPiecewiseFunction.New();

            PresetInfo = PresetReader.ReadXmlFile(presetName);
            _chart.Series["OpacityFunction"].Points.Clear();
            _chart.Series["OpacityFunctionSpline"].Points.Clear();

            foreach (var pair in PresetInfo.Series[0].OpacityFunction)
            {
                spwf.AddPoint(pair.Key, pair.Value);
                _chart.Series["OpacityFunction"].Points.AddXY(pair.Key, pair.Value);
                _chart.Series["OpacityFunctionSpline"].Points.AddXY(pair.Key, pair.Value);
            }

            foreach (var pair in PresetInfo.Series[0].ColorFuction)
            {
                ctf.AddRGBSegment(pair.Key, pair.Value[0].R, pair.Value[0].G, pair.Value[0].B,
                                  pair.Key, pair.Value[1].R, pair.Value[1].G, pair.Value[1].B);
                //Color colorRight = Color.FromArgb((int)pair.Value[1].R, (int)pair.Value[1].G, (int)pair.Value[1].B);
                //Color colorLeft = Color.FromArgb((int)pair.Value[0].R, (int)pair.Value[0].G, (int)pair.Value[0].B);
            }

            ctf.SetScaleToLinear();
            _volume.GetProperty().SetColor(ctf);
            _volume.GetProperty().SetScalarOpacity(spwf);

            _currentSerieNumber = 0;
        }
Пример #3
0
        /// <summary>
        /// Display the render window with the 3D Volume in it
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void renderWindowControl2_Load(object sender, EventArgs e)
        {
            //Create all the objects for the pipeline
            vtkRenderer                      renderer  = renderWindowControl2.RenderWindow.GetRenderers().GetFirstRenderer();
            vtkXMLImageDataReader            reader    = vtkXMLImageDataReader.New();
            vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New();
            vtkVolume vol = vtkVolume.New();
            vtkColorTransferFunction ctf  = vtkColorTransferFunction.New();
            vtkPiecewiseFunction     spwf = vtkPiecewiseFunction.New();
            vtkPiecewiseFunction     gpwf = vtkPiecewiseFunction.New();

            //Read in the file
            reader.SetFileName(fileName);
            reader.Update();

            //Go through the visulizatin pipeline
            texMapper.SetInputConnection(reader.GetOutputPort());

            //Set the color curve for the volume
            ctf.AddHSVPoint(0, .67, .07, 1);
            ctf.AddHSVPoint(94, .67, .07, 1);
            ctf.AddHSVPoint(139, 0, 0, 0);
            ctf.AddHSVPoint(160, .28, .047, 1);
            ctf.AddHSVPoint(254, .38, .013, 1);

            //Set the opacity curve for the volume
            spwf.AddPoint(84, 0);
            spwf.AddPoint(151, .1);
            spwf.AddPoint(255, 1);

            //Set the gradient curve for the volume
            gpwf.AddPoint(0, .2);
            gpwf.AddPoint(10, .2);
            gpwf.AddPoint(25, 1);

            vol.GetProperty().SetColor(ctf);
            vol.GetProperty().SetScalarOpacity(spwf);
            vol.GetProperty().SetGradientOpacity(gpwf);

            vol.SetMapper(texMapper);

            //Go through the Graphics Pipeline
            renderer.AddVolume(vol);
        }
        /// <summary>
        /// Reads new preset, updating color and opacity function from it.
        /// </summary>
        /// <param name="presetName">Name of choosen preset.</param>
        public void ChangeColorAndOpacityFunction(PresetInformation PresetInfo)
        {
            vtkColorTransferFunction ctf  = vtkColorTransferFunction.New();
            vtkPiecewiseFunction     spwf = vtkPiecewiseFunction.New();

            if (PresetInfo != null)
            {
                foreach (var pair in PresetInfo.Series[0].OpacityFunction)
                {
                    spwf.AddPoint(pair.Key, pair.Value);
                }

                foreach (var pair in PresetInfo.Series[0].ColorFuction)
                {
                    ctf.AddRGBSegment(pair.Key, pair.Value[0].R, pair.Value[0].G, pair.Value[0].B,
                                      pair.Key, pair.Value[1].R, pair.Value[1].G, pair.Value[1].B);
                }

                ctf.SetScaleToLinear();
                _volume.GetProperty().SetColor(ctf);
                _volume.GetProperty().SetScalarOpacity(spwf);

                _currentSerieNumber = 0;
                Update3DVisualization();
            }
        }
        public void changeColorFunction(String presetName)
        {
            ctf = vtkColorTransferFunction.New();
            Dictionary <int, float[]> values = presetMapper.changeColorFunction(presetName);

            foreach (var pair in values)
            {
                ctf.AddRGBPoint(pair.Key, pair.Value[0], pair.Value[1], pair.Value[2]);
            }

            vol.GetProperty().SetColor(ctf);
        }
Пример #6
0
        public void Coloring(int shft = 0)
        {
            //vtkFixedPointVolumeRayCastMapper texMapper = vtkFixedPointVolumeRayCastMapper.New();
            vtkSmartVolumeMapper texMapper = vtkSmartVolumeMapper.New();

            vol = vtkVolume.New();
            vtkColorTransferFunction ctf  = vtkColorTransferFunction.New();
            vtkPiecewiseFunction     spwf = vtkPiecewiseFunction.New();
            vtkPiecewiseFunction     gpwf = vtkPiecewiseFunction.New();

            texMapper.SetInputConnection(reader3D.GetOutputPort());

            //Set the color curve for the volume
            //ctf.AddHSVPoint(0, .67, .07, 1);
            //ctf.AddHSVPoint(94, .67, .07, 1);
            //ctf.AddHSVPoint(139, 0, 0, 0);
            //ctf.AddHSVPoint(160, .28, .047, 1);
            //ctf.AddHSVPoint(254, .38, .013, 1);

            ctf.AddRGBPoint(0.0, 0.0, 0.0, 0.0);
            ctf.AddRGBPoint(64.0, 1.0, 0.0, 0.0);
            ctf.AddRGBPoint(128.0, 0.0, 0.0, 1.0);
            ctf.AddRGBPoint(192.0, 0.0, 1.0, 0.0);
            ctf.AddRGBPoint(255.0, 0.0, 0.2, 0.0);

            //Set the opacity curve for the volume
            spwf.AddPoint(584 + shft, 0);
            spwf.AddPoint(651 + shft, .1);
            //spwf.AddPoint(255, 1);


            //spwf.AddPoint(4, 0);
            //spwf.AddPoint(51, .7);
            //spwf.AddPoint(155, 0.5);
            //spwf.AddPoint(255, 0.2);
            //spwf.AddPoint(1055, 0);


            //Set the gradient curve for the volume
            //gpwf.AddPoint(0, .2);
            gpwf.AddPoint(10, 1);
            gpwf.AddPoint(225, 0.5);
            gpwf.AddPoint(1235, 0.2);
            gpwf.AddPoint(3235, 0);

            vol.GetProperty().SetColor(ctf);
            vol.GetProperty().SetScalarOpacity(spwf);
            //vol.GetProperty().SetGradientOpacity(gpwf);

            vol.GetProperty().ShadeOn();
            vol.GetProperty().SetInterpolationTypeToLinear();

            vol.SetMapper(texMapper);

            //green background
            renderer3D.SetBackground(0.3, 0.6, 0.3);
            //Go through the Graphics Pipeline
            renderer3D.AddVolume(vol);

            renderWindow3D.Render();
        }