|
|
@@ -33,6 +33,30 @@ import java.util.stream.Collectors;
|
|
|
@Component
|
|
|
public class ConvertUtil {
|
|
|
|
|
|
+ private static String RESULTS_DIR = "results";
|
|
|
+
|
|
|
+ private static String DATA_DIR = "data";
|
|
|
+
|
|
|
+ private static String WALLS = "walls";
|
|
|
+
|
|
|
+ private static String SUBGROUP = "subgroup";
|
|
|
+
|
|
|
+ private static String JSON_EXTNAME = ".json";
|
|
|
+
|
|
|
+ private static String IMAGES_4K = "images/4k/";
|
|
|
+
|
|
|
+ private static String IMAGES_512 = "images/512/";
|
|
|
+
|
|
|
+ private static String IMAGES_8K = "images/8k/";
|
|
|
+
|
|
|
+ private static String TITLE = "title";
|
|
|
+
|
|
|
+ private final static String SHOOTTIME = "shootTime";
|
|
|
+
|
|
|
+ private static String extinguisherJson = "extinguisher.json";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private SceneService sceneService;
|
|
|
|
|
|
@@ -98,7 +122,7 @@ public class ConvertUtil {
|
|
|
//调用算法生成modeldata.txt
|
|
|
String extrasPath = obj2TxtPath + File.separator + "extras";
|
|
|
FileUtil.mkdir(extrasPath);
|
|
|
- FileUtil.copyContent(new File(sourcePath + "data" + File.separator + "mesh"), new File(extrasPath), true);
|
|
|
+ FileUtil.copyContent(new File(sourcePath + DATA_DIR + File.separator + "mesh"), new File(extrasPath), true);
|
|
|
|
|
|
//写data.json
|
|
|
writeDataJson(obj2TxtPath);
|
|
|
@@ -107,7 +131,7 @@ public class ConvertUtil {
|
|
|
build3dModel(obj2TxtPath);
|
|
|
|
|
|
//校验算法是否正常结束
|
|
|
- String uploadJsonPath = obj2TxtPath + File.separator + "results" +File.separator+"upload.json";
|
|
|
+ String uploadJsonPath = obj2TxtPath + File.separator + RESULTS_DIR +File.separator+"upload.json";
|
|
|
boolean success = checkComputeCompleted(uploadJsonPath, 5, 300);
|
|
|
if(!success){
|
|
|
throw new RuntimeException("计算失败,obj2TxtPath:" + obj2TxtPath);
|
|
|
@@ -126,23 +150,23 @@ public class ConvertUtil {
|
|
|
fileJson = array.getJSONObject(i);
|
|
|
fileName = fileJson.getString("file");
|
|
|
//文件不存在抛出异常
|
|
|
- if (!new File(obj2TxtPath + File.separator + "results" + File.separator + fileName).exists()) {
|
|
|
- throw new Exception(obj2TxtPath + File.separator + "results" + File.separator + fileName + "文件不存在");
|
|
|
+ if (!new File(obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName).exists()) {
|
|
|
+ throw new Exception(obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName + "文件不存在");
|
|
|
}
|
|
|
|
|
|
//tex文件夹
|
|
|
if (fileJson.getIntValue("clazz") == 15) {
|
|
|
-// FileUtil.copy(obj2TxtPath + File.separator + "results" + File.separator + fileName,
|
|
|
+// FileUtil.copy(obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName,
|
|
|
// targetImagePath + File.separator + "tieta_texture/" + fileName.replace("tex/", ""),true);
|
|
|
- map.put(imgViewPath + "tieta_texture/" + fileName.replace("tex/", ""), obj2TxtPath + File.separator + "results" + File.separator + fileName);
|
|
|
+ map.put(imgViewPath + "tieta_texture/" + fileName.replace("tex/", ""), obj2TxtPath + File.separator + RESULTS_DIR + File.separator + fileName);
|
|
|
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//压缩成dam
|
|
|
String damKey = imgViewPath + "tieta.dam";
|
|
|
- String damPath = obj2TxtPath + File.separator + "results" +File.separator + "dam.txt";
|
|
|
- CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + "results" +File.separator+"modeldata.txt", damPath);
|
|
|
+ String damPath = obj2TxtPath + File.separator + RESULTS_DIR +File.separator + "dam.txt";
|
|
|
+ CreateObjUtil.convertTxtToDam( obj2TxtPath + File.separator + RESULTS_DIR +File.separator+"modeldata.txt", damPath);
|
|
|
map.put(damKey, damPath);
|
|
|
|
|
|
//识别灭火器
|
|
|
@@ -151,17 +175,17 @@ public class ConvertUtil {
|
|
|
//复制文件
|
|
|
JSONObject standarFloor = null;
|
|
|
Integer maxWallNum = 0;
|
|
|
- if(FileUtil.exist(sourcePath + "data/floorplan.json")){
|
|
|
- String floorplanJson = FileUtil.readUtf8String(sourcePath + "data/floorplan.json");
|
|
|
+ if(FileUtil.exist(sourcePath + DATA_DIR + "/floorplan.json")){
|
|
|
+ String floorplanJson = FileUtil.readUtf8String(sourcePath + DATA_DIR + "/floorplan.json");
|
|
|
JSONObject jsonObject = JSON.parseObject(floorplanJson);
|
|
|
Integer currentId = jsonObject.getInteger("currentId");
|
|
|
if(Objects.nonNull(currentId) && currentId == 0){
|
|
|
- FileUtil.del(sourcePath + "data/" + "floorplan.json");
|
|
|
+ FileUtil.del(sourcePath + DATA_DIR + "/floorplan.json");
|
|
|
}else{
|
|
|
JSONArray floors = jsonObject.getJSONArray("floors");
|
|
|
for (Object floor : floors) {
|
|
|
JSONObject floorObj = (JSONObject) floor;
|
|
|
- Map walls = floorObj.getObject("walls", Map.class);
|
|
|
+ Map walls = floorObj.getObject(WALLS, Map.class);
|
|
|
if(walls.keySet().size() > maxWallNum){
|
|
|
maxWallNum = walls.keySet().size();
|
|
|
standarFloor = floorObj;
|
|
|
@@ -170,45 +194,45 @@ public class ConvertUtil {
|
|
|
//切割,按subgroup分成多份
|
|
|
for (Object floor : floors) {
|
|
|
JSONObject floorObj = (JSONObject) floor;
|
|
|
- Integer subgroup = floorObj.getIntValue("subgroup");
|
|
|
- floorObj.put("walls", standarFloor.getJSONObject("walls"));
|
|
|
+ Integer subgroup = floorObj.getIntValue(SUBGROUP);
|
|
|
+ floorObj.put(WALLS, standarFloor.getJSONObject(WALLS));
|
|
|
floorObj.put("points", standarFloor.getJSONObject("points"));
|
|
|
- floorObj.put("subgroup", 0);
|
|
|
+ floorObj.put(SUBGROUP, 0);
|
|
|
floorObj.put("id", 0);
|
|
|
jsonObject.replace("floors", Arrays.asList(floorObj));
|
|
|
- String floorplanPath = sourcePath + "data/floorplan" + "-" + subgroup + ".json";
|
|
|
+ String floorplanPath = sourcePath + DATA_DIR + "/floorplan" + "-" + subgroup + JSON_EXTNAME;
|
|
|
FileUtil.writeUtf8String(jsonObject.toJSONString(), floorplanPath);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- List<File> dataFiles = FileUtil.loopFiles(sourcePath + "data/");
|
|
|
+ List<File> dataFiles = FileUtil.loopFiles(sourcePath + DATA_DIR + "/");
|
|
|
for (File dataFile : dataFiles) {
|
|
|
if(dataFile.getAbsolutePath().contains("floorplan")){
|
|
|
continue;
|
|
|
}
|
|
|
- map.put(dataFile.getAbsolutePath().replace(sourcePath + "data/", dataViewPath) , dataFile.getAbsolutePath());
|
|
|
+ map.put(dataFile.getAbsolutePath().replace(sourcePath + DATA_DIR + "/", dataViewPath) , dataFile.getAbsolutePath());
|
|
|
}
|
|
|
|
|
|
String finalSourcePath = sourcePath;
|
|
|
- if(FileUtil.exist(finalSourcePath + "images/4k/")){
|
|
|
- FileUtil.listFileNames(sourcePath + "images/4k/").stream().forEach(v->{
|
|
|
- map.put(imgViewPath + "pan/high/" + v.replaceAll("-", ""), finalSourcePath + "images/4k/" + v);
|
|
|
-// FileUtil.copy(finalSourcePath + "images/4k/" + v, targetImagePath + "/pan/high/" + v.replaceAll("-", ""), true);
|
|
|
+ if(FileUtil.exist(finalSourcePath + IMAGES_4K)){
|
|
|
+ FileUtil.listFileNames(sourcePath + IMAGES_4K).stream().forEach(v->{
|
|
|
+ map.put(imgViewPath + "pan/high/" + v.replaceAll("-", ""), finalSourcePath + IMAGES_4K + v);
|
|
|
+// FileUtil.copy(finalSourcePath + IMAGES_4K + v, targetImagePath + "/pan/high/" + v.replaceAll("-", ""), true);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if(FileUtil.exist(finalSourcePath + "images/512/")){
|
|
|
- FileUtil.listFileNames(finalSourcePath + "images/512/").stream().forEach(v->{
|
|
|
- map.put(imgViewPath + "pan/low/" + v.replaceAll("-", ""), finalSourcePath + "images/512/" + v);
|
|
|
-// FileUtil.copy(finalSourcePath + "images/512/" + v, targetImagePath + "/pan/low/" + v.replaceAll("-", ""), true);
|
|
|
+ if(FileUtil.exist(finalSourcePath + IMAGES_512)){
|
|
|
+ FileUtil.listFileNames(finalSourcePath + IMAGES_512).stream().forEach(v->{
|
|
|
+ map.put(imgViewPath + "pan/low/" + v.replaceAll("-", ""), finalSourcePath + IMAGES_512 + v);
|
|
|
+// FileUtil.copy(finalSourcePath + IMAGES_512 + v, targetImagePath + "/pan/low/" + v.replaceAll("-", ""), true);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- if(FileUtil.exist(finalSourcePath + "images/8k/")) {
|
|
|
- FileUtil.listFileNames(finalSourcePath + "images/8k/").stream().forEach(v -> {
|
|
|
- map.put(imgViewPath + "pan/8k/" + v.replaceAll("-", ""), finalSourcePath + "images/8k/" + v);
|
|
|
-// FileUtil.copy(finalSourcePath + "images/8k/" + v, targetImagePath + "/pan/8k/" + v.replaceAll("-", ""), true);
|
|
|
+ if(FileUtil.exist(finalSourcePath + IMAGES_8K)) {
|
|
|
+ FileUtil.listFileNames(finalSourcePath + IMAGES_8K).stream().forEach(v -> {
|
|
|
+ map.put(imgViewPath + "pan/8k/" + v.replaceAll("-", ""), finalSourcePath + IMAGES_8K + v);
|
|
|
+// FileUtil.copy(finalSourcePath + IMAGES_8K + v, targetImagePath + "/pan/8k/" + v.replaceAll("-", ""), true);
|
|
|
});
|
|
|
|
|
|
}
|
|
|
@@ -225,13 +249,13 @@ public class ConvertUtil {
|
|
|
Map<Integer, List<JSONObject>> subgroupMap = new HashMap<>();
|
|
|
for (Object item : sweepLocationsArr) {
|
|
|
JSONObject obj = (JSONObject) item;
|
|
|
- int subgroup = obj.getIntValue("subgroup");
|
|
|
+ int subgroup = obj.getIntValue(SUBGROUP);
|
|
|
List<JSONObject> jsonObjects = subgroupMap.get(subgroup);
|
|
|
if(jsonObjects == null){
|
|
|
jsonObjects = new ArrayList<>();
|
|
|
subgroupMap.put(subgroup, jsonObjects);
|
|
|
}
|
|
|
- obj.put("subgroup", 0);
|
|
|
+ obj.put(SUBGROUP, 0);
|
|
|
jsonObjects.add(obj);
|
|
|
|
|
|
List<String> visible = visibleMap.get(subgroup);
|
|
|
@@ -273,14 +297,14 @@ public class ConvertUtil {
|
|
|
map.put(imgViewPath + "vision.txt", visionTxtPath);
|
|
|
|
|
|
//拆分floorplan.json
|
|
|
- String floorplanPath = sourcePath + "data/floorplan" + "-" + subgroup + ".json";
|
|
|
+ String floorplanPath = sourcePath + DATA_DIR + "/floorplan" + "-" + subgroup + JSON_EXTNAME;
|
|
|
if(FileUtil.exist(floorplanPath)){
|
|
|
map.put(dataViewPath + "floorplan.json", floorplanPath);
|
|
|
}
|
|
|
|
|
|
//生成scene.json
|
|
|
- String sceneJsonPath = sourcePath + "data/scene" + "-" + subgroup + ".json";
|
|
|
- SceneJsonBean sceneJsonBean = this.genSceneJson(num, sceneBashInfo.getString("title"), subgroup);
|
|
|
+ String sceneJsonPath = sourcePath + DATA_DIR + "/scene" + "-" + subgroup + JSON_EXTNAME;
|
|
|
+ SceneJsonBean sceneJsonBean = this.genSceneJson(num, sceneBashInfo.getString(TITLE), subgroup);
|
|
|
FileUtil.writeUtf8String(JSON.toJSONString(sceneJsonBean), sceneJsonPath);
|
|
|
map.put(dataViewPath + "scene.json", sceneJsonPath);
|
|
|
|
|
|
@@ -317,7 +341,7 @@ public class ConvertUtil {
|
|
|
// }
|
|
|
|
|
|
Scene scene = new Scene();
|
|
|
- scene.setTitle(sceneBashInfo.getString("title"));
|
|
|
+ scene.setTitle(sceneBashInfo.getString(TITLE));
|
|
|
scene.setNum(num);
|
|
|
scene.setFloorlogosize(100);
|
|
|
scene.setScenekind("pano");
|
|
|
@@ -327,13 +351,13 @@ public class ConvertUtil {
|
|
|
scene.setFloorplanangle(0);
|
|
|
scene.setSubgroup(subgroup);
|
|
|
scene.setStationcode(stationCode);
|
|
|
- scene.setShootTime(sceneBashInfo.getDate("shootTime"));
|
|
|
+ scene.setShootTime(sceneBashInfo.getDate(SHOOTTIME));
|
|
|
scene.setUpTime(upTime);
|
|
|
scene.setAlgorithmTime(new Date());
|
|
|
scene.setExtinguisher(extinguisher);
|
|
|
scene.setUpTimeKey(upTimeKey);
|
|
|
scene.setCacheKeyHasTime(1);
|
|
|
- sceneService.saveOrUpdate(scene);
|
|
|
+ sceneService.save(scene);
|
|
|
|
|
|
SceneEditInfo sceneEditInfo = new SceneEditInfo();
|
|
|
sceneEditInfo.setScenePlusId(scene.getId());
|
|
|
@@ -375,14 +399,14 @@ public class ConvertUtil {
|
|
|
|
|
|
//查询是否有热点
|
|
|
String key = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, preScene.getUpTimeKey(), preScene.getCacheKeyHasTime()));
|
|
|
- Map<String, String> allTagsMap = redisClient.hmget("scene", key);
|
|
|
+ Map<String, String> allTagsMap = redisClient.hmget(RedisClient.scene_sys_code, key);
|
|
|
if(CollUtil.isEmpty(allTagsMap)){
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
//如果有热点,复制redis和涉及的图片
|
|
|
String newKey = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(num, subgroup, upTimeKey, scene.getCacheKeyHasTime()));
|
|
|
- redisClient.hmset("scene", newKey, allTagsMap);
|
|
|
+ redisClient.hmset(RedisClient.scene_sys_code, newKey, allTagsMap);
|
|
|
|
|
|
sceneEditInfo.setTags(1);
|
|
|
sceneEditInfoService.updateById(sceneEditInfo);
|
|
|
@@ -421,11 +445,11 @@ public class ConvertUtil {
|
|
|
//复制icon
|
|
|
//查询缓存是否包含icons
|
|
|
String iconKey = String.format(RedisKey.SCENE_HOT_ICONS, RedisKey.getNumStr(num, subgroup, preScene.getUpTimeKey() ,preScene.getCacheKeyHasTime()));
|
|
|
- Set<String> icons = redisClient.sGet("scene", iconKey);
|
|
|
+ Set<String> icons = redisClient.sGet(RedisClient.scene_sys_code, iconKey);
|
|
|
if(CollUtil.isNotEmpty(icons)){
|
|
|
|
|
|
String newIconKey = String.format(RedisKey.SCENE_HOT_ICONS, RedisKey.getNumStr(num, subgroup, scene.getUpTimeKey() ,scene.getCacheKeyHasTime()));
|
|
|
- redisClient.sSet("scene", newIconKey, icons);
|
|
|
+ redisClient.sSet(RedisClient.scene_sys_code, newIconKey, icons);
|
|
|
|
|
|
List<String> iconFileList = icons.stream().map(i -> {
|
|
|
return String.format(Constant.USER_VIEW_PATH, num) + i;
|
|
|
@@ -451,7 +475,7 @@ public class ConvertUtil {
|
|
|
Integer cacheKeyHasTime = scene.getCacheKeyHasTime();
|
|
|
|
|
|
String hotDataKey = String.format(RedisKey.SCENE_HOT_DATA, RedisKey.getNumStr(sceneNum, subgroup,upTime,cacheKeyHasTime));
|
|
|
- Map<String, String> hotMap = redisClient.hmget("scene", hotDataKey);
|
|
|
+ Map<String, String> hotMap = redisClient.hmget(RedisClient.scene_sys_code, hotDataKey);
|
|
|
|
|
|
JSONArray tags = new JSONArray();
|
|
|
if(CollUtil.isNotEmpty(hotMap)){
|
|
|
@@ -482,33 +506,36 @@ public class ConvertUtil {
|
|
|
//灭火器标注识别
|
|
|
String imagesPath = sourcePath + "images/";
|
|
|
String annihilatorPath = imagesPath + "4k/";
|
|
|
- String cmd = "bash /home/ubuntu/bin/PotreeConverter.sh tieta_det " + annihilatorPath + " /home/ubuntu/bin/model/best.onnx " + imagesPath + "extinguisher.json";
|
|
|
+ String cmd = "bash /home/ubuntu/bin/PotreeConverter.sh tieta_det " + annihilatorPath + " /home/ubuntu/bin/model/best.onnx " + imagesPath + extinguisherJson;
|
|
|
log.info("---------start extinguisher, cmd:{}", cmd);
|
|
|
CmdUtils.callLineSh(cmd);
|
|
|
log.info("---------end extinguisher, cmd:{}", cmd);
|
|
|
- if(FileUtil.exist(imagesPath + "extinguisher.json")){
|
|
|
- map.put(imgViewPath + "extinguisher.json", imagesPath + "extinguisher.json");
|
|
|
+ if(FileUtil.exist(imagesPath + extinguisherJson)){
|
|
|
+ map.put(imgViewPath + extinguisherJson, imagesPath + extinguisherJson);
|
|
|
|
|
|
- String extinguisherStr = FileUtil.readUtf8String(imagesPath + "extinguisher.json");
|
|
|
+ String extinguisherStr = FileUtil.readUtf8String(imagesPath + extinguisherJson);
|
|
|
JSONObject jsonObject = JSON.parseObject(extinguisherStr);
|
|
|
JSONArray imgBoxsList = jsonObject.getJSONArray("imgBoxsList");
|
|
|
boolean existExtinguisher = imgBoxsList.stream().anyMatch(box -> {
|
|
|
JSONObject boxObj = (JSONObject) box;
|
|
|
JSONArray shapes = boxObj.getJSONArray("shapes");
|
|
|
- return shapes.stream().anyMatch(shape -> {
|
|
|
- JSONObject shapeObj = (JSONObject) shape;
|
|
|
- if ("extinguisher".equals(shapeObj.getString("category"))) {
|
|
|
- return true;
|
|
|
- }
|
|
|
- return false;
|
|
|
- });
|
|
|
+ if(CollUtil.isNotEmpty(shapes)){
|
|
|
+ return shapes.stream().anyMatch(shape -> {
|
|
|
+ JSONObject shapeObj = (JSONObject) shape;
|
|
|
+ if ("extinguisher".equals(shapeObj.getString("category"))) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ return false;
|
|
|
});
|
|
|
if(existExtinguisher){
|
|
|
extinguisher = 1;
|
|
|
}
|
|
|
}
|
|
|
}catch (Exception e){
|
|
|
- log.error("getExtinguisher fail, num{}", num, e);
|
|
|
+ log.error("getExtinguisher fail, num:{}", num, e);
|
|
|
}
|
|
|
return extinguisher;
|
|
|
}
|
|
|
@@ -547,20 +574,20 @@ public class ConvertUtil {
|
|
|
|
|
|
private JSONObject getSceneBashInfo(String roomId, String sourcePath){
|
|
|
JSONObject info = new JSONObject();
|
|
|
- String sceneJsonPath = sourcePath + "data/scene.json";
|
|
|
+ String sceneJsonPath = sourcePath + DATA_DIR + "/scene.json";
|
|
|
if(!FileUtil.exist(sceneJsonPath)){
|
|
|
return info;
|
|
|
}
|
|
|
String sceneJsonStr = FileUtil.readUtf8String(sceneJsonPath);
|
|
|
JSONObject jsonObject = JSON.parseObject(sceneJsonStr);
|
|
|
- String title = jsonObject.getString("title");
|
|
|
+ String title = jsonObject.getString(TITLE);
|
|
|
if(StrUtil.isEmpty(title)){
|
|
|
title = roomId;
|
|
|
}
|
|
|
- info.put("title", title);
|
|
|
- String shootTimeStr = jsonObject.getString("shootTime");
|
|
|
+ info.put(TITLE, title);
|
|
|
+ String shootTimeStr = jsonObject.getString(SHOOTTIME);
|
|
|
if(StrUtil.isNotEmpty(shootTimeStr)){
|
|
|
- info.put("shootTime", DateUtil.parse(shootTimeStr, DatePattern.NORM_DATETIME_FORMAT));
|
|
|
+ info.put(SHOOTTIME, DateUtil.parse(shootTimeStr, DatePattern.NORM_DATETIME_FORMAT));
|
|
|
}
|
|
|
|
|
|
return info;
|