Package org.codemap.util

Examples of org.codemap.util.StopWatch


            byte[] shoreColor = colorScheme().getShoreColor().asByte();
           
            int shorelineHeight = map.get(SHORELINE_HEIGHT);
            int hillineHeight = map.get(HILLLINE_HEIGHT);
           
            StopWatch nnStopWatch = new StopWatch("nearest neighbor (total)");
            for(int i=0; i < mapSize*mapSize; i++) {
                int y = i / mapSize;
                int x = i % mapSize;
               
                if (DEM[x][y] <= shorelineHeight) {
                    // water color
                    System.arraycopy(waterColor, 0, imageBytes, i*3, 3);
                    alphaBytes[i] = (byte) 255;
                    continue;
                } else if (DEM[x][y] <= hillineHeight) {
                    // shore colors
                    System.arraycopy(shoreColor, 0, imageBytes, i*3, 3);
                    alphaBytes[i] = (byte) 255;
                    continue;
                }
                // get color from location a.k.a. hill colors
                nnStopWatch.start();
                Location nearestNeighbor = map.nearestNeighbor(x, y);
                MColor mcolor;
                if (nearestNeighbor == null) {
                    mcolor = colorScheme().getHillColor();
                } else {
                    mcolor = colors.forLocation(nearestNeighbor.getPoint());                   
                }
                nnStopWatch.stop();
                // make rgb
                int baseIndex = i*3;
                imageBytes[baseIndex++] = (byte) mcolor.getRed(); // R
                imageBytes[baseIndex++] = (byte) mcolor.getGreen(); // G
                imageBytes[baseIndex++] = (byte) mcolor.getBlue(); // B
               
                // make alpha
                // 0 for fully transparent
                // 255 for fully opaque
                double f = shade[x][y];
                assert f <=1;
                // alpha values can get negative somehow so we fix that
                int alpha = (int) Math.max(0.0, 255*f);
                alphaBytes[i] = (byte) alpha;
            }
            nnStopWatch.print();
            // define a direct palette with masks for RGB
            PaletteData palette = new PaletteData(0xFF0000 , 0xFF00 , 0xFF);  
            ImageData imageData = new ImageData(mapSize, mapSize, 24, palette, mapSize*3, imageBytes);
            // enable alpha by setting alphabytes ... strange that i can't do that per pixel using 32bit values
            imageData.alphaData = alphaBytes;
View Full Code Here


        compute();
        return DEM;
    }

    private void compute() {
        StopWatch stopWatch = new StopWatch("DEM").start();
        // TODO a map configuration on map should return locations on map
        for (Location each: map.getDEMLocations()) {
            elevateHill(each, computePie(each));
        }
        stopWatch.printStop();
    }
View Full Code Here

        return hillShading;
    }

    private void paintBackground(ProgressMonitor monitor, GC gc, MapInstance mapInstance, DigitalElevationModel elevationModel, HillShading hillShading, MapScheme<MColor> colors) {
        if (elevationModel == null) {
            StopWatch stopWatch = new StopWatch("Background (Draft)").start();
            paintDraft(monitor, gc, mapInstance);
            stopWatch.printStop();
        }
        else {
            StopWatch stopWatch = new StopWatch("Background").start();
            paintHills(monitor, gc, mapInstance, elevationModel, hillShading, colors);
            stopWatch.printStop();
        }
    }
View Full Code Here

    private static final double Z_FACTOR_MULT = 1e-3;
    public static final MapSetting<Integer> CONTOUR_STEP = MapSetting.define("CONTOUR_STEP", 10);

    @Override
    public double[][] call() {
        StopWatch stopWatch = new StopWatch("HillShade").start();
       
        // zenith: height of sun over horizon (90 = horizon, 0 = zenith).
        double zenithRad = 45 * PI / 180;
        // azimuth: direction of sun on x-y-plane
        double azimuthRad = (315 - 180) * PI / 180;
       
       
        // generate magic factor that takes darken factor of color scheme into account
        // furthermore, it adapts to the map-size
        double z_factor = (1.1 - colorScheme().getDarkenFactor()) * Z_FACTOR_MULT * map.getWidth();
       
        int step = map.get(CONTOUR_STEP);
       
        double[][] hillshade = new double[map.width][map.width];
        float[][] DEM = map.getDEM();
       
        int width = map.width;
       
        double contour_darken_factor = colorScheme().getDarkenFactor();
       
        for (int x = 0; x < width; x++) {
            for (int y = 0; y < width; y++) {
                float here = DEM[x][y];
                if (here == 0.0) continue;
               
                // build kernel
                int yTop = (y == 0 ? 0 : y - 1);
                int xLeft = (x == 0 ? 0 : x - 1);
                int yBottom = (y == (width -1) ? (width - 1) : y + 1);
                int xRight = (x == (width - 1) ? (width - 1) : x + 1);               

                float topLeft = DEM[xLeft][yTop];
                float top = DEM[x][yTop];
                float topRight = DEM[xRight][yTop];
                float left = DEM[xLeft][y];
                float right = DEM[xRight][y];
                float bottomLeft = DEM[xLeft][yBottom];
                float bottom = DEM[x][yBottom];
                float bottomRight = DEM[xRight][yBottom];
               
                // calculate hillshading
                double dx = (topRight + (2 * right) + bottomRight - (topLeft + (2 * left) + bottomLeft)) / 8;
                double dy = (bottomLeft + (2 * bottom) + bottomRight - (topLeft + (2 * top) + topRight)) / 8;
                double slopeRad = atan(z_factor * sqrt(dx * dx + (dy * dy)));
                double aspectRad = atan2(dy, -dx);
                double shading = (cos(zenithRad) * cos(slopeRad) + (sin(zenithRad) * sin(slopeRad) * cos(azimuthRad
                        - aspectRad)));
                hillshade[x][y] = shading; //min(0.5, shading);
               
                // calculate contourlines
                int topHeight = (int) Math.floor(top / step);
                int leftHeight = (int) Math.floor(left / step);
                int hereHeight = (int) Math.floor(here / step);
                boolean isCoastline = topHeight == 0 || leftHeight == 0 || hereHeight == 0;
                boolean isContourLine = (topHeight != hereHeight || leftHeight != hereHeight) && !isCoastline;
                if (isContourLine) {
                    hillshade[x][y] *= contour_darken_factor;
                }
            }
        }
        stopWatch.printStop();
        return hillshade;
    }
View Full Code Here

TOP

Related Classes of org.codemap.util.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.