Loading src/CutMesh.cpp +12 −5 Original line number Diff line number Diff line Loading @@ -335,6 +335,8 @@ void floatTetWild::CutMesh::expand_new(std::vector<int> &cut_t_ids) { continue; if (!is_snapped[lv_id]) continue; if(is_projected[lv_id]) continue; bool is_in = true; for (int gt_id: mesh.tet_vertices[gv_id].conn_tets) { Loading Loading @@ -422,6 +424,7 @@ void floatTetWild::CutMesh::expand_new(std::vector<int> &cut_t_ids) { is_snapped.push_back(true); else is_snapped.push_back(false); is_projected.push_back(false); } else new_lv_id = map_v_ids[new_gv_id]; t[j] = new_lv_id; Loading Loading @@ -493,17 +496,19 @@ void floatTetWild::CutMesh::expand_new(std::vector<int> &cut_t_ids) { } int floatTetWild::CutMesh::project_to_plane(int input_vertices_size) { is_projected.resize(v_ids.size(), false); int cnt = 0; for (int i = 0; i < is_snapped.size(); i++) { if (!is_snapped[i]) if (!is_snapped[i] || is_projected[i]) continue; if (v_ids[i] < input_vertices_size) continue; Scalar dist = get_to_plane_dist(mesh.tet_vertices[v_ids[i]].pos); if (std::abs(dist) <= 1e-9) { cnt++; continue; } // if (std::abs(dist) <= 1e-9) { // cnt++; // continue; // } Vector3 proj_p = mesh.tet_vertices[v_ids[i]].pos - p_n * dist; // cout << get_to_plane_dist(proj_p) << endl; bool is_snappable = true; Loading @@ -516,9 +521,11 @@ int floatTetWild::CutMesh::project_to_plane(int input_vertices_size) { } if (is_snappable) { mesh.tet_vertices[v_ids[i]].pos = proj_p; is_projected[i] = true; cnt++; } } // cout<<std::count(is_snapped.begin(), is_snapped.end(), true)<<"/"<<cnt<<endl; return cnt; } Loading src/CutMesh.h +1 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ namespace floatTetWild { std::vector<Scalar> to_plane_dists; std::vector<bool> is_snapped; std::vector<bool> is_projected; Mesh &mesh; const Vector3 &p_n; Loading src/EdgeCollapsing.cpp +23 −2 Original line number Diff line number Diff line Loading @@ -102,6 +102,29 @@ void edge_collapsing_aux(Mesh& mesh, const AABBWrapper& tree, std::vector<std::a } #if EC_POSTPROCESS else { // //fortest // int v1_id = v_ids[0]; // int v2_id = v_ids[1]; //// std::vector<int> n12_t_ids; //// set_intersection(tet_vertices[v1_id].conn_tets, tet_vertices[v2_id].conn_tets, n12_t_ids); // // Scalar old_max_quality = 0; // std::vector<Scalar> new_qs; // new_qs.reserve(tet_vertices[v1_id].conn_tets.size()); // for (int t_id:tet_vertices[v1_id].conn_tets) { // if (tets[t_id].quality > old_max_quality) // old_max_quality = tets[t_id].quality; // } // if(old_max_quality>5e9){ // cout<<"resilt = "<<result<<endl; // cout<<"old_max_quality = "<<old_max_quality<<endl; // cout<<"e = "<<v1_id<<" "<<v2_id<<endl; // } // Eigen::MatrixXd V; // Eigen::MatrixXi T; // // //fortest // if(weight<SCALAR_ZERO_2){ // cout<<"len = "<<weight<<" but failed "<<result<<" "<<mesh.is_input_all_inserted<<endl; // //pausee(); Loading Loading @@ -289,8 +312,6 @@ int floatTetWild::collapse_an_edge(Mesh& mesh, int v1_id, int v2_id, const AABBW old_max_quality = tets[t_id].quality; } } // if(old_max_quality>1e10) // is_check_quality = false; for (int t_id:n1_t_ids) { int j = js_n1_t_ids[ii++]; Scalar new_q = get_quality(tet_vertices[v2_id], tet_vertices[tets[t_id][mod4(j + 1)]], Loading src/LocalOperations.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -916,9 +916,8 @@ bool floatTetWild::is_energy_unstable(const std::array<Scalar, 12>& T, Scalar re {{3, 2, 1, 0}}}; Scalar res0; if (std::isinf(res)) res0 = 0; else res0 = res; return true; for (int i = 0; i < combs.size(); i++) { std::array<Scalar, 12> tmp_T; for (int j = 0; j < 4; j++) { Loading @@ -930,7 +929,8 @@ bool floatTetWild::is_energy_unstable(const std::array<Scalar, 12>& T, Scalar re continue; if (res0 == 0) res0 = res1; if (res1 - res0 > 10) // if (res1 - res0 > 10) if (abs(res1 - res0)/res0 > 0.01) return true; } return false; Loading src/MeshImprovement.cpp +36 −7 Original line number Diff line number Diff line Loading @@ -291,11 +291,10 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s double max_energy, avg_energy; double time; untangle(mesh); for (int i = 0; i < ops[0]; i++) { igl_timer.start(); cout << "edge splitting..." << endl; untangle(mesh); edge_splitting(mesh, tree); time = igl_timer.getElapsedTime(); cout << "edge splitting done!" << endl; Loading @@ -314,6 +313,7 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s for (int i = 0; i < ops[1]; i++) { igl_timer.start(); cout << "edge collapsing..." << endl; untangle(mesh); edge_collapsing(mesh, tree); time = igl_timer.getElapsedTime(); cout << "edge collapsing done!" << endl; Loading @@ -332,6 +332,7 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s for (int i = 0; i < ops[2]; i++) { igl_timer.start(); cout << "edge swapping..." << endl; untangle(mesh); edge_swapping(mesh); time = igl_timer.getElapsedTime(); cout << "edge swapping done!" << endl; Loading Loading @@ -475,6 +476,8 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s #include <geogram/points/kd_tree.h> bool floatTetWild::update_scaling_field(Mesh &mesh, Scalar max_energy) { // return false; cout << "updating sclaing field ..." << endl; bool is_hit_min_edge_length = false; Loading @@ -501,6 +504,8 @@ bool floatTetWild::update_scaling_field(Mesh &mesh, Scalar max_energy) { Scalar refine_scale = 0.5; // Scalar min_refine_scale = mesh.epsilon / mesh.ideal_edge_length; Scalar min_refine_scale = mesh.params.min_edge_len_rel; // if(!mesh.is_input_all_inserted)//fortest // min_refine_scale = mesh.params.min_edge_len_rel * 100; const int N = -int(std::log2(min_refine_scale) - 1); std::vector<std::vector<int>> v_ids(N, std::vector<int>()); Loading Loading @@ -601,9 +606,9 @@ void floatTetWild::output_info(Mesh& mesh, const AABBWrapper& tree) { for(auto& v: mesh.tet_vertices){ if(v.is_removed || !v.is_on_boundary) continue; GEO::index_t prev_facet; if (tree.is_out_tmp_b_envelope(v.pos, mesh.params.eps_2, prev_facet)) cout<<"bad b_v"<<endl; // GEO::index_t prev_facet; // if (tree.is_out_tmp_b_envelope(v.pos, mesh.params.eps_2, prev_facet)) // cout<<"bad b_v"<<endl; fout<<v.pos[0]<<" "<<v.pos[1]<<" "<<v.pos[2]<<endl; } fout.close(); Loading Loading @@ -1390,7 +1395,8 @@ void floatTetWild::untangle(Mesh &mesh) { // return; auto &tet_vertices = mesh.tet_vertices; auto &tets = mesh.tets; static const Scalar zero_area = 1e2 * SCALAR_ZERO_2; // static const Scalar zero_area = 1e2 * SCALAR_ZERO_2; static const Scalar zero_area = 1e-10; static const std::vector<std::array<int, 4>> face_pairs = {{{0, 1, 2, 3}}, {{0, 2, 1, 3}}, {{0, 3, 1, 2}}}; Loading @@ -1401,7 +1407,8 @@ void floatTetWild::untangle(Mesh &mesh) { auto &t = tets[t_id]; if (t.is_removed) continue; if (t.quality < 1e10) if (t.quality < 1e7) // if (t.quality < 1e10) continue; int cnt_on_surface = 0; bool has_degenerate_face = false; Loading @@ -1424,6 +1431,19 @@ void floatTetWild::untangle(Mesh &mesh) { if (cnt_on_surface == 0) continue; // //fortest // bool is_output = false; // if(t.is_surface_fs[max_j] != NOT_SURFACE && cnt_on_surface>1 && // std::abs(max_area - areas[(max_j + 1) % 4] - areas[(max_j + 2) % 4] - areas[(max_j + 3) % 4]) < zero_area*10){ // cout<<std::abs(max_area - areas[(max_j + 1) % 4] - areas[(max_j + 2) % 4] - areas[(max_j + 3) % 4])<<endl; // cout<<"zero_area = "<<zero_area<<endl; // cout<<"cnt_on_surface = "<<cnt_on_surface<<endl; // is_output = true; // pausee(); // } // int old_cnt = cnt; // //fortest if (has_degenerate_face) { if (t.is_surface_fs[max_j] != NOT_SURFACE && max_area > zero_area) { for (int j = 0; j < 4; j++) { Loading Loading @@ -1497,6 +1517,15 @@ void floatTetWild::untangle(Mesh &mesh) { } } } // //fortest // if(is_output){ // if(old_cnt!=cnt) { // cout<<"success"<<endl; // pausee(); // } // } // //fortest } cout << "fixed " + std::to_string(cnt) + " tangled element" << endl; } Loading Loading
src/CutMesh.cpp +12 −5 Original line number Diff line number Diff line Loading @@ -335,6 +335,8 @@ void floatTetWild::CutMesh::expand_new(std::vector<int> &cut_t_ids) { continue; if (!is_snapped[lv_id]) continue; if(is_projected[lv_id]) continue; bool is_in = true; for (int gt_id: mesh.tet_vertices[gv_id].conn_tets) { Loading Loading @@ -422,6 +424,7 @@ void floatTetWild::CutMesh::expand_new(std::vector<int> &cut_t_ids) { is_snapped.push_back(true); else is_snapped.push_back(false); is_projected.push_back(false); } else new_lv_id = map_v_ids[new_gv_id]; t[j] = new_lv_id; Loading Loading @@ -493,17 +496,19 @@ void floatTetWild::CutMesh::expand_new(std::vector<int> &cut_t_ids) { } int floatTetWild::CutMesh::project_to_plane(int input_vertices_size) { is_projected.resize(v_ids.size(), false); int cnt = 0; for (int i = 0; i < is_snapped.size(); i++) { if (!is_snapped[i]) if (!is_snapped[i] || is_projected[i]) continue; if (v_ids[i] < input_vertices_size) continue; Scalar dist = get_to_plane_dist(mesh.tet_vertices[v_ids[i]].pos); if (std::abs(dist) <= 1e-9) { cnt++; continue; } // if (std::abs(dist) <= 1e-9) { // cnt++; // continue; // } Vector3 proj_p = mesh.tet_vertices[v_ids[i]].pos - p_n * dist; // cout << get_to_plane_dist(proj_p) << endl; bool is_snappable = true; Loading @@ -516,9 +521,11 @@ int floatTetWild::CutMesh::project_to_plane(int input_vertices_size) { } if (is_snappable) { mesh.tet_vertices[v_ids[i]].pos = proj_p; is_projected[i] = true; cnt++; } } // cout<<std::count(is_snapped.begin(), is_snapped.end(), true)<<"/"<<cnt<<endl; return cnt; } Loading
src/CutMesh.h +1 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ namespace floatTetWild { std::vector<Scalar> to_plane_dists; std::vector<bool> is_snapped; std::vector<bool> is_projected; Mesh &mesh; const Vector3 &p_n; Loading
src/EdgeCollapsing.cpp +23 −2 Original line number Diff line number Diff line Loading @@ -102,6 +102,29 @@ void edge_collapsing_aux(Mesh& mesh, const AABBWrapper& tree, std::vector<std::a } #if EC_POSTPROCESS else { // //fortest // int v1_id = v_ids[0]; // int v2_id = v_ids[1]; //// std::vector<int> n12_t_ids; //// set_intersection(tet_vertices[v1_id].conn_tets, tet_vertices[v2_id].conn_tets, n12_t_ids); // // Scalar old_max_quality = 0; // std::vector<Scalar> new_qs; // new_qs.reserve(tet_vertices[v1_id].conn_tets.size()); // for (int t_id:tet_vertices[v1_id].conn_tets) { // if (tets[t_id].quality > old_max_quality) // old_max_quality = tets[t_id].quality; // } // if(old_max_quality>5e9){ // cout<<"resilt = "<<result<<endl; // cout<<"old_max_quality = "<<old_max_quality<<endl; // cout<<"e = "<<v1_id<<" "<<v2_id<<endl; // } // Eigen::MatrixXd V; // Eigen::MatrixXi T; // // //fortest // if(weight<SCALAR_ZERO_2){ // cout<<"len = "<<weight<<" but failed "<<result<<" "<<mesh.is_input_all_inserted<<endl; // //pausee(); Loading Loading @@ -289,8 +312,6 @@ int floatTetWild::collapse_an_edge(Mesh& mesh, int v1_id, int v2_id, const AABBW old_max_quality = tets[t_id].quality; } } // if(old_max_quality>1e10) // is_check_quality = false; for (int t_id:n1_t_ids) { int j = js_n1_t_ids[ii++]; Scalar new_q = get_quality(tet_vertices[v2_id], tet_vertices[tets[t_id][mod4(j + 1)]], Loading
src/LocalOperations.cpp +4 −4 Original line number Diff line number Diff line Loading @@ -916,9 +916,8 @@ bool floatTetWild::is_energy_unstable(const std::array<Scalar, 12>& T, Scalar re {{3, 2, 1, 0}}}; Scalar res0; if (std::isinf(res)) res0 = 0; else res0 = res; return true; for (int i = 0; i < combs.size(); i++) { std::array<Scalar, 12> tmp_T; for (int j = 0; j < 4; j++) { Loading @@ -930,7 +929,8 @@ bool floatTetWild::is_energy_unstable(const std::array<Scalar, 12>& T, Scalar re continue; if (res0 == 0) res0 = res1; if (res1 - res0 > 10) // if (res1 - res0 > 10) if (abs(res1 - res0)/res0 > 0.01) return true; } return false; Loading
src/MeshImprovement.cpp +36 −7 Original line number Diff line number Diff line Loading @@ -291,11 +291,10 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s double max_energy, avg_energy; double time; untangle(mesh); for (int i = 0; i < ops[0]; i++) { igl_timer.start(); cout << "edge splitting..." << endl; untangle(mesh); edge_splitting(mesh, tree); time = igl_timer.getElapsedTime(); cout << "edge splitting done!" << endl; Loading @@ -314,6 +313,7 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s for (int i = 0; i < ops[1]; i++) { igl_timer.start(); cout << "edge collapsing..." << endl; untangle(mesh); edge_collapsing(mesh, tree); time = igl_timer.getElapsedTime(); cout << "edge collapsing done!" << endl; Loading @@ -332,6 +332,7 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s for (int i = 0; i < ops[2]; i++) { igl_timer.start(); cout << "edge swapping..." << endl; untangle(mesh); edge_swapping(mesh); time = igl_timer.getElapsedTime(); cout << "edge swapping done!" << endl; Loading Loading @@ -475,6 +476,8 @@ void floatTetWild::operation(const std::vector<Vector3> &input_vertices, const s #include <geogram/points/kd_tree.h> bool floatTetWild::update_scaling_field(Mesh &mesh, Scalar max_energy) { // return false; cout << "updating sclaing field ..." << endl; bool is_hit_min_edge_length = false; Loading @@ -501,6 +504,8 @@ bool floatTetWild::update_scaling_field(Mesh &mesh, Scalar max_energy) { Scalar refine_scale = 0.5; // Scalar min_refine_scale = mesh.epsilon / mesh.ideal_edge_length; Scalar min_refine_scale = mesh.params.min_edge_len_rel; // if(!mesh.is_input_all_inserted)//fortest // min_refine_scale = mesh.params.min_edge_len_rel * 100; const int N = -int(std::log2(min_refine_scale) - 1); std::vector<std::vector<int>> v_ids(N, std::vector<int>()); Loading Loading @@ -601,9 +606,9 @@ void floatTetWild::output_info(Mesh& mesh, const AABBWrapper& tree) { for(auto& v: mesh.tet_vertices){ if(v.is_removed || !v.is_on_boundary) continue; GEO::index_t prev_facet; if (tree.is_out_tmp_b_envelope(v.pos, mesh.params.eps_2, prev_facet)) cout<<"bad b_v"<<endl; // GEO::index_t prev_facet; // if (tree.is_out_tmp_b_envelope(v.pos, mesh.params.eps_2, prev_facet)) // cout<<"bad b_v"<<endl; fout<<v.pos[0]<<" "<<v.pos[1]<<" "<<v.pos[2]<<endl; } fout.close(); Loading Loading @@ -1390,7 +1395,8 @@ void floatTetWild::untangle(Mesh &mesh) { // return; auto &tet_vertices = mesh.tet_vertices; auto &tets = mesh.tets; static const Scalar zero_area = 1e2 * SCALAR_ZERO_2; // static const Scalar zero_area = 1e2 * SCALAR_ZERO_2; static const Scalar zero_area = 1e-10; static const std::vector<std::array<int, 4>> face_pairs = {{{0, 1, 2, 3}}, {{0, 2, 1, 3}}, {{0, 3, 1, 2}}}; Loading @@ -1401,7 +1407,8 @@ void floatTetWild::untangle(Mesh &mesh) { auto &t = tets[t_id]; if (t.is_removed) continue; if (t.quality < 1e10) if (t.quality < 1e7) // if (t.quality < 1e10) continue; int cnt_on_surface = 0; bool has_degenerate_face = false; Loading @@ -1424,6 +1431,19 @@ void floatTetWild::untangle(Mesh &mesh) { if (cnt_on_surface == 0) continue; // //fortest // bool is_output = false; // if(t.is_surface_fs[max_j] != NOT_SURFACE && cnt_on_surface>1 && // std::abs(max_area - areas[(max_j + 1) % 4] - areas[(max_j + 2) % 4] - areas[(max_j + 3) % 4]) < zero_area*10){ // cout<<std::abs(max_area - areas[(max_j + 1) % 4] - areas[(max_j + 2) % 4] - areas[(max_j + 3) % 4])<<endl; // cout<<"zero_area = "<<zero_area<<endl; // cout<<"cnt_on_surface = "<<cnt_on_surface<<endl; // is_output = true; // pausee(); // } // int old_cnt = cnt; // //fortest if (has_degenerate_face) { if (t.is_surface_fs[max_j] != NOT_SURFACE && max_area > zero_area) { for (int j = 0; j < 4; j++) { Loading Loading @@ -1497,6 +1517,15 @@ void floatTetWild::untangle(Mesh &mesh) { } } } // //fortest // if(is_output){ // if(old_cnt!=cnt) { // cout<<"success"<<endl; // pausee(); // } // } // //fortest } cout << "fixed " + std::to_string(cnt) + " tangled element" << endl; } Loading