Changeset 6923 in osm for applications/editors/josm/plugins
- Timestamp:
- 2008-02-19T01:24:25+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
r6914 r6923 119 119 } 120 120 121 v = wms.getPixel(xy[0], xy[1],0xFF00FF00); 122 if(v < 0){ 123 return null; 124 } 125 121 v = wms.getPixel(xy[0], xy[1]); 126 122 if(v > this.threshold){ 127 123 break; … … 169 165 170 166 if(!bbox.contains(geo[0], geo[1])){ 171 /**172 * TODO: Handle this case173 */174 167 System.out.println("Outside bbox"); 175 168 break; 176 169 } 177 170 178 v = wms.getPixel(test_x, test_y ,0xFF0000FF);171 v = wms.getPixel(test_x, test_y); 179 172 if(v > this.threshold){ 180 173 break; … … 218 211 } 219 212 } 220 221 // DEBUG 222 File f = new File(this.workingdir,"temp.png"); 223 wms.saveimage(f,wms.image2); 224 213 225 214 return nodelist; 226 215 } 227 216 228 public ArrayList<double[]> vertex_reduce(ArrayList<double[]> nodes, double proximity){ 217 /** 218 * Remove duplicate nodes from the list 219 * 220 * @param nodes 221 * @return 222 */ 223 public ArrayList<double[]> duplicateNodeRemove(ArrayList<double[]> nodes){ 224 225 double lastnode[] = new double[] {nodes.get(0)[0], nodes.get(0)[1]}; 226 227 for(int i = 1; i < nodes.size(); i++){ 228 double[] thisnode = new double[] {nodes.get(i)[0], nodes.get(i)[1]}; 229 230 if(thisnode[0] == lastnode[0] && thisnode[1] == lastnode[1]){ 231 // Remove the node 232 nodes.remove(i); 233 234 // Shift back one index 235 i = i - 1; 236 } 237 lastnode = thisnode; 238 } 239 240 return nodes; 241 } 242 243 /** 244 * Reduce the number of vertices based on their proximity to each other 245 * 246 * @param nodes 247 * @param proximity 248 * @return 249 */ 250 public ArrayList<double[]> vertexReduce(ArrayList<double[]> nodes, double proximity){ 251 252 // Check if node list is empty 253 if(nodes.size()==0){ 254 return nodes; 255 } 256 229 257 double[] test_v = nodes.get(0); 230 258 ArrayList<double[]> reducednodes = new ArrayList<double[]>(); … … 242 270 } 243 271 244 public double point _line_distance(double[] p1, double[] p2, double[] p3){272 public double pointLineDistance(double[] p1, double[] p2, double[] p3){ 245 273 246 274 double x0 = p1[0]; … … 258 286 } 259 287 260 public ArrayList<double[]> douglas_peucker(ArrayList<double[]> nodes, double epsilon){ 288 public ArrayList<double[]> douglasPeucker(ArrayList<double[]> nodes, double epsilon){ 289 290 // Check if node list is empty 291 if(nodes.size()==0){ 292 return nodes; 293 } 294 261 295 int farthest_node = -1; 262 296 double farthest_dist = 0; … … 269 303 270 304 for(int i = 1; i < nodes.size(); i++){ 271 d = point _line_distance(nodes.get(i),first,last);305 d = pointLineDistance(nodes.get(i),first,last); 272 306 if(d>farthest_dist){ 273 307 farthest_dist = d; … … 280 314 281 315 if(farthest_dist > epsilon){ 282 seg_a = douglas _peucker(sublist(nodes,0,farthest_node+1),epsilon);283 seg_b = douglas _peucker(sublist(nodes,farthest_node,nodes.size()-1),epsilon);316 seg_a = douglasPeucker(sublist(nodes,0,farthest_node+1),epsilon); 317 seg_b = douglasPeucker(sublist(nodes,farthest_node,nodes.size()-1),epsilon); 284 318 285 319 new_nodes.addAll(seg_a); … … 353 387 354 388 protected Boolean contains(double lat, double lon){ 355 if(lat > this.top || lat <this.bottom){389 if(lat >= this.top || lat <= this.bottom){ 356 390 return false; 391 } 392 if(lon >= this.right || lon <= this.left){ 393 return false; 357 394 } 358 395 if((this.right - this.left) % 360 == 0){ -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerAction.java
r6914 r6923 152 152 setStatus("Running vertex reduction..."); 153 153 154 nodelist = lw.vertex _reduce(nodelist, epsilon);154 nodelist = lw.vertexReduce(nodelist, epsilon); 155 155 156 156 System.out.println("After vertex reduction "+nodelist.size()+" nodes remain."); … … 162 162 setStatus("Running Douglas-Peucker approximation..."); 163 163 164 nodelist = lw.douglas _peucker(nodelist, epsilon);164 nodelist = lw.douglasPeucker(nodelist, epsilon); 165 165 166 166 System.out.println("After Douglas-Peucker approximation "+nodelist.size()+" nodes remain."); 167 167 168 /** 169 * And then through a duplicate node remover 170 */ 171 172 setStatus("Removing duplicate nodes..."); 173 174 nodelist = lw.duplicateNodeRemove(nodelist); 175 176 System.out.println("After removing duplicate nodes, "+nodelist.size()+" nodes remain."); 177 178 168 179 /** 169 180 * Turn the arraylist into osm nodes … … 225 236 } 226 237 227 commands.add(new AddCommand(way));238 228 239 String waytype = Main.pref.get(LakewalkerPreferences.PREF_WAYTYPE, "water"); 229 240 … … 236 247 way.nodes.add(fn); 237 248 249 commands.add(new AddCommand(way)); 238 250 239 251 if (!commands.isEmpty()) { … … 243 255 System.out.println("Failed"); 244 256 } 257 258 commands = new LinkedList<Command>(); 259 ways = new ArrayList<Way>(); 260 245 261 } 246 262 -
applications/editors/josm/plugins/lakewalker/src/org/openstreetmap/josm/plugins/lakewalker/LakewalkerWMS.java
r6914 r6923 23 23 // Hashmap to hold the mapping of cached images 24 24 private HashMap<String,Integer> imageindex = new HashMap<String,Integer>(); 25 26 public BufferedImage image2 = new BufferedImage(2000, 2000, BufferedImage.TYPE_INT_RGB);27 25 28 26 private int resolution; … … 152 150 } 153 151 154 public int getPixel(int x, int y , int pixcol){152 public int getPixel(int x, int y) throws LakewalkerException{ 155 153 156 154 BufferedImage image = null; … … 160 158 } catch(LakewalkerException e){ 161 159 System.out.println(e.getError()); 162 return -1;160 throw new LakewalkerException(e.getMessage()); 163 161 } 164 162 … … 173 171 int rgb = image.getRGB(pixel_x,pixel_y); 174 172 175 // DEBUG: set the pixels176 this.image2.setRGB(pixel_x,pixel_y,pixcol);177 178 173 int pixel; 179 174 … … 182 177 int b = (rgb >> 0) & 0xff; 183 178 184 //pixel = rgbToGrey(pixel); //(r+g+b)/3; //pixel & 0xff;185 186 int pixel2 = (int)((0.212671 * r) + (0.715160 * b) + (0.072169 * b));187 188 179 pixel = (int)((0.30 * r) + (0.59 * b) + (0.11 * g)); 189 180 190 //System.out.println(pixel_y+","+pixel_x+" "+r+","+g+","+b+"="+pixel+"("+pixel2+")");191 192 181 return pixel; 193 182 } 194 183 195 private int rgbToGrey(int color) {196 Color c = new Color(color);197 int red = c.getRed();198 int green = c.getGreen();199 int blue = c.getBlue();200 int tot = (red + green + blue) / 3;201 return tot;202 }203 204 184 public int floor(int num, int precision){ 205 185 double dnum = num/(double)precision; … … 214 194 return val.doubleValue() ; 215 195 } 216 196 217 197 public double[] xy_to_geo(int x, int y, double resolution){ 218 198 double[] geo = new double[2];
Note:
See TracChangeset
for help on using the changeset viewer.