@Test public void testRender() throws Exception { final String json = "{\n" + " \"x\" : 0.0, \"y\" : 0.0, \"width\" : 400, \"height\" : 100, \"scale\" : 1.0,\n" + " \"tileSpecs\" : [ {\n" + " \"tileId\" : \"tile_a.1.0\",\n" + " \"z\" : 1.0, \"minX\" : 0.0, \"minY\" : 0.0, \"maxX\" : 199.0, \"maxY\" : 99.0, \"width\" : 200.0, \"height\" : 100.0,\n" + " \"mipmapLevels\" : { \"0\" : { \"imageUrl\" : \"src/test/resources/stitch-test/col0075_row0021_cam1.png\" } },\n" + " \"transforms\" : { \"type\" : \"list\", \"specList\" : [ \n" + " { \"className\" : \"mpicbg.trakem2.transform.AffineModel2D\", \"dataString\" : \"1 0 0 1 0 0\" } ]\n" + " }\n" + " }, {\n" + " \"tileId\" : \"tile_b.1.0\",\n" + " \"z\" : 1.0, \"minX\" : 190.0, \"minY\" : 0.0, \"maxX\" : 389.0, \"maxY\" : 99.0, \"width\" : 200.0, \"height\" : 100.0,\n" + " \"mipmapLevels\" : { \"0\" : { \"imageUrl\" : \"src/test/resources/stitch-test/col0076_row0021_cam0.png\" } },\n" + " \"transforms\" : { \"type\" : \"list\", \"specList\" : [ \n" + " { \"className\" : \"mpicbg.trakem2.transform.AffineModel2D\", \"dataString\" : \"1 0 0 1 190 0\" } ]\n" + " }\n" + " } ]\n" + "}"; final RenderParameters renderParameters = RenderParameters.parseJson(json); final BufferedImage bufferedImage = renderParameters.openTargetImage(); final Color boxColor = Color.GREEN; final BoundingBoxRenderer renderer = new BoundingBoxRenderer(renderParameters, boxColor); renderer.render(bufferedImage); final int[][] boxPoints = { {0, 0}, {99, 0}, {99, 99}, {0, 99}, {90, 0} }; for (final int[] point : boxPoints) { Assert.assertEquals("invalid color for box point " + Arrays.toString(point), boxColor.getRGB(), bufferedImage.getRGB(point[0], point[1])); } final int[][] spacePoints = { {10, 10}, {110, 10} }; for (final int[] point : spacePoints) { Assert.assertEquals("invalid color for space point " + Arrays.toString(point), 0, bufferedImage.getRGB(point[0], point[1])); } }
public void render(final BufferedImage targetImage) throws IllegalArgumentException { final Graphics2D targetGraphics = targetImage.createGraphics(); targetGraphics.setColor(foregroundColor); targetGraphics.setStroke(stroke); if (backgroundColor != null) { targetGraphics.setBackground(backgroundColor); targetGraphics.clearRect(0, 0, targetImage.getWidth(), targetImage.getHeight()); } final List<TileSpec> tileSpecs = renderParameters.getTileSpecs(); final int maxCharactersPerLine = 12; int lineWidth = 0; int lineHeight = 0; int minBoxWidthForTileIdRendering = 0; if (tileSpecs.size() > 0) { targetGraphics.setFont(TILE_ID_FONT); final FontMetrics metrics = targetGraphics.getFontMetrics(); lineWidth = metrics.stringWidth("A") * maxCharactersPerLine; lineHeight = metrics.getHeight(); minBoxWidthForTileIdRendering = (int) (lineWidth * 1.3) + 1; } Rectangle box; String tileId; int x; int y; int start; for (final TileSpec tileSpec : tileSpecs) { box = getScaledBox(tileSpec); targetGraphics.draw(box); if (box.width > minBoxWidthForTileIdRendering) { tileId = tileSpec.getTileId(); if (tileId != null) { x = box.x + ((box.width - lineWidth) / 2); y = box.y + (box.height / 4); start = 0; for (int stop = maxCharactersPerLine; stop < tileId.length(); stop += maxCharactersPerLine) { targetGraphics.drawString(tileId.substring(start, stop), x, y); y = y + lineHeight; start = stop; } if (start < tileId.length()) { targetGraphics.drawString(tileId.substring(start), x, y); } } } } if (renderParameters.isAddWarpFieldDebugOverlay()) { WarpFieldDebugRenderer.render(renderParameters, targetGraphics, targetImage.getWidth(), targetImage.getHeight()); } targetGraphics.dispose(); LOG.debug("render: exit, boxes for {} tiles rendered", tileSpecs.size()); }
BoundingBoxRenderer { public void render(final BufferedImage targetImage) throws IllegalArgumentException { final Graphics2D targetGraphics = targetImage.createGraphics(); targetGraphics.setColor(foregroundColor); targetGraphics.setStroke(stroke); if (backgroundColor != null) { targetGraphics.setBackground(backgroundColor); targetGraphics.clearRect(0, 0, targetImage.getWidth(), targetImage.getHeight()); } final List<TileSpec> tileSpecs = renderParameters.getTileSpecs(); final int maxCharactersPerLine = 12; int lineWidth = 0; int lineHeight = 0; int minBoxWidthForTileIdRendering = 0; if (tileSpecs.size() > 0) { targetGraphics.setFont(TILE_ID_FONT); final FontMetrics metrics = targetGraphics.getFontMetrics(); lineWidth = metrics.stringWidth("A") * maxCharactersPerLine; lineHeight = metrics.getHeight(); minBoxWidthForTileIdRendering = (int) (lineWidth * 1.3) + 1; } Rectangle box; String tileId; int x; int y; int start; for (final TileSpec tileSpec : tileSpecs) { box = getScaledBox(tileSpec); targetGraphics.draw(box); if (box.width > minBoxWidthForTileIdRendering) { tileId = tileSpec.getTileId(); if (tileId != null) { x = box.x + ((box.width - lineWidth) / 2); y = box.y + (box.height / 4); start = 0; for (int stop = maxCharactersPerLine; stop < tileId.length(); stop += maxCharactersPerLine) { targetGraphics.drawString(tileId.substring(start, stop), x, y); y = y + lineHeight; start = stop; } if (start < tileId.length()) { targetGraphics.drawString(tileId.substring(start), x, y); } } } } if (renderParameters.isAddWarpFieldDebugOverlay()) { WarpFieldDebugRenderer.render(renderParameters, targetGraphics, targetImage.getWidth(), targetImage.getHeight()); } targetGraphics.dispose(); LOG.debug("render: exit, boxes for {} tiles rendered", tileSpecs.size()); } }
BoundingBoxRenderer { public void render(final BufferedImage targetImage) throws IllegalArgumentException { final Graphics2D targetGraphics = targetImage.createGraphics(); targetGraphics.setColor(foregroundColor); targetGraphics.setStroke(stroke); if (backgroundColor != null) { targetGraphics.setBackground(backgroundColor); targetGraphics.clearRect(0, 0, targetImage.getWidth(), targetImage.getHeight()); } final List<TileSpec> tileSpecs = renderParameters.getTileSpecs(); final int maxCharactersPerLine = 12; int lineWidth = 0; int lineHeight = 0; int minBoxWidthForTileIdRendering = 0; if (tileSpecs.size() > 0) { targetGraphics.setFont(TILE_ID_FONT); final FontMetrics metrics = targetGraphics.getFontMetrics(); lineWidth = metrics.stringWidth("A") * maxCharactersPerLine; lineHeight = metrics.getHeight(); minBoxWidthForTileIdRendering = (int) (lineWidth * 1.3) + 1; } Rectangle box; String tileId; int x; int y; int start; for (final TileSpec tileSpec : tileSpecs) { box = getScaledBox(tileSpec); targetGraphics.draw(box); if (box.width > minBoxWidthForTileIdRendering) { tileId = tileSpec.getTileId(); if (tileId != null) { x = box.x + ((box.width - lineWidth) / 2); y = box.y + (box.height / 4); start = 0; for (int stop = maxCharactersPerLine; stop < tileId.length(); stop += maxCharactersPerLine) { targetGraphics.drawString(tileId.substring(start, stop), x, y); y = y + lineHeight; start = stop; } if (start < tileId.length()) { targetGraphics.drawString(tileId.substring(start), x, y); } } } } if (renderParameters.isAddWarpFieldDebugOverlay()) { WarpFieldDebugRenderer.render(renderParameters, targetGraphics, targetImage.getWidth(), targetImage.getHeight()); } targetGraphics.dispose(); LOG.debug("render: exit, boxes for {} tiles rendered", tileSpecs.size()); } BoundingBoxRenderer(final RenderParameters renderParameters,
                               final Color foregroundColor);  BoundingBoxRenderer(final RenderParameters renderParameters,
                               final Color foregroundColor,
                               final float lineWidth); }
