From: lingutln Date: Thu, 26 Jan 2012 19:42:18 +0000 (+0000) Subject: Multi segment saving to imagemaps (partially done). Done by Nikhil. X-Git-Url: http://gitweb.planteome.org/?a=commitdiff_plain;h=b62dc85869aab43118c3f682be51a137304a7fcb;p=old-jaiswallab-svn%2F.git Multi segment saving to imagemaps (partially done). Done by Nikhil. svn path=/; revision=280 --- diff --git a/Annotation/src/ie/dcu/apps/ist/AppWindow.java b/Annotation/src/ie/dcu/apps/ist/AppWindow.java index 8694588..d157336 100644 --- a/Annotation/src/ie/dcu/apps/ist/AppWindow.java +++ b/Annotation/src/ie/dcu/apps/ist/AppWindow.java @@ -196,15 +196,10 @@ public class AppWindow extends ApplicationWindow implements FileDropListener { SegmentationContext ctx = getContext(); if (ctx != null && !isExperimentMode()) { - AnnotationManager am = ctx.getAnnotations(); - boolean hasObject = am.hasForegroundAnnotation() - && am.hasBackgroundAnnotation(); - // a.setEnabled(ExportImageMapAction.class, hasObject); - a.setEnabled(ExportImageMapAction.class, true);//change after demo - + a.setEnabled(ExportImageMapAction.class, ctx.hasSegmentationMasks()); + } else { - //a.setEnabled(ExportImageMapAction.class, false); - a.setEnabled(ExportImageMapAction.class, true);// change after demo + a.setEnabled(ExportImageMapAction.class, false); } } diff --git a/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java b/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java index bef17a8..8b758a3 100644 --- a/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java +++ b/Annotation/src/ie/dcu/apps/ist/actions/ExportImageMapAction.java @@ -26,7 +26,9 @@ public class ExportImageMapAction extends AppAction{ @Override public void run() { - if (window.hasContext()) { + SegmentationContext ctx = window.getContext(); + + if (ctx.hasSegmentationMasks()) { // Get options from user ExportDialog dialog = new ExportDialog(window.getShell()); @@ -35,35 +37,36 @@ public class ExportImageMapAction extends AppAction{ if (result != null) { // Grab image and mask - SegmentationContext ctx = window.getContext(); - SegmentationMask mask = ctx.getSegmentationMasks().get(0); - BufferedImage image = ImageConverter.convert(ctx.getImageData()); - - // Setup exporter - Exporter exporter = new Exporter(image, mask); - exporter.setEffect(result.effect); - exporter.setHtmlFile(result.html); - exporter.setImageFile(result.image); - exporter.setObjectLink(result.link); - exporter.setExportShape(result.shape); - exporter.setObjectDescription(result.description); - String label = SegmentationView.comboLabel.getText(); - if(label.indexOf('{') != -1) - { - label = label.substring(0,label.indexOf('{')-1); - } - exporter.setTitle(label); - // Export - try { - exporter.export(result.folder); - } catch (IOException e) { - handleError(e); - return; - } catch (ExportException e) { - handleError(e); - return; - } + for (SegmentationMask mask : ctx.getSegmentationMasks()) + { + BufferedImage image = ImageConverter.convert(ctx.getImageData()); + // Setup exporter + Exporter exporter = new Exporter(image, mask); + exporter.setEffect(result.effect); + exporter.setHtmlFile(result.html); + exporter.setImageFile(result.image); + exporter.setObjectLink(result.link); + exporter.setExportShape(result.shape); + exporter.setObjectDescription(result.description); + String label = SegmentationView.comboLabel.getText(); + if(label.indexOf('{') != -1) + { + label = label.substring(0,label.indexOf('{')-1); + } + exporter.setTitle(label); + + // Export + try { + exporter.export(result.folder, mask.layerNumber); + } catch (IOException e) { + handleError(e); + return; + } catch (ExportException e) { + handleError(e); + return; + } + } // for opening the image after saving as ImageMap if (result.open) { File file = new File(result.folder, result.html); diff --git a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java index 09fafa1..3418b85 100644 --- a/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java +++ b/Annotation/src/ie/dcu/apps/ist/export/imagemap/Exporter.java @@ -98,7 +98,7 @@ public class Exporter { this.exportShape = shape; } - public void export(File folder) throws IOException, ExportException { + public void export(File folder, int layerNumber) throws IOException, ExportException { ContourTracer tracer = new ContourTracer(mask, SegmentationMask.FOREGROUND); List trace = tracer.trace(); @@ -106,7 +106,7 @@ public class Exporter { throw new ExportException("No objects found"); } - List preloads = getPreloads(trace); + List preloads = getPreloads(trace,layerNumber); // Write image ImageIO.write(image, "png", new File(folder, imageFile)); @@ -168,10 +168,10 @@ public class Exporter { map.addArea(area); } - map.exportToFile(new File(folder, htmlFile)); + map.exportToFile(new File(folder, layerNumber+htmlFile)); } - private List getPreloads(List trace) { + private List getPreloads(List trace, int layerNumber) { List preloads = new ArrayList(); preloads.add(imageFile); @@ -179,7 +179,7 @@ public class Exporter { String basename = FileUtils.removeExtension(imageFile); for (int i = 0; i < trace.size(); i++) { - String filename = String.format("%s-%d.png", basename, i); + String filename = String.format("%s-%d.png", basename, layerNumber); preloads.add(filename); } } diff --git a/Annotation/src/ie/dcu/apps/ist/export/imagemap/ImageMap.java b/Annotation/src/ie/dcu/apps/ist/export/imagemap/ImageMap.java index 4125ccf..8c8ee38 100644 --- a/Annotation/src/ie/dcu/apps/ist/export/imagemap/ImageMap.java +++ b/Annotation/src/ie/dcu/apps/ist/export/imagemap/ImageMap.java @@ -130,7 +130,7 @@ public class ImageMap { subs.put("map-name", mapName); subs.put("contents", contents.toString()); subs.put("preloads", preloads.toString()); - + System.out.println("Contents coming as "+contents.toString()); return substitute(template, subs); } diff --git a/Annotation/src/ie/dcu/segment/SegmentationContext.java b/Annotation/src/ie/dcu/segment/SegmentationContext.java index a92c828..b7c0950 100644 --- a/Annotation/src/ie/dcu/segment/SegmentationContext.java +++ b/Annotation/src/ie/dcu/segment/SegmentationContext.java @@ -171,6 +171,15 @@ public class SegmentationContext { return segmentationMaskObjects; } + /** + * @return + * Returns boolean value based on whether there are segmentationMasks formed or not. + */ + public boolean hasSegmentationMasks() { + + return segmentationMaskObjects.size() != 0; + } + /** * For highlighting the clicked segmentObject * @param x, mouse clicked point x