Browse Source

自定义平面图需要重新计算四叉树值

wuweihao 3 years ago
parent
commit
cc31ea9ec8

+ 19 - 8
laser/pom.xml

@@ -202,22 +202,33 @@
 
 	</dependencies>
 
+	<!--<build>-->
+		<!--<plugins>-->
+			<!--<plugin>-->
+				<!--<groupId>org.springframework.boot</groupId>-->
+				<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
+			<!--</plugin>-->
+			<!--<plugin>-->
+				<!--<groupId>org.apache.maven.plugins</groupId>-->
+				<!--<artifactId>maven-surefire-plugin</artifactId>-->
+				<!--<version>2.18.1</version>-->
+				<!--<configuration>-->
+					<!--<skipTests>true</skipTests>-->
+				<!--</configuration>-->
+			<!--</plugin>-->
+		<!--</plugins>-->
+		<!--<finalName>indoor</finalName>-->
+	<!--</build>-->
+
 	<build>
 		<plugins>
 			<plugin>
 				<groupId>org.springframework.boot</groupId>
 				<artifactId>spring-boot-maven-plugin</artifactId>
 			</plugin>
-			<plugin>
-				<groupId>org.apache.maven.plugins</groupId>
-				<artifactId>maven-surefire-plugin</artifactId>
-				<version>2.18.1</version>
-				<configuration>
-					<skipTests>true</skipTests>
-				</configuration>
-			</plugin>
 		</plugins>
 		<finalName>indoor</finalName>
 	</build>
 
+
 </project>

+ 2 - 0
laser/src/main/java/com/fdkankan/indoor/core/controller/SceneController.java

@@ -2,6 +2,7 @@ package com.fdkankan.indoor.core.controller;
 
 import com.fdkankan.indoor.base.aop.WebControllerLog;
 import com.fdkankan.indoor.base.util.Result;
+import com.fdkankan.indoor.core.entity.InitEntity;
 import com.fdkankan.indoor.core.entity.dto.PageDto;
 import com.fdkankan.indoor.core.entity.dto.SceneAgePageDto;
 import com.fdkankan.indoor.core.service.InitService;
