private static List <Bitmap> GetDistinctBitmaps(List <List <Bitmap> > grid) { List <Bitmap> DistinctTiles = new List <Bitmap>(); foreach (var verticalRow in grid) { foreach (var tile in verticalRow) { var Distinct = true; foreach (var validatedTile in DistinctTiles) { var equal = BitmapOperations.Compare(validatedTile, tile); if (equal) { Distinct = false; break; } } if (Distinct == true) { DistinctTiles.Add(tile); } } } return(DistinctTiles); }
private List <OpinionatedItem <Bitmap> > getWcfTilesInBmp(string path, bool hasSpacing = false) { Bitmap bmp = Image.FromFile(path) as Bitmap; List <List <Bitmap> > tileset = BitmapOperations.GetBitmapTiles(bmp, _tileWidth, _tileHeight, hasSpacing); List <Bitmap> tiles = new List <Bitmap>(); foreach (var list in tileset) { tiles.AddRange(list); } return(_wfcTiles.Where(element => tiles.Any(t => BitmapOperations.Compare(t, element.actualItem))).ToList()); }
private static void SetAcceptableItems(List <OpinionatedItem <Bitmap> > Elements, List <List <Bitmap> > Tilemap) { foreach (var element in Elements) { for (var x = 0; x < Tilemap.Count; x++) { for (var y = 0; y < Tilemap[0].Count; y++) { if (BitmapOperations.Compare(Tilemap[x][y], element.actualItem)) { List <Point> neighborpoints = new List <Point>() { // new Point(x - 1, y - 1), new Point(x, y - 1), //new Point(x + 1, y - 1), new Point(x + 1, y), //new Point(x + 1, y + 1), new Point(x, y + 1), //new Point(x - 1, y + 1), new Point(x - 1, y) }; neighborpoints = neighborpoints.Where(point => point.X >= 0 && point.X < Tilemap.Count && point.Y >= 0 && point.Y < Tilemap[0].Count ).ToList(); List <Bitmap> neighborBmps = new List <Bitmap>(); foreach (var neighborpoint in neighborpoints) { neighborBmps.Add(Tilemap[neighborpoint.X][neighborpoint.Y]); } for (var n = 0; n < neighborBmps.Count; n++) { var neighborBmp = neighborBmps[n]; var neighborPoint = neighborpoints[n]; var elementPoint = new Point(x, y); var relativePoint = new Point(neighborPoint.X - elementPoint.X, neighborPoint.Y - elementPoint.Y); OpinionatedItem <Bitmap> neighborElement = null; foreach (var elementN in Elements) { if (BitmapOperations.Compare(elementN.actualItem, neighborBmp)) { neighborElement = elementN; break; } } //if neighbor in element has neighbor at pos, bail (make distinct - makes faster in long run.. no natural weight though /*if (element.GetAcceptableInDirection(relativePoint.X, relativePoint.Y, 0).Any(acc => acc.Id == neighborElement.Id)) * continue;*/ if (neighborElement == null) { throw new Exception("Couldn't find neighbor in distinct elements!"); } element.SetAcceptableInDirection(neighborElement, relativePoint.X, relativePoint.Y, 0); } } } } } }
private List <OpinionatedItem <Bitmap> > GetMatchesInMain(List <Bitmap> items) { return(MainDistinct.Where(element => items.Any(t => BitmapOperations.Compare(t, element.actualItem))).ToList()); }
private bool BitmapIsTile(Bitmap Bitmap, TileType tileType) { var refTile = GetBitmapByTileTypeFromRam(tileType); return(BitmapOperations.Compare(Bitmap, refTile)); }
private static void Execute() { Bitmap tileset = Image.FromFile(ConfigurationManager.AppSettings["TilesetInput"]) as Bitmap; tileset = tileset.AddHorizontalMirror(); List <List <Bitmap> > tiles = BitmapOperations.GetBitmapTiles(tileset, 5, 5); Bitmap hTraverseBmp = Image.FromFile(ConfigurationManager.AppSettings["hTraverseInput"]) as Bitmap; List <List <Bitmap> > hTraverseDbl = BitmapOperations.GetBitmapTiles(hTraverseBmp, 5, 5); Bitmap quickcheck = BitmapOperations.CreateBitmapFromTiles(hTraverseDbl, true); BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["TilesetOutput"], quickcheck); List <Bitmap> hTraverse = new List <Bitmap>(); foreach (var list in hTraverseDbl) { hTraverse.AddRange(list); } Bitmap vTraverseBmp = Image.FromFile(ConfigurationManager.AppSettings["vTraverseInput"]) as Bitmap; List <List <Bitmap> > vTraverseDbl = BitmapOperations.GetBitmapTiles(vTraverseBmp, 5, 5); List <Bitmap> vTraverse = new List <Bitmap>(); foreach (var list in vTraverseDbl) { vTraverse.AddRange(list); } var distinctTiles = GetDistinctBitmaps(tiles); List <List <Bitmap> > distinctElements = new List <List <Bitmap> >(); distinctElements.Add(distinctTiles); Bitmap tilemapWithSpacing = BitmapOperations.CreateBitmapFromTiles(distinctElements, true); BitmapOperations.SaveBitmapToFile(ConfigurationManager.AppSettings["TilesetOutput"], tilemapWithSpacing); var opinionatedItemsDistinct = ToOpinionatedList(distinctTiles); SetAcceptableItems(opinionatedItemsDistinct, tiles); var vTraverseOpinionated = opinionatedItemsDistinct.Where(element => vTraverse.Any(bmp => BitmapOperations.Compare(bmp, element.actualItem))).ToList(); var hTraverseOpinionated = opinionatedItemsDistinct.Where(element => hTraverse.Any(bmp => BitmapOperations.Compare(bmp, element.actualItem))).ToList(); for (var i = 0; i < 5; i++) { var wcf = new WcfGrid(); wcf.Init(20, 10, 1, opinionatedItemsDistinct); List <WcfVector> shape = WcfVector.GetCross3dShape(); wcf.SetInfluenceShape(shape); //Manual Edits //in and out AddDoor(wcf, opinionatedItemsDistinct[1], 5); //border AddBorder(wcf, opinionatedItemsDistinct[0], 5); //add path AddPath(wcf, hTraverseOpinionated, 5); var result = wcf.CollapseAllRecursive(); //if (result == false) //continue; var collapsedTiles = ToTilesList(wcf); wcf.PrintStatesToConsole2d(); Bitmap tilesetRedux = BitmapOperations.CreateBitmapFromTiles(collapsedTiles); BitmapOperations.SaveBitmapToFile( ConfigurationManager.AppSettings["BitmapOutput"].Replace( ".bmp", i.ToString() + ".bmp" ), tilesetRedux); } }