/** * Gets the value at the index which corresponds to the specified fraction * @param fraction 0 to 1 inclusive * @return value at fraction */ public int getFraction( double fraction ) { return get( (int)((size-1)*fraction) ); }
/** * Gets the value at the index which corresponds to the specified fraction * @param fraction 0 to 1 inclusive * @return value at fraction */ public int getFraction( double fraction ) { return get( (int)((size-1)*fraction) ); }
private void listSwap(GrowQueue_I32 list, int a, int b) { int tmp = list.get(a); list.data[a] = list.data[b]; list.data[b] = tmp; }
private void listSwap(GrowQueue_I32 list, int a, int b) { int tmp = list.get(a); list.data[a] = list.data[b]; list.data[b] = tmp; }
public int getPointId( int index ) { return point.get(index); }
/** * Convenient function for creating a leaf node */ private KdTree.Node createLeaf(List<P> points , GrowQueue_I32 indexes ) { int index = indexes == null ? -1 : indexes.get(0); return memory.requestNode(points.get(0),index); } }
/** * Convenient function for creating a leaf node */ private KdTree.Node createLeaf(List<P> points , GrowQueue_I32 indexes ) { int index = indexes == null ? -1 : indexes.get(0); return memory.requestNode(points.get(0),index); } }
/** * Look for two corners which point to the same point and removes one of them from the corner list */ void removeDuplicates( GrowQueue_I32 corners ) { // remove duplicates for (int i = 0; i < corners.size(); i++) { Point2D_I32 a = contour.get(corners.get(i)); // start from the top so that removing a corner doesn't mess with the for loop for (int j = corners.size()-1; j > i; j--) { Point2D_I32 b = contour.get(corners.get(j)); if( a.x == b.x && a.y == b.y ) { // this is still ok if j == 0 because it wrapped around. 'i' will now be > size corners.remove(j); } } } }
public static List<Contour> convertContours(BinaryContourInterface alg ) { List<ContourPacked> contours = alg.getContours(); List<Contour> ret = new ArrayList<>(); for (int i = 0; i < contours.size(); i++) { ContourPacked p = contours.get(i); Contour c = new Contour(); c.external = BinaryContourInterface.copyContour(alg,p.externalIndex); for (int j = 0; j < p.internalIndexes.size; j++) { c.internal.add( BinaryContourInterface.copyContour(alg,p.internalIndexes.get(j))); } ret.add(c); } return ret; }
/** * Sets the location of each cluster to the average location of all its members. */ protected void updateClusterCenters() { // compute the new centers of each cluster for (int i = 0; i < clusters.size; i++) { double mc = memberCount.get(i); double[] w = workClusters.get(i); double[] c = clusters.get(i); for (int j = 0; j < w.length; j++) { c[j] = w[j] / mc; } } }
/** * Sets the location of each cluster to the average location of all its members. */ protected void updateClusterCenters() { // compute the new centers of each cluster for (int i = 0; i < clusters.size; i++) { double mc = memberCount.get(i); double[] w = workClusters.get(i); double[] c = clusters.get(i); for (int j = 0; j < w.length; j++) { c[j] = w[j] / mc; } } }
@Override public void findNearest(double[] target, double maxDistance, int numNeighbors, FastQueue<NnData<double[]>> results) { results.reset(); PriorityQueue<HeapItem> heap = search(target, maxDistance < 0 ? Double.POSITIVE_INFINITY : Math.sqrt(maxDistance), numNeighbors); while (!heap.isEmpty()) { final HeapItem heapItem = heap.poll(); NnData<double[]> objects = new NnData<>(); objects.index = indexes.get(heapItem.index); objects.point = items[heapItem.index]; objects.distance = heapItem.dist * heapItem.dist; // squared distance is expected results.add(objects); } results.reverse(); }
@Override public void check(GrowQueue_I32 queue, int index, double value) { assertEquals((int)value,queue.get(index)); }
@Override protected void fitShape(List<Point2D_I32> contour) { if( !alg.process(contour) ) return; PolylineSplitMerge.CandidatePolyline best = alg.getBestPolyline(); Polygon2D_I32 poly = workPoly.grow(); poly.vertexes.resize(best.splits.size); for (int i = 0; i < best.splits.size; i++) { Point2D_I32 p = contour.get(best.splits.get(i)); poly.get(i).set(p); } }
@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 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); }