public PolygonExtractor(List<Path> paths, Bitmap image)
 {
     bmp = image;
     foreach (Path p in paths)
     {
         Node node1, node2;
         int node1Key = GetNodeKey(p.V1.Point.X, p.V1.Point.Y);
         if (NodeMap.ContainsKey(node1Key))
             node1 = NodeMap[node1Key];
         else
         {
             node1 = new Node(p.V1.Point.X, p.V1.Point.Y);
             Nodes.Add(node1);
             NodeMap.Add(node1Key, node1);
         }
         int node2Key = GetNodeKey(p.V2.Point.X, p.V2.Point.Y);
         if (NodeMap.ContainsKey(node2Key))
             node2 = NodeMap[node2Key];
         else
         {
             node2 = new Node(p.V2.Point.X, p.V2.Point.Y);
             Nodes.Add(node2);
             NodeMap.Add(node2Key, node2);
         }
         Edge edge = new Edge(node1, node2, p.Points);
         AddEdge(edge);
     }
 }
Esempio n. 2
0
 public Edge(Node n1, Node n2, List<Point> points)
 {
     Points = points;
     HalfEdges = new HalfEdge[] { new HalfEdge(n1, n2, this), new HalfEdge(n2, n1, this) };
     Nodes = new Node[] { n1, n2 };
 }
 public int GetNodeKey(Node n)
 {
     return GetNodeKey(n.X, n.Y);
 }
 public long GetHalfEdgeKey(Node start, Node end)
 {
     int startKey = GetNodeKey(start);
     int endKey = GetNodeKey(end);
     long multiplicator = bmp.Width * bmp.Height;
     return startKey * multiplicator + endKey;
 }
 public long GetEdgeKey(Node n1, Node n2)
 {
     int k1 = GetNodeKey(n1);
     int k2 = GetNodeKey(n2);
     int min = k1 < k2 ? k1 : k2;
     int max = k1 > k2 ? k1 : k2;
     long multiplicator = bmp.Width * bmp.Height;
     return min * multiplicator + max;
 }
Esempio n. 6
0
 public HalfEdge(Node start, Node end, Edge edge)
 {
     Start = start;
     End = end;
     Edge = edge;
 }