Search in sources :

Example 11 with Visualization

use of de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization in project elki by elki-project.

the class ThumbnailVisualization method doThumbnail.

@Override
public synchronized void doThumbnail() {
    pendingThumbnail = null;
    try {
        VisualizationPlot plot = new VisualizationPlot();
        plot.getRoot().setAttribute(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + getWidth() + " " + getHeight());
        // Work on a clone
        Visualization vis = visFactory.makeVisualization(context, task, plot, getWidth(), getHeight(), proj);
        plot.getRoot().appendChild(vis.getLayer());
        plot.updateStyleElement();
        final int tw = (int) (getWidth() * tresolution);
        final int th = (int) (getHeight() * tresolution);
        thumb = plot.makeAWTImage(tw, th);
        thumbid = ThumbnailRegistryEntry.registerImage(thumb);
        // The visualization will not be used anymore.
        vis.destroy();
        svgp.requestRedraw(this.task, this);
    } catch (Exception e) {
        final Logging logger = Logging.getLogger(task.getFactory().getClass());
        if (logger != null && logger.isDebugging()) {
            logger.exception("Thumbnail for " + task.getFactory() + " failed.", e);
        } else {
            LoggingUtil.warning("Thumbnail for " + task.getFactory() + " failed - enable debugging to see details.");
        }
    // TODO: hide the failed image?
    }
}
Also used : Logging(de.lmu.ifi.dbs.elki.logging.Logging) AbstractVisualization(de.lmu.ifi.dbs.elki.visualization.visualizers.AbstractVisualization) Visualization(de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization) VisualizationPlot(de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot)

Example 12 with Visualization

use of de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization in project elki by elki-project.

the class ExportVisualizations method processItem.

private void processItem(PlotItem item) {
    // Descend into subitems
    for (Iterator<PlotItem> iter = item.subitems.iterator(); iter.hasNext(); ) {
        processItem(iter.next());
    }
    if (item.taskSize() <= 0) {
        return;
    }
    item.sort();
    final double width = item.w, height = item.h;
    VisualizationPlot svgp = new VisualizationPlot();
    svgp.getRoot().setAttribute(SVGConstants.SVG_WIDTH_ATTRIBUTE, "20cm");
    svgp.getRoot().setAttribute(SVGConstants.SVG_HEIGHT_ATTRIBUTE, (20 * height / width) + "cm");
    svgp.getRoot().setAttribute(SVGConstants.SVG_VIEW_BOX_ATTRIBUTE, "0 0 " + width + " " + height);
    ArrayList<Visualization> layers = new ArrayList<>();
    for (Iterator<VisualizationTask> iter = item.tasks.iterator(); iter.hasNext(); ) {
        VisualizationTask task = iter.next();
        if (task.has(RenderFlag.NO_DETAIL) || task.has(RenderFlag.NO_EXPORT) || !task.isVisible()) {
            continue;
        }
        try {
            Visualization v = task.getFactory().makeVisualization(context, task, svgp, width, height, item.proj);
            layers.add(v);
        } catch (Exception e) {
            if (Logging.getLogger(task.getFactory().getClass()).isDebugging()) {
                LOG.exception("Visualization failed.", e);
            } else {
                LOG.warning("Visualizer " + task.getFactory().getClass().getName() + " failed - enable debugging to see details.");
            }
        }
    }
    if (layers.isEmpty()) {
        return;
    }
    for (Visualization layer : layers) {
        if (layer.getLayer() == null) {
            LOG.warning("NULL layer seen.");
            continue;
        }
        svgp.getRoot().appendChild(layer.getLayer());
    }
    svgp.updateStyleElement();
    String prefix = null;
    prefix = (prefix == null && item.proj != null) ? item.proj.getMenuName() : prefix;
    prefix = (prefix == null && item.tasks.size() > 0) ? item.tasks.get(0).getMenuName() : prefix;
    prefix = (prefix != null ? prefix : "plot");
    // TODO: generate names...
    Integer count = counter.get(prefix);
    counter.put(prefix, count = count == null ? 1 : (count + 1));
    try {
        switch(format) {
            case SVG:
                {
                    File outname = new File(output, prefix + "-" + count + ".svg");
                    svgp.saveAsSVG(outname);
                    break;
                }
            case PNG:
                {
                    File outname = new File(output, prefix + "-" + count + ".png");
                    svgp.saveAsPNG(outname, (int) (iwidth * ratio), iwidth);
                    break;
                }
            case PDF:
                {
                    File outname = new File(output, prefix + "-" + count + ".pdf");
                    svgp.saveAsPDF(outname);
                    break;
                }
            case PS:
                {
                    File outname = new File(output, prefix + "-" + count + ".ps");
                    svgp.saveAsPS(outname);
                    break;
                }
            case EPS:
                {
                    File outname = new File(output, prefix + "-" + count + ".eps");
                    svgp.saveAsEPS(outname);
                    break;
                }
            case JPEG:
                {
                    File outname = new File(output, prefix + "-" + count + ".jpg");
                    svgp.saveAsJPEG(outname, (int) (iwidth * ratio), iwidth);
                    break;
                }
        }
    } catch (Exception e) {
        LOG.warning("Export of visualization failed.", e);
    }
    for (Visualization layer : layers) {
        layer.destroy();
    }
}
Also used : Visualization(de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization) ArrayList(java.util.ArrayList) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException) VisualizationTask(de.lmu.ifi.dbs.elki.visualization.VisualizationTask) PlotItem(de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem) VisualizationPlot(de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot) File(java.io.File)

Aggregations

Visualization (de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization)12 VisualizationTask (de.lmu.ifi.dbs.elki.visualization.VisualizationTask)7 Element (org.w3c.dom.Element)5 VisualizationPlot (de.lmu.ifi.dbs.elki.visualization.gui.VisualizationPlot)3 ArrayList (java.util.ArrayList)2 Logging (de.lmu.ifi.dbs.elki.logging.Logging)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 SimpleSVGViewer (de.lmu.ifi.dbs.elki.visualization.gui.SimpleSVGViewer)1 PlotItem (de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem)1 Projector (de.lmu.ifi.dbs.elki.visualization.projector.Projector)1 AbstractVisualization (de.lmu.ifi.dbs.elki.visualization.visualizers.AbstractVisualization)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 File (java.io.File)1 Entry (java.util.Map.Entry)1 Node (org.w3c.dom.Node)1 EventTarget (org.w3c.dom.events.EventTarget)1