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);
});
}
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);
});
}
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();
}
}
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);
}
}
Aggregations