Esempio n. 1
0
        /// <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);
        }