Exemplo n.º 1
0
        public void GenerateWL()
        {
            if (histo_data == null || histo_data.HistogramData == null)
            {
                return;
            }

            WL_BMP = new Bitmap(histo_width, histo_height);
            Graphics gp = Graphics.FromImage(WL_BMP);

            Point p      = HisLUT.GetCminCmax(histo_data.windowCenter, histo_data.windowWidth);
            int   curMin = GetValuePosition(p.X);
            int   curMax = GetValuePosition(p.Y);

            int maxX = WL_BMP.Width - 1;

            if (curMin < 0)
            {
                curMin = 0;
            }
            else if (curMin > maxX)
            {
                curMin = maxX;
            }

            if (curMax < 0)
            {
                curMax = 0;
            }
            else if (curMax > maxX)
            {
                curMax = maxX;
            }
            if (curMax < curMin)
            {
                curMax = curMin;
            }
            Pen   WL_pen       = new Pen(WL_Color);
            Point p_left_down  = new Point(curMin, WL_BMP.Height);
            Point p_left_up    = new Point(curMin, 0);
            Point p_right_down = new Point(curMax, WL_BMP.Height);
            Point p_right_up   = new Point(curMax, 0);
            Point p_mid_up     = new Point((curMin + curMax) / 2, 0);
            Point p_mid_down   = new Point((curMin + curMax) / 2, WL_BMP.Height);

            gp.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            gp.DrawLine(WL_pen, p_left_down, p_left_up);
            gp.DrawLine(WL_pen, p_left_down, p_right_up);
            gp.DrawLine(WL_pen, p_right_down, p_right_up);
            gp.DrawLine(WL_pen, p_mid_up, p_mid_down);
            gp.Dispose();
        }
Exemplo n.º 2
0
        public void MouseDown(PictureBox picturebox, MouseEventArgs e)
        {
            if (histo_data == null || histo_data.HistogramData == null)
            {
                return;
            }

            Point p = new Point(e.X - startPoint_ref.X, e.Y - startPoint_ref.Y);

            if (p.Y > histo_height)
            {
                return;
            }

            Point p_minMax = HisLUT.GetCminCmax(histo_data.windowCenter, histo_data.windowWidth);
            int   curMin   = GetValuePosition(p_minMax.X);
            int   curMax   = GetValuePosition(p_minMax.Y);

            if (Math.Abs(p.X - curMin) < 5 && p.Y < histo_height)
            {
                breakPoint.Y = 1;
            }
            else if (((p.X - curMin) > 5) && ((curMax - p.X) > 5) && p.Y < histo_height)
            {
                breakPoint.Y = 2;
            }
            else if (Math.Abs(p.X - curMax) < 5 && p.Y < histo_height)
            {
                breakPoint.Y = 3;
            }
            else
            {
                breakPoint.Y = 0;
            }
            breakPoint.X = p.X;
        }
Exemplo n.º 3
0
        public void MouseMove(PictureBox picturebox, MouseEventArgs e)
        {
            if (histo_data == null || histo_data.HistogramData == null)
            {
                return;
            }

            Point p = new Point(e.X - startPoint_ref.X, e.Y - startPoint_ref.Y);

            if (p.Y > histo_height)
            {
                return;
            }

            Point p_minMax = HisLUT.GetCminCmax(histo_data.windowCenter, histo_data.windowWidth);
            int   curMin   = GetValuePosition(p_minMax.X);
            int   curMax   = GetValuePosition(p_minMax.Y);

            int error = 3;

            if (e.Button != MouseButtons.Left)
            {
                if (Math.Abs(p.X - curMin) < error && p.Y < histo_height)
                {
                    picturebox.Cursor = Cursors.SizeWE;
                }
                else if (Math.Abs(p.X - curMax) < error && p.Y < histo_height)
                {
                    picturebox.Cursor = Cursors.SizeWE;//TCursor.curRight;
                }
                else if (((p.X - curMin) >= error) && ((curMax - p.X) >= error) && p.Y < histo_height)
                {
                    picturebox.Cursor = Cursors.Hand;
                }
                else
                {
                    picturebox.Cursor = Cursors.Default;
                }
            }
            else if (breakPoint.Y != 0 && Math.Abs(p.X - breakPoint.X) > 5 && p.Y < histo_height)
            {
                int oldMinInHist = curMin;
                int oldMaxInHist = curMax;

                if (breakPoint.Y == 1)
                {
                    curMin       = p.X;
                    breakPoint.X = p.X;
                }
                else if (breakPoint.Y == 3)
                {
                    curMax       = e.X;
                    breakPoint.X = p.X;
                }
                else if (breakPoint.Y == 2)
                {
                    curMax += (p.X - breakPoint.X);   //加上偏移量
                    curMin += (p.X - breakPoint.X);
                    if (curMin < 0 && p.X < (0 + curMax) / 2)
                    {
                        curMax -= (0 - curMin);
                    }
                    if (curMax > histo_width && p.X > (curMin + histo_width - 0 - 1) / 2)
                    {
                        curMin += (curMax - histo_width);
                    }
                    breakPoint.X = p.X;
                }

                if (Math.Abs(oldMinInHist - curMin) < 1 && Math.Abs(oldMaxInHist - curMax) < 1)
                {
                    return;
                }

                int minV = GetPositionValue(curMin);
                int maxV = GetPositionValue(curMax);
                if (minV > maxV)
                {
                    int temp = maxV;
                    maxV = minV;
                    minV = temp;
                }
                histo_data.SetCenterWindow((maxV - minV) / 2 + minV, maxV - minV);
                picturebox.Image = new Bitmap(histo_width, histo_height);
                Graphics g = Graphics.FromImage(picturebox.Image);
                GenerateWL();
                g.DrawImage(backBMP, new Point(0, 0));
                g.DrawImage(WL_BMP, new Point(0, 0));
                picturebox.Refresh();



                //hist1.RefreshLUT();
                //if (LUTChanged != null)
                //{
                //    LUTChanged(0, new Point(hist1.windowCenter, hist1.windowWidth), hist1.LUT);
                //}
            }
        }