Browse Source

更新平面图代码

wuweihao 3 years ago
parent
commit
4fa149acf6

+ 106 - 23
laser/src/main/java/com/fdkankan/indoor/base/convert/quadTree/Solution.java

@@ -1,7 +1,10 @@
 package com.fdkankan.indoor.base.convert.quadTree;
 
-import java.io.File;
+import net.sf.json.JSONObject;
 
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
 
 
 /**
@@ -93,23 +96,31 @@ public class Solution {
 		}
 	}
 
+
+
+
 //	public String getXYTiles(File f){
 //		File[] files = f.listFiles();
 //		String tiles = "";
 //
-//		int maxX = files.length;
-//		int maxY = 0;
+//		int maxX = -1;
+//		int maxY = -1;
 //		for(int i=0;i<files.length;++i) {
 //			String[] fileNames = files[i].list();
-//			if(fileNames.length>maxY) {
-//				maxY = fileNames.length;
+//			if(Integer.valueOf(files[i].getName())>maxX) {
+//				maxX = Integer.valueOf(files[i].getName());
 //			}
 //			for(int j=0;j<fileNames.length;++j) {
+//				String str = fileNames[j].substring(0,fileNames[j].indexOf("."));
+//				if(Integer.valueOf(str)>maxY) {
+//					maxY = Integer.valueOf(str);
+//				}
 //				tiles += files[i].getName()+"-"+fileNames[j].replace(".png", "")+",";
 //			}
 //		}
 //
-//		int max = Math.max(maxX, maxY);
+//		//2021-09-24 加1的原因是从0开始数的
+//		int max = Math.max(maxX+1, maxY+1);
 //		max = getMaxDepth(max);
 //		int[][] numthree = new int[max][max];
 //
@@ -128,12 +139,13 @@ public class Solution {
 //		getSingleScore(node);
 //		ouput(node);
 //		return quadTree;
+////		System.out.println(quadTree);
 //	}
 
 
 	public String getXYTiles(File f){
 		File[] files = f.listFiles();
-		String tiles = "";
+		String tiles = ",";
 
 		int maxX = -1;
 		int maxY = -1;
@@ -150,16 +162,15 @@ public class Solution {
 				tiles += files[i].getName()+"-"+fileNames[j].replace(".png", "")+",";
 			}
 		}
-
-//		int max = Math.max(maxX, maxY);
-		//2021-09-24 加1的原因是从0开始数的
+		//加1的原因是从0开始数的
 		int max = Math.max(maxX+1, maxY+1);
-		max = getMaxDepth(max);
+		JSONObject info = getMaxDepth(max);
+		max = info.getInt("max");
 		int[][] numthree = new int[max][max];
 
 		for(int i=0;i<max;++i) {
 			for(int j=0;j<max;++j) {
-				if(tiles.indexOf(String.valueOf(i)+"-"+String.valueOf(j))>-1) {
+				if(tiles.indexOf(","+String.valueOf(i)+"-"+String.valueOf(j)+",")>-1) {
 					numthree[i][j] = 1;
 				}
 				else {
@@ -167,13 +178,85 @@ public class Solution {
 				}
 			}
 		}
-
+		int depth = info.getInt("depth");
 		Node node = construct(numthree);
-		getSingleScore(node);
-		ouput(node);
+		getScores(node,depth);
 		return quadTree;
 //		System.out.println(quadTree);
 	}
+
+
+	public JSONObject getMaxDepth(int max) {
+		JSONObject result = new JSONObject();
+		for(int i=0;i<10;++i) {
+			if(Math.pow(2, i)>=max) {
+				result.put("depth", i);
+				result.put("max", (int)Math.pow(2, i));
+				return result;
+			}
+		}
+		return null;
+	}
+
+
+	public void getScores(Node node,int depth) {
+		if(node.isLeaf) {
+			return;
+		}
+
+		getSingleScore(node);
+		if(depth == 1) {
+			return;
+		}
+
+		List<Node> nodes = new ArrayList<Node>();
+		List<Node> childNodes = null;
+		for(int i=1;i<depth;++i) {
+			if(i == 1) {
+				childNodes = getChildNodes(node);
+				nodes.addAll(childNodes);
+			}
+			else {
+				childNodes = getChildrenNodes(childNodes);
+				nodes.addAll(childNodes);
+			}
+		}
+
+		for(int i=0;i<nodes.size();++i) {
+			getSingleScore(nodes.get(i));
+		}
+	}
+
+
+	public List<Node> getChildrenNodes(List<Node> nodes) {
+		List<Node> result = new ArrayList<Node>();
+		for(int i=0;i<nodes.size();++i) {
+			List<Node> childNodes = getChildNodes(nodes.get(i));
+			result.addAll(childNodes);
+		}
+		return result;
+	}
+
+	public List<Node> getChildNodes(Node node) {
+		List<Node> nodes = new ArrayList<Node>();
+		if(!node.topLeft.isLeaf)
+		{
+			nodes.add(node.topLeft);
+		}
+		if(!node.bottomLeft.isLeaf)
+		{
+			nodes.add(node.bottomLeft);
+		}
+		if(!node.topRight.isLeaf)
+		{
+			nodes.add(node.topRight);
+		}
+		if(!node.bottomRight.isLeaf)
+		{
+			nodes.add(node.bottomRight);
+		}
+		return nodes;
+	}
 	
 	private  void ouput(Node node) {
 		if(node.isLeaf) {
@@ -240,14 +323,14 @@ public class Solution {
 	}
 
 
-	private int getMaxDepth(int max) {
-		for(int i=0;i<10;++i) {
-			if(Math.pow(2, i)>=max) {
-				return (int)Math.pow(2, i);
-			}
-		}
-		return -1;
-	}
+//	private int getMaxDepth(int max) {
+//		for(int i=0;i<10;++i) {
+//			if(Math.pow(2, i)>=max) {
+//				return (int)Math.pow(2, i);
+//			}
+//		}
+//		return -1;
+//	}
 
 
 	public static void main(String args[]) {

+ 7 - 1
laser/src/main/java/com/fdkankan/indoor/core/service/impl/SiteModelServiceImpl.java

@@ -214,11 +214,17 @@ public class SiteModelServiceImpl implements SiteModelService {
     public Result getData(JSONObject param, String sceneCode) {
         String type = param.getString("type");
         if (!"BUILDING".equals(type)) {
-            throw new RuntimeException("非BUILDING类型");
+//            throw new RuntimeException("非BUILDING类型");
+            log.info("非BUILDING类型,返回空数组");
+            return Result.success();
         }
 
 
         List<SiteDto> resData = getDataBySceneCode(sceneCode);
+        if (resData == null || resData.size() == 0) {
+            log.info("没有数据,返回空数组");
+            return Result.success();
+        }