/** * Creates a queue with the specified length as its size filled with all zeros */ public static GrowQueue_I32 zeros( int length ) { GrowQueue_I32 out = new GrowQueue_I32(length); out.size = length; return out; }
public WatershedVincentSoille1991() { for( int i = 0; i < histogram.length; i++ ) { histogram[i] = new GrowQueue_I32(); } }
/** * Creates a queue with the specified length as its size filled with all zeros */ public static GrowQueue_I32 zeros( int length ) { GrowQueue_I32 out = new GrowQueue_I32(length); out.size = length; return out; }
@Override public GrowQueue_I32 copy() { GrowQueue_I32 ret = new GrowQueue_I32(size); ret.setTo(this); return ret; }
@Override public GrowQueue_I32 copy() { GrowQueue_I32 ret = new GrowQueue_I32(size); ret.setTo(this); return ret; }
@Override public GrowQueue_I32 declare(int maxsize) { return new GrowQueue_I32(maxsize); }
@SuppressWarnings("unchecked") @Override public void setPoints(List<double[]> points, boolean trackIndicies) { // Make a copy because we mutate the lists this.items = points.toArray(new double[0][]); this.indexes = new GrowQueue_I32(); indexes.resize(points.size()); for (int i = 0; i < points.size(); i++) { indexes.data[i] = i; } this.root = buildFromPoints(0, items.length); }
@SuppressWarnings("unchecked") @Override public void setPoints(List<double[]> points, boolean trackIndicies) { // Make a copy because we mutate the lists this.items = points.toArray(new double[0][]); this.indexes = new GrowQueue_I32(); indexes.resize(points.size()); for (int i = 0; i < points.size(); i++) { indexes.data[i] = i; } this.root = buildFromPoints(0, items.length); }
@Test public void findClosestN_zero() { List<double[]> list = new ArrayList<double[]>(); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{1, 2}, 10, 5, outputIndex, outputDistance); assertEquals(0,outputIndex.size); assertEquals(0,outputDistance.size); }
@Test public void auto_grow() { GrowQueue_I32 alg = new GrowQueue_I32(3); assertEquals(3,alg.data.length); for( int i = 0; i < 10; i++ ) alg.push(i); assertEquals(10,alg.size); for( int i = 0; i < 10; i++ ) assertEquals(i,alg.get(i),1e-8); }
@Test public void push_pop() { GrowQueue_I32 alg = new GrowQueue_I32(10); alg.push(1); alg.push(3); assertEquals(2,alg.size); assertTrue(3==alg.pop()); assertTrue(1==alg.pop()); assertEquals(0, alg.size); }
@Test public void indexOf() { GrowQueue_I32 alg = new GrowQueue_I32(10); alg.push(1); alg.push(3); alg.push(4); alg.push(3); assertEquals(1,alg.indexOf(3)); assertEquals(-1,alg.indexOf(8)); }
@Test public void reset() { GrowQueue_I32 alg = new GrowQueue_I32(10); alg.push(1); alg.push(3); alg.push(-2); assertTrue(1.0 == alg.get(0)); assertEquals(3,alg.size); alg.reset(); assertEquals(0,alg.size); }
@Test public void findClosestN_standard() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4 , 4,5, 6,7 , 8,9 ); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{4.1, 4.9}, 10, 3, outputIndex, outputDistance); assertEquals(3,outputIndex.size); assertEquals(3,outputDistance.size); checkContains(1,outputIndex); checkContains(2,outputIndex); checkContains(3,outputIndex); }
@Test public void remove_one() { GrowQueue_I32 alg = new GrowQueue_I32(10); alg.push(1); alg.push(3); alg.push(4); alg.push(5); alg.remove(1); assertEquals(3,alg.size); assertEquals(1,alg.get(0)); assertEquals(4,alg.get(1)); assertEquals(5,alg.get(2)); }
/** * Request more inliers than there are */ @Test public void findClosestN_toomany() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{1, 2}, 10, 5, outputIndex, outputDistance); assertEquals(2,outputIndex.size); assertEquals(2,outputDistance.size); assertEquals(0,outputIndex.get(0)); assertEquals(1,outputIndex.get(1)); }
/** * Request more inliers than there are within the allowed distance */ @Test public void findClosestN_toomany_distance() { List<double[]> list = TestKdTreeConstructor.createPoints(2, 1,2, 3,4); ExhaustiveNeighbor<double[]> alg = new ExhaustiveNeighbor<>(distance); alg.setPoints(list); GrowQueue_I32 outputIndex = new GrowQueue_I32(); GrowQueue_F64 outputDistance = new GrowQueue_F64(); alg.findClosestN(new double[]{1, 2}, 0.1, 5, outputIndex, outputDistance); assertEquals(1,outputIndex.size); assertEquals(1,outputDistance.size); assertEquals(0,outputIndex.get(0)); assertEquals(0,outputDistance.get(0),1e-8); }
@Test public void removeHead() { GrowQueue_I32 alg = new GrowQueue_I32(10); alg.push(1); alg.push(3); alg.push(4); alg.push(5); alg.removeHead(0); assertEquals(4,alg.size); assertEquals(1,alg.get(0)); alg.removeHead(2); assertEquals(2,alg.size); assertEquals(4,alg.get(0)); }
@Test public void sort() { GrowQueue_I32 alg = new GrowQueue_I32(6); alg.push(8); alg.push(2); alg.push(4); alg.push(3); alg.sort(); assertEquals(4,alg.size); assertEquals(2,alg.get(0)); assertEquals(3,alg.get(1)); assertEquals(4,alg.get(2)); assertEquals(8,alg.get(3)); }
@Test public void getFraction() { GrowQueue_I32 alg = new GrowQueue_I32(20); for (int i = 0; i < 20; i++) { alg.add(i); } assertEquals(0,alg.getFraction(0.0)); assertEquals(0,alg.getFraction(0.02)); assertEquals(0,alg.getFraction(0.03)); assertEquals(1,alg.getFraction(1.0/19.0)); assertEquals(1,alg.getFraction(1.7/19.0)); assertEquals(19/2,alg.getFraction(0.5)); assertEquals(19,alg.getFraction(1.0)); } }