@@ -47,6 +48,7 @@ public class SceneController {
     @ApiOperation(value = "查询场景详情")
     @GetMapping("indoor/{sceneCode}/scene/getInfo")
     public Result getInfo(@PathVariable String sceneCode){
+        InitEntity en = initService.findById(sceneCode);
         return Result.success(initService.findById(sceneCode));
     }
 

+ 3 - 0
laser/src/main/java/com/fdkankan/indoor/core/entity/dto/TiledMapDto.java

@@ -52,6 +52,9 @@ public class TiledMapDto {
 
     private Integer max_depth;
 
+    /**
+     * 图片透明度会影响这个值
+     */
     private String quadtree;
 
     @ApiModelProperty(value = "坐标")

+ 5 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/impl/SceneServiceImpl.java

@@ -103,6 +103,11 @@ public class SceneServiceImpl extends IBaseServiceImpl implements SceneService {
     @Override
     public Result updateByUseStatus(String sceneCode, Integer useStatus) {
         InitEntity entity = initService.findById(sceneCode);
+        if (entity == null){
+            String msg = "此场景码不存在: " + sceneCode;
+            log.warn(msg);
+            return Result.success(msg);
+        }
         entity.setUseStatus(useStatus);
         entity.setUpdateTime(LocalDateTime.now());
         initMapper.save(entity);

+ 62 - 7
laser/src/main/java/com/fdkankan/indoor/core/service/impl/TiledMapServiceImpl.java

@@ -121,7 +121,6 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
             log.error("文件名: {}", originalFilename);
             return Result.failure("文件不能为空, 或者不是zip文件");
         }
-//        String basePath = redisPath(sceneCode) + "/laserData/upload_cover";
         String basePath = redisPath(sceneCode) + "/upload_cover";
         String savePath = basePath + "/cover.zip";
         if ("dev".equals(configConstant.active)) {
@@ -213,6 +212,8 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         Integer width = resolution.getInteger("width");
         Integer height = resolution.getInteger("height");
 
+
+
         BufferedImage read = null;
         String tiledMapPath = tiledBasePath + "/extras/final_freespace.png";
         try {
@@ -231,13 +232,28 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
             // 调用算法切图
             cmdTiledMap(tiledBasePath);
 
+
+
+
             // 上传平面图到download目录
             uploadOss(tiledBasePath, sceneCode);
 
             // 2021-12-2 更新状态为自定义平面图
             TiledMapEntity entity = this.findById(sceneCode);
+
+            // 2021-12-03 更新quadTree, 切图后会生成新的info.json
+            List<TiledMapDto> data = entity.getData();
+            for (TiledMapDto dao : data) {
+                if (sceneCode.equals(dao.getSceneCode())){
+                    dao.setQuadtree(getQuadTree(tiledBasePath));
+                }
+            }
+
+
             // 0  默认平面图 ,1自定义平面图
             entity.setStatus(1);
+            entity.setData(data);
+
             entity.setUpdateTime(LocalDateTime.now());
             this.save(entity);
 
@@ -288,7 +304,7 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         // 上传切片后的平面图
         String uploadDir = tiledBasePath + "/results/laserData/cover";
         uploadDiyCover(sceneCode, uploadDir );
-        log.info("切图上传oss完成");
+        log.info("平面图切图上传oss完成");
 
     }
 
@@ -475,10 +491,6 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         dto.setMap_size_m(mapSize_m);
         // 使用dataSet.location
         dto.setLocation(location);
-//        double[] quaternion = PlanGraph.getQuaternion(orientation);
-//        Double[] calcQuaternion = {quaternion[0],quaternion[1],quaternion[2],quaternion[3]};
-//        dto.setOrientation(calcQuaternion);
-
 
         // 计算 2021-09-14
         dto.setOrientation(PlanGraph.tiledMapOrientation(orientation));
@@ -490,13 +502,56 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         String uploadDir = path + "/cover";
         ossUploadDir(ossTarget, uploadDir);
         // 压缩并上传oss提供下载
-//        zipAndUploadOss(path, uploadDir, sceneCode);
         tiledMapUploadOss(path, sceneCode);
         log.info("算法生成平面图上传oss完成");
 
         return list;
     }
 
+
+    /**
+     * 2021-12-03
+     * 四叉树
+     * 图片透明度会影响这个值,上传后的平面图需要重新计算
+     * @return
+     */
+    private String getQuadTree(String basePath){
+
+        // 读取算法新生成的info.json
+//        basePath = "/results/laserData/cover";
+        String infoPath = basePath + "/results/laserData/cover/info.json";
+        log.info("平面图info.json path: {}", infoPath);
+
+        if (!FileUtil.isFile(infoPath)){
+            String msg = "算法生成平面图失败, info.json不存在";
+            log.error(msg);
+            throw new BaseRuntimeException(msg);
+        }
+
+
+        String str = FileUtil.readUtf8String(infoPath);
+        JSONObject strJson = JSONObject.parseObject(str);
+        JSONArray zoom = strJson.getJSONArray("zoom");
+        Integer maxDepth = zoom.size()-1;
+        log.info("平面图maxDepth: {}", maxDepth);
+
+        // 四叉树
+        String dirPath = basePath + "/results/laserData/cover/" + maxDepth;
+        log.info("平面图quadTree dirPath: {}", dirPath);
+        Solution solution = new Solution();
+        File file = solution.readFiles(dirPath);
+        String quadTree = "";
+        if(file!=null) {
+            quadTree = solution.getXYTiles(file);
+        }
+        log.info("平面图quadTree : {}", quadTree);
+        return quadTree;
+    }
+
+
+
+
+
     /**
      * 长传平面图提供下载
      * @param basePath