Commit a131f1d1 authored by Teseo Schneider's avatar Teseo Schneider
Browse files

using input surace for boolean operations filtering

parent d416e161
Loading
Loading
Loading
Loading
+62 −10
Original line number Diff line number Diff line
@@ -1376,7 +1376,9 @@ void floatTetWild::correct_tracked_surface_orientation(Mesh &mesh, AABBWrapper&
    }
}

void floatTetWild::boolean_operation(Mesh& mesh, const json &csg_tree_with_ids){

void floatTetWild::boolean_operation(Mesh& mesh, const json& csg_tree_with_ids, const std::vector<std::string> &meshes)
{
    Eigen::MatrixXd C(mesh.get_t_num(), 3);
    C.setZero();
    int index = 0;
@@ -1390,20 +1392,70 @@ void floatTetWild::boolean_operation(Mesh& mesh, const json &csg_tree_with_ids){
    }

    int max_id = CSGTreeParser::get_max_id(csg_tree_with_ids);
    std::vector<Eigen::VectorXd> w(max_id + 1);

    if(meshes.empty())
    {
        Eigen::Matrix<Scalar, Eigen::Dynamic, 3> vs;
        Eigen::Matrix<int, Eigen::Dynamic, 3>    fs;

    std::vector<Eigen::VectorXd> w(max_id+1);

        for (int i = 0; i <= max_id; ++i) {
            get_tracked_surface(mesh, vs, fs, i);

            if (!mesh.params.use_general_wn)
        floatTetWild::fast_winding_number(Eigen::MatrixXd(vs.cast<double>()), Eigen::MatrixXi(fs), C, w[i]);
                floatTetWild::fast_winding_number(
                  Eigen::MatrixXd(vs.cast<double>()), Eigen::MatrixXi(fs), C, w[i]);
            else
        igl::winding_number(Eigen::MatrixXd(vs.cast<double>()), Eigen::MatrixXi(fs), C, w[i]);
                igl::winding_number(
                  Eigen::MatrixXd(vs.cast<double>()), Eigen::MatrixXi(fs), C, w[i]);
        }
    }
    else {
        std::vector<std::vector<Vector3>>  Vs;
        std::vector<std::vector<Vector3i>> Fs;

        Vs.resize(meshes.size());
        Fs.resize(meshes.size());

        GEO::Mesh        tmp_mesh;
        std::vector<int> tmp_tags;

        for (int i = 0; i < meshes.size(); ++i) {
            const auto& m = meshes[i];
            if (!MeshIO::load_mesh(m, Vs[i], Fs[i], tmp_mesh, tmp_tags)) {
                logger().error("unable to open {} file", m);
                return;
            }
        }

        for (int i = 0; i <= max_id; ++i) {
            Eigen::Matrix<Scalar, Eigen::Dynamic, 3> vs(Vs[i].size(), 3);
            Eigen::Matrix<int, Eigen::Dynamic, 3>    fs(Fs[i].size(), 3);
            for (int k = 0; k < vs.rows(); ++k)
                vs.row(k) = Vs[i][k];
            for (int k = 0; k < fs.rows(); ++k)
                fs.row(k) = Fs[i][k];

            if (!mesh.params.use_general_wn)
                floatTetWild::fast_winding_number(
                  Eigen::MatrixXd(vs.cast<double>()), Eigen::MatrixXi(fs), C, w[i]);
            else
                igl::winding_number(
                  Eigen::MatrixXd(vs.cast<double>()), Eigen::MatrixXi(fs), C, w[i]);
        }
    }

    boolean_operation(mesh, csg_tree_with_ids, w);
}

void floatTetWild::boolean_operation(Mesh& mesh, const json &csg_tree_with_ids){
    boolean_operation(mesh, csg_tree_with_ids, std::vector<std::string>());
}

void floatTetWild::boolean_operation(Mesh& mesh, const json &csg_tree_with_ids, const std::vector<Eigen::VectorXd> &w)
{
    int max_id = CSGTreeParser::get_max_id(csg_tree_with_ids);

    int cnt = 0;
    for (int t_id = 0; t_id < mesh.tets.size(); ++t_id) {
+2 −0
Original line number Diff line number Diff line
@@ -28,6 +28,8 @@ namespace floatTetWild {
    void correct_tracked_surface_orientation(Mesh &mesh, AABBWrapper& tree);
    void get_tracked_surface(Mesh& mesh, Eigen::Matrix<Scalar, Eigen::Dynamic, 3> &V, Eigen::Matrix<int, Eigen::Dynamic, 3> &F, int c_id = 0);
    void boolean_operation(Mesh& mesh, int op);
    void boolean_operation(Mesh& mesh, const json& csg_tree_with_ids, const std::vector<std::string> &meshes);
    void boolean_operation(Mesh& mesh, const json &csg_tree_with_ids, const std::vector<Eigen::VectorXd> &w);
    void boolean_operation(Mesh& mesh, const json &csg_tree_with_ids);
    void filter_outside(Mesh& mesh, bool invert_faces = false);
    void filter_outside_floodfill(Mesh& mesh, bool invert_faces = false);
+5 −3
Original line number Diff line number Diff line
@@ -296,6 +296,8 @@ int main(int argc, char **argv) {
    GEO::Mesh sf_mesh;
    json tree_with_ids;

    std::vector<std::string> meshes;

    if(!csg_file.empty())
    {
        json csg_tree = json({});
@@ -310,12 +312,12 @@ int main(int argc, char **argv) {
        }
		file.close();

        std::vector<std::string> meshes;

        CSGTreeParser::get_meshes(csg_tree, meshes, tree_with_ids);

        if(!CSGTreeParser::load_and_merge(meshes, input_vertices, input_faces, sf_mesh, input_tags))
            return EXIT_FAILURE;

        // To disable the recent modification of using input for wn, use meshes.clear();
    }
    else{
        if (!MeshIO::load_mesh(params.input_path, input_vertices, input_faces, sf_mesh, input_tags)) {
@@ -421,7 +423,7 @@ int main(int argc, char **argv) {
    correct_tracked_surface_orientation(mesh, tree);
    logger().info("correct_tracked_surface_orientation done");
    if(!csg_file.empty())
        boolean_operation(mesh, tree_with_ids);
        boolean_operation(mesh, tree_with_ids, meshes);
    else if(boolean_op >= 0)
        boolean_operation(mesh, boolean_op);
    else {