/// <summary> /// bmpからGridMapを生成 /// </summary> /// <param name="bitmap"></param> public GridMap(Bitmap bitmap) { W = bitmap.Width; H = bitmap.Height; M = new Grid[W, H]; BitmapAccess access = new BitmapAccess(bitmap); access.BeginAccess(); // bmpからGridMapを生成 for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { Color c = access[x, y]; if (c == GridColor_Fill) { // 障害物 this[x, y] = Grid.Fill; } else if (c == GridColor_Free) { // 何もないところ this[x, y] = Grid.Free; } else if (c == GridColor_RedArea) { // 異常地帯 壁の中 this[x, y] = Grid.RedArea; } else if (c == GridColor_GreenArea) { // 位置補正エリア this[x, y] = Grid.GreenArea; } else if (c == GridColor_BlueArea) { // スローエリア this[x, y] = Grid.BlueArea; } else { // それ以外 this[x, y] = Grid.Unknown; } } } access.EndAccess(); }
/// <summary> /// GridMapからBMP更新 /// </summary> /// <returns></returns> public Bitmap UpdateBitmap() { BitmapAccess MapAccess = new BitmapAccess(img); MapAccess.BeginAccess(); for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { Color cl = Color.Yellow; switch (this[x, y]) { case Grid.Fill: cl = Color.Black; break; case Grid.Free: cl = Color.White; break; case Grid.RedArea: cl = Color.Red; break; case Grid.BlueArea: cl = Color.Blue; break; case Grid.GreenArea: cl = Color.Green; break; case Grid.Unknown: cl = Color.LightGray; break; } MapAccess[x, y] = cl; } } MapAccess.EndAccess(); return(img); }
/// <summary> /// ワールドBMPからエリアのGridMapを作成 /// </summary> /// <returns></returns> public GridMap MakeAreaGridMap() { GridMap gm = new GridMap(AreaGridSize.w, AreaGridSize.h); BitmapAccess bmpAp = new BitmapAccess(mapBmp); bmpAp.BeginAccess(); // bmpからGridMapを生成 for (int x = 0; x < gm.W; ++x) { for (int y = 0; y < gm.H; ++y) { Color c; int adX = WldOffset.x + x; int adY = WldOffset.y + y; if (adX < 0 || adX >= mapBmp.Width || adY < 0 || adY >= mapBmp.Height) { // レンジ外 c = GridMap.GridColor_Fill; } else { c = bmpAp[adX, adY]; // 色数を減らして、微妙な誤差をなくす //c = Color.FromArgb((((c.R+4) / 5) * 5), (((c.G+4) / 5) * 5), (((c.B+4) / 5) * 5)); } //if (c == GridMap.GridColor_Fill) if (GridMap.IsLess(c, GridMap.GridColor_Fill, 20)) { // 障害物 gm.M[x, y] = Grid.Fill; } //else if (c == GridMap.GridColor_Free) else if (GridMap.IsUpper(c, GridMap.GridColor_Free, -20)) { // 通行可能 gm.M[x, y] = Grid.Free; } else if (c == GridMap.GridColor_RedArea) { // 通行不可 壁の中 gm.M[x, y] = Grid.RedArea; } else if (c == GridMap.GridColor_GreenArea) { // 通行可能 位置補正推奨 gm.M[x, y] = Grid.GreenArea; } else if (c == GridMap.GridColor_BlueArea) { // 通行可能 スローダウン gm.M[x, y] = Grid.BlueArea; } else { // それ以外 gm.M[x, y] = Grid.Unknown; } } } bmpAp.EndAccess(); AreaGridMap = gm; return(gm); }
/// <summary> /// GridMapからBMP更新 /// </summary> /// <returns></returns> public Bitmap UpdateBitmap() { BitmapAccess MapAccess = new BitmapAccess(img); MapAccess.BeginAccess(); for (int x = 0; x < W; ++x) { for (int y = 0; y < H; ++y) { Color cl = Color.Yellow; switch (this[x, y]) { case Grid.Fill: cl = Color.Black; break; case Grid.Free: cl = Color.White; break; case Grid.RedArea: cl = Color.Red; break; case Grid.BlueArea: cl = Color.Blue; break; case Grid.GreenArea: cl = Color.Green; break; case Grid.Unknown: cl = Color.LightGray; break; } MapAccess[x, y] = cl; } } MapAccess.EndAccess(); return img; }
/// <summary> /// ワールドBMPからエリアのGridMapを作成 /// </summary> /// <returns></returns> public GridMap MakeAreaGridMap() { GridMap gm = new GridMap(AreaGridSize.w, AreaGridSize.h); BitmapAccess bmpAp = new BitmapAccess(mapBmp); bmpAp.BeginAccess(); // bmpからGridMapを生成 for (int x = 0; x < gm.W; ++x) { for (int y = 0; y < gm.H; ++y) { Color c; int adX = WldOffset.x + x; int adY = WldOffset.y + y; if (adX < 0 || adX >= mapBmp.Width || adY < 0 || adY >= mapBmp.Height) { // レンジ外 c = GridMap.GridColor_Fill; } else { c = bmpAp[adX, adY]; // 色数を減らして、微妙な誤差をなくす //c = Color.FromArgb((((c.R+4) / 5) * 5), (((c.G+4) / 5) * 5), (((c.B+4) / 5) * 5)); } //if (c == GridMap.GridColor_Fill) if ( GridMap.IsLess(c,GridMap.GridColor_Fill,20)) { // 障害物 gm.M[x, y] = Grid.Fill; } //else if (c == GridMap.GridColor_Free) else if (GridMap.IsUpper(c, GridMap.GridColor_Free, -20)) { // 通行可能 gm.M[x, y] = Grid.Free; } else if (c == GridMap.GridColor_RedArea) { // 通行不可 壁の中 gm.M[x, y] = Grid.RedArea; } else if (c == GridMap.GridColor_GreenArea) { // 通行可能 位置補正推奨 gm.M[x, y] = Grid.GreenArea; } else if (c == GridMap.GridColor_BlueArea) { // 通行可能 スローダウン gm.M[x, y] = Grid.BlueArea; } else { // それ以外 gm.M[x, y] = Grid.Unknown; } } } bmpAp.EndAccess(); AreaGridMap = gm; return gm; }