432 {
433 PointD p = new PointD();
435 return;
436 p = ImageView.SelectedImage.isPyramidal ? e :
ImageView.SelectedImage.ToImageSpace(e);
437 PointD roiPoint = GetAnnotationPoint(e);
438 if (
App.viewer ==
null || currentTool ==
null ||
ImageView.SelectedImage ==
null || anno ==
null)
439 return;
441 if (currentTool.type == Tool.Type.point && buts == MouseButtons.Left)
442 {
443 ROI an = new ROI();
444 an.AddPoint(roiPoint);
445 an.type = ROI.Type.Point;
447 ImageView.SelectedImage.Annotations.Add(an);
448 }
449 else
450 if (currentTool.type == Tool.Type.line && anno.type == ROI.Type.Line && buts == MouseButtons.Left)
451 {
452 if (anno.GetPointCount() > 0)
453 {
454 anno.UpdatePoint(roiPoint, 1);
455 anno.UpdateBoundingBox();
456 RefreshRoiManager();
457 anno = new ROI();
458 }
459 }
460 else
461 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle && buts == MouseButtons.Left)
462 {
463 currentTool.Rectangle = new RectangleD(0, 0, 0, 0);
464 anno = new ROI();
465 rectStart = new PointD();
466 }
467 else
468 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse && buts == MouseButtons.Left)
469 {
470 currentTool.Rectangle = new RectangleD(0, 0, 0, 0);
471 anno = new ROI();
472 rectStart = new PointD();
473 }
474 else
475 if (currentTool.type == Tool.Type.freeform && anno.type == ROI.Type.Freeform && buts == MouseButtons.Left)
476 {
477 anno.closed = true;
478 anno.UpdateBoundingBox();
479 RefreshRoiManager();
480 anno = new ROI();
481 }
482 else
483 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left)
484 {
487 RectangleD r = GetTool(Tool.Type.rectSel).Rectangle;
488 double hitSize =
App.viewer.GetSelectionBoxHitSize();
489 foreach (ROI an
in App.viewer.AnnotationsRGB)
490 {
491 if (an.GetSelectBound(hitSize, hitSize).ToRectangleF().IntersectsWith(r.ToRectangleF()))
492 {
494 an.selectedPoints.Clear();
496 an.Selected = true;
497 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
498 for (int i = 0; i < sels.Length; i++)
499 {
500 if (sels[i].IntersectsWith(r))
501 {
502 an.selectedPoints.Add(i);
503 }
504 }
505 }
506 else
507 an.Selected = false;
508 }
509 Tools.GetTool(
Tools.
Tool.Type.rectSel).Rectangle =
new RectangleD(0, 0, 0, 0);
510 }
511 else
512 if (
Tools.currentTool.type ==
Tools.
Tool.Type.magic && buts == MouseButtons.Left)
513 {
515 AForge.RectangleF rr =
ImageView.SelectedImage.ToImageSpace(r);
517 Bitmap bf;
518 if (
ImageView.SelectedImage.Buffers[0].RGBChannelsCount > 1)
520 else
522 bf.Crop(rr.ToRectangleInt());
523 Statistics[] sts = Statistics.FromBytes(bf);
524 Statistics st = sts[0];
525 int th = 0;
526 if (magicSel.Numeric)
527 {
528 th = magicSel.Threshold;
529 }
530 else
531 if (magicSel.Index == 2)
532 th = (int)(st.Min + st.Mean);
533 else
534 if (magicSel.Index == 1)
535 th = (int)st.Median;
536 else
537 th = (int)st.Min;
538 Bitmap det;
539 if (bf.BitsPerPixel > 8)
540 {
541 bf.To8Bit();
542 det = bf;
543
544 }
545 else
546 {
547
548 det = bf;
549 }
550 BlobCounter blobCounter = new BlobCounter(det);
551 blobCounter.FilterBlobs = true;
552 blobCounter.MinWidth = 2;
553 blobCounter.MinHeight = 2;
554 blobCounter.CoupledSizeFiltering = true;
555 Blob[] blobs = blobCounter.GetObjects(det, true);
556 double px =
ImageView.SelectedImage.PhysicalSizeX;
557 double py =
ImageView.SelectedImage.PhysicalSizeY;
558 foreach (Blob blob in blobs)
559 {
560 AForge.RectangleD rd = new RectangleD(blob.Rectangle.X * px, blob.Rectangle.Y * py, blob.Rectangle.Width * px, blob.Rectangle.Height * py);
561 PointD loc = new PointD(r.X + rd.X, r.Y + rd.Y);
562 ROI an = ROI.CreateRectangle(coord, loc.X, loc.Y, rd.W, rd.H);
563 ImageView.SelectedImage.Annotations.Add(an);
564 }
565 }
566 else
567 if (
Tools.currentTool.type ==
Tools.
Tool.Type.bucket && buts == MouseButtons.Left)
568 {
570 floodFiller.FillColor = DrawColor;
571 floodFiller.Tolerance = currentTool.tolerance;
572 floodFiller.Bitmap =
ImageView.SelectedImage.Buffers[
ImageView.SelectedImage.Coords[coord.C, coord.Z, coord.T]];
573 floodFiller.FloodFill(new AForge.Point((int)p.X, (int)p.Y));
575 }
576 else
577 if (
Tools.currentTool.type ==
Tools.
Tool.Type.dropper && buts == MouseButtons.Left)
578 {
579 DrawColor =
ImageView.SelectedBuffer.GetPixel((
int)p.X, (
int)p.Y);
580 UpdateGUI();
581 }
582 UpdateOverlay();
583 }
static State GetUp(PointD pf, MouseButtons mb)