示例#1
0
文件: Form1.cs 项目: 5l1v3r1/ctf-14
        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);
        }
示例#2
0
文件: Form1.cs 项目: CorpOfHack/ctf-1
 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;
 }
示例#3
0
文件: Form1.cs 项目: CorpOfHack/ctf-1
        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)) ;
        }
示例#4
0
文件: Form1.cs 项目: CorpOfHack/ctf-1
        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;
        }
示例#5
0
文件: Form1.cs 项目: 5l1v3r1/ctf-14
        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);
        }
示例#6
0
文件: Form1.cs 项目: 5l1v3r1/ctf-14
        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))
            {
                ;
            }
        }