Class Unsigned128BitType
- All Implemented Interfaces:
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>
Type
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 superinterface NumericType
are implemented using BigInteger
and BigDecimal
.
This class is not Thread
-safe; do a copy()
first to operate on a different Thread
.- Author:
- Albert Cardona
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final byte[]
protected LongAccess
protected final NativeImg<?,
? extends LongAccess> -
Constructor Summary
ConstructorsConstructorDescriptionUnsigned128BitType
(long lower, long upper) Unsigned128BitType
(BigInteger value) Unsigned128BitType
(LongAccess access) Unsigned128BitType
(NativeImg<?, ? extends LongAccess> bitStorage) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Relies onBigInteger.add(BigInteger)
.int
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.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
Relies onBigInteger.divide(BigInteger)
.Creates a newNativeType
which stores in the same physical array.get()
int
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
Return the lowest 32 bits, likeBigInteger.intValue()
.long
Return the lowest 64 bits, likeBigInteger.intValue()
.The true maximum value, unlikegetMaxValue()
which cannot represent it in adouble
.double
The maximum value that can be stored isMath.pow(2, 128) -1
, which cannot be represented with precision using a doubledouble
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
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
(BigInteger value) void
void
setInteger
(int value) void
setInteger
(long value) void
setOne()
void
setZero()
void
Relies onBigInteger.subtract(BigInteger)
.void
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
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 Details
-
img
-
bytes
protected final byte[] bytes -
dataAccess
-
-
Constructor Details
-
Unsigned128BitType
-
Unsigned128BitType
public Unsigned128BitType(long lower, long upper) -
Unsigned128BitType
-
Unsigned128BitType
-
Unsigned128BitType
public Unsigned128BitType()
-
-
Method Details
-
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
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
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
-
set
-
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
- 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
- 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
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
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
Description copied from interface:Type
- Specified by:
copy
in interfaceType<Unsigned128BitType>
- Returns:
- a new
Type
variable
-
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
Relies onBigInteger.add(BigInteger)
.- Specified by:
add
in interfaceAdd<Unsigned128BitType>
- Overrides:
add
in classAbstractRealType<Unsigned128BitType>
-
sub
Relies onBigInteger.subtract(BigInteger)
.- Specified by:
sub
in interfaceSub<Unsigned128BitType>
- Overrides:
sub
in classAbstractRealType<Unsigned128BitType>
-
mul
Relies onBigInteger.multiply(BigInteger)
.- Specified by:
mul
in interfaceMul<Unsigned128BitType>
- Overrides:
mul
in classAbstractRealType<Unsigned128BitType>
-
div
Relies onBigInteger.divide(BigInteger)
.- Specified by:
div
in interfaceDiv<Unsigned128BitType>
- Overrides:
div
in classAbstractRealType<Unsigned128BitType>
-
compareTo
- Specified by:
compareTo
in interfaceComparable<Unsigned128BitType>
- Overrides:
compareTo
in classAbstractIntegerType<Unsigned128BitType>
-
valueEquals
- Specified by:
valueEquals
in interfaceValueEquals<Unsigned128BitType>
-