Ignore:
Timestamp:
2010-04-18T23:40:01+02:00 (14 years ago)
Author:
pieren
Message:

add multi-cache management for buildings

Location:
applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/Buildings.java

    r20659 r20931  
    5555        public Point p;
    5656        public int dir;
     57        @SuppressWarnings("unused")
     58        public boolean toKeep;
    5759        public Pixel(int x, int y, int dir) {
    5860            this.p = new Point(x,y);
     
    6971            return p.equals(obj);
    7072        }
     73        @Override
     74        public String toString() {
     75            return new String("p="+p+", dir="+dir);
     76        }
    7177    }
    7278    private ArrayList<Pixel> listPixels = new ArrayList<Pixel>();
    7379   
    74     private static final int cMaxnode = 10000;
    75     private static final double cDistanceForOptimization = 0.7;
     80    //  5 6 7
     81    //   \|/
     82    //  4-*-0       'dir' index vs pixel direction
     83    //   /|\
     84    //  3 2 1
    7685    private int[] dirsX = new int[] {1,1,0,-1,-1,-1,0,1};
    7786    private int[] dirsY = new int[] {0,1,1,1,0,-1,-1,-1};
     
    8089    BuildingsImageModifier bim = new BuildingsImageModifier();
    8190
    82     private double snapDistance = Main.pref.getDouble("cadastrewms.snap-distance", 50); // in centimeters
     91    private static final int cMaxnode = 10000;
     92    private static final double cDistanceForOptimization = 0.5;
     93    private double snapDistance = Main.pref.getDouble("cadastrewms.snap-distance", 25); // in centimeters
     94    private double SimplifyFactor = 0.1;
     95
    8396    private double snapDistanceSq = snapDistance*snapDistance;
    8497    private double dx, dy;
    85 
    8698   
    8799    public Buildings(MapFrame mapFrame) {
     
    154166                    }
    155167                    wayToCreate.addNode(wayToCreate.getNode(0)); // close the way
    156                     new SimplifyWay().simplifyWay(wayToCreate, 0.2);
     168                    new SimplifyWay().simplifyWay(wayToCreate, SimplifyFactor);
    157169                    // move the node closing the loop and simplify again
    158170                    for (int i = 1; i < wayToCreate.getNodesCount(); i++) {
     
    160172                    }
    161173                    way2.addNode(way2.getNode(0));
    162                     new SimplifyWay().simplifyWay(way2, 0.2);
     174                    new SimplifyWay().simplifyWay(way2, SimplifyFactor);
    163175                    simplifyAngles(way2);
    164176                    Way wayToAdd = new Way();
     
    315327            addPixeltoList(x, y, new_dir);
    316328        }
     329        inflate();
    317330        System.out.println("list size="+listPixels.size());
    318331        return true;
     
    322335        listPixels.add( new Pixel(x, y, dir));
    323336        System.out.println("added pixel at "+x+","+y);
     337    }
     338   
     339    private void inflate() {
     340        // TODO
     341        if (listPixels.size() > 1) {
     342//            for (int i=1; i<listPixels.size()-1; i++) {
     343//                int delta_dir = Math.abs((listPixels.get(i+1).dir - listPixels.get(i-1).dir + 8)%8);
     344//                if (delta_dir > 1 && delta_dir < 4) {
     345//                    System.out.println(listPixels.get(i).dir);
     346//                    int j = i;
     347//                    if (listPixels.get(i).dir == 0 || listPixels.get(i).dir == 1 || listPixels.get(i).dir == 4 || listPixels.get(i).dir == 2)
     348//                        j = i-1;
     349//                    listPixels.get(j).toKeep = true;
     350//                    i+=2;
     351//                    selectedImage.image.setRGB(listPixels.get(j).p.x, listPixels.get(j).p.y, Color.GREEN.getRGB());
     352//                }
     353//            }
     354            ArrayList<Pixel> newList = new ArrayList<Pixel>();
     355            for (int i=0; i<listPixels.size(); i++) {
     356//                    selectedImage.image.setRGB(listPixels.get(i).p.x, listPixels.get(i).p.y, Color.GREEN.getRGB());
     357                boolean inflatedPixel = false;
     358                for (int j=0; j<3; j++) {
     359                    if ((i+j-1) > 0 && (i+j-1) < listPixels.size()) {
     360                        int inflate_dir = (listPixels.get(i+j-1).dir+6)%8;
     361                        Pixel p = new Pixel(listPixels.get(i).p.x+dirsX[inflate_dir],
     362                              listPixels.get(i).p.y+dirsY[inflate_dir],
     363                              listPixels.get(i).dir);
     364                        if (bim.isParcelColor(selectedImage.image, p.p.x, p.p.y)) {
     365                            if (!newList.contains(p))
     366                                newList.add(p);
     367                            inflatedPixel = true;
     368                        }
     369                    }
     370                }
     371                if (!inflatedPixel) {
     372                    if (!newList.contains(listPixels.get(i)))
     373                        newList.add(listPixels.get(i));
     374                }
     375            }
     376            listPixels = newList;
     377        }
    324378    }
    325379   
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/CacheControl.java

    r20824 r20931  
    9494    public boolean loadCacheIfExist() {
    9595        try {
    96             File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension());
    97             if (file.exists()) {
    98                 JOptionPane pane = new JOptionPane(
    99                         tr("Location \"{0}\" found in cache.\n"+
    100                         "Load cache first ?\n"+
    101                         "(No = new cache)", wmsLayer.getName()),
    102                         JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null);
    103                 // this below is a temporary workaround to fix the "always on top" issue
    104                 JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille"));
    105                 CadastrePlugin.prepareDialog(dialog);
    106                 dialog.setVisible(true);
    107                 int reply = (Integer)pane.getValue();
    108                 // till here
    109 
    110                 if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) {
    111                     return true;
    112                 } else {
    113                     delete(file);
     96            if (!wmsLayer.isBuildingsOnly()) {
     97                File file = new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "." + WMSFileExtension());
     98                if (file.exists()) {
     99                    JOptionPane pane = new JOptionPane(
     100                            tr("Location \"{0}\" found in cache.\n"+
     101                            "Load cache first ?\n"+
     102                            "(No = new cache)", wmsLayer.getName()),
     103                            JOptionPane.QUESTION_MESSAGE, JOptionPane.YES_NO_OPTION, null);
     104                    // this below is a temporary workaround to fix the "always on top" issue
     105                    JDialog dialog = pane.createDialog(Main.parent, tr("Select Feuille"));
     106                    CadastrePlugin.prepareDialog(dialog);
     107                    dialog.setVisible(true);
     108                    int reply = (Integer)pane.getValue();
     109                    // till here
     110   
     111                    if (reply == JOptionPane.OK_OPTION && loadCache(file, wmsLayer.getLambertZone())) {
     112                        return true;
     113                    } else {
     114                        delete(file);
     115                    }
    114116                }
     117            } else {
     118                int i=0;
     119                while (new File(CadastrePlugin.cacheDir + wmsLayer.getName() + "."+i+"."+ WMSFileExtension()).exists())
     120                    i++;
     121                wmsLayer.setName(wmsLayer.getName()+"."+i);
    115122            }
    116123        } catch (Exception e) {
  • applications/editors/josm/plugins/cadastre-fr/src/cadastre_fr/ImageModifier.java

    r20390 r20931  
    132132    }
    133133
     134    public boolean isParcelColor(BufferedImage img, int x, int y) {
     135        int rgb = img.getRGB(x, y);
     136        return (rgb == parcelColor);
     137    }
     138
    134139    public boolean isBuildingOrRoofColor(BufferedImage img, int x, int y, boolean ignoreParcelColor) {
    135140        int rgb = img.getRGB(x, y);
     
    147152        return ret;
    148153    }
    149 
     154   
    150155    /**
    151156     * Checks if the rgb value is the black background color
Note: See TracChangeset for help on using the changeset viewer.