/** * Sets up data structures for nearest-neighbor search used in {@link #connectNodes()} */ private void setupSearch() { searchPoints.reset(); for (int i = 0; i < nodes.size(); i++) { SquareNode n = nodes.get(i); double[] point = searchPoints.grow(); point[0] = n.center.x; point[1] = n.center.y; } search.setPoints(searchPoints.toList(), nodes.toList()); }
/** * Put all the neighbors into the same list */ private void markNeighbors(PointVectorNN p ) { List<PointVectorNN> cluster = new ArrayList<PointVectorNN>(); clusters.add(cluster); int mark = clusters.size(); open.reset(); open.add(p); p.matchMarker = mark; while( open.size() > 0 ) { p = open.removeTail(); cluster.add(p); for (int i = 0; i < p.neighbors.size(); i++) { PointVectorNN n = p.neighbors.get(i); if( n.matchMarker == -1 ) { n.matchMarker = mark; open.add(n); } // neighbors are not always symmetric. This it is possible to have an island in one direction // this case will be ignored. } } }
/** * Removes the current point set from the end */ public void removeTail() { while( blocks.size-1 != tail.block ) blocks.removeTail(); tailBlockSize = tail.start; sets.removeTail(); tail = sets.size > 0 ? sets.get( sets.size-1 ) : null; }
/** * Remove grids which cannot possible match the expected shape */ static void pruneIncorrectShape(FastQueue<Grid> grids , int numRows, int numCols ) { // prune clusters which can't be a member calibration target for (int i = grids.size()-1; i >= 0; i--) { Grid g = grids.get(i); if ((g.rows != numRows || g.columns != numCols) && (g.rows != numCols || g.columns != numRows)) { grids.remove(i); } } }
/** * Recycles and initializes all internal data structures */ private void init(List<EllipseRotated_F64> ellipses) { searchPoints.resize(ellipses.size()); nodes.resize(ellipses.size()); clusters.reset(); for (int i = 0; i < ellipses.size(); i++) { EllipseRotated_F64 e = ellipses.get(i); double[] p = searchPoints.get(i); p[0] = e.center.x; p[1] = e.center.y; Node n = nodes.get(i); n.connections.reset(); n.which = i; n.cluster = -1; } search.setPoints(searchPoints.toList(),nodes.toList()); }
@Override public void detectFeatures(I input, FastQueue<Point2D_F64> locDst, FastQueue<Desc> featDst) { // detect features in the image detector.detect(input,null); describe.setImage(input); QueueCorner found = detector.getMaximums(); // compute descriptors and populate results list descriptors.reset(); locations.reset(); for( int i = 0; i < found.size; i++ ) { Point2D_I16 p = found.get(i); Desc desc = descriptors.grow(); if( describe.process(p.x,p.y,0,scale,desc) ) { Point2D_F64 loc = locations.grow(); loc.set(p.x,p.y); describe.process(loc.x,loc.y,0,scale,desc); featDst.add(desc); locDst.add( loc ); } else { descriptors.removeTail(); } } }
@Test public void toList() { FastQueue<DummyData> alg = new FastQueue<DummyData>(10,DummyData.class,true); List<DummyData> l = alg.toList(); assertEquals(0,l.size()); alg.grow().value = 1; alg.grow().value = 1; alg.grow().value = 2; alg.removeTail(); l = alg.toList(); assertEquals(2,l.size()); assertEquals(1,l.get(0).value); assertEquals(1,l.get(1).value); }
@Test public void addAll() { FastQueue<DummyData> alg = new FastQueue<DummyData>(DummyData.class,true); alg.grow(); alg.grow(); FastQueue<DummyData> alg2 = new FastQueue<DummyData>(DummyData.class,false); alg2.addAll(alg); assertTrue(alg.get(0) == alg2.get(0)); assertTrue(alg.get(1) == alg2.get(1)); }
private void createSet( T image , FastQueue<TupleDesc_F64> descs , FastQueue<Point2D_F64> points ) { detector.detect(image); descs.reset(); points.reset(); for( int i = 0; i < detector.getNumberOfFeatures(); i++ ) { points.grow().set(detector.getLocation(i)); descs.add( detector.getDescription(i).copy() ); } }
@Test public void toArray() { FastQueue<Double> queue = new FastQueue<Double>(100,Double.class,false); queue.add(1.0); queue.add(2.0); queue.add(3.0); Object[] array = queue.toList().toArray(); assertEquals(3, array.length); assertTrue(1.0 == (Double)array[0]); assertTrue(2.0 == (Double)array[1]); assertTrue(3.0 == (Double)array[2]); // remove an element from the queue to make sure it isn't using array length queue.removeTail(); array = queue.toList().toArray(); assertEquals(2, array.length); }