Sfoglia il codice sorgente

添加dam2obj功能

wuweihao 3 anni fa
parent
commit
f5cc191923

+ 62 - 1
gis_common/src/main/java/com/gis/common/exception/BaseRuntimeException.java

@@ -1,5 +1,10 @@
 package com.gis.common.exception;
 
+import cn.hutool.core.util.StrUtil;
+import org.springframework.util.CollectionUtils;
+
+import java.util.List;
+
 public class BaseRuntimeException extends RuntimeException{
 
     private static final long serialVersionUID = -1518945670203783450L;
@@ -8,15 +13,23 @@ public class BaseRuntimeException extends RuntimeException{
 
     public BaseRuntimeException(String msg){
         super(msg);
+        this.code = -1;
         this.msg = msg;
     }
 
+    /**
+     *
+     * @param code 允许为null
+     * @param msg
+     */
     public BaseRuntimeException(Integer code, String msg){
         super(msg);
-        this.code = code;
+        this.code = code == null? -1 : code;
         this.msg = msg;
     }
 
+
+
     public Integer getCode() {
         return code;
     }
@@ -32,4 +45,52 @@ public class BaseRuntimeException extends RuntimeException{
     public void setMsg(String msg) {
         this.msg = msg;
     }
+
+
+    public static void isNull(Object obj, Integer code, String msg){
+        if (obj == null){
+            getExc(code, msg);
+        }
+    }
+
+    public static void isBlank(Object obj, Integer code, String msg){
+        if (obj == null){
+            getExc(code, msg);
+        }
+
+        if (obj instanceof String && StrUtil.isBlank(obj.toString())){
+            getExc(code, msg);
+        }
+
+    }
+
+
+
+
+
+
+    /**
+     *
+     * @param obj 存在抛异常
+     * @param code 允许为null
+     * @param msg
+     */
+    public static void isTrue(boolean obj, Integer code, String msg){
+        if (obj){
+            getExc(code, msg);
+        }
+    }
+
+    public static void  getExc(Integer code, String msg){
+        throw new BaseRuntimeException(code, msg);
+    }
+
+
+
+    public static void isEmpty(List obj, Integer code, String msg){
+        if (CollectionUtils.isEmpty(obj)){
+            getExc(code, msg);
+        }
+    }
+
 }

+ 10 - 2
gis_common/src/main/java/com/gis/common/proto/util/ConvertUtils.java

@@ -239,8 +239,8 @@ public class ConvertUtils {
 
     @Test
     public void testDam2Txt() throws Exception {
-        String inPath = "F:\\test\\dam\\b\\8a8a10ff38c44a068812cf2f456e6956_50k.dam";
-        String outPath = "F:\\test\\dam\\b\\test.txt";
+        String inPath = "F:\\test\\dam\\6\\8a8a10ff38c44a068812cf2f456e6956_50k.dam";
+        String outPath = "F:\\test\\dam\\6\\modeldata.txt";
         convertDamToTxt(inPath, outPath);
     }
 
@@ -252,6 +252,14 @@ public class ConvertUtils {
     }
 
 
+    @Test
+    public void testTxt2Dam() throws Exception {
+        String inPath = "F:\\test\\dam\\6\\modeldata.txt";
+        String outPath = "F:\\test\\dam\\6\\8a8a10ff38c44a068812cf2f456e6956_50k.dam";
+        convertTxtToDam(inPath, outPath);
+    }
+
+
     public List<List<String>> descartes(List<List<String>> dimValue) {
         List<List<String>> res = new ArrayList<>();
         if (dimValue == null || dimValue.size() == 0)

+ 77 - 0
gis_common/src/main/java/com/gis/common/util/ConvertWinUtils.java

@@ -0,0 +1,77 @@
+package com.gis.common.util;
+
+import cn.hutool.core.io.FileUtil;
+import com.gis.common.exception.BaseRuntimeException;
+import com.gis.common.proto.util.ConvertUtils;
+import lombok.extern.slf4j.Slf4j;
+import org.junit.Test;
+
+
+/**
+ * Created by owen on 2022/6/13 0013 18:08
+ * win版数据转换
+ */
+@Slf4j
+public class ConvertWinUtils {
+
+    /**
+     * dam to obj
+     * by owen 2022-06-14
+     * 测试完成
+     */
+    @Test
+    public void damToObj(){
+
+        String basePath = "D:\\baseData\\";
+        String damPath = basePath + "/dam/79ed9f301626478ab6edf9ffc747e5f8_50k.dam";
+        try {
+            doDamToTxt(damPath, basePath);
+            doTxtToObj(basePath);
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+
+
+    }
+
+    /**
+     * dam to txt
+     */
+    private static void doDamToTxt(String damPath, String basePath) throws Exception {
+        String txtPath = basePath + "txt2obj\\test.txt";
+        // 删除旧text.txt
+        FileUtil.del(txtPath);
+        ConvertUtils.convertDamToTxt2(damPath, txtPath);
+        log.info("处理完成:damToTxt ,  {}",  txtPath);
+        BaseRuntimeException.isTrue(!FileUtil.isFile(txtPath), null, "生成text.txt失败");
+
+    }
+
+    /**
+     * txt to obj
+     * 默认对目录里test.txt 文件转 obj
+     */
+    private static void doTxtToObj(String basePath) {
+        String txt2objDir = basePath + "txt2obj";
+        String txt2objCmd = "python " + basePath + "txt2obj\\run.py " + txt2objDir;
+        String meshObjPath = txt2objDir + "/test.obj";
+        FileUtil.del(meshObjPath);
+        CmdUtils.callLine(txt2objCmd);
+        // 删除旧obj
+        String meshObjMtlPath = txt2objDir + "/test.mtl";
+        if (!FileUtil.exist(meshObjPath)) {
+            throw new BaseRuntimeException("算法生成test.obj失败: " + meshObjPath);
+        }
+        log.info("mesh.obj生成完成");
+
+        // 将mesh.obj、mesh.obj.mtl复制到场景码跟目录
+//        String objPath = basePath + "/test.obj";
+//        String mntPath = basePath + "/test.mtl";
+//        FileUtil.copy(new File(meshObjPath), new File(objPath), true);
+//        FileUtil.copy(new File(meshObjMtlPath), new File(mntPath), true);
+//        log.info("test.obj复制到根目录完成: {}", basePath);
+    }
+
+
+
+}