Пример #1
0
        public static void SetHChart()
        {
            if (HArray == null || HZArray == null)
            {
                MessageBox.Show("array is null");
                return;
            }

            HTable = vtkTable.New();
            HTable.AddColumn(HArray);
            HTable.AddColumn(HZArray);

            HChart = vtkChartXY.New();
            var line = HChart.AddPlot(0);

            line.SetInput(HTable, 0, 1);

            HView = vtkContextView.New();
            HView.GetScene().AddItem(HChart);

            RenWinControlHorizontal.RenderWindow.GetRenderers().GetFirstRenderer().RemoveAllViewProps();

            HView.SetRenderWindow(RenWinControlHorizontal.RenderWindow);
            RenWinControlHorizontal.RenderWindow.Render();
        }
Пример #2
0
        public static void SetVChart()
        {
            if (VZArray == null || VArray == null)
            {
                MessageBox.Show("array is null");
                return;
            }

            VTable = vtkTable.New();
            VTable.AddColumn(VZArray);
            VTable.AddColumn(VArray);

            VChart = vtkChartXY.New();
            var line = VChart.AddPlot(0);

            line.SetInput(VTable, 0, 1);

            VView = vtkContextView.New();
            VView.GetScene().AddItem(VChart);

            RenWinControlVertical.RenderWindow.GetRenderers().GetFirstRenderer().RemoveAllViewProps();

            VView.SetRenderWindow(RenWinControlVertical.RenderWindow);
            RenWinControlVertical.RenderWindow.Render();
        }
Пример #3
0
        public virtual void ClearPlots()
        {
            vtkChartXY chart = this._chartItem as vtkChartXY;

            if (chart == null)
            {
                return;
            }

            chart.ClearPlots();

            VtkChartXyModel model = this.Model as VtkChartXyModel;

            if (model == null)
            {
                return;
            }

            foreach (IVtkPlotItemModel plotItemModel in model.Plots)
            {
                plotItemModel.PropertyChanged -= OnPlotItemChanged;
            }

            model.Plots.Clear();

            numPlots = 0;

            this.Render();
        }
Пример #4
0
        protected virtual void Create()
        {
            _chartItem = new vtkChartXY();

            _textBox = new FloatingTextBox();

            vtkChartXY chart = (vtkChartXY)_chartItem;

            _lAxis = chart.GetAxis((int)vtkAxis.Location.LEFT);
            vtkTextProperty titleProps = _lAxis.GetTitleProperties();

            titleProps.SetOpacity(0.0);

            _bAxis     = chart.GetAxis((int)vtkAxis.Location.BOTTOM);
            titleProps = _bAxis.GetTitleProperties();
            titleProps.SetOpacity(0.0);

            _rAxis     = chart.GetAxis((int)vtkAxis.Location.RIGHT);
            titleProps = _rAxis.GetTitleProperties();
            titleProps.SetOpacity(0.0);

            _tAxis     = chart.GetAxis((int)vtkAxis.Location.TOP);
            titleProps = _tAxis.GetTitleProperties();
            titleProps.SetOpacity(0.0);
        }
Пример #5
0
        protected override void Initialize()
        {
            base.Initialize();

            IVtkChartXyModel model = this.Model as IVtkChartXyModel;
            vtkChartXY       chart = this._chartItem as vtkChartXY;

            if (model != null && chart != null)
            {
            }
        }
Пример #6
0
        /// <summary>
        /// Sets plot corner.
        /// The bottom left corner, 0, uses the left and bottom axes.
        /// The bottom right corner, 1, uses the right and bottom axes.
        /// The top right corner, 2, uses the right and top axes.
        /// The top left corner, 3, uses the left and top axes.
        /// </summary>
        /// <param name="plotModel"> The plot model. </param>
        /// <param name="corner"> The corner, accepts 0 through 3. </param>
        public virtual void SetPlotCorner(VtkPlotPointsModel plotModel, int corner)
        {
            vtkPlotPoints plot  = plotModel.PlotItem as vtkPlotPoints;
            vtkChartXY    chart = this._chartItem as vtkChartXY;

            if (plot == null || chart == null)
            {
                return;
            }

            chart.SetPlotCorner(plot, corner);

            this.Render();
        }
Пример #7
0
        protected double[] ConvertPixelPositionToGraphValues(int x, int y)
        {
            vtkChartXY chart = this._chartItem as vtkChartXY;

            if (chart == null)
            {
                return(null);
            }

            int lowerLeftX = chart.GetPoint1()[0];
            int lowerLeftY = chart.GetPoint1()[1];

            int upperRightX = chart.GetPoint2()[0];
            int upperRightY = chart.GetPoint2()[1];

            if (x < lowerLeftX || x > upperRightX || y < lowerLeftY || y > upperRightY)
            {
                return(null);
            }

            int xPosPixels = x - lowerLeftX;
            int yPosPixels = y - lowerLeftY;

            int xTotPixels = upperRightX - lowerLeftX;
            int yTotPixels = upperRightY - lowerLeftY;

            double xBotTotValue   = _bAxis.GetMaximum() - _bAxis.GetMinimum();
            double yLeftTotValue  = _lAxis.GetMaximum() - _lAxis.GetMinimum();
            double xTopTotValue   = _tAxis.GetMaximum() - _tAxis.GetMinimum();
            double yRightTotValue = _rAxis.GetMaximum() - _rAxis.GetMinimum();

            double xBotPosValue   = xBotTotValue * xPosPixels / xTotPixels + _bAxis.GetMinimum();
            double yLeftPosValue  = yLeftTotValue * yPosPixels / yTotPixels + _lAxis.GetMinimum();
            double xTopPosValue   = xTopTotValue * xPosPixels / xTotPixels + _tAxis.GetMinimum();
            double yRightPosValue = yRightTotValue * yPosPixels / yTotPixels + _rAxis.GetMinimum();

            return(new[] { xBotPosValue, yLeftPosValue, xTopPosValue, yRightPosValue });
        }
