395 {
396 PointD p = new PointD();
398 return;
399 p =
ImageView.SelectedImage.ToImageSpace(e);
400 if (
App.viewer ==
null || currentTool ==
null ||
ImageView.SelectedImage ==
null || anno ==
null)
401 return;
403 if (currentTool.type == Tool.Type.point && buts == MouseButtons.Left)
404 {
405 ROI an = new ROI();
406 an.AddPoint(new PointD(e.X, e.Y));
407 an.type = ROI.Type.Point;
409 ImageView.SelectedImage.Annotations.Add(an);
410 }
411 else
412 if (currentTool.type == Tool.Type.line && anno.type == ROI.Type.Line && buts == MouseButtons.Left)
413 {
414 if (anno.GetPointCount() > 0)
415 {
416 anno.UpdatePoint(new PointD(e.X, e.Y), 1);
417 anno = new ROI();
418 }
419 }
420 else
421 if (currentTool.type == Tool.Type.rect && anno.type == ROI.Type.Rectangle && buts == MouseButtons.Left)
422 {
423 if (anno.GetPointCount() == 4)
424 {
425 anno = new ROI();
426 }
427 }
428 else
429 if (currentTool.type == Tool.Type.ellipse && anno.type == ROI.Type.Ellipse && buts == MouseButtons.Left)
430 {
431 if (anno.GetPointCount() == 4)
432 {
433 anno = new ROI();
434 }
435 }
436 else
437 if (currentTool.type == Tool.Type.freeform && anno.type == ROI.Type.Freeform && buts == MouseButtons.Left)
438 {
439 anno = new ROI();
440 }
441 else
442 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left)
443 {
446 RectangleD r = GetTool(Tool.Type.rectSel).Rectangle;
447 foreach (ROI an
in App.viewer.AnnotationsRGB)
448 {
449 if (an.GetSelectBound(
App.viewer.
GetScale(),
App.viewer.
GetScale()).ToRectangleF().IntersectsWith(r.ToRectangleF()))
450 {
452 an.selectedPoints.Clear();
454 an.Selected = true;
455 RectangleD[] sels = an.GetSelectBoxes(selectBoxSize);
456 for (int i = 0; i < sels.Length; i++)
457 {
458 if (sels[i].IntersectsWith(r))
459 {
460 an.selectedPoints.Add(i);
461 }
462 }
463 }
464 else
465 an.Selected = false;
466 }
467 Tools.GetTool(
Tools.
Tool.Type.rectSel).Rectangle =
new RectangleD(0, 0, 0, 0);
468 }
469 else
470 if (
Tools.currentTool.type ==
Tools.
Tool.Type.magic && buts == MouseButtons.Left)
471 {
473 AForge.RectangleF rr =
ImageView.SelectedImage.ToImageSpace(r);
475 Bitmap bf;
476 if (
ImageView.SelectedImage.Buffers[0].RGBChannelsCount > 1)
478 else
480 bf.Crop(rr.ToRectangleInt());
481 Statistics[] sts = Statistics.FromBytes(bf);
482 Statistics st = sts[0];
483 int th = 0;
484 if (magicSel.Numeric)
485 {
486 th = magicSel.Threshold;
487 }
488 else
489 if (magicSel.Index == 2)
490 th = (int)(st.Min + st.Mean);
491 else
492 if (magicSel.Index == 1)
493 th = (int)st.Median;
494 else
495 th = (int)st.Min;
496 Bitmap det;
497 if (bf.BitsPerPixel > 8)
498 {
499 bf.To8Bit();
500 det = bf;
501
502 }
503 else
504 {
505
506 det = bf;
507 }
508 BlobCounter blobCounter = new BlobCounter(det);
509 blobCounter.FilterBlobs = true;
510 blobCounter.MinWidth = 2;
511 blobCounter.MinHeight = 2;
512 blobCounter.CoupledSizeFiltering = true;
513 Blob[] blobs = blobCounter.GetObjects(det, true);
514 double px =
ImageView.SelectedImage.PhysicalSizeX;
515 double py =
ImageView.SelectedImage.PhysicalSizeY;
516 foreach (Blob blob in blobs)
517 {
518 AForge.RectangleD rd = new RectangleD(blob.Rectangle.X * px, blob.Rectangle.Y * py, blob.Rectangle.Width * px, blob.Rectangle.Height * py);
519 PointD loc = new PointD(r.X + rd.X, r.Y + rd.Y);
520 ROI an = ROI.CreateRectangle(coord, loc.X, loc.Y, rd.W, rd.H);
521 ImageView.SelectedImage.Annotations.Add(an);
522 }
523 }
524 else
525 if (
Tools.currentTool.type ==
Tools.
Tool.Type.bucket && buts == MouseButtons.Left)
526 {
528 floodFiller.FillColor = DrawColor;
529 floodFiller.Tolerance = currentTool.tolerance;
530 floodFiller.Bitmap =
ImageView.SelectedImage.Buffers[
ImageView.SelectedImage.Coords[coord.C, coord.Z, coord.T]];
531 floodFiller.FloodFill(new AForge.Point((int)p.X, (int)p.Y));
533 }
534 else
535 if (
Tools.currentTool.type ==
Tools.
Tool.Type.dropper && buts == MouseButtons.Left)
536 {
537 DrawColor =
ImageView.SelectedBuffer.GetPixel((
int)p.X, (
int)p.Y);
538 UpdateGUI();
539 }
540 UpdateOverlay();
541 }
static State GetUp(PointD pf, MouseButtons mb)