private void BuildImage(Graphics gfrx, IPlotArea gl, XYZMeshedColumnPlotData myPlotAssociation, IROMatrix <double> matrix, IReadOnlyList <double> logicalRowHeaderValues, IReadOnlyList <double> logicalColumnHeaderValues) { // ---------------- prepare the color scaling ------------------------------------- // --------------- end preparation of color scaling ------------------------------ // test if the coordinate system is affine and the scale is linear if (!gl.CoordinateSystem.IsAffine) { BuildImageV3(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); } else // Coordinate System is affine { // now test lx and ly (only the valid indices for equidistantness bool isEquististantX = IsEquidistant(logicalRowHeaderValues, 0.2); bool isEquististantY = IsEquidistant(logicalColumnHeaderValues, 0.2); bool areLinearScales = (gl.XAxis is LinearScale) && (gl.YAxis is LinearScale); if (areLinearScales && isEquististantX && isEquististantY) { BuildImageV1(matrix); // affine, linear scales, and equidistant points } else if (areLinearScales) { BuildImageV3(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); // affine and linear, but nonequidistant scale } else { BuildImageV3(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); // affine, but nonlinear scales } } }
protected override System.Collections.Generic.IEnumerable <Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName() { if (null != _plotData) { yield return(new Main.DocumentNodeAndName(_plotData, () => _plotData = null, "Data")); } if (null != _plotStyle) { yield return(new Main.DocumentNodeAndName(_plotStyle, () => _plotStyle = null, "Style")); } }
/// <summary> /// This routine ensures that the plot item updates all its cached data and send the appropriate /// events if something has changed. Called before the layer paint routine paints the axes because /// it must be ensured that the axes are scaled correctly before the plots are painted. /// </summary> /// <param name="layer">The plot layer.</param> /// <param name="plotData">The plot data which are here used to determine the bounds of the independent data column.</param> public void PrepareScales(IPlotArea layer, XYZMeshedColumnPlotData plotData) { NumericalBoundaries pb = _scale.DataBounds; plotData.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set using (var suspendToken = pb.SuspendGetToken()) { pb.Reset(); plotData.MergeVBoundsInto(pb); suspendToken.Resume(); } }
/// <summary> /// This routine ensures that the plot item updates all its cached data and send the appropriate /// events if something has changed. Called before the layer paint routine paints the axes because /// it must be ensured that the axes are scaled correctly before the plots are painted. /// </summary> /// <param name="layer">The plot layer.</param> /// <param name="plotData">The plot data.</param> public void PrepareScales(IPlotArea layer, XYZMeshedColumnPlotData plotData) { if (_colorScale != null) { // in case we use our own scale for coloring, we need to calculate the data bounds NumericalBoundaries pb = _colorScale.DataBounds; plotData.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set using (var suspendToken = pb.SuspendGetToken()) { pb.Reset(); plotData.MergeVBoundsInto(pb); suspendToken.Resume(); } } }
public object Deserialize(object o, Altaxo.Serialization.Xml.IXmlDeserializationInfo info, object parent) { XYZMeshedColumnPlotData pa = (XYZMeshedColumnPlotData)info.GetValue("Data", o); DensityImagePlotStyle ps = (DensityImagePlotStyle)info.GetValue("Style", o); if (o == null) { return(new DensityImagePlotItem(pa, ps)); } else { DensityImagePlotItem s = (DensityImagePlotItem)o; s.Data = pa; s.Style = ps; return(s); } }
/// <summary> /// Plots a density image of the selected columns. /// </summary> /// <param name="dg"></param> /// <param name="bLine"></param> /// <param name="bScatter"></param> public static void PlotDensityImage(GUI.WorksheetController dg, bool bLine, bool bScatter) { DensityImagePlotStyle plotStyle = new DensityImagePlotStyle(); // if nothing is selected, assume that the whole table should be plotted int len = dg.SelectedDataColumns.Count; XYZMeshedColumnPlotData assoc = new XYZMeshedColumnPlotData(dg.Doc.DataColumns, len == 0 ? null : dg.SelectedDataColumns); // now create a new Graph with this plot associations Altaxo.Graph.GUI.IGraphController gc = Current.ProjectService.CreateNewGraph(); IGPlotItem pi = new DensityImagePlotItem(assoc, plotStyle); gc.Doc.Layers[0].PlotItems.Add(pi); }
/// <summary> /// Plots a density image of the selected columns. /// </summary> /// <param name="dg"></param> public static void AddSurfacePlot(Altaxo.Gui.Worksheet.Viewing.IWorksheetController dg, GraphDocument graph) { var layer = graph.RootLayer.Layers.OfType <XYZPlotLayer>().First(); var context = graph.GetPropertyContext(); var plotStyle = new DataMeshPlotStyle(); var assoc = new XYZMeshedColumnPlotData(dg.DataTable, dg.SelectedDataRows, dg.SelectedDataColumns, dg.SelectedPropertyColumns); if (assoc.DataTableMatrix.RowHeaderColumn == null) { assoc.DataTableMatrix.RowHeaderColumn = new IndexerColumn(); } if (assoc.DataTableMatrix.ColumnHeaderColumn == null) { assoc.DataTableMatrix.ColumnHeaderColumn = new IndexerColumn(); } var pi = new DataMeshPlotItem(assoc, plotStyle); layer.PlotItems.Add(pi); }
/// <summary> /// Plots a density image of the selected columns. /// </summary> /// <param name="dg"></param> /// <param name="bLine"></param> /// <param name="bScatter"></param> public static void PlotDensityImage(IWorksheetController dg, bool bLine, bool bScatter) { var graph = Altaxo.Graph.Gdi.GraphTemplates.TemplateWithXYPlotLayerWithG2DCartesicCoordinateSystem.CreateGraph(dg.DataTable.GetPropertyContext(), null, dg.DataTable.Name, true); var xylayer = graph.RootLayer.Layers.OfType <XYPlotLayer>().First(); var context = graph.GetPropertyContext(); var plotStyle = new DensityImagePlotStyle(); var assoc = new XYZMeshedColumnPlotData(dg.DataTable, dg.SelectedDataRows, dg.SelectedDataColumns, dg.SelectedPropertyColumns); if (assoc.DataTableMatrix.RowHeaderColumn == null) { assoc.DataTableMatrix.RowHeaderColumn = new IndexerColumn(); } if (assoc.DataTableMatrix.ColumnHeaderColumn == null) { assoc.DataTableMatrix.ColumnHeaderColumn = new IndexerColumn(); } IGPlotItem pi = new DensityImagePlotItem(assoc, plotStyle); xylayer.PlotItems.Add(pi); Current.ProjectService.CreateNewGraph(graph); }
/// <summary> /// This routine ensures that the plot item updates all its cached data and send the appropriate /// events if something has changed. Called before the layer paint routine paints the axes because /// it must be ensured that the axes are scaled correctly before the plots are painted. /// </summary> /// <param name="layer">The plot layer.</param> /// <param name="plotData">The plot data.</param> public void PrepareScales(IPlotArea layer, XYZMeshedColumnPlotData plotData) { if (_colorScale != null) { // in case we use our own scale for coloring, we need to calculate the data bounds NumericalBoundaries pb = _colorScale.DataBounds; plotData.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set using (var suspendToken = pb.SuspendGetToken()) { pb.Reset(); plotData.MergeVBoundsInto(pb); suspendToken.Resume(); } } }
public DensityImagePlotItem(XYZMeshedColumnPlotData pa, DensityImagePlotStyle ps) { this.Data = pa; this.Style = ps; }
protected override System.Collections.Generic.IEnumerable<Main.DocumentNodeAndName> GetDocumentNodeChildrenWithName() { if (null != _plotData) yield return new Main.DocumentNodeAndName(_plotData, () => _plotData = null, "Data"); if (null != _plotStyle) yield return new Main.DocumentNodeAndName(_plotStyle, () => _plotStyle = null, "Style"); }
public DensityImagePlotItem(XYZMeshedColumnPlotData pa, DensityImagePlotStyle ps) { this.Data = pa; this.Style = ps; }
/// <summary> /// This routine ensures that the plot item updates all its cached data and send the appropriate /// events if something has changed. Called before the layer paint routine paints the axes because /// it must be ensured that the axes are scaled correctly before the plots are painted. /// </summary> /// <param name="layer">The plot layer.</param> /// <param name="plotData">The plot data which are here used to determine the bounds of the independent data column.</param> public void PrepareScales(IPlotArea layer, XYZMeshedColumnPlotData plotData) { NumericalBoundaries pb = _scale.DataBounds; plotData.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set using (var suspendToken = pb.SuspendGetToken()) { pb.Reset(); plotData.MergeVBoundsInto(pb); suspendToken.Resume(); } }
public DataMeshPlotItem(XYZMeshedColumnPlotData pa, DataMeshPlotStyle ps) { Data = pa; Style = ps; }
public DataMeshPlotItem(XYZMeshedColumnPlotData pa, DataMeshPlotStyle ps) { this.Data = pa; this.Style = ps; }
private void BuildImage(IGraphicsContext3D gfrx, IPlotArea gl, XYZMeshedColumnPlotData myPlotAssociation, IROMatrix <double> matrix, IReadOnlyList <double> logicalRowHeaderValues, IReadOnlyList <double> logicalColumnHeaderValues) { BuildImageWithUColor(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); // affine, linear scales, and equidistant points }
private void BuildImage(Graphics gfrx, IPlotArea gl, XYZMeshedColumnPlotData myPlotAssociation, IROMatrix matrix, IROVector logicalRowHeaderValues, IROVector logicalColumnHeaderValues) { // ---------------- prepare the color scaling ------------------------------------- // --------------- end preparation of color scaling ------------------------------ // test if the coordinate system is affine and the scale is linear if (!gl.CoordinateSystem.IsAffine) { BuildImageV3(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); } else // Coordinate System is affine { // now test lx and ly (only the valid indices for equidistantness bool isEquististantX = IsEquidistant(logicalRowHeaderValues, 0.2); bool isEquististantY = IsEquidistant(logicalColumnHeaderValues, 0.2); bool areLinearScales = (gl.XAxis is LinearScale) && (gl.YAxis is LinearScale); if (areLinearScales && isEquististantX && isEquististantY) { BuildImageV1(matrix); // affine, linear scales, and equidistant points } else if (areLinearScales) { BuildImageV3(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); // affine and linear, but nonequidistant scale } else { BuildImageV3(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); // affine, but nonlinear scales } } }
private void BuildImage(IGraphicsContext3D gfrx, IPlotArea gl, XYZMeshedColumnPlotData myPlotAssociation, IROMatrix matrix, IROVector logicalRowHeaderValues, IROVector logicalColumnHeaderValues) { BuildImageWithUColor(gfrx, gl, logicalRowHeaderValues, logicalColumnHeaderValues, matrix); // affine, linear scales, and equidistant points }
/// <summary> /// Paint the density image in the layer. /// </summary> /// <param name="gfrx">The graphics context painting in.</param> /// <param name="gl">The layer painting in.</param> /// <param name="plotObject">The data to plot.</param> public void Paint(Graphics gfrx, IPlotArea gl, object plotObject) // plots the curve with the choosen style { if (!(plotObject is XYZMeshedColumnPlotData)) { return; // we cannot plot any other than a TwoDimMeshDataAssociation now } XYZMeshedColumnPlotData myPlotAssociation = (XYZMeshedColumnPlotData)plotObject; Altaxo.Data.INumericColumn xColumn = myPlotAssociation.XColumn as Altaxo.Data.INumericColumn; Altaxo.Data.INumericColumn yColumn = myPlotAssociation.YColumn as Altaxo.Data.INumericColumn; if (null == xColumn || null == yColumn) { return; // this plotitem is only for x and y double columns } //double layerWidth = gl.Size.Width; //double layerHeight = gl.Size.Height; int cols = myPlotAssociation.ColumnCount; int rows = myPlotAssociation.RowCount; if (cols <= 0 || rows <= 0) { return; // we cannot show a picture if one length is zero } // there is a need for rebuilding the bitmap only if the data are invalid for some reason if (!m_bCachedDataValid) { System.Diagnostics.Trace.WriteLine("DensityImagePlotStyle.Paint, calculate image data..."); // look if the image has the right dimensions if (null == m_Image || m_Image.Width != cols || m_Image.Height != rows) { if (null != m_Image) { m_Image.Dispose(); } // please notice: the horizontal direction of the image is related to the row index!!! (this will turn the image in relation to the table) // and the vertical direction of the image is related to the column index m_Image = new System.Drawing.Bitmap(rows, cols, System.Drawing.Imaging.PixelFormat.Format32bppArgb); } // now we can fill the image with our data NumericalBoundaries pb = m_ScalingStyle == ScalingStyle.Logarithmic ? (NumericalBoundaries) new PositiveFiniteNumericalBoundaries() : (NumericalBoundaries) new FiniteNumericalBoundaries(); myPlotAssociation.SetVBoundsFromTemplate(pb); // ensure that the right v-boundary type is set myPlotAssociation.MergeVBoundsInto(pb); double vmin = double.IsNaN(this.m_RangeFrom) ? pb.LowerBound : Math.Max(pb.LowerBound, this.m_RangeFrom); double vmax = double.IsNaN(this.m_RangeTo) ? pb.UpperBound : Math.Min(pb.UpperBound, this.m_RangeTo); double lowerBound = vmin; double upperBound = vmax; if (this.m_ScalingStyle == ScalingStyle.Logarithmic) { // Ensure that min and max >0 vmin = lowerBound = Math.Max(lowerBound, double.Epsilon); vmax = upperBound = Math.Max(lowerBound, upperBound); // lowerBound is ok, to ensure that upperBound>=lowerBound vmin = Math.Log(vmin); vmax = vmax > 0 ? Math.Log(vmax) : vmin; } // double vmid = (vmin+vmax)*0.5; double vscal = vmax <= vmin ? 1 : 255.0 / (vmax - vmin); int r, g, b; for (int i = 0; i < cols; i++) { Altaxo.Data.INumericColumn col = myPlotAssociation.DataColumns[i] as Altaxo.Data.INumericColumn; if (null == col) { continue; } for (int j = 0; j < rows; j++) { double val = col[j]; if (double.IsNaN(val)) { m_Image.SetPixel(j, cols - i - 1, m_ColorInvalid); // invalid pixels are transparent } else if (val < lowerBound) { m_Image.SetPixel(j, cols - i - 1, m_ColorBelow); // below the lower bound } else if (val > upperBound) { m_Image.SetPixel(j, cols - i - 1, m_ColorAbove); // above the upper bound } else // a valid value { double relval; // calculate a relative value between 0 and 255 from the borders and the scaling style if (this.m_ScalingStyle == ScalingStyle.Logarithmic) { relval = (Math.Log(val) - vmin) * vscal; } else // ScalingStyle is linear { relval = (val - vmin) * vscal; } r = ((int)(Math.Abs(relval))) % 256; g = ((int)(Math.Abs(relval + relval))) % 256; b = ((int)(Math.Abs(255 - relval))) % 256; m_Image.SetPixel(j, cols - i - 1, System.Drawing.Color.FromArgb(r, g, b)); } } // for all pixel of a column } // for all columns m_bCachedDataValid = true; // now the bitmap is valid } double x_rel_left = gl.XAxis.PhysicalVariantToNormal(xColumn[0]); double x_rel_right = gl.XAxis.PhysicalVariantToNormal(xColumn[rows - 1]); double y_rel_bottom = gl.YAxis.PhysicalVariantToNormal(yColumn[0]); double y_rel_top = gl.YAxis.PhysicalVariantToNormal(yColumn[cols - 1]); double xleft, xright, ytop, ybottom; if (gl.CoordinateSystem.LogicalToLayerCoordinates(new Logical3D(x_rel_left, y_rel_top), out xleft, out ytop) && gl.CoordinateSystem.LogicalToLayerCoordinates(new Logical3D(x_rel_right, y_rel_bottom), out xright, out ybottom)) { GraphicsState savedGraphicsState = gfrx.Save(); if (this.m_ClipToLayer) { gfrx.Clip = gl.CoordinateSystem.GetRegion(); } gfrx.DrawImage(m_Image, (float)xleft, (float)ytop, (float)(xright - xleft), (float)(ybottom - ytop)); gfrx.Restore(savedGraphicsState); } }