Update map utils douglas-peuker (to return filtered out points)

This commit is contained in:
vshcherb 2014-01-20 19:34:45 +01:00
parent 2d3a054fd0
commit 4b9697f104
2 changed files with 21 additions and 20 deletions

View file

@ -1,15 +1,13 @@
package net.osmand.osm.edit; package net.osmand.osm.edit;
import java.io.FileInputStream; import java.util.ArrayList;
import java.io.FileNotFoundException; import java.util.Collection;
import java.io.IOException; import java.util.Collections;
import java.util.*; import java.util.Comparator;
import java.util.List;
import net.osmand.IProgress;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.osm.io.OsmBaseStorage;
import net.osmand.util.MapUtils; import net.osmand.util.MapUtils;
import org.xml.sax.SAXException;
public class OsmMapUtils { public class OsmMapUtils {
@ -135,11 +133,11 @@ public class OsmMapUtils {
return ccw(A, C, D) != ccw(B, C, D) && ccw(A, B, C) != ccw(A, B, D); return ccw(A, C, D) != ccw(B, C, D) && ccw(A, B, C) != ccw(A, B, D);
} }
public static void simplifyDouglasPeucker(List<Node> n, int zoom, int epsilon, List<Node> result, boolean avoidNooses) { public static boolean[] simplifyDouglasPeucker(List<Node> n, int zoom, int epsilon, List<Node> result, boolean avoidNooses) {
if (zoom > 31) { if (zoom > 31) {
zoom = 31; zoom = 31;
} }
ArrayList<Integer> l = new ArrayList<Integer>(); boolean[] kept = new boolean[n.size()];
int first = 0; int first = 0;
int nsize = n.size(); int nsize = n.size();
while (first < nsize) { while (first < nsize) {
@ -156,7 +154,7 @@ public class OsmMapUtils {
last--; last--;
} }
if (last - first < 1) { if (last - first < 1) {
return; return kept;
} }
// check for possible cycle // check for possible cycle
boolean checkCycle = true; boolean checkCycle = true;
@ -175,20 +173,23 @@ public class OsmMapUtils {
} }
} }
if (last - first < 1) { if (last - first < 1) {
return; return kept;
} }
simplifyDouglasPeucker(n, zoom, epsilon, l, first, last, avoidNooses); simplifyDouglasPeucker(n, zoom, epsilon, kept, first, last, avoidNooses);
result.add(n.get(first)); result.add(n.get(first));
int lsize = l.size(); for (int i = 0; i < kept.length; i++) {
for (int i = 0; i < lsize; i++) { if(kept[i]) {
result.add(n.get(l.get(i))); result.add(n.get(i));
}
} }
if (cycle) { if (cycle) {
result.add(n.get(first)); result.add(n.get(first));
kept[first] = true;
} }
return kept;
} }
private static void simplifyDouglasPeucker(List<Node> n, int zoom, int epsilon, List<Integer> ints, private static void simplifyDouglasPeucker(List<Node> n, int zoom, int epsilon, boolean[] kept,
int start, int end, boolean avoidNooses) { int start, int end, boolean avoidNooses) {
double dmax = -1; double dmax = -1;
int index = -1; int index = -1;
@ -223,10 +224,10 @@ public class OsmMapUtils {
} }
} }
if (dmax >= epsilon || nooseFound ) { if (dmax >= epsilon || nooseFound ) {
simplifyDouglasPeucker(n, zoom, epsilon, ints, start, index, avoidNooses); simplifyDouglasPeucker(n, zoom, epsilon, kept, start, index, avoidNooses);
simplifyDouglasPeucker(n, zoom, epsilon, ints, index, end, avoidNooses); simplifyDouglasPeucker(n, zoom, epsilon, kept, index, end, avoidNooses);
} else { } else {
ints.add(end); kept[end] = true;
} }
} }

View file

@ -90,7 +90,7 @@ public class RoutePlannerFrontEnd {
ctx.calculationProgress = new RouteCalculationProgress(); ctx.calculationProgress = new RouteCalculationProgress();
} }
boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty(); boolean intermediatesEmpty = intermediates == null || intermediates.isEmpty();
// TODO native, empty route, intermediates... // TODO native, empty route...
// + intermediates, + progress, +complex, // + intermediates, + progress, +complex,
PrecalculatedRouteDirection routeDirection = null; PrecalculatedRouteDirection routeDirection = null;
if(ctx.calculationMode == RouteCalculationMode.COMPLEX) { if(ctx.calculationMode == RouteCalculationMode.COMPLEX) {