cutdigital / mcut

A library for detecting and resolving intersections between two surface meshes.
https://cutdigital.github.io/mcut.site
Other
395 stars 69 forks source link

How can we do a cut with STL file ? #2

Closed onuralpszr closed 2 years ago

onuralpszr commented 2 years ago

I read STL file via "libigl STL read" but how can I do a proper cut because, when I read with STL file and convert Eigen matrix into vectors it can't cut it. After I convert the Eigen Matrix it still gives me error code "-4" and not do a cut until I convert them into obj via blender then it does do the cut.

My conversion snippet code is;

` // V is "MatrixXd" and F is "MatrixXi"

 for (int i = 0; i < V.rows(); ++i)
 {
     std::vector<double> v1;
     //std::cout << i << " : " << V.row(i)(0) << " " << V.row(i)(1) << " " << V.row(i)(2) << "\n";

     v1.push_back(V.row(i)(0));
     v1.push_back(V.row(i)(1));
     v1.push_back(V.row(i)(2));
     // index 0 ---| -> [0]
     //            | -> [1]
     //            | -> [2]
     srcMesh.mcutVertices.push_back(v1);
 }
 for (int i = 0; i < F.rows(); ++i)
 {
     std::vector<int> v1;
     //std::cout << i << " : " << F.row(i)(0) << " " << F.row(i)(1) << " " << F.row(i)(2) << "\n";

     v1.push_back(F.row(i)(0));
     v1.push_back(F.row(i)(1));
     v1.push_back(F.row(i)(2));
     srcMesh.mcutFaces.push_back(v1);
 }

 // copy vertices
 for (int i = 0; i < (int)srcMesh.mcutVertices.size(); ++i)
 {
     const std::vector<double>& v = srcMesh.mcutVertices[i];
     my_assert(v.size() == 3);
     srcMesh.vertexCoordsArray.push_back(v[0]);
     srcMesh.vertexCoordsArray.push_back(v[1]);
     srcMesh.vertexCoordsArray.push_back(v[2]);
 }

 // copy faces
 for (int i = 0; i < (int)srcMesh.mcutFaces.size(); ++i)
 {
     const std::vector<int>& f = srcMesh.mcutFaces[i];
     for (int j = 0; j < (int)f.size(); ++j)
     {
         srcMesh.faceIndicesArray.push_back(f[j]);
     }

     srcMesh.faceSizesArray.push_back((uint32_t)f.size());
 }

`

chitalu commented 2 years ago

Hi,

Your code appears fine but for one detail, which is that the second for-loop assumes that each face is defined with exactly 3 vertices. This will be a problem e.g. if your input .stl file does not represent a triangle mesh.

I also recommend that you enable debug mode, which you can do while creating an mcut context. This will enable logging.

onuralpszr commented 2 years ago

How may I enable that debug mode ? Any pointer ?

onuralpszr commented 2 years ago

Hi,

Your code appears fine but for one detail, which is that the second for-loop assumes that each face is defined with exactly 3 vertices. This will be a problem e.g. if your input .stl file does not represent a triangle mesh.

I also recommend that you enable debug mode, which you can do while creating an mcut context. This will enable logging.

  • Floyd

I enabled debug mode but still can't see much of it. I know that error code is "-4" but that's it. I had to debug myself to find each step where is the crash point.

onuralpszr commented 2 years ago

Actual error was;

ctxtPtr->log(McDebugSource::MC_DEBUG_SOURCE_API, McDebugType::MC_DEBUG_TYPE_ERROR, 0, McDebugSeverity::MC_DEBUG_SEVERITY_HIGH, "found duplicate vertex in face - " + std::to_string(i));

chitalu commented 2 years ago

For more information about debugging, see the tutorial page here.