Changeset 6914 in osm for applications/editors/josm/plugins/lakewalker
- Timestamp:
- 2008-02-18T14:00:37+01:00 (17 years ago)
- Location:
- applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/Lakewalker.java
r6913 r6914 111 111 int v; 112 112 113 setStatus("Looking for shoreline..."); 114 113 115 while(true){ 114 116 double[] geo = xy_to_geo(xy[0],xy[1],this.resolution); … … 136 138 int[] startxy = new int[] {xy[0], xy[1]}; 137 139 double[] startgeo = xy_to_geo(xy[0],xy[1],this.resolution); 138 139 System.out.println("Found shore at "+startxy[0]+","+startxy[1]); 140 140 141 141 System.out.printf("Found shore at lat %.4f lon %.4f\n",lat,lon); 142 142 … … 145 145 for(int i = 0; i < this.maxnode; i++){ 146 146 147 // Print a counter 147 148 if(i % 250 == 0){ 149 setStatus(i+" nodes so far..."); 148 150 System.out.println(i+" nodes so far..."); 149 151 } … … 155 157 int new_dir = 0; 156 158 159 // Loop through all the directions we can go 157 160 for(d = 1; d <= this.dirslat.length; d++){ 158 161 162 // Decide which direction we want to look at from this pixel 159 163 new_dir = (last_dir + d + 4) % 8; 160 164 … … 165 169 166 170 if(!bbox.contains(geo[0], geo[1])){ 171 /** 172 * TODO: Handle this case 173 */ 167 174 System.out.println("Outside bbox"); 168 175 break; … … 182 189 // Remember this direction 183 190 last_dir = new_dir; 191 192 // Set the pixel we found as current 184 193 xy[0] = test_x; 185 194 xy[1] = test_y; 186 195 196 // Break the loop if we managed to get back to our starting point 187 197 if(xy[0] == startxy[0] && xy[1] == startxy[1]){ 188 198 break; 189 199 } 190 200 201 // Store this node 191 202 double[] geo = xy_to_geo(xy[0],xy[1],this.resolution); 192 203 nodelist.add(geo); 193 204 System.out.println("Adding node at "+xy[0]+","+xy[1]+" ("+geo[1]+","+geo[0]+")"); 194 205 206 // Check if we got stuck in a loop 195 207 double start_proximity = Math.pow((geo[0] - startgeo[0]),2) + Math.pow((geo[1] - startgeo[1]),2); 196 208 -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r6910 r6914 150 150 */ 151 151 152 setStatus("Running vertex reduction..."); 153 152 154 nodelist = lw.vertex_reduce(nodelist, epsilon); 153 155 … … 155 157 156 158 /** 157 * And then through douglas-peucker reduction 158 */ 159 * And then through douglas-peucker approximation 160 */ 161 162 setStatus("Running Douglas-Peucker approximation..."); 159 163 160 164 nodelist = lw.douglas_peucker(nodelist, epsilon); … … 266 270 public void mouseReleased(MouseEvent e) { 267 271 } 268 272 protected void setStatus(String s) { 273 Main.pleaseWaitDlg.currentAction.setText(s); 274 Main.pleaseWaitDlg.repaint(); 275 } 269 276 } -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerWMS.java
r6913 r6914 11 11 import java.awt.image.*; 12 12 import java.awt.geom.*; 13 import java.util.*; 13 14 14 15 public class LakewalkerWMS { 15 16 public LakewalkerWMS(){17 18 }19 16 20 17 private BufferedImage image; 21 18 private int imagex; 22 19 private int imagey; 20 21 // Vector to cache images in memory 22 private Vector<BufferedImage> images = new Vector<BufferedImage>(); 23 // Hashmap to hold the mapping of cached images 24 private HashMap<String,Integer> imageindex = new HashMap<String,Integer>(); 23 25 24 26 public BufferedImage image2 = new BufferedImage(2000, 2000, BufferedImage.TYPE_INT_RGB); … … 63 65 File file = new File(this.working_dir,filename); 64 66 67 // Calculate the hashmap key 68 String hashkey = Integer.toString(bottom_left_xy[0])+":"+Integer.toString(bottom_left_xy[1]); 69 65 70 // See if this image is already loaded 66 if(this.image != null){ 71 if(this.image != null){ 67 72 if(this.imagex != bottom_left_xy[0] || this.imagey != bottom_left_xy[1]){ 68 this.image = null; 73 74 // Check if this image exists in the hashmap 75 if(this.imageindex.containsKey(hashkey)){ 76 // Store which image we have 77 this.imagex = bottom_left_xy[0]; 78 this.imagey = bottom_left_xy[1]; 79 80 // Retrieve from cache 81 this.image = this.images.get(this.imageindex.get(hashkey)); 82 return this.image; 83 } else { 84 this.image = null; 85 } 69 86 } else { 70 87 return this.image; … … 73 90 74 91 try { 75 System.out.println("Looking for image in cache: "+filename);92 System.out.println("Looking for image in disk cache: "+filename); 76 93 77 94 // Read from a file 78 95 this.image = ImageIO.read(file); 79 96 97 this.images.add(this.image); 98 this.imageindex.put(hashkey,this.images.size()-1); 99 80 100 } catch(FileNotFoundException e){ 81 101 System.out.println("Could not find cached image, downloading."); … … 104 124 } 105 125 126 this.images.add(this.image); 127 this.imageindex.put(hashkey,this.images.size()-1); 128 106 129 this.saveimage(file,this.image); 107 130 }
Note:
See TracChangeset
for help on using the changeset viewer.