Пример #1
0
 private Node1[,] GetNode(int width, int height, List<Segment1> segments)
 {
     Node1[,] nodes = new Node1[width, height];
     for (int x = 0; x < width; x++)
         for (int y = 0; y < height; y++)
         {
             nodes[x, y] = new Node1(x, y, segments[y * width + x]);
             segments[y * width + x].AddNode(nodes[x, y]);
         }
     return nodes;
 }
Пример #2
0
 private List<Edge1> BuildEdges(int width, int height, byte[,] pixels, Node1[,] nodes)
 {
     List<Edge1> edges = new List<Edge1>();
     for (int y = 0; y < height; y++)
         for (int x = 0; x < width; x++)
         {
             byte pixel1 = pixels[x, y];
             if (x < (width - 1))
             {
                 if (y > 0)
                     edges.Add(new Edge1(nodes[x, y], nodes[x + 1, y - 1], Math.Abs(pixel1 - pixels[x + 1, y - 1]))); // Up-Right
                 edges.Add(new Edge1(nodes[x, y], nodes[x + 1, y], Math.Abs(pixel1 - pixels[x + 1, y]))); // Right
                 if (y < (height - 1))
                     edges.Add(new Edge1(nodes[x, y], nodes[x + 1, y + 1], Math.Abs(pixel1 - pixels[x + 1, y + 1]))); // Down-Right
             }
             if (y < (height - 1))
                 edges.Add(new Edge1(nodes[x, y], nodes[x, y + 1], Math.Abs(pixel1 - pixels[x, y + 1]))); // Down
         }
     return edges;
 }
Пример #3
0
 public Edge1(Node1 a, Node1 b, int weight)
 {
     A = a;
     B = b;
     Weight = weight;
 }
Пример #4
0
 public Graph1(Node1[,] nodes, List<Edge1> edges, List<Segment1> segments)
 {
     Nodes = nodes;
     Edges = edges;
     Segments = segments;
 }
Пример #5
0
 public void AddNode(Node1 node)
 {
     Clear();
     Nodes.Add(node);
 }