Commit 10da8cec authored by YIxin-Hu's avatar YIxin-Hu
Browse files

checking boundary

114720: boundary marking
111551: boundary intersection
parent 0e720fc8
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -1500,6 +1500,9 @@ bool floatTetWild::insert_boundary_edges_get_intersecting_edges_and_points(
                  input_vertices[input_faces[n_f_ids.front()][1]],
                  input_vertices[input_faces[n_f_ids.front()][2]]);
    std::array<Vector2, 2> evs_2d = {{to_2d(input_vertices[e[0]], t), to_2d(input_vertices[e[1]], t)}};
    Vector3 n = (input_vertices[input_faces[n_f_ids.front()][1]] - input_vertices[input_faces[n_f_ids.front()][0]]).cross(input_vertices[input_faces[n_f_ids.front()][2]] - input_vertices[input_faces[n_f_ids.front()][0]]);
    n.normalize();
    const Vector3& pp = input_vertices[input_faces[n_f_ids.front()][0]];

    std::vector<bool> is_visited(mesh.tets.size(), false);
    std::queue<int> t_ids_queue;
@@ -1555,9 +1558,12 @@ bool floatTetWild::insert_boundary_edges_get_intersecting_edges_and_points(
            //check tri side of seg
            std::array<int, 3> f_v_ids = {{mesh.tets[t_id][(j + 1) % 4], mesh.tets[t_id][(j + 2) % 4],
                                                  mesh.tets[t_id][(j + 3) % 4]}};
            std::array<Vector2, 3> fvs_2d = {{to_2d(mesh.tet_vertices[f_v_ids[0]].pos, t),
                                                     to_2d(mesh.tet_vertices[f_v_ids[1]].pos, t),
                                                     to_2d(mesh.tet_vertices[f_v_ids[2]].pos, t)}};
//            std::array<Vector2, 3> fvs_2d = {{to_2d(mesh.tet_vertices[f_v_ids[0]].pos, t),
//                                                     to_2d(mesh.tet_vertices[f_v_ids[1]].pos, t),
//                                                     to_2d(mesh.tet_vertices[f_v_ids[2]].pos, t)}};
            std::array<Vector2, 3> fvs_2d = {{to_2d(mesh.tet_vertices[f_v_ids[0]].pos, n, pp, t),
                                                     to_2d(mesh.tet_vertices[f_v_ids[1]].pos, n, pp, t),
                                                     to_2d(mesh.tet_vertices[f_v_ids[2]].pos, n, pp, t)}};
            int cnt_pos = 0;
            int cnt_neg = 0;
            int cnt_on = 0;
@@ -1711,8 +1717,11 @@ bool floatTetWild::insert_boundary_edges_get_intersecting_edges_and_points(
            if (!is_cross(f_oris[i][j], f_oris[i][(j + 1) % 3]))
                continue;

            std::array<Vector2, 2> tri_evs_2d = {{to_2d(mesh.tet_vertices[cut_fs[i][j]].pos, t),
                                                         to_2d(mesh.tet_vertices[cut_fs[i][(j + 1) % 3]].pos, t)}};
//            std::array<Vector2, 2> tri_evs_2d = {{to_2d(mesh.tet_vertices[cut_fs[i][j]].pos, t),
//                                                         to_2d(mesh.tet_vertices[cut_fs[i][(j + 1) % 3]].pos, t)}};
            std::array<Vector2, 2> tri_evs_2d = {{to_2d(mesh.tet_vertices[cut_fs[i][j]].pos, n, pp, t),
                                                         to_2d(mesh.tet_vertices[cut_fs[i][(j + 1) % 3]].pos, n, pp, t)}};

            Scalar t_seg = -1;
            if (seg_line_intersection_2d(tri_evs_2d, evs_2d, t_seg)) {
                std::array<int, 2> tri_e = {{cut_fs[i][j], cut_fs[i][(j + 1) % 3]}};
+29 −0
Original line number Diff line number Diff line
@@ -70,6 +70,29 @@ bool floatTetWild::seg_seg_intersection_2d(const std::array<Vector2, 2> &seg1, c
    return true;
}

floatTetWild::Scalar floatTetWild::seg_seg_squared_dist_3d(const std::array<Vector3, 2> &s1, const std::array<Vector3, 2> &s2) {
    Vector3 w0 = s1[0] - s2[0];
    Vector3 u = (s1[1] - s1[0]).normalized();
    Vector3 v = (s2[1] - s2[0]).normalized();
    Scalar a = u.dot(u);
    Scalar b = u.dot(v);
    Scalar c = v.dot(v);
    Scalar d = u.dot(w0);
    Scalar e = v.dot(w0);

    Scalar dd = a * c - b * b;
    Scalar t1, t2;
    if (dd == 0) {
        t1 = 0;
        t2 = d / b;
    } else {
        t1 = (b * e - c * d) / dd;
        t2 = (a * e - b * d) / dd;
    }

    return (((1 - t1) * s1[0] + t1 * s1[1]) - ((1 - t2) * s2[0] + t2 * s2[1])).squaredNorm();
}

floatTetWild::Scalar floatTetWild::p_line_squared_dist_3d(const Vector3 &v, const Vector3 &a, const Vector3 &b) {
    return ((b - a).cross(a - v)).squaredNorm() / (b - a).squaredNorm();
}
@@ -384,6 +407,12 @@ floatTetWild::Vector2 floatTetWild::to_2d(const Vector3 &p, int t) {
    return Vector2(p[(t + 1) % 3], p[(t + 2) % 3]);
}

floatTetWild::Vector2 floatTetWild::to_2d(const Vector3 &p, const Vector3& n, const Vector3& pp, int t) {
    Scalar dist = n.dot(p - pp);
    Vector3 proj_p = p - dist * n;
    return Vector2(proj_p[(t + 1) % 3], proj_p[(t + 2) % 3]);
}

bool floatTetWild::is_crossing(int s1, int s2) {
    if (s1 == Predicates::ORI_POSITIVE && s2 == Predicates::ORI_NEGATIVE
        || s2 == Predicates::ORI_POSITIVE && s1 == Predicates::ORI_NEGATIVE)
+3 −0
Original line number Diff line number Diff line
@@ -14,6 +14,8 @@ namespace floatTetWild {
    int is_tri_tri_cutted(const std::array<Vector3, 3> &f_tri, const std::array<Vector3, 3> &f_tet,
                          const std::array<int, 3>& oris_tri);

    Scalar seg_seg_squared_dist_3d(const std::array<Vector3, 2> &s1, const std::array<Vector3, 2> &s2);

    Scalar p_seg_squared_dist_3d(const Vector3 &p, const Vector3 &a, const Vector3 &b);
    Scalar p_line_squared_dist_3d(const Vector3 &p, const Vector3 &a, const Vector3 &b);

@@ -28,6 +30,7 @@ namespace floatTetWild {

    int get_t(const Vector3 &p0, const Vector3 &p1, const Vector3 &p2);
    Vector2 to_2d(const Vector3 &p, int t);
    Vector2 to_2d(const Vector3 &p, const Vector3& n, const Vector3& pp, int t);

    bool is_crossing(int s1, int s2);