Exemplo n.º 1
0
 public void removeLink(Node node)
 {
     list.Remove(node);
 }
Exemplo n.º 2
0
 public void addLink(Node node)
 {
     this.list.Add(node);
 }
Exemplo n.º 3
0
        private Dictionary<Point, Node> generateMap(Node[,] nodes)
        {
            Dictionary<Point, Node> dict = new Dictionary<Point, Node>();

            // Build the graph and dictionary
            for (int i = 1; i < nodes.GetLength(0) - 1; i++)
            {
                for (int j = 1; j < nodes.GetLength(1) - 1; j++)
                {
                    nodes[i, j].addLink(nodes[i - 1, j - 1]);
                    nodes[i, j].addLink(nodes[i + 1, j + 1]);
                    nodes[i, j].addLink(nodes[i - 1, j + 1]);
                    nodes[i, j].addLink(nodes[i + 1, j - 1]);
                    nodes[i, j].addLink(nodes[i + 1, j]);
                    nodes[i, j].addLink(nodes[i - 1, j]);
                    nodes[i, j].addLink(nodes[i, j + 1]);
                    nodes[i, j].addLink(nodes[i, j - 1]);
                    dict.Add(nodes[i, j].getPoint(), nodes[i, j]);
                }
            }

            // Find points inside unallowed regions
            List<Point> removeList = new List<Point>();
            foreach (KeyValuePair<Point, Node> d in dict)
            {
                int x = (int)d.Value.getPoint().X;
                int y = (int)d.Value.getPoint().Y;
                Color color = image_mask.GetPixel(x, y);
                if (color.R < 10 && color.G < 10 && color.B < 10)
                {
                    removeList.Add(d.Key);
                }
            }

            // Remove points from graph and dictionary
            foreach (Point p in removeList)
            {
                Node node = dict[p];
                foreach (Node n in node.getLinks())
                {
                    n.removeLink(node);
                }
                dict.Remove(p);
            }

            return dict;
        }
Exemplo n.º 4
0
 private Node[,] generateNodes(int step)
 {
     Node[,] nodes = new Node[image_mask.Width / step + 1, image_mask.Height / step + 1];
     for (int i = 0; i < nodes.GetLength(0); i++)
     {
         for (int j = 0; j < nodes.GetLength(1); j++)
         {
             nodes[i, j] = new Node(new Point(i * step, j * step));
         }
     }
     return nodes;
 }
Exemplo n.º 5
0
        private List<Node> followPath(Node node, List<Node> list)
        {
            if (node.parent == null)
            {
                list.Reverse();
                return list;
            }
            list.Add(node);

            return followPath(node.parent, list);
        }