Пример #1
0
        /// <summary>
        /// This will create a point list out of the data, which can be used to plot the data. In order to create this list,
        /// the function must have knowledge how to calculate the points out of the data. This will be done
        /// by a function provided by the calling function.
        /// </summary>
        /// <param name="layer">The plot layer.</param>
        /// <returns>An array of plot points in layer coordinates.</returns>
        public Processed2DPlotData GetRangesAndPoints(
            Gdi.IPlotArea layer)
        {
            const int    functionPoints   = 1000;
            const double MaxRelativeValue = 1E6;


            // allocate an array PointF to hold the line points
            PointF[]            ptArray = new PointF[functionPoints];
            Processed2DPlotData result  = new Processed2DPlotData();
            MyPlotData          pdata   = new MyPlotData();

            result.PlotPointsInAbsoluteLayerCoordinates = ptArray;
            double[] xPhysArray = new double[functionPoints];
            double[] yPhysArray = new double[functionPoints];
            pdata._xPhysical         = xPhysArray;
            pdata._yPhysical         = yPhysArray;
            result.XPhysicalAccessor = new IndexedPhysicalValueAccessor(pdata.GetXPhysical);
            result.YPhysicalAccessor = new IndexedPhysicalValueAccessor(pdata.GetYPhysical);

            // double xorg = layer.XAxis.Org;
            // double xend = layer.XAxis.End;
            // Fill the array with values
            // only the points where x and y are not NaNs are plotted!

            int i, j;

            bool          bInPlotSpace = true;
            int           rangeStart   = 0;
            PlotRangeList rangeList    = new PlotRangeList();

            result.RangeList = rangeList;
            Gdi.G2DCoordinateSystem coordsys = layer.CoordinateSystem;

            NumericalScale xaxis = layer.XAxis as NumericalScale;
            NumericalScale yaxis = layer.YAxis as NumericalScale;

            if (xaxis == null || yaxis == null)
            {
                return(null);
            }

            for (i = 0, j = 0; i < functionPoints; i++)
            {
                double x_rel = ((double)i) / (functionPoints - 1);
                double x     = xaxis.NormalToPhysical(x_rel);
                double y     = Evaluate(x);

                if (Double.IsNaN(x) || Double.IsNaN(y))
                {
                    if (!bInPlotSpace)
                    {
                        bInPlotSpace = true;
                        rangeList.Add(new PlotRange(rangeStart, j));
                    }
                    continue;
                }


                // double x_rel = layer.XAxis.PhysicalToNormal(x);
                double y_rel = yaxis.PhysicalToNormal(y);

                // chop relative values to an range of about -+ 10^6
                if (y_rel > MaxRelativeValue)
                {
                    y_rel = MaxRelativeValue;
                }
                if (y_rel < -MaxRelativeValue)
                {
                    y_rel = -MaxRelativeValue;
                }

                // after the conversion to relative coordinates it is possible
                // that with the choosen axis the point is undefined
                // (for instance negative values on a logarithmic axis)
                // in this case the returned value is NaN
                double xcoord, ycoord;
                if (coordsys.LogicalToLayerCoordinates(new Logical3D(x_rel, y_rel), out xcoord, out ycoord))
                {
                    if (bInPlotSpace)
                    {
                        bInPlotSpace = false;
                        rangeStart   = j;
                    }
                    xPhysArray[j] = x;
                    yPhysArray[j] = y;
                    ptArray[j].X  = (float)xcoord;
                    ptArray[j].Y  = (float)ycoord;
                    j++;
                }
                else
                {
                    if (!bInPlotSpace)
                    {
                        bInPlotSpace = true;
                        rangeList.Add(new PlotRange(rangeStart, j));
                    }
                }
            } // end for
            if (!bInPlotSpace)
            {
                bInPlotSpace = true;
                rangeList.Add(new PlotRange(rangeStart, j)); // add the last range
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// This will create a point list out of the data, which can be used to plot the data. In order to create this list,
        /// the function must have knowledge how to calculate the points out of the data. This will be done
        /// by a function provided by the calling function.
        /// </summary>
        /// <param name="layer">The plot layer.</param>
        /// <returns>An array of plot points in layer coordinates.</returns>
        public Processed2DPlotData GetRangesAndPoints(
            Gdi.IPlotArea layer)
        {
            const int    functionPoints   = 1000;
            const double MaxRelativeValue = 1E6;

            // allocate an array PointF to hold the line points
            var ptArray = new PointF[functionPoints];
            var result  = new Processed2DPlotData();
            var pdata   = new MyPlotData();

            result.PlotPointsInAbsoluteLayerCoordinates = ptArray;
            double[] xPhysArray = new double[functionPoints];
            double[] yPhysArray = new double[functionPoints];
            pdata._xPhysical         = xPhysArray;
            pdata._yPhysical         = yPhysArray;
            result.XPhysicalAccessor = new IndexedPhysicalValueAccessor(pdata.GetXPhysical);
            result.YPhysicalAccessor = new IndexedPhysicalValueAccessor(pdata.GetYPhysical);

            // double xorg = layer.XAxis.Org;
            // double xend = layer.XAxis.End;
            // Fill the array with values
            // only the points where x and y are not NaNs are plotted!

            int i, j;

            bool bInPlotSpace = true;
            int  rangeStart   = 0;
            var  rangeList    = new PlotRangeList();

            result.RangeList = rangeList;
            Gdi.G2DCoordinateSystem coordsys = layer.CoordinateSystem;

            var xaxis = layer.XAxis;
            var yaxis = layer.YAxis;

            if (xaxis == null || yaxis == null)
            {
                return(null);
            }

            for (i = 0, j = 0; i < functionPoints; i++)
            {
                double x_rel     = ((double)i) / (functionPoints - 1);
                var    x_variant = xaxis.NormalToPhysicalVariant(x_rel);
                double x         = x_variant.ToDouble();
                double y         = Evaluate(x);

                if (double.IsNaN(x) || double.IsNaN(y))
                {
                    if (!bInPlotSpace)
                    {
                        bInPlotSpace = true;
                        rangeList.Add(new PlotRange(rangeStart, j));
                    }
                    continue;
                }

                // double x_rel = layer.XAxis.PhysicalToNormal(x);
                double y_rel = yaxis.PhysicalVariantToNormal(y);

                // chop relative values to an range of about -+ 10^6
                if (y_rel > MaxRelativeValue)
                {
                    y_rel = MaxRelativeValue;
                }
                if (y_rel < -MaxRelativeValue)
                {
                    y_rel = -MaxRelativeValue;
                }
                if (coordsys.LogicalToLayerCoordinates(new Logical3D(x_rel, y_rel), out var xcoord, out var ycoord))
                {
                    if (bInPlotSpace)
                    {
                        bInPlotSpace = false;
                        rangeStart   = j;
                    }
                    xPhysArray[j] = x;
                    yPhysArray[j] = y;
                    ptArray[j].X  = (float)xcoord;
                    ptArray[j].Y  = (float)ycoord;
                    j++;
                }
Пример #3
0
        /// <summary>
        /// This will create a point list out of the data, which can be used to plot the data. In order to create this list,
        /// the function must have knowledge how to calculate the points out of the data. This will be done
        /// by a function provided by the calling function.
        /// </summary>
        /// <param name="layer">The plot layer.</param>
        /// <returns>An array of plot points in layer coordinates.</returns>
        public Processed2DPlotData GetRangesAndPoints(
            Gdi.IPlotArea layer)
        {
            const double MaxRelativeValue = 1E2;

            Altaxo.Data.IReadableColumn xColumn = this.XColumn;
            Altaxo.Data.IReadableColumn yColumn = this.YColumn;

            if (null == xColumn || null == yColumn)
            {
                return(null); // this plotitem is only for x and y double columns
            }
            if (this.PlottablePoints <= 0)
            {
                return(null);
            }


            Processed2DPlotData result     = new Processed2DPlotData();
            MyPlotData          myPlotData = new MyPlotData(xColumn, yColumn);

            result.XPhysicalAccessor = new IndexedPhysicalValueAccessor(myPlotData.GetXPhysical);
            result.YPhysicalAccessor = new IndexedPhysicalValueAccessor(myPlotData.GetYPhysical);
            PlotRangeList rangeList = null;

            PointF[] ptArray = null;



            // allocate an array PointF to hold the line points
            ptArray = new PointF[this.PlottablePoints];
            result.PlotPointsInAbsoluteLayerCoordinates = ptArray;

            // Fill the array with values
            // only the points where x and y are not NaNs are plotted!

            int i, j;

            bool bInPlotSpace = true;
            int  rangeStart   = 0;
            int  rangeOffset  = 0;

            rangeList        = new PlotRangeList();
            result.RangeList = rangeList;


            Scale xAxis = layer.XAxis;
            Scale yAxis = layer.YAxis;

            Gdi.G2DCoordinateSystem coordsys = layer.CoordinateSystem;


            int len = this.PlotRangeEnd;

            for (i = this.PlotRangeStart, j = 0; i < len; i++)
            {
                if (xColumn.IsElementEmpty(i) || yColumn.IsElementEmpty(i))
                {
                    if (!bInPlotSpace)
                    {
                        bInPlotSpace = true;
                        rangeList.Add(new PlotRange(rangeStart, j, rangeOffset));
                    }
                    continue;
                }


                double x_rel, y_rel;
                double xcoord, ycoord;



                x_rel = xAxis.PhysicalVariantToNormal(xColumn[i]);
                y_rel = yAxis.PhysicalVariantToNormal(yColumn[i]);

                // chop relative values to an range of about -+ 10^6
                if (x_rel > MaxRelativeValue)
                {
                    x_rel = MaxRelativeValue;
                }
                if (x_rel < -MaxRelativeValue)
                {
                    x_rel = -MaxRelativeValue;
                }
                if (y_rel > MaxRelativeValue)
                {
                    y_rel = MaxRelativeValue;
                }
                if (y_rel < -MaxRelativeValue)
                {
                    y_rel = -MaxRelativeValue;
                }


                // after the conversion to relative coordinates it is possible
                // that with the choosen axis the point is undefined
                // (for instance negative values on a logarithmic axis)
                // in this case the returned value is NaN
                if (coordsys.LogicalToLayerCoordinates(new Logical3D(x_rel, y_rel), out xcoord, out ycoord))
                {
                    if (bInPlotSpace)
                    {
                        bInPlotSpace = false;
                        rangeStart   = j;
                        rangeOffset  = i - j;
                    }
                    ptArray[j].X = (float)xcoord;
                    ptArray[j].Y = (float)ycoord;

                    j++;
                }
                else
                {
                    if (!bInPlotSpace)
                    {
                        bInPlotSpace = true;
                        rangeList.Add(new PlotRange(rangeStart, j, rangeOffset));
                    }
                }
            } // end for
            if (!bInPlotSpace)
            {
                bInPlotSpace = true;
                rangeList.Add(new PlotRange(rangeStart, j, rangeOffset)); // add the last range
            }
            return(result);
        }