Skip to content
Snippets Groups Projects
Commit b0d678e4 authored by Stephan Saalfeld's avatar Stephan Saalfeld
Browse files

added VolatileUnsignedByteType... more to come I guess...

parent b98b55b5
Branches
Tags
No related merge requests found
package net.imglib2.img.basictypeaccess.volatiles;
import net.imglib2.img.basictypeaccess.ByteAccess;
/**
* @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
* @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
*/
public interface VolatileByteAccess extends ByteAccess, VolatileAccess
{}
package net.imglib2.img.basictypeaccess.volatiles.array;
import net.imglib2.img.basictypeaccess.volatiles.VolatileByteAccess;
/**
* A {@link ByteArray} with an {@link #isValid()} flag.
*
* @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
* @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
*/
public class VolatileByteArray extends AbstractVolatileArray< VolatileByteArray > implements VolatileByteAccess
{
private static final long serialVersionUID = -2609245209721069962L;
protected byte[] data;
public VolatileByteArray( final int numEntities, final boolean isValid )
{
super( isValid );
this.data = new byte[ numEntities ];
}
public VolatileByteArray( final byte[] data, final boolean isValid )
{
super( isValid );
this.data = data;
}
@Override
public byte getValue( final int index )
{
return data[ index ];
}
@Override
public void setValue( final int index, final byte value )
{
data[ index ] = value;
}
@Override
public VolatileByteArray createArray( final int numEntities )
{
return new VolatileByteArray( numEntities, true );
}
@Override
public byte[] getCurrentStorageArray()
{
return data;
}
}
......@@ -10,6 +10,8 @@ import net.imglib2.img.basictypeaccess.volatiles.VolatileShortAccess;
*/
public class VolatileShortArray extends AbstractVolatileArray< VolatileShortArray > implements VolatileShortAccess
{
private static final long serialVersionUID = -8460450507170281183L;
protected short data[];
public VolatileShortArray( final int numEntities, final boolean isValid )
......
package net.imglib2.type.volatiles;
import net.imglib2.Volatile;
import net.imglib2.img.NativeImg;
import net.imglib2.img.NativeImgFactory;
import net.imglib2.img.basictypeaccess.ByteAccess;
import net.imglib2.img.basictypeaccess.volatiles.VolatileByteAccess;
import net.imglib2.img.basictypeaccess.volatiles.array.VolatileByteArray;
import net.imglib2.type.numeric.integer.UnsignedByteType;
/**
* A {@link Volatile} variant of {@link UnsignedByteType}. It uses an
* underlying {@link UnsignedByteType} that maps into a
* {@link VolatileByteAccess}.
*
* @author Stephan Saalfeld <saalfelds@janelia.hhmi.org>
* @author Tobias Pietzsch <tobias.pietzsch@gmail.com>
*/
public class VolatileUnsignedByteType extends AbstractVolatileNativeRealType< UnsignedByteType, VolatileUnsignedByteType >
{
final protected NativeImg< ?, ? extends VolatileByteAccess > img;
private static class WrappedUnsignedByteType extends UnsignedByteType
{
public WrappedUnsignedByteType( final NativeImg<?, ? extends ByteAccess> img )
{
super( img );
}
public WrappedUnsignedByteType( final ByteAccess access )
{
super( access );
}
public void setAccess( final ByteAccess access )
{
dataAccess = access;
}
}
// this is the constructor if you want it to read from an array
public VolatileUnsignedByteType( final NativeImg< ?, ? extends VolatileByteAccess > img )
{
super( new WrappedUnsignedByteType( img ), false );
this.img = img;
}
// this is the constructor if you want to specify the dataAccess
public VolatileUnsignedByteType( final VolatileByteAccess access )
{
super( new WrappedUnsignedByteType( access ), access.isValid() );
this.img = null;
}
// this is the constructor if you want it to be a variable
public VolatileUnsignedByteType( final int value )
{
this( new VolatileByteArray( 1, true ) );
set( value );
}
// this is the constructor if you want it to be a variable
public VolatileUnsignedByteType()
{
this( 0 );
}
public void set( final int value )
{
get().set( value );
}
@Override
public void updateContainer( final Object c )
{
final VolatileByteAccess a = img.update( c );
( ( WrappedUnsignedByteType )t ).setAccess( a );
setValid( a.isValid() );
}
@Override
public NativeImg< VolatileUnsignedByteType, ? extends VolatileByteAccess > createSuitableNativeImg( final NativeImgFactory< VolatileUnsignedByteType > storageFactory, final long[] dim )
{
throw new UnsupportedOperationException();
}
@Override
public VolatileUnsignedByteType duplicateTypeOnSameNativeImg()
{
return new VolatileUnsignedByteType( img );
}
@Override
public VolatileUnsignedByteType createVariable()
{
return new VolatileUnsignedByteType();
}
@Override
public VolatileUnsignedByteType copy()
{
final VolatileUnsignedByteType v = createVariable();
v.set( this );
return v;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment