commit
1a0b38d375
4 changed files with 76 additions and 3 deletions
|
@ -285,6 +285,7 @@ public final class OsmTrack {
|
||||||
}
|
}
|
||||||
dis.close();
|
dis.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
t = null;
|
||||||
if (debugInfo != null) {
|
if (debugInfo != null) {
|
||||||
debugInfo.append("Error reading rawTrack: " + e);
|
debugInfo.append("Error reading rawTrack: " + e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,8 @@ import btools.mapaccess.OsmLink;
|
||||||
import btools.mapaccess.OsmLinkHolder;
|
import btools.mapaccess.OsmLinkHolder;
|
||||||
import btools.mapaccess.OsmNode;
|
import btools.mapaccess.OsmNode;
|
||||||
import btools.mapaccess.OsmNodePairSet;
|
import btools.mapaccess.OsmNodePairSet;
|
||||||
|
import btools.util.CheapAngleMeter;
|
||||||
|
import btools.util.CheapRuler;
|
||||||
import btools.util.CompactLongMap;
|
import btools.util.CompactLongMap;
|
||||||
import btools.util.SortedHeap;
|
import btools.util.SortedHeap;
|
||||||
import btools.util.StackSampler;
|
import btools.util.StackSampler;
|
||||||
|
@ -30,6 +32,8 @@ public class RoutingEngine extends Thread {
|
||||||
public final static int BROUTER_ENGINEMODE_SEED = 1;
|
public final static int BROUTER_ENGINEMODE_SEED = 1;
|
||||||
public final static int BROUTER_ENGINEMODE_GETELEV = 2;
|
public final static int BROUTER_ENGINEMODE_GETELEV = 2;
|
||||||
|
|
||||||
|
public final static int BROUTER_ENGINEMODE_PREPARE_REROUTE = 6;
|
||||||
|
|
||||||
private NodesCache nodesCache;
|
private NodesCache nodesCache;
|
||||||
private SortedHeap<OsmPath> openSet = new SortedHeap<>();
|
private SortedHeap<OsmPath> openSet = new SortedHeap<>();
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
@ -158,6 +162,7 @@ public class RoutingEngine extends Thread {
|
||||||
|
|
||||||
switch (engineMode) {
|
switch (engineMode) {
|
||||||
case BROUTER_ENGINEMODE_ROUTING:
|
case BROUTER_ENGINEMODE_ROUTING:
|
||||||
|
case BROUTER_ENGINEMODE_PREPARE_REROUTE:
|
||||||
if (waypoints.size() < 2) {
|
if (waypoints.size() < 2) {
|
||||||
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
throw new IllegalArgumentException("we need two lat/lon points at least!");
|
||||||
}
|
}
|
||||||
|
@ -189,6 +194,9 @@ public class RoutingEngine extends Thread {
|
||||||
ArrayList<String> messageList = new ArrayList<>();
|
ArrayList<String> messageList = new ArrayList<>();
|
||||||
for (int i = 0; ; i++) {
|
for (int i = 0; ; i++) {
|
||||||
track = findTrack(refTracks, lastTracks);
|
track = findTrack(refTracks, lastTracks);
|
||||||
|
|
||||||
|
if (engineMode==BROUTER_ENGINEMODE_PREPARE_REROUTE) break; // no output for rerouting prepare
|
||||||
|
|
||||||
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
|
track.message = "track-length = " + track.distance + " filtered ascend = " + track.ascend
|
||||||
+ " plain-ascend = " + track.plainAscend + " cost=" + track.cost;
|
+ " plain-ascend = " + track.plainAscend + " cost=" + track.cost;
|
||||||
if (track.energy != 0) {
|
if (track.energy != 0) {
|
||||||
|
@ -575,6 +583,10 @@ public class RoutingEngine extends Thread {
|
||||||
boolean dirty = found && nearbyTrack.isDirty;
|
boolean dirty = found && nearbyTrack.isDirty;
|
||||||
logInfo("read referenceTrack, found=" + found + " dirty=" + dirty + " " + debugInfo);
|
logInfo("read referenceTrack, found=" + found + " dirty=" + dirty + " " + debugInfo);
|
||||||
}
|
}
|
||||||
|
if (nearbyTrack != null &&
|
||||||
|
engineMode==BROUTER_ENGINEMODE_PREPARE_REROUTE) {
|
||||||
|
return null; // already rerouting prepared
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (matchedWaypoints == null) { // could exist from the previous alternative level
|
if (matchedWaypoints == null) { // could exist from the previous alternative level
|
||||||
|
@ -587,6 +599,22 @@ public class RoutingEngine extends Thread {
|
||||||
matchedWaypoints.add(mwp);
|
matchedWaypoints.add(mwp);
|
||||||
}
|
}
|
||||||
matchWaypointsToNodes(matchedWaypoints);
|
matchWaypointsToNodes(matchedWaypoints);
|
||||||
|
if (routingContext.startDirection != null) {
|
||||||
|
// add a nogo not to turn back
|
||||||
|
double angle = CheapAngleMeter.normalize(180 + routingContext.startDirection);
|
||||||
|
int[] np = CheapRuler.destination(matchedWaypoints.get(0).crosspoint.ilon, matchedWaypoints.get(0).crosspoint.ilat, 10, angle);
|
||||||
|
OsmNodeNamed n = new OsmNodeNamed();
|
||||||
|
n.name = "nogo8";
|
||||||
|
n.ilon = np[0];
|
||||||
|
n.ilat = np[1];
|
||||||
|
n.isNogo = true;
|
||||||
|
n.radius = 8;
|
||||||
|
n.nogoWeight = 9999;
|
||||||
|
if (routingContext.nogopoints == null) {
|
||||||
|
routingContext.nogopoints = new ArrayList<>();
|
||||||
|
}
|
||||||
|
routingContext.nogopoints.add(n);
|
||||||
|
}
|
||||||
|
|
||||||
routingContext.checkMatchedWaypointAgainstNogos(matchedWaypoints);
|
routingContext.checkMatchedWaypointAgainstNogos(matchedWaypoints);
|
||||||
|
|
||||||
|
@ -631,7 +659,8 @@ public class RoutingEngine extends Thread {
|
||||||
routingContext.inverseDirection = false;
|
routingContext.inverseDirection = false;
|
||||||
wptIndex = i + 1;
|
wptIndex = i + 1;
|
||||||
} else {
|
} else {
|
||||||
seg = searchTrack(matchedWaypoints.get(i), matchedWaypoints.get(i + 1), i == matchedWaypoints.size() - 2 ? nearbyTrack : null, refTracks[i]);
|
//seg = searchTrack(matchedWaypoints.get(i), matchedWaypoints.get(i + 1), i == matchedWaypoints.size() - 2 ? nearbyTrack : null, refTracks[i]);
|
||||||
|
seg = searchTrack(matchedWaypoints.get(i), matchedWaypoints.get(i + 1), nearbyTrack, refTracks[i]);
|
||||||
wptIndex = i;
|
wptIndex = i;
|
||||||
}
|
}
|
||||||
if (seg == null)
|
if (seg == null)
|
||||||
|
@ -1048,7 +1077,18 @@ public class RoutingEngine extends Thread {
|
||||||
track.nogoChecksums = routingContext.getNogoChecksums();
|
track.nogoChecksums = routingContext.getNogoChecksums();
|
||||||
track.profileTimestamp = routingContext.profileTimestamp;
|
track.profileTimestamp = routingContext.profileTimestamp;
|
||||||
track.isDirty = isDirty;
|
track.isDirty = isDirty;
|
||||||
foundRawTrack = track;
|
if (foundRawTrack == null) {
|
||||||
|
foundRawTrack = track;
|
||||||
|
} else {
|
||||||
|
for (OsmPathElement n : track.nodes) {
|
||||||
|
foundRawTrack.nodes.add(n);
|
||||||
|
}
|
||||||
|
foundRawTrack.endPoint = endWp;
|
||||||
|
}
|
||||||
|
if (engineMode==BROUTER_ENGINEMODE_PREPARE_REROUTE) {
|
||||||
|
return null; // rerouting prepared
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!wasClean && isDirty) {
|
if (!wasClean && isDirty) {
|
||||||
|
|
|
@ -105,13 +105,28 @@ public class BRouter {
|
||||||
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_GETELEV) {
|
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_GETELEV) {
|
||||||
re = new RoutingEngine("testinfo", null, new File(args[0]), wplist, rc, engineMode);
|
re = new RoutingEngine("testinfo", null, new File(args[0]), wplist, rc, engineMode);
|
||||||
} else {
|
} else {
|
||||||
|
rc.rawTrackPath = "testtrack.raw";
|
||||||
re = new RoutingEngine("testtrack", null, new File(args[0]), wplist, rc, engineMode);
|
re = new RoutingEngine("testtrack", null, new File(args[0]), wplist, rc, engineMode);
|
||||||
}
|
}
|
||||||
re.doRun(0);
|
re.doRun(0);
|
||||||
|
|
||||||
|
if (engineMode == RoutingEngine.BROUTER_ENGINEMODE_ROUTING ||
|
||||||
|
engineMode == RoutingEngine.BROUTER_ENGINEMODE_PREPARE_REROUTE) {
|
||||||
|
// store new reference track if any
|
||||||
|
// (can exist for timed-out search)
|
||||||
|
if (re.getFoundRawTrack() != null) {
|
||||||
|
try {
|
||||||
|
re.getFoundRawTrack().writeBinary(rc.rawTrackPath);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println(e.getMessage());
|
System.out.println(e.getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -77,4 +77,21 @@ public final class CheapRuler {
|
||||||
double dlat = (ilat1 - ilat2) * kxky[1];
|
double dlat = (ilat1 - ilat2) * kxky[1];
|
||||||
return Math.sqrt(dlat * dlat + dlon * dlon); // in m
|
return Math.sqrt(dlat * dlat + dlon * dlon); // in m
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int[] destination(int lon1, int lat1, double distance, double angle) {
|
||||||
|
|
||||||
|
double[] lonlat2m = CheapRuler.getLonLatToMeterScales(lat1);
|
||||||
|
double lon2m = lonlat2m[0];
|
||||||
|
double lat2m = lonlat2m[1];
|
||||||
|
angle = 90. - angle;
|
||||||
|
double st = Math.sin(angle * Math.PI / 180.);
|
||||||
|
double ct = Math.cos(angle * Math.PI / 180.);
|
||||||
|
|
||||||
|
int lon2 = (int) (0.5 + lon1 + ct * distance / lon2m);
|
||||||
|
int lat2 = (int) (0.5 + lat1 + st * distance / lat2m);
|
||||||
|
int[] ret = new int[2];
|
||||||
|
ret[0] = lon2;
|
||||||
|
ret[1] = lat2;
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue