public void pruneUnusedCameras ( ) { // Count how many views are used by each camera int histogram [ ] = new int [ structure . cameras . length ] ; for ( int i = 0 ; i < structure . views . length ; i ++ ) { histogram [ structure . views [ i ] . camera ] ++ ; } // See which cameras need to be removed and create a look up table from old to new camera IDs int oldToNew [ ] = new int [ structure . cameras . length ] ; List < SceneStructureMetric . Camera > remaining = new ArrayList <> ( ) ; for ( int i = 0 ; i < structure . cameras . length ; i ++ ) { if ( histogram [ i ] > 0 ) { oldToNew [ i ] = remaining . size ( ) ; remaining . add ( structure . cameras [ i ] ) ; } } // Create the new camera array without the unused cameras structure . cameras = new SceneStructureMetric . Camera [ remaining . size ( ) ] ; for ( int i = 0 ; i < remaining . size ( ) ; i ++ ) { structure . cameras [ i ] = remaining . get ( i ) ; } // Update the references to the cameras for ( int i = 0 ; i < structure . views . length ; i ++ ) { SceneStructureMetric . View v = structure . views [ i ] ; v . camera = oldToNew [ v . camera ] ; } }
Prunes cameras that are not referenced by any views .