public override void Initial() { base.Initial(); rects = new RectObject[4]; Vector2Int[][] posRect = new Vector2Int[4][]; for (int i = 0; i < 4; i++) { posRect[i] = new Vector2Int[2]; } posRect[0][0] = new Vector2Int(2 + posStartX, 1 + posStartY); posRect[0][1] = new Vector2Int(0 + posStartX, 2 + posStartY); posRect[1][0] = new Vector2Int(1 + posStartX, 1 + posStartY); posRect[1][1] = new Vector2Int(0 + posStartX, 1 + posStartY); posRect[2][0] = new Vector2Int(1 + posStartX, 0 + posStartY); posRect[2][1] = new Vector2Int(1 + posStartX, 1 + posStartY); posRect[3][0] = new Vector2Int(0 + posStartX, 0 + posStartY); posRect[3][1] = new Vector2Int(1 + posStartX, 0 + posStartY); for (int i = 0; i < 4; i++) { rects[i] = PoolManager.Instance.RectObjPop(SpriteName); rects[i].PosList = posRect[i]; rects[i].Initial(); } }
private IEnumerable <TextObject> GetCommonNameTexts(PlantInfo plantInfo, RectObject labelRect) { var yPos = GetCommonNameYPositon(labelRect.Height, _config.CommonFontY, _config.OffsetFromTop); if (plantInfo.CommonName.Length < _config.CommonCharLengthThreshhold) { return(new [] { CreateTextObject(plantInfo.CommonName, labelRect, _config.OffsetFromLeft, yPos, _config.CommonFontY, _config.CommonFontName) }); } if (plantInfo.CommonName.Contains(" ")) { var segs = plantInfo.CommonName.Split(' '); var firstLine = segs[0]; var secondLine = segs.Skip(1).Aggregate((i, j) => i + " " + j); return(new [] { CreateTextObject(firstLine, labelRect, _config.OffsetFromLeft, yPos, _config.CommonFontY, _config.CommonFontName), CreateTextObject(secondLine, labelRect, _config.OffsetFromLeft, yPos - _config.CommonFontY - _config.CommonNameLineSpacing, _config.CommonFontY, _config.CommonFontName), }); } return(new [] { CreateTextObject(plantInfo.CommonName, labelRect, _config.OffsetFromLeft, yPos, _config.CommonFontY * .9, _config.CommonFontName) }); }
public RectObject RectObjPop(string name) { RectObject obj; if (poolRectObject[name].Count == 0) { obj = new RectObject(name); } else { obj = poolRectObject[name].Pop(); } return(obj); }
private void rect_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.OriginalSource is Canvas) { Canvas can = (Canvas)e.OriginalSource; var mousePos = e.GetPosition(MainCanvas); obj = new RectObject(); double left = mousePos.X - (can.ActualWidth / 2); double top = mousePos.Y - (can.ActualHeight / 2); obj.RectObjectOld(can, top, left); _isRectDragInProg = true; can.CaptureMouse(); } }
private TextObject CreateTextObject(string text, RectObject labelRect, double x, double y, double fontHeight, string font) { var textObj = new TextObject() { Font = font, Text = text, }; textObj.FontHeight = fontHeight; textObj.Position = new Point() { Y = y, X = x }; return(textObj); }
private IEnumerable <TextObject> GetScientificNameTexts(PlantInfo plantInfo, RectObject labelRect) { if (plantInfo.ScientificName.Length < _config.ScientificCharLengthThreshhold) { var scientificNameText = CreateTextObject(plantInfo.ScientificName, labelRect, _config.OffsetFromLeft, labelRect.Height / 3.5, _config.ScientificFontY, _config.ScientificFontName); return(new [] { scientificNameText }); } var segs = plantInfo.ScientificName.Split(' '); var firstLine = segs[0]; var secondLine = segs.Skip(1).Aggregate((i, j) => i + " " + j); return(new [] { CreateTextObject(firstLine, labelRect, _config.OffsetFromLeft, labelRect.Height / 3.5, _config.ScientificFontY, _config.ScientificFontName), CreateTextObject(secondLine, labelRect, _config.OffsetFromLeft, labelRect.Height / 3.5 - _config.ScientificFontY - _config.ScientificNameLineSpacing, _config.ScientificFontY, _config.ScientificFontName), }); }
public MainWindow() { InitializeComponent(); Context wrapper = Context.getInstance(); wrapper.mw = this; this.DataContext = wrapper.ct; LoginForm win = new LoginForm(); //otvara prvo login Table.DataContext = wrapper.ct; TableNode.DataContext = wrapper.ct; TableTerminals.DataContext = wrapper.ct; TableLines.DataContext = wrapper.ct; obj = new RectObject(); win.ShowDialog(); }
static void SuperimposeGT(string image_folder) { string[] image_files = System.IO.Directory.GetFiles(image_folder, "*.jpg"); for (int i = 0; i < image_files.Length; i++) { string image_file = image_files[i]; string xml_file = image_file.Replace(@"\Image\", @"\GT\").Replace(".jpg", "_data.xml"); if (System.IO.File.Exists(xml_file)) { iPhotoDrawAnnotation annotation = new iPhotoDrawAnnotation(); annotation.LoadRectObjects(xml_file); Mat image = new Emgu.CV.Mat(image_file, Emgu.CV.CvEnum.LoadImageType.Color); for (int j = 0; j < annotation.RectObjects.Count; j++) { RectObject rect_object = annotation.RectObjects[j]; MCvScalar scalar = rect_object.Name.StartsWith("panel") ? new MCvScalar(0, 0, 255): new MCvScalar(255, 0, 0); CvInvoke.Rectangle(image, rect_object.Rect, scalar); } CvInvoke.Imwrite(System.IO.Path.GetFileName(image_file), image); } } }
public void RectObjPush(string name, RectObject obj) { poolRectObject[name].Push(obj); }
static void LabelStatistics(string gt_folder) { string[] gt_files = System.IO.Directory.GetFiles(gt_folder, "*_data.xml"); List <int> widths = new List <int>(), heights = new List <int>(); for (int i = 0; i < gt_files.Length; i++) { string xml_file = gt_files[i]; iPhotoDrawAnnotation annotation = new iPhotoDrawAnnotation(); annotation.LoadRectObjects(xml_file); for (int j = 0; j < annotation.RectObjects.Count; j++) { RectObject rect_object = annotation.RectObjects[j]; string name = rect_object.Name; if (!name.StartsWith("label")) { continue; } if (name.Length > "label a".Length) { continue; } widths.Add(rect_object.Rect.Width); heights.Add(rect_object.Rect.Height); } } double mean_width = 0, mean_height = 0, mean_aspect_ratio = 0; int max_width = int.MinValue, max_height = int.MinValue, min_width = int.MaxValue, min_height = int.MaxValue; double min_aspect_ration = double.MaxValue, max_aspect_ratio = double.MinValue; for (int i = 0; i < widths.Count; i++) { int width = widths[i], height = heights[i]; double aspect_ratio = (double)width / (double)height; mean_width += width; mean_height += height; mean_aspect_ratio += aspect_ratio; if (width > max_width) { max_width = width; } if (width < min_width) { min_width = width; } if (height > max_height) { max_height = height; } if (height < min_height) { min_height = height; } if (aspect_ratio > max_aspect_ratio) { max_aspect_ratio = aspect_ratio; } if (aspect_ratio < min_aspect_ration) { min_aspect_ration = aspect_ratio; } } mean_width /= widths.Count; mean_height /= heights.Count; mean_aspect_ratio /= widths.Count; using (System.IO.StreamWriter sw = new System.IO.StreamWriter("LabelStatistics.txt")) { sw.WriteLine("Min Width {0}\tMax Width {1}\tMean Width {2}", min_width, max_width, mean_width); sw.WriteLine("Min Height {0}\tMax Height {1}\tMean Height {2}", min_height, max_height, mean_height); sw.WriteLine("Min Aspect Ratio {0}\tMax Aspect Ratio {1}\tMean Aspect Ratio {2}", min_aspect_ration, max_aspect_ratio, mean_aspect_ratio); for (int i = 0; i < widths.Count; i++) { sw.WriteLine("{0}\t{1}", widths[i], heights[i]); } } }
private void InitRect() { int cols = 20; int rows = 20; int size = 10; AStar astar = new AStar(); Framework.Grid grid = new Framework.Grid(GridType.DIRECTION_4); astar.grid = grid; grid.InitGrid(rows, cols); byte[][] gridData = new byte[rows][]; rectObjects = new List <RectObject>(); for (int x = 0; x < cols; x++) { gridData[x] = new byte[cols]; for (int y = 0; y < rows; y++) { gridData[x][y] = (byte)(Random.Range(0f, 1f) > 0.25f ? 0 : 1); RectObject rectObject = new RectObject(); rectObject.x = x; rectObject.y = y; rectObject.transform.SetParent(GameObject.Find("RectMap").transform, false); rectObject.transform.rotation = Quaternion.Euler(90f, 0, 0); rectObject.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f); rectObject.transform.localPosition = new Vector3(x * size, 0, y * size); rectObject.renderer.color = new Color(rectObject.renderer.color.r, rectObject.renderer.color.g, rectObject.renderer.color.b, 0.2f); rectObjects.Add(rectObject); } } grid.InitGridData(gridData); while (true) { int index = MathUtil.RandomRangeInt(0, rectObjects.Count - 1); RectObject rectObject = rectObjects[index]; Node node = grid.GetNode(rectObject.x, rectObject.y); if (node.moveable) { grid.SetStartNode(node.x, node.y); break; } } { RectObject rectObject = rectObjects[MathUtil.RandomRangeInt(0, rectObjects.Count - 1)]; grid.SetEndNode(rectObject.x, rectObject.y); } List <Node> path = astar.Find(grid.startNode.x, grid.startNode.y, grid.endNode.x, grid.endNode.y); if (path != null) { Debug.Log("开始寻路:"); foreach (Node node in path) { Debug.Log(node.x + "," + node.y); } } else { Debug.Log("路径为空:"); } }