Skip to content

Commit c978d29

Browse files
author
Peter
committed
major: pillarNode enabled storage; Path is now edgeId based; introduced PointList;
1 parent 754d0ec commit c978d29

File tree

62 files changed

+1328
-1070
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1328
-1070
lines changed

nb-configuration.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ You can copy and paste the single properties, into the pom.xml file and the IDE
1616
That way multiple projects can share the same settings (useful for formatting rules for example).
1717
Any value defined here will override the pom.xml file value but is only applicable to the current project.
1818
-->
19-
<netbeans.hint.jdkPlatform>Oracle_JDK_1.6</netbeans.hint.jdkPlatform>
19+
<netbeans.hint.jdkPlatform>JDK_1.6</netbeans.hint.jdkPlatform>
2020
<org-netbeans-modules-whitelist.whitelist-oracle>false</org-netbeans-modules-whitelist.whitelist-oracle>
2121
<netbeans.compile.on.save>all</netbeans.compile.on.save>
2222
</properties>

pom.xml

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,18 @@
1010
<packaging>jar</packaging>
1111
<properties>
1212
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
13-
<slf4j.version>1.7.2</slf4j.version>
13+
<slf4j.version>1.7.2</slf4j.version>
14+
<netbeans.hint.license>apache20</netbeans.hint.license>
1415
</properties>
15-
16+
<licenses>
17+
<license>
18+
<name>The Apache Software License, Version 2.0</name>
19+
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
20+
<distribution>repo</distribution>
21+
<comments>A business-friendly OSS license</comments>
22+
</license>
23+
</licenses>
24+
1625
<dependencies>
1726

1827
<!-- Trove is LGPL and slightly big (~3MB) -->
@@ -79,7 +88,7 @@
7988
<artifactId>maven-compiler-plugin</artifactId>
8089
<version>3.0</version>
8190
<configuration>
82-
<!-- <compilerArgument>-Xlint:unchecked</compilerArgument>
91+
<!-- <compilerArgument>-Xlint:unchecked</compilerArgument>
8392
-->
8493
<source>1.6</source>
8594
<target>1.6</target>

src/main/java/com/graphhopper/GHResponse.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515
*/
1616
package com.graphhopper;
1717

18-
import com.graphhopper.util.shapes.GHPoint;
19-
import java.util.List;
18+
import com.graphhopper.util.PointList;
2019

