Skip to content

Commit

Permalink
Merge pull request abrensch#742 from afischerdev/new-voicehints
Browse files Browse the repository at this point in the history
New voicehints for motorway exit
  • Loading branch information
afischerdev authored Dec 14, 2024
2 parents f2cba63 + 2712777 commit 625ff0c
Show file tree
Hide file tree
Showing 7 changed files with 187 additions and 49 deletions.
18 changes: 9 additions & 9 deletions brouter-core/src/main/java/btools/router/FormatGpx.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sb.append("<!-- cmd idx lon lat d2next geometry -->\n");
sb.append("<!-- $turn-instruction-start$\n");
for (VoiceHint hint : t.voiceHints.list) {
sb.append(String.format(" $turn$%6s;%6d;%10s;%10s;%6d;%s$\n", hint.getCommandString(), hint.indexInTrack,
sb.append(String.format(" $turn$%6s;%6d;%10s;%10s;%6d;%s$\n", hint.getCommandString(turnInstructionMode), hint.indexInTrack,
formatILon(hint.ilon), formatILat(hint.ilat), (int) (hint.distanceToNext), hint.formatGeometry()));
}
sb.append(" $turn-instruction-end$ -->\n");
Expand Down Expand Up @@ -121,7 +121,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sb.append(" <rtept lat=\"").append(formatILat(hint.ilat)).append("\" lon=\"")
.append(formatILon(hint.ilon)).append("\">\n")
.append(" <desc>")
.append(turnInstructionMode == 3 ? hint.getMessageString() : hint.getCruiserMessageString())
.append(turnInstructionMode == 3 ? hint.getMessageString(turnInstructionMode) : hint.getCruiserMessageString())
.append("</desc>\n <extensions>\n");

rteTime = t.getVoiceHintTime(i + 1);
Expand All @@ -132,7 +132,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
lastRteTime = rteTime;
}
sb.append(" <turn>")
.append(turnInstructionMode == 3 ? hint.getCommandString() : hint.getCruiserCommandString())
.append(turnInstructionMode == 3 ? hint.getCommandString(turnInstructionMode) : hint.getCruiserCommandString())
.append("</turn>\n <turn-angle>").append("" + (int) hint.angle)
.append("</turn-angle>\n <offset>").append("" + hint.indexInTrack).append("</offset>\n </extensions>\n </rtept>\n");
}
Expand All @@ -154,7 +154,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
.append(formatILat(hint.ilat)).append("\">")
.append(hint.selev == Short.MIN_VALUE ? "" : "<ele>" + (hint.selev / 4.) + "</ele>")
.append("<name>")
.append(hint.getMessageString())
.append(hint.getMessageString(turnInstructionMode))
.append("</name>")
.append("<extensions><locus:rteDistance>").append("" + hint.distanceToNext).append("</locus:rteDistance>");
float rteTime = t.getVoiceHintTime(i + 1);
Expand All @@ -173,9 +173,9 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
for (VoiceHint hint : t.voiceHints.list) {
sb.append(" <wpt lon=\"").append(formatILon(hint.ilon)).append("\" lat=\"")
.append(formatILat(hint.ilat)).append("\">")
.append("<name>").append(hint.getMessageString()).append("</name>")
.append("<sym>").append(hint.getSymbolString().toLowerCase()).append("</sym>")
.append("<type>").append(hint.getSymbolString()).append("</type>")
.append("<name>").append(hint.getMessageString(turnInstructionMode)).append("</name>")
.append("<sym>").append(hint.getSymbolString(turnInstructionMode).toLowerCase()).append("</sym>")
.append("<type>").append(hint.getSymbolString(turnInstructionMode)).append("</type>")
.append("</wpt>\n");
}
}
Expand Down Expand Up @@ -270,7 +270,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sele += "<name>" + mwpt.name + "</name>";
}
sele += "<desc>" + hint.getCruiserMessageString() + "</desc>";
sele += "<sym>" + hint.getCommandString(hint.cmd) + "</sym>";
sele += "<sym>" + hint.getCommandString(hint.cmd, turnInstructionMode) + "</sym>";
if (mwpt != null) {
sele += "<type>Via</type>";
}
Expand All @@ -287,7 +287,7 @@ public String formatAsGpx(BufferedWriter sb, OsmTrack t) throws IOException {
sele += "<brouter:speed>" + (((int) (speed * 10)) / 10.f) + "</brouter:speed>";
}

