Class Unsigned128BitType
- java.lang.Object
-
- net.imglib2.type.numeric.complex.AbstractComplexType<T>
-
- net.imglib2.type.numeric.real.AbstractRealType<T>
-
- net.imglib2.type.numeric.integer.AbstractIntegerType<Unsigned128BitType>
-
- net.imglib2.type.numeric.integer.Unsigned128BitType
-
- All Implemented Interfaces:
java.lang.Comparable<Unsigned128BitType>
,NativeType<Unsigned128BitType>
,ComplexType<Unsigned128BitType>
,IntegerType<Unsigned128BitType>
,NumericType<Unsigned128BitType>
,RealType<Unsigned128BitType>
,Add<Unsigned128BitType>
,Div<Unsigned128BitType>
,Mul<Unsigned128BitType>
,MulFloatingPoint
,SetOne
,SetZero
,Sub<Unsigned128BitType>
,ValueEquals<Unsigned128BitType>
,Type<Unsigned128BitType>
public class Unsigned128BitType extends AbstractIntegerType<Unsigned128BitType> implements NativeType<Unsigned128BitType>
AType
with a bit depth of 128. Each value is stored in two adjacent long in an array, with the lower long first, then the upper long. Currently the math methods defined in the superinterfaceNumericType
are implemented usingBigInteger
andBigDecimal
. This class is notThread
-safe; do acopy()
first to operate on a differentThread
.- Author:
- Albert Cardona
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
bytes
protected LongAccess
dataAccess
protected NativeImg<?,? extends LongAccess>
img
-
Constructor Summary
Constructors Constructor Description Unsigned128BitType()
Unsigned128BitType(long lower, long upper)
Unsigned128BitType(java.math.BigInteger value)
Unsigned128BitType(LongAccess access)
Unsigned128BitType(NativeImg<?,? extends LongAccess> bitStorage)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(Unsigned128BitType t)
Relies onBigInteger.add(BigInteger)
.int
compareTo(Unsigned128BitType t)
Unsigned128BitType
copy()
NativeImg<Unsigned128BitType,? extends LongAccess>
createSuitableNativeImg(NativeImgFactory<Unsigned128BitType> storageFactory, long[] dim)
TheNativeType
creates theNativeImg
used for storing image data; based on the given storage strategy and its size.Unsigned128BitType
createVariable()
Creates a newType
variable which can only store one value.void
dec()
void
decIndex()
Decrement the index into the current data array.void
decIndex(int decrement)
Decrease the index into the current data array bydecrement
steps.void
div(Unsigned128BitType t)
Relies onBigInteger.divide(BigInteger)
.Unsigned128BitType
duplicateTypeOnSameNativeImg()
Creates a newNativeType
which stores in the same physical array.java.math.BigInteger
get()
java.math.BigInteger
getBigInteger()
int
getBitsPerPixel()
Fraction
getEntitiesPerPixel()
Get the number of entities in the storage array required to store one pixel value.int
getIndex()
Get the current index into the current data array.int
getInteger()
Return the lowest 32 bits, likeBigInteger.intValue()
.long
getIntegerLong()
Return the lowest 64 bits, likeBigInteger.intValue()
.java.math.BigInteger
getMaxBigIntegerValue()
The true maximum value, unlikegetMaxValue()
which cannot represent it in adouble
.double
getMaxValue()
The maximum value that can be stored isMath.pow(2, 128) -1
, which cannot be represented with precision using a doubledouble
getMinValue()
void
inc()
void
incIndex()
Increment the index into the current data array.void
incIndex(int increment)
Increases the index into the current data array byincrement
steps.void
mul(double c)
Implemented usingBigDecimal.multiply(BigDecimal)
andBigDecimal.toBigInteger()
.void
mul(float c)
Seemul(double)
.void
mul(Unsigned128BitType t)
Relies onBigInteger.multiply(BigInteger)
.void
set(byte[] bytes)
The first byte is the most significant byte, like inBigInteger.toByteArray()
.void
set(long lower, long upper)
void
set(java.math.BigInteger value)
void
setBigInteger(java.math.BigInteger b)
void
setInteger(int value)
void
setInteger(long value)
void
setOne()
void
setZero()
void
sub(Unsigned128BitType t)
Relies onBigInteger.subtract(BigInteger)
.void
updateContainer(java.lang.Object c)
This method is used by an accessor (e.g., aCursor
) to request an update of the current data array.void
updateIndex(int index)
Set the index into the current data array.boolean
valueEquals(Unsigned128BitType t)
-
Methods inherited from class net.imglib2.type.numeric.integer.AbstractIntegerType
getMinIncrement, getRealDouble, getRealFloat, hashCode, setReal, setReal, toString
-
Methods inherited from class net.imglib2.type.numeric.real.AbstractRealType
equals, getImaginaryDouble, getImaginaryFloat, getPhaseDouble, getPhaseFloat, getPowerDouble, getPowerFloat, set, setImaginary, setImaginary
-
Methods inherited from class net.imglib2.type.numeric.complex.AbstractComplexType
complexConjugate, setComplexNumber, setComplexNumber
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface net.imglib2.type.numeric.ComplexType
complexConjugate, getImaginaryDouble, getImaginaryFloat, getPhaseDouble, getPhaseFloat, getPowerDouble, getPowerFloat, setComplexNumber, setComplexNumber, setImaginary, setImaginary
-
-
-
-
Field Detail
-
img
protected final NativeImg<?,? extends LongAccess> img
-
bytes
protected final byte[] bytes
-
dataAccess
protected LongAccess dataAccess
-
-
Constructor Detail
-
Unsigned128BitType
public Unsigned128BitType(NativeImg<?,? extends LongAccess> bitStorage)
-
Unsigned128BitType
public Unsigned128BitType(long lower, long upper)
-
Unsigned128BitType
public Unsigned128BitType(java.math.BigInteger value)
-
Unsigned128BitType
public Unsigned128BitType(LongAccess access)
-
Unsigned128BitType
public Unsigned128BitType()
-
-
Method Detail
-
createSuitableNativeImg
public NativeImg<Unsigned128BitType,? extends LongAccess> createSuitableNativeImg(NativeImgFactory<Unsigned128BitType> storageFactory, long[] dim)
Description copied from interface:NativeType
TheNativeType
creates theNativeImg
used for storing image data; based on the given storage strategy and its size. It basically only decides here which BasicType it uses (float, int, byte, bit, ...) and how many entities per pixel it needs (e.g. 2 floats per pixel for a complex number). This enables the separation of containers and the basic types.- Specified by:
createSuitableNativeImg
in interfaceNativeType<Unsigned128BitType>
- Parameters:
storageFactory
- which storage strategy is useddim
- the dimensions- Returns:
- the instantiated
NativeImg
where only theType
knows the BasicType it contains.
-
updateContainer
public void updateContainer(java.lang.Object c)
Description copied from interface:NativeType
This method is used by an accessor (e.g., aCursor
) to request an update of the current data array.As an example consider a
CellCursor
moving on aCellImg
. The cursor maintains aNativeType
which provides access to the image data. When the cursor moves from one cell to the next, the underlying data array of theNativeType
must be switched to the data array of the new cell.To achieve this, the
CellCursor
callsupdateContainer()
with itself as the argument.updateContainer()
in turn will callNativeImg.update(Object)
on it's container, passing along the reference to the cursor. In this example, the container would be aCellImg
. While theNativeType
does not know about the type of the cursor, the container does.CellImg
knows that it is passed aCellCursor
instance, which can be used to figure out the current cell and the underlying data array, which is then returned to theNativeType
.The idea behind this concept is maybe not obvious. The
NativeType
knows which basic type is used (float, int, byte, ...). However, it does not know how the data is stored (ArrayImg
,CellImg
, ...). This prevents the need for multiple implementations ofNativeType
.- Specified by:
updateContainer
in interfaceNativeType<Unsigned128BitType>
- Parameters:
c
- reference to an accessor which can be passed on to the container (which will know what to do with it).
-
duplicateTypeOnSameNativeImg
public Unsigned128BitType duplicateTypeOnSameNativeImg()
Description copied from interface:NativeType
Creates a newNativeType
which stores in the same physical array. This is only used internally.- Specified by:
duplicateTypeOnSameNativeImg
in interfaceNativeType<Unsigned128BitType>
- Returns:
- a new
NativeType
instance working on the sameNativeImg
-
set
public void set(byte[] bytes)
The first byte is the most significant byte, like inBigInteger.toByteArray()
. Only the last 16 bytes are read, if there are more.
-
get
public java.math.BigInteger get()
-
set
public void set(java.math.BigInteger value)
-
set
public void set(long lower, long upper)
-
getInteger
public int getInteger()
Return the lowest 32 bits, likeBigInteger.intValue()
.- Specified by:
getInteger
in interfaceIntegerType<Unsigned128BitType>
-
getIntegerLong
public long getIntegerLong()
Return the lowest 64 bits, likeBigInteger.intValue()
.- Specified by:
getIntegerLong
in interfaceIntegerType<Unsigned128BitType>
-
getBigInteger
public java.math.BigInteger getBigInteger()
- Specified by:
getBigInteger
in interfaceIntegerType<Unsigned128BitType>
-
setInteger
public void setInteger(int value)
- Specified by:
setInteger
in interfaceIntegerType<Unsigned128BitType>
-
setInteger
public void setInteger(long value)
- Specified by:
setInteger
in interfaceIntegerType<Unsigned128BitType>
-
setBigInteger
public void setBigInteger(java.math.BigInteger b)
- Specified by:
setBigInteger
in interfaceIntegerType<Unsigned128BitType>
-
getMaxValue
public double getMaxValue()
The maximum value that can be stored isMath.pow(2, 128) -1
, which cannot be represented with precision using a double- Specified by:
getMaxValue
in interfaceRealType<Unsigned128BitType>
-
getMaxBigIntegerValue
public java.math.BigInteger getMaxBigIntegerValue()
The true maximum value, unlikegetMaxValue()
which cannot represent it in adouble
.
-
getMinValue
public double getMinValue()
- Specified by:
getMinValue
in interfaceRealType<Unsigned128BitType>
-
getIndex
public int getIndex()
Description copied from interface:NativeType
Get the current index into the current data array.This is used by accessors (e.g., a
Cursor
) to position theNativeType
in the container.- Specified by:
getIndex
in interfaceNativeType<Unsigned128BitType>
- Returns:
- the current index into the underlying data array
-
updateIndex
public void updateIndex(int index)
Description copied from interface:NativeType
Set the index into the current data array.This is used by accessors (e.g., a
Cursor
) to position theNativeType
in the container.- Specified by:
updateIndex
in interfaceNativeType<Unsigned128BitType>
- Parameters:
index
- the new array index
-
incIndex
public void incIndex()
Description copied from interface:NativeType
Increment the index into the current data array.This is used by accessors (e.g., a
Cursor
) to position theNativeType
in the container.- Specified by:
incIndex
in interfaceNativeType<Unsigned128BitType>
-
incIndex
public void incIndex(int increment)
Description copied from interface:NativeType
Increases the index into the current data array byincrement
steps.This is used by accessors (e.g., a
Cursor
) to position theNativeType
in the container.- Specified by:
incIndex
in interfaceNativeType<Unsigned128BitType>
- Parameters:
increment
- how many steps
-
decIndex
public void decIndex()
Description copied from interface:NativeType
Decrement the index into the current data array.This is used by accessors (e.g., a
Cursor
) to position theNativeType
in the container.- Specified by:
decIndex
in interfaceNativeType<Unsigned128BitType>
-
decIndex
public void decIndex(int decrement)
Description copied from interface:NativeType
Decrease the index into the current data array bydecrement
steps.This is used by accessors (e.g., a
Cursor
) to position theNativeType
in the container.- Specified by:
decIndex
in interfaceNativeType<Unsigned128BitType>
- Parameters:
decrement
- how many steps
-
createVariable
public Unsigned128BitType createVariable()
Description copied from interface:Type
Creates a newType
variable which can only store one value.- Specified by:
createVariable
in interfaceType<Unsigned128BitType>
- Returns:
- a new
Type
variable
-
copy
public Unsigned128BitType copy()
Description copied from interface:Type
- Specified by:
copy
in interfaceType<Unsigned128BitType>
- Returns:
- a new
Type
variable
-
getEntitiesPerPixel
public Fraction getEntitiesPerPixel()
Description copied from interface:NativeType
Get the number of entities in the storage array required to store one pixel value. A pixel value may be spread over several or less than one entity. For example, a complex number may require 2 entries of a float[] array to store one pixel. Or a 12-bit type might need 12/64th entries of a long[] array.- Specified by:
getEntitiesPerPixel
in interfaceNativeType<Unsigned128BitType>
- Returns:
- the number of storage type entities required to store one pixel value.
-
getBitsPerPixel
public int getBitsPerPixel()
- Specified by:
getBitsPerPixel
in interfaceRealType<Unsigned128BitType>
-
inc
public void inc()
- Specified by:
inc
in interfaceRealType<Unsigned128BitType>
- Overrides:
inc
in classAbstractIntegerType<Unsigned128BitType>
-
dec
public void dec()
- Specified by:
dec
in interfaceRealType<Unsigned128BitType>
- Overrides:
dec
in classAbstractIntegerType<Unsigned128BitType>
-
setZero
public void setZero()
- Specified by:
setZero
in interfaceSetZero
- Overrides:
setZero
in classAbstractIntegerType<Unsigned128BitType>
-
setOne
public void setOne()
- Specified by:
setOne
in interfaceSetOne
- Overrides:
setOne
in classAbstractIntegerType<Unsigned128BitType>
-
mul
public void mul(float c)
Seemul(double)
.- Specified by:
mul
in interfaceMulFloatingPoint
- Overrides:
mul
in classAbstractRealType<Unsigned128BitType>
-
mul
public void mul(double c)
Implemented usingBigDecimal.multiply(BigDecimal)
andBigDecimal.toBigInteger()
.- Specified by:
mul
in interfaceMulFloatingPoint
- Overrides:
mul
in classAbstractRealType<Unsigned128BitType>
-
add
public void add(Unsigned128BitType t)
Relies onBigInteger.add(BigInteger)
.- Specified by:
add
in interfaceAdd<Unsigned128BitType>
- Overrides:
add
in classAbstractRealType<Unsigned128BitType>
-
sub
public void sub(Unsigned128BitType t)
Relies onBigInteger.subtract(BigInteger)
.- Specified by:
sub
in interfaceSub<Unsigned128BitType>
- Overrides:
sub
in classAbstractRealType<Unsigned128BitType>
-
mul
public void mul(Unsigned128BitType t)
Relies onBigInteger.multiply(BigInteger)
.- Specified by:
mul
in interfaceMul<Unsigned128BitType>
- Overrides:
mul
in classAbstractRealType<Unsigned128BitType>
-
div
public void div(Unsigned128BitType t)
Relies onBigInteger.divide(BigInteger)
.- Specified by:
div
in interfaceDiv<Unsigned128BitType>
- Overrides:
div
in classAbstractRealType<Unsigned128BitType>
-
compareTo
public int compareTo(Unsigned128BitType t)
- Specified by:
compareTo
in interfacejava.lang.Comparable<Unsigned128BitType>
- Overrides:
compareTo
in classAbstractIntegerType<Unsigned128BitType>
-
valueEquals
public boolean valueEquals(Unsigned128BitType t)
- Specified by:
valueEquals
in interfaceValueEquals<Unsigned128BitType>
-
-