eltopo3d/surftrack.cpp
// --------------------------------------------------------
///
/// Delete flaps and zero-area triangles.  Then separate singular vertices.
///
// --------------------------------------------------------
Delete flaps and zero-area triangles.  Then separate singular vertices.
Delete flaps and zero - area triangles . Then separate singular vertices .
void SurfTrack::trim_non_manifold( std::vector<size_t>& triangle_indices )
{   
    if ( false == m_allow_non_manifold )
    {
        for ( size_t i = 0; i < m_mesh.m_edge_to_triangle_map.size(); ++i )
        {
            if ( m_mesh.edge_is_deleted(i) ) { continue; }
            assert( m_mesh.m_edge_to_triangle_map[i].size() == 1 ||
                   m_mesh.m_edge_to_triangle_map[i].size() == 2 );
        }
        triangle_indices.clear();
        return;
    }
    for ( size_t j = 0; j < triangle_indices.size(); ++j )      
    {
        size_t i = triangle_indices[j];
        const Vec3st& current_triangle = m_mesh.get_triangle(i);
        if ( (current_triangle[0] == 0) && (current_triangle[1] == 0) && (current_triangle[2] == 0) ) 
        {
            continue;
        }
         look for triangles with repeated vertices
        if (    (current_triangle[0] == current_triangle[1])
            || (current_triangle[1] == current_triangle[2]) 
            || (current_triangle[2] == current_triangle[0]) )
        {
            if ( m_verbose ) { std::cout << "deleting degenerate triangle " << i << ": " << current_triangle << std::endl; }
             delete it
            remove_triangle( i );
            continue;
        }
         look for flaps
        const Vec3st& tri_edges = m_mesh.m_triangle_to_edge_map[i];
        bool flap_found = false;
        for ( unsigned int e = 0; e < 3 && flap_found == false; ++e )
        {
            const std::vector<size_t>& edge_tris = m_mesh.m_edge_to_triangle_map[ tri_edges[e] ];
            for ( size_t t = 0; t < edge_tris.size(); ++t )
            {
                if ( edge_tris[t] == i )
                {
                    continue;
                }
                size_t other_triangle_index = edge_tris[t];
                const Vec3st& other_triangle = m_mesh.get_triangle( other_triangle_index );
                if (    (other_triangle[0] == other_triangle[1]) 
                    || (other_triangle[1] == other_triangle[2]) 
                    || (other_triangle[2] == other_triangle[0]) ) 
                {
                    continue;
                }
                if ( ((current_triangle[0] == other_triangle[0]) || (current_triangle[0] == other_triangle[1]) || (current_triangle[0] == other_triangle[2])) &&
                    ((current_triangle[1] == other_triangle[0]) || (current_triangle[1] == other_triangle[1]) || (current_triangle[1] == other_triangle[2])) &&
                    ((current_triangle[2] == other_triangle[0]) || (current_triangle[2] == other_triangle[1]) || (current_triangle[2] == other_triangle[2])) ) 
                {
                    if ( false == m_allow_topology_changes )
                    {
                        std::cout << "flap found while topology changes disallowed" << std::endl;
                        std::cout << current_triangle << std::endl;
                        std::cout << other_triangle << std::endl;
                        assert(0);
                    }
                    size_t common_edge = tri_edges[e];
                    if ( m_mesh.oriented( m_mesh.m_edges[common_edge][0], m_mesh.m_edges[common_edge][1], current_triangle ) == 
                        m_mesh.oriented( m_mesh.m_edges[common_edge][0], m_mesh.m_edges[common_edge][1], other_triangle ) )
                    {
                        continue;
                    }
                     the dangling vertex will be safely removed by the vertex cleanup function
                     delete the triangle
                    if ( m_verbose )
                    {
                        std::cout << "flap: triangles << " << i << " [" << current_triangle << 
                        "] and " << edge_tris[t] << " [" << other_triangle << "]" << std::endl;
                    }
                    remove_triangle( i );
                     delete its opposite
                    remove_triangle( other_triangle_index );
                    flap_found = true;
                    break;
                }
            }
        }
    }
    triangle_indices.clear();
}
void SurfTrack :: trim_non_manifold ( std :: vector < size_t > & triangle_indices ) { if ( false == m_allow_non_manifold ) { for ( size_t i = 0 ; i < m_mesh . m_edge_to_triangle_map . size ( ) ; ++ i ) { if ( m_mesh . edge_is_deleted ( i ) ) { continue ; } assert ( m_mesh . m_edge_to_triangle_map [ i ] . size ( ) == 1 || m_mesh . m_edge_to_triangle_map [ i ] . size ( ) == 2 ) ; } triangle_indices . clear ( ) ; return ; } for ( size_t j = 0 ; j < triangle_indices . size ( ) ; ++ j ) { size_t i = triangle_indices [ j ] ; const Vec3st & current_triangle = m_mesh . get_triangle ( i ) ; if ( ( current_triangle [ 0 ] == 0 ) && ( current_triangle [ 1 ] == 0 ) && ( current_triangle [ 2 ] == 0 ) ) { continue ; } if ( ( current_triangle [ 0 ] == current_triangle [ 1 ] ) || ( current_triangle [ 1 ] == current_triangle [ 2 ] ) || ( current_triangle [ 2 ] == current_triangle [ 0 ] ) ) { if ( m_verbose ) { std :: cout << " " << i << " " << current_triangle << std :: endl ; } remove_triangle ( i ) ; continue ; } const Vec3st & tri_edges = m_mesh . m_triangle_to_edge_map [ i ] ; bool flap_found = false ; for ( unsigned int e = 0 ; e < 3 && flap_found == false ; ++ e ) { const std :: vector < size_t > & edge_tris = m_mesh . m_edge_to_triangle_map [ tri_edges [ e ] ] ; for ( size_t t = 0 ; t < edge_tris . size ( ) ; ++ t ) { if ( edge_tris [ t ] == i ) { continue ; } size_t other_triangle_index = edge_tris [ t ] ; const Vec3st & other_triangle = m_mesh . get_triangle ( other_triangle_index ) ; if ( ( other_triangle [ 0 ] == other_triangle [ 1 ] ) || ( other_triangle [ 1 ] == other_triangle [ 2 ] ) || ( other_triangle [ 2 ] == other_triangle [ 0 ] ) ) { continue ; } if ( ( ( current_triangle [ 0 ] == other_triangle [ 0 ] ) || ( current_triangle [ 0 ] == other_triangle [ 1 ] ) || ( current_triangle [ 0 ] == other_triangle [ 2 ] ) ) && ( ( current_triangle [ 1 ] == other_triangle [ 0 ] ) || ( current_triangle [ 1 ] == other_triangle [ 1 ] ) || ( current_triangle [ 1 ] == other_triangle [ 2 ] ) ) && ( ( current_triangle [ 2 ] == other_triangle [ 0 ] ) || ( current_triangle [ 2 ] == other_triangle [ 1 ] ) || ( current_triangle [ 2 ] == other_triangle [ 2 ] ) ) ) { if ( false == m_allow_topology_changes ) { std :: cout << " " << std :: endl ; std :: cout << current_triangle << std :: endl ; std :: cout << other_triangle << std :: endl ; assert ( 0 ) ; } size_t common_edge = tri_edges [ e ] ; if ( m_mesh . oriented ( m_mesh . m_edges [ common_edge ] [ 0 ] , m_mesh . m_edges [ common_edge ] [ 1 ] , current_triangle ) == m_mesh . oriented ( m_mesh . m_edges [ common_edge ] [ 0 ] , m_mesh . m_edges [ common_edge ] [ 1 ] , other_triangle ) ) { continue ; } if ( m_verbose ) { std :: cout << " " << i << " " << current_triangle << " " << edge_tris [ t ] << " " << other_triangle << " " << std :: endl ; } remove_triangle ( i ) ; remove_triangle ( other_triangle_index ) ; flap_found = true ; break ; } } } } triangle_indices . clear ( ) ; }
Delete flaps and zero-area triangles.
Delete flaps and zero - area triangles .
// If we're not allowing non-manifold, assert we don't have any // check for edges incident on more than 2 triangles // // look for triangles with repeated vertices // // delete it // // look for flaps // // the dangling vertex will be safely removed by the vertex cleanup function // delete the triangle // delete its opposite