예제 #1
0
        protected override void OnMouseUp(MouseEventArgs e)
        {
            base.OnMouseUp(e);
            if ((action_status == ActionMode.Add || action_status == ActionMode.RangeQuery || action_status == ActionMode.WindowQuery) && is_draggin)
            {
                PointF prevPos = ConvertCoordFromScreen(mouse_down_pos.X, mouse_down_pos.Y);
                PointF curPos  = ConvertCoordFromScreen(current_mouse_pos.X, current_mouse_pos.Y);

                Point pPos = new Point((int)prevPos.X, (int)prevPos.Y);
                Point cPos = new Point((int)curPos.X, (int)curPos.Y);

                RectangleObj newRectangle = new RectangleObj();
                newRectangle.SetRectangleByCoords(pPos, cPos);

                if (action_status == ActionMode.RangeQuery)
                {
                    int rad = Math.Max(newRectangle.rect_height, newRectangle.rect_width);
                    newRectangle.UpdateWH(rad, rad);
                }

                newRectangle.rect_color       = Color.FromArgb(rnd.Next(256), rnd.Next(256), rnd.Next(256));
                newRectangle.importance_layer = -1;

                OnRectangleAdded(newRectangle);

                is_draggin = false;
                RedrawCanvas();
            }
            else if (action_status == ActionMode.PointQuery || action_status == ActionMode.Remove || action_status == ActionMode.IncrementalNN)
            {
                PointF curPos = ConvertCoordFromScreen(e.Location.X, e.Location.Y);
                OnPointQueryRequested(new Point((int)curPos.X, (int)curPos.Y));
                if (action_status == ActionMode.IncrementalNN)
                {
                    incrementalSet = true;
                    incrementalPos = e.Location;
                }
                else
                {
                    incrementalSet = false;
                }
            }
            else if (action_status == ActionMode.Move)
            {
                is_draggin = false;
                OnPointQueryRequested(new Point(-1, -1));
                RedrawCanvas();
            }
        }
예제 #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (canvas_size < 0)
            {
                return;
            }

            int numRects = Convert.ToInt32(tbNumRects.Text);
            int randSeed = Convert.ToInt32(tbRandSeed.Text);

            Random rand = new Random(randSeed);

            List <RectangleObj> rects = new List <RectangleObj>();

            for (int i = 0; i < numRects; i++)
            {
                int          x1   = rand.Next(1, canvas_size);
                int          y1   = rand.Next(1, canvas_size);
                int          x2   = rand.Next(1, canvas_size);
                int          y2   = rand.Next(1, canvas_size);
                RectangleObj rect = new RectangleObj();
                rect.SetRectangleByCoords(new Point(x1, y1), new Point(x2, y2));
                rect.importance_layer = Convert.ToInt32(tbImportance.Text);
                rect.rect_color       = Color.FromArgb(rand.Next(256), rand.Next(256), rand.Next(256));
                rects.Add(rect);
            }

            Stopwatch watch = Stopwatch.StartNew();

            if (type_partition)
            {
                rect_database_partition.AddManyRectangles(rects);
            }
            else
            {
                rect_database_cover.AddManyRectangles(rects);
            }
            watch.Stop();
            tbStopwatch.Text = watch.ElapsedMilliseconds.ToString();

            UpdateCanvasBounds();
        }
예제 #3
0
        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            if (all_layer_bounds.Count < 1)
            {
                return;
            }

            foreach (LayerBounds bound in all_layer_bounds)
            {
                int   colval    = ((bound.layerNum) * 220) / num_layers;
                int   pen_width = Math.Max(1, 5 - bound.layerNum);
                Brush br        = new SolidBrush(Color.FromArgb(colval, colval, colval));
                Pen   pen       = new Pen(br, pen_width);

                PointF p1 = ConvertCoordToScreen(bound.bounds.X, bound.bounds.Y);
                PointF p2 = ConvertCoordToScreen(bound.bounds.Width, bound.bounds.Height);

                e.Graphics.DrawRectangle(pen, p1.X, p1.Y, p2.X, p2.Y);
            }

            if (is_draggin && action_status != ActionMode.Move)
            {
                Brush br = new SolidBrush(Color.Black);

                PointF prevPos = ConvertCoordFromScreen(mouse_down_pos.X, mouse_down_pos.Y);
                PointF curPos  = ConvertCoordFromScreen(current_mouse_pos.X, current_mouse_pos.Y);

                Point pPos = new Point((int)prevPos.X, (int)prevPos.Y);
                Point cPos = new Point((int)curPos.X, (int)curPos.Y);

                RectangleObj newRectangle = new RectangleObj();
                newRectangle.SetRectangleByCoords(pPos, cPos);
                if (action_status == ActionMode.RangeQuery)
                {
                    int rad = Math.Max(newRectangle.rect_width, newRectangle.rect_height);
                    newRectangle.UpdateWH(rad, rad);
                }

                prevPos = ConvertCoordToScreen(newRectangle.min_extent_X, newRectangle.min_extent_Y);
                curPos  = ConvertCoordToScreen(newRectangle.rect_width, newRectangle.rect_height);
                if (action_status == ActionMode.Add || action_status == ActionMode.WindowQuery)
                {
                    e.Graphics.DrawRectangle(new Pen(br), prevPos.X, prevPos.Y, curPos.X, curPos.Y);
                }
                else if (action_status == ActionMode.RangeQuery)
                {
                    e.Graphics.DrawEllipse(new Pen(br), prevPos.X, prevPos.Y, curPos.X, curPos.Y);
                }
            }
            if (rects_to_draw != null && rects_to_draw.Count > 0)
            {
                foreach (RectangleObj rect in rects_to_draw)
                {
                    Brush  br           = new SolidBrush(rect.rect_color);
                    PointF corner_coord = ConvertCoordToScreen(rect.min_extent_X, rect.min_extent_Y);
                    PointF wh_extent    = ConvertCoordToScreen(rect.rect_width, rect.rect_height);
                    e.Graphics.FillRectangle(br, corner_coord.X, corner_coord.Y, wh_extent.X, wh_extent.Y);
                }
            }
            if (hollow_rects_to_draw.Count > 0)
            {
                foreach (RectangleObj rect in hollow_rects_to_draw)
                {
                    Brush  br           = new SolidBrush(Color.Red);
                    PointF corner_coord = ConvertCoordToScreen(rect.min_extent_X, rect.min_extent_Y);
                    PointF wh_extent    = ConvertCoordToScreen(rect.rect_width, rect.rect_height);
                    Pen    pen          = new Pen(br, 3);
                    e.Graphics.DrawRectangle(pen, corner_coord.X, corner_coord.Y, wh_extent.X, wh_extent.Y);
                    pen.Dispose();
                }
            }
            if (incrementalSet)
            {
                Brush br = new SolidBrush(Color.Orange);
                e.Graphics.FillRectangle(br, incrementalPos.X, incrementalPos.Y, 5, 5);
            }
            if (hollow_circles.Count > 0)
            {
                foreach (RectangleObj rect in hollow_circles)
                {
                    PointF corner_coord = ConvertCoordToScreen(rect.min_extent_X, rect.min_extent_Y);
                    PointF wh_extent    = ConvertCoordToScreen(rect.rect_width, rect.rect_height);
                    Brush  br           = new SolidBrush(rect.rect_color);
                    Pen    pen          = new Pen(br, 2);
                    e.Graphics.DrawEllipse(pen, corner_coord.X, corner_coord.Y, wh_extent.X, wh_extent.Y);
                    pen.Dispose();
                }
            }
        }