Example #1
0
        /// <summary>
        /// Clones the Plot2D object
        /// </summary>
        public override Plot Clone()
        {
            Plot2D p = new Plot2D(Model);

            p.CopyFrom(this);
            return(p);
        }
Example #2
0
        /// <summary>
        /// Recalculates the Painter.
        /// </summary>
        public override void Calc(Plot plot)
        {
            int           X, Y;
            Plot2D        plot2D = (Plot2D)plot;
            BitmapBuilder bmp    = cache;
            Rectangle     r      = plot2D.Bounds;

            if (Recalc)
            {
                unsafe {
                    lock (this) {
                        int * pixel;
                        Color c;
                        bmp.Lock();
                        pixel = bmp.Pixel(r.X, r.Y);
                        for (Y = r.Y; Y < r.Y + r.Height; Y++)
                        {
                            if (plot2D.DrawStop)
                            {
                                break;
                            }
                            for (X = r.X; X < r.X + r.Width; X++)
                            {
                                if (plot2D.DrawStop)
                                {
                                    break;
                                }
                                try {
                                    c = F.f(plot2D.WorldCoordinateX(X), plot2D.WorldCoordinateY(Y));
                                } catch (ThreadAbortException ex) {
                                    throw ex;
                                } catch (Exception e) {
                                    if (F.ThrowOnErrors)
                                    {
                                        throw e;
                                    }
                                    else
                                    {
                                        c = Color.Transparent;
                                    }
                                }
                                *pixel = c.ToArgb();
                                pixel++;
                            }
                            plot2D.Progress += r.Width;
                        }
                        bmp.Unlock();
                    }
                }
                Recalc = plot.DrawStop;
            }
        }
Example #3
0
 /// <summary>
 /// Copies from another Plot2D object
 /// </summary>
 public void CopyFrom(Plot2D p)
 {
     base.CopyFrom(p);
     fd    = p.fd; fld = p.fld;
     Model = p.Model;
 }
Example #4
0
        /// <summary>
        /// Recalculates the Painter
        /// </summary>
        public override void Calc(Plot plot)
        {
            int           X, Y;
            double        z, dzinv;
            Plot2D        plot2D = (Plot2D)plot;
            Rectangle     r      = plot2D.Bounds;
            BitmapBuilder bmp;

            //Color c;
            if (Recalc)
            {
                dzinv = 1 / (Model.z1 - Model.z0);
                unsafe {
                    bmp = cache;
                    bmp.Lock();
                    int *pixel = bmp.Pixel(r.X, r.Y);
                    for (Y = r.Y; Y < r.Y + r.Height; Y++)
                    {
                        if (plot2D.DrawStop)
                        {
                            break;
                        }
                        for (X = r.X; X < r.X + r.Width; X++)
                        {
                            if (plot2D.DrawStop)
                            {
                                break;
                            }
                            try {
                                z = (F.f(plot2D.WorldCoordinateX(X), plot2D.WorldCoordinateY(Y)) - Model.z0) * dzinv;
                            } catch (ThreadAbortException ex) {
                                throw ex;
                            } catch (Exception e) {
                                if (F.ThrowOnErrors)
                                {
                                    throw e;
                                }
                                else
                                {
                                    z = double.NaN;
                                }
                            }
                            if (double.IsInfinity(z) || double.IsNaN(z))
                            {
                                *pixel = Color.Transparent.ToArgb();
                            }
                            else
                            {
                                try {
                                    *pixel = F.Gradient.Color(z).ToArgb();
                                } catch (ThreadAbortException ex) {
                                    throw ex;
                                } catch {
                                    *pixel = Color.Transparent.ToArgb();
                                }
                            }
                            pixel++;
                        }
                        plot2D.Progress += r.Width;
                    }
                    bmp.Unlock();
                }
                Recalc = plot2D.DrawStop;
            }
        }
Example #5
0
        /// <summary>
        /// Recalculates the Painter.
        /// </summary>
        /// <param name="plot">The Plot to paint from</param>
        public override void Calc(Plot plot)
        {
            Plot2D plot2D = (Plot2D)plot;
            int    X, Xp;
            double x, y, x0, x1, xn;
            float  Y;

            PointF[]        points = new PointF[plot2D.Bounds.Width];
            List <PointF[]> plist  = cache;

            if (Recalc)
            {
                x0 = x1 = Model.x0;
                for (X = plot2D.Bounds.X, Xp = 0; X < plot2D.Bounds.X + plot2D.Bounds.Width; X++)
                {
                    if (plot2D.DrawStop)
                    {
                        break;
                    }
                    x = plot2D.WorldCoordinateX(X);
                    try {
                        y = F.f(x);
                    } catch (ThreadAbortException ex) {
                        throw ex;
                    } catch (Exception e) {
                        if (F.ThrowOnErrors)
                        {
                            throw e;
                        }
                        else
                        {
                            y = double.NaN;
                        }
                    }
                    Y = plot2D.DeviceCoordinateY(y);
                    if (float.IsNaN(Y))
                    {
                        if (Xp > 0)
                        {
                            // search the y value where the function turns into NaN
                            BinSearchNaN(x1, x, out y, out xn);
                            points[Xp].X   = plot2D.DeviceCoordinateX(xn);
                            points[Xp++].Y = plot2D.DeviceCoordinateY(y);
                            // insert the points into the cache
                            PointF[] copy = new PointF[Xp];
                            Array.Copy(points, copy, Xp);
                            lock (this) plist.Add(copy);
                        }
                        Xp = -1;
                    }
                    else
                    {
                        if (Xp == -1)                           // the last point was a NaN
                        // search the y value where the function turns into NaN
                        {
                            BinSearchNaN(x1, x, out y, out xn);
                            points[0].X = plot2D.DeviceCoordinateX(xn);
                            points[0].Y = plot2D.DeviceCoordinateY(y);
                            Xp          = 1;
                        }
                        points[Xp].X   = X;
                        points[Xp++].Y = Y;
                    }
                    x0 = x1;
                    x1 = x;
                    plot2D.Progress++;
                }
                if (Xp == plot2D.Bounds.Width)
                {
                    lock (this) plist.Add(points);
                }
                else if (Xp > 0)
                {
                    PointF[] copy = new PointF[Xp];
                    Array.Copy(points, copy, Xp);
                    lock (this) plist.Add(copy);
                }
                Recalc = plot2D.DrawStop;
            }
        }