Esempio n. 1
0
        private void handleKeyUpOnAnnotatorTab(KeyEventArgs e)
        {
            if (centroidMode == CentroidMode.Rotating && e.KeyCode == Keys.ControlKey)
            {
                centroidMode = CentroidMode.None;
                tempoPolygonPoints = new List<PointF>();
            }

            if (centroidMode == CentroidMode.Zooming && e.KeyCode == Keys.ShiftKey)
            {
                centroidMode = CentroidMode.None;
                tempoPolygonPoints = new List<PointF>();
            }

            invalidatePictureBoard();
        }
Esempio n. 2
0
        private void pictureBoard_MouseUp(object sender, MouseEventArgs e)
        {
            if (currentSession == null)
                return;

            // These two lines should be together
            if (videoReader == null && depthReader == null) return;
            calculateLinear();

            if (drawingButtonSelected[rectangleDrawing] && drawingNewRectangle)
            {
                var boundingBox = (boundingBoxLocationMark.getScaledLocationMark(scale, translation) as RectangleLocationMark).boundingBox;
                var endPoint = e.Location;

                boundingBoxLocationMark = new RectangleLocationMark(-1, getRectangleFromStartAndEndPoint(startPoint.Value.scalePoint(scale, translation), endPoint)).
                    getScaledLocationMark(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale)) as RectangleLocationMark;

                boundingBox = boundingBoxLocationMark.boundingBox;
                if (drawingNewRectangle && boundingBox != null && boundingBox.Width > 0 && boundingBox.Height > 0)
                    newObjectContextPanel.Visible = true;
                else
                    newObjectContextPanel.Visible = false;
                drawingNewRectangle = false;
            }

            if (drawingButtonSelected[rectangleDrawing] || (selectedObject != null && selectedObject is RectangleObject))
            {
                if (draggingSelectBoxes)
                {
                    draggingSelectBoxes = false;
                }
            }

            if (drawingButtonSelected[polygonDrawing] ||   // Drawing mode 
                (selectedObject != null && selectedObject is PolygonObject)) // Editing mode
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left && videoReader != null)
                {
                    if (editingPolygon)
                    {
                        // ----------------------------------
                        // ---- Handle dragging select boxes
                        // If mouse up release selected box
                        if (draggingSelectBoxes)
                        {
                            draggingSelectBoxes = false;
                            invalidatePictureBoard();
                            return;
                        }

                        // ----------------------------------
                        // ---- Handle when release hold of centroid
                        // Turn centroid mode to None
                        if (centroidMode == CentroidMode.Dragging || centroidMode == CentroidMode.Rotating || centroidMode == CentroidMode.Zooming)
                        {
                            centroidMode = CentroidMode.None;
                            invalidatePictureBoard();
                            return;
                        }
                    }
                }
            }
        }
Esempio n. 3
0
        private void handleKeyDownOnAnnotatorTab(KeyEventArgs e)
        {
            // While editing a polygon
            if (selectedObject != null && selectedObject is PolygonObject && editingAtAFrame)
            {
                calculateLinear();

                // While dragging a select box, and user press delete, handle delete that polygon point
                if (draggingSelectBoxes && e.KeyCode == Keys.Delete)
                {
                    polygonPointsLocationMark.boundingPolygon.RemoveAt(draggingSelectBoxIndex);
                    selectBoxes.RemoveAt(draggingSelectBoxIndex);
                    draggingSelectBoxes = false;
                }

                if (e.KeyCode == Keys.Insert)
                {
                    this.Cursor = Cursors.Cross;
                    addPolygonPoint = true;
                }

                if (centroidMode == CentroidMode.Dragging && e.KeyCode == Keys.ControlKey)
                {
                    centroidMode = CentroidMode.Rotating;
                    tempoPolygonPoints.AddRange(polygonPointsLocationMark.boundingPolygon.Select(value => value.scalePoint(scale, translation)));
                }

                if (centroidMode == CentroidMode.Dragging && e.KeyCode == Keys.ShiftKey)
                {
                    centroidMode = CentroidMode.Zooming;
                    tempoPolygonPoints.AddRange(polygonPointsLocationMark.boundingPolygon.Select(value => value.scalePoint(scale, translation)));
                }

                invalidatePictureBoard();
            }
        }
