Exemplo n.º 1
0
        public static Bitmap[,] ReconstructFromExample(int ndx, List <Bitmap> bitmaps, int size)
        {
            var example   = bitmaps[ndx];
            var width     = example.Width;
            var height    = example.Height;
            var edgeTypes = Enum.GetValues(typeof(EdgeType)).Cast <EdgeType>();
            var templates = edgeTypes.Select(x => new EdgeTemplate(x, width, height)).ToList();
            var edges     = bitmaps.SelectMany(bmp => templates.Select(tmpl => new Edge(bmp, tmpl)))
                            .Where(GoodEdge)
                            .ToList();

            var result  = new Bitmap[size * 2 + 3, size * 2 + 3];
            var edgeCol = new EdgeCollection(edges);

            result[size + 1, size + 1] = example;
            ReconstructFrom(result, templates, size + 1, size + 1, edgeCol);
            return(result);
        }
Exemplo n.º 2
0
 private static bool TryReconstructFrom(Bitmap[,] result, List<EdgeTemplate> templates, int x, int y, EdgeCollection edges)
 {
     var current = result[x, y];
     var currentEdges = templates.Select(tmpl => new Edge(current, tmpl));
     foreach (var edge in edges.Edges)
     {
         foreach (var curr in currentEdges)
         {
             var dir = Edge.ToDirection(curr.Type);
             var x2 = x + dir.X;
             var y2 = y + dir.Y;
             if (result[x2, y2] == null && curr.Matches(edge) && MatchesInPosition(result, templates, edge.Source, x2, y2))
             {
                 result[x2, y2] = edge.Source;
                 ReconstructFrom(result, templates, x2, y2, edges);
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 3
0
        private static void ReconstructFrom(Bitmap[,] result, List<EdgeTemplate> templates, int x, int y, EdgeCollection edges)
        {
            var current = result[x, y];
            edges.RemoveBySource(current);

            while (TryReconstructFrom(result, templates, x, y, edges)) ;
        }
Exemplo n.º 4
0
        public static Bitmap[,] ReconstructFromExample(int ndx, List<Bitmap> bitmaps, int size)
        {
            var example = bitmaps[ndx];
            var width = example.Width;
            var height = example.Height;
            var edgeTypes = Enum.GetValues(typeof(EdgeType)).Cast<EdgeType>();
            var templates = edgeTypes.Select(x => new EdgeTemplate(x, width, height)).ToList();
            var edges = bitmaps.SelectMany(bmp => templates.Select(tmpl => new Edge(bmp, tmpl)))
                .Where(GoodEdge)
                .ToList();

            var result = new Bitmap[size * 2 + 3, size * 2 + 3];
            var edgeCol = new EdgeCollection(edges);
            result[size + 1, size + 1] = example;
            ReconstructFrom(result, templates, size + 1, size + 1, edgeCol);
            return result;
        }
Exemplo n.º 5
0
        private static bool TryReconstructFrom(Bitmap[,] result, List <EdgeTemplate> templates, int x, int y, EdgeCollection edges)
        {
            var current      = result[x, y];
            var currentEdges = templates.Select(tmpl => new Edge(current, tmpl));

            foreach (var edge in edges.Edges)
            {
                foreach (var curr in currentEdges)
                {
                    var dir = Edge.ToDirection(curr.Type);
                    var x2  = x + dir.X;
                    var y2  = y + dir.Y;
                    if (result[x2, y2] == null && curr.Matches(edge) && MatchesInPosition(result, templates, edge.Source, x2, y2))
                    {
                        result[x2, y2] = edge.Source;
                        ReconstructFrom(result, templates, x2, y2, edges);
                        return(true);
                    }
                }
            }
            return(false);
        }
Exemplo n.º 6
0
        private static void ReconstructFrom(Bitmap[,] result, List <EdgeTemplate> templates, int x, int y, EdgeCollection edges)
        {
            var current = result[x, y];

            edges.RemoveBySource(current);

            while (TryReconstructFrom(result, templates, x, y, edges))
            {
                ;
            }
        }