sele += "<brouter:voicehint>" + hint.getCommandString() + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + "</brouter:voicehint>";
sele += "<brouter:voicehint>" + hint.getCommandString(turnInstructionMode) + ";" + (int) (hint.distanceToNext) + "," + hint.formatGeometry() + "</brouter:voicehint>";
if (n.message != null && n.message.wayKeyValues != null && !n.message.wayKeyValues.equals(lastway)) {
sele += "<brouter:way>" + n.message.wayKeyValues + "</brouter:way>";
lastway = n.message.wayKeyValues;
Expand Down
6 changes: 3 additions & 3 deletions brouter-core/src/main/java/btools/router/FormatJson.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ public String format(OsmTrack t) {
for (VoiceHint hint : t.voiceHints.list) {
sb.append(" [");
sb.append(hint.indexInTrack);
sb.append(',').append(hint.getJsonCommandIndex());
sb.append(',').append(hint.getJsonCommandIndex(turnInstructionMode));
sb.append(',').append(hint.getExitNumber());
sb.append(',').append(hint.distanceToNext);
sb.append(',').append((int) hint.angle);

// not always include geometry because longer and only needed for comment style
if (turnInstructionMode == 4) { // comment style
if (turnInstructionMode == 4 || turnInstructionMode == 9) { // comment style
sb.append(",\"").append(hint.formatGeometry()).append("\"");
}

Expand Down Expand Up @@ -122,7 +122,7 @@ public String format(OsmTrack t) {
.append(sele).append("],\n");
nn = n;
}
if (t.nodes != null && !t.nodes.isEmpty()) sb.deleteCharAt(sb.lastIndexOf(","));
sb.deleteCharAt(sb.lastIndexOf(","));

sb.append(" ]\n");
sb.append(" }\n");
Expand Down
11 changes: 11 additions & 0 deletions brouter-core/src/main/java/btools/router/OsmTrack.java
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,17 @@ public void processVoiceHints(RoutingContext rc) {
List<VoiceHint> inputs = new ArrayList<>();
while (node != null) {
if (node.origin != null) {
if (nodeNr == nodes.size() - 1) {
VoiceHint input = new VoiceHint();
inputs.add(0, input);
input.ilat = node.getILat();
input.ilon = node.getILon();
input.selev = node.getSElev();
input.goodWay = node.message;
input.oldWay = node.message;
input.indexInTrack = nodes.size() - 1;
input.cmd = VoiceHint.END;
}
VoiceHint input = new VoiceHint();
inputs.add(input);
input.ilat = node.origin.getILat();
Expand Down
46 changes: 41 additions & 5 deletions brouter-core/src/main/java/btools/router/RoutingEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ public class RoutingEngine extends Thread {
private boolean finished = false;

protected List<OsmNodeNamed> waypoints = null;
List<OsmNodeNamed> extraWaypoints = null;
protected List<MatchedWaypoint> matchedWaypoints;
private int linksProcessed = 0;

private int nodeLimit; // used for target island search
private int MAXNODES_ISLAND_CHECK = 500;
private OsmNodePairSet islandNodePairs = new OsmNodePairSet(MAXNODES_ISLAND_CHECK);
private boolean useNodePoints = false; // use the start/end nodes instead of crosspoint

private int engineMode = 0;

Expand Down Expand Up @@ -548,6 +550,20 @@ private OsmTrack findTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
try {
return tryFindTrack(refTracks, lastTracks);
} catch (RoutingIslandException rie) {
if (routingContext.useDynamicDistance) {
useNodePoints = true;
boolean useNodeOne = true;
if (extraWaypoints != null) useNodeOne = false;
extraWaypoints = new ArrayList<>();
for (MatchedWaypoint mwp : matchedWaypoints) {
if (mwp.name.contains("_add")) {
OsmNodeNamed wp = new OsmNodeNamed(useNodeOne ? mwp.node1 : mwp.node1);
wp.name = mwp.name;
wp.direct = mwp.direct;
extraWaypoints.add(wp);
}
}
}
islandNodePairs.freezeTempPairs();
nodesCache.clean(true);
matchedWaypoints = null;
Expand All @@ -560,6 +576,26 @@ private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
int nUnmatched = waypoints.size();
boolean hasDirectRouting = false;

if (useNodePoints && extraWaypoints != null) {
// add extra waypoints from the last broken round
for (OsmNodeNamed wp : extraWaypoints) {
if (wp.direct) hasDirectRouting = true;
if (wp.name.startsWith("from")) {
waypoints.add(1, wp);
waypoints.get(0).direct = true;
nUnmatched++;
} else {
waypoints.add(waypoints.size()-1, wp);
waypoints.get(waypoints.size()-2).direct = true;
nUnmatched++;
}
}
}
if (lastTracks.length < waypoints.size()-1) {
refTracks = new OsmTrack[waypoints.size()-1]; // used ways for alternatives
lastTracks = new OsmTrack[waypoints.size()-1];
hasDirectRouting = true;
}
for (OsmNodeNamed wp : waypoints) {
if (hasInfo()) logInfo("wp=" + wp + (wp.direct ? " direct" : ""));
if (wp.direct) hasDirectRouting = true;
Expand Down Expand Up @@ -592,8 +628,8 @@ private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
int startSize = matchedWaypoints.size();
matchWaypointsToNodes(matchedWaypoints);
if (startSize < matchedWaypoints.size()) {
refTracks = new OsmTrack[matchedWaypoints.size()]; // used ways for alternatives
lastTracks = new OsmTrack[matchedWaypoints.size()];
refTracks = new OsmTrack[matchedWaypoints.size()-1]; // used ways for alternatives
lastTracks = new OsmTrack[matchedWaypoints.size()-1];
hasDirectRouting = true;
}

Expand Down Expand Up @@ -624,9 +660,9 @@ private OsmTrack tryFindTrack(OsmTrack[] refTracks, OsmTrack[] lastTracks) {
matchedWaypoints.add(nearbyTrack.endPoint);
}
} else {
if (lastTracks.length < matchedWaypoints.size()) {
refTracks = new OsmTrack[matchedWaypoints.size()]; // used ways for alternatives
lastTracks = new OsmTrack[matchedWaypoints.size()];
if (lastTracks.length < matchedWaypoints.size()-1) {
refTracks = new OsmTrack[matchedWaypoints.size()-1]; // used ways for alternatives
lastTracks = new OsmTrack[matchedWaypoints.size()-1];
hasDirectRouting = true;
}
}
Expand Down
56 changes: 51 additions & 5 deletions brouter-core/src/main/java/btools/router/VoiceHint.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class VoiceHint {
static final int RNLB = 14; // Roundabout left
static final int TU = 15; // 180 degree u-turn
static final int BL = 16; // Beeline routing
static final int EL = 17; // exit left
static final int ER = 18; // exit right

static final int END = 100; // end point

int ilon;
int ilat;
Expand Down Expand Up @@ -65,7 +69,7 @@ public void addBadWay(MessageData badWay) {
badWays.add(badWay);
}

public int getJsonCommandIndex() {
public int getJsonCommandIndex(int timode) {
switch (cmd) {
case TLU:
return 10;
Expand Down Expand Up @@ -97,6 +101,10 @@ public int getJsonCommandIndex() {
return 14;
case BL:
return 16;
case EL:
return timode == 2 || timode == 9 ? 17 : 8;
case ER:
return timode == 2 || timode == 9 ? 18 : 9;
case OFFR:
return 12;
default:
Expand All @@ -111,7 +119,7 @@ public int getExitNumber() {
/*
* used by comment style, osmand style
*/
public String getCommandString() {
public String getCommandString(int timode) {
switch (cmd) {
case TLU:
return "TU"; // should be changed to TLU when osmand uses new voice hint constants
Expand Down Expand Up @@ -143,8 +151,14 @@ public String getCommandString() {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return timode == 2 || timode == 9 ? "EL" : "KL";
case ER:
return timode == 2 || timode == 9 ? "ER" : "KR";
case OFFR:
return "OFFR";
case END:
return "END";
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand All @@ -153,7 +167,7 @@ public String getCommandString() {
/*
* used by trkpt/sym style
*/
public String getCommandString(int c) {
public String getCommandString(int c, int timode) {
switch (c) {
case TLU:
return "TLU";
Expand Down Expand Up @@ -185,6 +199,10 @@ public String getCommandString(int c) {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return timode == 2 || timode == 9 ? "EL" : "KL";
case ER:
return timode == 2 || timode == 9 ? "ER" : "KR";
case OFFR:
return "OFFR";
default:
Expand All @@ -195,7 +213,7 @@ public String getCommandString(int c) {
/*
* used by gpsies style
*/
public String getSymbolString() {
public String getSymbolString(int timode) {
switch (cmd) {
case TLU:
return "TU";
Expand Down Expand Up @@ -227,6 +245,10 @@ public String getSymbolString() {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return timode == 2 || timode == 9 ? "EL" : "KL";
case ER:
return timode == 2 || timode == 9 ? "ER" : "KR";
case OFFR:
return "OFFR";
default:
Expand Down Expand Up @@ -269,6 +291,10 @@ public String getLocusSymbolString() {
return "roundabout_e" + (-roundaboutExit);
case BL:
return "beeline";
case EL:
return "exit_left";
case ER:
return "exit_right";
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand All @@ -277,7 +303,7 @@ public String getLocusSymbolString() {
/*
* used by osmand style
*/
public String getMessageString() {
public String getMessageString(int timode) {
switch (cmd) {
case TLU:
return "u-turn"; // should be changed to u-turn-left when osmand uses new voice hint constants
Expand Down Expand Up @@ -307,6 +333,10 @@ public String getMessageString() {
return "Take exit " + roundaboutExit;
case RNLB:
return "Take exit " + (-roundaboutExit);
case EL:
return timode == 2 || timode == 9 ? "exit left" : "keep left";
case ER:
return timode == 2 || timode == 9 ? "exit right" : "keep right";
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand Down Expand Up @@ -345,6 +375,10 @@ public int getLocusAction() {
return 26 + roundaboutExit;
case RNLB:
return 26 - roundaboutExit;
case EL:
return 9;
case ER:
return 10;
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand Down Expand Up @@ -383,6 +417,10 @@ public int getOruxAction() {
return 1008 + roundaboutExit;
case RNLB:
return 1008 + roundaboutExit;
case EL:
return 1015;
case ER:
return 1014;
default:
throw new IllegalArgumentException("unknown command: " + cmd);
}
Expand Down Expand Up @@ -423,6 +461,10 @@ public String getCruiserCommandString() {
return "RNLB" + (-roundaboutExit);
case BL:
return "BL";
case EL:
return "EL";
case ER:
return "ER";
case OFFR:
return "OFFR";
default:
Expand Down Expand Up @@ -465,6 +507,10 @@ public String getCruiserMessageString() {
return "take exit " + (-roundaboutExit);
case BL:
return "beeline";
case EL:
return "exit left";
case ER:
return "exit right";
case OFFR:
return "offroad";
default:
Expand Down
Loading

0 comments on commit 625ff0c

Please sign in to comment.