Пример #1
0
        internal void InitScrollBar()
        {
            if (!m_scrollbarInit)
            {
                MPR_UI_Interface.WriteLog("Initializing scroll bar");
                this.scrollBar.Maximum     = m_UIInterface.GetNumberOfImages((int)this.m_axis);
                this.scrollBar.Minimum     = 0;
                this.scrollBar.SmallChange = 1;
                this.scrollBar.LargeChange = 1;
                ScrollBarCurrentVal        = this.scrollBar.Value = m_UIInterface.GetCurrentImageIndex((int)this.m_axis);

                // Init scroll bar event
                this.scrollBar.ValueChanged += scrollBar_ValueChanged;


                // ORIENTATION MARKERS
                OrientationMarkerLeft   = m_UIInterface.GetOrientationMarkerLeft((int)this.m_axis);
                OrientationMarkerRight  = m_UIInterface.GetOrientationMarkerRight((int)this.m_axis);
                OrientationMarkerTop    = m_UIInterface.GetOrientationMarkerTop((int)this.m_axis);
                OrientationMarkerBottom = m_UIInterface.GetOrientationMarkerBottom((int)this.m_axis);

                this.m_UIInterface.RaiseSlicerPositionUpdate((int)this.m_axis);
                m_scrollbarInit = true;
            }
        }
Пример #2
0
        private void Handle_UpdateImage(BitmapWrapper bmpWrapper, int axis, double reslicerPositionX, double reslicerPositionY)
        {
            if (axis == (int)this.m_axis)
            {
                MPR_UI_Interface.WriteLog("Handling update image event.");
                this.m_imagePanel.StoreBitmap = bmpWrapper.StoredBitmap;
                //if(axis == (int)Axis.AxialAxis)
                //     this.m_UIInterface.GetCurrentSliceROI(axis,ref m_roiPoints, ref m_roiColor);
                Position = m_UIInterface.GetCurrentImagePosition((int)this.m_axis);
                Index    = m_UIInterface.GetCurrentImageIndex((int)this.m_axis);

                DosePosition = 0;  // m_UIInterface.GetCurrentDoseImagePosition((int)this.m_axis);
                DoseIndex    = -0; // m_UIInterface.GetCurrentDoseImageIndex((int)this.m_axis);

                //UpdateCursorPosition();
                PointF cursorPoint = new PointF((float)reslicerPositionX, (float)reslicerPositionY);
                switch (m_axis)
                {
                case Axis.AxialAxis:
                {
                    this.m_imagePanel.SetCursorPositionX_Axis(cursorPoint, Axis.SagittalAxis);
                    this.m_imagePanel.SetCursorPositionY_Axis(cursorPoint, Axis.CoronalAxis);
                }
                break;

                case Axis.SagittalAxis:
                {
                    this.m_imagePanel.SetCursorPositionX_Axis(cursorPoint, Axis.CoronalAxis);
                    this.m_imagePanel.SetCursorPositionY_Axis(cursorPoint, Axis.AxialAxis);
                }
                break;

                case Axis.CoronalAxis:
                {
                    this.m_imagePanel.SetCursorPositionX_Axis(cursorPoint, Axis.SagittalAxis);
                    this.m_imagePanel.SetCursorPositionY_Axis(cursorPoint, Axis.AxialAxis);
                }
                break;

                default:
                    break;
                }
            }
        }
