protected void checkMask(int index) { if( output.data[index] == MASK ) { output.data[index] = currentLabel; fifo.add(index); } }
@Override protected void assignNewToNeighbors(int index) { if( output.data[index+1] >= 0 ) { // (x+1,y) distance.data[index] = 1; fifo.add(index); } else if( output.data[index-1] >= 0 ) { // (x-1,y) distance.data[index] = 1; fifo.add(index); } else if( output.data[index+output.stride] >= 0 ) { // (x,y+1) distance.data[index] = 1; fifo.add(index); } else if( output.data[index-output.stride] >= 0 ) { // (x,y-1) distance.data[index] = 1; fifo.add(index); } }
protected void handleNeighborAssign(int indexTarget, int indexNeighbor) { int regionNeighbor = output.data[indexNeighbor]; int distanceNeighbor = distance.data[indexNeighbor]; // if neighbor has been assigned a region or is WSHED if( regionNeighbor >= 0 && distanceNeighbor < currentDistance ) { int regionTarget = output.data[indexTarget]; // see if the target belongs to an already labeled basin or watershed if( regionNeighbor > 0 ) { if( regionTarget < 0 ) {// if is MASK output.data[indexTarget] = regionNeighbor; } else if( regionTarget == 0 ) { // if it is a watershed only assign to the neighbor value if it would be closer // this is a deviation from what's in the paper. There might be a type-o there or I miss read it if( distanceNeighbor+1 < currentDistance ) { output.data[indexTarget] = regionNeighbor; } } else if( regionTarget != regionNeighbor ) { output.data[indexTarget] = WSHED; } } else if( regionTarget == MASK ) { output.data[indexTarget] = WSHED; } } else if( regionNeighbor == MASK && distanceNeighbor == 0) { distance.data[indexNeighbor] = currentDistance + 1; fifo.add(indexNeighbor); } }
@Override protected void assignNewToNeighbors(int index) { if( output.data[index+1] >= 0 ) { // (x+1,y) distance.data[index] = 1; fifo.add(index); } else if( output.data[index-1] >= 0 ) { // (x-1,y) distance.data[index] = 1; fifo.add(index); } else if( output.data[index+output.stride] >= 0 ) { // (x,y+1) distance.data[index] = 1; fifo.add(index); } else if( output.data[index-output.stride] >= 0 ) { // (x,y-1) distance.data[index] = 1; fifo.add(index); } else if( output.data[index+1+output.stride] >= 0 ) { // (x+1,y+1) distance.data[index] = 1; fifo.add(index); } else if( output.data[index-1+output.stride] >= 0 ) { // (x-1,y+1) distance.data[index] = 1; fifo.add(index); } else if( output.data[index+1-output.stride] >= 0 ) { // (x+1,y-1) distance.data[index] = 1; fifo.add(index); } else if( output.data[index-1-output.stride] >= 0 ) { // (x-1,y-1) distance.data[index] = 1; fifo.add(index); } }
@Test public void get() { CircularQueue_I32 alg = new CircularQueue_I32(2); assertEquals(2,alg.data.length); // easy case alg.add(1); alg.add(2); assertEquals(1,alg.get(0)); assertEquals(2,alg.get(1)); // make there be an offset alg.removeHead(); alg.add(3); assertEquals(2,alg.data.length); // sanity check assertEquals(2,alg.get(0)); assertEquals(3,alg.get(1)); }
assertEquals(3,alg.data.length); alg.add(1); assertEquals(1,alg.data[0]); assertEquals(1,alg.size); alg.add(2); assertEquals(1,alg.data[0]); assertEquals(2,alg.data[1]); alg.add(3); alg.add(4); assertEquals(1,alg.data[0]); assertEquals(2,alg.data[1]); alg.data = new int[]{1,2,3}; alg.size = 3; alg.add(4); assertEquals(2,alg.data[0]); assertEquals(3,alg.data[1]); alg.size = 2; alg.data = new int[3]; alg.add(10); assertEquals(10,alg.data[0]); assertEquals(10,alg.data[0]);
@Test public void isEmpty() { CircularQueue_I32 alg = new CircularQueue_I32(3); assertTrue(alg.isEmpty()); alg.add(5); assertFalse(alg.isEmpty()); alg.removeTail(); assertTrue(alg.isEmpty()); }