-2

WPFとC#(動的データ表示)を使用して、リアルタイム信号、信号対時間のプロットを試みています。信号が生成されると、すぐにプロット チャートに表示されます。信号は非常に高速 (ミリ秒 (0.001 秒) のオーダー) で生成できます。それを行う最良の方法は何ですか?どんな提案でも大歓迎です.Thanks.

EDIT:サンプルコードは高く評価されます。

これが私が試したことです:

プロットの開始:

#region Constructor
public SignalStatsDisplay()
{
    InitializeComponent();

    plotter.Legend.Remove();

    _initialChildrenCount = plotter.Children.Count;

    int count = plotter.Children.Count;

    //do not remove the initial children
    if (count > _initialChildrenCount)
    {
        for (int i = count - 1; i >= _initialChildrenCount; i--)
        {
            plotter.Children.RemoveAt(i);
        }
    }

    _nColorChannels = 4;

    _lineprofileColor = new Color[4];

    _lineprofileColor[0] = Colors.Transparent;
    _lineprofileColor[1] = Colors.Red;
    _lineprofileColor[2] = Colors.Black;
    _lineprofileColor[3] = Colors.Blue;


    //LineGraph lg = new LineGraph();
    LineAndMarker<MarkerPointsGraph> lg = new LineAndMarker<MarkerPointsGraph>();
    CirclePointMarker pm = new CirclePointMarker { Size = 10, Fill = Brushes.Green };

  //  MarkerPointsGraph mpg = new MarkerPointsGraph();

    if (_nColorChannels > 0)    // plotter init
    {
        _dataX = new List<int[]>();
        _dataY = new List<int[]>();

        int[] dataXOneCh = new int[1];
        int[] dataYOneCh = new int[1];

        dataXOneCh[0] = 0;
        dataYOneCh[0] = 0;

        /*CirclePointMarker marker = new CirclePointMarker();
        marker.Fill = new SolidColorBrush(_lineprofileColor[0]);
        marker.Pen = new Pen(marker.Fill, 0);

        marker.Size = 2;
        int lineWidth = 1;*/




        for (int i = 0; i < 4; i++)
        {
            _dataX.Add(dataXOneCh);    // data x-y mapping init
            _dataY.Add(dataYOneCh);

            EnumerableDataSource<int> xOneCh = new EnumerableDataSource<int>(dataXOneCh);
            EnumerableDataSource<int> yOneCh = new EnumerableDataSource<int>(dataYOneCh);

            xOneCh.SetXMapping(xVal => xVal);
            yOneCh.SetXMapping(yVal => yVal);

            CompositeDataSource dsOneCh = new CompositeDataSource(xOneCh, yOneCh);

           // LineProfileColorSetup();

            lg = plotter.AddLineGraph(dsOneCh,                    
                (new Pen(Brushes.Green, 2)),
                 pm,
                (new PenDescription("Data")));

           // lg = plotter.AddLineGraph(dsOneCh,
           //    Colors.Transparent,
           //    2,
           //    "Data");

          // pm.FilteringEnabled = false;

        }

        plotter.FitToView();
    }
    else
    {
        return;
    }
}

データ更新:

 for (int i = 0; i < 1; i++)
                {
                    if (_dataX[i].Length == _dataY[i].Length)
                    {
                        EnumerableDataSource<int> xOneCh = new EnumerableDataSource<int>(_dataX[i]);
                        xOneCh.SetXMapping(xVal => xVal);
                        EnumerableDataSource<int> yOneCh = new EnumerableDataSource<int>(_dataY[i]);
                        yOneCh.SetYMapping(yVal => yVal);
                        CompositeDataSource ds = new CompositeDataSource(xOneCh, yOneCh);

                        Action UpdateData = delegate()
                        {
                           // ((LineGraph)plotter.Children.ElementAt(startIndex + i)).DataSource = ds;
                           // ((LineGraph)plotter.Children.ElementAt(startIndex + i)).LinePen = new Pen(new SolidColorBrush(Colors.Green), 1);
                           // ((PointsGraphBase)plotter.Children.ElementAt(startIndex + i)).DataSource = ds;
                            ((PointsGraphBase)plotter.Children.ElementAt(startIndex + i + 1)).DataSource = ds;

                            //  }
                           // (plotter.Children.ElementAt(startIndex + i)).DataSource = ds; 

                        };

                        this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, UpdateData);
                    }
                }

私が抱えている問題は、信号が非常に太い場合です。たとえば、新しい信号がミリ秒ごとに生成されると、グラフは1秒ごとに新しいマーカーしか生成しないようですが、これはわかりません。

基本的な考え方は、plotter.AddLineGraph を生成してから、DataSource のみを更新することです。しかし、うまくいかないようです。だから私は間違った方向に進んでいるのかもしれないと思いました。

私は C# や WPF の専門家ではありません。LineAndMarker が期待どおりに機能しないとき、私は疑うようになりました。したがって、WPF と C# を使用して、人々がリアルタイム信号を表示する一般的な方法 (急速に変化し、サンプル間の時間間隔がミリ秒になる可能性があります) はどうなるのだろうかと思っています。

4

1 に答える 1

0

私は自分が間違ったことを見つけました。問題が発生する部分は次のとおりです。

_pxlValAllChan[0, signalIndex] = pxlValue;
                                                DateTime currentTime = DateTime.Now; //has to come from real file: Tiff
                                                TimeSpan timeSpan = currentTime - _startTime;

                                                _timeStampAllChan[0, signalIndex] = Convert.ToInt16(timeSpan.TotalSeconds);


                                                _pxlValOneChan = new int[_signalLength]; // no need to new it every time
                                                _timeStampOneChan = new int[_signalLength];
                                                for (int i = 0; i <= signalIndex; i++)
                                                {
                                                    _pxlValOneChan[i] = _pxlValAllChan[0, i];
                                                    //_timeStampOneChan[i] = _timeStampAllChan[0, i];
                                                    _timeStampOneChan[i] = i;
                                                }

                                                _signalDisplay.SetData(_timeStampOneChan, _pxlValOneChan, 0, true);

私のxデータは時間に基づいていました。私は基本的にプログラムの開始を開始点と見なし、開始時間を現在の時間から差し引くことによって時間の経過を追跡します。次に、経過時間がx軸データとして保存されます(コメントアウトされた行を参照)。そして、これは実際に問題を引き起こします。x軸データをインデックスとして単純に変更すると、問題はなくなります。グラフの更新はかなり高速です。x軸データとして時間の経過を使用するようにロジックを変更する方法がわかりませんが、それがグラフの更新が遅い原因です。

于 2013-02-15T16:24:21.030 に答える