Пример #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (StoreBitmap == null)
            {
                return;
            }
            MPR_UI_Interface.WriteLog("Handling paint event.");

            RectangleF srcRect = new RectangleF((e.ClipRectangle.X / currentZoomFactor) - currentDisplayOffsetPt.X,
                                                (e.ClipRectangle.Y / currentZoomFactor) - currentDisplayOffsetPt.Y,
                                                e.ClipRectangle.Width / currentZoomFactor, e.ClipRectangle.Height / currentZoomFactor);

            Rectangle roundedRectangle = Rectangle.Round(imageRect);

            e.Graphics.DrawRectangle(new Pen(Color.FromArgb(255, 0, 0)), roundedRectangle);
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;

            e.Graphics.DrawImage(StoreBitmap, e.ClipRectangle, srcRect, GraphicsUnit.Pixel);

            Point pet_p = new Point(0, 0);

            if (m_pet_storedBitmap != null)
            {
                ///step1: find the center of CT Image rect
                Point center_point_ct = new Point(roundedRectangle.Left + roundedRectangle.Width / 2,
                                                  roundedRectangle.Top + roundedRectangle.Height / 2);

                ///step2: calculate PT image display rect
                PointF ptDisplayPosition1 = new PointF(roundedRectangle.Left - PetPosition.X, roundedRectangle.Top - PetPosition.Y);

                Rectangle pt_rect = new Rectangle((int)(ptDisplayPosition1.X), (int)(ptDisplayPosition1.Y), (int)(m_pet_storedBitmap.Width * currentZoomFactor), (int)(m_pet_storedBitmap.Height * currentZoomFactor));

                /// find center point of PT image rect
                Point center_point_pt = new Point(pt_rect.Left + pt_rect.Width / 2,
                                                  pt_rect.Top + pt_rect.Height / 2);

                // step3: map center of CT and PT rect;
                // CT rect is fixed; PT rect is movable.
                Point displacement = new Point(center_point_ct.X - center_point_pt.X, center_point_ct.Y - center_point_pt.Y);

                /// step4: displace pt_rect
                pt_rect.Offset(displacement);


                //  e.Graphics.DrawRectangle(new Pen(Color.Blue), pt_rect);
                e.Graphics.DrawImage(this.m_pet_storedBitmap, pt_rect);

                using (Graphics gg = Graphics.FromImage(this.m_pet_storedBitmap))
                {
                }
            }



            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            Pen p = new Pen(Color.Gold, 10.0F);

            e.Graphics.FillPath(p.Brush, objectPath);

            Pen  _pen1 = new Pen(Color.LightGoldenrodYellow, 2.0F);
            Pen  _pen2 = new Pen(Color.ForestGreen, 2.0F);
            Font _font = new Font("Verdana", 10.0F);
            int  currY = 0;

            if (this.Parent.Parent.Name.CompareTo("ImageControl") == 0)
            {
                var imgControl = (ImageControl)this.Parent.Parent;
                int idx        = imgControl.GetScrollbarValue();

                StringBuilder _sb = new StringBuilder();
                _sb.Append("Scroll Pos#");
                _sb.Append(idx);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(10, currY));
                currY += 20;
                _sb.Clear();
                _sb.Append("CT Slicer Pos#");
                _sb.Append(imgControl.Position);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(10, currY));
                currY += 20;
                _sb.Clear();
                _sb.Append("PT Slicer Pos#");
                _sb.Append(imgControl.PetSlicerPosition);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(10, currY));
                currY += 20;

                _sb.Clear();
                _sb.Append("X:").Append(lastMousePosition.X).Append(" Y:").Append(lastMousePosition.Y).Append(" Val:").Append(imgControl.HU);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(10, currY));
                currY += 20;

                _sb.Clear();
                _sb.Append("X:").Append(imgControl.PET_MouseLocation.X).Append(" Y:").Append(imgControl.PET_MouseLocation.Y).Append(" Val:").Append(imgControl.SUV);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(10, currY));
                currY += 20;

                _sb.Clear();
                _sb.Append("Zoom#");
                _sb.Append(currentZoomFactor);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(10, currY));
            }

            if (cursorPosition != null)
            {
                cursorPath.Reset();
                cursorPath.AddEllipse(cursorPosition.X - 5.0F, cursorPosition.Y - 5.0F, 10.0F, 10.0F);
                cursorPath.CloseFigure();
                //  e.Graphics.FillPath(p.Brush, cursorPath);
            }

            // paint cursor
            if (this.m_mprCursor.l1 != null)
            {
                //e.Graphics.DrawLine(this.m_mprCursor.l1.DisplayPen,                    this.m_mprCursor.l1.P1.X, this.m_mprCursor.l1.P1.Y, this.m_mprCursor.l1.P2.X, this.m_mprCursor.l1.P2.Y);
            }
            if (this.m_mprCursor.l2 != null)
            {
                //     e.Graphics.DrawLine(this.m_mprCursor.l2.DisplayPen,                    this.m_mprCursor.l2.P1.X, this.m_mprCursor.l2.P1.Y, this.m_mprCursor.l2.P2.X, this.m_mprCursor.l2.P2.Y);
            }

            // paint side marker
            {
                var imgControl = (ImageControl)this.Parent.Parent;
                e.Graphics.DrawString(imgControl.OrientationMarkerLeft, _font, _pen2.Brush, new PointF(this.Width - 20, this.Height / 2));
                e.Graphics.DrawString(imgControl.OrientationMarkerRight, _font, _pen2.Brush, new PointF(0, this.Height / 2));
                e.Graphics.DrawString(imgControl.OrientationMarkerTop, _font, _pen2.Brush, new PointF(this.Width / 2, 0));
                e.Graphics.DrawString(imgControl.OrientationMarkerBottom, _font, _pen2.Brush, new PointF(this.Width / 2, this.Height - 20));
            }



            base.OnPaint(e);
        }
