|
@@ -1,332 +0,0 @@
|
|
|
-package com.fdkankan.modeling.utils;
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONArray;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.fdkankan.utils.constant.ConstantFileName;
|
|
|
-import com.fdkankan.utils.constant.ConstantFilePath;
|
|
|
-import com.fdkankan.utils.utils.CreateObjUtil;
|
|
|
-import com.fdkankan.utils.utils.FileUtils;
|
|
|
-import lombok.extern.slf4j.Slf4j;
|
|
|
-import org.springframework.stereotype.Component;
|
|
|
-
|
|
|
-import java.io.File;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
-import java.util.UUID;
|
|
|
-
|
|
|
-/**
|
|
|
- * 生成场景和计算场景
|
|
|
- * Created by Hb_zzZ on 2019/5/8.
|
|
|
- */
|
|
|
-@Slf4j
|
|
|
-@Component
|
|
|
-public class ComputerUtil {
|
|
|
-
|
|
|
-
|
|
|
- public static Map<String,String> computer(String projectNum, String path, String buildType) throws Exception{
|
|
|
- Map<String,String> map = new HashMap<String,String>();
|
|
|
- path = path.replace("//", "/");
|
|
|
-
|
|
|
- log.info("开始建模:"+projectNum);
|
|
|
- //构建算法isModel去掉,因此改成空字符串
|
|
|
- if("V2".equals(buildType)){
|
|
|
- CreateObjUtil.build3dModelOld(path, "");
|
|
|
- }
|
|
|
- if("V3".equals(buildType)){
|
|
|
- CreateObjUtil.build3dModel(path, "");
|
|
|
-// CreateObjUtil.build3dModel(unicode, "");
|
|
|
- }
|
|
|
- log.info("建模完成转换数据:"+projectNum);
|
|
|
-
|
|
|
- boolean vision2 = false;
|
|
|
- //读取upload文件,检验需要上传的文件是否存在
|
|
|
- String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
|
|
|
- JSONObject uploadJson = null;
|
|
|
- JSONArray array = null;
|
|
|
- if(uploadData!=null) {
|
|
|
- uploadJson = JSONObject.parseObject(uploadData);
|
|
|
- array = uploadJson.getJSONArray("upload");
|
|
|
- }
|
|
|
- if(array == null){
|
|
|
- String instanceId = FileUtils.readFile("/opt/hosts/hosts.txt");
|
|
|
- FileUtils.writeFile(path + File.separator + "javaErrorNow.log", instanceId + ":计算错误!");
|
|
|
-
|
|
|
- Thread.sleep(10000L);
|
|
|
- FileUtils.writeFile(path + File.separator + "javaError.log", instanceId + ":计算错误!");
|
|
|
- throw new Exception("upload.json数据出错");
|
|
|
- }
|
|
|
- JSONObject fileJson = null;
|
|
|
- String fileName = "";
|
|
|
- String meshfix = ""; //双模型时候会有改文件路径
|
|
|
- for(int i = 0, len = array.size(); i < len; i++){
|
|
|
- fileJson = array.getJSONObject(i);
|
|
|
- fileName = fileJson.getString("file");
|
|
|
- //文件不存在抛出异常
|
|
|
- if(!new File(path + File.separator + "results" +File.separator + fileName).exists()){
|
|
|
- throw new Exception(path + File.separator + "results" +File.separator + fileName+"文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- //判断是否有vision2.txt
|
|
|
- if("vision2.txt".equals(fileName)){
|
|
|
- vision2 = true;
|
|
|
- }
|
|
|
-
|
|
|
- //tex文件夹
|
|
|
- if(fileJson.getIntValue("clazz") == 2 && !fileJson.containsKey("pack-file")){
|
|
|
- if(fileName.contains("meshfix.txt")){
|
|
|
- meshfix = fileName;
|
|
|
- }else {
|
|
|
- map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
|
|
|
- projectNum+"/"+ ConstantFileName.modelUUID+"_50k_texture_jpg_high1/"+fileName.replace("tex/", ""));
|
|
|
- }
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //high文件夹
|
|
|
- if(fileJson.getIntValue("clazz") == 3){
|
|
|
- map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
|
|
|
- projectNum+"/pan/high/"+ fileName.replace("high/", ""));
|
|
|
- continue;
|
|
|
- }
|
|
|
- //low文件夹
|
|
|
- if(fileJson.getIntValue("clazz") == 4){
|
|
|
- map.put(path + File.separator + "results" +File.separator+ fileName,"images/images"+
|
|
|
- projectNum+"/pan/low/"+ fileName.replace("low/", ""));
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //tiles文件夹,亚马逊没有裁剪图片api,不需要上传4k图
|
|
|
-// if(fileJson.getIntValue("clazz") == 5 && !"s3".equals(ossType)){
|
|
|
-// map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
|
|
|
-// projectNum+ File.separator + fileName);
|
|
|
-// continue;
|
|
|
-// }
|
|
|
- if(fileJson.getIntValue("clazz") == 5 ){
|
|
|
- map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
|
|
|
- projectNum+ File.separator + fileName);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //tiles文件夹,亚马逊瓦片图
|
|
|
- if(fileJson.getIntValue("clazz") == 7 ){
|
|
|
- if(fileName.contains("/4k_")){
|
|
|
- continue;
|
|
|
- }
|
|
|
- map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
|
|
|
- projectNum+ File.separator + fileName);
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //updown文件复制一份到ecs中并去掉换行符
|
|
|
- if(fileJson.getIntValue("clazz") == 10){
|
|
|
- String updown = FileUtils.readFile(path + File.separator + "results" +File.separator+ fileName);
|
|
|
- JSONObject updownJson = JSONObject.parseObject(updown);
|
|
|
- FileUtils.writeFile(ConstantFilePath.SCENE_PATH + "data" + File.separator + "data" + projectNum +
|
|
|
- File.separator + fileName.replace("updown", "mapping"), updownJson.toString());
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- //video视频文件或封面图
|
|
|
- if(fileJson.getIntValue("clazz") == 11 || fileJson.getIntValue("cl" +
|
|
|
- "azz") == 12){
|
|
|
- map.put(path + File.separator + "results" + File.separator+ fileName,"video/video"+
|
|
|
- projectNum+ File.separator + fileName.replace("videos/", ""));
|
|
|
-
|
|
|
- if(fileName.contains(".mp4")){
|
|
|
-// CreateObjUtil.mp4ToFlv(path + File.separator + "results" + File.separator+ fileName,
|
|
|
-// path + File.separator + "results" + File.separator+ fileName.replace("mp4", "flv"));
|
|
|
-
|
|
|
- map.put(path + File.separator + "results" + File.separator+ fileName.replace("mp4", "flv"),"video/video"+
|
|
|
- projectNum+ File.separator + fileName.replace("videos/", "").replace("mp4", "flv"));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //2048的模型和贴图
|
|
|
- if(fileJson.getIntValue("clazz") == 16){
|
|
|
- map.put(path + File.separator + "results" + File.separator+ fileName,"data/data"+
|
|
|
- projectNum+ File.separator + fileName);
|
|
|
- }
|
|
|
-
|
|
|
- if(fileJson.getIntValue("clazz") == 18){
|
|
|
- map.put(path + File.separator + "results" + File.separator+ fileName,"images/images"+
|
|
|
- projectNum+ File.separator + fileName);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k.dam");
|
|
|
- CreateObjUtil.convertDamToLzma(path + File.separator + "results");
|
|
|
- CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+"tex"+File.separator+"modeldata.txt", path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
- //有meshfix,表示双模型
|
|
|
- if(!"".equals(meshfix)){
|
|
|
- CreateObjUtil.convertTxtToDam( path + File.separator + "results" + File.separator+meshfix, path + File.separator + "results" +File.separator+ ConstantFileName.modelUUID+"_50k2.dam");
|
|
|
- CreateObjUtil.convertDamToLzma2(path + File.separator + "results");
|
|
|
- CreateObjUtil.convertTxtToDam( path + File.separator + "results" +File.separator+meshfix, path + File.separator + "results" + File.separator+ConstantFileName.modelUUID+"_50k2.dam");
|
|
|
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k2.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k2.dam.lzma");
|
|
|
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k2.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k2.dam");
|
|
|
- }
|
|
|
- //8目相机有两个vision.txt因此第二个叫vision2.txt
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
|
|
|
- if(vision2){
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldata(path + File.separator + "results" +File.separator+"vision2.txt",path + File.separator + "results" +File.separator+"vision2.modeldata");
|
|
|
- map.put(path + File.separator + "results" +File.separator+"vision2.modeldata", "images/images"+projectNum+"/"+"vision2.modeldata");
|
|
|
- }else {
|
|
|
- CreateObjUtil.convertTxtToVisionmodeldataCommon(path + File.separator + "results" +File.separator+"vision.txt",path + File.separator + "results" +File.separator+"vision.modeldata");
|
|
|
- }
|
|
|
- log.info("数据转换完成:"+projectNum);
|
|
|
-
|
|
|
- File file = new File(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma");
|
|
|
- while(!file.exists())
|
|
|
- {
|
|
|
- Thread.sleep(60000);
|
|
|
- }
|
|
|
-
|
|
|
- map.put(path + File.separator + "results" +File.separator+"vision.modeldata", "images/images"+projectNum+"/"+"vision.modeldata");
|
|
|
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam.lzma", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam.lzma");
|
|
|
- map.put(path + File.separator + "results" +File.separator+ConstantFileName.modelUUID+"_50k.dam", "images/images"+projectNum+"/"+ConstantFileName.modelUUID+"_50k.dam");
|
|
|
-
|
|
|
- file = new File(ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum);
|
|
|
- if(!file.exists())
|
|
|
- {
|
|
|
- file.mkdir();
|
|
|
- }
|
|
|
- FileUtils.copyFile(path + File.separator + "results" +File.separator+"floor.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floor.json", true);
|
|
|
- FileUtils.copyFile(path + File.separator + "results" +File.separator+"floorplan.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floor.json", true);
|
|
|
- FileUtils.copyFile(path + File.separator + "results" +File.separator+"floorplan.json", ConstantFilePath.SCENE_PATH+"data"+File.separator+"data"+projectNum+File.separator+"floorplan.json", true);
|
|
|
- log.info("floor.json路径:"+ path + File.separator + "results" +File.separator+"floor.json");
|
|
|
- map.put(path + File.separator + "results" +File.separator+"floor.json","data/data"+projectNum+"/floor.json");
|
|
|
- map.put(path + File.separator + "results" +File.separator+"floorplan.json","data/data"+projectNum+"/floor.json");
|
|
|
-// map.put(path + File.separator + "results" +File.separator+"floorplan_cad.json","data/data"+projectNum+"/house_floor.json");
|
|
|
- map.put(path + File.separator + "results" +File.separator+"floorplan_cad.json","data/data"+projectNum+"/floorplan_cad.json");
|
|
|
- log.info("准备上传文件到oss:"+projectNum);
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 标定算法
|
|
|
- * @param path
|
|
|
- * @throws Exception
|
|
|
- */
|
|
|
- public static Map<String,String> computerCalibration(String path) throws Exception{
|
|
|
-
|
|
|
- Map<String,String> map = new HashMap<String,String>();
|
|
|
-
|
|
|
- log.info("开始标定:" );
|
|
|
- //构建算法isModel去掉,因此改成空字符串
|
|
|
- CreateObjUtil.build3dModel(path, "");
|
|
|
-// CreateObjUtil.build3dModel(unicode, "");
|
|
|
- log.info("标定完成转换数据:" );
|
|
|
-
|
|
|
- boolean vision2 = false;
|
|
|
- //读取upload文件,检验需要上传的文件是否存在
|
|
|
- String uploadData = FileUtils.readFile(path + File.separator + "results" +File.separator+"upload.json");
|
|
|
- JSONObject uploadJson = null;
|
|
|
- JSONArray array = null;
|
|
|
- if(uploadData!=null) {
|
|
|
- uploadJson = JSONObject.parseObject(uploadData);
|
|
|
- array = uploadJson.getJSONArray("upload");
|
|
|
- }
|
|
|
- if(array == null){
|
|
|
- throw new Exception("upload.json数据出错");
|
|
|
- }
|
|
|
- JSONObject fileJson = null;
|
|
|
- String fileName = "";
|
|
|
- for(int i = 0, len = array.size(); i < len; i++) {
|
|
|
- fileJson = array.getJSONObject(i);
|
|
|
- fileName = fileJson.getString("file");
|
|
|
- //文件不存在抛出异常
|
|
|
- if (!new File(path + File.separator + "results" + File.separator + fileName).exists()) {
|
|
|
- throw new Exception(path + File.separator + "results" + File.separator + fileName + "文件不存在");
|
|
|
- }
|
|
|
-
|
|
|
- if(fileJson.getIntValue("clazz") == 13 || fileJson.getIntValue("clazz") == 14){
|
|
|
- map.put(path + File.separator + "results" +File.separator+ fileName,
|
|
|
- ConstantFilePath.OSS_PREFIX + path.replace(ConstantFilePath.BUILD_MODEL_PATH, "") +
|
|
|
- File.separator + fileName);
|
|
|
- }
|
|
|
- }
|
|
|
- return map;
|
|
|
- }
|
|
|
-
|
|
|
- public static void createJson(String path, String splitType, String skyboxType, String dataDescribe,
|
|
|
- String sceneNum, String dataSource) throws Exception{
|
|
|
- JSONObject projectJson = new JSONObject();
|
|
|
- projectJson.put("version", "201909231830");
|
|
|
- projectJson.put("protocol", "file api 1.4");
|
|
|
- projectJson.put("uuid", UUID.randomUUID().toString());
|
|
|
- projectJson.put("description", "");
|
|
|
- projectJson.put("time", System.currentTimeMillis());
|
|
|
- projectJson.put("category", "default");
|
|
|
- projectJson.put("tag", null);
|
|
|
- projectJson.put("status", null);
|
|
|
- projectJson.put("sceneNum", sceneNum);
|
|
|
- projectJson.put("dataSource", dataSource);
|
|
|
- FileUtils.writeFile(path + File.separator + "project.json", projectJson.toString());
|
|
|
-
|
|
|
- JSONObject dataJson = new JSONObject();
|
|
|
- dataJson.put("split_type", splitType);
|
|
|
- dataJson.put("skybox_type", skyboxType);
|
|
|
-// dataJson.put("data_describe", dataDescribe);
|
|
|
- dataJson.put("extras", null);
|
|
|
- FileUtils.writeFile(path + File.separator + "data.json", dataJson.toString());
|
|
|
- }
|
|
|
-
|
|
|
- public static Map<String, String> getTypeString(String cameraType, String algorithm, String resolution){
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
- String splitType = "";
|
|
|
- String skyboxType = "";
|
|
|
- String dataDescribe = "";
|
|
|
- if(Integer.parseInt(cameraType) >= 4){
|
|
|
- if("0".equals(resolution)){
|
|
|
-// skyboxType = "SKYBOX_V4"; //tiles
|
|
|
-// skyboxType = "SKYBOX_V6"; //high,low,4k
|
|
|
- skyboxType = "SKYBOX_V7"; //high,low,2k
|
|
|
- }else {
|
|
|
- skyboxType = "SKYBOX_V1";
|
|
|
- }
|
|
|
- splitType = "SPLIT_V1";
|
|
|
-// skyboxType = "SKYBOX_V4"; //tiles
|
|
|
- dataDescribe = "double spherical";
|
|
|
-
|
|
|
- if(Integer.parseInt(cameraType) == 5 ){
|
|
|
- //新双目相机
|
|
|
-// skyboxType = "SKYBOX_V9";
|
|
|
- splitType = "SPLIT_V9";
|
|
|
- skyboxType = "SKYBOX_V1";
|
|
|
- }
|
|
|
- if(Integer.parseInt(cameraType) == 6){
|
|
|
- //小红屋新双目相机
|
|
|
-// skyboxType = "SKYBOX_V9";
|
|
|
- splitType = "SPLIT_V3";
|
|
|
- skyboxType = "SKYBOX_V7";
|
|
|
- }
|
|
|
-
|
|
|
- if(Integer.parseInt(cameraType) == 13){
|
|
|
- //转台相机
|
|
|
- skyboxType = "SKYBOX_V6";
|
|
|
- splitType = "SPLIT_V12";
|
|
|
- }
|
|
|
-
|
|
|
- if(Integer.parseInt(cameraType) == 14){
|
|
|
- //转台相机
|
|
|
- log.info("激光转台相机调用算法");
|
|
|
- skyboxType = "SKYBOX_V11";
|
|
|
- splitType = "SPLIT_V14";
|
|
|
- }
|
|
|
-
|
|
|
- }else {
|
|
|
- if("sfm".equals(algorithm)){
|
|
|
- splitType = "SPLIT_V2";
|
|
|
- skyboxType = "SKYBOX_V1";
|
|
|
- dataDescribe = "old sfm";
|
|
|
- }else {
|
|
|
- splitType = "SPLIT_V3";
|
|
|
- skyboxType = "SKYBOX_V1";
|
|
|
- dataDescribe = "old slam";
|
|
|
- }
|
|
|
- }
|
|
|
- map.put("splitType", splitType);
|
|
|
- map.put("skyboxType", skyboxType);
|
|
|
- map.put("dataDescribe", dataDescribe);
|
|
|
- return map;
|
|
|
- }
|
|
|
-}
|