unfolding icon indicating copy to clipboard operation
unfolding copied to clipboard

Add an example for the Distorter classes

Open bertbalcaen opened this issue 12 years ago • 1 comments

The JavaDoc mentions a few interesting looking Distorter classes, but it's not easy to figure out how they can be used. An example would be very useful.

bertbalcaen avatar Nov 20 '12 17:11 bertbalcaen

There are currently no examples included in the Unfolding distribution. Since our refactoring of the core (>0.9) the distortion system is not a fully supported part of Unfolding anymore (at the moment).

Having said that, feel free to fork or download the project, dig into the sources, and check out the package 'de.fhpotsdam.unfolding.texture'. Some parts might or might not work.

I just uploaded an old video showing fisheye and lens distortion. Check it out: https://vimeo.com/54025047 The source e.g. for the fisheye example looks like below. Keep in mind this only works with the latest develop-branch.

package de.fhpotsdam.unfolding.distortion;

import processing.core.PApplet;
import codeanticode.glgraphics.GLConstants;
import de.fhpotsdam.unfolding.UnfoldingMap;
import de.fhpotsdam.unfolding.geo.Location;
import de.fhpotsdam.unfolding.mapdisplay.DistortedGLGraphicsMapDisplay;
import de.fhpotsdam.unfolding.providers.AbstractMapProvider;
import de.fhpotsdam.unfolding.providers.Microsoft;
import de.fhpotsdam.unfolding.texture.PAppletFactory;
import de.fhpotsdam.unfolding.texture.ScaleInterpolationDistorter;
import de.fhpotsdam.unfolding.utils.MapUtils;

/**
 * Fisheye lens distortion of an interactive map. A fisheye distorts the whole map,
 * i.e. acts globally. For a local distortion see the LinearDistortionLensApp.
 * 
 * This example demonstrates how to use the (unofficial) DistortedGLGraphicsMapDisplay.
 * 
 * Press R or r to increase or decrease the radius of the lens.
 * Press Z or z to increase or decrease the zoom distortion.
 * 
 */
public class ScaleDistortionLensApp extends PApplet {

    UnfoldingMap map;

    float innerRadius = 90;
    float outerRadius = 180;
    float zoom = 2;

    public void setup() {
        size(800, 600, GLConstants.GLGRAPHICS);

        new PAppletFactory(this);

        // AbstractMapProvider provider = new Google.GoogleSimplifiedProvider();
        AbstractMapProvider provider = new Microsoft.AerialProvider();
        map = new UnfoldingMap(this, "map1", 0, 0, width, height, true, true, provider);
        map.mapDisplay = new DistortedGLGraphicsMapDisplay(this, provider, 0, 0, width, height,
                new ScaleInterpolationDistorter(innerRadius, outerRadius));
        map.zoomAndPanTo(new Location(40f, -96f), 4);

        MapUtils.createDefaultEventDispatcher(this, map);
    }

    public void draw() {
        background(0);
        map.draw();

        showLensOutline();
    }

    public void showLensOutline() {
        noFill();
        strokeWeight(6);
        stroke(0, 40);
        ellipse(mouseX, mouseY, innerRadius * 2, innerRadius * 2);
        stroke(0, 60);
        ellipse(mouseX, mouseY, outerRadius * 2, outerRadius * 2);
    }

    public void mouseMoved() {
        DistortedGLGraphicsMapDisplay md = (DistortedGLGraphicsMapDisplay) map.mapDisplay;
        ScaleInterpolationDistorter lig = (ScaleInterpolationDistorter) md.distorter;
        lig.setCenter(mouseX, mouseY);
    }

    public void setScaleDistortion() {
        DistortedGLGraphicsMapDisplay md = (DistortedGLGraphicsMapDisplay) map.mapDisplay;
        ScaleInterpolationDistorter lig = (ScaleInterpolationDistorter) md.distorter;
        lig.setRadius((int) innerRadius);
        lig.setZoom(zoom);
    }

    public void keyPressed() {
        if (key == 'R') {
            innerRadius++;
            outerRadius = innerRadius * zoom;
        } else if (key == 'r') {
            innerRadius--;
            outerRadius = innerRadius * zoom;
        } else if (key == 'z') {
            zoom -= 0.1;
        } else if (key == 'Z') {
            zoom += 0.1;
        }
        setScaleDistortion();
    }

}

tillnagel avatar Nov 21 '12 17:11 tillnagel