EllipsoidOptimisationStrategy extends AbstractBinaryFunctionOp<byte[][], Vector3d, QuickEllipsoid> { boolean isInvalid(final QuickEllipsoid ellipsoid, final int w, final int h, final int d) { double[][] surfacePoints = ellipsoid.getAxisAlignRandomlyDistributedSurfacePoints(algorithmParameters.nVectors); final double minRadius = ellipsoid.getSortedRadii()[0]; if (minRadius < 0.5) { return true; } int outOfBoundsCount = 0; final int half = algorithmParameters.nVectors / 2; for (final double[] p : surfacePoints) { if (isOutOfBounds((int) (p[0]), (int) (p[1]), (int) (p[2]), w, h, d)) outOfBoundsCount++; if (outOfBoundsCount > half) return true; } final double volume = ellipsoid.getVolume(); return volume > stackVolume; }  @Override QuickEllipsoid calculate(byte[][] pixels, Vector3d seedPoint);  }
@Test public void testIsInvalid() { QuickEllipsoid tooSmall = new QuickEllipsoid(new double[]{0.3,0.3,0.3},new double[]{50,50,50},new double[][]{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}); QuickEllipsoid tooLarge = new QuickEllipsoid(new double[]{10,10,10},new double[]{50,50,50},new double[][]{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}); QuickEllipsoid tooFarOutOfBounds = new QuickEllipsoid(new double[]{2,2,2},new double[]{0,0,0},new double[][]{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}); final EllipsoidOptimisationStrategy optimisation = (EllipsoidOptimisationStrategy) Functions.binary(ops, EllipsoidOptimisationStrategy.class, QuickEllipsoid.class, new byte[10][10], new Vector3d(),new long[]{10,10,1}, new NoEllipsoidConstrain(), new OptimisationParameters(2,0,0,0,0,1000)); boolean tooSmallInvalid = optimisation.isInvalid(tooSmall, 100,100,100); boolean tooFarOutInvalid = optimisation.isInvalid(tooFarOutOfBounds, 100,100,100); boolean tooLargeInvalid = optimisation.isInvalid(tooLarge, 100,100,100); assertTrue("Too small ellipsoid is valid.", tooSmallInvalid); assertTrue("Too large ellipsoid is valid.", tooLargeInvalid); assertTrue("Too far out ellipsoid is valid.", tooFarOutInvalid); }