Package org.codemap

Examples of org.codemap.MapInstance


    public void nearestNeighborRegression() {
        final HashMap<Point, Integer> points = new HashMap<Point, Integer>();
        QuickNDirtyMap.anotherDebugPointSet(points);
     
        Configuration configuration = new Configuration(points.keySet());
        MapInstance mapInstance = configuration.withSize(mapSize, new MapScheme<Double>() {
            @Override
            public Double forLocation(Point location) {
                // TODO fill in size
                return (double) points.get(location);

            }
        });
       
        int badCount = 0;
        for(int x = 0; x < mapInstance.width; x++) {
            for (int y = 0; y < mapInstance.height; y++) {
                Location kdTreeNearest = mapInstance.kdTreeNearest(x, y);
                Location naiveNearest = mapInstance.naiveNearest(x, y);
                if (naiveNearest.equals(kdTreeNearest)) continue;
               
                badCount++;
//                assertEquals(naiveNearest, kdTreeNearest);
            }
View Full Code Here


        if (! model.isEnabled()) return;
        if (map.mapSize.getValue() != mapSize || model.isDirty() || !isInitialized()) {
            mapSize = map.mapSize.getValue();
            model.setClean();
           
            MapInstance value = map.mapInstance.getValue();
            // map not yet available
            if (value == null) return;
            Iterable<Location> locations = value.locations();
            createGraphs(locations);
            createRenderers();
        }
       
        gc.setAlpha(255);
View Full Code Here

            int fontsize = (points.get(each))/3;
            labels.add(new Label(x-20, y-60, extent, fontsize, each.getDocument(), new Location(each, 0, x, y)));
        }
        labeling = new Labeling(labels);
       
        MapInstance mapInstance = configuration.withSize(mapSize, new MapScheme<Double>() {
            @Override
            public Double forLocation(Point location) {
                // TODO fill in size
                return (double) points.get(location);

            }
        })
       
        DEMAlgorithm algorithm = new DEMAlgorithm();
        algorithm.setMap(mapInstance);
        float[][] DEM = algorithm.call();
       
        ShadeAlgorithm hsa = new ShadeAlgorithm();
        hsa.setMap(mapInstance);
        double[][] shading = hsa.call();
       
        int mapSize = mapInstance.getWidth();
        Device device = Display.getCurrent();
        background = new Image(device, mapSize, mapSize);
        GC gc = new GC(background);
       
        String makeRed = "MapPerProject";
       
        CodemapColors colors = new CodemapColors();
        colors.setColor(makeRed, new MColor(255, 0, 0));
        Iterable<Location> locations = mapInstance.locations();
        ColorBrewer colorBrewer = new ColorBrewer();
        for (Location location : locations) {
            MColor color = colorBrewer.forPackage(location.getDocument());
            colors.setColor(location.getDocument(), color);
        }
       
        Color black = new Color(gc.getDevice(), 0, 0, 0);
        gc.setBackground(black);
        gc.fillRectangle(gc.getClipping());
        black.dispose();       
        Image image = new FastBackgroundRenderer(DEM, shading, mapInstance, colors, device).render();       
        gc.drawImage(image, 0, 0);
       
       
        gc.setForeground(new Color(gc.getDevice(), 255, 0, 0));
        for(int x = 0; x < mapInstance.width; x++) {
            for (int y = 0; y < mapInstance.height; y++) {
                Location kdTreeNearest = mapInstance.kdTreeNearest(x, y);
                Location naiveNearest = mapInstance.naiveNearest(x, y);
                if (naiveNearest.equals(kdTreeNearest)) continue;
               
                gc.drawPoint(x, y);
//                assertEquals(naiveNearest, kdTreeNearest);
            }
        }       
       
//        gc.setForeground(new Color(gc.getDevice(), 123, 0, 0));
//        ImageData id = image.getImageData();
//        for(int x = 0; x < id.width; x++) {
//            for (int y = 0; y < id.height; y++) {
//                Location nn = mapInstance.nearestNeighbor(x, y);
//                if (! nn.getDocument().equals(makeRed)) continue;
//                gc.drawPoint(x, y);
//            }
//        }
        gc.dispose();
       
//        Location mpp = getLocation(mapInstance, "MapPerProject");
//        Location dda = getLocation(mapInstance, "ColorDropDownAction");       
//        System.out.println("Distance to MapPerProject: " +  Math.sqrt(Math.pow(575 - mpp.px, 2) + Math.pow(500 - mpp.py, 2)));
//        System.out.println("Distance to ColorDropDownAction: " + Math.sqrt(Math.pow(575 - dda.px, 2) + Math.pow(500 - dda.py, 2)));
       
//        KdTree kdTree = mapInstance.getKdTree();
//        kdTree.setLog(new DebugLog());
        System.out.println(mapInstance.nearestNeighbor(575, 500).getDocument());
    }
