예제 #1
0
        /// <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();
            }
        }
예제 #2
0
 /// <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();
         }
     }
 }
예제 #3
0
 public void SetZBoundsFromTemplate(IPhysicalBoundaries val)
 {
     _plotData.SetVBoundsFromTemplate(val);
 }
예제 #4
0
		/// <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();
				}
			}
		}
예제 #5
0
		/// <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();
			}
		}
예제 #6
0
        /// <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);
            }
        }