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

operator()(...) -> invalid source-mesh connectivity #23

Closed ning2510 closed 1 year ago

ning2510 commented 1 year ago

Hi, I try to read the STL file and then do boolean operations, but it fails. I made a modification on CSGBollean.cpp and below is my code to read STL:

bool read_stl(std::string filename, std::vector<std::vector<double>> &V, std::vector<std::vector<int>> &F) {
    Eigen::MatrixXd V1;
    Eigen::MatrixXi F1;
    igl::read_triangle_mesh(filename, V1, F1);
    for (int i = 0; i < V1.rows(); i++) {
        std::vector<double> tmp;
        for (int j = 0; j < V1.cols(); j++) {
            double x = V1(i, j);
            tmp.push_back(x);
        }
        V.push_back(tmp);
    }

    for (int i = 0; i < F1.rows(); i++) {
        std::vector<int> tmp;
        for (int j = 0; j < F1.cols(); j++) {
            int x = F1(i, j);
            tmp.push_back(x);
        }

        F.push_back(tmp);
    }
    return true;
}

I modified the original code to read stl file:

// original
srcMesh.fpath = user_provided_meshes ? argv[1] : DATA_DIR "/cube.obj";
bool srcMeshLoaded = igl::read_triangle_mesh(srcMesh.fpath, srcMesh.V, srcMesh.F);

// my modified
srcMesh.fpath = user_provided_meshes ? argv[1] : DATA_DIR "/test1.stl";
bool srcMeshLoaded = read_stl(srcMesh.fpath, srcMesh.V, srcMesh.F);

I think the above code for reading STL files should be right.

After that, I perform Boolean operations. When the mcDispatch function is called, its return value is -4, and an error operator()(...) -> invalid source-mesh connectivity is reported.

This problem also happened in #12 . But it didn't solve my problem. In #12 , you separated the skull into its connected components to then cut cranium with a plane. But in fact, I am quite confused about this piece. What rules do you divide according to?

And you said it is because your source mesh (which is likely the skull mesh) has more than one connected component. I don't really get it, can you explain the connection components a bit more, and how do i divide my stl file into individual connected components.

Here is my test file: test_file.zip

chitalu commented 1 year ago

Hi @ning2510

When the mcDispatch function is called ... an error ... is reported

Setup a debug context (see e.g. BasicCmdLineApp tutorial on how to do this).

What rules do you divide according to?

There are no special "rules". Simply ensure that each input mesh is a single connected component.