/** * Create a new {@link LabelingMapping} that maps label sets to the given * integral {@code indexType}. */ public LabelingMapping( final IntegerType< ? > indexType ) { this( ( int ) indexType.getMaxValue() ); }
public LabelingMapping( final IntegerType< ? > value ) { maxNumLabels = ( int ) value.getMaxValue(); final List< T > background = Collections.emptyList(); theEmptyList = intern( background ); }
/** * Given an IntegerType, returns a new Type containing its maximum possible * value. * @param <R> the IntegerType in question. * @param r a representative Type object. * @return a new Type containing its maximum possible * value. */ private static <R extends IntegerType<R>> R maxType(R r) { R type = r.createVariable(); type.setReal(r.getMaxValue()); return type; }
/** * Given an IntegerType, returns a new Type containing its maximum possible * value. * * @param <R> * the IntegerType in question. * @param r * a representative Type object. * @return a new Type containing its maximum possible value. */ private static < R extends IntegerType< R >> R maxType( final R r ) { final R type = r.createVariable(); type.setReal( r.getMaxValue() ); return type; }
private < T extends IntegerType< T > & NativeType< T > > void testIsRandomImageIntegerType( RandomAccessibleInterval< T > image ) { T type = Util.getTypeFromInterval( image ); double min = type.getMinValue(); double max = type.getMaxValue(); double actualMin = fold( Double.POSITIVE_INFINITY, Math::min, Views.iterable( image ) ); double actualMax = fold( Double.NEGATIVE_INFINITY, Math::max, Views.iterable( image ) ); // NB: Test, if the actual maximal value is close enough to the types getMaxValue(). String msg1 = "Actual max is to low, type: " + type.getClass().getSimpleName() + " max: " + max + " actual max: " + actualMax; assertTrue( msg1, min * 0.2 + max * 0.8 < actualMax ); // NB: Test, if the actual minimal value is close enough to the types getMinValue(). String msg2 = "Actual min is to high, type: " + type.getClass().getSimpleName() + " min: " + min + " actual min: " + actualMin; assertTrue( msg2, min * 0.8 + max * 0.2 > actualMin ); }