@@ -634,6 +634,12 @@ void C0Polyhedron::retriangulate()
634634 local_tet_quality [jplus ]);
635635 // Count number of bad neighbors
636636 auto num_bad_neigh_best = (local_tet_quality [jminus ] <= 0 ) + (local_tet_quality [jplus ] <= 0 );
637+ // Skip our heuristics if we are considering a bad tet
638+ if (local_tet_quality [jbest ] == -1e6 )
639+ {
640+ num_bad_neigh_best = 0 ;
641+ qneighbest = 1e6 ;
642+ }
637643
638644 // Count the number of valid surrounding nodes
639645 unsigned int n_valid_surrounding = 0 ;
@@ -642,7 +648,7 @@ void C0Polyhedron::retriangulate()
642648 n_valid_surrounding ++ ;
643649
644650 bool bad_future_neighbors = false;
645- if (local_tet_quality_of (jminus , /*without*/ jbest ) <= 0 &&
651+ if (( n_valid_surrounding > 3 ) && local_tet_quality_of (jminus , /*without*/ jbest ) <= 0 &&
646652 local_tet_quality_of (jplus , /*without*/ jbest ) <= 0 )
647653 bad_future_neighbors = true;
648654
@@ -666,8 +672,9 @@ void C0Polyhedron::retriangulate()
666672
667673 // Avoid chosing a tet that when constructed would leave both neighbors in bad shape
668674 // TODO: simply pre-compute that for every vertex and exclude those nodes
669- if (local_tet_quality_of (jminus , /*without*/ j ) <= 0 &&
670- local_tet_quality_of (jplus , /*without*/ j ) <= 0 )
675+ // Note: It does not matter if we are down to 3 surrounding nodes, as we are building the final tet
676+ if ((n_valid_surrounding > 3 ) && local_tet_quality_of (jminus , /*without*/ j ) <= 0 &&
677+ local_tet_quality_of (jplus , /*without*/ j ) <= 0 )
671678 continue ;
672679
673680 const auto num_bad_neigh = (local_tet_quality [jminus ] <= 0 ) +
@@ -676,9 +683,10 @@ void C0Polyhedron::retriangulate()
676683 // - The more bad (volume <= 0) neighbors we fix the better
677684 // - If same number of bad neighbors, pick best quality one
678685 // - If the current pick for best tet will make the two neighbor tets bad,
679- // don't keep it
680- if (((num_bad_neigh >= num_bad_neigh_best ) &&
681- ((local_tet_quality [j ] - qneighj ) > (local_tet_quality [jbest ] - qneighj )))
686+ // don't keep it and always try another
687+ if (((num_bad_neigh > num_bad_neigh_best ) || ((num_bad_neigh == num_bad_neigh_best )
688+ && ((local_tet_quality [j ] - qneighj ) >
689+ (local_tet_quality [jbest ] - qneighj ))))
682690 || bad_future_neighbors )
683691 {
684692 jbest = j ;
0 commit comments