Browse Source

渲染stl

Gis-Y 9 tháng trước cách đây
mục cha
commit
92e52f81ad

+ 85 - 22
js_ext_comx_ply_io/src/js_ext_comx_ply_io.cc

@@ -776,6 +776,10 @@ string getTypes() { return types; }
 string setArrow1(double x, double y, double z, double nx, double ny, double nz,
 string setArrow1(double x, double y, double z, double nx, double ny, double nz,
     string name, vtkRenderer* renderer, workData* work, int flag, string id);
     string name, vtkRenderer* renderer, workData* work, int flag, string id);
 
 
+
+string generateBrep(string id, string path, workData* work, string path2);
+void callbackMouse(TMouseEvent* event, void* pRawInf);
+bool _init_callback = false; // 未用
 //////////////////////////////////////////////////////////////////////////////////////
 //////////////////////////////////////////////////////////////////////////////////////
 // system pre-define segment, please don't modify the following codes.
 // system pre-define segment, please don't modify the following codes.
 
 
@@ -784,6 +788,39 @@ JS_EXT_DATA_DECLARE()
 // 0x4cc0c89c-0x0090-0x47e3-0xb7-0x63-0xc1-0xaf-0xf1-0xe7-0x99-0x4e
 // 0x4cc0c89c-0x0090-0x47e3-0xb7-0x63-0xc1-0xaf-0xf1-0xe7-0x99-0x4e
 // please don't modify or delete the previous line codes.
 // please don't modify or delete the previous line codes.
 // 渲染ply(目前未用)
 // 渲染ply(目前未用)
+
+#define GENERATEBREPSEX_FUNC_USAGE "generateBrepsEx Usage: comx.ply.generateBrepsEx(/*put your parameters list here*/);"
+JS_EXT_FUNC_BEGIN(generateBrepsEx, 5, GENERATEBREPSEX_FUNC_USAGE)
+{
+    unsigned long long ullVtk = JS_EXT_PARA(unsigned long long, 0);
+    IVtkContext* pVtkContext = (IVtkContext*)((void*)ullVtk);
+
+    unsigned long long ullWorkData = JS_EXT_PARA(unsigned long long, 1);
+    workData* pEntry = (workData*)((void*)ullWorkData);
+    setWorkData(pEntry);
+
+    string id = JS_EXT_PARA(string, 2);
+    string path = JS_EXT_PARA(string, 3);
+    string path_Brep = JS_EXT_PARA(string, 4);
+
+
+    if (!_init_callback) {
+        _init_callback = true;
+        pVtkContext->RegisterMouseListenCallback(callbackMouse);
+    }
+
+    void* pRawRenderer = NULL;
+    pVtkContext->GetRenderer(pRawRenderer);
+
+    vtkRenderer* renderer = (vtkRenderer*)pRawRenderer;
+
+    string res = type_cast<string>(generateBrep(id, path, pEntry, path_Brep));
+
+    JS_EXT_FUNC_ASSIGN_RET(res);
+
+}
+JS_EXT_FUNC_END()
+
 void createAndDisplayPolyData(const std::vector<double> &points,
 void createAndDisplayPolyData(const std::vector<double> &points,
                               const std::vector<double> &normals,
                               const std::vector<double> &normals,
                               const std::vector<int> &triangles,
                               const std::vector<int> &triangles,
@@ -849,7 +886,7 @@ bool isInBounds(double x, double y, double z, double *bound) {
         }
         }
 }
 }
 
 
