394 {
395 PointD p = new PointD();
399 else
401 if (
App.viewer ==
null || currentTool ==
null ||
ImageView.SelectedImage ==
null || anno ==
null)
402 return;
404 if (currentTool.type == Tool.Type.point && buts == MouseButtons.Left)
405 {
408 an.type =
ROI.Type.Point;
410 ImageView.SelectedImage.Annotations.Add(an);
411 }
412 else
413 if (currentTool.type == Tool.Type.line && anno.type ==
ROI.Type.Line && buts == MouseButtons.Left)
414 {
416 {
419 }
420 }
421 else
422 if (currentTool.type == Tool.Type.rect && anno.type ==
ROI.Type.Rectangle && buts == MouseButtons.Left)
423 {
425 {
427 }
428 }
429 else
430 if (currentTool.type == Tool.Type.ellipse && anno.type ==
ROI.Type.Ellipse && buts == MouseButtons.Left)
431 {
433 {
435 }
436 }
437 else
438 if (currentTool.type == Tool.Type.freeform && anno.type ==
ROI.Type.Freeform && buts == MouseButtons.Left)
439 {
441 }
442 else
443 if (currentTool.type == Tool.Type.rectSel && buts == MouseButtons.Left)
444 {
446 RectangleD r = GetTool(Tool.Type.rectSel).Rectangle;
447 foreach (
ROI an
in App.viewer.AnnotationsRGB)
448 {
450 {
451 an.selectedPoints.Clear();
453 an.selected = true;
455 for (int i = 0; i < sels.Length; i++)
456 {
457 if (sels[i].IntersectsWith(r))
458 {
459 an.selectedPoints.Add(i);
460 }
461 }
462 }
463 else
464 an.selected = false;
465 }
466 Tools.GetTool(
Tools.
Tool.Type.rectSel).Rectangle =
new RectangleD(0, 0, 0, 0);
467 }
468 else
469 if (
Tools.currentTool.type ==
Tools.
Tool.Type.magic && buts == MouseButtons.Left)
470 {
473
475 if (r.Width <= 2 || r.Height <= 2)
476 return;
477 Bitmap bf =
ImageView.SelectedImage.Buffers[
ImageView.SelectedImage.Coords[coord.Z, coord.C, coord.T]].GetCropBuffer(r);
478 Statistics[] sts = Statistics.FromBytes(bf);
479 Statistics st = sts[0];
480 Threshold th;
481 if (magicSel.Numeric)
482 {
483 th = new Threshold((int)magicSel.Threshold);
484 }
485 else
486 if (magicSel.Index == 2)
487 th = new Threshold((int)(st.Min + st.Mean));
488 else
489 if (magicSel.Index == 1)
490 th = new Threshold((int)st.Median);
491 else
492 th = new Threshold(st.Min);
493 th.ApplyInPlace((Bitmap)bf.Image);
494 Invert inv = new Invert();
495 Bitmap det;
496 if (bf.BitsPerPixel > 8)
497 det = AForge.Imaging.Image.Convert16bppTo8bpp((Bitmap)bf.Image);
498 else
499 det = (Bitmap)bf.Image;
500 BlobCounter blobCounter = new BlobCounter();
501 blobCounter.ProcessImage(det);
502 Blob[] blobs = blobCounter.GetObjectsInformation();
503
504 GrahamConvexHull hullFinder = new GrahamConvexHull();
505
506
507 foreach (Blob blob in blobs)
508 {
509 if (blob.Rectangle.Width < magicSel.Max && blob.Rectangle.Height < magicSel.Max)
510 continue;
511 List<IntPoint> leftPoints = new List<IntPoint>();
512 List<IntPoint> rightPoints = new List<IntPoint>();
513 List<IntPoint> edgePoints = new List<IntPoint>();
514 List<IntPoint> hull = new List<IntPoint>();
515
516 blobCounter.GetBlobsLeftAndRightEdges(blob,
517 out leftPoints, out rightPoints);
518 edgePoints.AddRange(leftPoints);
519 edgePoints.AddRange(rightPoints);
520
521 hull = hullFinder.FindHull(edgePoints);
522 PointD[] pfs = new PointD[hull.Count];
523 for (int i = 0; i < hull.Count; i++)
524 {
525 pfs[i] = new PointD(r.X + hull[i].X, r.Y + hull[i].Y);
526 }
528 ImageView.SelectedImage.Annotations.Add(an);
529 }
530 }
531 else
532 if (
Tools.currentTool.type ==
Tools.
Tool.Type.bucket && buts == MouseButtons.Left)
533 {
535 floodFiller.FillColor = DrawColor;
536 floodFiller.Tolerance = currentTool.tolerance;
537 floodFiller.Bitmap =
ImageView.SelectedImage.Buffers[
ImageView.SelectedImage.Coords[coord.C, coord.Z, coord.T]];
538 floodFiller.FloodFill(new AForge.Point((int)p.X, (int)p.Y));
540 }
541 else
542 if (
Tools.currentTool.type ==
Tools.
Tool.Type.dropper && buts == MouseButtons.Left)
543 {
544 DrawColor =
ImageView.SelectedBuffer.GetPixel((
int)p.X, (
int)p.Y);
545 UpdateGUI();
546 }
547 UpdateOverlay();
548 }
static ROI CreateFreeform(ZCT coord, PointD[] pts)
static State GetUp(PointD pf, MouseButtons mb)