Hello!

To see the file structure, click on "tree".

Note that updates take place every 10 minutes, commits may not be seen immediately.
Independent segment enabling functionality. Done by Nikhil.
authorlingutln <lingutln@localhost>
Wed, 11 Jan 2012 23:14:15 +0000 (23:14 +0000)
committerlingutln <lingutln@localhost>
Wed, 11 Jan 2012 23:14:15 +0000 (23:14 +0000)
svn path=/; revision=261

Annotation/src/ie/dcu/apps/ist/views/SegmentationView.java
Annotation/src/ie/dcu/apps/ist/widgets/AnnotatedImageControl.java
Annotation/src/ie/dcu/segment/SegmentationContext.java
Annotation/src/ie/dcu/segment/SegmentationMask.java
Annotation/src/ie/dcu/segment/painters/CombinedPainter.java

index 40392d5d41cf2d89bea2cc35e099cfade859d90f..af34230d4307140f6dac0f9caa145973a7874e63 100644 (file)
@@ -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
index e366a1121c83c805f935b2631924ba8ad77b5758..3a8df3980b9d9a517ee7f9f3d702448a33bf98b5 100644 (file)
@@ -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.
         */
index 85e2ed793afca15def82d16e69a13fc2351f2a0e..d5a5b0e57ca20cae0d3927273bc9c8d91a89e7e1 100644 (file)
@@ -141,6 +141,10 @@ public class SegmentationContext {
        }
        
        public final void formSegmentationObject() {
+               // Makes needsHighlighting <code>False</code> for all the previous segments.
+               disableAllSegments(false);
+               // Set needsHighlighting <code>True</code> 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;
        }
        
        /**
index 28211a90e7d2cd2c8395f0fbc70bbc8c08672a6d..7252996158f2264457f5c8980fb3c40a786622d5 100644 (file)
@@ -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).
         * 
index 11c51a6d472f8b7d055d7e1233fc2766ab0fd7cf..f64b7431f78443202d9b58efbe9cdb76e40f155f 100644 (file)
@@ -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 <code>True</code> will blend the background and fore ground pixels.
+        */
        private void createVisibleMask(SegmentationMask mask,boolean isFirstObject) {
+               
                dispose();
+               
                if (isNewMaskDataRequired(mask.getBounds())) {
                        maskData = createMaskData(mask.getBounds());
                }