Changeset 28027 in osm for applications/editors
- Timestamp:
- 2012-03-10T06:18:26+01:00 (13 years ago)
- Location:
- applications/editors/josm/plugins
- Files:
-
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationCandidateList.java
r27971 r28027 1 /*2 * To change this template, choose Tools | Templates3 * and open the template in the editor.4 */5 1 package org.openstreetmap.josm.plugins.conflation; 6 2 -
applications/editors/josm/plugins/conflation/src/org/openstreetmap/josm/plugins/conflation/ConflationToggleDialog.java
r27997 r28027 1 1 package org.openstreetmap.josm.plugins.conflation; 2 2 3 import utilsplugin2.dumbutils.HungarianAlgorithm; 3 4 import java.awt.BorderLayout; 4 5 import java.awt.Component; … … 206 207 @Override 207 208 public void actionPerformed(ActionEvent e) { 209 //FIXME: should layer listen for selection change? 208 210 ConflationCandidate c = conflationLayer.getSelectedCandidate(); 211 if (c.getReferenceLayer() != c.getSubjectLayer()) { 212 JOptionPane.showMessageDialog(Main.parent, tr("Conflation between layers isn't supported yet."), 213 tr("Cannot conflate between layes"), JOptionPane.ERROR_MESSAGE); 214 return; 215 } 209 216 if (ReplaceGeometryUtils.replace(c.getReferenceObject(), c.getSubjectObject())) { 210 217 candidates.remove(c); … … 331 338 int n = subjectSelection.size(); 332 339 int m = referenceSelection.size(); 333 int maxLen = Math.max(n, m); 334 double cost[][] = new double[maxLen][maxLen]; 340 double cost[][] = new double[n][m]; 335 341 336 342 // calculate cost matrix … … 345 351 OsmPrimitive subObject, refObject; 346 352 candidates.clear(); 347 for (int i = 0; i < maxLen; i++) {353 for (int i = 0; i < n; i++) { 348 354 int subIdx = assignment[i][0]; 349 355 int refIdx = assignment[i][1]; -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/HungarianAlgorithm.java
r28026 r28027 37 37 */ 38 38 39 package org.openstreetmap.josm.plugins.conflation;39 package utilsplugin2.dumbutils; 40 40 41 41 import static java.lang.Math.*; -
applications/editors/josm/plugins/utilsplugin2/src/utilsplugin2/dumbutils/ReplaceGeometryUtils.java
r27997 r28027 256 256 257 257 // Prepare a list of nodes that are not used anywhere except in the way 258 Collection<Node> nodePool = getUnimportantNodes(subjectWay);258 List<Node> nodePool = getUnimportantNodes(subjectWay); 259 259 260 260 // And the same for geometry, list nodes that can be freely deleted 261 Set<Node> geometryPool = new HashSet<Node>();261 List<Node> geometryPool = new LinkedList<Node>(); 262 262 for( Node node : referenceWay.getNodes() ) { 263 263 List<OsmPrimitive> referrers = node.getReferrers(); 264 264 if( node.isNew() && !node.isDeleted() && referrers.size() == 1 265 265 && referrers.get(0).equals(referenceWay) && !subjectWay.containsNode(node) 266 && !hasInterestingKey(node) )266 && !hasInterestingKey(node) && !geometryPool.contains(node)) 267 267 geometryPool.add(node); 268 268 } 269 269 270 270 // Find new nodes that are closest to the old ones, remove matching old ones from the pool 271 // Assign node moves with least overall distance moved 271 272 Map<Node, Node> nodeAssoc = new HashMap<Node, Node>(); 272 for( Node n : geometryPool ) { 273 Node nearest = findNearestNode(n, nodePool); 274 if( nearest != null ) { 275 nodeAssoc.put(n, nearest); 276 nodePool.remove(nearest); 277 } 273 if (geometryPool.size() > 0 && nodePool.size() > 0) { 274 int gLen = geometryPool.size(); 275 int nLen = nodePool.size(); 276 double cost[][] = new double[nLen][gLen]; 277 278 double maxDistance = Double.parseDouble(Main.pref.get("utilsplugin2.replace-geometry.max-distance", "1")); 279 for (int i = 0; i < nLen; i++) { 280 for (int j = 0; j < gLen; j++) { 281 double d = nodePool.get(i).getCoor().distance(geometryPool.get(j).getCoor()); 282 if (d > maxDistance) 283 cost[i][j] = Double.MAX_VALUE; 284 else 285 cost[i][j] = d; 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 } 297 298 // node will be moved, remove from pool 299 for (Node n : nodeAssoc.values()) { 300 nodePool.remove(n); 278 301 } 279 302 … … 319 342 * @return 320 343 */ 321 protected static Collection<Node> getUnimportantNodes(Way way) {322 Set<Node> nodePool = new HashSet<Node>();344 protected static List<Node> getUnimportantNodes(Way way) { 345 List<Node> nodePool = new LinkedList<Node>(); 323 346 for (Node n : way.getNodes()) { 324 347 List<OsmPrimitive> referrers = n.getReferrers(); 325 348 if (!n.isDeleted() && referrers.size() == 1 && referrers.get(0).equals(way) 326 && !hasInterestingKey(n) ) {349 && !hasInterestingKey(n) && !nodePool.contains(n)) { 327 350 nodePool.add(n); 328 351 }
Note:
See TracChangeset
for help on using the changeset viewer.