/// <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(); }
protected virtual void SetXArray(vtkDoubleArray array, VtkPlotPointsModel plot) { VtkChartXyModel model = this.Model as VtkChartXyModel; if (model == null) { return; } vtkTable table = plot.Table; if (table.GetNumberOfColumns() <= 1) { table.Initialize(); table.AddColumn(array); } else { vtkDoubleArray arrY = table.GetColumn(1) as vtkDoubleArray; if (arrY == null) { this.Log.Error("SetXArray(): Could not cast table data to vtkDoubleArray"); return; } table.Initialize(); table.AddColumn(array); table.AddColumn(arrY); vtkPlotPoints vtkPlot = plot.PlotItem as vtkPlotPoints; if (vtkPlot == null) { this.Log.Error("SetXArray(): Could not cast plot item to vtkPlotPoints"); return; } vtkPlot.SetInputData(table, 0, 1); } }
protected virtual void SetYArray(vtkDoubleArray array, VtkPlotPointsModel plot) { VtkChartXyModel model = this.Model as VtkChartXyModel; if (model == null) { return; } vtkTable table = plot.Table; if (table.GetNumberOfColumns() == 0) { this.Log.Error("SetYArray(): No XArray data"); return; } if (table.GetNumberOfColumns() == 1) { table.AddColumn(array); } else { table.RemoveColumn(1); table.AddColumn(array); } vtkPlotPoints vtkPlot = plot.PlotItem as vtkPlotPoints; if (vtkPlot == null) { this.Log.Error("SetYArray(): Could not cast plot item to vtkPlotPoints"); return; } vtkPlot.SetInputData(table, 0, 1); }
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(); }