Add bounding-box in GraphStatistics.
This commit is contained in:
parent
2a77c2d271
commit
84f01ce47e
@ -10,6 +10,46 @@ package org.insa.graph;
|
|||||||
*/
|
*/
|
||||||
public class GraphStatistics {
|
public class GraphStatistics {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class representing a bounding box for a graph (a rectangle that contains all
|
||||||
|
* nodes in the graph).
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static class BoundingBox {
|
||||||
|
|
||||||
|
private final Point topLeft, bottomRight;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new BoundingBox represented by the given top-left and bottom-right
|
||||||
|
* points.
|
||||||
|
*
|
||||||
|
* @param topLeft Top left corner of the bounding box.
|
||||||
|
* @param bottomRight Bottom right corner of the bounding box.
|
||||||
|
*/
|
||||||
|
public BoundingBox(Point topLeft, Point bottomRight) {
|
||||||
|
this.topLeft = topLeft;
|
||||||
|
this.bottomRight = bottomRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Bottom-right point of this boundin box.
|
||||||
|
*/
|
||||||
|
public Point getBottomRightPoint() {
|
||||||
|
return bottomRight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Top-left point of this bounding box.
|
||||||
|
*/
|
||||||
|
public Point getTopLeftPoint() {
|
||||||
|
return topLeft;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bounding box for this graph.
|
||||||
|
private final BoundingBox boundingBox;
|
||||||
|
|
||||||
// Maximum speed on this graph (in kmph).
|
// Maximum speed on this graph (in kmph).
|
||||||
private final int maximumSpeed;
|
private final int maximumSpeed;
|
||||||
|
|
||||||
@ -23,11 +63,19 @@ public class GraphStatistics {
|
|||||||
* be used to indicate that this graph has no maximum limitation.
|
* be used to indicate that this graph has no maximum limitation.
|
||||||
* @param maximumLength Maximum length of any arc of the graph.
|
* @param maximumLength Maximum length of any arc of the graph.
|
||||||
*/
|
*/
|
||||||
public GraphStatistics(int maximumSpeed, float maximumLength) {
|
public GraphStatistics(BoundingBox boundingBox, int maximumSpeed, float maximumLength) {
|
||||||
|
this.boundingBox = boundingBox;
|
||||||
this.maximumLength = maximumLength;
|
this.maximumLength = maximumLength;
|
||||||
this.maximumSpeed = maximumSpeed;
|
this.maximumSpeed = maximumSpeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The bounding box for this graph.
|
||||||
|
*/
|
||||||
|
public BoundingBox getBoundingBox() {
|
||||||
|
return this.boundingBox;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Maximum speed of any arc in the graph, or 0 if some road have no
|
* @return Maximum speed of any arc in the graph, or 0 if some road have no
|
||||||
* speed limitations.
|
* speed limitations.
|
||||||
|
@ -12,6 +12,7 @@ import org.insa.graph.AccessRestrictions.AccessRestriction;
|
|||||||
import org.insa.graph.Arc;
|
import org.insa.graph.Arc;
|
||||||
import org.insa.graph.Graph;
|
import org.insa.graph.Graph;
|
||||||
import org.insa.graph.GraphStatistics;
|
import org.insa.graph.GraphStatistics;
|
||||||
|
import org.insa.graph.GraphStatistics.BoundingBox;
|
||||||
import org.insa.graph.Node;
|
import org.insa.graph.Node;
|
||||||
import org.insa.graph.Point;
|
import org.insa.graph.Point;
|
||||||
import org.insa.graph.RoadInformation;
|
import org.insa.graph.RoadInformation;
|
||||||
@ -49,7 +50,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
|||||||
// the order correspond to the 4 bits value (i.e. FORBIDDEN is 0 or PRIVATE is
|
// the order correspond to the 4 bits value (i.e. FORBIDDEN is 0 or PRIVATE is
|
||||||
// 2) - UKNOWN is not included because value above 6 (FORESTRY) are all
|
// 2) - UKNOWN is not included because value above 6 (FORESTRY) are all
|
||||||
// considered unknown.
|
// considered unknown.
|
||||||
final AccessRestriction[] allRestrictions = new AccessRestriction[]{
|
final AccessRestriction[] allRestrictions = new AccessRestriction[] {
|
||||||
AccessRestriction.FORBIDDEN, AccessRestriction.ALLOWED, AccessRestriction.PRIVATE,
|
AccessRestriction.FORBIDDEN, AccessRestriction.ALLOWED, AccessRestriction.PRIVATE,
|
||||||
AccessRestriction.DESTINATION, AccessRestriction.DELIVERY,
|
AccessRestriction.DESTINATION, AccessRestriction.DELIVERY,
|
||||||
AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY };
|
AccessRestriction.CUSTOMERS, AccessRestriction.FORESTRY };
|
||||||
@ -57,7 +58,7 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
|||||||
// The order of values inside this array is VERY IMPORTANT: The order is such
|
// The order of values inside this array is VERY IMPORTANT: The order is such
|
||||||
// that each 4-bits group of the long value is processed in the correct order,
|
// that each 4-bits group of the long value is processed in the correct order,
|
||||||
// i.e. FOOT is processed first (4 lowest bits), and so on.
|
// i.e. FOOT is processed first (4 lowest bits), and so on.
|
||||||
final AccessMode[] allModes = new AccessMode[]{ AccessMode.FOOT, null, AccessMode.BICYCLE,
|
final AccessMode[] allModes = new AccessMode[] { AccessMode.FOOT, null, AccessMode.BICYCLE,
|
||||||
AccessMode.SMALL_MOTORCYCLE, AccessMode.AGRICULTURAL, AccessMode.MOTORCYCLE,
|
AccessMode.SMALL_MOTORCYCLE, AccessMode.AGRICULTURAL, AccessMode.MOTORCYCLE,
|
||||||
AccessMode.MOTORCAR, AccessMode.HEAVY_GOODS, null, AccessMode.PUBLIC_TRANSPORT };
|
AccessMode.MOTORCAR, AccessMode.HEAVY_GOODS, null, AccessMode.PUBLIC_TRANSPORT };
|
||||||
|
|
||||||
@ -179,12 +180,25 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
|||||||
ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
|
ArrayList<Node> nodes = new ArrayList<Node>(nbNodes);
|
||||||
|
|
||||||
// Read nodes.
|
// Read nodes.
|
||||||
|
float minLongitude = Float.POSITIVE_INFINITY, minLatitude = Float.POSITIVE_INFINITY,
|
||||||
|
maxLongitude = Float.NEGATIVE_INFINITY, maxLatitude = Float.NEGATIVE_INFINITY;
|
||||||
observers.forEach((observer) -> observer.notifyStartReadingNodes(nbNodes));
|
observers.forEach((observer) -> observer.notifyStartReadingNodes(nbNodes));
|
||||||
for (int node = 0; node < nbNodes; ++node) {
|
for (int node = 0; node < nbNodes; ++node) {
|
||||||
|
// Read longitude / latitude.
|
||||||
float longitude = ((float) dis.readInt()) / 1E6f;
|
float longitude = ((float) dis.readInt()) / 1E6f;
|
||||||
float latitude = ((float) dis.readInt()) / 1E6f;
|
float latitude = ((float) dis.readInt()) / 1E6f;
|
||||||
|
|
||||||
|
// Update minimum / maximum.
|
||||||
|
minLongitude = Math.min(longitude, minLongitude);
|
||||||
|
minLatitude = Math.min(latitude, minLatitude);
|
||||||
|
maxLongitude = Math.max(longitude, maxLongitude);
|
||||||
|
maxLatitude = Math.max(latitude, maxLatitude);
|
||||||
|
|
||||||
|
// Update information.
|
||||||
nbSuccessors[node] = dis.readUnsignedByte();
|
nbSuccessors[node] = dis.readUnsignedByte();
|
||||||
nbTotalSuccessors += nbSuccessors[node];
|
nbTotalSuccessors += nbSuccessors[node];
|
||||||
|
|
||||||
|
// Create node.
|
||||||
final Node aNode = new Node(node, new Point(longitude, latitude));
|
final Node aNode = new Node(node, new Point(longitude, latitude));
|
||||||
nodes.add(aNode);
|
nodes.add(aNode);
|
||||||
observers.forEach((observer) -> observer.notifyNewNodeRead(aNode));
|
observers.forEach((observer) -> observer.notifyNewNodeRead(aNode));
|
||||||
@ -270,7 +284,9 @@ public class BinaryGraphReader extends BinaryReader implements GraphReader {
|
|||||||
|
|
||||||
this.dis.close();
|
this.dis.close();
|
||||||
|
|
||||||
return new Graph(mapId, mapName, nodes, new GraphStatistics(maxSpeed, maxLength));
|
return new Graph(mapId, mapName, nodes,
|
||||||
|
new GraphStatistics(new BoundingBox(new Point(minLongitude, maxLatitude),
|
||||||
|
new Point(maxLongitude, minLatitude)), maxSpeed, maxLength));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -23,6 +23,7 @@ import javax.swing.JPanel;
|
|||||||
|
|
||||||
import org.insa.graph.Arc;
|
import org.insa.graph.Arc;
|
||||||
import org.insa.graph.Graph;
|
import org.insa.graph.Graph;
|
||||||
|
import org.insa.graph.GraphStatistics.BoundingBox;
|
||||||
import org.insa.graph.Node;
|
import org.insa.graph.Node;
|
||||||
import org.insa.graph.Path;
|
import org.insa.graph.Path;
|
||||||
import org.insa.graph.Point;
|
import org.insa.graph.Point;
|
||||||
@ -394,6 +395,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.insa.graphics.drawing.Drawing#clear()
|
* @see org.insa.graphics.drawing.Drawing#clear()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -409,6 +411,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
* @see org.insa.graphics.drawing.Drawing#clearOverlays()
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
@ -469,6 +472,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see
|
* @see
|
||||||
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
* org.insa.graphics.drawing.Drawing#addDrawingClickListener(org.insa.graphics.
|
||||||
* drawing.DrawingClickListener)
|
* drawing.DrawingClickListener)
|
||||||
@ -480,6 +484,7 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* (non-Javadoc)
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
|
* @see org.insa.graphics.drawing.Drawing#removeDrawingClickListener(org.insa.
|
||||||
* graphics.drawing.DrawingClickListener)
|
* graphics.drawing.DrawingClickListener)
|
||||||
*/
|
*/
|
||||||
@ -561,24 +566,13 @@ public class BasicDrawing extends JPanel implements Drawing {
|
|||||||
// Clear everything.
|
// Clear everything.
|
||||||
this.clear();
|
this.clear();
|
||||||
|
|
||||||
|
BoundingBox box = graph.getGraphInformation().getBoundingBox();
|
||||||
|
|
||||||
// Find minimum/maximum longitude and latitude.
|
// Find minimum/maximum longitude and latitude.
|
||||||
double minLon = Double.POSITIVE_INFINITY, minLat = Double.POSITIVE_INFINITY,
|
double minLon = box.getTopLeftPoint().getLongitude(),
|
||||||
maxLon = Double.NEGATIVE_INFINITY, maxLat = Double.NEGATIVE_INFINITY;
|
maxLon = box.getBottomRightPoint().getLongitude(),
|
||||||
for (Node node: graph.getNodes()) {
|
minLat = box.getBottomRightPoint().getLatitude(),
|
||||||
Point pt = node.getPoint();
|
maxLat = box.getTopLeftPoint().getLatitude();
|
||||||
if (pt.getLatitude() < minLat) {
|
|
||||||
minLat = pt.getLatitude();
|
|
||||||
}
|
|
||||||
if (pt.getLatitude() > maxLat) {
|
|
||||||
maxLat = pt.getLatitude();
|
|
||||||
}
|
|
||||||
if (pt.getLongitude() < minLon) {
|
|
||||||
minLon = pt.getLongitude();
|
|
||||||
}
|
|
||||||
if (pt.getLongitude() > maxLon) {
|
|
||||||
maxLon = pt.getLongitude();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a little delta to avoid drawing on the edge...
|
// Add a little delta to avoid drawing on the edge...
|
||||||
double diffLon = maxLon - minLon, diffLat = maxLat - minLat;
|
double diffLon = maxLon - minLon, diffLat = maxLat - minLat;
|
||||||
|
Loading…
Reference in New Issue
Block a user