@Override public void getCenterValue( final long binPos, final T value ) { long val; if ( tailBins ) { if ( binPos == 0 ) val = minVal - 1; // TODO HACK - what is best to return? else if ( binPos == bins - 1 ) val = maxVal + 1; // TODO same HACK else val = minVal + binPos - 1; } else { // no tail bins val = minVal + binPos; } value.setInteger( val ); }
@Override public void getLowerBound( final long binPos, final T value ) { if ( tailBins && ( binPos == 0 || binPos == bins - 1 ) ) { if ( binPos == 0 ) value.setInteger( Long.MIN_VALUE + 1 ); else value.setInteger( maxVal + 1 ); } else { getCenterValue( binPos, value ); } }
@Override public void getLowerBound( final long binPos, final T value ) { if ( tailBins && ( binPos == 0 || binPos == bins - 1 ) ) { if ( binPos == 0 ) value.setInteger( Long.MIN_VALUE + 1 ); else value.setInteger( maxVal + 1 ); } else { getCenterValue( binPos, value ); } }
@Override public void getUpperBound( final long binPos, final T value ) { if ( tailBins && ( binPos == 0 || binPos == bins - 1 ) ) { if ( binPos == 0 ) value.setInteger( minVal - 1 ); else value.setInteger( Long.MAX_VALUE - 1 ); } else { getCenterValue( binPos, value ); } }
@Override public void getUpperBound( final long binPos, final T value ) { if ( tailBins && ( binPos == 0 || binPos == bins - 1 ) ) { if ( binPos == 0 ) value.setInteger( minVal - 1 ); else value.setInteger( Long.MAX_VALUE - 1 ); } else { getCenterValue( binPos, value ); } }
@Override public T invMap(final int i) { T out = minType.createVariable(); out.setInteger(i + minVal); return out; }
@Override public final void convert(final IntegerType<?> input, final IntegerType<?> output) { output.setInteger(input.getIntegerLong()); } };
/** * Set the labeling at the current pixel * * @param labeling */ public void setLabeling( final List< T > labeling ) { this.type.setInteger( mapping.indexOf( labeling ) ); synchronized ( generation ) { generation[ 0 ]++; } }
@Override public T invMap( final int i ) { final T out = minType.createVariable(); out.setInteger( i + minVal ); return out; }
@Override public void set( final LabelingType< T > c ) { if ( c.mapping == mapping ) type.setInteger( c.type.getInteger() ); else type.setInteger( mapping.intern( c ).index ); generation.modCount++; }
@Override public boolean add( final T label ) { final int index = type.getInteger(); final int newindex = mapping.addLabelToSetAtIndex( label, index ).index; if ( newindex == index ) return false; type.setInteger( newindex ); generation.modCount++; return true; }
@SuppressWarnings( "unchecked" ) @Override public boolean remove( final Object label ) { final int index = type.getInteger(); final int newindex = mapping.removeLabelFromSetAtIndex( ( T ) label, index ).index; if ( newindex == index ) return false; type.setInteger( newindex ); generation.modCount++; return true; }
@Override public boolean addAll( final Collection< ? extends T > c ) { final int index = type.getInteger(); int newindex = index; for ( final T label : c ) newindex = mapping.addLabelToSetAtIndex( label, newindex ).index; if ( newindex == index ) return false; type.setInteger( newindex ); generation.modCount++; return true; }
@Override public void clear() { final int index = type.getInteger(); final int newindex = mapping.emptySet().index; if ( newindex != index ) { type.setInteger( newindex ); generation.modCount++; } }
@SuppressWarnings( "unchecked" ) @Override public boolean removeAll( final Collection< ? > c ) { final int index = type.getInteger(); int newindex = index; for ( final T label : ( Collection< ? extends T > ) c ) newindex = mapping.removeLabelFromSetAtIndex( label, newindex ).index; if ( newindex == index ) return false; type.setInteger( newindex ); generation.modCount++; return true; }
public void relabel() { for ( final L label : Views.iterable( output ) ) label.setInteger( canonicalLabels.get( label.getInteger() ) ); } }
/** * Expand a RandomAccessibleInterval as specified by border. source will be * extended with a constant value specified by the caller. * * @param source * the interval to expand. * @param value * Constant extension of source. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by t and border. */ public static < T extends IntegerType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final int value, final long... border ) { final T extension = Util.getTypeFromInterval( source ).createVariable(); extension.setInteger( value ); return Views.expandValue( source, extension, border ); }
/** * Extend a RandomAccessibleInterval with a constant-value out-of-bounds * strategy. * * @param source * the interval to extend. * @param value * the extension value * @return (unbounded) RandomAccessible which extends the input interval to * infinity. * @see net.imglib2.outofbounds.OutOfBoundsConstantValue */ public static < T extends IntegerType< T >, F extends RandomAccessibleInterval< T > > ExtendedRandomAccessibleInterval< T, F > extendValue( final F source, final int value ) { final T extension = Util.getTypeFromInterval( source ).createVariable(); extension.setInteger( value ); return Views.extendValue( source, extension ); }
/** * Expand a RandomAccessibleInterval as specified by border. source will be * extended with a constant value specified by the caller. * * @param source * the interval to expand. * @param value * Constant extension of source. * @return Expansion of the {@link RandomAccessibleInterval} source as * specified by t and border. */ public static < T extends IntegerType< T > > IntervalView< T > expandValue( final RandomAccessibleInterval< T > source, final long value, final long... border ) { final T extension = Util.getTypeFromInterval( source ).createVariable(); extension.setInteger( value ); return Views.expandValue( source, extension, border ); }
@Override public boolean conforms() { final Object inType = in().firstElement(); // HACK: Help the matcher overcome generics limitations. if (!(inType instanceof IntegerType)) return false; // HACK: Reject types that are small. // Because the InvertII is faster. // TODO: Think of a better solution. final T copy = in().firstElement().createVariable(); copy.setInteger(Long.MAX_VALUE); return copy.getIntegerLong() == Long.MAX_VALUE; }