浏览代码

初始化集成tiledMap 还没部署

wuweihao 4 年之前
父节点
当前提交
09c0860014

+ 46 - 9
laser/src/main/java/com/fdkankan/indoor/base/convert/PlanGraph.java

@@ -1,6 +1,11 @@
 package com.fdkankan.indoor.base.convert;
 
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
 import net.sf.json.JSONObject;
+import org.junit.Test;
+
+import java.util.Map;
 
 /**
  * Created by owen on 2021/9/1 0001 18:06
@@ -10,12 +15,12 @@ import net.sf.json.JSONObject;
 public class PlanGraph {
 
     //THREE.Math.degToRad(-90)
-    public double degToRad(double angle) {
+    private static double degToRad(double angle) {
         double DEG2RAD = Math.PI/180;
         return angle * DEG2RAD;
     }
 
-    public JSONObject setFromAxisAngle(JSONObject axis, double angle) {
+    private static JSONObject setFromAxisAngle(JSONObject axis, double angle) {
         // http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToQuaternion/index.htm
         // assumes axis is normalized
 
@@ -36,7 +41,7 @@ public class PlanGraph {
         return quaternion;
     }
 
-    public JSONObject inverse(JSONObject quaternion) {
+    private static JSONObject inverse(JSONObject quaternion) {
         double _x = -1*quaternion.getDouble("x");
         double _y = -1*quaternion.getDouble("y");
         double _z = -1*quaternion.getDouble("z");
@@ -48,13 +53,13 @@ public class PlanGraph {
         return _quaternion;
     }
 
-    public JSONObject multiply(JSONObject q, JSONObject p ) {
+    private static JSONObject multiply(JSONObject q, JSONObject p ) {
 
         return multiplyQuaternions( q, p );
 
     }
 
-    public JSONObject multiplyQuaternions(JSONObject a,JSONObject b ) {
+    private static JSONObject multiplyQuaternions(JSONObject a,JSONObject b ) {
 
         // from http://www.euclideanspace.com/maths/algebra/realNormedAlgebra/quaternions/code/index.htm
 
@@ -75,7 +80,7 @@ public class PlanGraph {
 
     }
 
-    public double[] toArray(JSONObject quaternion) {
+    private static double[] toArray(JSONObject quaternion) {
 
         //new THREE.Quaternion
 		/*
@@ -99,7 +104,7 @@ public class PlanGraph {
         //return [e[3], e[0], e[1], e[2]]
     }
 
-    public JSONObject setFromEuler(double x,double y,double z) {
+    private  static JSONObject setFromEuler(double x,double y,double z) {
 
         double c1 = Math.cos( x / 2 );
         double c2 = Math.cos( y / 2 );
@@ -123,12 +128,23 @@ public class PlanGraph {
         return quaternion;
     }
 
-    public double[] getQuaternion(double angle) {
+    /**
+     *
+     * @param angle dataSet.quaternion
+     * @return
+     */
+    public static double[] getQuaternion(double angle) {
         JSONObject quaternion = setFromEuler(0,0,degToRad(-angle));
         return toArray(quaternion);
     }
 