View Full Code Here

        // does nothing       
    }   

    private final void paintChildren(MapValues map, GC gc) {
        MapSelection selection = this.getSelection(map);
        MapInstance mapInstance = map.mapInstance.getValue();
        if (selection == null || mapInstance == null) return;
        for (Location each: selection.locationsOn(map)) {
            paintChild(map, gc, each);
        }
    }
View Full Code Here

        dragStop = dragStart = new Point(e.x, e.y)
    }

    @Override
    public void mouseDoubleClick(MouseEvent e) {
        MapInstance map = CodemapVisualization.mapValues(e).mapInstance.getValue();
        if (map == null) return;
        Location neighbor = map.nearestNeighbor(e.x, e.y);
        if (neighbor == null) return;
       
        IResource resource = Resources.asResource(neighbor.getDocument());
        if (!(resource instanceof IFile))
            return;
View Full Code Here

       
        gc.drawOval(each.px-magic_r, each.py-magic_r, magic_r*2, magic_r*2);
    }
   
    private void updateSelection(MapValues map) {
        MapInstance mapInstance = map.mapInstance.getValue();
        if (mapInstance == null) return;
        int minX = Math.min(dragStart.x, dragStop.x);
        int minY = Math.min(dragStart.y, dragStop.y);
        int maxX = Math.max(dragStart.x, dragStop.x);
        int maxY = Math.max(dragStart.y, dragStop.y);   
        Collection<String> ids = new ArrayList<String>();
        for (Location each : mapInstance.locations()) {
            if (each.px < maxX && each.px > minX && each.py < maxY && each.py > minY) {     
                ids.add(each.getDocument());
            }
        }
        getSelection(map).replaceAll(ids);
View Full Code Here

        this.updateTooltip(e);
        super.mouseMove(e);
    }

    private void updateTooltip(MouseEvent e) {
        MapInstance map = mapValues.mapInstance.getValue();
        if (map == null) return;
        Location nearestNeighbor = map.nearestNeighbor(e.x, e.y);
       
        boolean noName = map.isEmpty() || !map.containsPoint(e.x, e.y) || nearestNeighbor == null;
        String name = noName ? null : nearestNeighbor.getName();
        textUpdater.updateNearestNeighbor(name);
    }
View Full Code Here

        super("Label layout", mapInstance, labelScheme);
    }

    @Override
    protected Labeling computeValue(ProgressMonitor monitor, Arguments arguments) {
        MapInstance mapInstance = arguments.nextOrFail();
        MapScheme<String> labelScheme = arguments.nextOrFail();
        if (labelScheme == null) labelScheme = new DefaultLabelScheme();
        return computeValue(monitor, mapInstance, labelScheme);
    }
View Full Code Here

        super("Computing hill shading", mapInstance, elevationModel);
    }

    @Override
    protected HillShading computeValue(ProgressMonitor monitor, Arguments arguments) {
        MapInstance mapInstance = arguments.nextOrFail();
        DigitalElevationModel elevationModel = arguments.nextOrFail();
        return computeValue(monitor, mapInstance, elevationModel);
    }
View Full Code Here

        super("Creating digital elevation model", mapInstance, hills);
    }

    @Override
    protected DigitalElevationModel computeValue(ProgressMonitor monitor, Arguments arguments) {
        MapInstance map = arguments.nextOrFail();
        MapScheme<Boolean> hills = arguments.nextOrFail();
        if (hills == null) hills = new MapScheme<Boolean>(true);
        return computeValue(monitor, map, hills);
    }
View Full Code Here

TOP

Related Classes of org.codemap.MapInstance

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.