Changeset 28045 in osm for applications/editors
- Timestamp:
- 2012-03-11T19:45:24+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/utilsplugin2/src/org/openstreetmap/josm/plugins/utilsplugin2/replacegeometry/ReplaceGeometryUtils.java
r28028 r28045 264 264 } 265 265 266 boolean useHungarian = Main.pref.getBoolean("utilsplugin2.replace-geometry.robustAssignment", false); 267 266 268 // Find new nodes that are closest to the old ones, remove matching old ones from the pool 267 269 // Assign node moves with least overall distance moved 268 270 Map<Node, Node> nodeAssoc = new HashMap<Node, Node>(); 269 271 if (geometryPool.size() > 0 && nodePool.size() > 0) { 270 int gLen = geometryPool.size(); 271 int nLen = nodePool.size(); 272 double cost[][] = new double[nLen][gLen]; 273 274 double maxDistance = Double.parseDouble(Main.pref.get("utilsplugin2.replace-geometry.max-distance", "1")); 275 for (int i = 0; i < nLen; i++) { 276 for (int j = 0; j < gLen; j++) { 277 double d = nodePool.get(i).getCoor().distance(geometryPool.get(j).getCoor()); 278 if (d > maxDistance) 279 cost[i][j] = Double.MAX_VALUE; 280 else 281 cost[i][j] = d; 282 } 283 } 284 int[][] assignment = HungarianAlgorithm.hgAlgorithm(cost, "min"); 285 for (int i = 0; i < nLen; i++) { 286 int nIdx = assignment[i][0]; 287 int gIdx = assignment[i][1]; 288 if (cost[nIdx][gIdx] != Double.MAX_VALUE) { 289 nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx)); 290 } 291 } 292 } 293 294 // node will be moved, remove from pool 295 for (Node n : nodeAssoc.values()) { 296 nodePool.remove(n); 272 if (useHungarian) { // use robust, but slower assignment 273 int gLen = geometryPool.size(); 274 int nLen = nodePool.size(); 275 double cost[][] = new double[nLen][gLen]; 276 277 double maxDistance = Double.parseDouble(Main.pref.get("utilsplugin2.replace-geometry.max-distance", "1")); 278 for (int i = 0; i < nLen; i++) { 279 for (int j = 0; j < gLen; j++) { 280 double d = nodePool.get(i).getCoor().distance(geometryPool.get(j).getCoor()); 281 if (d > maxDistance) { 282 cost[i][j] = Double.MAX_VALUE; 283 } else { 284 cost[i][j] = d; 285 } 286 } 287 } 288 int[][] assignment = HungarianAlgorithm.hgAlgorithm(cost, "min"); 289 for (int i = 0; i < nLen; i++) { 290 int nIdx = assignment[i][0]; 291 int gIdx = assignment[i][1]; 292 if (cost[nIdx][gIdx] != Double.MAX_VALUE) { 293 nodeAssoc.put(geometryPool.get(gIdx), nodePool.get(nIdx)); 294 } 295 } 296 // node will be moved, remove from pool 297 for (Node n : nodeAssoc.values()) { 298 nodePool.remove(n); 299 } 300 } else { // use simple, faster, but less robust assignment method 301 for (Node n : geometryPool) { 302 Node nearest = findNearestNode(n, nodePool); 303 if (nearest != null) { 304 nodeAssoc.put(n, nearest); 305 nodePool.remove(nearest); 306 } 307 } 308 309 } 297 310 } 298 311
Note:
See TracChangeset
for help on using the changeset viewer.