|
@@ -5,16 +5,23 @@ import java.util.List;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.extra.spring.SpringUtil;
|
|
|
import com.fdkankan.indoor.base.convert.kesar.AStar;
|
|
|
import com.fdkankan.indoor.base.convert.kesar.Coord;
|
|
|
import com.fdkankan.indoor.base.convert.kesar.MapInfo;
|
|
|
import com.fdkankan.indoor.base.convert.kesar.Node;
|
|
|
+import com.fdkankan.indoor.base.exception.BaseRuntimeException;
|
|
|
+import com.fdkankan.indoor.base.util.ResponseUtil;
|
|
|
import com.fdkankan.indoor.core.entity.ControlPointCalculateEntity;
|
|
|
import com.fdkankan.indoor.core.entity.ControlPointEntity;
|
|
|
import com.fdkankan.indoor.core.entity.dto.RouteInputDto;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import net.sf.json.JSONArray;
|
|
|
import net.sf.json.JSONObject;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+
|
|
|
+import javax.servlet.ServletResponse;
|
|
|
+
|
|
|
@Slf4j
|
|
|
public class GetRoute {
|
|
|
|
|
@@ -40,6 +47,7 @@ public class GetRoute {
|
|
|
private static AStar g_AStar = new AStar();
|
|
|
|
|
|
|
|
|
+
|
|
|
// /**
|
|
|
// * 读取文件,获取文件内容
|
|
|
// * F:\test\project\age_laser\routeMap.txt
|
|
@@ -85,11 +93,13 @@ public class GetRoute {
|
|
|
* F:\test\project\age_laser\final_freespace.csv
|
|
|
*
|
|
|
* list 是routeMap的结果集
|
|
|
+ *
|
|
|
+ * , ServletResponse response
|
|
|
* @return
|
|
|
*/
|
|
|
- public static JSONArray getRoute(List<String> list, RouteInputDto dto, ControlPointCalculateEntity controlPoint){
|
|
|
+ public static JSONArray getRoute(List<String> list, RouteInputDto dto, ControlPointCalculateEntity controlPoint, ServletResponse response){
|
|
|
try {
|
|
|
- JSONArray maps = readMap(list, dto);
|
|
|
+ JSONArray maps = readMap(list, dto, response);
|
|
|
MapInfo info=new MapInfo(maps,start,end);
|
|
|
List<Node> path = g_AStar.start(info);
|
|
|
JSONArray jsonArray = convertFromPath(path, dto, controlPoint);
|
|
@@ -102,7 +112,7 @@ public class GetRoute {
|
|
|
|
|
|
|
|
|
|
|
|
- private static JSONArray readMap(List<String> list, RouteInputDto dto) throws Exception {
|
|
|
+ private static JSONArray readMap(List<String> list, RouteInputDto dto, ServletResponse response) throws Exception {
|
|
|
// List<String> list = FileUtil.readFileByLines2(inputFilePath);
|
|
|
JSONArray maps = new JSONArray();
|
|
|
|
|
@@ -170,6 +180,35 @@ public class GetRoute {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
+ if(startDistance>1.08){
|
|
|
+
|
|
|
+// jsonObject.put("msg", "Could not create route: No navigation graph node found near start.");
|
|
|
+// jsonObject.put("exception", "de.navvis.iv.routing.exception.NoNavgraphNearRouteStartException");
|
|
|
+ log.error("路径规划错误start: {}", jsonObject);
|
|
|
+
|
|
|
+ // 直接返回Response信息
|
|
|
+
|
|
|
+ ResponseUtil.writeResponse(response, jsonObject);
|
|
|
+ return null;
|
|
|
+
|
|
|
+// return {"msg":"Could not create route: No navigation graph node found near start.","exception":"de.navvis.iv.routing.exception.NoNavgraphNearRouteStartException"}
|
|
|
+ }
|
|
|
+ else if(endDistance>1.08){
|
|
|
+// jsonObject.put("msg", "Could not create route: No navigation graph node found near end.");
|
|
|
+// jsonObject.put("exception", "de.navvis.iv.routing.exception.NoNavgraphNearRouteStartException");
|
|
|
+ log.error("路径规划错误end: {}", jsonObject);
|
|
|
+ ResponseUtil.writeResponse(response, jsonObject);
|
|
|
+ return null;
|
|
|
+// return {"msg":"Could not create route: No navigation graph node found near end.","exception":"de.navvis.iv.routing.exception.NoNavgraphNearRouteStartException"}
|
|
|
+ }
|
|
|
+
|
|
|
+// if (!jsonObject.isEmpty()){
|
|
|
+// ResponseUtil.writeResponse(response, jsonObject);
|
|
|
+// return null;
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
JSONObject virtualStart = maps.getJSONObject(minStartId);
|
|
|
JSONObject virtualEnd = maps.getJSONObject(minEndId);
|
|
|
Coord startVirtualCoord = new Coord(virtualStart.getDouble("x"), virtualStart.getDouble("y"),virtualStart.getDouble("z"));
|
|
@@ -302,7 +341,6 @@ public class GetRoute {
|
|
|
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);
|
|
@@ -313,7 +351,7 @@ public class GetRoute {
|
|
|
item.put("distance", distance);
|
|
|
if(i == path.size()-1) {
|
|
|
instruction = new JSONObject();
|
|
|
- instruction.put("type", "destination_projection_to_navgraph");
|
|
|
+ //instruction.put("type", "destination_projection_to_navgraph");
|
|
|
item.put("instruction", instruction);
|
|
|
|
|
|
// virtualEndPosition[0] = node.coord.x;
|
|
@@ -354,246 +392,21 @@ public class GetRoute {
|
|
|
}
|
|
|
|
|
|
|
|
|
-// private static JSONArray convertFromPath(List<Node> mappath, RouteInputDto dto, ControlPointEntity controlPoint) {
|
|
|
-// double defaultdistance = 0.36;
|
|
|
-// 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();
|
|
|
-//
|
|
|
-// 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) {
|
|
|
-//// Node node = mappath.get(i);
|
|
|
-//// path.add(node);
|
|
|
-//// }
|
|
|
-//
|
|
|
-// // 点的距离
|
|
|
-// for(int i = mappath.size()-1;i>-1;) {
|
|
|
-// Node node = mappath.get(i);
|
|
|
-// if(mappath.size()>4){
|
|
|
-// i -= 3;
|
|
|
-// }
|
|
|
-// else{
|
|
|
-// --i;
|
|
|
-// }
|
|
|
-// path.add(node);
|
|
|
-// }
|
|
|
-//
|
|
|
-// JSONArray route = new JSONArray();
|
|
|
-//
|
|
|
-// //起点不在path上,path的第一个点对应的是格子
|
|
|
-// JSONObject start = new JSONObject();
|
|
|
-//
|
|
|
-//
|
|
|
-// double[] startPosition = {startX,startY};
|
|
|
-// startPosition = TransformGPS.convertLocationToGis(startPosition, controlPoint);
|
|
|
-// start.put("longitude", startPosition[0]);
|
|
|
-// start.put("latitude", startPosition[1]);
|
|
|
-// start.put("z", startZ);
|
|
|
-// Double[] location = new Double[3];
|
|
|
-//
|
|
|
-//
|
|
|
-// 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.convertLocationToGis(position, controlPoint);
|
|
|
-// item.put("longitude", position[0]);
|
|
|
-// item.put("latitude", position[1]);
|
|
|
-//
|
|
|
-//
|
|
|
-// item.put("z", node.coord.z);
|
|
|
-// location = new Double[3];
|
|
|
-//
|
|
|
-//
|
|
|
-// 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;
|
|
|
-//
|
|
|
-// virtualEndPosition[0] = node.coord.x;
|
|
|
-// virtualEndPosition[1] = node.coord.y;
|
|
|
-// virtualEndPosition[2] = node.coord.z;
|
|
|
-//
|
|
|
-// 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.convertLocationToGis(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);
|
|
|
- JSONArray maps = new JSONArray();
|
|
|
-
|
|
|
- Coord _start = new Coord(startX,startY,startZ);
|
|
|
- Coord _end = new Coord(endX,endY,endZ);
|
|
|
-
|
|
|
- Double startDistance=1000.0;
|
|
|
- Double endDistance = 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]);
|
|
|
-
|
|
|
- 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) {
|
|
|
- minStartId = i;
|
|
|
- startDistance = _startDistance;
|
|
|
- }
|
|
|
- Double _endDistance = g_AStar.calcH(_end, coord);
|
|
|
- if(_endDistance<endDistance) {
|
|
|
- minEndId = i;
|
|
|
- endDistance = _endDistance;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- 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 convertFromPath(List<Node> mappath) {
|
|
|
if(mappath == null||mappath.size() == 0) {
|
|
|
return null;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
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);
|
|
@@ -608,7 +421,7 @@ public class GetRoute {
|
|
|
start.put("distance_to_previous", 0);
|
|
|
start.put("instruction", null);
|
|
|
route.add(start);
|
|
|
-
|
|
|
+
|
|
|
for(int i=0;i<path.size();++i) {
|
|
|
Node node = path.get(i);
|
|
|
JSONObject item = new JSONObject();
|
|
@@ -621,16 +434,15 @@ public class GetRoute {
|
|
|
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 {
|
|
@@ -642,7 +454,7 @@ public class GetRoute {
|
|
|
item.put("distance", distance);
|
|
|
if(i == path.size()-1) {
|
|
|
instruction = new JSONObject();
|
|
|
- instruction.put("type", "destination_projection_to_navgraph");
|
|
|
+ //instruction.put("type", "destination_projection_to_navgraph");
|
|
|
item.put("instruction", instruction);
|
|
|
}
|
|
|
else {
|
|
@@ -650,10 +462,10 @@ public class GetRoute {
|
|
|
}
|
|
|
System.out.println("distance:"+distance_to_previous);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
route.add(item);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
JSONObject endItem = route.getJSONObject(route.size()-1);
|
|
|
JSONObject end = new JSONObject();
|
|
|
end.put("longitude", endX);
|
|
@@ -669,16 +481,33 @@ public class GetRoute {
|
|
|
end.put("distance_to_previous", enddistance);
|
|
|
end.put("instruction", null);
|
|
|
route.add(end);
|
|
|
-
|
|
|
+
|
|
|
return route;
|
|
|
}
|
|
|
-
|
|
|
- public static void main(String[] args) throws Exception
|
|
|
- {
|
|
|
- JSONArray maps = readMap();
|
|
|
- MapInfo info=new MapInfo(maps,start,end);
|
|
|
- List<Node> path = g_AStar.start(info);
|
|
|
- convertFromPath(path);
|
|
|
- }
|
|
|
|
|
|
+// public static void main(String[] args) throws Exception
|
|
|
+// {
|
|
|
+// JSONArray maps = readMap();
|
|
|
+// MapInfo info=new MapInfo(maps,start,end);
|
|
|
+// List<Node> path = g_AStar.start(info);
|
|
|
+// convertFromPath(path);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 封装异常信息
|
|
|
+ */
|
|
|
+ private void exceptionMsg(ServletResponse response) {
|
|
|
+ // 认证出现异常,传递错误信息msg
|
|
|
+ // 获取应用异常(该Cause是导致抛出此throwable(异常)的throwable(异常))
|
|
|
+ com.alibaba.fastjson.JSONObject jsonObject = new com.alibaba.fastjson.JSONObject();
|
|
|
+
|
|
|
+ jsonObject.put("code", 5002);
|
|
|
+ jsonObject.put("msg", "token invalid");
|
|
|
+
|
|
|
+// jsonObject.put("timestamp", LocalDateTime.now());
|
|
|
+ // 直接返回Response信息
|
|
|
+ ResponseUtil.writeResponse(response, jsonObject);
|
|
|
+
|
|
|
+ }
|
|
|
}
|