-bool _init_callback = false; // 未用
+
 // 鼠标响应事件
 // 鼠标响应事件
 void callbackMouse(TMouseEvent *event, void *pRawInf) {
 void callbackMouse(TMouseEvent *event, void *pRawInf) {
 
 
@@ -1248,11 +1285,11 @@ string setArrow1(double x, double y, double z, double nx, double ny, double nz,
         }
         }
         cout << flag << endl;
         cout << flag << endl;
         cout << "高斯点个数size:" << pts.size() << endl;
         cout << "高斯点个数size:" << pts.size() << endl;
+        cout << "id:" << id << endl;
+        cout << "x:" << x << "   y:" << y << "   z:" << z << endl;
+        cout << "nx:" << nx << "   ny:" << ny << "   nz:" << nz << endl;
         if (pts.size() <= 0)
         if (pts.size() <= 0)
         {
         {
-            cout << "id = 1 || size =0"  << endl;
-            cout << "x:" << x << "   y:" << y <<  "   z:" << z << endl;
-            cout<< "nx:" << nx << "   ny:" << ny << "   nz:" << nz << endl;
             string tit = std::to_string(
             string tit = std::to_string(
                 std::sqrt(std::pow(nx, 2) + std::pow(ny, 2) + std::pow(nz, 2)));
                 std::sqrt(std::pow(nx, 2) + std::pow(ny, 2) + std::pow(nz, 2)));
 
 
@@ -1275,7 +1312,7 @@ string setArrow1(double x, double y, double z, double nx, double ny, double nz,
         }
         }
         else
         else
         {
         {
-            cout << "id = 0" << endl;
+            cout << "pts.size > 0" << endl;
             for (int i = 0; i < pts.size(); i++) {
             for (int i = 0; i < pts.size(); i++) {
                 /* if (work->pts[i].id % 2 != 0) {
                 /* if (work->pts[i].id % 2 != 0) {
                          continue;
                          continue;
@@ -2531,11 +2568,13 @@ void OnRenderers(string path, double rate, vtkRenderer *renderer,
 
 
         renderer->RemoveAllViewProps();
         renderer->RemoveAllViewProps();
 
 
-        string pathSTL = path + "/data/locomotive_bogieassembly_sldasm2.stl";
+        string pathSTL = path + "/locomotive_bogieassembly_sldasm2.stl";
+        std::cout << pathSTL << std::endl;
         work->stlReader->SetFileName(pathSTL.c_str());
         work->stlReader->SetFileName(pathSTL.c_str());
         work->stlReader->Update();
         work->stlReader->Update();
         work->targetData = work->stlReader->GetOutput();
         work->targetData = work->stlReader->GetOutput();
-        string pathVTS = path + "/data/postprocess0.vts";
+        string pathVTS = path + "/postprocess0.vts";
+        std::cout << pathVTS << std::endl;
         work->readers->SetFileName(pathVTS.c_str());
         work->readers->SetFileName(pathVTS.c_str());
         work->readers->Update();
         work->readers->Update();
         work->structuredGrid = work->readers->GetOutput();
         work->structuredGrid = work->readers->GetOutput();
@@ -3227,7 +3266,7 @@ void setPostChange(int attribute, vtkRenderer *renderer, postManage *work) {
         }
         }
 }
 }
 // 高斯点,放到pts容器中
 // 高斯点,放到pts容器中
-void setPts(string path, int id, workData *work) {
+void setPts(string path, string id, workData *work) {
         ifstream fs;
         ifstream fs;
         guass p;
         guass p;
         fs.open(path);
         fs.open(path);
@@ -3235,7 +3274,7 @@ void setPts(string path, int id, workData *work) {
         double x, y, z;
         double x, y, z;
         vector<guass> temppts;
         vector<guass> temppts;
         while (fs >> x >> y >> z) {
         while (fs >> x >> y >> z) {
-                p.id = id;
+                p.id = stoi(id);
                 p.pts.x = x;
                 p.pts.x = x;
                 p.pts.y = y;
                 p.pts.y = y;
                 p.pts.z = z;
                 p.pts.z = z;
@@ -3243,7 +3282,8 @@ void setPts(string path, int id, workData *work) {
                 temppts.push_back(p);
                 temppts.push_back(p);
                
                
         }
         }
-        work->newPts[to_string(id)] = temppts;
+        cout << "guass num: " << temppts.size() << endl;
+        work->newPts[id] = temppts;
 
 
         fs.close();
         fs.close();
 }
 }
@@ -3255,19 +3295,38 @@ void printfPts(workData *work) {
                 //    endl;
                 //    endl;
         }
         }
 }
 }
+void ensure_directory(const fs::path& dir) {
+    std::error_code ec;
+    // 如果目标目录不存在,就递归创建所有父目录
+    if (!fs::exists(dir, ec)) {
+        if (!fs::create_directories(dir, ec) || ec) {
+            throw std::runtime_error("Failed to create directory '"
+                + dir.string() + "': " + ec.message());
+        }
+    }
+}
 // 生成brep文件(前处理)
 // 生成brep文件(前处理)
-string generateBrep(int id, string path, workData *work) {
-        string name = path + "/data/brep/face" + to_string(id) + ".brep";
-
-        string guass = path + "/src/guass/demo1.exe " + name + " " + path +
-                       "/data/guass/guass.txt";
+string generateBrep(string id, string path, workData *work, string path2 ) {
+
+        string name = path2 + "face" + id + ".brep";
+        string guassExePath = path + "src/guass/demo1.exe ";
+        string guassTxtPath = path2 + "guass/guass.txt ";
+        fs::path dir = fs::path(path2 + "guass");
+        ensure_directory(dir);
+        std::replace(guassExePath.begin(), guassExePath.end(), '\\', '/');
+        string guass = path + "src/guass/demo1.exe " + name + " " + path2 +
+                       "guass/guass.txt";
+        cout << "namePath: " << name << endl;
+        cout << "guassExePath: " << guassExePath << endl;
+        cout << "guassTxtPath: " << guassTxtPath << endl;
         system(guass.c_str()); // 生成
         system(guass.c_str()); // 生成
 
 
-        setPts(path + "/data/guass/guass.txt", id, work);
+        setPts(guassTxtPath, id, work);
 
 
         return "ok";
         return "ok";
         // printfPts(work);
         // printfPts(work);
 }
 }
+
 // 设置标记-几何-标记
 // 设置标记-几何-标记
 void setMark(double x, double y, double z, double r, double g, double b,
 void setMark(double x, double y, double z, double r, double g, double b,
              double size, string mark, string name, vtkRenderer *renderer,
              double size, string mark, string name, vtkRenderer *renderer,
@@ -6176,8 +6235,9 @@ JS_EXT_FUNC_BEGIN(generateBreps, 4, GENERATEBREPS_FUNC_USAGE) {
         workData *pEntry = (workData *)((void *)ullWorkData);
         workData *pEntry = (workData *)((void *)ullWorkData);
         setWorkData(pEntry);
         setWorkData(pEntry);
 
 
-        int id = JS_EXT_PARA(int, 2);
+        string id = JS_EXT_PARA(string, 2);
         string path = JS_EXT_PARA(string, 3);
         string path = JS_EXT_PARA(string, 3);
+        
 
 
         if (!_init_callback) {
         if (!_init_callback) {
                 _init_callback = true;
                 _init_callback = true;
@@ -6189,9 +6249,9 @@ JS_EXT_FUNC_BEGIN(generateBreps, 4, GENERATEBREPS_FUNC_USAGE) {
 
 
         vtkRenderer *renderer = (vtkRenderer *)pRawRenderer;
         vtkRenderer *renderer = (vtkRenderer *)pRawRenderer;
 
 
-        string res = type_cast<string>(generateBrep(id, path, pEntry));
+        //string res = type_cast<string>(generateBrep(id, path, pEntry));
 
 
-        JS_EXT_FUNC_ASSIGN_RET(res);
+        //JS_EXT_FUNC_ASSIGN_RET(res);
 }
 }
 JS_EXT_FUNC_END()
 JS_EXT_FUNC_END()
 
 
@@ -6343,8 +6403,8 @@ JS_EXT_FUNC_BEGIN(cutters, 8, CUTTERS_FUNC_USAGE) {
         pVtkContext->GetRenderer(pRawRenderer);
         pVtkContext->GetRenderer(pRawRenderer);
         vtkRenderer *renderer = (vtkRenderer *)pRawRenderer;
         vtkRenderer *renderer = (vtkRenderer *)pRawRenderer;
 
 
-        // cutter(x, y, z, xn, yn, zn, renderer, pEntry);
-        plyCutter(x, y, z, xn, yn, zn, renderer, pEntry);
+         cutter(x, y, z, xn, yn, zn, renderer, pEntry);
+        //plyCutter(x, y, z, xn, yn, zn, renderer, pEntry);
 
 
         return Napi::Boolean::From(info.Env(), false);
         return Napi::Boolean::From(info.Env(), false);
 }
 }
@@ -7618,6 +7678,7 @@ JS_EXT_FUNC_BEGIN(setArrows, 11, SETARROWS_FUNC_USAGE) {
         string name = JS_EXT_PARA(string, 8);
         string name = JS_EXT_PARA(string, 8);
         int flag = JS_EXT_PARA(int, 9);
         int flag = JS_EXT_PARA(int, 9);
         string id = JS_EXT_PARA(string, 10);
         string id = JS_EXT_PARA(string, 10);
+        cout << "setArrows_id:" << id << endl;
 
 
         if (!_init_callback) {
         if (!_init_callback) {
                 _init_callback = true;
                 _init_callback = true;
@@ -8011,6 +8072,7 @@ JS_EXT_FUNC_END()
 // following codes.
 // following codes.
 
 
 JS_EXT_ENTRY_BEGIN()
 JS_EXT_ENTRY_BEGIN()
+JS_EXT_ENTRY(generateBrepsEx)
 JS_EXT_ENTRY(RenderEntryToVtlBuffer)
 JS_EXT_ENTRY(RenderEntryToVtlBuffer)
 JS_EXT_ENTRY(RenderAllToGlBuffer)
 JS_EXT_ENTRY(RenderAllToGlBuffer)
 JS_EXT_ENTRY(Clear)
 JS_EXT_ENTRY(Clear)
@@ -8075,7 +8137,8 @@ JS_EXT_ENTRY(OnOpenMeshs)
 JS_EXT_ENTRY(LoadVtpPlys)
 JS_EXT_ENTRY(LoadVtpPlys)
 JS_EXT_ENTRY_END()
 JS_EXT_ENTRY_END()
 
 
-JS_EXT_MAIN_BEGIN(JS_EXT_NS, 62)
+JS_EXT_MAIN_BEGIN(JS_EXT_NS, 63)
+JS_EXT_FUNC_REG(generateBrepsEx)
 JS_EXT_FUNC_REG(RenderEntryToVtlBuffer)
 JS_EXT_FUNC_REG(RenderEntryToVtlBuffer)
 JS_EXT_FUNC_REG(RenderAllToGlBuffer)
 JS_EXT_FUNC_REG(RenderAllToGlBuffer)
 JS_EXT_FUNC_REG(Clear)
 JS_EXT_FUNC_REG(Clear)