protected void draw_gridlines(Graphics drawer)
        {
            Pen gridlinepen = new Pen(Color.FromArgb(130, 0, 0, 0), GRIDLINE_THICKNESS);

            NCAMRNode[,] gridpoints = new NCAMRNode[settings.XGridlineCount, settings.YGridlineCount];
            double coordinate_dx = (subject.Xmax - subject.Xmin) / (settings.XGridlineCount - 1);
            double coordinate_dy = (subject.Ymax - subject.Ymin) / (settings.YGridlineCount - 1);

            for (int i = 0; i < settings.XGridlineCount; i++)
            {
                for (int j = 0; j < settings.YGridlineCount; j++)
                {
                    gridpoints[i, j] = new NCAMRNode(subject.Xmin + i * coordinate_dx, subject.Ymin + j * coordinate_dy, 0);
                }
            }
            for (int i = 0; i < settings.XGridlineCount; i++)
            {
                for (int j = 0; j < settings.YGridlineCount - 1; j++)
                {
                    //thick grid pen temporary
                    drawer.DrawLine(gridlinepen, mapGridNode(gridpoints[i, j]), mapGridNode(gridpoints[i, j + 1]));
                }
            }
            for (int i = 0; i < settings.YGridlineCount; i++)
            {
                for (int j = 0; j < settings.XGridlineCount - 1; j++)
                {
                    //thick grid pen temporary
                    drawer.DrawLine(gridlinepen, mapGridNode(gridpoints[j + 1, i]), mapGridNode(gridpoints[j, i]));
                }
            }
        }
