From a8e4387bdde5a28c5cc8b0faeee04211fff99b63 Mon Sep 17 00:00:00 2001 From: Jane Tournois Date: Tue, 12 Dec 2023 18:01:36 +0100 Subject: [PATCH] factorization of duplicate code --- .../internal/smooth_vertices.h | 94 ++++++------------- 1 file changed, 29 insertions(+), 65 deletions(-) diff --git a/Tetrahedral_remeshing/include/CGAL/Tetrahedral_remeshing/internal/smooth_vertices.h b/Tetrahedral_remeshing/include/CGAL/Tetrahedral_remeshing/internal/smooth_vertices.h index 99f8a89593a..8dfbec6c361 100644 --- a/Tetrahedral_remeshing/include/CGAL/Tetrahedral_remeshing/internal/smooth_vertices.h +++ b/Tetrahedral_remeshing/include/CGAL/Tetrahedral_remeshing/internal/smooth_vertices.h @@ -488,82 +488,46 @@ private: if (!free_vertex[vid]) continue; - if (neighbors[vid] > 1) + Vector_3 final_position; + const Vector_3 current_pos(CGAL::ORIGIN, point(v->point())); + const std::vector& v_surface_indices = vertices_surface_indices.at(v); + const std::size_t count = v_surface_indices.size(); + + const std::size_t nb_neighbors = neighbors[vid]; + + const Vector_3 smoothed_position = (nb_neighbors > 1) + ? smoothed_positions[vid] / static_cast(nb_neighbors) + : current_pos; + + for (const Surface_patch_index& si : v_surface_indices) { - Vector_3 smoothed_position = smoothed_positions[vid] / neighbors[vid]; - Vector_3 final_position = CGAL::NULL_VECTOR; + const Vector_3 projection_vector = (nb_neighbors > 1) + ? project_on_tangent_plane(smoothed_position, current_pos, vertices_normals.at(v).at(si)) + : smoothed_position; - std::size_t count = 0; - const Vector_3 current_pos(CGAL::ORIGIN, point(v->point())); + //Check if the mls surface exists to avoid degenerated cases + std::optional mls_projection = project(si, projection_vector); - const std::vector& v_surface_indices = vertices_surface_indices.at(v); - for (const Surface_patch_index& si : v_surface_indices) - { - Vector_3 normal_projection - = project_on_tangent_plane(smoothed_position, current_pos, vertices_normals.at(v).at(si)); - - //Check if the mls surface exists to avoid degenerated cases - if (std::optional mls_projection = project(si, normal_projection)) { - final_position = final_position + *mls_projection; - } - else { - final_position = final_position + normal_projection; - } - count++; - } - - if (count > 0) - final_position = final_position / static_cast(count); + if (mls_projection != std::nullopt) + final_position = final_position + *mls_projection; else - final_position = smoothed_position; - -#ifdef CGAL_TETRAHEDRAL_REMESHING_DEBUG - os_surf << "2 " << current_pos << " " << final_position << std::endl; -#endif - // move vertex - const typename Tr::Point new_pos(final_position.x(), final_position.y(), final_position.z()); - if (check_inversion_and_move(v, new_pos, inc_cells[vid], tr, total_move)){ -#ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE - nb_done_1d++; -#endif - } + final_position = final_position + projection_vector; } - else if (neighbors[vid] > 0) - { - Vector_3 final_position = CGAL::NULL_VECTOR; - int count = 0; - const Vector_3 current_pos(CGAL::ORIGIN, point(v->point())); - - const std::vector& v_surface_indices = vertices_surface_indices.at(v); - for (const Surface_patch_index& si : v_surface_indices) - { - //Check if the mls surface exists to avoid degenerated cases - - if (std::optional mls_projection = project(si, current_pos)) { - final_position = final_position + *mls_projection; - } - else { - final_position = final_position + current_pos; - } - count++; - } - - if (count > 0) - final_position = final_position / static_cast(count); - else - final_position = current_pos; + if (count > 0) + final_position = final_position / static_cast(count); + else + final_position = smoothed_position; #ifdef CGAL_TETRAHEDRAL_REMESHING_DEBUG - os_surf << "2 " << current_pos << " " << final_position << std::endl; + os_surf << "2 " << current_pos << " " << final_position << std::endl; #endif - // move vertex - const typename Tr::Point new_pos(final_position.x(), final_position.y(), final_position.z()); - if (check_inversion_and_move(v, new_pos, inc_cells[vid], tr, total_move)){ + // move vertex + const typename Tr::Point new_pos(final_position.x(), final_position.y(), final_position.z()); + if (check_inversion_and_move(v, new_pos, inc_cells[vid], tr, total_move)){ #ifdef CGAL_TETRAHEDRAL_REMESHING_VERBOSE - nb_done_1d++; + nb_done_1d++; #endif - } } } }