Changeset 26309 in osm for applications/editors/josm/plugins/FastDraw/src
- Timestamp:
- 2011-07-12T19:24:21+02:00 (13 years ago)
- Location:
- applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/DrawnPolyLine.java
r26303 r26309 109 109 * Increase epsilon to fit points count in maxPKM point per 1 km 110 110 */ 111 double autoSimplify(double initEpsilon,double ekf, double maxPKM) {111 double autoSimplify(double initEpsilon,double ekf,int k,double maxPKM) { 112 112 double e=initEpsilon; 113 113 if (e<1e-3) e=1e-3; 114 114 if (ekf<1+1e-2) ekf=1.01; 115 do { 115 simplify(e); 116 while (getNodesPerKm(k)>maxPKM && e<1e3) { 116 117 e=e*ekf; 117 118 simplify(e); 118 119 //System.out.printf("eps=%f n=%d\n", e,simplePoints.size()); 119 } while (getNodesPerKm()>maxPKM && e<1e3);120 } 120 121 return e; 121 122 } … … 318 319 } 319 320 } 320 public double getNodesPerKm() { 321 if (points.size()<2) return 0; 322 Point p1, p2; 321 322 /** 323 * Returns maximum number of simplified line points divided by line segment length 324 * max((k-1) / (L(i,i+1)+L(i+1,i+2)+...+L(i+k-1,i+k))) [ i=1..n-k ] 325 * @param k - window size (number of points to average points per km 326 */ 327 public double getNodesPerKm(int k) { 328 List<LatLon> pts = simplePoints; 329 if (!wasSimplified()) pts=points; 330 int n=pts.size(); 331 if (n<2) return 0; 332 if (k<2) k=2; 333 if (k>n) k=n; 334 323 335 LatLon pp1, pp2=null; 324 336 Iterator<LatLon> it1,it2; 325 326 it1=points.listIterator(0); 327 it2=points.listIterator(1); 328 int n=points.size(); 329 double len=0; 337 it1=pts.listIterator(0); 338 it2=pts.listIterator(1); 339 double lens[]=new double[n]; 330 340 for (int i = 0; i < n-1; i++) { 331 341 pp1 = it1.next(); … … 333 343 pp2 = it2.next(); 334 344 //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 345 lens[i]=pp1.greatCircleDistance(pp2); 346 } 347 double pkm=0,maxpkm=0; 348 double len=0; 349 for (int i = 1; i < n; i++) { 350 len+=lens[i-1]; // add next next point 351 // remove old segment 352 if (i>k) len-=lens[i-k-1]; 353 if (i>=k) { 354 // len is length of points[i-windowSize] .. points[i] 355 if (len>0) pkm = k / len * 1000; 356 //System.out.println("i="+i+" pkm="+len+" pkm="+pkm); 357 if (pkm > maxpkm) maxpkm=pkm; 358 } 359 } 360 return Math.round(maxpkm); 341 361 342 362 } -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FDSettings.java
r26303 r26309 22 22 /// Maximum number of points per 1 km of way 23 23 public double maxPointsPerKm; 24 public int pkmBlockSize; 24 25 25 26 public void loadPrefs() { … … 34 35 minPixelsBetweenPoints = Main.pref.getDouble("fastdraw.mindelta", 20); 35 36 startingEps = Main.pref.getDouble("fastdraw.startingEps", 20); 36 maxPointsPerKm = Main.pref.getDouble("fastdraw.maxpkm", 200); 37 maxPointsPerKm = Main.pref.getDouble("fastdraw.maxpkm", 20); 38 pkmBlockSize = Main.pref.getInteger("fastdraw.pkmblocksize", 10); 37 39 } 38 40 … … 49 51 Main.pref.putDouble("fastdraw.startingEps",startingEps); 50 52 Main.pref.putDouble("fastdraw.maxpkm",maxPointsPerKm); 53 Main.pref.putInteger("fastdraw.pkmblocksize",pkmBlockSize); 51 54 try {Main.pref.save();} catch (IOException e) { 52 55 System.err.println(tr("Can not save preferences")); -
applications/editors/josm/plugins/FastDraw/src/org/openstreetmap/josm/plugins/fastdraw/FastDrawingMode.java
r26303 r26309 365 365 if (!line.wasSimplified()) { 366 366 //line.simplify(eps); 367 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings.maxPointsPerKm); 367 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, 368 settings.pkmBlockSize, settings.maxPointsPerKm); 368 369 repaint(); 369 370 showSimplifyHint(); … … 391 392 Toolkit.getDefaultToolkit().removeAWTEventListener(this); 392 393 new FastDrawConfigDialog(settings); 393 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings. maxPointsPerKm);394 eps = line.autoSimplify(settings.startingEps, settings.epsilonMult, settings.pkmBlockSize,settings.maxPointsPerKm); 394 395 //System.out.println("final eps="+eps); 395 396 Toolkit.getDefaultToolkit().addAWTEventListener(this, … … 544 545 private void showSimplifyHint() { 545 546 setStatusLine(tr("Eps={0}, {1} points, {2} p/km", 546 eps, line.getSimplePointsCount(),line.getNodesPerKm( ))+" "547 eps, line.getSimplePointsCount(),line.getNodesPerKm(settings.pkmBlockSize))+" " 547 548 +SIMPLIFYMODE_MESSAGE); 548 549 }
Note:
See TracChangeset
for help on using the changeset viewer.