Exemple #2
0
        public static double NormDifference(NCGrid_Distribution A, NCGrid_Distribution B)
        {
            NCGrid_Distribution newgrid = new NCGrid_Distribution(A.Bounds, A.Xcount + 1, A.Ycount + 1);
            int       n    = newgrid.Ycount;
            int       m    = newgrid.Xcount;
            double    xmin = newgrid.Xmin;
            double    xmax = newgrid.Xmax;
            double    ymin = newgrid.Ymin;
            double    ymax = newgrid.Ymax;
            NCAMRNode ll   = new NCAMRNode(xmin, ymin, 0);
            NCAMRNode lr   = new NCAMRNode(xmax, ymin, 0);
            NCAMRNode ul   = new NCAMRNode(xmin, ymax, 0);
            NCAMRNode ur   = new NCAMRNode(xmax, ymax, 0);

            newgrid[0, 0]         = ll;
            newgrid[0, n - 1]     = ul;
            newgrid[m - 1, 0]     = lr;
            newgrid[m - 1, n - 1] = ur;
            for (int i = 0; i < A.Xcount - 1; i++)
            {
                newgrid[i + 1, 0]        = xyavg(A[i, 0], A[i + 1, 0]);
                newgrid[i + 1, A.Ycount] = xyavg(A[i, A.Ycount - 1], A[i + 1, A.Ycount - 1]);
            }
            for (int j = 0; j < A.Ycount - 1; j++)
            {
                newgrid[0, j + 1]        = xyavg(A[0, j], A[0, j + 1]);
                newgrid[A.Xcount, j + 1] = xyavg(A[A.Xcount - 1, j], A[A.Xcount - 1, j + 1]);
            }
            for (int i = 0; i < A.Xcount - 1; i++)
            {
                for (int j = 0; j < A.Ycount - 1; j++)
                {
                    newgrid[i + 1, j + 1] = xyavg(A[i, j], A[i + 1, j], A[i, j + 1], A[i + 1, j + 1]);
                }
            }
            double accumulator = 0;

            for (int i = 0; i < m - 1; i++)
            {
                for (int j = 0; j < n - 1; j++)
                {
                    NCAMRNode[] nodes =
                    {
                        newgrid[i,     j],
                        newgrid[i + 1, j],
                        newgrid[i + 1, j + 1],
                        newgrid[i,     j + 1]
                    };
                    double[] x = new double[nodes.Length];
                    double[] y = new double[nodes.Length];
                    for (int z = 0; z < nodes.Length; z++)
                    {
                        x[z] = nodes[z].X;
                        y[z] = nodes[z].Y;
                    }
                    accumulator += quad_area(x, y) * (A[i, j].Value - B[i, j].Value) * (A[i, j].Value - B[i, j].Value);
                }
            }
            return(Math.Sqrt(accumulator));
        }
        public static NCGrid_Distribution from_file(string title, bool using_full_path)
        {
            string path = Paths.DistributionRepo + "\\" + title + ".dist";

            if (using_full_path)
            {
                path = title;
            }
            string[]  contents   = File.ReadAllLines(path);
            int       length     = contents.Length;
            RBounds2D new_bounds = RBounds2D.fromstring(contents[0]);

            string[] numbers = contents[1].Split(':');
            int      nx, ny;

            if (!(int.TryParse(numbers[1], out nx) && int.TryParse(numbers[3], out ny)))
            {
                throw new Exception("File format error");
            }
            NCGrid_Distribution created = new NCGrid_Distribution(new_bounds, nx, ny);

            for (int q = additional_file_lines; q < contents.Length; q++)
            {
                int qprime = q - additional_file_lines;
                int i      = qprime % nx;
                int j      = (qprime - i) / nx;
                created[i, j] = NCAMRNode.fromstring(contents[q]);
            }
            return(created);
        }
        private void generate_nodes(double preset_value)
        {
            dx     = (bounds.Xmax - bounds.Xmin) / (x_node_count - 1);
            dy     = (bounds.Ymax - bounds.Ymin) / (y_node_count - 1);
            minval = preset_value;

            maxval = preset_value;
            for (int i = 0; i < x_node_count; i++)
            {
                for (int j = 0; j < y_node_count; j++)
                {
                    NCAMRNode newnode = new NCAMRNode(bounds.Xmin + i * dx, bounds.Ymin + j * dy, preset_value);
                    nodes[i, j] = newnode;
                }
            }
        }
        private bool in_y_polygon_assume_right(int lowerbound, double x, double y)
        {
            bool odd = false;

            for (int i = 0; i < Xcount; i++)
            {
                NCAMRNode tracker = nodes[i, lowerbound];
                double    track_x = tracker.X;
                double    track_y = tracker.Y;
                if (((track_x > x) != odd) && track_y > y)
                {
                    odd = !odd;
                }
            }
            return(odd);
        }
 public double interpolate_at(double x, double y)
 {
     if (x < bounds.Xmin || x > bounds.Xmax || y < bounds.Ymin || y > bounds.Ymax)
     {
         throw new Exception("Error: Extrapolation prevented.");
     }
     else
     {
         int i = get_x_ll_index(x, y);
         int j = get_y_ll_index(x, y);
         if (i >= Xcount - 1)
         {
             i--;
         }
         if (j >= Ycount - 1)
         {
             j--;
         }
         NCAMRNode n1      = nodes[i, j];
         NCAMRNode n2      = nodes[i + 1, j];
         NCAMRNode n3      = nodes[i + 1, j + 1];
         NCAMRNode n4      = nodes[i, j + 1];
         double[]  weights =
         {
             Math.Exp(-sq(x - n1.X) - sq(y - n1.Y)),
             Math.Exp(-sq(x - n2.X) - sq(y - n2.Y)),
             Math.Exp(-sq(x - n3.X) - sq(y - n3.Y)),
             Math.Exp(-sq(x - n4.X) - sq(y - n4.Y))
         };
         double[] vals =
         {
             n1.Value,
             n2.Value,
             n3.Value,
             n4.Value
         };
         double acc_top    = 0;
         double acc_bottom = 0;
         for (int q = 0; q < vals.Length; q++)
         {
             acc_bottom += weights[q];
             acc_top    += weights[q] * vals[q];
         }
         return(acc_top / acc_bottom);
     }
 }
        public Vector3 estimate_num_graident(int i, int j, DerivativeEstimationMode mode)
        {
            //will need to add in edge cases. Ignore for now.
            switch (mode)
            {
            case DerivativeEstimationMode.GFDM:
            {
                //lacks implementation
                return(Vector3.Zero);
            }

            case DerivativeEstimationMode.TAYLOR_SURPLUS_UPPER_RIGHT:
            {
                //clean this up???
                NCAMRNode[] stencil =
                {
                    nodes[i,     j],
                    nodes[i + 1, j],
                    nodes[i,     j + 1],
                    nodes[i - 1, j],
                    nodes[i,     j - 1],
                    nodes[i + 1, j + 1]
                };
                double[] deltas_u =
                {
                    stencil[1].Value - stencil[0].Value,
                    stencil[2].Value - stencil[0].Value,
                    stencil[3].Value - stencil[0].Value,
                    stencil[4].Value - stencil[0].Value,
                    stencil[5].Value - stencil[0].Value
                };
                double[] deltas_x =
                {
                    stencil[1].X - stencil[0].X,
                    stencil[2].X - stencil[0].X,
                    stencil[3].X - stencil[0].X,
                    stencil[4].X - stencil[0].X,
                    stencil[5].X - stencil[0].X
                };
                double[] deltas_y =
                {
                    stencil[1].Y - stencil[0].Y,
                    stencil[2].Y - stencil[0].Y,
                    stencil[3].Y - stencil[0].Y,
                    stencil[4].Y - stencil[0].Y,
                    stencil[5].Y - stencil[0].Y
                };
                double[] matrix_contents =
                {
                    deltas_x[0], deltas_y[0], 0.5 * sq(deltas_x[0]), 0.5 * sq(deltas_x[0]), deltas_x[0] * deltas_y[0],
                    deltas_x[1], deltas_y[1], 0.5 * sq(deltas_x[1]), 0.5 * sq(deltas_x[1]), deltas_x[1] * deltas_y[1],
                    deltas_x[2], deltas_y[2], 0.5 * sq(deltas_x[2]), 0.5 * sq(deltas_x[2]), deltas_x[2] * deltas_y[2],
                    deltas_x[3], deltas_y[3], 0.5 * sq(deltas_x[3]), 0.5 * sq(deltas_x[3]), deltas_x[3] * deltas_y[3],
                    deltas_x[4], deltas_y[4], 0.5 * sq(deltas_x[4]), 0.5 * sq(deltas_x[4]), deltas_x[4] * deltas_y[4]
                };
                Matrix delta = new Matrix(5, 1);
                return(Vector3.Zero);
            }

            case DerivativeEstimationMode.WEIGHTFUNCTION:
            {
                return(Vector3.Zero);
            }

            case DerivativeEstimationMode.NAIVE:
            {
                double    delta_x = (bounds.Xmax - bounds.Xmin) / (Xcount - 1);
                double    delta_y = (bounds.Ymax - bounds.Ymin) / (Ycount - 1);
                NCAMRNode node    = nodes[i, j];
                double    dzdx    = (this.interpolate_at(node.X + delta_x, node.Y) - this.interpolate_at(node.X - delta_x, node.Y)) / (2 * delta_x);
                double    dzdy    = (this.interpolate_at(node.X, node.Y + delta_y) - this.interpolate_at(node.X, node.Y - delta_y)) / (2 * delta_x);
                return(new Vector3(dzdx, dzdy, 0));
            }

            default:
            {
                return(Vector3.Zero);
            }
            }
        }
 protected PointF mapGridNode(NCAMRNode toMap)
 {
     return(new PointF(grid_xmin + pix_per_unit_x * (float)(toMap.X - subject.Xmin), grid_ymin + pix_per_unit_y * (float)((subject.Ymax - toMap.Y))));
 }
Exemple #9
0
        public NCAMRNode Clone()
        {
            NCAMRNode b = new NCAMRNode(x, y, node_value);

            return(b);
        }