Exporting preview only partially to PNG

Screenshots, Vectorial Preview and printable exports
Post Reply [phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
pegerp
Posts:124
Joined:21 Dec 2011 17:10
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
Exporting preview only partially to PNG

Post by pegerp » 26 Jan 2013 16:48

Hi.

Using Gephi's Java Toolkit how would it be possible to render only parts of the view? What I'd like to have is exporter plugin similar to exporting a PNG image of the whole graph but instead of the whole graph there would be multiple output images.

Below is an example which I've done with a custom Perl renderer. However I'd like to have this functionality done in Java instead.

In practice I'm asking for guidance how to do following:
1. Using Java zoom/pan the preview panel to some part of the graph
2. Render the visible part
3. Zoom/pan the preview panel to different part of the graph
4. Goto point 2.

Eventually I'd have images such as graph-x-y-z.png. This format is used in Google Maps API. See here.

Image

Image

Thanks.

pegerp
Posts:124
Joined:21 Dec 2011 17:10
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Exporting preview only partially to PNG

Post by pegerp » 09 Mar 2013 15:35

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.

pegerp
Posts:124
Joined:21 Dec 2011 17:10
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable

Re: Exporting preview only partially to PNG

Post by pegerp » 09 Mar 2013 21:25

I figured it out a little bit more. When the network layout is on an approximately square area the tiles get rendered properly. Now I've modified PreviewControllerImpl.java's updateDimensions() method to set width and height dimensions to be whichever of the width or height is greater.

In code that is:
// model.setDimensions(new Dimension((int) (bottomRightX - topLeftX), (int) (bottomRightY - topLeftY)));
int dim = (int)Math.max(bottomRightX - topLeftX, bottomRightY - topLeftY);
model.setDimensions(new Dimension(dim, dim));
Image :!: Notice that image has empty space on the right side

With this modification I can now render tiles on different zoom levels so that all tiles align properly next to each others. However I couldn't get my head around why the dimensions should be square. Although now that I'm thinking about it it might make sense...

Example of the rendered output is at http://85.25.226.110/mapper/test?noidle

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1275: count(): Parameter must be an array or an object that implements Countable