Пример #1
0
        public static SpectralPoint[] ToSpectralPoints(ExperimentEntityDataViewModel data, double[] wavelengthArray)
        {
            var spectralPointArray = new SpectralPoint[wavelengthArray.Length];

            for (int i = 0; i < wavelengthArray.Length; i++)
            {
                spectralPointArray[i] = new SpectralPoint
                {
                    WaveLength      = wavelengthArray[i],
                    DistancedSignal = new Dictionary <double, double>()
                };
            }

            foreach (var dataItem in data.DataItems.Where(x => x.Distance > 0))
            {
                alglib.spline1dinterpolant s;
                alglib.spline1dbuildlinear(data.WaveLengthArray, dataItem.IntensityArray, out s);
                for (int i = 0; i < wavelengthArray.Length; i++)
                {
                    if (!spectralPointArray[i].DistancedSignal.ContainsKey(dataItem.Distance))
                    {
                        var value = alglib.spline1dcalc(s, spectralPointArray[i].WaveLength);
                        spectralPointArray[i].DistancedSignal.Add(dataItem.Distance, value);
                    }
                }
            }


            return(spectralPointArray);
        }
        private void ProcessDataItem(ExperimentEntityDataViewModel data, ExperimentEntityDataItemViewModel dataItem, int width,
                                     int height, double maxX, double maxY, double minX, double minY, int number)
        {
            if (data.WaveLengthArray.Length != dataItem.IntensityArray.Length || data.WaveLengthArray.Length < 2)
            {
                return;
            }
            if (_isDivideToBase)
            {
                if (dataItem.IsNoise || dataItem.IsNormalize)
                {
                    return;
                }
            }


            var key            = GetKey(dataItem);
            var intensityArray = dataItem.IntensityArray;

            if (_isDivideToBase)
            {
                intensityArray = (double[])intensityArray.Clone();
                for (int i = 0; i < intensityArray.Length; i++)
                {
                    intensityArray[i] /= _base[i];
                }
            }
            var pointsForShow = CalculatePoints(data.WaveLengthArray, intensityArray, width, height, maxX, maxY, minX,
                                                minY);


            Application.Current.Dispatcher.Invoke((Action) delegate()
            {
                var segmentsList = new PathSegmentCollection();
                for (int i = 1; i < pointsForShow.Count(); i++)
                {
                    var lineSegment = new LineSegment()
                    {
                        Point = pointsForShow[i].Item1,
                    };

                    //lineSegment.IsSmoothJoin = true;
                    segmentsList.Add(lineSegment);
                }
                PathFigure pathFigure = new PathFigure()
                {
                    StartPoint = pointsForShow[0].Item1,
                    Segments   = segmentsList,
                    IsClosed   = false,
                    IsFilled   = false
                };
                var geometry = new PathGeometry()
                {
                    Figures = new PathFigureCollection()
                    {
                        pathFigure
                    }
                };
                geometry.Freeze();
                var stroke = _brushes[number % _brushes.Length];

                var path = new Path()
                {
                    Data = geometry,

                    StrokeThickness = 1,
                    Stroke          = stroke,
                    Visibility      = dataItem.IsShow ? Visibility.Visible : Visibility.Hidden
                };

                GraphCanvas.Children.Add(path);
                if (_dictionaryPaths.ContainsKey(key))
                {
                    _dictionaryPaths[key] = path;
                }
                else
                {
                    _dictionaryPaths.Add(key, path);
                }
                if (_dictionaryColors.ContainsKey(key))
                {
                    _dictionaryColors[key] = stroke;
                }
                else
                {
                    _dictionaryColors.Add(key, stroke);
                }
            });
            if (_dictionaryOfPointsToshow.ContainsKey(key))
            {
                _dictionaryOfPointsToshow[key] = pointsForShow;
            }
            else
            {
                _dictionaryOfPointsToshow.Add(key, pointsForShow);
            }


            if (_dictionaryViewModels.ContainsKey(key))
            {
                _dictionaryViewModels[key] = dataItem;
            }
            else
            {
                _dictionaryViewModels.Add(key, dataItem);
            }
            //Path.Data = geometry;
        }