Remove output.
This commit is contained in:
parent
05c4f0da2a
commit
20a64255aa
@ -14,168 +14,181 @@ import org.insa.graph.RoadInformation.RoadType;
|
|||||||
|
|
||||||
public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
||||||
|
|
||||||
// Map version and magic number targeted for this reader.
|
// Map version and magic number targeted for this reader.
|
||||||
private static final int VERSION = 4;
|
private static final int VERSION = 4;
|
||||||
private static final int MAGIC_NUMBER = 0xbacaff;
|
private static final int MAGIC_NUMBER = 0xbacaff;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a character to its corresponding road type.
|
* Convert a character to its corresponding road type.
|
||||||
*
|
*
|
||||||
* @param ch Character to convert.
|
* @param ch Character to convert.
|
||||||
*
|
*
|
||||||
* @return Road type corresponding to ch.
|
* @return Road type corresponding to ch.
|
||||||
*
|
*
|
||||||
* @see http://wiki.openstreetmap.org/wiki/Highway_tag_usage.
|
* @see http://wiki.openstreetmap.org/wiki/Highway_tag_usage.
|
||||||
*/
|
*/
|
||||||
public static RoadType toRoadType(char ch) {
|
public static RoadType toRoadType(char ch) {
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
case 'a': return RoadType.MOTORWAY;
|
case 'a':
|
||||||
case 'b': return RoadType.TRUNK;
|
return RoadType.MOTORWAY;
|
||||||
case 'c': return RoadType.PRIMARY;
|
case 'b':
|
||||||
case 'd': return RoadType.SECONDARY;
|
return RoadType.TRUNK;
|
||||||
case 'e': return RoadType.MOTORWAY_LINK;
|
case 'c':
|
||||||
case 'f': return RoadType.TRUNK_LINK;
|
return RoadType.PRIMARY;
|
||||||
case 'g': return RoadType.PRIMARY_LINK;
|
case 'd':
|
||||||
case 'h': return RoadType.SECONDARY_LINK;
|
return RoadType.SECONDARY;
|
||||||
case 'i': return RoadType.TERTIARY;
|
case 'e':
|
||||||
case 'j': return RoadType.RESIDENTIAL;
|
return RoadType.MOTORWAY_LINK;
|
||||||
case 'k': return RoadType.UNCLASSIFIED;
|
case 'f':
|
||||||
case 'l': return RoadType.ROAD;
|
return RoadType.TRUNK_LINK;
|
||||||
case 'm': return RoadType.LIVING_STREET;
|
case 'g':
|
||||||
case 'n': return RoadType.SERVICE;
|
return RoadType.PRIMARY_LINK;
|
||||||
case 'o': return RoadType.ROUNDABOUT;
|
case 'h':
|
||||||
case 'z': return RoadType.COASTLINE;
|
return RoadType.SECONDARY_LINK;
|
||||||
}
|
case 'i':
|
||||||
return RoadType.UNCLASSIFIED;
|
return RoadType.TERTIARY;
|
||||||
}
|
case 'j':
|
||||||
|
return RoadType.RESIDENTIAL;
|
||||||
|
case 'k':
|
||||||
|
return RoadType.UNCLASSIFIED;
|
||||||
|
case 'l':
|
||||||
|
return RoadType.ROAD;
|
||||||
|
case 'm':
|
||||||
|
return RoadType.LIVING_STREET;
|
||||||
|
case 'n':
|
||||||
|
return RoadType.SERVICE;
|
||||||
|
case 'o':
|
||||||
|
return RoadType.ROUNDABOUT;
|
||||||
|
case 'z':
|
||||||
|
return RoadType.COASTLINE;
|
||||||
|
}
|
||||||
|
return RoadType.UNCLASSIFIED;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new BinaryGraphReader using the given DataInputStream.
|
* Create a new BinaryGraphReader using the given DataInputStream.
|
||||||
*
|
*
|
||||||
* @param dis
|
* @param dis
|
||||||
*/
|
*/
|
||||||
public BinaryGraphReader(DataInputStream dis) {
|
public BinaryGraphReader(DataInputStream dis) {
|
||||||
super(MAGIC_NUMBER, VERSION, dis);
|
super(MAGIC_NUMBER, VERSION, dis);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Graph read() throws IOException {
|
public Graph read() throws IOException {
|
||||||
|
|
||||||
System.out.println(getClass());
|
// Read and check magic number and file version.
|
||||||
|
checkMagicNumberOrThrow(dis.readInt());
|
||||||
|
checkVersionOrThrow(dis.readInt());
|
||||||
|
|
||||||
// Read and check magic number and file version.
|
// Read map id.
|
||||||
checkMagicNumberOrThrow(dis.readInt());
|
int mapId = dis.readInt();
|
||||||
checkVersionOrThrow(dis.readInt());
|
|
||||||
|
|
||||||
// Read map id.
|
// Read zone.
|
||||||
int mapId = dis.readInt();
|
int graphZone = dis.readInt();
|
||||||
|
|
||||||
// Read zone.
|
// Number of descriptors and nodes.
|
||||||
int graphZone = dis.readInt();
|
int nbDesc = dis.readInt();
|
||||||
|
int nbNodes = dis.readInt();
|
||||||
|
|
||||||
// Number of descriptors and nodes.
|
// Number of successors for each nodes.
|
||||||
int nbDesc = dis.readInt();
|
int[] nbSuccessors = new int[nbNodes];
|
||||||
int nbNodes = dis.readInt();
|
|
||||||
|
|
||||||
// Number of successors for each nodes.
|
// Construct an array list with initial capacity of nbNodes.
|
||||||
int[] nbSuccessors = new int[nbNodes];
|
ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
|
||||||
|
|
||||||
// Construct an array list with initial capacity of nbNodes.
|
// Read nodes.
|
||||||
ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
|
for (int node = 0; node < nbNodes; ++node) {
|
||||||
|
float longitude = ((float) dis.readInt()) / 1E6f;
|
||||||
|
float latitude = ((float) dis.readInt()) / 1E6f;
|
||||||
|
nbSuccessors[node] = dis.readUnsignedByte();
|
||||||
|
nodes.add(new Node(node, new Point(longitude, latitude)));
|
||||||
|
}
|
||||||
|
|
||||||
// Read nodes.
|
// Check format.
|
||||||
for (int node = 0; node < nbNodes; ++node) {
|
checkByteOrThrow(255);
|
||||||
float longitude = ((float)dis.readInt ()) / 1E6f;
|
|
||||||
float latitude = ((float)dis.readInt ()) / 1E6f;
|
|
||||||
nbSuccessors[node] = dis.readUnsignedByte();
|
|
||||||
nodes.add(new Node(node, new Point(longitude, latitude)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check format.
|
// Read descriptors.
|
||||||
checkByteOrThrow(255);
|
RoadInformation[] descs = new RoadInformation[nbDesc];
|
||||||
|
|
||||||
// Read descriptors.
|
// Read
|
||||||
RoadInformation[] descs = new RoadInformation[nbDesc];
|
for (int descr = 0; descr < nbDesc; ++descr) {
|
||||||
|
descs[descr] = readRoadInformation();
|
||||||
|
}
|
||||||
|
|
||||||
// Read
|
// Check format.
|
||||||
for (int descr = 0; descr < nbDesc; ++descr) {
|
checkByteOrThrow(254);
|
||||||
descs[descr] = readRoadInformation();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check format.
|
// Read successors and convert to arcs.
|
||||||
checkByteOrThrow(254);
|
for (int node = 0; node < nbNodes; ++node) {
|
||||||
|
for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
|
||||||
|
|
||||||
// Read successors and convert to arcs.
|
// Read destination zone.
|
||||||
for (int node = 0; node < nbNodes; ++node) {
|
int destZone = dis.readUnsignedByte();
|
||||||
for (int succ = 0; succ < nbSuccessors[node]; ++succ) {
|
|
||||||
|
|
||||||
// Read destination zone.
|
// Read target node number.
|
||||||
int destZone = dis.readUnsignedByte();
|
int destNode = this.read24bits();
|
||||||
|
|
||||||
// Read target node number.
|
// Read information number.
|
||||||
int destNode = this.read24bits();
|
int descrNum = this.read24bits();
|
||||||
|
|
||||||
// Read information number.
|
// Length of the arc.
|
||||||
int descrNum = this.read24bits();
|
int length = dis.readUnsignedShort();
|
||||||
|
|
||||||
// Length of the arc.
|
// Number of segments.
|
||||||
int length = dis.readUnsignedShort();
|
int nbSegments = dis.readUnsignedShort();
|
||||||
|
|
||||||
// Number of segments.
|
// Chain of points corresponding to the segments.
|
||||||
int nbSegments = dis.readUnsignedShort();
|
ArrayList<Point> points = new ArrayList<Point>(nbSegments + 2);
|
||||||
|
points.add(nodes.get(node).getPoint());
|
||||||
|
|
||||||
// Chain of points corresponding to the segments.
|
for (int seg = 0; seg < nbSegments; ++seg) {
|
||||||
ArrayList<Point> points = new ArrayList<Point>(nbSegments + 2);
|
Point lastPoint = points.get(points.size() - 1);
|
||||||
points.add(nodes.get(node).getPoint());
|
|
||||||
|
|
||||||
for (int seg = 0; seg < nbSegments; ++seg) {
|
float dlon = (dis.readShort()) / 2.0e5f;
|
||||||
Point lastPoint = points.get(points.size() - 1);
|
float dlat = (dis.readShort()) / 2.0e5f;
|
||||||
|
|
||||||
float dlon = (dis.readShort()) / 2.0e5f;
|
points.add(new Point(lastPoint.getLongitude() + dlon, lastPoint.getLatitude() + dlat));
|
||||||
float dlat = (dis.readShort()) / 2.0e5f;
|
}
|
||||||
|
|
||||||
points.add(new Point(lastPoint.getLongitude() + dlon,
|
points.add(nodes.get(destNode).getPoint());
|
||||||
lastPoint.getLatitude() + dlat));
|
|
||||||
}
|
|
||||||
|
|
||||||
points.add(nodes.get(destNode).getPoint());
|
if (graphZone == destZone) {
|
||||||
|
|
||||||
if (graphZone == destZone) {
|
RoadInformation info = descs[descrNum];
|
||||||
|
Node orig = nodes.get(node);
|
||||||
|
Node dest = nodes.get(destNode);
|
||||||
|
|
||||||
RoadInformation info = descs[descrNum];
|
// Add successor to initial arc.
|
||||||
Node orig = nodes.get(node);
|
new Arc(orig, dest, length, info, points);
|
||||||
Node dest = nodes.get(destNode);
|
|
||||||
|
|
||||||
// Add successor to initial arc.
|
// And reverse arc if its a two-way road.
|
||||||
new Arc(orig, dest, length, info, points);
|
if (!info.isOneWay()) {
|
||||||
|
// Add without segments.
|
||||||
|
ArrayList<Point> rPoints = new ArrayList<Point>(points);
|
||||||
|
Collections.reverse(rPoints);
|
||||||
|
new Arc(dest, orig, length, info, rPoints);
|
||||||
|
}
|
||||||
|
|
||||||
// And reverse arc if its a two-way road.
|
}
|
||||||
if (!info.isOneWay()) {
|
}
|
||||||
// Add without segments.
|
}
|
||||||
ArrayList<Point> rPoints = new ArrayList<Point>(points);
|
|
||||||
Collections.reverse(rPoints);
|
|
||||||
new Arc(dest, orig, length, info, rPoints);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
// Check format.
|
||||||
}
|
checkByteOrThrow(253);
|
||||||
}
|
|
||||||
|
|
||||||
// Check format.
|
return new Graph(mapId, nodes);
|
||||||
checkByteOrThrow(253);
|
}
|
||||||
|
|
||||||
return new Graph(mapId, nodes);
|
/**
|
||||||
}
|
* Read the next road information from the stream.
|
||||||
|
*
|
||||||
/**
|
* @throws IOException
|
||||||
* Read the next road information from the stream.
|
*/
|
||||||
*
|
private RoadInformation readRoadInformation() throws IOException {
|
||||||
* @throws IOException
|
char type = (char) dis.readUnsignedByte();
|
||||||
*/
|
int x = dis.readUnsignedByte();
|
||||||
private RoadInformation readRoadInformation() throws IOException {
|
return new RoadInformation(toRoadType(type), (x & 0x80) > 0, (x & 0x7F) * 5, dis.readUTF());
|
||||||
char type = (char)dis.readUnsignedByte();
|
}
|
||||||
int x = dis.readUnsignedByte() ;
|
|
||||||
return new RoadInformation(toRoadType(type), (x & 0x80) > 0, (x & 0x7F) * 5, dis.readUTF());
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user