void SetLegoType_OverView(LegoColor legoColor) { switch (legoColor) { case LegoColor.Blue: myType_Detail_OverView = LandscapeType_OverView.Water; break; case LegoColor.Green: myType_Detail_OverView = LandscapeType_OverView.Nature; break; case LegoColor.Red: myType_Detail_OverView = LandscapeType_OverView.Building; break; case LegoColor.White: myType_Detail_OverView = LandscapeType_OverView.Road; break; /*case LegoColor.None: * myType_Detail_OverView = LandscapeType_OverView.Spaces; * break;*/ default: myType_Detail_OverView = LandscapeType_OverView.Spaces; break; } }
public LandscapeLegoInfo(LegoColor lc) { SetLegoType_OverView(lc); myType_Detail = LandscapeType_Details.Space; north = south = east = west = LandscapeType_OverView.Spaces; myDirection = Direction.North; height = 0; }
LegoBlockInfo[,] CalcLandscapeMapMode() { LegoBlockInfo[,] lsMap = new LegoBlockInfo[LegoData.LANDSCAPE_MAP_WIDTH, LegoData.LANDSCAPE_MAP_HEIGHT]; for (int y = 0; y < LegoData.LANDSCAPE_MAP_HEIGHT; y++) { for (int x = 0; x < LegoData.LANDSCAPE_MAP_WIDTH; x++) { int i = 0; LegoColor[] legoColor = new LegoColor[landscapeMapList_.Count]; int[] legoHeight = new int[landscapeMapList_.Count]; while (i < landscapeMapList_.Count) { legoColor[i] = landscapeMapList_[i][x, y].legoColor; legoHeight[i] = landscapeMapList_[i][x, y].height; i++; } lsMap[x, y].legoColor = LegoGeneric.CalcMode(legoColor, Enum.GetNames(typeof(LegoColor)).Length); lsMap[x, y].height = LegoGeneric.CalcMode(legoHeight, LegoData.BUILDING_HIERARCHY_NUM); } } return(lsMap); }
public LoadColors(string rootpath, string filename) { RootPath = rootpath; if (RootPath.IndexOf('\\', RootPath.Length - 1) < 0) { RootPath += "\\"; } FileName = filename; Colors = new List <LegoColor>(); if (!File.Exists(RootPath + FileName)) { return; } StreamReader file = new StreamReader(RootPath + FileName); while (!file.EndOfStream) { try { var line = file.ReadLine(); var str = Text.CleanSpace(line).Split(' '); if (str.Length > 2) { if (str[1] == "!COLOUR") { LegoColor lc = new LegoColor(); lc.Name = str[2]; lc.Code = int.Parse(str[4]); lc.Color = new RGB(str[6]); lc.Edge = new RGB(str[8]); if (str.Length >= 10) { for (int i = 0; i < str.Length; i++) { if (str[i] == "ALPHA") { lc.Alpha = int.Parse(str[i + 1]); break; } } for (int i = 0; i < str.Length; i++) { if (str[i] == "LUMINANCE") { lc.Luminance = int.Parse(str[i + 1]); break; } } for (int i = 0; i < str.Length; i++) { if ((str[i] == "CHROME") || (str[i] == "PEARLESCENT") || (str[i] == "RUBBER") || (str[i] == "MATERIAL") || (str[i] == "METAL")) { for (int j = i; j < str.Length; j++) { lc.Material += str[j] + ' '; } lc.Material = lc.Material.TrimEnd(' '); } } } Colors.Add(lc); } } } catch (Exception ex) { Debug.WriteLine(ex.Message); } //create a 24 and 16 color as it's a no color for //those colors is mapped to white. It is used when a raw dat part is loaded LegoColor Leg24 = new LegoColor(); Leg24.Name = "Master Color"; Leg24.Code = 24; Leg24.Color = new RGB("#FF0000"); Colors.Add(Leg24); LegoColor Leg16 = new LegoColor(); Leg16.Name = "Neutral"; Leg16.Code = 16; Leg16.Color = new RGB("#FF0000"); Colors.Add(Leg16); } }
private static RedComponentLimitsAttribute GetRedAttribute(LegoColor legoColor) { throw new NotImplementedException(); }
//LegoBlockInfo[,] CreateLandscapeMap() void CreateLandscapeMap() { #region Main RawLegoPixelInfo[,] rawLegoMap = GetTexturedata((Texture2D)colorImage_.texture); LegoBlockInfo[,] legoMap = ConvertRawLegoMap2LandscapeMap(rawLegoMap); landscapeMapList_.Add(legoMap); #endregion #region Local Method //指定したエリア内のレゴデータを取得する RawLegoPixelInfo[,] GetTexturedata(Texture2D colorTexture) { RawLegoPixelInfo[,] cameramap = new RawLegoPixelInfo[rawLegoImageWidth_, rawLegoImageHeight_]; Texture2D texture = new Texture2D(rawLegoImageWidth_, rawLegoImageHeight_, TextureFormat.RGBA32, false); manager_ = KinectManager.Instance; for (int y = 0; y < rawLegoImageHeight_; y++) { for (int x = 0; x < rawLegoImageWidth_; x++) { cameramap[x, y].depth = manager_.GetDepthForPixel(x + (int)LegoData.CalibrationData.baseEdgeXY[0].x, y + (int)LegoData.CalibrationData.baseEdgeXY[0].y); cameramap[x, y].depth = (ushort)Mathf.Abs(cameramap[x, y].depth >> 3); Vector2 posColor = manager_.GetColorMapPosForDepthPos(new Vector2(x + (int)LegoData.CalibrationData.baseEdgeXY[0].x, y + (int)LegoData.CalibrationData.baseEdgeXY[0].y)); cameramap[x, y].color = colorTexture.GetPixel((int)posColor.x, (int)posColor.y); texture.SetPixel(x, y, cameramap[x, y].color); } } texture.Apply(); trimRectImage_.texture = texture; return(cameramap); } // Array(RawLegoPixelInfo) => Array(LegoBlockInfo) LegoBlockInfo[,] ConvertRawLegoMap2LandscapeMap(RawLegoPixelInfo[,] cameraMap) { LegoBlockInfo[,] landscapeMap = new LegoBlockInfo[LegoData.LANDSCAPE_MAP_WIDTH, LegoData.LANDSCAPE_MAP_HEIGHT]; int cellWidth = rawLegoImageWidth_ / LegoData.LANDSCAPE_MAP_WIDTH; int cellHeight = rawLegoImageHeight_ / LegoData.LANDSCAPE_MAP_HEIGHT; for (int y = 0; y < LegoData.LANDSCAPE_MAP_HEIGHT; y++) { for (int x = 0; x < LegoData.LANDSCAPE_MAP_WIDTH; x++) { LegoColor[] cellColorMap = new LegoColor[cellHeight * cellWidth]; int[] cellFloorMap = new int[cellWidth * cellHeight]; for (int cy = 0; cy < cellHeight; cy++) { for (int cx = 0; cx < cellWidth; cx++) { cellColorMap[cy * cellWidth + cx] = DiscernColor(cameraMap[x * cellWidth + cx, y * cellHeight + cy].color); cellFloorMap[cy * cellWidth + cx] = DiscernLegoHeight(cameraMap[x * cellWidth + cx, y * cellHeight + cy].depth); } } landscapeMap[x, y].legoColor = LegoGeneric.CalcMode(cellColorMap, Enum.GetNames(typeof(LegoColor)).Length); landscapeMap[x, y].height = LegoGeneric.CalcMode(cellFloorMap, LegoData.BUILDING_HIERARCHY_NUM); } } return(landscapeMap); } LegoColor DiscernColor(Color c) { HSV hsv = LegoGeneric.RGB2HSV(c); /* * if (hsv.h == 0 && hsv.v == 0) return LegoColor.Black; * if (225 <= hsv.h && hsv.h < 255) return LegoColor.Blue; //base : 240 * if (hsv.h < 15 || 345 <= hsv.h) return LegoColor.Red; //base : 0 * if (75 <= hsv.h && hsv.h < 105) return LegoColor.Green; //base : 90 */ /* * if (hsv.h == 0 && hsv.v == 0) return LegoColor.Black; * if (165 <= hsv.h && hsv.h < 300) return LegoColor.Blue; //base : 240 * if (hsv.h < 45 || 300 <= hsv.h) return LegoColor.Red; //base : 0 * if (45 <= hsv.h && hsv.h < 165) return LegoColor.Green; //base : 90 * * return LegoColor.None; */ LegoColor max = LegoGeneric.Max_rgb(c); if (c.r > 0.6f && c.g > 0.6f && c.b > 0.6f) { return(LegoColor.White); } else { return(max); } } int DiscernLegoHeight(ushort depth) { ushort baseDepth = LegoData.CalibrationData.baseCenterDepth; if (depth > baseDepth - 3) { return(0); } if (baseDepth - 3 >= depth && depth > baseDepth - 13) { return(1); } if (baseDepth - 13 >= depth && depth > baseDepth - 23) { return(2); } if (baseDepth - 23 >= depth && depth > baseDepth - 33) { return(3); } if (baseDepth - 33 >= depth && depth > baseDepth - 42) { return(4); } return(5); } #endregion }