Пример #8
0
        public static void LinePlotTest()
        {
            vtkTable table = vtkTable.New();

            vtkFloatArray arrX = vtkFloatArray.New();

            table.AddColumn(arrX);

            vtkFloatArray arrSine = vtkFloatArray.New();

            table.AddColumn(arrSine);

            int numPoints = 100;

            table.SetNumberOfRows(100);

            for (int i = 0; i < numPoints; i++)
            {
                arrSine.SetValue(i, (float)Math.Cos(i));
            }

            table.Update();

            vtkContextView view = vtkContextView.New();

            view.GetRenderer().SetBackground(0, 0, 0);


            vtkChartXY chart = vtkChartXY.New();

            view.GetScene().AddItem(chart);


            chart.AddPlot(0).SetInput(table);

            view.GetInteractor().Initialize();
            view.GetInteractor().Start();
        }
Пример #9
0
        protected virtual void PlotInternal(CodeContext context, ndarray array, IList <string> names = null, Type type = null)
        {
            VtkChartXyModel model = this.Model as VtkChartXyModel;

            if (model == null)
            {
                return;
            }

            int ndim = array.ndim;

            if (type == null || !type.IsSubclassOf(typeof(VtkPlotPointsModel)))
            {
                type = typeof(VtkPlotPointsModel);
            }

            ConstructorInfo cInfo = type.GetConstructor(new Type[] { });

            if (cInfo == null)
            {
                return;
            }

            switch (ndim)
            {
            case 1:
            {
                // Treat array as y-values
                VtkPlotPointsModel plot = cInfo.Invoke(new object[] {}) as VtkPlotPointsModel;
                if (plot == null)
                {
                    return;
                }

                int len = (int)array.Dims[0];

                ndarray linspace = Math.General.LinSpace(context, len, 0.0, 1.0);

                vtkDoubleArray arrX = NumpyVtk.NumpyToVtk(linspace) as vtkDoubleArray;
                vtkDoubleArray arrY = NumpyVtk.NumpyToVtk(array) as vtkDoubleArray;

                if (arrX == null || arrY == null)
                {
                    this.Log.Error("Plot(): Could not cast ndarrays to vtkDoubleArrays");
                    return;
                }

                numPlots++;
                arrX.SetName(DEFAULT_X_ARRAY + '_' + numPlots);

                if (names != null && !String.IsNullOrEmpty(names[0]))
                {
                    arrY.SetName(names[0]);
                }
                else
                {
                    numPlots++;
                    arrY.SetName(DEFAULT_Y_ARRAY + '_' + numPlots);
                }

                this.SetXArray(arrX, plot);
                this.SetYArray(arrY, plot);

                model.Plots.Add(plot);
            }
            break;

            case 2:
            {
                // Treat 1st array as x-values, rest as y-values
                // No need to check for dimensional conformity, ndarray won't allow asymmetric arrays to be created
                ndarray arrayX = array[0] as ndarray;
                if (arrayX == null)
                {
                    this.Log.Error("Plot(): Could not cast X-data to ndarray");
                    return;
                }

                vtkDoubleArray arrX = NumpyVtk.NumpyToVtk(arrayX) as vtkDoubleArray;
                if (arrX == null)
                {
                    this.Log.Error("Plot(): Could not cast X-ndarray to vtkDoubleArray");
                    return;
                }

                if (names != null && !String.IsNullOrEmpty(names[0]))
                {
                    arrX.SetName(names[0]);
                }
                else
                {
                    numPlots++;
                    arrX.SetName(DEFAULT_X_ARRAY + '_' + numPlots);
                }

                int numArrays = (int)array.Dims[0];

                for (int i = 1; i < numArrays; i++)
                {
                    VtkPlotPointsModel plot = cInfo.Invoke(new object[] { }) as VtkPlotPointsModel;
                    if (plot == null)
                    {
                        return;
                    }

                    ndarray arrayY = array[i] as ndarray;
                    if (arrayY == null)
                    {
                        this.Log.Error("Plot(): Could not cast Y-data to ndarray");
                        return;
                    }

                    vtkDoubleArray arrY = NumpyVtk.NumpyToVtk(arrayY) as vtkDoubleArray;
                    if (arrY == null)
                    {
                        this.Log.Error("Plot(): Could not cast Y-ndarray to vtkDoubleArray");
                        return;
                    }

                    if (names != null && names.Count > i && !String.IsNullOrEmpty(names[i]))
                    {
                        arrY.SetName(names[i]);
                    }
                    else
                    {
                        numPlots++;
                        arrY.SetName(DEFAULT_Y_ARRAY + '_' + numPlots);
                    }

                    this.SetXArray(arrX, plot);
                    this.SetYArray(arrY, plot);

                    model.Plots.Add(plot);
                }
            }
            break;

            default:
                this.Log.Error("Can only plot 1D and 2D arrays");
                break;
            }

            vtkChartXY chart = this._chartItem as vtkChartXY;

            if (chart == null)
            {
                return;
            }

            foreach (IVtkPlotItemModel plotItemModel in model.Plots)
            {
                plotItemModel.PropertyChanged += OnPlotItemChanged;
                vtkPlot plot = plotItemModel.PlotItem as vtkPlot;
                if (plot != null)
                {
                    chart.AddPlot(plot);
                }
            }

            this.RenderInternal();
        }