eltopo3d/dynamicsurface.cpp
// --------------------------------------------------------
///
/// Break up the triangle mesh into connected components, determine surface IDs for all vertices.
///
// --------------------------------------------------------
Break up the triangle mesh into connected components, determine surface IDs for all vertices.
Break up the triangle mesh into connected components determine surface IDs for all vertices .
void DynamicSurface::partition_surfaces( std::vector<size_t>& surface_ids, std::vector< std::vector< size_t> >& surfaces ) const
{
    static const size_t UNASSIGNED = (size_t) ~0;
    surfaces.clear();
    surface_ids.clear();
    surface_ids.resize( get_num_vertices(), UNASSIGNED );
    size_t curr_surface = 0;
    while ( true )
    { 
        size_t next_unassigned_vertex;
        for ( next_unassigned_vertex = 0; next_unassigned_vertex < surface_ids.size(); ++next_unassigned_vertex )
        {
            if ( m_mesh.m_vertex_to_edge_map[next_unassigned_vertex].empty() ) { continue; }
            if ( surface_ids[next_unassigned_vertex] == UNASSIGNED )
            {
                break;
            }
        }
        if ( next_unassigned_vertex == surface_ids.size() )
        {
            break;
        }
        std::queue<size_t> open;
        open.push( next_unassigned_vertex );
        std::vector<size_t> surface_vertices;
        while ( false == open.empty() )
        {
            size_t vertex_index = open.front();
            open.pop();
            if ( m_mesh.m_vertex_to_edge_map[vertex_index].empty() ) { continue; }
            if ( surface_ids[vertex_index] != UNASSIGNED )
            {
                assert( surface_ids[vertex_index] == curr_surface );
                continue;
            }
            surface_ids[vertex_index] = curr_surface;
            surface_vertices.push_back( vertex_index );
            const std::vector<size_t>& incident_edges = m_mesh.m_vertex_to_edge_map[vertex_index];
            for( size_t i = 0; i < incident_edges.size(); ++i )
            {
                size_t adjacent_vertex = m_mesh.m_edges[ incident_edges[i] ][0];
                if ( adjacent_vertex == vertex_index ) { adjacent_vertex = m_mesh.m_edges[ incident_edges[i] ][1]; }
                if ( surface_ids[adjacent_vertex] == UNASSIGNED )
                {
                    open.push( adjacent_vertex );
                }
                else
                {
                    assert( surface_ids[adjacent_vertex] == curr_surface );
                }
            } 
        }
        surfaces.push_back( surface_vertices );
        ++curr_surface;
    }
     assert all vertices are assigned and share volume IDs with their neighbours
    for ( size_t i = 0; i < surface_ids.size(); ++i )
    {
        if ( m_mesh.m_vertex_to_edge_map[i].empty() ) { continue; }
        assert( surface_ids[i] != UNASSIGNED );
        const std::vector<size_t>& incident_edges = m_mesh.m_vertex_to_edge_map[i];    
        for( size_t j = 0; j < incident_edges.size(); ++j )
        {
            size_t adjacent_vertex = m_mesh.m_edges[ incident_edges[j] ][0];
            if ( adjacent_vertex == i ) { adjacent_vertex = m_mesh.m_edges[ incident_edges[j] ][1]; }
            assert( surface_ids[adjacent_vertex] == surface_ids[i] );         
        } 
    }
}
void DynamicSurface :: partition_surfaces ( std :: vector < size_t > & surface_ids , std :: vector < std :: vector < size_t > > & surfaces ) const { static const size_t UNASSIGNED = ( size_t ) ~ 0 ; surfaces . clear ( ) ; surface_ids . clear ( ) ; surface_ids . resize ( get_num_vertices ( ) , UNASSIGNED ) ; size_t curr_surface = 0 ; while ( true ) { size_t next_unassigned_vertex ; for ( next_unassigned_vertex = 0 ; next_unassigned_vertex < surface_ids . size ( ) ; ++ next_unassigned_vertex ) { if ( m_mesh . m_vertex_to_edge_map [ next_unassigned_vertex ] . empty ( ) ) { continue ; } if ( surface_ids [ next_unassigned_vertex ] == UNASSIGNED ) { break ; } } if ( next_unassigned_vertex == surface_ids . size ( ) ) { break ; } std :: queue < size_t > open ; open . push ( next_unassigned_vertex ) ; std :: vector < size_t > surface_vertices ; while ( false == open . empty ( ) ) { size_t vertex_index = open . front ( ) ; open . pop ( ) ; if ( m_mesh . m_vertex_to_edge_map [ vertex_index ] . empty ( ) ) { continue ; } if ( surface_ids [ vertex_index ] != UNASSIGNED ) { assert ( surface_ids [ vertex_index ] == curr_surface ) ; continue ; } surface_ids [ vertex_index ] = curr_surface ; surface_vertices . push_back ( vertex_index ) ; const std :: vector < size_t > & incident_edges = m_mesh . m_vertex_to_edge_map [ vertex_index ] ; for ( size_t i = 0 ; i < incident_edges . size ( ) ; ++ i ) { size_t adjacent_vertex = m_mesh . m_edges [ incident_edges [ i ] ] [ 0 ] ; if ( adjacent_vertex == vertex_index ) { adjacent_vertex = m_mesh . m_edges [ incident_edges [ i ] ] [ 1 ] ; } if ( surface_ids [ adjacent_vertex ] == UNASSIGNED ) { open . push ( adjacent_vertex ) ; } else { assert ( surface_ids [ adjacent_vertex ] == curr_surface ) ; } } } surfaces . push_back ( surface_vertices ) ; ++ curr_surface ; } for ( size_t i = 0 ; i < surface_ids . size ( ) ; ++ i ) { if ( m_mesh . m_vertex_to_edge_map [ i ] . empty ( ) ) { continue ; } assert ( surface_ids [ i ] != UNASSIGNED ) ; const std :: vector < size_t > & incident_edges = m_mesh . m_vertex_to_edge_map [ i ] ; for ( size_t j = 0 ; j < incident_edges . size ( ) ; ++ j ) { size_t adjacent_vertex = m_mesh . m_edges [ incident_edges [ j ] ] [ 0 ] ; if ( adjacent_vertex == i ) { adjacent_vertex = m_mesh . m_edges [ incident_edges [ j ] ] [ 1 ] ; } assert ( surface_ids [ adjacent_vertex ] == surface_ids [ i ] ) ; } } }
Break up the triangle mesh into connected components, determine surface IDs for all vertices.
Break up the triangle mesh into connected components determine surface IDs for all vertices .
// // assert all vertices are assigned and share volume IDs with their neighbours //