Esempio n. 4
0
        //Start drawing selection rectangle
        private void pictureBoard_MouseDown(object sender, MouseEventArgs e)
        {
            if (currentSession == null) return;

            // These two lines should be together
            if (videoReader == null && depthReader == null) return;
            calculateLinear();

            if (drawingButtonSelected[zoomDrawing])
            {
                whenZoomButtonAndMouseDown(e);
            }

            if (drawingButtonSelected[rectangleDrawing] ||
                (selectedObject != null && selectedObject is RectangleObject))
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left && videoReader != null)
                {
                    // If mouse down click on resize select boxes
                    if (selectBoxes != null && selectBoxes.Count != 0)
                    {
                        for (int i = 0; i < selectBoxes.Count; i++)
                        {
                            RectangleF r = selectBoxes[i];
                            if (r.Contains(e.Location))
                            {
                                draggingSelectBoxes = true;
                                draggingSelectBoxIndex = i;
                                return;
                            }
                        }
                    }


                    if (drawingButtonSelected[rectangleDrawing])
                    {
                        ////set selection point for a new rectangle
                        drawingNewRectangle = true;
                        var scaledPointerLocation = e.Location.scalePoint(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale));
                        startPoint = scaledPointerLocation;
                        boundingBoxLocationMark = new RectangleLocationMark(-1, new RectangleF(scaledPointerLocation, new SizeF()));
                        return;
                    }

                    // Only allow editing the current rectangle when you edit the rectangle object at a frame
                    if (editingAtAFrame)
                    {
                        return;
                    }
                }
            }

            if (drawingButtonSelected[polygonDrawing] ||   // Drawing mode 
                (selectedObject != null && selectedObject is PolygonObject)) // Editing mode
            {
                if (e.Button == System.Windows.Forms.MouseButtons.Left && videoReader != null)
                {
                    List<PointF> polygonPoints = polygonPointsLocationMark.boundingPolygon;
                    var scaledPointerLocation = e.Location.scalePoint(1 / scale, new PointF(-translation.X / scale, -translation.Y / scale));

                    if (editingPolygon)
                    {
                        if (!draggingSelectBoxes)
                        {
                            if (selectBoxes != null && selectBoxes.Count != 0)
                            {
                                for (int i = 0; i < selectBoxes.Count; i++)
                                {
                                    RectangleF r = selectBoxes[i];
                                    if (r.Contains(e.Location))
                                    {
                                        draggingSelectBoxes = true;
                                        draggingSelectBoxIndex = i;
                                        return;
                                    }
                                }
                            }
                        }

                        if (centroidMode == CentroidMode.None && !centroid.Equals(new Point()))
                        {
                            RectangleF r = new RectangleF(centroid.X - centroidRadius, centroid.Y - centroidRadius, 2 * centroidRadius, 2 * centroidRadius);
                            if (r.Contains(e.Location))
                            {
                                centroidMode = CentroidMode.Dragging;
                                invalidatePictureBoard();
                                return;
                            }
                        }


                        if (addPolygonPoint)
                        {
                            double minDistance = double.MaxValue;
                            int minPos = -1;

                            for (int i = 0; i < polygonPoints.Count; i++)
                            {
                                double distance = Math.Pow(polygonPoints[i].X - scaledPointerLocation.X, 2) + Math.Pow(polygonPoints[i].Y - scaledPointerLocation.Y, 2);
                                if (minDistance > distance)
                                {
                                    minDistance = distance;
                                    minPos = i;
                                }
                            }

                            draggingSelectBoxIndex = minPos + 1;
                            polygonPoints.Insert(draggingSelectBoxIndex, scaledPointerLocation);
                            selectBoxes.Insert(draggingSelectBoxIndex, new Rectangle(e.Location.X - (boxSize - 1) / 2, e.Location.Y - (boxSize - 1) / 2, boxSize, boxSize));

                            // Recalculate centroid
                            calculateCentroid();

                            draggingSelectBoxes = true;
                            addPolygonPoint = false;

                            this.Cursor = Cursors.Default;
                            invalidatePictureBoard();
                            return;
                        }
                    }
                    else
                    {
                        if (drawingButtonSelected[polygonDrawing])
                        {
                            drawingNewPolygon = true;
                            polygonPoints.Add(scaledPointerLocation);
                            return;
                        }
                    }
                }

                // Allow edit the polygon just have been drawn
                // Right click after drawing polygon
                if (e.Button == System.Windows.Forms.MouseButtons.Right && videoReader != null && drawingNewPolygon)
                {
                    drawingNewPolygon = false;
                    editingPolygon = true;
                    temporaryPoint = null;
                    newObjectContextPanel.Visible = true;
                    selectBoxes = (polygonPointsLocationMark.getScaledLocationMark(scale, translation) as PolygonLocationMark2D).getCornerSelectBoxes(boxSize);
                    calculateCentroid();

                    invalidatePictureBoard();
                    return;
                }

                // Only allow editing the current polygon when you edit the polygon object at a frame
                if (editingAtAFrame)
                {
                    return;
                }
            }

            if (e.Button == System.Windows.Forms.MouseButtons.Left)
            {
                whenCursorButtonAndMouseDown(e);
            }
        }