Example #1
0
 public static void ResetTileset()
 {
     allSortedTiles = new TileSorting();
     TilesetReady = false;
 }
Example #2
0
        public static void SortTiles(float patternThreshold, float colourThreshold)
        {
            TilesetReady = false;
            TasksComplete = 0;
            TotalTasks = allSubImageTiles.Count;
            Duplicates = 0;
            SortTime = 0;

            Stopwatch timer = new Stopwatch();
            timer.Start();

            if (allSortedTiles == null)
            {
                allSortedTiles = new TileSorting();
            }

            //while(allSubImageTiles.Count > 0)
            for (int i = 0; i < allSubImageTiles.Count; i++)
            {
                //Tile tileToCompare = allSubImageTiles[i];
                Tile tile = allSubImageTiles.ElementAt(i);
                //int index = tile.Index;
                //Tile tileToCompare = allSubImageTiles.First.Value;
                //allSubImageTiles.RemoveFirst();

                if (i == 0)
                {
                    //allSortedTiles.AddGroup(index);
                    allSortedTiles.AddGroup(tile);
                    TasksComplete++;
                    continue;
                }

                //TileGroup group = FindMatchingGroup(tile, patternThreshold, colourThreshold);
                TileGroupMatchResults results = FindMatchingGroupWithResults(tile, patternThreshold, colourThreshold);
                TileGroup group = results.group;
                if (group == null)
                {
                    // Add to new group
                    //allSortedTiles.AddGroup(index);
                    allSortedTiles.AddGroup(tile);
                    TasksComplete++;
                    continue;
                }

                // Convert pattern match to hashcode
                //int MasterIndex = group.MasterIndex;
                ////Tile Master = allSubImageTiles[MasterIndex];
                //Tile Master = allSubImageTiles.ElementAt(MasterIndex);
                //Tuple<float, float> results = Master.GetMatches(tile);
                //float patternMatch = results.Item1;
                //float colourMatch = results.Item2;

                float patternMatch = results.patternMatch;
                float colourMatch = results.colourMatch;

                bool areIdentical = Tile.IdenticalTo(patternMatch, colourMatch);
                if (areIdentical == true)
                {
                    Duplicates++;
                    TasksComplete++;
                    continue;
                }

                // If tilecount is saved for each group, could improve performance by reducing the hashcode TileSize since tilecount gets smaller with time
                int key = Tile.GetHashcode(ACCURACY, patternMatch, colourMatch, TotalTasks);
                AddSimilarTileToGroup(tile, group, key);
                TasksComplete++;
            }

            timer.Stop();
            SortTime = timer.ElapsedMilliseconds;

            TilesetReady = true;
        }
Example #3
0
        public static void LoadImage(string path, int tileSize, int offsetX, int offsetY)
        {
            Bitmap image = LoadCroppedImage(path, tileSize, offsetX, offsetY);
            int width = image.Width;
            int height = image.Height;

            Images = new ImageCollection(path, tileSize, width, height, offsetX, offsetY);

            allSortedTiles = new TileSorting();

            Images.SetSubImageByRefFromImage(ref image, 0);

            //loadedImage = canvas;
        }