-    public double getSize(int imgWidth, int scale) {
+    /**
+     *
+     * @param imgWidth 获取laserData/cover/info.json -> resolution.width/height的最大值
+     * @param scale 写死1
+     * @return
+     */
+    public static double getSize(int imgWidth, int scale) {
         double level = imgWidth / 1024;  //以1024为基准
         return 95.54628610610962 * level * scale; // 95.54628610610962 = 38.21851444244385 * (2+0.5), 其中38.21851444244385 = mapSizeM / Math.pow(2,maxDepth) = 40075017 / Math.pow(2,20) 可能表示地图在缩放zoom为20时的单块宽度
         //0.5是试出来的,因为图片层的bias=0.5, 暂不知道其用处,所以试用了下……
@@ -136,6 +152,27 @@ public class PlanGraph {
         //有出现过一次错误是2048时的图但是大了一倍,发现是传图的那个网页在缩放值为0.1(即图为1:1显示,函数canvasFunction(extent, scale )时只有1024大小,后来刷新重新操作就是2048然后就正确。所以可能是这个网页出错。
     }
 
+
+  @Test
+  public void testGetInfo(){
+      String path = "F:\\test\\ngin\\age_laser_data\\w-60\\results\\laserData\\cover\\info.json";
+      if (!FileUtil.isFile(path)){
+          System.out.println("文件不存在");
+      }
+
+      String str = FileUtil.readUtf8String(path);
+      com.alibaba.fastjson.JSONObject strJson = com.alibaba.fastjson.JSONObject.parseObject(str);
+      JSONArray zoom = strJson.getJSONArray("zoom");
+      System.out.println("zoom:" + (zoom.size()-1));
+      com.alibaba.fastjson.JSONObject resolution = strJson.getJSONObject("resolution");
+      Integer width = resolution.getInteger("width");
+      Integer height = resolution.getInteger("height");
+
+      Integer imgWidth = width >= height? width: height;
+      System.out.println("imgWidth:" + imgWidth);
+
+  }
+
     public static void main(String[] args) {
         PlanGraph _testMap = new PlanGraph();
         double angle = 0;

+ 8 - 9
laser/src/main/java/com/fdkankan/indoor/base/convert/quadTree/Solution.java

@@ -75,7 +75,7 @@ public class Solution {
     	return true;
     }
     
-    private  File readFiles(String inPath) {
+    public File readFiles(String inPath) {
 		try {
 			File f = new File(inPath);
 			if(f.isDirectory()) {
@@ -92,7 +92,7 @@ public class Solution {
 		}
 	}
 
-	private  void getXYTiles(File f){
+	public String getXYTiles(File f){
 		File[] files = f.listFiles();
 		String tiles = "";
 
@@ -124,12 +124,9 @@ public class Solution {
 		}
 		
 		Node node = construct(numthree);
-		String singleScore = getSingleScore(node);
-//		System.out.println("singleScore: " + singleScore);
+		getSingleScore(node);
 		ouput(node);
-		// tiledMap.Quadtree("fccf7fffcff3bf7f") 的值;
-//		System.out.println(quadTree);
-//		return quadTree;
+		return quadTree;
 	}
 	
 	private  void ouput(Node node) {
@@ -206,14 +203,16 @@ public class Solution {
 		return -1;
 	}
 
+
 	public static void main(String args[]) {
 		String path = "F:\\test\\ngin\\age_laser_data\\w-60\\results\\laserData\\cover\\0";
 		Solution solution = new Solution();
 		File file = solution.readFiles(path);
 		if(file!=null) {
-			solution.getXYTiles(file);
+			String xyTiles = solution.getXYTiles(file);
 			// tiledMap.Quadtree("fccf7fffcff3bf7f") 的值;
-			System.out.println("quadTree:" + quadTree);
+			System.out.println("quadTree:" + xyTiles);
+
 		}
 	}
 }

+ 11 - 0
laser/src/main/java/com/fdkankan/indoor/core/controller/TestController.java

@@ -49,6 +49,9 @@ public class TestController {
     @Autowired
     AliYunOssUtil aliYunOssUtil;
 
+    @Autowired
+    TiledMapService tiledMapService;
+
     @ApiOperation("测试成员变量")
     @GetMapping("testVariate/{param}")
     public Result testVariate(@PathVariable Integer param){
@@ -223,4 +226,12 @@ public class TestController {
     public Result mergeInfoRemove(@PathVariable String sceneCode, @PathVariable Integer dataSetId){
         return  owenService.mergeInfoRemove(sceneCode, dataSetId);
     }
+
+
+    @ApiOperation("tiledMapInit")
+    @GetMapping("tiledMapInit/init/{sceneCode}")
+    public Result tiledMapInit(@PathVariable String sceneCode){
+        tiledMapService.init(sceneCode);
+        return Result.success();
+    }
 }

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

@@ -15,7 +15,7 @@ import lombok.Data;
  * map_size_m: 自己生成的
  * max_depth: 目录的最大值,算法部会给到json文件里
  * orientation:根据datasets里的orientation,计算得到的
- * quadtree: 根据文件目录,计算得到的
+ * quadtree: 根据文件目录,计算得到的,用目录最大值
  * tile_size_px: 256
  * type: "TILED_PYRAMID"
  */

+ 0 - 3
laser/src/main/java/com/fdkankan/indoor/core/service/impl/IBaseServiceImpl.java

@@ -28,9 +28,6 @@ public class IBaseServiceImpl {
     @Autowired
     ConfigConstant configConstant;
 
-//    @Autowired
-//    RedisTemplate<String, String> redisTemplate;
-
 
     @Autowired
     RedisUtil redisUtil;

+ 4 - 2
laser/src/main/java/com/fdkankan/indoor/core/service/impl/InitServiceImpl.java

@@ -179,8 +179,7 @@ public class InitServiceImpl implements InitService {
         // step9 创建 t_measurement表, 测量表,空数据
         createMeasurement(sceneCode);
 
-        // step 10 创建 t_tiled_map表, 空数据
-        tiledMapService.init(sceneCode);
+
 
         log.info("================== 初始化第一步完成 ==================");
 
@@ -263,6 +262,9 @@ public class InitServiceImpl implements InitService {
         // step7 创建t_datasets表, 使用的是代码, 需要处理原点之后执行
         createDataSet(sceneCode, laserDataPath, controlPoint);
 
+        // step 10 创建 t_tiled_map表, 需要用到dataSet数据
+        tiledMapService.init(sceneCode);
+
 
         // step8 目录pano、pano_depth、webcloud上传oss, 初始化合并场景码跟原来的一样
         ossUploadDirByLaserData(sceneCode, laserDataPath, sceneCode);

+ 114 - 0
laser/src/main/java/com/fdkankan/indoor/core/service/impl/TiledMapServiceImpl.java

@@ -1,16 +1,26 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import cn.hutool.core.io.FileUtil;
+import com.alibaba.fastjson.JSONArray;
+import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.indoor.base.constant.CmdConstant;
+import com.fdkankan.indoor.base.convert.PlanGraph;
+import com.fdkankan.indoor.base.convert.quadTree.Solution;
 import com.fdkankan.indoor.base.exception.BaseRuntimeException;
+import com.fdkankan.indoor.base.util.CmdUtils;
 import com.fdkankan.indoor.base.util.Result;
+import com.fdkankan.indoor.core.entity.DataSetEntity;
 import com.fdkankan.indoor.core.entity.TiledMapEntity;
 import com.fdkankan.indoor.core.entity.dto.TiledEditDto;
 import com.fdkankan.indoor.core.entity.dto.TiledMapDto;
+import com.fdkankan.indoor.core.entity.po.DataSetPo;
 import com.fdkankan.indoor.core.mapper.TiledMapMapper;
 import com.fdkankan.indoor.core.service.TiledMapService;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
+import java.io.File;
 import java.time.LocalDateTime;
 import java.util.ArrayList;
 import java.util.List;
@@ -26,6 +36,9 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
     @Autowired
     TiledMapMapper entityMapper;
 
+    @Autowired
+    DataSetServiceImpl dataSetService;
+
 
     private TiledMapEntity findById(String sceneCode){
         Optional<TiledMapEntity> optional = entityMapper.findById(sceneCode);
@@ -46,7 +59,10 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         TiledMapEntity entity = new TiledMapEntity();
         entity.setId(sceneCode);
         entity.setCreateTime(LocalDateTime.now());
+        // 2021.09.03
+        entity.setData(initData(sceneCode));
         entityMapper.save(entity);
+
         log.info("TiledMap数据初始化完成");
     }
 
@@ -68,7 +84,10 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         }
         entity.setData(editData(param));
         entity.setUpdateTime(LocalDateTime.now());
+
         entityMapper.save(entity);
+
+
         return Result.success();
     }
 
@@ -115,6 +134,8 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
          * 2:1024*1024
          * 3:2048*2048
          * 4:4096*4096
+         *
+         * Max_dept=读取info值,zoom.size()-1
          */
         dto.setMax_depth(3);
         dto.setQuadtree("fccf7fffcff3bf7f");
@@ -132,4 +153,97 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
     }
 
 
+    private List<TiledMapDto> initData(String sceneCode){
+        String path = redisPath(sceneCode) + "/laserData";
+        if ("dev".equals(configConstant.active)) {
+            path = "F:\\test\\ngin\\age_laser_data\\" + sceneCode + "\\results\\laserData";
+        }
+        String infoPath = path + "/cover/info.json";
+        log.info("info.json path: {}", infoPath);
+
+        if (!FileUtil.isFile(infoPath)){
+            log.error("info.json文件不存在");
+            throw new BaseRuntimeException("info.json文件不存在");
+        }
+
+        String str = FileUtil.readUtf8String(infoPath);
+        JSONObject strJson = JSONObject.parseObject(str);
+        JSONArray zoom = strJson.getJSONArray("zoom");
+        Integer maxDepth = zoom.size()-1;
+        log.info("maxDepth: {}", maxDepth);
+
+        JSONObject resolution = strJson.getJSONObject("resolution");
+        Integer width = resolution.getInteger("width");
+        Integer height = resolution.getInteger("height");
+        Integer imgWidth = width >= height? width: height;
+        log.info("imgWidth: {}", imgWidth);
+
+
+        double mapSize_m = PlanGraph.getSize(imgWidth, 1);
+        List<DataSetPo> data = dataSetService.getDataBySceneCode(sceneCode);
+        DataSetPo dataSetPo = data.get(0);
+        Double orientation = dataSetPo.getOrientation();
+        Double[] location = dataSetPo.getLocation();
+
+        double[] quaternion = PlanGraph.getQuaternion(orientation);
+
+
+        // 四查收书
+        String dirPath = path + "/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);
+
+
+        TiledMapDto dto = new TiledMapDto();
+        dto.setId(1);
+        // 默认1
+        dto.setBundle_id(1);
+        // 小地图oss路径
+        /**
+         * data/bundle/building_1/map_tiles/11
+         * building_1: bundle_id值
+         * 11=floor_id值:site_model.type:floor的id
+         */
+        dto.setFile_path("data/bundle/building_1/map_tiles/11");
+        dto.setFile_name("$DEPTH/$X/$Y.png");
+        // 11=floor_id值:site_model.type:floor的id
+        dto.setFloor_id(11);
+
+        dto.setMax_depth(maxDepth);
+        dto.setQuadtree(quadTree);
+        dto.setType("TILED_PYRAMID");
+        dto.setTile_size_px(256);
+
+        dto.setMap_size_m(mapSize_m);
+        // 使用dataSet.location
+        dto.setLocation(location);
+        // 前端提供
+        Double[] calcQuaternion = {quaternion[0],quaternion[1],quaternion[2],quaternion[3]};
+        dto.setOrientation(calcQuaternion);
+        List<TiledMapDto> list = new ArrayList<>();
+        list.add(dto);
+
+        // 将cover上传oss
+        String ossTarget = "data/" + sceneCode + "/" + dto.getFile_path();
+        String uploadDir = path + "/cover";
+        ossUploadDir(ossTarget, uploadDir);
+        return list;
+
+    }
+
+    private void ossUploadDir(String ossTarget, String uploadDir){
+        String cmd = CmdConstant.OSSUTIL_UPLOAD_DIR;
+        cmd = cmd.replaceAll("@uploadDir", uploadDir);
+        cmd = cmd.replaceAll("@target", ossTarget);
+        CmdUtils.ossUploadDir(cmd);
+        log.info("切图上传oss完成");
+    }
+
+
 }