Пример #4
0
        protected override void OnPaint(PaintEventArgs e)
        {
            if (StoreBitmap == null)
            {
                return;
            }
            MPR_UI_Interface.WriteLog("Handling paint event.");

            RectangleF srcRect = new RectangleF((e.ClipRectangle.X / currentZoomFactor) - currentDisplayOffsetPt.X,
                                                (e.ClipRectangle.Y / currentZoomFactor) - currentDisplayOffsetPt.Y,
                                                e.ClipRectangle.Width / currentZoomFactor, e.ClipRectangle.Height / currentZoomFactor);

            Rectangle roundedRectangle = Rectangle.Round(imageRect);

            e.Graphics.DrawRectangle(new Pen(Color.FromArgb(255, 0, 0)), roundedRectangle);
            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;

            e.Graphics.DrawImage(StoreBitmap, e.ClipRectangle, srcRect, GraphicsUnit.Pixel);

            if (DoseBitmap != null)
            {
                PointF     doseDisplayPosition1 = this.GetActualDisplayPosition(DosePosition);
                RectangleF doseRect             = new RectangleF(doseDisplayPosition1, new SizeF(this.DoseBitmap.Width * this.currentZoomFactor,
                                                                                                 this.DoseBitmap.Height * this.currentZoomFactor));
#if DEBUG
                e.Graphics.DrawRectangle(new Pen(Color.Blue), doseDisplayPosition1.X, doseDisplayPosition1.Y, DoseBitmap.Width, DoseBitmap.Height);
#endif
                e.Graphics.DrawImage(this.DoseBitmap, doseRect);
            }

            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.SmoothingMode     = SmoothingMode.AntiAlias;
            Pen p = new Pen(Color.Gold, 10.0F);
            e.Graphics.FillPath(p.Brush, objectPath);



            Pen   _pen1   = new Pen(Color.LightGoldenrodYellow, 2.0F);
            Pen   _pen2   = new Pen(Color.ForestGreen, 2.0F);
            Font  _font   = new Font("Verdana", 10.0F);
            int   spacing = 2;
            int   currX   = spacing;
            int   currY   = 4 + spacing;
            SizeF sz      = new SizeF(0F, 0F);
            if (this.Parent.Parent.Parent.Parent.Name.CompareTo("ImageControl") == 0)
            {
                var imgControl = (ImageControl)this.Parent.Parent.Parent.Parent;
                int idx        = imgControl.GetScrollbarValue();

                StringBuilder _sb = new StringBuilder();
                _sb.Append("Scroll Pos#");
                _sb.Append(idx);
                sz = e.Graphics.MeasureString(_sb.ToString(), _font);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));
                currY = currY + (int)sz.Height + spacing;

                _sb.Clear();
                _sb.Append("Slicer Pos#");
                _sb.Append(imgControl.Position);
                sz = e.Graphics.MeasureString(_sb.ToString(), _font);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));
                currY = currY + (int)sz.Height + spacing;

                _sb.Clear();
                _sb.Append("Slicer idx#");
                _sb.Append(imgControl.Index);
                sz = e.Graphics.MeasureString(_sb.ToString(), _font);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));
                currY = currY + (int)sz.Height + spacing;

                _sb.Clear();
                _sb.Append("Dose idx#");
                _sb.Append(imgControl.DoseIndex);
                sz = e.Graphics.MeasureString(_sb.ToString(), _font);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));
                currY = currY + (int)sz.Height + spacing;

                _sb.Clear();
                _sb.Append("Dose Pos#");
                _sb.Append(imgControl.DosePosition);
                sz = e.Graphics.MeasureString(_sb.ToString(), _font);
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));
                currY = currY + (int)sz.Height + spacing;
            }

            // paint bottom left
            currY = this.Height - 10 - spacing;
            if (this.Parent.Parent.Parent.Parent.Name.CompareTo("ImageControl") == 0)
            {
                var imgControl = (ImageControl)this.Parent.Parent.Parent.Parent;

                StringBuilder _sb = new StringBuilder();
                _sb.Clear();
                _sb.Append("X: ").Append(lastMousePosition.X).Append("px Y:").Append(lastMousePosition.Y).Append(" px");;
                _sb.Append("/");
                _sb.Append("X: ").Append((int)(lastMousePosition.X * XPixelSpacing)).Append(" mm Y:").Append((int)(lastMousePosition.Y * YPixelSpacing)).Append(" mm");
                sz    = e.Graphics.MeasureString(_sb.ToString(), _font);
                currY = currY - (int)sz.Height;
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));

                _sb.Clear();
                _sb.Append("Value:").Append(PixelIntensity);
                sz    = e.Graphics.MeasureString(_sb.ToString(), _font);
                currY = currY - (int)sz.Height;
                e.Graphics.DrawString(_sb.ToString(), _font, _pen1.Brush, new PointF(currX, currY));
            }

            if (cursorPosition != null)
            {
                cursorPath.Reset();
                cursorPath.AddEllipse(cursorPosition.X - 5.0F, cursorPosition.Y - 5.0F, 10.0F, 10.0F);
                cursorPath.CloseFigure();
                e.Graphics.FillPath(p.Brush, cursorPath);
            }

            // paint cursor
            if (this.m_mprCursor.l1 != null && XAxisLine != null)
            {
                XAxisLine.Reset();
                XAxisLine.AddLine(this.m_mprCursor.l1.P1, this.m_mprCursor.l1.P2);
                XAxisLine.CloseFigure();
                e.Graphics.DrawPath(this.m_mprCursor.l1.DisplayPen, XAxisLine);
                //e.Graphics.DrawLine(this.m_mprCursor.l1.DisplayPen,                    this.m_mprCursor.l1.P1.X, this.m_mprCursor.l1.P1.Y, this.m_mprCursor.l1.P2.X, this.m_mprCursor.l1.P2.Y);
            }
            if (this.m_mprCursor.l2 != null && YAxisLine != null)
            {
                YAxisLine.Reset();
                YAxisLine.AddLine(this.m_mprCursor.l2.P1, this.m_mprCursor.l2.P2);
                YAxisLine.CloseFigure();
                e.Graphics.DrawPath(this.m_mprCursor.l2.DisplayPen, YAxisLine);
                //e.Graphics.DrawLine(this.m_mprCursor.l2.DisplayPen,                    this.m_mprCursor.l2.P1.X, this.m_mprCursor.l2.P1.Y, this.m_mprCursor.l2.P2.X, this.m_mprCursor.l2.P2.Y);
            }

            // paint side marker
            {
                var imgControl = (ImageControl)this.Parent.Parent.Parent.Parent;
                // draw on right-middle side of view
                e.Graphics.DrawString(imgControl.OrientationMarkerLeft, _font, _pen2.Brush, new PointF(this.Width - 20, this.Height / 2));
                // draw on left-middle side of view
                e.Graphics.DrawString(imgControl.OrientationMarkerRight, _font, _pen2.Brush, new PointF(0, this.Height / 2));
                // draw on top-middle side
                e.Graphics.DrawString(imgControl.OrientationMarkerTop, _font, _pen2.Brush, new PointF(this.Width / 2, 0));

                // draw on bottom-middle
                e.Graphics.DrawString(imgControl.OrientationMarkerBottom, _font, _pen2.Brush, new PointF(this.Width / 2, this.Height - 20));
            }
            Monitor.Enter(lockobj);
            try
            {
                var imgControl = (ImageControl)this.Parent.Parent.Parent.Parent;
                foreach (KeyValuePair <int, Dictionary <int, List <PointF> > > kvp in imgControl.RoiPoints)
                {
                    int   roiNumber = kvp.Key;
                    Color c         = imgControl.RoiColor.ContainsKey(kvp.Key) ? imgControl.RoiColor[kvp.Key]: Color.Red;

                    Pen pen;
                    pen = new Pen(c, 1.0F);
                    try
                    {
                        Dictionary <int, List <PointF> > lineSegments = kvp.Value;
                        GraphicsPath path  = new GraphicsPath();
                        int          count = 0;
                        foreach (KeyValuePair <int, List <PointF> > lineSegment in lineSegments)
                        {
                            count++;

                            List <PointF> points = lineSegment.Value as List <PointF>;
                            PointF[]      tr     = new PointF[points.Count];
                            for (int ptIdx = 0; ptIdx < points.Count; ptIdx++)
                            {
                                PointF p3  = new PointF((float)(points[ptIdx].X / XPixelSpacing), (float)(points[ptIdx].Y / YPixelSpacing));
                                PointF ppp = this.GetActualDisplayPosition(new Point((int)Math.Abs(p3.X), (int)Math.Abs(p3.Y)));
                                tr[ptIdx] = ppp;
                            }
                            if (points.Count > 1)
                            {
                                path.AddLines(tr);
                                path.StartFigure();
                            }
                        }
                        e.Graphics.DrawPath(pen, path);
                    }
                    catch (KeyNotFoundException ex)
                    {
                        MessageBox.Show("Exception occurred");
                    }
                }

                foreach (KeyValuePair <int, Dictionary <int, List <PointF> > > kvp in imgControl.DosePoints)
                {
                    int   roiNumber = kvp.Key;
                    Color c         = imgControl.DoseColor.ContainsKey(kvp.Key) ? imgControl.DoseColor[kvp.Key] : Color.Red;

                    Pen pen;
                    pen = new Pen(c, 1.0F);
                    try
                    {
                        Dictionary <int, List <PointF> > lineSegments = kvp.Value;
                        GraphicsPath path  = new GraphicsPath();
                        int          count = 0;
                        foreach (KeyValuePair <int, List <PointF> > lineSegment in lineSegments)
                        {
                            count++;

                            List <PointF> points = lineSegment.Value as List <PointF>;
                            PointF[]      tr     = new PointF[points.Count];
                            for (int ptIdx = 0; ptIdx < points.Count; ptIdx++)
                            {
                                PointF p3  = new PointF((float)(points[ptIdx].X / XPixelSpacing), (float)(points[ptIdx].Y / YPixelSpacing));
                                PointF ppp = this.GetActualDisplayPosition(new Point((int)Math.Abs(p3.X), (int)Math.Abs(p3.Y)));
                                tr[ptIdx] = ppp;
                            }
                            if (points.Count > 1)
                            {
                                path.AddLines(tr);
                                path.StartFigure();
                            }
                        }
                        e.Graphics.DrawPath(pen, path);
                    }
                    catch (KeyNotFoundException ex)
                    {
                        MessageBox.Show("Exception occurred");
                    }
                }
            }
            catch (KeyNotFoundException ex)
            {
                MessageBox.Show("Exception occurred");
            }
            Monitor.Exit(lockobj);
            base.OnPaint(e);
        }