ソースを参照

处理数据集空间模型问题

wuweihao 3 年 前
コミット
564537e722

+ 2 - 106
laser/src/main/java/com/fdkankan/indoor/base/convert/ConvertToVision.java

@@ -48,7 +48,8 @@ public class ConvertToVision {
 			JSONObject rotation = pose.getJSONObject("rotation");
 			JSONObject translation = pose.getJSONObject("translation");
 			JSONObject puck = sweepItem.getJSONObject("puck");
-			
+
+			// 2021-10-18, id+1 加载全景图会失败
 			item.put("id", id);   //第一个元素的id是1
 			item.put("rotation", rotation);    //quaternation
 			item.put("translation", translation);     //相机坐标
@@ -60,111 +61,6 @@ public class ConvertToVision {
 		return result;
 	}
 
-	/**
-	 * 初始化vision数据
-	 * @param sceneCode
-	 * @param panoInfos
-	 * @param dto
-	 * @return
-	 */
-//	private  JSONArray createVisionToFilter(String sceneCode, JSONArray panoInfos,  ControlPointEntity dto) {
-//
-//		JSONArray laserPanos = new JSONArray();
-//		int visionSize = panoInfos.size();
-//		log.info("漫游点位数量: {}", visionSize);
-//		log.info("需要的大地坐标值:开始======================================================");
-//		for(int i=0;i< visionSize;++i) {
-//			JSONObject item = panoInfos.getJSONObject(i);
-//			JSONObject laserPano = new JSONObject();
-//			int id = item.getInt("id");
-//			laserPano.put("camera_head_id", 12);
-//			laserPano.put("dataset_id", 1);
-////			laserPano.put("file_path", "data/chunk1");
-//			// 2021-8-26
-//			laserPano.put("file_path", "data/" + sceneCode);
-//			laserPano.put("hidden", false);
-//			laserPano.put("id", id);
-////			laserPano.put("site_model_entity_id", 12);
-//			// 2021-09-06改用floor类型的id
-//			laserPano.put("site_model_entity_id", 11);
-//
-//			//JSONObject pose = item.getJSONObject("pose");
-//			JSONObject position2 = item.getJSONObject("puck");
-//			JSONObject position1 = item.getJSONObject("translation");
-//			//相机
-//			double[] location = new double[3];
-//			location[0] = position1.getDouble("x");
-//			location[1] = position1.getDouble("y");
-//			location[2] = position1.getDouble("z");
-//			//地面
-//			double[] floor_location = new double[3];
-//			floor_location[0] = position2.getDouble("x");
-//			floor_location[1] = position2.getDouble("y");
-//			floor_location[2] = position2.getDouble("z");
-//			//gis坐标
-//			log.warn("=============== _location 开始" + i +" =========================");
-//			double[] _location = TransformGPS.convertLocationToGis(location,dto);
-//			log.warn("=============== _location 结束" + i +" =========================");
-//			double[] _floor_location = TransformGPS.convertLocationToGis(floor_location, dto);
-//			location[0] = _location[0];
-//			location[1] = _location[1];
-//			floor_location[0] = _floor_location[0];
-//			floor_location[1] = _floor_location[1];
-//			laserPano.put("location", location);
-//			laserPano.put("floor_location", floor_location);
-//
-//			//相机
-//			double[] dataset_location = new double[3];
-//			dataset_location[0] = position2.getDouble("x");
-//			dataset_location[1] = position2.getDouble("y");
-//			dataset_location[2] = position1.getDouble("z");
-//			//地面
-//			double[] dataset_floor_location = new double[3];
-//			dataset_floor_location[0] = position2.getDouble("x");
-//			dataset_floor_location[1] = position2.getDouble("y");
-//			dataset_floor_location[2] = position2.getDouble("z");
-//
-//			laserPano.put("dataset_location", dataset_location);
-//			laserPano.put("dataset_floor_location", dataset_floor_location);
-//
-//			JSONObject rotation = item.getJSONObject("rotation");
-//			double[] quaternation = new double[4];
-//			quaternation[0] = rotation.getDouble("w");
-//			quaternation[1] = rotation.getDouble("x");
-//			quaternation[2] = rotation.getDouble("y");
-//			quaternation[3] = rotation.getDouble("z");
-//
-//			laserPano.put("orientation", quaternation);
-//			// 2021-08-11
-//			laserPano.put("dataset_orientation", quaternation);
-//			laserPano.put("dataset_floor_orientation", quaternation);
-//
-//			String fileId = String.valueOf(id);
-//			while(fileId.length()<5) {
-//				fileId = "0"+fileId;
-//			}
-//			laserPano.put("file_id", fileId);
-//
-//			laserPanos.add(laserPano);
-//			//firstView
-//			if(i == 0) {
-//				//保存初始点的gis坐标
-//				// _location 存入数据库
-//				SpecialPointEntity pointEntity = new SpecialPointEntity();
-//				// 经度 22 纬度 113
-//				Double[] edit = {_location[0], _location[1]};
-//				pointEntity.setPoi(edit);
-//				pointEntity.setSceneCode(sceneCode);
-//				pointEntity.setUpdateTime(LocalDateTime.now());
-//				pointEntity.setId(SnowFlakeUUidUtils.getUuid("SP"));
-//				pointEntity.setPoiKey(TypeConstant.POI_FIRST_VIEW);
-//				specialPointService.save(pointEntity);
-//				log.info("firstVieW保存成功");
-//			}
-//		}
-//		log.info("需要的大地坐标值:结束====================================================================");
-//		return laserPanos;
-//	}
 
 
 	/**

+ 1 - 1
laser/src/main/java/com/fdkankan/indoor/base/util/CmdUtils.java

@@ -114,7 +114,7 @@ public class CmdUtils {
      */
     public static void ossUploadDir(String cmd){
 
-        log.info("ossCmd: " + cmd);
+//        log.info("ossCmd: " + cmd);
         long start = System.currentTimeMillis();
         CmdUtils.callLineSh(cmd);
         long end = System.currentTimeMillis();

+ 0 - 1
laser/src/main/java/com/fdkankan/indoor/core/controller/SiteModelController.java

@@ -180,7 +180,6 @@ public class SiteModelController {
     @WebControllerLog(description = "分类信息-初始化表")
     @ApiOperation(value = "初始化表", notes = "传入参数目前不处理")
     @PostMapping("indoor/{sceneCode}/api/site_model/generate")
-//    public Object initSiteModel(@PathVariable String sceneCode, @RequestBody Object param) {
     public Object initSiteModel(@PathVariable String sceneCode) {
         Result search = entityService.initSiteModel(sceneCode);
         return search.getData();

+ 149 - 25
laser/src/main/java/com/fdkankan/indoor/core/service/impl/SiteModelServiceImpl.java

@@ -1,10 +1,14 @@
 package com.fdkankan.indoor.core.service.impl;
 
+import com.alibaba.fastjson.JSON;
 import com.alibaba.fastjson.JSONObject;
+import com.fdkankan.indoor.base.constant.ConfigConstant;
 import com.fdkankan.indoor.base.convert.DistanceUtil;
+import com.fdkankan.indoor.base.convert.ModifyCloud;
 import com.fdkankan.indoor.base.exception.BaseRuntimeException;
 import com.fdkankan.indoor.base.util.GisUtils;
 import com.fdkankan.indoor.base.util.Result;
+import com.fdkankan.indoor.core.entity.ControlPointCalculateEntity;
 import com.fdkankan.indoor.core.entity.DataSetEntity;
 import com.fdkankan.indoor.core.entity.FilterEntity;
 import com.fdkankan.indoor.core.entity.SiteModelEntity;
@@ -16,6 +20,7 @@ import com.fdkankan.indoor.core.entity.po.DataSetPo;
 import com.fdkankan.indoor.core.mapper.SiteModelMapper;
 import com.fdkankan.indoor.core.service.*;
 import lombok.extern.slf4j.Slf4j;
+import net.sf.json.JSONArray;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.data.mongodb.core.MongoTemplate;
@@ -23,6 +28,7 @@ import org.springframework.stereotype.Service;
 import org.springframework.util.CollectionUtils;
 
 import java.awt.geom.Point2D;
+import java.io.IOException;
 import java.time.LocalDateTime;
 import java.util.*;
 import java.util.stream.Collectors;
@@ -32,7 +38,7 @@ import java.util.stream.Collectors;
  */
 @Slf4j
 @Service
-public class SiteModelServiceImpl implements SiteModelService {
+public class SiteModelServiceImpl extends IBaseServiceImpl implements SiteModelService {
 
     @Autowired
     MongoTemplate mongoTemplate;
@@ -52,6 +58,12 @@ public class SiteModelServiceImpl implements SiteModelService {
     @Autowired
     FilterService filterService;
 
+    @Autowired
+    ConfigConstant configConstant;
+
+    @Autowired
+    ControlPointCalculateService controlPointCalculateService;
+
 
     // updateSiteMode 只是这个方法用的
     private Integer maxId;
@@ -123,8 +135,6 @@ public class SiteModelServiceImpl implements SiteModelService {
     @Override
     public Result withinType(String sceneCode, Double[] location, String type) {
 
-
-
         List<SiteDto> resData = getDataBySceneCode(sceneCode);
         // 2021-09-18
         if (resData.size() == 0) {
@@ -347,9 +357,6 @@ public class SiteModelServiceImpl implements SiteModelService {
 
     @Override
     public Result initSiteModel(String sceneCode) {
-
-
-
         SiteModelEntity entity = findById(sceneCode);
         if (entity == null) {
             String msg = "siteModel表数据不存在,请检查表数据, 场景码:" + sceneCode;
@@ -359,8 +366,13 @@ public class SiteModelServiceImpl implements SiteModelService {
 
         // 去掉房间数据
         List<SiteDto> data = entity.getData();
-//        recursionRemoveRoom(data);
-        data = removeRoom(data);
+        // 2021-10-18 没有分类信息则添加初始化数据,有则删除房间
+        if (data.size() == 0) {
+            log.info("分类信息为空,重新初始化分类信息数据");
+            data = getBaseSiteModel(sceneCode);
+        } else {
+            data = removeRoom(data);
+        }
 
         entity.setData(data);
         this.save(entity);
@@ -373,6 +385,134 @@ public class SiteModelServiceImpl implements SiteModelService {
 
 
     /**
+     * 2021-10-18 创建初始化的siteModel.data
+     * @param sceneCode
+     * @return
+     */
+    private List<SiteDto> getBaseSiteModel(String sceneCode){
+        String path = redisPath(sceneCode);
+        ControlPointCalculateEntity controlPoint = controlPointCalculateService.findById(sceneCode);
+        List<SiteDto> siteDtos = processCould(path, controlPoint);
+        log.info("分类信息初始化完成");
+
+        return siteDtos;
+    }
+
+    /**
+     *
+     * 处理could.js 并做相应的计算
+     * @param path
+     */
+    private List<SiteDto> processCould(String path, ControlPointCalculateEntity dto){
+        path = path + "/webcloud/cloud.js";
+
+        try {
+            // 修改cloud.js文件
+            net.sf.json.JSONObject info = ModifyCloud.fixCloud(path);
+
+            /**
+             * 将boundingBox坐标转换成gis坐标, site_model需要
+             * boundingBox:虚拟点坐标,存特殊点, dataSet数据要使用
+             */
+            net.sf.json.JSONObject boundingBox = ModifyCloud.getBoundingBox(info);
+            Double maxZ = boundingBox.getDouble("maxZ");
+            Double minZ = boundingBox.getDouble("minZ");
+
+
+            net.sf.json.JSONObject resJson = ModifyCloud.convertFromBoundingBox(boundingBox, dto);
+
+            Double[] gpsMax = getKey(resJson, "max");
+            Double[] gpsMin = getKey(resJson, "min");
+            Double[] gpsCentre = getKeyZ(resJson, "centre");
+
+            // 创建sitModel
+            List<SiteDto> siteModel = initBaseSiteModel(gpsMax, gpsMin, gpsCentre, maxZ, minZ);
+            return siteModel;
+        } catch (IOException e) {
+            e.printStackTrace();
+        }
+        return null;
+    }
+
+
+    /**
+     * 2021-10-18
+     * 创建模板siteModel, 没有ROOM类型
+     * @param max
+     * @param min
+     * @param centre
+     * @param maxZ
+     * @param minZ
+     */
+    private List<SiteDto> initBaseSiteModel(Double[] max, Double[] min, Double[] centre, Double maxZ, Double minZ) {
+        //读取初始文件
+        String content = cn.hutool.core.io.FileUtil.readUtf8String(configConstant.templatePath + "/site_model.json");
+        List<SiteDto> siteModels = JSON.parseArray(content, SiteDto.class);
+        // z_max、z_min 替换site_model的Floor、root类型
+        // max、min四个顶点替换BUILDING、FLOOR 的coordinates,
+        // 顺时针,(x_max,y_max),(x_max,y_min),(x_min,y_min),(x_min,y_max)
+        // 一般参数1:x, 参数2:Y
+        Double[] peak_1 = {max[0], max[1]};
+        Double[] peak_2 = {max[0], min[1]};
+        Double[] peak_3 = {min[0], min[1]};
+        Double[] peak_4 = {min[0], max[1]};
+        List<List<Double[]>> doubles = Arrays.asList(Arrays.asList(peak_1, peak_2, peak_3, peak_4));
+
+        // centre 替换BUILDING、FLOOR、ROOM 的center
+        log.info("中心点:{}, {}, {}", centre[0], centre[1], centre[2]);
+        siteModels.forEach(p -> {
+            // 第一层:BUILDING,处理centre、coordinates
+            p.setCenter(centre);
+            SitePolygon polygon = p.getPolygon();
+
+            //  BUILDING. coordinates, max、min四个顶点替换
+            polygon.setCoordinates(doubles);
+
+            // 第二层:FLOOR 层
+            List<SiteDto> children = p.getChildren();
+            if (children.size() > 0) {
+                children.forEach(c -> {
+                    c.setCenter(centre);
+                    c.setZ_max(maxZ);
+                    c.setZ_min(minZ);
+
+                });
+            }
+
+        });
+        return siteModels;
+
+
+    }
+
+
+    /**
+     * 获取两个值的
+     * json数组转 double[]
+     * @param resJson
+     * @param key
+     * @return
+     */
+    private Double[] getKey(net.sf.json.JSONObject resJson , String key){
+        JSONArray array = resJson.getJSONArray(key);
+        Double[] res = {array.getDouble(0), array.getDouble(1)};
+        return res;
+    }
+
+    /**
+     * 获取三个值的
+     * @param resJson
+     * @param key
+     * @return
+     */
+    private Double[] getKeyZ(net.sf.json.JSONObject resJson , String key){
+        JSONArray array = resJson.getJSONArray(key);
+        Double[] res = {array.getDouble(0), array.getDouble(1), array.getDouble(2)};
+        return res;
+    }
+
+
+    /**
      * 2021-9-16
      * 处理dataSet.site_model_ids, 是否在site_model.z_min,z_max范围内,且去掉房间ids
      *
@@ -495,23 +635,7 @@ public class SiteModelServiceImpl implements SiteModelService {
         return resSite;
     }
 
-    /**
-     * 2021-9-16
-     * 递归方法遍历, 删除房间
-     */
-//    private  void recursionRemoveRoom(List<SiteDto> param){
-////        for (SiteDto dto : param) {
-////            // 递归调用
-////            List<SiteDto> children = dto.getChildren();
-////            if ("FLOOR".equals(dto.getType())){
-////                children = new ArrayList<>();
-////                dto.setChildren(children);
-////            }
-////            if (children.size() > 0) {
-////                recursionRemoveRoom(children);
-////            }
-////        }
-////    }
+
 
 
 

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

@@ -529,10 +529,13 @@ public class TiledMapServiceImpl extends IBaseServiceImpl implements TiledMapSer
         String bundlePath = "data/bundle_" + sceneCode +"/building_1/map_tiles/11";
         String ossTarget = "data/" + sceneCode + "/" + bundlePath;
         String uploadDir = path + "/cover";
+
+
+
+        // 平面图切图上传oss
         ossUploadDir(ossTarget, uploadDir);
 
-        // 压缩并上传oss
-//        zipAndUploadOss(path, uploadDir, sceneCode);
+        // 平面图上传oss
         tiledMapUploadOss(path, sceneCode);
 
     }