/// <summary> /// Paints all objects from the ROIList into the HALCON window /// </summary> /// <param name="window">HALCON window</param> public void PaintData(HWindow window) { window.SetDraw("margin"); window.SetLineWidth(1); if (ROIList.Count > 0) { window.SetColor(InactiveCol); //window.SetDraw("margin"); for (int i = 0; i < ROIList.Count; i++) { if (ActiveROIidx != i) { //显示ROI window.SetLineStyle(ROIList[i].flagLineStyle); ROIList[i].Draw(window); //显示序号 if (RoiDrawConfig.IsDrawIndex) { ROI roi = ROIList[i]; var point = roi.GetCenter(); double row = point.Y + RoiDrawConfig.PaneWidth; double column = point.X + RoiDrawConfig.PaneWidth; HOperatorSet.SetTposition(window, row, column); HOperatorSet.WriteString(window, i.ToString()); } } } if (ActiveROIidx != -1) { //显示选中的ROI window.SetColor(ActiveCol); window.SetLineStyle(ROIList[ActiveROIidx].flagLineStyle); ROIList[ActiveROIidx].Draw(window); //显示选中的ROI序号 if (RoiDrawConfig.IsDrawIndex) { ROI roi = ROIList[ActiveROIidx]; var point = roi.GetCenter(); var row = point.Y + RoiDrawConfig.PaneWidth; var column = point.X + RoiDrawConfig.PaneWidth; HOperatorSet.SetTposition(window, row, column); HOperatorSet.WriteString(window, ActiveROIidx.ToString()); } //显示选中的小方框 window.SetColor(ActiveHdlCol); ROIList[ActiveROIidx].DisplayActive(window); } } }
/// <summary> /// Reaction of ROI objects to the 'mouse button down' event: changing /// the shape of the ROI and adding it to the ROIList if it is a 'seed' /// ROI. /// </summary> /// <param name="imgX">x coordinate of mouse event</param> /// <param name="imgY">y coordinate of mouse event</param> /// <returns></returns> public int MouseDownAction(double imgX, double imgY) { int idxROI = -1; double max = 10000, dist; //maximal shortest distance to one of //the handles //选中范围=ROI方格中心线长 double epsilon = RoiDrawConfig.PaneWidth * Math.Sqrt(2); //选中范围缩小到10,并按缩放比例自动调整,最低Math.Sqrt(15) //if (epsilon < Math.Sqrt(15)) epsilon = Math.Sqrt(15); if (ROI != null) //either a new ROI object is created { ROI.CreateROI(imgX, imgY); ROIList.Add(ROI); ROI = null; ActiveROIidx = ROIList.Count - 1; viewController.Repaint(); } else if (ROIList.Count > 0) // ... or an existing one is manipulated { //判断是否点击已被选中的ROI if (ActiveROIidx != -1) { dist = ROIList[ActiveROIidx].DistToClosestHandle(imgX, imgY); if ((dist < max) && (dist < epsilon)) { return(ActiveROIidx); } } //扫描全部,改为倒序扫描 ActiveROIidx = -1; //for (int i = 0; i < ROIList.Count; i++) for (int i = ROIList.Count - 1; i >= 0; i--) { dist = ROIList[i].DistToClosestHandle(imgX, imgY); if ((dist < max) && (dist < epsilon)) { max = dist; idxROI = i; } }//end of for if (idxROI >= 0) { ActiveROIidx = idxROI; } viewController.Repaint(); } return(ActiveROIidx); }
/// <summary> /// To create a new ROI object the application class initializes a /// 'seed' ROI instance and passes it to the ROIController. /// The ROIController now responds by manipulating this new ROI /// instance. /// </summary> /// <param name="r"> /// 'Seed' ROI object forwarded by the application forms class. /// </param> public void SetROIShape(ROI r) { ROI = r; ROI.OperatorFlag = MODE_ROI_NONE; }
/// <summary> /// Deletes this ROI instance if a 'seed' ROI object has been passed /// to the ROIController by the application class. /// /// </summary> public void ResetROI() { ActiveROIidx = -1; ROI = null; }
/// <summary> /// Clears all variables managing ROI objects /// </summary> public void Reset() { ROIList.Clear(); ActiveROIidx = -1; ROI = null; }