I've got progress on this by implementing a TileExporter and modifying ExportController to have exportFiles() method. However there is a strange problem when rendering the tiles.
Consecutive tiles align properly by x-axis or by y-axis but not both. Orientation of the network affects whether the rendered tiles connect properly on their horizontal or vertical edges. Any idea what could be causing this?
Here's the code I'm using:
Code: Select all
PreviewModel model = controller.getModel(workspace);
Point p = model.getTopLeftPosition();
Dimension d = model.getDimensions();
int divisor = z+1;
int tileWidth = d.width / divisor;
int tileHeight = d.height / divisor;
model.setDimensions(new Dimension(tileWidth, tileHeight));
model.setTopLeftPosition(new Point(
p.x + (x * tileWidth),
p.y + (y * tileHeight)));
target = (ProcessingTarget)controller.getRenderTarget(RenderTarget.PROCESSING_TARGET, workspace);
if (target instanceof LongTask) {
((LongTask) target).setProgressTicket(progress);
}
try {
target.refresh();
Progress.switchToIndeterminate(progress);
PGraphicsJava2D pg2 = (PGraphicsJava2D) target.getGraphics();
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
img.setRGB(0, 0, width, height, pg2.pixels, 0, width);
ImageIO.write(img, "png", stream);
props.putValue(PreviewProperty.BACKGROUND_COLOR, oldColor);
} catch (Exception e) {
throw new RuntimeException(e);
}
Somehow the rendered output isn't properly aligned on the topLeftPosition as it should be.
Edit: Here's an example how it looks like:
http://85.25.226.110/mapper/test?noidle - Notice that there are 3 columns of 256x256 tiles which are correctly aligned on top and bottom edges but not on left and right side edges. Sometimes the layout algorithm produces differently oriented network which might make the top and bottom edges align wrong and the sides correctly. Could this have something do with ProcessingGraphics class? In there there is some code related to height/width ratios etc.
Edit 2: z+1 should probably be Math.pow(2, z); Well... it's possible there's some math errors on my part instead of code doing something crazy.