Exemple #1
0
        /// <summary>
        /// Adds annotation that requires no control points.
        /// There can be only one of those annotations per annotation name.
        /// </summary>
        /// <param name="annotationName"></param>
        public void AddSimpleAnnotation(string annotationName)
        {
            Annotation ann = AnnotationFactory.Create(annotationName);

            foreach (Annotation ann2 in PictureBox.Annotations)
            {
                if (ann2.GetType() == ann.GetType())
                {
                    return; // This annotation is already visible, do not add a second one.
                }
            }

            PictureBox.Annotations.Add(ann);
            Refresh();
        }
Exemple #2
0
        private void buttonActivateAnnotationClick(object sender, EventArgs e)
        {
            string annotationName = ((ToolStripButton)sender).Name;

            if (AnnotationFactory.Create(annotationName).RequiredPointCount > 0)
            {
                PictureViewer.NewAnnotationName = annotationName;
                PictureViewer.Mode = Pi2PictureViewer.MouseMode.AddAnnotation;
            }
            else
            {
                PictureViewer.AddSimpleAnnotation(annotationName);
            }

            UpdateToolButtons();
        }
Exemple #3
0
        private void PictureBox_MouseDown(object sender, MouseEventArgs e)
        {
            if ((Mode == MouseMode.Pan && e.Button == MouseButtons.Left) ||
                (e.Button == MouseButtons.Middle))
            {
                // Start panning the image
                PanStartMousePosition   = e.Location;
                PanStartPicturePosition = PictureBox.PicturePosition;
            }
            else if ((Mode == MouseMode.Pick || Mode == MouseMode.Erase) &&
                     e.Button == MouseButtons.Left &&
                     ActiveAnnotation == null)
            {
                // Pick and activate annotation and possibly also control point

                var result = PictureBox.FindAnnotation(e.Location);

                if (result != null)
                {
                    if (Mode == MouseMode.Pick)
                    {
                        ActiveAnnotation   = result.Item1;
                        ActiveControlPoint = result.Item2;

                        oldControlPointLocations.Clear();
                        oldControlPointLocations.AddRange(ActiveAnnotation.ControlPoints);

                        controlPointSelectLocation = new Vec3(PictureBox.ScreenToPicture(new Vec2(e.Location)), PictureBox.Slice);
                    }
                    else
                    {
                        // Erase annotation
                        PictureBox.Annotations.Remove(result.Item1);
                        Refresh();
                    }
                }
            }
            else if ((Mode == MouseMode.AddAnnotation || Mode == MouseMode.Profile) &&
                     e.Button == MouseButtons.Left &&
                     ActiveAnnotation == null)
            {
                if (Mode == MouseMode.Profile)
                {
                    NewAnnotationName = "Line segment";
                    EraseProfileAnnotation();
                }

                // Add new annotation object
                if (!String.IsNullOrEmpty(NewAnnotationName))
                {
                    ActiveAnnotation = AnnotationFactory.Create(NewAnnotationName);
                    PictureBox.Annotations.Add(ActiveAnnotation);
                    Vec3 pos = new Vec3(PictureBox.ScreenToPicture(new Vec2(e.Location)), PictureBox.Slice);
                    ActiveAnnotation.ControlPoints.Add(pos);
                    ActiveControlPoint = 0;

                    // Add another control point right away if multiple points are required.
                    if (ActiveAnnotation.RequiredPointCount > 1)
                    {
                        ActiveAnnotation.ControlPoints.Add(pos);
                        ActiveControlPoint = 1;
                    }

                    Refresh();

                    if (Mode != MouseMode.Profile)
                    {
                        if (ToolStrip != null)
                        {
                            ToolStrip.ResetAnnotation();
                        }
                    }
                }

                if (Mode == MouseMode.Profile)
                {
                    ProfileAnnotation = ActiveAnnotation;
                    UpdateProfile();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        public Pi2PictureToolStrip()
        {
            InitializeComponent();

            Histogram = new HistogramDialog(null);

            ImageScalingSize = new Size(20, 20);

            ToolStripButton buttonZoomOut = new ToolStripButton(String.Empty, Resources.zoom_out_multi_size.ToBitmap(), buttonZoomOutClick);

            buttonZoomOut.ToolTipText = "Zoom out" + Environment.NewLine + "Alternatively use Control + mouse wheel to zoom.";
            Items.Add(buttonZoomOut);

            labelZoom             = new ToolStripLabel("100 %");
            labelZoom.ToolTipText = "Current zoom level." + Environment.NewLine + "Use Control + mouse wheel or toolbar buttons to zoom.";;
            Items.Add(labelZoom);

            ToolStripButton buttonZoomIn = new ToolStripButton(String.Empty, Resources.zoom_in_multi_size.ToBitmap(), buttonZoomInClick);

            buttonZoomIn.ToolTipText = "Zoom in" + Environment.NewLine + "Alternatively use Control + mouse wheel to zoom.";
            Items.Add(buttonZoomIn);

            ToolStripButton buttonZoomFit = new ToolStripButton(String.Empty, Resources.zoom_to_fit.ToBitmap(), buttonZoomFitClick);

            buttonZoomFit.ToolTipText = "Zoom such that the whole image fits into the window.";
            Items.Add(buttonZoomFit);

            ToolStripButton buttonZoomFull = new ToolStripButton(String.Empty, Resources.zoom_100.ToBitmap(), buttonZoomFullClick);

            buttonZoomFull.ToolTipText = "Zooms such that one screen pixel equals one image pixel.";
            Items.Add(buttonZoomFull);


            Items.Add(new ToolStripSeparator());

            buttonHistogram             = new ToolStripButton(String.Empty, Resources.bar_chart_5_multi_size.ToBitmap(), buttonHistogramClick);
            buttonHistogram.ToolTipText = "Show histogram";
            Items.Add(buttonHistogram);

            ToolStripButton buttonAutoContrast = new ToolStripButton(String.Empty, Resources.contrast_multi_size.ToBitmap(), buttonAutoContrastClick);

            buttonAutoContrast.ToolTipText = "Adjust contrast automatically";
            Items.Add(buttonAutoContrast);

            Items.Add(new ToolStripSeparator());

            buttonCross             = new ToolStripButton(String.Empty, Resources.cursor_multi_size.ToBitmap(), buttonCrossClick);
            buttonCross.ToolTipText = "Move and adjust annotations.";
            Items.Add(buttonCross);

            buttonErase             = new ToolStripButton(String.Empty, Resources.erase_multi_size.ToBitmap(), buttonEraseClick);
            buttonErase.ToolTipText = "Erase annotations.";
            Items.Add(buttonErase);

            buttonHand             = new ToolStripButton(String.Empty, Resources.so_so_multi_size.ToBitmap(), buttonHandClick);
            buttonHand.ToolTipText = "Pan the image." + Environment.NewLine + "Alternatively, use the middle mouse button to pan the image.";
            Items.Add(buttonHand);

            buttonProfile             = new ToolStripButton(String.Empty, Resources.scatter_plot_multi_size.ToBitmap(), buttonProfileClick);
            buttonProfile.ToolTipText = "Plot a profile along a line.";
            Items.Add(buttonProfile);

            Items.Add(new ToolStripSeparator());

            buttonStickyAnnotationTools              = new ToolStripButton(String.Empty, Resources.magnet_multi_size.ToBitmap());
            buttonStickyAnnotationTools.ToolTipText  = "Activate this button to keep selected annotation tool active indefinitely." + Environment.NewLine + "Deactivate this button to automatically switch to Move and adjust tool after creation of an annotation.";
            buttonStickyAnnotationTools.CheckOnClick = true;
            Items.Add(buttonStickyAnnotationTools);

            Items.Add(new ToolStripSeparator());

            annotationButtons = new List <ToolStripButton>();
            List <string> annotations = AnnotationFactory.Names();

            foreach (string name in annotations)
            {
                ToolStripButton btn = new ToolStripButton(String.Empty, AnnotationFactory.GetIcon(name), buttonActivateAnnotationClick, name);
                btn.ToolTipText = "Create new " + name.ToLower() + " annotation.";
                Items.Add(btn);
                annotationButtons.Add(btn);
            }
        }