BoundingBoxRenderer { public void render(final BufferedImage targetImage) throws IllegalArgumentException { final Graphics2D targetGraphics = targetImage.createGraphics(); targetGraphics.setColor(foregroundColor); targetGraphics.setStroke(stroke); if (backgroundColor != null) { targetGraphics.setBackground(backgroundColor); targetGraphics.clearRect(0, 0, targetImage.getWidth(), targetImage.getHeight()); } final List<TileSpec> tileSpecs = renderParameters.getTileSpecs(); final int maxCharactersPerLine = 12; int lineWidth = 0; int lineHeight = 0; int minBoxWidthForTileIdRendering = 0; if (tileSpecs.size() > 0) { targetGraphics.setFont(TILE_ID_FONT); final FontMetrics metrics = targetGraphics.getFontMetrics(); lineWidth = metrics.stringWidth("A") * maxCharactersPerLine; lineHeight = metrics.getHeight(); minBoxWidthForTileIdRendering = (int) (lineWidth * 1.3) + 1; } Rectangle box; String tileId; int x; int y; int start; for (final TileSpec tileSpec : tileSpecs) { box = getScaledBox(tileSpec); targetGraphics.draw(box); if (box.width > minBoxWidthForTileIdRendering) { tileId = tileSpec.getTileId(); if (tileId != null) { x = box.x + ((box.width - lineWidth) / 2); y = box.y + (box.height / 4); start = 0; for (int stop = maxCharactersPerLine; stop < tileId.length(); stop += maxCharactersPerLine) { targetGraphics.drawString(tileId.substring(start, stop), x, y); y = y + lineHeight; start = stop; } if (start < tileId.length()) { targetGraphics.drawString(tileId.substring(start), x, y); } } } } if (renderParameters.isAddWarpFieldDebugOverlay()) { WarpFieldDebugRenderer.render(renderParameters, targetGraphics, targetImage.getWidth(), targetImage.getHeight()); } targetGraphics.dispose(); LOG.debug("render: exit, boxes for {} tiles rendered", tileSpecs.size()); } BoundingBoxRenderer(final RenderParameters renderParameters,
                               final Color foregroundColor);  BoundingBoxRenderer(final RenderParameters renderParameters,
                               final Color foregroundColor,
                               final float lineWidth); void render(final BufferedImage targetImage); }
