/** * Gets the value at the index which corresponds to the specified fraction * @param fraction 0 to 1 inclusive * @return value at fraction */ public float getFraction( double fraction ) { return get( (int)((size-1)*fraction) ); }
@Override public GrowQueue_F32 copy() { GrowQueue_F32 ret = new GrowQueue_F32(size); ret.setTo(this); return ret; }
@Test public void addAll_queue() { GrowQueue_F32 queue0 = new GrowQueue_F32(2); GrowQueue_F32 queue1 = new GrowQueue_F32(3); queue0.add(1); queue0.add(2); queue1.add(3); queue1.add(4); queue1.add(5); assertEquals(2,queue0.size); queue0.addAll(queue1); assertEquals(5,queue0.size); for( int i = 0; i < queue0.size; i++ ) { assertEquals(queue0.get(i),i+1,1e-5); } queue0.reset(); queue0.addAll(queue1); assertEquals(3,queue0.size); for( int i = 0; i < queue0.size; i++ ) { assertEquals(queue0.get(i),i+3,1e-5); } }
@Test public void auto_grow() { GrowQueue_F32 alg = new GrowQueue_F32(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-4f); }
@Override public void addCloud(List<Point3D_F64> cloud) { GrowQueue_F32 fcloud = new GrowQueue_F32(); fcloud.resize(cloud.size()*3); int fidx = 0; for (int i = 0; i < cloud.size(); i++) { Point3D_F64 p = cloud.get(i); fcloud.data[fidx++]=(float)p.x; fcloud.data[fidx++]=(float)p.y; fcloud.data[fidx++]=(float)p.z; } Platform.runLater(()->panel.addCloud(fcloud)); }
@Test public void indexOfLeast() { GrowQueue_F32 alg = new GrowQueue_F32(20); assertEquals(-1,alg.indexOfLeast()); alg.add(-3); alg.add(-2); alg.add(-4); assertEquals(2, alg.indexOfLeast()); } }
@Test public void indexOfGreatest() { GrowQueue_F32 alg = new GrowQueue_F32(20); assertEquals(-1,alg.indexOfGreatest()); alg.add(-3); alg.add(-2); alg.add(-1); assertEquals(2, alg.indexOfGreatest()); }
@Test public void push_pop() { GrowQueue_F32 alg = new GrowQueue_F32(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 getFraction() { GrowQueue_F32 alg = new GrowQueue_F32(20); for (int i = 0; i < 20; i++) { alg.add(i); } assertEquals(0,alg.getFraction(0.0), UtilEjml.TEST_F32); assertEquals(0,alg.getFraction(0.02), UtilEjml.TEST_F32); assertEquals(0,alg.getFraction(0.03), UtilEjml.TEST_F32); assertEquals(1,alg.getFraction(1.0/19.0), UtilEjml.TEST_F32); assertEquals(1,alg.getFraction(1.7/19.0), UtilEjml.TEST_F32); assertEquals(19/2,alg.getFraction(0.5), UtilEjml.TEST_F32); assertEquals(19,alg.getFraction(1.0), UtilEjml.TEST_F32); }
/** * Searches for local maximas and converts into lines. * * @return Found lines in the image. */ public FastQueue<LineParametric2D_F32> extractLines() { lines.reset(); foundLines.reset(); foundIntensity.reset(); extractor.process(transform,null, candidates,null, foundLines); for( int i = 0; i < foundLines.size(); i++ ) { Point2D_I16 p = foundLines.get(i); int x0 = p.x - originX; int y0 = p.y - originY; if( Math.abs(x0) >= minDistanceFromOrigin || Math.abs(y0) >= minDistanceFromOrigin ) { LineParametric2D_F32 l = lines.grow(); l.p.set(p.x,p.y); l.slope.set(-y0,x0); foundIntensity.push(transform.get(p.x,p.y)); } } return lines; }
/** * Predeclares all memory required and sets data structures to their initial values */ protected void initialize(T input , GrayS32 output ) { this.graph = output; final int N = input.width*input.height; regionSize.resize(N); threshold.resize(N); for( int i = 0; i < N; i++ ) { regionSize.data[i] = 1; threshold.data[i] = K; graph.data[i] = i; // assign a unique label to each pixel since they are all their own region initially } edges.reset(); edgesNotMatched.reset(); }
/** * Creates a queue with the specified length as its size filled with all zeros */ public static GrowQueue_F32 zeros( int length ) { GrowQueue_F32 out = new GrowQueue_F32(length); out.size = length; return out; }
public void add( float val ) { push(val); }
/** * Given the disparity image compute the 3D location of valid points and save pixel colors * at that point * * @param disparity Disparity image * @param color Color image of left camera */ public void process(ImageGray disparity , BufferedImage color ) { cloudRgb.setMaxSize(disparity.width*disparity.height); cloudXyz.setMaxSize(disparity.width*disparity.height*3); cloudRgb.reset(); cloudXyz.reset(); if( disparity instanceof GrayU8) process((GrayU8)disparity,color); else process((GrayF32)disparity,color); }