Search in sources :

Example 1 with GeoCoordinate

use of spacegraph.util.geo.osm.GeoCoordinate in project narchy by automenta.

the class OsmSpace method compile.

protected Consumer<GL2> compile() {
    List<Consumer<GL2>> draw = new FasterList();
    Osm osm = id;
    for (OsmWay way : osm.ways) {
        Map<String, String> tags = way.tags;
        String building, building_part, landuse, natural, route, highway;
        if (!tags.isEmpty()) {
            building = tags.get("building");
            building_part = tags.get("building:part");
            landuse = tags.get("landuse");
            natural = tags.get("natural");
            route = tags.get("route");
            highway = tags.get("highway");
        } else {
            building = building_part = landuse = natural = route = highway = null;
        }
        boolean isPolygon = false;
        boolean isClosed = way.isClosed();
        float r, g, b, a;
        float lw;
        short ls;
        if (building != null || building_part != null) {
            r = 0f;
            g = 1f;
            b = 1f;
            a = 1f;
            lw = 1f;
            ls = (short) 0xFFFF;
            isPolygon = !wireframe && isClosed;
        } else if ("forest".equals(landuse) || "grass".equals(landuse) || "wood".equals(natural)) {
            r = 0f;
            g = 1f;
            b = 0f;
            a = 1f;
            lw = 1f;
            ls = (short) 0xFFFF;
            isPolygon = !wireframe && isClosed;
        } else if ("water".equals(natural)) {
            r = 0f;
            g = 0f;
            b = 1f;
            a = 1f;
            lw = 1f;
            ls = (short) 0xFFFF;
            isPolygon = !wireframe && isClosed;
        } else if ("pedestrian".equals(highway)) {
            r = 0f;
            g = 0.5f;
            b = 0f;
            a = 1f;
            lw = 2f;
            ls = (short) 0xFFFF;
        } else if ("motorway".equals(highway)) {
            r = 1f;
            g = 0.5f;
            b = 0f;
            a = 1f;
            lw = 5f;
            ls = (short) 0xFFFF;
        } else if (highway != null) {
            r = 1f;
            g = 1f;
            b = 1f;
            a = 1f;
            lw = 3f;
            ls = (short) 0xFFFF;
        } else if ("road".equals(route)) {
            r = 1f;
            g = 1f;
            b = 1f;
            a = 1f;
            lw = 1f;
            ls = (short) 0xFFFF;
        } else if ("train".equals(route)) {
            r = 1f;
            g = 1f;
            b = 1f;
            a = 1f;
            lw = 5f;
            ls = (short) 0xF0F0;
        } else {
            r = 0.5f;
            g = 0f;
            b = 0.5f;
            a = 1f;
            lw = 1f;
            ls = (short) 0xFFFF;
        }
        if (isPolygon) {
            List<OsmNode> nn = way.getOsmNodes();
            double[][] coord = new double[nn.size()][7];
            for (int i = 0, nnSize = nn.size(); i < nnSize; i++) {
                OsmNode node = nn.get(i);
                double[] ci = coord[i];
                project(node.geoCoordinate, ci);
                ci[3] = r;
                ci[4] = g;
                ci[5] = b;
                ci[6] = a;
            }
            draw.add((gl) -> {
                gl.glColor4f(r * 0.5f, g * .5f, b * 0.5f, a);
                gl.glLineWidth(lw);
                gl.glLineStipple(1, ls);
                GLU.gluTessBeginPolygon(tobj, null);
                GLU.gluTessBeginContour(tobj);
                for (int i = 0, nnSize = nn.size(); i < nnSize; i++) {
                    double[] ci = coord[i];
                    GLU.gluTessVertex(tobj, ci, 0, ci);
                }
                GLU.gluTessEndContour(tobj);
                GLU.gluTessEndPolygon(tobj);
            });
        } else {
            List<OsmNode> ways = way.getOsmNodes();
            int ws = ways.size();
            double[] c3 = new double[3 * ws];
            for (int i = 0, waysSize = ws; i < waysSize; i++) {
                project(ways.get(i).geoCoordinate, c3, i * 3);
            }
            draw.add((gl) -> {
                gl.glColor4f(r, g, b, a);
                gl.glLineWidth(lw);
                gl.glLineStipple(1, ls);
                gl.glBegin(GL_LINE_STRIP);
                for (int i = 0; i < c3.length / 3; i++) {
                    gl.glVertex3dv(c3, i * 3);
                }
                gl.glEnd();
            });
        }
    }
    for (OsmNode node : osm.nodes) {
        Map<String, String> tags = node.tags;
        if (tags.isEmpty())
            continue;
        String highway = tags.get("highway");
        String natural = tags.get("natural");
        float pointSize;
        float r, g, b, a;
        if ("bus_stop".equals(highway)) {
            pointSize = 3;
            r = g = b = 1f;
            a = 0.7f;
        } else if ("traffic_signals".equals(highway)) {
            pointSize = 3;
            r = g = 1f;
            b = 0f;
            a = 0.7f;
        } else if ("tree".equals(natural)) {
            pointSize = 3;
            g = 1f;
            r = b = 0f;
            a = 0.7f;
        } else {
            pointSize = 3;
            r = 1f;
            g = b = 0f;
            a = 0.7f;
        }
        double[] c3 = new double[3];
        project(node.geoCoordinate, c3);
        draw.add((gl) -> {
            gl.glPointSize(pointSize);
            gl.glBegin(GL_POINTS);
            gl.glColor4f(r, g, b, a);
            gl.glVertex3d(c3[0], c3[1], c3[2]);
            gl.glEnd();
        });
    }
    return (v) -> draw.forEach(d -> d.accept(v));
}
Also used : GL2(com.jogamp.opengl.GL2) GLUtessellatorCallback(com.jogamp.opengl.glu.GLUtessellatorCallback) GeoCoordinate(spacegraph.util.geo.osm.GeoCoordinate) AbstractSpatial(spacegraph.space3d.AbstractSpatial) GLU(com.jogamp.opengl.glu.GLU) OsmWay(spacegraph.util.geo.osm.OsmWay) FasterList(jcog.list.FasterList) GLUtessellator(com.jogamp.opengl.glu.GLUtessellator) GL_LINE_STRIP(com.jogamp.opengl.GL.GL_LINE_STRIP) Draw(spacegraph.video.Draw) Osm(spacegraph.util.geo.osm.Osm) Consumer(java.util.function.Consumer) List(java.util.List) OsmNode(spacegraph.util.geo.osm.OsmNode) Map(java.util.Map) ECEF(spacegraph.util.geo.ECEF) GL_POINTS(com.jogamp.opengl.GL.GL_POINTS) Collidable(spacegraph.space3d.phys.Collidable) OsmNode(spacegraph.util.geo.osm.OsmNode) FasterList(jcog.list.FasterList) Osm(spacegraph.util.geo.osm.Osm) OsmWay(spacegraph.util.geo.osm.OsmWay) Consumer(java.util.function.Consumer)

Aggregations

GL_LINE_STRIP (com.jogamp.opengl.GL.GL_LINE_STRIP)1 GL_POINTS (com.jogamp.opengl.GL.GL_POINTS)1 GL2 (com.jogamp.opengl.GL2)1 GLU (com.jogamp.opengl.glu.GLU)1 GLUtessellator (com.jogamp.opengl.glu.GLUtessellator)1 GLUtessellatorCallback (com.jogamp.opengl.glu.GLUtessellatorCallback)1 List (java.util.List)1 Map (java.util.Map)1 Consumer (java.util.function.Consumer)1 FasterList (jcog.list.FasterList)1 AbstractSpatial (spacegraph.space3d.AbstractSpatial)1 Collidable (spacegraph.space3d.phys.Collidable)1 ECEF (spacegraph.util.geo.ECEF)1 GeoCoordinate (spacegraph.util.geo.osm.GeoCoordinate)1 Osm (spacegraph.util.geo.osm.Osm)1 OsmNode (spacegraph.util.geo.osm.OsmNode)1 OsmWay (spacegraph.util.geo.osm.OsmWay)1 Draw (spacegraph.video.Draw)1