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