Changeset 26303 in osm
- Timestamp:
- 2011-07-11T20:27:27+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLine.java
r26264 r26303 8 8 import java.util.ListIterator; 9 9 import java.util.Set; 10 import javax.xml.stream.events.StartDocument; 10 11 import org.openstreetmap.josm.data.coor.LatLon; 11 12 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 105 106 } 106 107 108 /** 109 * Increase epsilon to fit points count in maxPKM point per 1 km 110 */ 111 double autoSimplify(double initEpsilon,double ekf,double maxPKM) { 112 double e=initEpsilon; 113 if (e<1e-3) e=1e-3; 114 if (ekf<1+1e-2) ekf=1.01; 115 do { 116 e=e*ekf; 117 simplify(e); 118 //System.out.printf("eps=%f n=%d\n", e,simplePoints.size()); 119 } while (getNodesPerKm()>maxPKM && e<1e3); 120 return e; 121 } 122 107 123 /** 108 124 * Simplified drawn line, not touching the nodes includes in "fixed" set. … … 302 318 } 303 319 } 320 public double getNodesPerKm() { 321 if (points.size()<2) return 0; 322 Point p1, p2; 323 LatLon pp1, pp2=null; 324 Iterator<LatLon> it1,it2; 325 326 it1=points.listIterator(0); 327 it2=points.listIterator(1); 328 int n=points.size(); 329 double len=0; 330 for (int i = 0; i < n-1; i++) { 331 pp1 = it1.next(); 332 //p1 = getPoint(pp1); 333 pp2 = it2.next(); 334 //p2 = getPoint(pp2); 335 len+=pp1.greatCircleDistance(pp2); 336 } 337 if (isClosed()) len+=pp2.greatCircleDistance(points.get(0)); 338 return Math.round((wasSimplified()?simplePoints.size():points.size()) 339 /len*1000); 340 341 342 } 304 343 305 344 } -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java
r26264 r26303 20 20 /// Initial tolerance for Douglas-Pecker algorithm 21 21 public double startingEps; 22 /// Maximum number of points per 1 km of way 23 public double maxPointsPerKm; 22 24 23 25 public void loadPrefs() { … … 32 34 minPixelsBetweenPoints = Main.pref.getDouble("fastdraw.mindelta", 20); 33 35 startingEps = Main.pref.getDouble("fastdraw.startingEps", 20); 36 maxPointsPerKm = Main.pref.getDouble("fastdraw.maxpkm", 200); 34 37 } 35 38 … … 45 48 Main.pref.putDouble("fastdraw.mindelta",minPixelsBetweenPoints); 46 49 Main.pref.putDouble("fastdraw.startingEps",startingEps); 50 Main.pref.putDouble("fastdraw.maxpkm",maxPointsPerKm); 47 51 try {Main.pref.save();} catch (IOException e) { 48 52 System.err.println(tr("Can not save preferences")); -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawConfigDialog.java
r26264 r26303 29 29 JLabel label1=new JLabel(tr("Epsilon multiplier")); 30 30 JLabel label2=new JLabel(tr("Starting Epsilon")); 31 JLabel label3=new JLabel(tr("Max points count per 1 km")); 31 32 JFormattedTextField text1=new JFormattedTextField(NumberFormat.getInstance()); 32 33 JFormattedTextField text2=new JFormattedTextField(NumberFormat.getInstance()); 34 JFormattedTextField text3=new JFormattedTextField(NumberFormat.getInstance()); 33 35 layout.setHorizontalGroup( 34 36 layout.createSequentialGroup() 35 37 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 36 38 .addComponent(label1) 37 .addComponent(label2)) 39 .addComponent(label2) 40 .addComponent(label3)) 38 41 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING) 39 42 .addComponent(text1) 40 43 .addComponent(text2) 44 .addComponent(text3) 41 45 ) 42 46 ); … … 49 53 .addComponent(label2) 50 54 .addComponent(text2)) 55 .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE) 56 .addComponent(label3) 57 .addComponent(text3)) 51 58 ); 52 59 53 60 text1.setValue(settings.epsilonMult); 54 61 text2.setValue(settings.startingEps); 62 text3.setValue(settings.maxPointsPerKm); 55 63 56 64 ExtendedDialog dialog = new ExtendedDialog(Main.parent, … … 71 79 settings.epsilonMult=NumberFormat.getInstance().parse(text1.getText()).doubleValue(); 72 80 settings.startingEps=NumberFormat.getInstance().parse(text2.getText()).doubleValue(); 81 settings.maxPointsPerKm=NumberFormat.getInstance().parse(text3.getText()).doubleValue(); 73 82 settings.savePrefs(); 74 83 } catch (ParseException e) { -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26264 r26303 364 364 // first Enter = simplify, second = save the way 365 365 if (!line.wasSimplified()) { 366 line.simplify(eps); 367 setStatusLine(tr("Eps={0}, {1} points", eps, line.getSimplePointsCount())+" "+SIMPLIFYMODE_MESSAGE); 366 //line.simplify(eps); 367 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings.maxPointsPerKm); 368 repaint(); 369 showSimplifyHint(); 368 370 } else saveAsWay(); 369 371 } … … 389 391 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 390 392 new FastDrawConfigDialog(settings); 393 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings.maxPointsPerKm); 394 //System.out.println("final eps="+eps); 391 395 Toolkit.getDefaultToolkit().addAWTEventListener(this, 392 396 AWTEvent.KEY_EVENT_MASK); 393 397 } catch (SecurityException ex) { } 394 eps=settings.startingEps;398 repaint(); 395 399 } 396 400 } … … 485 489 line.simplify(eps); 486 490 /* I18N: Eps = Epsilon, the tolerance parameter */ 487 s etStatusLine(tr("Eps={0}, {1} points", eps, line.getSimplePointsCount()));491 showSimplifyHint(); 488 492 repaint(); 489 493 } … … 538 542 // </editor-fold> 539 543 544 private void showSimplifyHint() { 545 setStatusLine(tr("Eps={0}, {1} points, {2} p/km", 546 eps, line.getSimplePointsCount(),line.getNodesPerKm())+" " 547 +SIMPLIFYMODE_MESSAGE); 548 } 540 549 }
Note:
See TracChangeset
for help on using the changeset viewer.