From 93142cce74a061ea1dc6ad17ba4b7e4e34f4d1d8 Mon Sep 17 00:00:00 2001 From: lingutln Date: Wed, 11 Jan 2012 23:14:15 +0000 Subject: [PATCH] Independent segment enabling functionality. Done by Nikhil. svn path=/; revision=261 --- .../dcu/apps/ist/views/SegmentationView.java | 46 +-------------- .../ist/widgets/AnnotatedImageControl.java | 57 ++++++++++++++++++- .../ie/dcu/segment/SegmentationContext.java | 27 +++++++-- .../src/ie/dcu/segment/SegmentationMask.java | 21 +++++-- .../dcu/segment/painters/CombinedPainter.java | 39 +++++++++---- 5 files changed, 123 insertions(+), 67 deletions(-) diff --git a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java index 40392d5..af34230 100644 --- a/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java +++ b/Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java @@ -11,7 +11,6 @@ import ie.dcu.segment.options.SegmenterOptionDialog; import ie.dcu.segment.painters.SegmentationPainter; import ie.dcu.swt.*; import ie.dcu.swt.event.*; -import ie.dcu.apps.ist.dialogs.PopUpLabelDialog; import java.lang.reflect.InvocationTargetException; import java.net.*; @@ -134,7 +133,6 @@ public class SegmentationView extends Composite { init(); } - /** * Initialize. */ @@ -456,7 +454,7 @@ public class SegmentationView extends Composite { Tool.Foreground.action.setEnabled(false); Tool.Background.action.setEnabled(false); view.removeContextChangeListener(eventHandler); - view.getImageControl().getCanvas().addMouseListener(popupListener); + view.addPopupListener(); if(!(view.getTool() == null)) { view.getTool().detach(); @@ -464,7 +462,7 @@ public class SegmentationView extends Composite { } else { - view.getImageControl().getCanvas().removeMouseListener(popupListener); + view.removePopupListener(); view.addContextChangeListener(eventHandler); view.getTool().attach(view.getImageControl()); } @@ -1041,45 +1039,7 @@ public class SegmentationView extends Composite { } }; - private final MouseListener popupListener = new MouseListener() { - - public void mouseUp(MouseEvent event) { - // For the right click - if(event.button == 3) - { - PopUpLabelDialog dialog = new PopUpLabelDialog(getShell()); - PopUpLabelDialog.Result result = dialog.open(); - if (result != null) - { - String lab = null; - if(result.comboText.indexOf('{') != -1) - { - lab = result.comboText.substring(0,result.comboText.indexOf('{')-1); - } - else - { - lab = result.comboText; - } - System.out.println("selected"+lab); - comboLabel.setText(result.comboText); - execute(Tool.AssignButton, null); - } - } - else if(event.button == 1) - { - System.out.println("Mask number "+view.getContext().getMasks().size()); - //view.highlightClickedSegment(event.x,event.y); - repaint(); - } - } - public void mouseDown(MouseEvent e) - { - } - public void mouseDoubleClick(MouseEvent e) - { - } - - }; + /** * Class that prevents segmentation algorithms crashing the application diff --git a/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java b/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java index e366a11..3a8df39 100644 --- a/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java +++ b/Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java @@ -2,6 +2,7 @@ package ie.dcu.apps.ist.widgets; import ie.dcu.apps.ist.controllers.AnnotationTool; +import ie.dcu.apps.ist.dialogs.PopUpLabelDialog; import ie.dcu.apps.ist.event.*; import ie.dcu.apps.ist.views.SegmentationView; import ie.dcu.segment.SegmentationContext; @@ -301,6 +302,13 @@ public class AnnotatedImageControl extends Composite { listeners.remove(listener); } + public void addPopupListener() { + view.getCanvas().addMouseListener(popupListener); + } + + public void removePopupListener() { + view.getCanvas().removeMouseListener(popupListener); + } private void fireContextChanged(SegmentationContext old) { ContextChangedEvent e = null; @@ -313,11 +321,11 @@ public class AnnotatedImageControl extends Composite { } /** - * For highlighting the mouse clicked segment in Labelling Mode. + * For Enabling the mouse clicked segment in Labelling Mode. * @param Mosue clicked points x,y */ - public void highlightClickedSegment(int x, int y) { - ctx.highlightClickedSegment(x,y); + public void enableClickedSegment(Point mouseClickedPoint) { + ctx.enableClickedSegment(mouseClickedPoint); } @@ -399,6 +407,49 @@ public class AnnotatedImageControl extends Composite { } }; + private final MouseListener popupListener = new MouseListener() { + + public void mouseUp(MouseEvent event) { + Point mouseClickedPoint = new Point(event.x,event.y); + // For the right click + if(event.button == 3) + { + PopUpLabelDialog dialog = new PopUpLabelDialog(getShell()); + PopUpLabelDialog.Result result = dialog.open(); + if (result != null) + { + String lab = null; + if(result.comboText.indexOf('{') != -1) + { + lab = result.comboText.substring(0,result.comboText.indexOf('{')-1); + } + else + { + lab = result.comboText; + } + System.out.println("selected"+lab); + //comboLabel.setText(result.comboText); + //execute(Tool.AssignButton, null); + } + } + else if(event.button == 1) + { + if(view.imageContains(mouseClickedPoint)) + { + ctx.enableClickedSegment(view.canvasToImage(mouseClickedPoint)); + } + repaint(); + } + } + public void mouseDown(MouseEvent e) + { + } + public void mouseDoubleClick(MouseEvent e) + { + } + + }; + /** * Listens for annotations and updates the buffer and view accordingly. */ diff --git a/Annotation/src/ie/dcu/segment/SegmentationContext.java b/Annotation/src/ie/dcu/segment/SegmentationContext.java index 85e2ed7..d5a5b0e 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationContext.java +++ b/Annotation/src/ie/dcu/segment/SegmentationContext.java @@ -141,6 +141,10 @@ public class SegmentationContext { } public final void formSegmentationObject() { + // Makes needsHighlighting False for all the previous segments. + disableAllSegments(false); + // Set needsHighlighting True for the current segment. + segmentationMask.enabled = true; segmentationMaskObjects.add(segmentationMask); // Making a new segmentationObject after storing the current SegmentationObject @@ -168,19 +172,30 @@ public class SegmentationContext { return segmentationMaskObjects; } + /** * For highlighting the clicked segmentObject * @param x, mouse clicked point x * @param y, mouse clicked point y */ - public void highlightClickedSegment(int x, int y) { - mouseClickedPoint.x = x; - mouseClickedPoint.y = y; + public void enableClickedSegment(Point mouseClickedPoint) { + + for(SegmentationMask segmentMaskObject : segmentationMaskObjects) + { + if(segmentMaskObject.getPixel(mouseClickedPoint.x, mouseClickedPoint.y) == 1) + { + // Disable all previous segments + disableAllSegments(false); + // Enable the currently clicked segment. + segmentMaskObject.enabled = true; + } + } } - - public Point getMouseClickedPoint() + + public void disableAllSegments(boolean value) { - return mouseClickedPoint; + for(SegmentationMask maskObject : segmentationMaskObjects) + maskObject.enabled = value; } /** diff --git a/Annotation/src/ie/dcu/segment/SegmentationMask.java b/Annotation/src/ie/dcu/segment/SegmentationMask.java index 28211a9..7252996 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationMask.java +++ b/Annotation/src/ie/dcu/segment/SegmentationMask.java @@ -48,7 +48,21 @@ public class SegmentationMask extends ByteMatrix{ */ public final int width; + /** + * The total number of layers formed. + */ + public static int numberOfLayers; + + /** + * The layering number of the segmentation mask. + */ + public int layerNumber; + /** + * Whether the segment needs to be enabled(highlighted) or not ? + */ + public boolean enabled; + /** * The height of the segmentation mask. */ @@ -67,6 +81,8 @@ public class SegmentationMask extends ByteMatrix{ super(height, width); this.width = width; this.height = height; + this.layerNumber = ++numberOfLayers; + this.enabled = false; clear(); } @@ -90,11 +106,6 @@ public class SegmentationMask extends ByteMatrix{ fill(UNKNOWN); } - /** - * forms a segmentation object and stores it in an arrayList - */ - - /** * Get the offset of pixel (x, y). * diff --git a/Annotation/src/ie/dcu/segment/painters/CombinedPainter.java b/Annotation/src/ie/dcu/segment/painters/CombinedPainter.java index 11c51a6..f64b743 100644 --- a/Annotation/src/ie/dcu/segment/painters/CombinedPainter.java +++ b/Annotation/src/ie/dcu/segment/painters/CombinedPainter.java @@ -38,19 +38,16 @@ public class CombinedPainter implements SegmentationPainter { // Paint image gc.drawImage(ctx.getImage(), 0, 0); - Point mouseClickedPoint = ctx.getMouseClickedPoint(); - - // Paint masks + // Paint all masks skipping the enabled mask. if(ctx.getMasks().size() > 0) { - // For drawing all the previous masks. + // For drawing all the disabled masks. for(SegmentationMask mask : ctx.getMasks()) { - // Blending of background pixel values while pasting the last mask only - if(ctx.getMasks().indexOf(mask) == ctx.getMasks().size()-1) + // Skipping the enabled segment from painting. We will paint the enabled segment at last. + if(mask.enabled == true) { - createVisibleMask(mask,true); - gc.drawImage(maskImage, 0, 0); + continue; } else { @@ -62,6 +59,21 @@ public class CombinedPainter implements SegmentationPainter { createVisibleMask(ctx.getMask(),false); gc.drawImage(maskImage, 0, 0); } + // Painting the enabled mask. + if(ctx.getMasks().size() > 0) + { + // For drawing all the previous masks. + for(SegmentationMask mask : ctx.getMasks()) + { + // Blending of background pixel values while pasting the last mask only + if(mask.enabled == true) + { + createVisibleMask(mask,true); + gc.drawImage(maskImage, 0, 0); + } + } + } + // Very initial mask, which has not yet been turned into an object. else { createVisibleMask(ctx.getMask(),true); @@ -74,11 +86,18 @@ public class CombinedPainter implements SegmentationPainter { // Commit changes im.endPaint(); } - - + /** + * + * @param mask + * Mask object to be drawn. + * @param isFirstObject + * If set to True will blend the background and fore ground pixels. + */ private void createVisibleMask(SegmentationMask mask,boolean isFirstObject) { + dispose(); + if (isNewMaskDataRequired(mask.getBounds())) { maskData = createMaskData(mask.getBounds()); } -- 2.34.1