From 7b0b04f70114711704396d1b7231d632d5ca302a Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Mon, 2 Jul 2012 01:12:30 +0200 Subject: [PATCH] Add lanes info --- .../net/osmand/binary/RouteDataObject.java | 12 ++++ .../net/osmand/router/BinaryRoutePlanner.java | 58 +++++++++++++++++-- .../src/net/osmand/router/TurnType.java | 12 ++++ OsmAnd/.gitignore | 1 + OsmAnd/assets/voice/en/config.p | 4 +- OsmAnd/assets/voice/ru2/config.p | 2 + OsmAnd/assets/voice/ru3/config.p | 8 ++- 7 files changed, 90 insertions(+), 7 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/binary/RouteDataObject.java b/DataExtractionOSM/src/net/osmand/binary/RouteDataObject.java index fef282f34e..45aeb3ae6d 100644 --- a/DataExtractionOSM/src/net/osmand/binary/RouteDataObject.java +++ b/DataExtractionOSM/src/net/osmand/binary/RouteDataObject.java @@ -173,6 +173,18 @@ public class RouteDataObject { } return highway; } + + public int getLanes() { + int sz = types.length; + for (int i = 0; i < sz; i++) { + RouteTypeRule r = region.quickGetEncodingRule(types[i]); + int ln = r.lanes(); + if (ln > 0) { + return ln; + } + } + return -1; + } // Gives route direction of EAST degrees from NORTH ]-PI, PI] public double directionRoute(int startPoint, boolean plus) { diff --git a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java index 8eadaec904..2aafea8c22 100644 --- a/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java +++ b/DataExtractionOSM/src/net/osmand/router/BinaryRoutePlanner.java @@ -7,6 +7,7 @@ import gnu.trove.map.hash.TLongObjectHashMap; import java.io.IOException; import java.text.MessageFormat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.Iterator; @@ -903,10 +904,22 @@ public class BinaryRoutePlanner { if (ref != null) { name += " " + ref; } + StringBuilder additional = new StringBuilder(); + additional.append("time = \"").append(res.getSegmentTime()).append("\" "); + additional.append("name = \"").append(name).append("\" "); + additional.append("distance = \"").append(res.getDistance()).append("\" "); + if(res.getTurnType() != null) { + additional.append("turn = \"").append(res.getTurnType()).append("\" "); + if(res.getTurnType().getLanes() != null) { + additional.append("lanes = \"").append(Arrays.toString(res.getTurnType().getLanes())).append("\" "); + } + } + additional.append("start_bearing = \"").append(res.getBearingBegin()).append("\" "); + additional.append("end_bearing = \"").append(res.getBearingEnd()).append("\" "); + additional.append("description = \"").append(res.getDescription()).append("\" "); println(MessageFormat.format( - "\t", - (res.getObject().getId()) + "", res.getStartPointIndex() + "", res.getEndPointIndex() + "", name, - res.getSegmentTime(),res.getDistance(), res.getBearingBegin() + "", res.getBearingEnd() + "", res.getDescription()+"")); + "\t", + (res.getObject().getId()) + "", res.getStartPointIndex() + "", res.getEndPointIndex() + "", additional.toString())); } println(""); } @@ -954,7 +967,7 @@ public class BinaryRoutePlanner { if (prev != null) { // add description about turn double mpi = MapUtils.degreesDiff(prev.getBearingEnd(), rr.getBearingBegin()); - + int[] lanes = null; if (mpi >= 50) { if (mpi < 60) { t = TurnType.valueOf(TurnType.TSLL, leftSide); @@ -980,16 +993,48 @@ public class BinaryRoutePlanner { boolean kl = false; boolean kr = false; List attachedRoutes = rr.getAttachedRoutes(rr.getStartPointIndex()); + int ls = prev.getObject().getLanes(); + int left = 0; + int right = 0; + if (ls > 0) { + lanes = new int[ls]; + } if(attachedRoutes != null){ for(RouteSegmentResult rs : attachedRoutes){ double ex = MapUtils.degreesDiff(rs.getBearingBegin(), rr.getBearingBegin()); if(ex < 30 && ex >= 0) { kl = true; + int lns = rs.getObject().getLanes(); + if (lns > 0) { + right += lns; + } } else if(ex > -30 && ex <= 0) { kr = true; + int lns = rs.getObject().getLanes(); + if (lns > 0) { + left += lns; + } } } } + int current = rr.getObject().getLanes(); + if (current <= 0) { + current = 1; + } + if(lanes != null) { + if(current + left + right != ls){ + lanes = null; + } else { + for(int it=0; it< ls; it++) { + if(it < left || it >= left + current) { + lanes[it] = 0; + } else { + lanes[it] = 1; + } + } + } + } + if (kl) { t = TurnType.valueOf(TurnType.KL, leftSide); } else if(kr){ @@ -998,7 +1043,12 @@ public class BinaryRoutePlanner { } if(t != null) { t.setTurnAngle((float) -mpi); + + if (lanes != null) { + t.setLanes(lanes); + } } + } return t; } diff --git a/DataExtractionOSM/src/net/osmand/router/TurnType.java b/DataExtractionOSM/src/net/osmand/router/TurnType.java index 0e410e90ae..806ea0b1c3 100644 --- a/DataExtractionOSM/src/net/osmand/router/TurnType.java +++ b/DataExtractionOSM/src/net/osmand/router/TurnType.java @@ -34,6 +34,7 @@ public class TurnType { private boolean isLeftSide; // calculated CW head rotation if previous direction to NORTH private float turnAngle; + private int[] lanes; private static TurnType getExitTurn(int out, float angle, boolean leftSide) { TurnType r = new TurnType("EXIT", out, leftSide); //$NON-NLS-1$ @@ -76,6 +77,17 @@ public class TurnType { return value.equals("EXIT"); //$NON-NLS-1$ } + // lanes encoded as array of int + // last bit is 1, 0 (should we take this lane) + // first bits 0 - left, 1 - straight, 2 - right + public void setLanes(int[] lanes) { + this.lanes = lanes; + } + + public int[] getLanes() { + return lanes; + } + public boolean keepLeft() { return value.equals(KL); } diff --git a/OsmAnd/.gitignore b/OsmAnd/.gitignore index ccc9733e52..b5543a0ceb 100644 --- a/OsmAnd/.gitignore +++ b/OsmAnd/.gitignore @@ -1,4 +1,5 @@ bin/ +dist/ gen/ local.properties raw/ diff --git a/OsmAnd/assets/voice/en/config.p b/OsmAnd/assets/voice/en/config.p index c50b15dc8f..acd896a800 100644 --- a/OsmAnd/assets/voice/en/config.p +++ b/OsmAnd/assets/voice/en/config.p @@ -42,9 +42,11 @@ then == ['then.ogg', delay_350]. reached_destination == ['you_have_reached_your_destination.ogg']. bear_right == ['keep_right-e.ogg']. bear_left == ['keep_left-e.ogg']. -route_recalc(_Dist) == []. % ['recalc.ogg']. %nothing to said possibly beep? +route_recalc(_Dist) == ['recalc.ogg']. %nothing to said possibly beep? route_new_calc(Dist) == ['the_trip_is_more_than.ogg', delay_150, D] :- distance(Dist) == D. % nothing to said possibly beep? +% location_lost == ['gps_signal_lost.ogg']. + go_ahead(Dist) == ['drive_for-h.ogg', delay_250, D]:- distance(Dist) == D. go_ahead == ['continue_straight-e.ogg']. diff --git a/OsmAnd/assets/voice/ru2/config.p b/OsmAnd/assets/voice/ru2/config.p index 0637ca0421..6d57c9553f 100644 --- a/OsmAnd/assets/voice/ru2/config.p +++ b/OsmAnd/assets/voice/ru2/config.p @@ -45,6 +45,8 @@ bear_left == ['keep_left-e.ogg']. route_recalc(_Dist) == []. % ['recalc.ogg']. %nothing to said possibly beep? route_new_calc(Dist) == ['the_trip_is_more_than.ogg', delay_150, D] :- distance(Dist) == D. % nothing to said possibly beep? +% location_lost == ['no_file.ogg']. + go_ahead(Dist) == ['Drive-n.ogg', delay_250, D]:- distance(Dist) == D. go_ahead == ['continue_straight-e.ogg']. diff --git a/OsmAnd/assets/voice/ru3/config.p b/OsmAnd/assets/voice/ru3/config.p index 35fe94c3c3..78437be839 100644 --- a/OsmAnd/assets/voice/ru3/config.p +++ b/OsmAnd/assets/voice/ru3/config.p @@ -42,8 +42,12 @@ reached_destination == ['you_have_reached_your_destination.ogg']. bear_right == ['keep_right-e.ogg']. location_lost == ['gps_signal_lost.ogg']. bear_left == ['keep_left-e.ogg']. -route_recalc(_Dist) == []. % 'recalc.ogg' -route_new_calc(_Dist) == ['have_a_nice_trip_drive_carefully.ogg']. +% route_recalc(_Dist) == []. % 'recalc.ogg' +route_recalc(Dist) == Res :- go_ahead(Dist) == Res . +% route_new_calc(_Dist) == ['have_a_nice_trip_drive_carefully.ogg']. +route_new_calc(Dist) == Res :- go_ahead(Dist) == Res . + +location_lost == ['gps_signal_lost.ogg']. go_ahead(Dist) == ['Drive-n.ogg', D]:- distance(Dist) == D. go_ahead == ['continue_straight-e.ogg'].