protected void computeOutput ( ) { outputRegionId . reset ( ) ; outputRegionSizes . reset ( ) ; for ( int y = 0 ; y < graph . height ; y ++ ) { int indexGraph = graph . startIndex + y * graph . stride ; for ( int x = 0 ; x < graph . width ; x ++ , indexGraph ++ ) { int parent = graph . data [ indexGraph ] ; if ( parent == indexGraph ) { outputRegionId . add ( indexGraph ) ; outputRegionSizes . add ( regionSize . get ( indexGraph ) ) ; } else { // find the parent and set the child to it int child = indexGraph ; while ( parent != child ) { child = parent ; parent = graph . data [ child ] ; } graph . data [ indexGraph ] = parent ; } } } }
Searches for root nodes in the graph and adds their size to the list of region sizes . Makes sure all other nodes in the graph point directly at their root .