Преглед на файлове

修复合并数据集时, 创建多个firstView点

wuweihao преди 3 години
родител
ревизия
6c2aecc335

+ 7 - 5
laser/src/main/java/com/fdkankan/indoor/base/convert/ConvertToVision.java

@@ -68,9 +68,10 @@ public class ConvertToVision {
 	 * @param sceneCode
 	 * @param panoInfos
 	 * @param from web(手动控制点), null(默认控制点)
+	 * @param isMerge 是否合并
 	 * @return
 	 */
-	private  JSONArray createVisionToFilter(String sceneCode, JSONArray panoInfos,  ControlPointCalculateEntity calculateEntity, String from) {
+	private  JSONArray createVisionToFilter(String sceneCode, JSONArray panoInfos,  ControlPointCalculateEntity calculateEntity, String from, boolean isMerge) {
 
 		JSONArray laserPanos = new JSONArray();
 		int visionSize = panoInfos.size();
@@ -159,8 +160,9 @@ public class ConvertToVision {
 			laserPano.put("file_id", fileId);
 
 			laserPanos.add(laserPano);
-			//firstView
-			if(i == 0) {
+			//2021-11-05 firstView, 用于创建t_config, 合并时不需要场景初始点
+			if(i == 0 && !isMerge) {
+
 				//保存初始点的gis坐标
 				// _location 存入数据库
 				SpecialPointEntity pointEntity = new SpecialPointEntity();
@@ -191,14 +193,14 @@ public class ConvertToVision {
 
 
 
-	public  JSONArray createFilter(String sceneCode, String path, ControlPointCalculateEntity calculateEntity, String from){
+	public  JSONArray createFilter(String sceneCode, String path, ControlPointCalculateEntity calculateEntity, String from, boolean isMerge){
 		if (!cn.hutool.core.io.FileUtil.isFile(path)) {
 			log.error("文件路径不存在: {}", path);
 			throw new RuntimeException("文件路径不存在");
 		}
 		try {
 			JSONArray panoInfos = readVisionTxt(path);
-			return createVisionToFilter(sceneCode, panoInfos, calculateEntity, from);
+			return createVisionToFilter(sceneCode, panoInfos, calculateEntity, from, isMerge);
 		} catch (IOException e) {
 			e.printStackTrace();
 		}

+ 171 - 36
laser/src/main/java/com/fdkankan/indoor/core/service/impl/CutModelServiceImpl.java

@@ -258,6 +258,105 @@ public class CutModelServiceImpl extends IBaseServiceImpl implements CutModelSer
      * @param sceneCode
      * @return
      */
+//    @Override
+//    public Result multipleCrop(String sceneCode) {
+//
+//
+//        // 1. 根据dataSetId 将dataSet表location(需要转本地坐标), orientation, path, 封装到merge_cut_model.json
+//        List<DataSetPo> dataSetInfos = dataSetService.getDataBySceneCode(sceneCode);
+//
+//
+//        String ossUrl;
+//        String basePath = redisPath(sceneCode);
+//        if (dataSetInfos.size() == 1) { // 只有一个数据集时
+//            // 2021-10-13 把算法提供的点云直接上传oss
+//
+//            String ossPath = "data/" +sceneCode + "/download/merge_cut.las";
+//            String outPath = basePath + "/laser.las";
+//            aliYunOssUtil.upload(outPath, ossPath);
+//
+//            ossUrl = configConstant.ossDomain + ossPath + "?m=" + System.currentTimeMillis();
+//            log.info("单数据集,直接上传算法提供的点云到oss");
+//
+//        } else { // 多个数据集
+//            // 转坐标,获取控制点计算值
+//            ControlPointCalculateEntity pointCalculate = controlPointCalculateService.findById(sceneCode);
+//
+//            HashMap<Object, double[] > covertPoint = new HashMap<>();
+//            for (DataSetPo po : dataSetInfos) {
+//                Double[] location = po.getLocation();
+//                // gis坐标转本地坐标
+//                double[] doubles = GisCoordinateUtil.transformBLToLocation(location[0], location[1], pointCalculate);
+//
+//                Double orientation = po.getOrientation();
+//
+//                // 将本地坐标, 旋转角度按顺序封装起来
+//                double[] resParam = {doubles[0], doubles[1], location[2], orientation};
+//                Integer id = po.getId();
+//
+//                // dataSetId做为key
+//                covertPoint.put(id, resParam);
+//            }
+//
+//
+//            // 2. 合并场景表(t_merge_info)获取dataSetId, 场景码
+//            List<MergeInfoEntity> mergeInfo = mergeInfoService.findBySceneCode(sceneCode, 1);
+//
+//            int SizeDataSet = dataSetInfos.size();
+//            int SizeMergeDataSet = mergeInfo.size();
+//            log.info("数据集数量:{}, 合并数据集数量: {}", SizeDataSet, SizeMergeDataSet);
+//
+//
+//
+//            JSONArray models = new JSONArray();
+//            for (MergeInfoEntity info : mergeInfo) {
+//                // 获取本地坐标,旋转角度
+//                Integer dataSetId = info.getDataSetId();
+//                double[] point = covertPoint.get(dataSetId);
+//
+//                JSONObject cutJson = new JSONObject();
+//                cutJson.put("file", info.getPath() + "/laser.las");
+//                cutJson.put("sceneCode", info.getMergeCode());
+//                cutJson.put("dataSetId", dataSetId);
+//                // 算法要求用空格隔开
+//                cutJson.put("translation", point[0] + " " + point[1] + " " + point[2]);
+//                cutJson.put("rotation", point[3]);
+//                models.add(cutJson);
+//            }
+//
+//            // 修剪模型参数
+//            JSONObject mergeCut = new JSONObject();
+//            mergeCut.put("model", models);
+//            // 这个值目前写死
+//            mergeCut.put("aabb", "b-0.5 -0.5 -0.5 0.5 0.5 0.5");
+//
+//            // 剪切模型参数json写入服务器
+//
+//            if ("dev".equals(configConstant.active)){
+//                basePath = configConstant.serverBasePath + "/" + sceneCode + "/results/laserData";
+//            }
+//            String savePath = basePath + "/merge_cut_param.json";
+//            log.info("剪切参数:{}", savePath);
+//            FileUtil.writeUtf8String(mergeCut.toJSONString(), savePath);
+//            log.info("剪切参数json写入完成");
+//
+//            // 剪切并oss上传模型
+//             ossUrl = cutLas(basePath, sceneCode);
+//
+//        }
+//        // 数据更新到数据库
+//        saveLasInfo(sceneCode, ossUrl);
+//
+//
+//
+//
+//        JSONObject result = new JSONObject();
+//        // 返回值id, 默认1
+//        result.put("job_id", 1);
+//        return Result.success(result);
+//
+//    }
+
     @Override
     public Result multipleCrop(String sceneCode) {
 
@@ -268,62 +367,73 @@ public class CutModelServiceImpl extends IBaseServiceImpl implements CutModelSer
 
         String ossUrl;
         String basePath = redisPath(sceneCode);
-        if (dataSetInfos.size() == 1) { // 只有一个数据集时
-            // 2021-10-13 把算法提供的点云直接上传oss
-
-            String ossPath = "data/" +sceneCode + "/download/merge_cut.las";
-            String outPath = basePath + "/laser.las";
-            aliYunOssUtil.upload(outPath, ossPath);
-
-            ossUrl = configConstant.ossDomain + ossPath + "?m=" + System.currentTimeMillis();
-            log.info("单数据集,直接上传算法提供的点云到oss");
 
-        } else { // 多个数据集
             // 转坐标,获取控制点计算值
             ControlPointCalculateEntity pointCalculate = controlPointCalculateService.findById(sceneCode);
 
             HashMap<Object, double[] > covertPoint = new HashMap<>();
-            for (DataSetPo po : dataSetInfos) {
-                Double[] location = po.getLocation();
-                // gis坐标转本地坐标
-                double[] doubles = GisCoordinateUtil.transformBLToLocation(location[0], location[1], pointCalculate);
 
-                Double orientation = po.getOrientation();
+        for (DataSetPo po : dataSetInfos) {
+            Double[] location = po.getLocation();
+            // gis坐标转本地坐标
+            double[] doubles = GisCoordinateUtil.transformBLToLocation(location[0], location[1], pointCalculate);
 
-                // 将本地坐标, 旋转角度按顺序封装起来
-                double[] resParam = {doubles[0], doubles[1], location[2], orientation};
-                Integer id = po.getId();
-
-                // dataSetId做为key
-                covertPoint.put(id, resParam);
-            }
-
-
-            // 2. 合并场景表(t_merge_info)获取dataSetId, 场景码
-            List<MergeInfoEntity> mergeInfo = mergeInfoService.findBySceneCode(sceneCode, 1);
-
-            int SizeDataSet = dataSetInfos.size();
-            int SizeMergeDataSet = mergeInfo.size();
-            log.info("数据集数量:{}, 合并数据集数量: {}", SizeDataSet, SizeMergeDataSet);
+            Double orientation = po.getOrientation();
 
+            // 将本地坐标, 旋转角度按顺序封装起来
+            double[] resParam = {doubles[0], doubles[1], location[2], orientation};
+            Integer id = po.getId();
 
+            // dataSetId做为key
+            covertPoint.put(id, resParam);
+        }
 
             JSONArray models = new JSONArray();
-            for (MergeInfoEntity info : mergeInfo) {
+            if (dataSetInfos.size() == 1) { // 只有一个数据集时
+                DataSetPo dataSetPo = dataSetInfos.get(0);
                 // 获取本地坐标,旋转角度
-                Integer dataSetId = info.getDataSetId();
+                Integer dataSetId = dataSetPo.getId();
                 double[] point = covertPoint.get(dataSetId);
 
                 JSONObject cutJson = new JSONObject();
-                cutJson.put("file", info.getPath() + "/laser.las");
-                cutJson.put("sceneCode", info.getMergeCode());
+                // 这两个参数算法不用,后端自己看
+                cutJson.put("sceneCode", sceneCode);
                 cutJson.put("dataSetId", dataSetId);
                 // 算法要求用空格隔开
+                cutJson.put("file", basePath + "/laser.las");
                 cutJson.put("translation", point[0] + " " + point[1] + " " + point[2]);
                 cutJson.put("rotation", point[3]);
                 models.add(cutJson);
+            } else { // 多数据集
+
+
+
+                // 2. 合并场景表(t_merge_info)获取dataSetId, 场景码
+                List<MergeInfoEntity> mergeInfo = mergeInfoService.findBySceneCode(sceneCode, 1);
+                int SizeDataSet = dataSetInfos.size();
+                int SizeMergeDataSet = mergeInfo.size();
+                log.info("数据集数量:{}, 合并数据集数量: {}", SizeDataSet, SizeMergeDataSet);
+
+                for (MergeInfoEntity info : mergeInfo) {
+                    // 获取本地坐标,旋转角度
+                    Integer dataSetId = info.getDataSetId();
+                    double[] point = covertPoint.get(dataSetId);
+
+                    JSONObject cutJson = new JSONObject();
+                    // 这两个参数算法不用,后端自己看
+                    cutJson.put("sceneCode", info.getMergeCode());
+                    cutJson.put("dataSetId", dataSetId);
+                    // 算法要求用空格隔开
+                    cutJson.put("file", info.getPath() + "/laser.las");
+                    cutJson.put("translation", point[0] + " " + point[1] + " " + point[2]);
+                    cutJson.put("rotation", point[3]);
+                    models.add(cutJson);
+                }
             }
 
+
+
+
             // 修剪模型参数
             JSONObject mergeCut = new JSONObject();
             mergeCut.put("model", models);
@@ -341,9 +451,9 @@ public class CutModelServiceImpl extends IBaseServiceImpl implements CutModelSer
             log.info("剪切参数json写入完成");
 
             // 剪切并oss上传模型
-             ossUrl = cutLas(basePath, sceneCode);
+            ossUrl = cutLas(basePath, sceneCode);
+
 
-        }
         // 数据更新到数据库
         saveLasInfo(sceneCode, ossUrl);
 
@@ -358,6 +468,31 @@ public class CutModelServiceImpl extends IBaseServiceImpl implements CutModelSer
     }
 
     /**
+     * 2021-11-04
+     * 处理剪切模型参数并剪切模型,结果上传oss
+     */
+    private void handleCutLas(){
+//        JSONObject mergeCut = new JSONObject();
+//        mergeCut.put("model", models);
+//        // 这个值目前写死
+//        mergeCut.put("aabb", "b-0.5 -0.5 -0.5 0.5 0.5 0.5");
+//
+//        // 剪切模型参数json写入服务器
+//
+//        if ("dev".equals(configConstant.active)){
+//            basePath = configConstant.serverBasePath + "/" + sceneCode + "/results/laserData";
+//        }
+//        String savePath = basePath + "/merge_cut_param.json";
+//        log.info("剪切参数:{}", savePath);
+//        FileUtil.writeUtf8String(mergeCut.toJSONString(), savePath);
+//        log.info("剪切参数json写入完成");
+//
+//        // 剪切并oss上传模型
+//        ossUrl = cutLas(basePath, sceneCode);
+
+    }
+
+    /**
      * 模型剪切信息保存数据库
      */
     private void saveLasInfo(String sceneCode, String ossUrl){

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

@@ -586,7 +586,7 @@ public class InitServiceImpl implements InitService {
         if (!cn.hutool.core.io.FileUtil.isFile(path)) {
             throw new BaseRuntimeException(MsgCode.e3001, "vision.txt不存在");
         }
-        JSONArray jsonArray = convertToVision.createFilter(sceneCode, path, calculateEntity, from);
+        JSONArray jsonArray = convertToVision.createFilter(sceneCode, path, calculateEntity, from, false);
         FilterEntity entity = new FilterEntity();
         entity.setId(sceneCode);
         entity.setCreateTime(LocalDateTime.now());

+ 5 - 2
laser/src/main/java/com/fdkankan/indoor/core/service/impl/MergeSceneServiceImpl.java

@@ -601,8 +601,11 @@ public class MergeSceneServiceImpl extends IBaseServiceImpl implements MergeScen
         if (!cn.hutool.core.io.FileUtil.isFile(path)){
             throw new BaseRuntimeException(MsgCode.e3001, "vision.txt不存在");
         }
-        // 2021-09-14 todo 这里使用web
-        JSONArray jsonArray = convertToVision.createFilter(sceneCode, path, dto, "web");
+        /**
+         * 2021-09-14 todo 这里使用web
+         * 2021-11-05 合并时不需要记录firstView到数据库
+         * */
+        JSONArray jsonArray = convertToVision.createFilter(sceneCode, path, dto, "web", true);
         FilterEntity entity = new FilterEntity();
         entity.setId(sceneCode);
         entity.setCreateTime(LocalDateTime.now());