Exemple #1
0
        void UpdateChannel()
        {
            int i, j;

            _mplayer.Close();

            _throughputGraph.BeginUpdate();
            _throughputSeries.SamplesSingle = _throughputdata[_selectChannelIndex];
            _rmsSeries.SamplesSingle        = _rmsData[_selectChannelIndex];
            _throughputGraph.ViewXY.ZoomToFit();
            _throughputGraph.EndUpdate();

            _tfGraph.BeginUpdate();
            _tfdata = new double[_dataFileNode.NFrame][];
            float[] curdata = new float[_dataFileNode.Nfft];
            float[] fdata   = null;
            int     curind  = 0;

            for (i = 0; i < _dataFileNode.NFrame; i++)
            {
                Array.Copy(_throughputdata[_selectChannelIndex], curind, curdata, 0, _dataFileNode.Nfft);
                curind += _dataFileNode.FrameDN;

                spectrumCalculator.PowerSpectrum(curdata, out fdata);
                _tfdata[i] = new double[flen];
                for (j = 0; j < flen; j++)
                {
                    _tfdata[i][j] = 20 * Math.Log10(fdata[j + fstarti]) + _aweightdb[j];
                }
            }
            _tfSeries.SetValuesData(_tfdata, IntensityGridValuesDataOrder.ColumnsRows);
            _tfGraph.ViewXY.ZoomToFit();
            _tfGraph.EndUpdate();

            oldiColIndex = -1;
            verticalCursor_PositionChanged(null, new PositionChangedEventArgs()
            {
                NewValue = _tfgraph_verticalCursor.ValueAtXAxis
            });
        }
        /// <summary>
        /// 构造
        /// </summary>
        /// <param name="parentControl">父控件</param>
        /// <param name="verticalScrolling">是否可以垂直滚动</param>
        /// <param name="resolution">分辨率</param>
        /// <param name="timeStepMs"></param>
        /// <param name="timeRangeLengthSec"></param>
        /// <param name="freqMin">最小频率</param>
        /// <param name="freqMax">最大频率</param>
        /// <param name="title">频谱仪标题(未使用)</param>
        /// <param name="toneColor"></param>
        public SpectrogramViewXYIntensity(Panel parentControl, bool verticalScrolling,
                                          int resolution, double timeStepMs, double timeRangeLengthSec,
                                          double freqMin, double freqMax, string title, Color toneColor)
        {
            _parentControl = parentControl;

            double dDefaultYMax = 7000000;

            double dAxisTimeScaleMin = timeStepMs / 1000.0 - timeRangeLengthSec;
            double dAxisTimeScaleMax = 0;

            m_dStepTime           = timeStepMs / 1000.0;
            m_dTimeRangeLengthSec = timeRangeLengthSec;

            //Create chart
            LightningChartUltimate chart = new LightningChartUltimate();

            _chart = chart;
            _chart.VerticalAlignment   = VerticalAlignment.Top;
            _chart.HorizontalAlignment = HorizontalAlignment.Left;

            m_bIsHorizontalScrolling = !verticalScrolling;

            chart.BeginUpdate();

            parentControl.Children.Add(chart);

            _chart.ChartBackground.Color             = ChartTools.CalcGradient(toneColor, Colors.Black, 65);
            _chart.ChartBackground.GradientDirection = 0;
            _chart.ChartBackground.GradientFill      = GradientFill.Cylindrical;

            chart.ChartName    = "Spectrogram chart";
            chart.ViewXY.XAxes = ViewXY.CreateDefaultXAxes();
            chart.ViewXY.YAxes = ViewXY.CreateDefaultYAxes();

            chart.Title.Visible = false;
            chart.Title.Font    = new WpfFont("Segoe UI", 13, true, false);
            chart.Title.Offset.SetValues(0, 20);
            chart.ViewXY.ZoomPanOptions.RightMouseButtonAction = MouseButtonAction.None;
            chart.ViewXY.ZoomPanOptions.LeftMouseButtonAction  = MouseButtonAction.None;
            chart.ViewXY.ZoomPanOptions.MouseWheelZooming      = MouseWheelZooming.Off;

            //Disable automatic axis layouts
            chart.ViewXY.AxisLayout.AutoAdjustMargins       = false;
            chart.ViewXY.AxisLayout.XAxisAutoPlacement      = XAxisAutoPlacement.Off;
            chart.ViewXY.AxisLayout.YAxisAutoPlacement      = YAxisAutoPlacement.Off;
            chart.ViewXY.AxisLayout.XAxisTitleAutoPlacement = false;
            chart.ViewXY.AxisLayout.YAxisTitleAutoPlacement = false;
            chart.ViewXY.Margins = new Thickness(60, 10, 15, 50);

            if (m_bIsHorizontalScrolling)
            {
                chart.ViewXY.XAxes[0].ValueType  = AxisValueType.Time;
                chart.ViewXY.XAxes[0].Title.Text = "Time";
                chart.ViewXY.XAxes[0].SetRange(dAxisTimeScaleMin, dAxisTimeScaleMax);

                chart.ViewXY.YAxes[0].ValueType  = AxisValueType.Number;
                chart.ViewXY.YAxes[0].Title.Text = "Frequency(Hz)";
                chart.ViewXY.YAxes[0].SetRange(freqMin, freqMax);
            }
            else
            {
                chart.ViewXY.XAxes[0].ValueType  = AxisValueType.Number;
                chart.ViewXY.XAxes[0].Title.Text = "Frequency(Hz)";
                chart.ViewXY.XAxes[0].SetRange(freqMin, freqMax);

                chart.ViewXY.YAxes[0].ValueType  = AxisValueType.Time;
                chart.ViewXY.YAxes[0].Title.Text = "Time";
                chart.ViewXY.YAxes[0].SetRange(dAxisTimeScaleMin, dAxisTimeScaleMax);
            }

            m_dCurrentTime = dAxisTimeScaleMax;

            Color color = Colors.White;

            chart.ViewXY.XAxes[0].MinorDivTickStyle.Visible = false;
            chart.ViewXY.XAxes[0].LabelsColor             = Color.FromArgb(200, color.R, color.G, color.B);
            chart.ViewXY.XAxes[0].MajorDivTickStyle.Color = Colors.Orange;
            chart.ViewXY.XAxes[0].Title.Shadow.Style      = TextShadowStyle.Off;
            chart.ViewXY.XAxes[0].LabelsNumberFormat      = "0";

            chart.ViewXY.YAxes[0].MinorDivTickStyle.Visible = false;
            chart.ViewXY.YAxes[0].LabelsColor             = Color.FromArgb(200, color.R, color.G, color.B);
            chart.ViewXY.YAxes[0].MajorDivTickStyle.Color = Colors.Orange;
            chart.ViewXY.YAxes[0].Title.Shadow.Style      = TextShadowStyle.Off;
            chart.ViewXY.YAxes[0].LabelsNumberFormat      = "0";

            //Setup legend box
            chart.ViewXY.LegendBoxes = ViewXY.CreateDefaultLegendBoxes();
            chart.ViewXY.LegendBoxes[0].SeriesTitleColor = toneColor;
            chart.ViewXY.LegendBoxes[0].ValueLabelColor  = Colors.White;
            chart.ViewXY.LegendBoxes[0].IntensityScales.ScaleBorderColor = Colors.White;
            chart.ViewXY.LegendBoxes[0].Position = LegendBoxPositionXY.RightCenter;
            chart.ViewXY.LegendBoxes[0].Layout   = LegendBoxLayout.Vertical;
            chart.ViewXY.LegendBoxes[0].Offset.SetValues(-20, 0);
            chart.ViewXY.LegendBoxes[0].Fill.Style     = RectFillStyle.None;
            chart.ViewXY.LegendBoxes[0].Shadow.Visible = false;
            chart.ViewXY.LegendBoxes[0].BorderWidth    = 0;
            chart.ViewXY.LegendBoxes[0].IntensityScales.ScaleSizeDim1 = 100;
            chart.ViewXY.LegendBoxes[0].IntensityScales.ScaleSizeDim2 = 15;
            chart.ViewXY.LegendBoxes[0].ShowCheckboxes = false;
            chart.ViewXY.LegendBoxes[0].UnitsColor     = Colors.Transparent;
            chart.Name = "Spectrogram";

            //Create grid
            _grid = new IntensityGridSeries(chart.ViewXY, chart.ViewXY.XAxes[0], chart.ViewXY.YAxes[0]);
            chart.ViewXY.IntensityGridSeries.Add(_grid);

            m_iSizeTimeSlots  = (int)Math.Round(timeRangeLengthSec / (timeStepMs / 1000.0));
            m_iSizeResolution = resolution;

            m_aFastData = new double[m_iSizeTimeSlots][];
            for (int iTimeSlot = 0; iTimeSlot < m_iSizeTimeSlots; iTimeSlot++)
            {
                m_aFastData[iTimeSlot] = new double[m_iSizeResolution];
            }
            if (m_bIsHorizontalScrolling)
            {
                _grid.SetValuesData(m_aFastData, IntensityGridValuesDataOrder.ColumnsRows);
            }
            else
            {
                _grid.SetValuesData(m_aFastData, IntensityGridValuesDataOrder.RowsColumns);
            }

            _grid.Data = null;

            _grid.SetRangesXY(chart.ViewXY.XAxes[0].Minimum, chart.ViewXY.XAxes[0].Maximum,
                              chart.ViewXY.YAxes[0].Minimum, chart.ViewXY.YAxes[0].Maximum);
            _grid.ContourLineType   = ContourLineTypeXY.None;
            _grid.WireframeType     = SurfaceWireframeType.None;
            _grid.PixelRendering    = true;
            _grid.MouseInteraction  = false;
            _grid.ValueRangePalette = CreatePalette(_grid, dDefaultYMax);
            _grid.Title.Text        = "P(f)";
            chart.EndUpdate();
        }