BoundingBoxRenderer { public void render(final BufferedImage targetImage) throws IllegalArgumentException { final Graphics2D targetGraphics = targetImage.createGraphics(); targetGraphics.setColor(foregroundColor); targetGraphics.setStroke(stroke); if (backgroundColor != null) { targetGraphics.setBackground(backgroundColor); targetGraphics.clearRect(0, 0, targetImage.getWidth(), targetImage.getHeight()); } final List<TileSpec> tileSpecs = renderParameters.getTileSpecs(); final int maxCharactersPerLine = 12; int lineWidth = 0; int lineHeight = 0; int minBoxWidthForTileIdRendering = 0; if (tileSpecs.size() > 0) { targetGraphics.setFont(TILE_ID_FONT); final FontMetrics metrics = targetGraphics.getFontMetrics(); lineWidth = metrics.stringWidth("A") * maxCharactersPerLine; lineHeight = metrics.getHeight(); minBoxWidthForTileIdRendering = (int) (lineWidth * 1.3) + 1; } Rectangle box; String tileId; int x; int y; int start; for (final TileSpec tileSpec : tileSpecs) { box = getScaledBox(tileSpec); targetGraphics.draw(box); if (box.width > minBoxWidthForTileIdRendering) { tileId = tileSpec.getTileId(); if (tileId != null) { x = box.x + ((box.width - lineWidth) / 2); y = box.y + (box.height / 4); start = 0; for (int stop = maxCharactersPerLine; stop < tileId.length(); stop += maxCharactersPerLine) { targetGraphics.drawString(tileId.substring(start, stop), x, y); y = y + lineHeight; start = stop; } if (start < tileId.length()) { targetGraphics.drawString(tileId.substring(start), x, y); } } } } if (renderParameters.isAddWarpFieldDebugOverlay()) { WarpFieldDebugRenderer.render(renderParameters, targetGraphics, targetImage.getWidth(), targetImage.getHeight()); } targetGraphics.dispose(); LOG.debug("render: exit, boxes for {} tiles rendered", tileSpecs.size()); } BoundingBoxRenderer(final RenderParameters renderParameters,
                               final Color foregroundColor);  BoundingBoxRenderer(final RenderParameters renderParameters,
                               final Color foregroundColor,
                               final float lineWidth); void render(final BufferedImage targetImage);  }