Search in sources :

Example 41 with VisualizationTask

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

the class SelectionAxisRangeVisualization method processNewResult.

@Override
public void processNewResult(VisualizerContext context, Object start) {
    VisualizationTree.findVis(context, start).filter(ParallelPlotProjector.class).forEach(p -> {
        Relation<?> rel = p.getRelation();
        if (!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(rel.getDataTypeInformation())) {
            return;
        }
        final VisualizationTask task = // 
        new VisualizationTask(this, NAME, context.getSelectionResult(), rel).level(// 
        VisualizationTask.LEVEL_DATA - 1).with(UpdateFlag.ON_SELECTION);
        context.addVis(context.getSelectionResult(), task);
        context.addVis(p, task);
    });
}
Also used : VisualizationTask(de.lmu.ifi.dbs.elki.visualization.VisualizationTask) ParallelPlotProjector(de.lmu.ifi.dbs.elki.visualization.projector.ParallelPlotProjector)

Example 42 with VisualizationTask

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

the class SelectionLineVisualization method processNewResult.

@Override
public void processNewResult(VisualizerContext context, Object start) {
    VisualizationTree.findVis(context, start).filter(ParallelPlotProjector.class).forEach(p -> {
        Relation<?> rel = p.getRelation();
        if (!TypeUtil.NUMBER_VECTOR_FIELD.isAssignableFromType(rel.getDataTypeInformation())) {
            return;
        }
        final VisualizationTask task = // 
        new VisualizationTask(this, NAME, context.getSelectionResult(), rel).level(// 
        VisualizationTask.LEVEL_DATA - 1).with(UpdateFlag.ON_DATA).with(UpdateFlag.ON_SELECTION);
        context.addVis(context.getSelectionResult(), task);
        context.addVis(p, task);
    });
}
Also used : VisualizationTask(de.lmu.ifi.dbs.elki.visualization.VisualizationTask) ParallelPlotProjector(de.lmu.ifi.dbs.elki.visualization.projector.ParallelPlotProjector)

Example 43 with VisualizationTask

use of de.lmu.ifi.dbs.elki.visualization.VisualizationTask 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)

Example 44 with VisualizationTask

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

the class ExportVisualizations method processNewResult.

@Override
public void processNewResult(ResultHierarchy hier, Result newResult) {
    if (output.isFile()) {
        throw new AbortException("Output folder cannot be an existing file.");
    }
    if (!output.exists() && !output.mkdirs()) {
        throw new AbortException("Could not create output directory.");
    }
    if (this.baseResult == null) {
        this.baseResult = newResult;
        context = null;
        counter = new HashMap<>();
        LOG.warning("Note: Reusing visualization exporter for more than one result is untested.");
    }
    if (context == null) {
        context = manager.newContext(hier, baseResult);
    }
    // Projected visualizations
    Hierarchy<Object> vistree = context.getVisHierarchy();
    for (It<Projector> iter2 = vistree.iterAll().filter(Projector.class); iter2.valid(); iter2.advance()) {
        // TODO: allow selecting individual projections only.
        Collection<PlotItem> items = iter2.get().arrange(context);
        for (PlotItem item : items) {
            processItem(item);
        }
    }
    for (It<VisualizationTask> iter2 = vistree.iterAll().filter(VisualizationTask.class); iter2.valid(); iter2.advance()) {
        VisualizationTask task = iter2.get();
        if (vistree.iterParents(task).filter(Projector.class).valid()) {
            continue;
        }
        PlotItem pi = new PlotItem(ratio, 1.0, null);
        pi.add(task);
        processItem(pi);
    }
}
Also used : Projector(de.lmu.ifi.dbs.elki.visualization.projector.Projector) VisualizationTask(de.lmu.ifi.dbs.elki.visualization.VisualizationTask) PlotItem(de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Aggregations

VisualizationTask (de.lmu.ifi.dbs.elki.visualization.VisualizationTask)44 ScatterPlotProjector (de.lmu.ifi.dbs.elki.visualization.projector.ScatterPlotProjector)10 ParallelPlotProjector (de.lmu.ifi.dbs.elki.visualization.projector.ParallelPlotProjector)7 Visualization (de.lmu.ifi.dbs.elki.visualization.visualizers.Visualization)7 PlotItem (de.lmu.ifi.dbs.elki.visualization.gui.overview.PlotItem)6 ArrayList (java.util.ArrayList)6 Element (org.w3c.dom.Element)4 ScalesResult (de.lmu.ifi.dbs.elki.result.ScalesResult)3 Relation (de.lmu.ifi.dbs.elki.database.relation.Relation)2 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)2 Projector (de.lmu.ifi.dbs.elki.visualization.projector.Projector)2 LabelVisualization (de.lmu.ifi.dbs.elki.visualization.visualizers.visunproj.LabelVisualization)2 PointerHierarchyRepresentationResult (de.lmu.ifi.dbs.elki.algorithm.clustering.hierarchical.PointerHierarchyRepresentationResult)1 ClusterOrder (de.lmu.ifi.dbs.elki.algorithm.clustering.optics.ClusterOrder)1 OPTICSXi (de.lmu.ifi.dbs.elki.algorithm.clustering.optics.OPTICSXi)1 PolygonsObject (de.lmu.ifi.dbs.elki.data.spatial.PolygonsObject)1 Database (de.lmu.ifi.dbs.elki.database.Database)1 UpdatableDatabase (de.lmu.ifi.dbs.elki.database.UpdatableDatabase)1 AffineTransformation (de.lmu.ifi.dbs.elki.math.linearalgebra.AffineTransformation)1 EvaluationResult (de.lmu.ifi.dbs.elki.result.EvaluationResult)1