/** * Gets the value at the index which corresponds to the specified fraction * @param fraction 0 to 1 inclusive * @return value at fraction */ public double 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 double getFraction( double fraction ) { return get( (int)((size-1)*fraction) ); }
public double getOrientation(int featureIndex) { return featureAngles.get(featureIndex); } }
@Override public double getOrientation(int featureIndex) { return featureAngles.get(featureIndex); }
@Override public double getRadius(int featureIndex) { return featureRadiuses.get(featureIndex); }
@Override public double getOrientation(int featureIndex) { return featureAngles.get(featureIndex); }
@Override public double getOrientation(int featureIndex) { return alg.getOrientations().get(featureIndex); }
/** * Updates the list of distances from a point to the closest cluster. Update list of total distances */ protected final void updateDistances( List<double[]> points , double []clusterNew ) { totalDistance = 0; for (int i = 0; i < distance.size(); i++) { double dOld = distance.get(i); double dNew = StandardKMeans_F64.distanceSq(points.get(i),clusterNew); if( dNew < dOld ) { distance.data[i] = dNew; totalDistance += dNew; } else { totalDistance += dOld; } } }
/** * Updates the list of distances from a point to the closest cluster. Update list of total distances */ protected final void updateDistances( List<double[]> points , double []clusterNew ) { totalDistance = 0; for (int i = 0; i < distance.size(); i++) { double dOld = distance.get(i); double dNew = StandardKMeans_F64.distanceSq(points.get(i),clusterNew); if( dNew < dOld ) { distance.data[i] = dNew; totalDistance += dNew; } else { totalDistance += dOld; } } }
@Override public void check(GrowQueue_F64 queue, int index, double value) { assertEquals(value,queue.get(index),1e-8); }
@Override public void onDraw(Canvas canvas, Matrix imageToView) { canvas.drawBitmap(bitmap,imageToView,null); canvas.save(); canvas.concat(imageToView); synchronized (listPose) { for ( int i = 0; i < listPose.size; i++ ) { double width = listWidths.get(i); long id = listIDs.get(i); drawCube(id, listPose.get(i), intrinsic, width, canvas); } } canvas.restore(); if( textToDraw != null ) { renderDrawText(canvas); } }
@Override protected void handleDetection(ScalePoint p) { // adjust the image for the down sampling in each octave double localX = p.x / pixelScaleToInput; double localY = p.y / pixelScaleToInput; double localSigma = p.scale / pixelScaleToInput; // find potential orientations first orientation.process(localX,localY,localSigma); // describe each feature GrowQueue_F64 angles = orientation.getOrientations(); for (int i = 0; i < angles.size; i++) { BrightFeature feature = features.grow(); feature.white = p.white; describe.process(localX,localY,localSigma,angles.get(i),feature); orientations.add(angles.get(i)); locations.add(p); } }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance < 0 ) maxDistance = Double.MAX_VALUE; outputIndex.reset(); outputDistance.reset(); alg.findClosestN(point,maxDistance,numNeighbors,outputIndex,outputDistance); for( int i = 0; i < outputIndex.size; i++ ) { int index = outputIndex.get(i); NnData<P> r = results.grow(); r.distance = outputDistance.get(i); r.point = points.get(index); r.index = index; } } }
@Override public void findNearest(P point, double maxDistance, int numNeighbors, FastQueue<NnData<P>> results) { results.reset(); if( maxDistance < 0 ) maxDistance = Double.MAX_VALUE; outputIndex.reset(); outputDistance.reset(); alg.findClosestN(point,maxDistance,numNeighbors,outputIndex,outputDistance); for( int i = 0; i < outputIndex.size; i++ ) { int index = outputIndex.get(i); NnData<P> r = results.grow(); r.distance = outputDistance.get(i); r.point = points.get(index); r.index = index; } } }
@Test public void updateDistances() { InitializePlusPlus alg = new InitializePlusPlus(); alg.init(1,123); alg.distance.resize(3); alg.distance.data = new double[]{3,6,1}; List<double[]> points = new ArrayList<double[]>(); for (int i = 0; i < 3; i++) { points.add(new double[]{i*i}); } alg.updateDistances(points, new double[]{-1}); assertEquals(1,alg.distance.get(0),1e-8); assertEquals(4,alg.distance.get(1),1e-8); assertEquals(1,alg.distance.get(2),1e-8); assertEquals(6,alg.totalDistance,1e-8); }
@Test public void auto_grow() { GrowQueue_F64 alg = new GrowQueue_F64(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_F64 alg = new GrowQueue_F64(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); }
/** * 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); }