/// <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();
            }
        }
Esempio n. 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;
        }
        /// <summary>
        /// Changes the opacity function to another serie from preset.
        /// </summary>
        /// <param name="numberOfSerie">Number of serie to update.</param>
        public void ChangeToSerie(PresetInformation PresetInfo, int numberOfSerie)
        {
            vtkPiecewiseFunction spwf = vtkPiecewiseFunction.New();

            foreach (var pair in PresetInfo.Series[numberOfSerie].OpacityFunction)
            {
                spwf.AddPoint(pair.Key, pair.Value);
            }
            _volume.GetProperty().SetScalarOpacity(spwf);

            _window.Validate();
            _window.Update();
            _window.RenderWindow.Render();

            _currentSerieNumber = numberOfSerie;
        }
Esempio n. 4
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBoxSeries != null && PresetInfo != null)
            {
                PresetInfo = PresetReader.ReadXmlFile(comboBox1.Text);
                if (_vizualization3D != null)
                {
                    _vizualization3D.ChangeColorAndOpacityFunction(PresetInfo);
                }

                comboBoxSeries.Items.Clear();
                int numberOfSeries = PresetInfo.Series.Count;
                for (var i = 0; i < numberOfSeries; i++)
                {
                    comboBoxSeries.Items.Add(i.ToString(CultureInfo.InvariantCulture));
                }
                comboBoxSeries.SelectedIndex = 0;
                updateChart();
                colorStrip.Invalidate();
            }
        }
Esempio n. 5
0
        //wizualizacja 3d -----------------------------------------------------------------
        private void fourthWindow_Load(object sender, EventArgs e)
        {
            string[] filePaths = Directory.GetFiles(Path.Combine(Directory.GetCurrentDirectory(), PresetDir), "*.xml");

            PresetInfo = PresetReader.ReadXmlFile(new FileInfo(filePaths[0]).Name);

            foreach (string dir in filePaths)
            {
                comboBox1.Items.Add(new FileInfo(dir).Name);
            }
            comboBox1.SelectedIndex = 1;

            comboBoxSeries.Items.Clear();
            int numberOfSeries = PresetInfo.Series.Count;

            for (int i = 0; i < numberOfSeries; i++)
            {
                comboBoxSeries.Items.Add(i.ToString(CultureInfo.InvariantCulture));
            }
            comboBoxSeries.SelectedIndex = 0;

            createVisialization3D();
            updateChart();
        }
        /// <summary>
        /// Generate strip representing function of color.
        /// </summary>
        /// <param name="sourceGraphics">Graphics to paint strip on.</param>
        /// <param name="height">Strip height.</param>
        /// <param name="width">Strip width.</param>
        public void GenerateStrip(PresetInformation PresetInfo, Graphics sourceGraphics, int height, int width)
        {
            var opacityFunction = _volume.GetProperty().GetScalarOpacity();

            var colorFunction = _volume.GetProperty().GetRGBTransferFunction();

            double[] rangeArray = opacityFunction.GetRange();
            var      min        = (float)rangeArray[0];
            var      max        = (float)rangeArray[1];
            int      len        = (int)(max - min);

            logger.Warn(rangeArray[1].ToString() + " " + rangeArray[0].ToString());

            int   unit = len / width;
            int   counter;
            int?  prevCounter = null;
            float counterf    = 0;

            var colorList = PresetInfo.Series[_currentSerieNumber].ColorFuction.Keys
                            .Where(key => key > min & key < max)
                            .Select(key => PresetInfo.Series[_currentSerieNumber].ColorFuction[key]).ToList();

            var firstColor = Color.FromArgb(255, (int)colorFunction.GetRedValue(min),
                                            (int)colorFunction.GetGreenValue(min), (int)colorFunction.GetBlueValue(min));

            var lastColor = Color.FromArgb(255, (int)colorFunction.GetRedValue(max),
                                           (int)colorFunction.GetGreenValue(max), (int)colorFunction.GetBlueValue(max));

            colorList.Add(new Color[] { lastColor, lastColor });
            colorList.Insert(0, new Color[] { firstColor, firstColor });

            var keyList = PresetInfo.Series[_currentSerieNumber].ColorFuction.Keys.Select(key => key).Where(key => key > min & key < max).ToList();

            keyList.Add(max);
            keyList.Insert(0, min);

            int i = -1;

            foreach (var key in keyList)
            {
                i++;
                if (prevCounter == null)
                {
                    prevCounter = (int)0;
                    counterf    = key;
                }
                else
                {
                    counter = (int)((key - counterf) / unit);
                    if (counter > 0)
                    {
                        var colorInfo1 = colorList[i - 1][1];
                        var colorInfo2 = colorList[i][0];

                        logger.Warn(counterf.ToString() + " " + key.ToString() + " " + colorInfo1.ToString() + " " + colorInfo2.ToString());

                        var rect = new Rectangle(prevCounter.Value, 0, prevCounter.Value + counter, height);

                        using (Brush aGradientBrush = new LinearGradientBrush(rect, colorInfo1, colorInfo2, LinearGradientMode.Horizontal))
                        {
                            sourceGraphics.FillRectangle(aGradientBrush, prevCounter.Value, 0, prevCounter.Value + counter, height);
                        }
                    }
                    prevCounter = prevCounter.Value + counter;
                    counterf    = key;
                }
            }
        }