|
@@ -13,8 +13,7 @@ import com.fdkankan.indoor.core.entity.dto.RouteInputDto;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
|
-public class GetRoute
|
|
|
-{
|
|
|
+public class GetRoute {
|
|
|
|
|
|
/*
|
|
|
public static void main(String[] args)
|
|
@@ -46,30 +45,9 @@ public class GetRoute
|
|
|
}
|
|
|
*/
|
|
|
|
|
|
-
|
|
|
- /**
|
|
|
- * 读取文件,获取文件内容
|
|
|
- * F:\test\project\age_laser\routeMap.txt
|
|
|
- *
|
|
|
- * list 是routeMap的结果集
|
|
|
- * @return
|
|
|
- */
|
|
|
- public static JSONArray getRoute(List<String> list, RouteInputDto dto, ControlPointEntity controlPoint){
|
|
|
- try {
|
|
|
- JSONArray maps = readMap(list, dto);
|
|
|
- MapInfo info=new MapInfo(maps,start,end);
|
|
|
- List<Node> path = g_AStar.start(info);
|
|
|
- JSONArray jsonArray = convertFromPath(path, dto, controlPoint);
|
|
|
- return jsonArray;
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
-// public static String inputFilePath = "F:\\2021\\navvis\\���Ի���\\test3(v2.7.3)\\map.txt";
|
|
|
+ // public static String inputFilePath = "F:\\2021\\navvis\\���Ի���\\test3(v2.7.3)\\map.txt";
|
|
|
private static String inputFilePath = "F:\\test\\project\\age_laser\\routeMap.txt";
|
|
|
-
|
|
|
+
|
|
|
// private static float startX = 5.358192084229412f;
|
|
|
// private static float startY = -7.905951689748807f;
|
|
|
// private static float startZ = -1.3145928255248511f;
|
|
@@ -88,11 +66,109 @@ public class GetRoute
|
|
|
|
|
|
private static int minStartId = -1;
|
|
|
private static int minEndId = -1;
|
|
|
-
|
|
|
+
|
|
|
private static Node start = null;
|
|
|
private static Node end = null;
|
|
|
private static AStar g_AStar = new AStar();
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 读取文件,获取文件内容
|
|
|
+ * F:\test\project\age_laser\routeMap.txt
|
|
|
+ *
|
|
|
+ * list 是routeMap的结果集
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static JSONArray getRoute(List<String> list, RouteInputDto dto, ControlPointEntity controlPoint){
|
|
|
+ try {
|
|
|
+ JSONArray maps = readMap(list, dto);
|
|
|
+ MapInfo info=new MapInfo(maps,start,end);
|
|
|
+ List<Node> path = g_AStar.start(info);
|
|
|
+ JSONArray jsonArray = convertFromPath(path, dto, controlPoint);
|
|
|
+ return jsonArray;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+// private static JSONArray readMap(List<String> list, RouteInputDto dto) throws Exception {
|
|
|
+//// List<String> list = FileUtil.readFileByLines2(inputFilePath);
|
|
|
+// JSONArray maps = new JSONArray();
|
|
|
+//
|
|
|
+// Double startX = dto.getSource_longitude();
|
|
|
+// Double startY = dto.getSource_latitude();
|
|
|
+// Double startZ = dto.getSource_z();
|
|
|
+//
|
|
|
+// Double endX = dto.getDestination_longitude();
|
|
|
+// Double endY = dto.getDestination_latitude();
|
|
|
+// Double endZ = dto.getDestination_z();
|
|
|
+//
|
|
|
+//
|
|
|
+// Coord _start = new Coord(startX,startY,startZ);
|
|
|
+// Coord _end = new Coord(endX,endY,endZ);
|
|
|
+//
|
|
|
+// double startDistance=1.5;
|
|
|
+// double endDistance = 1.5;
|
|
|
+//
|
|
|
+// double minStartDistance = 1000.0;
|
|
|
+// double minEndDistance = 1000.0;
|
|
|
+//
|
|
|
+// for(int i=0;i<list.size();++i) {
|
|
|
+// String str = list.get(i);
|
|
|
+// String[] strArray = str.trim().split(" ");
|
|
|
+// JSONObject item = new JSONObject();
|
|
|
+// //item.put("id", i);
|
|
|
+// item.put("x", strArray[0]);
|
|
|
+// item.put("y", strArray[1]);
|
|
|
+// item.put("z", strArray[2]);
|
|
|
+// //item.put("weight", strArray[3]);
|
|
|
+// item.put("weight", 1);
|
|
|
+// String linkedIds = "";
|
|
|
+// for(int j = 4;j<strArray.length;++j) {
|
|
|
+// if(Integer.valueOf(strArray[j])>0) {
|
|
|
+// linkedIds += strArray[j]+",";
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// item.put("linkedIds", linkedIds.substring(0, linkedIds.length()-1));
|
|
|
+// maps.add(item);
|
|
|
+//
|
|
|
+// Coord coord = new Coord(Double.valueOf(strArray[0]),Double.valueOf(strArray[1]),Double.valueOf(strArray[2]));
|
|
|
+// //先找起点附近的点
|
|
|
+// double _startDistance = g_AStar.calcH(_start, coord);
|
|
|
+//
|
|
|
+//
|
|
|
+// if(_startDistance<startDistance) {
|
|
|
+// //附近点里,离终点的距离最小的
|
|
|
+// if(minStartDistance>g_AStar.calcH(_end, coord)){
|
|
|
+// minStartId = i;
|
|
|
+// minStartDistance = g_AStar.calcH(_end, coord);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// //先找终点附近的点
|
|
|
+// double _endDistance = g_AStar.calcH(_end, coord);
|
|
|
+// if(_endDistance<endDistance) {
|
|
|
+// //附近点里,离起点的距离最小的
|
|
|
+// if(minEndDistance>g_AStar.calcH(_start, coord)){
|
|
|
+// minEndId = i;
|
|
|
+// minEndDistance = g_AStar.calcH(_start, coord);
|
|
|
+// }
|
|
|
+// }
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONObject virtualStart = maps.getJSONObject(minStartId);
|
|
|
+// JSONObject virtualEnd = maps.getJSONObject(minEndId);
|
|
|
+// Coord startVirtualCoord = new Coord(virtualStart.getDouble("x"), virtualStart.getDouble("y"),virtualStart.getDouble("z"));
|
|
|
+// Coord endVirtualCoord = new Coord(virtualEnd.getDouble("x"), virtualEnd.getDouble("y"),virtualEnd.getDouble("z"));
|
|
|
+// Double startH = g_AStar.calcH(startVirtualCoord, endVirtualCoord);
|
|
|
+//
|
|
|
+// start = new Node(minStartId,0.0,startVirtualCoord, null, 0.0, startH);
|
|
|
+// end = new Node(minEndId,0.0,endVirtualCoord, null, 0.0, 0.0);
|
|
|
+//
|
|
|
+// return maps;
|
|
|
+// }
|
|
|
+
|
|
|
private static JSONArray readMap(List<String> list, RouteInputDto dto) throws Exception {
|
|
|
// List<String> list = FileUtil.readFileByLines2(inputFilePath);
|
|
|
JSONArray maps = new JSONArray();
|
|
@@ -157,7 +233,9 @@ public class GetRoute
|
|
|
return maps;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
private static JSONArray convertFromPath(List<Node> mappath, RouteInputDto dto, ControlPointEntity controlPoint) {
|
|
|
+ double defaultdistance = 0.36;
|
|
|
if(mappath == null||mappath.size() == 0) {
|
|
|
return null;
|
|
|
}
|
|
@@ -172,10 +250,43 @@ public class GetRoute
|
|
|
Double endY = dto.getDestination_latitude();
|
|
|
Double endZ = dto.getDestination_z();
|
|
|
|
|
|
+ if(mappath.size()>5){
|
|
|
+
|
|
|
+ //从前三个和后三个路径点开始优化,防止绕来绕去
|
|
|
+ Node tempNode = mappath.get(mappath.size()-2);
|
|
|
+ double dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
|
|
|
+ if(dis<defaultdistance){
|
|
|
+ mappath.remove(mappath.size()-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ tempNode = mappath.get(mappath.size()-2);
|
|
|
+ dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
|
|
|
+ if(dis<defaultdistance){
|
|
|
+ mappath.remove(mappath.size()-1);
|
|
|
+ }
|
|
|
+
|
|
|
+ tempNode = mappath.get(0);
|
|
|
+ dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
|
|
|
+ if(dis<defaultdistance){
|
|
|
+ mappath.remove(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ tempNode = mappath.get(0);
|
|
|
+ dis = g_AStar.calcH(tempNode.coord,new Coord(startX,startY,startZ));
|
|
|
+ if(dis<defaultdistance){
|
|
|
+ mappath.remove(0);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
List<Node> path = new ArrayList<Node>();
|
|
|
- for(int i = mappath.size()-1;i>-1;--i) {
|
|
|
+// for(int i = mappath.size()-1;i>-1;--i) {
|
|
|
+// Node node = mappath.get(i);
|
|
|
+// path.add(node);
|
|
|
+// }
|
|
|
+
|
|
|
+ for(int i = mappath.size()-1;i>-1;) {
|
|
|
Node node = mappath.get(i);
|
|
|
+ i -= 3;
|
|
|
path.add(node);
|
|
|
}
|
|
|
|
|
@@ -183,8 +294,7 @@ public class GetRoute
|
|
|
|
|
|
//起点不在path上,path的第一个点对应的是格子
|
|
|
JSONObject start = new JSONObject();
|
|
|
-// start.put("longitude", startX);
|
|
|
-// start.put("latitude", startY);
|
|
|
+
|
|
|
|
|
|
double[] startPosition = {startX,startY};
|
|
|
startPosition = TransformGPS.convert(startPosition, controlPoint);
|
|
@@ -192,8 +302,7 @@ public class GetRoute
|
|
|
start.put("latitude", startPosition[1]);
|
|
|
start.put("z", startZ);
|
|
|
Double[] location = new Double[3];
|
|
|
-// location[0] = startX;
|
|
|
-// location[1] = startY;
|
|
|
+
|
|
|
|
|
|
location[0] = startPosition[0];
|
|
|
location[1] = startPosition[1];
|
|
@@ -216,12 +325,10 @@ public class GetRoute
|
|
|
item.put("longitude", position[0]);
|
|
|
item.put("latitude", position[1]);
|
|
|
|
|
|
-// item.put("longitude", node.coord.x);
|
|
|
-// item.put("latitude", node.coord.y);
|
|
|
+
|
|
|
item.put("z", node.coord.z);
|
|
|
location = new Double[3];
|
|
|
-// location[0] = node.coord.x;
|
|
|
-// location[1] = node.coord.y;
|
|
|
+
|
|
|
|
|
|
location[0] = position[0];
|
|
|
location[1] = position[1];
|
|
@@ -289,6 +396,138 @@ public class GetRoute
|
|
|
return route;
|
|
|
}
|
|
|
|
|
|
+// private static JSONArray convertFromPath(List<Node> mappath, RouteInputDto dto, ControlPointEntity controlPoint) {
|
|
|
+// if(mappath == null||mappath.size() == 0) {
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+//
|
|
|
+// // 起始点
|
|
|
+// Double startX = dto.getSource_longitude();
|
|
|
+// Double startY = dto.getSource_latitude();
|
|
|
+// Double startZ = dto.getSource_z();
|
|
|
+//
|
|
|
+// // 终点
|
|
|
+// Double endX = dto.getDestination_longitude();
|
|
|
+// Double endY = dto.getDestination_latitude();
|
|
|
+// Double endZ = dto.getDestination_z();
|
|
|
+//
|
|
|
+//
|
|
|
+// List<Node> path = new ArrayList<Node>();
|
|
|
+// for(int i = mappath.size()-1;i>-1;--i) {
|
|
|
+// Node node = mappath.get(i);
|
|
|
+// path.add(node);
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONArray route = new JSONArray();
|
|
|
+//
|
|
|
+// //起点不在path上,path的第一个点对应的是格子
|
|
|
+// JSONObject start = new JSONObject();
|
|
|
+//// start.put("longitude", startX);
|
|
|
+//// start.put("latitude", startY);
|
|
|
+//
|
|
|
+// double[] startPosition = {startX,startY};
|
|
|
+// startPosition = TransformGPS.convert(startPosition, controlPoint);
|
|
|
+// start.put("longitude", startPosition[0]);
|
|
|
+// start.put("latitude", startPosition[1]);
|
|
|
+// start.put("z", startZ);
|
|
|
+// Double[] location = new Double[3];
|
|
|
+//// location[0] = startX;
|
|
|
+//// location[1] = startY;
|
|
|
+//
|
|
|
+// location[0] = startPosition[0];
|
|
|
+// location[1] = startPosition[1];
|
|
|
+// location[2] = startZ;
|
|
|
+//
|
|
|
+// start.put("location", location);
|
|
|
+// start.put("distance", 0);
|
|
|
+// start.put("distance_to_previous", 0);
|
|
|
+// start.put("instruction", null);
|
|
|
+// route.add(start);
|
|
|
+//
|
|
|
+// Double[] virtualEndPosition = new Double[3];
|
|
|
+// for(int i=0;i<path.size();++i) {
|
|
|
+// Node node = path.get(i);
|
|
|
+// JSONObject item = new JSONObject();
|
|
|
+//
|
|
|
+// //转经纬度
|
|
|
+// double[] position = {node.coord.x,node.coord.y};
|
|
|
+// position = TransformGPS.convert(position, controlPoint);
|
|
|
+// item.put("longitude", position[0]);
|
|
|
+// item.put("latitude", position[1]);
|
|
|
+//
|
|
|
+//// item.put("longitude", node.coord.x);
|
|
|
+//// item.put("latitude", node.coord.y);
|
|
|
+// item.put("z", node.coord.z);
|
|
|
+// location = new Double[3];
|
|
|
+//// location[0] = node.coord.x;
|
|
|
+//// location[1] = node.coord.y;
|
|
|
+//
|
|
|
+// location[0] = position[0];
|
|
|
+// location[1] = position[1];
|
|
|
+//
|
|
|
+// location[2] = node.coord.z;
|
|
|
+// item.put("location", location);
|
|
|
+// item.put("id", node.id);
|
|
|
+//
|
|
|
+// JSONObject instruction = null;
|
|
|
+//
|
|
|
+// if(i == 0) {
|
|
|
+// item.put("distance", g_AStar.calcH(node.coord,new Coord(startX,startY,startZ)));
|
|
|
+// item.put("distance_to_previous", g_AStar.calcH(node.coord,new Coord(startX,startY,startZ)));
|
|
|
+// item.put("instruction", instruction);
|
|
|
+//
|
|
|
+// instruction = new JSONObject();
|
|
|
+// instruction.put("type", "source_projection_to_navgraph");
|
|
|
+// item.put("instruction", instruction);
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// Node prenode = path.get(i-1);
|
|
|
+// JSONObject preitem = route.getJSONObject(i);
|
|
|
+// Double distance_to_previous = g_AStar.calcH(node.coord,prenode.coord);
|
|
|
+// item.put("distance_to_previous", distance_to_previous);
|
|
|
+// Double distance = preitem.getDouble("distance")+distance_to_previous;
|
|
|
+// item.put("distance", distance);
|
|
|
+// if(i == path.size()-1) {
|
|
|
+// instruction = new JSONObject();
|
|
|
+// instruction.put("type", "destination_projection_to_navgraph");
|
|
|
+// item.put("instruction", instruction);
|
|
|
+//
|
|
|
+// virtualEndPosition[0] = node.coord.x;
|
|
|
+// virtualEndPosition[1] = node.coord.y;
|
|
|
+// virtualEndPosition[2] = node.coord.z;
|
|
|
+//
|
|
|
+// }
|
|
|
+// else {
|
|
|
+// item.put("instruction", instruction);
|
|
|
+// }
|
|
|
+// System.out.println("distance:"+distance_to_previous);
|
|
|
+// }
|
|
|
+//
|
|
|
+// route.add(item);
|
|
|
+// }
|
|
|
+//
|
|
|
+// JSONObject endItem = route.getJSONObject(route.size()-1);
|
|
|
+// JSONObject end = new JSONObject();
|
|
|
+// double[] endPosition = {endX,endY};
|
|
|
+// endPosition = TransformGPS.convert(endPosition, controlPoint);
|
|
|
+//
|
|
|
+// end.put("longitude", endPosition[0]);
|
|
|
+// end.put("latitude", endPosition[1]);
|
|
|
+// end.put("z", endZ);
|
|
|
+// location = new Double[3];
|
|
|
+// location[0] = endPosition[0];
|
|
|
+// location[1] = endPosition[1];
|
|
|
+// location[2] = endZ;
|
|
|
+// end.put("location", location);
|
|
|
+// Double enddistance = g_AStar.calcH(new Coord(virtualEndPosition[0],virtualEndPosition[1],virtualEndPosition[2]),new Coord(endX,endY,endZ));
|
|
|
+// end.put("distance", enddistance+(float)endItem.getDouble("distance"));
|
|
|
+// end.put("distance_to_previous", enddistance);
|
|
|
+// end.put("instruction", null);
|
|
|
+// route.add(end);
|
|
|
+//
|
|
|
+// return route;
|
|
|
+// }
|
|
|
+
|
|
|
|
|
|
private static JSONArray readMap() throws Exception {
|
|
|
List<String> list = FileUtil.readFileByLines2(inputFilePath);
|