@Override
	public void process(List<EllipseRotated_F64> ellipses , List<List<EllipsesIntoClusters.Node>> clusters ) {

		foundGrids.reset();

		for (int i = 0; i < clusters.size(); i++) {
			List<EllipsesIntoClusters.Node> cluster = clusters.get(i);
			int clusterSize = cluster.size();
			if( clusterSize < 2 )
				continue;
			computeNodeInfo(ellipses, cluster);

			// finds all the nodes in the outside of the cluster
			if( !findContour(false) ) {
				if( verbose ) System.out.println("Contour find failed");
				continue;
			}

			// Find corner to start alignment
			NodeInfo corner = selectSeedCorner();
			corner.marked = true;

			boolean ccw = UtilAngle.distanceCCW(direction(corner,corner.right),direction(corner,corner.left)) > Math.PI;

			// find the row and column which the corner is a member of
			List<NodeInfo> cornerRow = findLine(corner,corner.left,clusterSize, null,ccw);
			List<NodeInfo> cornerColumn = findLine(corner,corner.right,clusterSize, null,!ccw);

			if( cornerRow == null || cornerColumn == null ) {
				if( verbose )System.out.println("Corner row/column line find failed");
				continue;
			}

			// Go down the columns and find each of the rows
			List<List<NodeInfo>> gridByRows = new ArrayList<>();
			gridByRows.add( cornerRow );

			boolean failed = false;
			for (int j = 1; j < cornerColumn.size(); j++) {
				List<NodeInfo> prev = gridByRows.get( j - 1);
				NodeInfo seed = cornerColumn.get(j);
				NodeInfo next = selectSeedNext(prev.get(0),prev.get(1), seed,ccw);
				if( next == null ) {
					if( verbose )
						System.out.println("Outer column with a row that has only one element");
					failed = true;
					break;
				}
				List<NodeInfo> row = findLine( seed , next, clusterSize, null,ccw);
				gridByRows.add( row );
			}
			if( failed )
				continue;

			// perform sanity checks
			if( !checkGridSize(gridByRows, cluster.size()) ) {
				if( verbose ) {
					System.out.println("grid size check failed");
					for (int j = 0; j < gridByRows.size(); j++) {
						System.out.println("  row "+gridByRows.get(j).size());
					}
				}
				continue;
			}

			if( checkDuplicates(gridByRows) ) {
				if( verbose ) System.out.println("contains duplicates");
				continue;
			}

			createRegularGrid(gridByRows,foundGrids.grow());
		}
	}
@ Override public void process ( List < EllipseRotated_F64 > ellipses , List < List < EllipsesIntoClusters . Node > > clusters ) { foundGrids . reset ( ) ; for ( int i = 0 ; i < clusters . size ( ) ; i ++ ) { List < EllipsesIntoClusters . Node > cluster = clusters . get ( i ) ; int clusterSize = cluster . size ( ) ; if ( clusterSize < 2 ) continue ; computeNodeInfo ( ellipses , cluster ) ; if ( ! findContour ( false ) ) { if ( verbose ) System . out . println ( "Contour find failed" ) ; continue ; } NodeInfo corner = selectSeedCorner ( ) ; corner . marked = true ; boolean ccw = UtilAngle . distanceCCW ( direction ( corner , corner . right ) , direction ( corner , corner . left ) ) > Math . PI ; List < NodeInfo > cornerRow = findLine ( corner , corner . left , clusterSize , null , ccw ) ; List < NodeInfo > cornerColumn = findLine ( corner , corner . right , clusterSize , null , ! ccw ) ; if ( cornerRow == null || cornerColumn == null ) { if ( verbose ) System . out . println ( "Corner row/column line find failed" ) ; continue ; } List < List < NodeInfo > > gridByRows = new ArrayList < > ( ) ; gridByRows . add ( cornerRow ) ; boolean failed = false ; for ( int j = 1 ; j < cornerColumn . size ( ) ; j ++ ) { List < NodeInfo > prev = gridByRows . get ( j - 1 ) ; NodeInfo seed = cornerColumn . get ( j ) ; NodeInfo next = selectSeedNext ( prev . get ( 0 ) , prev . get ( 1 ) , seed , ccw ) ; if ( next == null ) { if ( verbose ) System . out . println ( "Outer column with a row that has only one element" ) ; failed = true ; break ; } List < NodeInfo > row = findLine ( seed , next , clusterSize , null , ccw ) ; gridByRows . add ( row ) ; } if ( failed ) continue ; if ( ! checkGridSize ( gridByRows , cluster . size ( ) ) ) { if ( verbose ) { System . out . println ( "grid size check failed" ) ; for ( int j = 0 ; j < gridByRows . size ( ) ; j ++ ) { System . out . println ( "  row " + gridByRows . get ( j ) . size ( ) ) ; } } continue ; } if ( checkDuplicates ( gridByRows ) ) { if ( verbose ) System . out . println ( "contains duplicates" ) ; continue ; } createRegularGrid ( gridByRows , foundGrids . grow ( ) ) ; } }
{@inheritDoc}