SurfaceAreaWrapper extends BoneJCommand { static <T extends AnnotatedSpace<CalibratedAxis>> boolean isAxesMatchingSpatialCalibration(final T space) { final boolean noUnits = spatialAxisStream(space).map(CalibratedAxis::unit) .allMatch(StringUtils::isNullOrEmpty); final boolean matchingUnit = spatialAxisStream(space).map( CalibratedAxis::unit).distinct().count() == 1; final boolean matchingScale = spatialAxisStream(space).map(a -> a .averageScale(0, 1)).distinct().count() == 1; return (matchingUnit || noUnits) && matchingScale; }  @Override void run();  }
@Test public void testIsAxesMatchingSpatialCalibrationDifferentUnits() { final double scale = 0.75; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "cm", scale); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, "mm", scale); final Img<BitType> img = ArrayImgs.bits(1, 1); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis); final boolean result = SurfaceAreaWrapper.isAxesMatchingSpatialCalibration( imgPlus); assertFalse( "Different units in axes should mean that calibration doesn't match", result); }
@Test public void testIsAxesMatchingSpatialCalibrationNoUnits() { final double scale = 0.75; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, "", scale); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, null, scale); final Img<BitType> img = ArrayImgs.bits(1, 1); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis); final boolean result = SurfaceAreaWrapper.isAxesMatchingSpatialCalibration( imgPlus); assertTrue("No units should mean matching calibration", result); }
@Test public void testIsAxesMatchingSpatialCalibration() { final String unit = "mm"; final double scale = 0.75; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, scale); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, scale); final Img<BitType> img = ArrayImgs.bits(1, 1); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis); final boolean result = SurfaceAreaWrapper.isAxesMatchingSpatialCalibration( imgPlus); assertTrue("Axes should have matching calibration", result); }
@Test public void testIsAxesMatchingSpatialCalibrationDifferentScales() { final String unit = "mm"; final DefaultLinearAxis xAxis = new DefaultLinearAxis(Axes.X, unit, 0.5); final DefaultLinearAxis yAxis = new DefaultLinearAxis(Axes.Y, unit, 0.6); final Img<BitType> img = ArrayImgs.bits(1, 1); final ImgPlus<BitType> imgPlus = new ImgPlus<>(img, "Test image", xAxis, yAxis); final boolean result = SurfaceAreaWrapper.isAxesMatchingSpatialCalibration( imgPlus); assertFalse( "Different scales in axes should mean that calibration doesn't match", result); }