/** * 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; }
/** * A node was just split then it was realized that it should not have been split. Undoes the split * and recycles the data * * @param node Node which needs to become a leaf again. */ protected void undoSplit(O node) { for (int i = 0; i < 8; i++) { O o = (O)node.children[i]; if (o != null) { // the order might be different, but the N most recent will be recycled storageNodes.removeTail(); o.parent = null; o.points.reset(); node.children[i] = null; } } storageChildren.add((O[])node.children); node.children = null; }
/** * 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. } } }
/** * Checks to see if the child already exists. If not it creates the child. If the * child won't occupy a physically possible space then null is returned. */ protected O checkAddChild(O node, int index) { O child = (O)node.children[index]; if (child == null) { node.children[index] = child = storageNodes.grow(); child.parent = node; setChildSpace(node, index, child); // no points to add to child since none of the previous ones belong to it if( !isSpaceValid(child)) { // remove this child storageNodes.removeTail(); node.children[index] = child = null; } } return child; }
final Node node = nodes.removeTail(); final double dist = distance(items[node.index], target);
if( verbose ) System.out.println("Rejecting: Not approximately elliptical. size = "+pointsF.size()); found.removeTail(); } else if( f.ellipse.a > maxMajorToMinorRatio*f.ellipse.b ) { if( verbose ) System.out.println("Rejecting: Major to minor axis length ratio too extreme = "+pointsF.size()); found.removeTail();
final Node node = nodes.removeTail(); final double dist = distance(items[node.index], target);
/** * <p> * Find the polynomial roots and for each root compute the Fundamental matrix. * Given the two matrices it will compute an alpha such that the determinant is zero.<br> * * det(&alpha*F1 + (1-α)*F2 ) = 0 * </p> */ public void computeSolutions( FastQueue<DMatrixRMaj> solutions ) { if( !rootFinder.process(poly)) return; List<Complex_F64> zeros = rootFinder.getRoots(); for( Complex_F64 c : zeros ) { if( !c.isReal() && Math.abs(c.imaginary) > 1e-10 ) continue; DMatrixRMaj F = solutions.grow(); double a = c.real; double b = 1-c.real; for( int i = 0; i < 9; i++ ) { F.data[i] = a*F1.data[i] + b*F2.data[i]; } // det(F) = 0 is already enforced, but for essential matrices it needs to enforce // that the first two singular values are zero and the last one is zero if( !computeFundamental && !projectOntoEssential(F) ) { solutions.removeTail(); } } }
/** * <p> * Find the polynomial roots and for each root compute the Fundamental matrix. * Given the two matrices it will compute an alpha such that the determinant is zero.<br> * * det(&alpha*F1 + (1-α)*F2 ) = 0 * </p> */ public void computeSolutions( FastQueue<DenseMatrix64F> solutions ) { if( !rootFinder.process(poly)) return; List<Complex64F> zeros = rootFinder.getRoots(); for( Complex64F c : zeros ) { if( !c.isReal() && Math.abs(c.imaginary) > 1e-10 ) continue; DenseMatrix64F F = solutions.grow(); double a = c.real; double b = 1-c.real; for( int i = 0; i < 9; i++ ) { F.data[i] = a*F1.data[i] + b*F2.data[i]; } // det(F) = 0 is already enforced, but for essential matrices it needs to enforce // that the first two singular values are zero and the last one is zero if( !computeFundamental && !projectOntoEssential(F) ) { solutions.removeTail(); } } }
nodes.removeTail(); continue;
@Override public void process(T input ) { if( periodX <= 0 || periodY <= 0 ) throw new IllegalArgumentException("Must call configure() first"); alg.setImage(input); int x0 = featureWidth/2; int x1 = input.getWidth()-featureWidth/2; int y0 = featureWidth/2; int y1 = input.getHeight()-featureWidth/2; descriptions.reset(); locations.reset(); for (int y = y0; y < y1; y += periodY ) { for (int x = x0; x < x1; x += periodX ) { Desc d = descriptions.grow(); if( !alg.process(x,y,0,radius,d) ) { descriptions.removeTail(); } else { locations.grow().set(x,y); } } } }
private void computeDescriptions(FastQueue<Point2D_F64> locDst, FastQueue<Desc> featDst, QueueCorner found) { 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(); } } }
/** * Detects ellipses inside the binary image and refines the edges for all detections inside the gray image * * @param gray Grayscale image * @param binary Binary image of grayscale. 1 = ellipse and 0 = ignored background */ public void process(T gray, GrayU8 binary) { refined.reset(); ellipseDetector.process(binary); if( ellipseRefiner != null) ellipseRefiner.setImage(gray); intensityCheck.setImage(gray); List<BinaryEllipseDetectorPixel.Found> found = ellipseDetector.getFound(); for( BinaryEllipseDetectorPixel.Found f : found ) { if( !intensityCheck.process(f.ellipse) ) { if( verbose ) System.out.println("Rejecting ellipse which isn't intense enough"); continue; } EllipseRotated_F64 r = refined.grow(); if( ellipseRefiner != null ) { if (!ellipseRefiner.process(f.ellipse, r)) { refined.removeTail(); } } else { r.set(f.ellipse); } } }
@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); }
nodes.removeTail(); final double dist = distance(items[node.index], target);
@Test public void removeTail() { FastQueue<DummyData> alg = new FastQueue<DummyData>(10,DummyData.class,true); alg.grow(); assertEquals(1,alg.size); alg.removeTail(); assertEquals(0,alg.size); }
@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); }
@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(); } } }
@Override public void process(T image) { // detect features and setup describe and orientation detector.detect(image); describe.setImage(image); if( orientation != null ) orientation.setImage(image); // go through each set of features for( int i = 0; i < info.length; i++ ) { FoundPointSO points = detector.getFeatureSet(i); SetInfo<TD> setInfo = info[i]; setInfo.reset(); // describe each detected feature for( int j = 0; j < points.getNumberOfFeatures(); j++ ) { Point2D_F64 p = points.getLocation(j); double radius = points.getRadius(j); double ori = points.getOrientation(j); if( orientation != null ) { orientation.setObjectRadius(radius); ori = orientation.compute(p.x,p.y); } TD d = setInfo.descriptors.grow(); if( describe.process(p.x,p.y,ori,radius,d)) { setInfo.location.grow().set(p); } else { setInfo.descriptors.removeTail(); } } } }
@Override public void detect(T input) { descs.reset(); featureRadiuses.reset(); featureAngles.reset(); location.reset(); if( orientation != null ) { orientation.setImage(input); } describe.setImage(input); detector.detect(input); int N = detector.getNumberOfFeatures(); for( int i = 0; i < N; i++ ) { Point2D_F64 p = detector.getLocation(i); double radius = detector.getRadius(i); double yaw = detector.getOrientation(i); if( orientation != null ) { orientation.setObjectRadius(radius); yaw = orientation.compute(p.x,p.y); } if( describe.process(p.x,p.y,yaw,radius,descs.grow()) ) { featureRadiuses.push(radius); featureAngles.push(yaw); location.add(p); } else { descs.removeTail(); } } }