2120
/**
2221
* Wrapper to simplify output of GraphHopper.
@@ -25,12 +24,12 @@
2524
*/
2625
public class GHResponse {
2726

28-
private final List<GHPoint> list;
27+
private final PointList list;
2928
private double distance;
3029
private long time;
3130
private String debugInfo = "";
3231

33-
public GHResponse(List<GHPoint> list) {
32+
public GHResponse(PointList list) {
3433
this.list = list;
3534
}
3635

@@ -56,7 +55,7 @@ public boolean found() {
5655
return !list.isEmpty();
5756
}
5857

59-
public List<GHPoint> points() {
58+
public PointList points() {
6059
return list;
6160
}
6261

src/main/java/com/graphhopper/GraphHopper.java

+11-16
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,8 @@
3333
import com.graphhopper.util.DouglasPeucker;
3434
import com.graphhopper.util.Helper;
3535
import com.graphhopper.util.StopWatch;
36-
import com.graphhopper.util.shapes.GHPoint;
3736
import java.io.File;
3837
import java.io.IOException;
39-
import java.util.ArrayList;
40-
import java.util.List;
4138

4239
/**
4340
* Main wrapper of the offline API for a simple and efficient usage.
@@ -55,6 +52,7 @@ public class GraphHopper implements GraphHopperAPI {
5552
private boolean memoryMapped;
5653
private boolean levelGraph;
5754
private String ghLocation = "";
55+
private boolean simplify = true;
5856

5957
public GraphHopper() {
6058
}
@@ -102,6 +100,11 @@ public GraphHopper levelGraph() {
102100
return this;
103101
}
104102

103+
public GraphHopper simplify(boolean doSimplify) {
104+
this.simplify = doSimplify;
105+
return this;
106+
}
107+
105108
public GraphHopper setGraphHopperLocation(String ghLocation) {
106109
if (ghLocation != null)
107110
this.ghLocation = ghLocation;
@@ -194,7 +197,7 @@ public GHResponse route(GHRequest request) {
194197
} else
195198
prepare = Helper.createAlgoPrepare(request.algorithm());
196199

197-
request.check();
200+
request.check();
198201
StopWatch sw = new StopWatch().start();
199202
int from = index.findID(request.from().lat, request.from().lon);
200203
int to = index.findID(request.to().lat, request.to().lon);
@@ -206,20 +209,12 @@ public GHResponse route(GHRequest request) {
206209
Path path = algo.calcPath(from, to);
207210
debug += " routing (" + algo.name() + "):" + sw.stop().getSeconds() + "s";
208211

209-
sw = new StopWatch().start();
210-
path.simplify(new DouglasPeucker(graph).setMaxDist(request.minPathPrecision()));
211-
debug += " simplify:" + sw.stop().getSeconds() + "s";
212-
213-
int nodes = path.nodes();
214-
List<GHPoint> list = new ArrayList<GHPoint>(nodes);
215-
if (path.found()) {
212+
if (simplify) {
216213
sw = new StopWatch().start();
217-
for (int i = 0; i < nodes; i++) {
218-
list.add(new GHPoint(graph.getLatitude(path.node(i)), graph.getLongitude(path.node(i))));
219-
}
220-
debug += " createList:" + sw.stop().getSeconds() + "s";
214+
path.simplify(new DouglasPeucker().setMaxDist(request.minPathPrecision()));
215+
debug += " simplify:" + sw.stop().getSeconds() + "s";
221216
}
222-
return new GHResponse(list).distance(path.distance()).time(path.time()).debugInfo(debug);
217+
return new GHResponse(path.points()).distance(path.distance()).time(path.time()).debugInfo(debug);
223218
}
224219

225220
private void initIndex(Directory dir) {

src/main/java/com/graphhopper/GraphHopperWeb.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.graphhopper;
1717

18+
import com.graphhopper.util.PointList;
1819
import com.graphhopper.util.StopWatch;
1920
import com.graphhopper.util.shapes.GHPoint;
2021
import java.io.DataInputStream;
@@ -86,11 +87,11 @@ public GHResponse route(GHRequest request) {
8687
float distance = is.readFloat();
8788
int time = is.readInt();
8889
int nodes = is.readInt();
89-
List<GHPoint> list = new ArrayList<GHPoint>(nodes);
90+
PointList list = new PointList(nodes);
9091
for (int i = 0; i < nodes; i++) {
9192
float lat = is.readFloat();
9293
float lon = is.readFloat();
93-
list.add(new GHPoint(lat, lon));
94+
list.add(lat, lon);
9495
}
9596
return new GHResponse(list).distance(distance).time(time);
9697
} catch (IOException ex) {

src/main/java/com/graphhopper/reader/OSMReaderHelper.java

+12-22
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
import com.graphhopper.storage.GraphStorage;
2020
import com.graphhopper.util.DistanceCalc;
2121
import com.graphhopper.util.EdgeIterator;
22-
import gnu.trove.list.TDoubleList;
23-
import gnu.trove.list.TIntList;
22+
import com.graphhopper.util.PointList;
2423
import gnu.trove.list.TLongList;
25-
import gnu.trove.list.array.TIntArrayList;
2624
import java.io.InputStream;
2725
import org.slf4j.Logger;
2826
import org.slf4j.LoggerFactory;
@@ -32,7 +30,6 @@
3230
*/
3331
public abstract class OSMReaderHelper {
3432

35-
protected static final int FILLED = -2;
3633
private final Logger logger = LoggerFactory.getLogger(getClass());
3734
protected int counter = 0;
3835
protected int zeroCounter = 0;
@@ -56,29 +53,26 @@ public int getExpectedNodes() {
5653
public void preProcess(InputStream osmXml) {
5754
}
5855

59-
public boolean addNode(long osmId, double lat, double lon) {
60-
return true;
61-
}
56+
public abstract boolean addNode(long osmId, double lat, double lon);
6257

6358
public abstract int addEdge(TLongList nodes, int flags);
6459

65-
public int addEdge(TDoubleList latitudes, TDoubleList longitudes,
66-
TIntList allNodes, int flags) {
67-
int nodes = allNodes.size();
68-
if (latitudes.size() != nodes || longitudes.size() != nodes)
69-
throw new IllegalArgumentException("latitudes.size must be equals to longitudes.size and node list size " + nodes);
70-
60+
public int addEdge(int fromIndex, int toIndex, PointList pointList, int flags) {
7161
double towerNodeDistance = 0;
72-
double prevLat = latitudes.get(0);
73-
double prevLon = longitudes.get(0);
62+
double prevLat = pointList.latitude(0);
63+
double prevLon = pointList.longitude(0);
7464
double lat;
7565
double lon;
66+
PointList pillarNodes = new PointList(pointList.size() - 2);
67+
int nodes = pointList.size();
7668
for (int i = 1; i < nodes; i++) {
77-
lat = latitudes.get(i);
78-
lon = longitudes.get(i);
69+
lat = pointList.latitude(i);
70+
lon = pointList.longitude(i);
7971
towerNodeDistance += callback.calcDist(prevLat, prevLon, lat, lon);
8072
prevLat = lat;
8173
prevLon = lon;
74+
if (nodes > 2 && i < nodes - 1)
75+
pillarNodes.add(lat, lon);
8276
}
8377
if (towerNodeDistance == 0) {
8478
// As investigation shows often two paths should have crossed via one identical point
@@ -88,13 +82,9 @@ public int addEdge(TDoubleList latitudes, TDoubleList longitudes,
8882
towerNodeDistance = 0.0001;
8983
}
9084

91-
int fromIndex = allNodes.get(0);
92-
int toIndex = allNodes.get(nodes - 1);
9385
EdgeIterator iter = g.edge(fromIndex, toIndex, towerNodeDistance, flags);
94-
if (nodes > 2) {
95-
TIntList pillarNodes = allNodes.subList(1, nodes - 1);
86+
if (nodes > 2)
9687
iter.pillarNodes(pillarNodes);
97-
}
9888
return nodes;
9989
}
10090

0 commit comments

Comments
 (0)