Woolz Image Processing  Version 1.7.5
AlgBits

Files

file  AlgBits.c
 Provides bit fiddling functions.
 
file  AlgGrayCode.c
 Provides functions for computing Gray codes and their inverse. See Christopher H. Hamilton. "Range Searching Data Structures with Cache Locality" PhD Thesis, Dalhousie University, March 20011. The code within this file is derived from this thesis and the software it refers to.
 
file  AlgHilbertIndex.c
 Provides functions for Hilbert indices and their inverse. See J. K. Lawder "Calculation of Mappings Between One an n-dimensional Values Using the Hilbert Space-filling Curve", Birkbeck, University of London Research Report BBKCS-00-01, 2000. The code in this technical report has been modifiied to support n-dimensions and variable bit orders without recompilation.
 

Functions

unsigned int AlgBitSetCount (unsigned long gMsk)
 Counts the number of bits set in the given mask. More...
 
int AlgBitMostSigSet (unsigned long gMsk)
 Finds the most significant bit set in the given mask. The value returned will be zero if the mask was zero one if the mask had the value 1 or higher integer if the most significant bit set in the mask is greater. More...
 
int AlgBitMostSigSetLL (unsigned long long gMsk)
 Finds the most significant bit set in the given mask. The value returned will be zero if the mask was zero one if the mask had the value 1 or higher integer if the most significant bit set in the mask is greater. More...
 
unsigned int AlgBitSetPositions (unsigned int *posA, unsigned long gMsk)
 Counts the number of bits set in the given mask and sets the first elements of the given bit position array. More...
 
unsigned int AlgBitRotateRight (unsigned int g, unsigned int n, unsigned int d)
 Rotates the given bit mask d places to the right (towards less significant bits) where there are n valid bits in the given bit mask. More...
 
unsigned long AlgBitNextNOfM (unsigned long curMsk, int n, int m)
 Computes a bit mask which has n bits set and is <= maxMsk, the new bit mask is the next after the given current mask. The maximum number of bits that can be stored in an unsigned long is assumed to be 32. If the actual number is less than this then this code won't work, if it's higher everything should be fine. This function can be used together with AlgBitSetPositions() to select all ordered combinations of N of M. Eg to select all ordered combinations of 3 out of 5 this function would return 00111, 01011, 01101, 01110, 10110, 11010, 11100. More...
 
int AlgBitNextSet (unsigned long msk, int idC)
 Computes the index of the next bit set in the given mask using the index to the current bit as the start index. maxMsk, the new bit mask is the next after the given current mask. More...
 
int AlgBitNextPowerOfTwo (unsigned int *dstP2I, unsigned int gI)
 Computes the next integer that is >= the given integer and has only a single bit set. More...
 
int AlgBitIsPowerOfTwo (unsigned int gI)
 Checks that the given integer is an integral power of two. More...
 
unsigned int AlgGrayCode (unsigned int g)
 Computes the Gray code of the given value. More...
 
unsigned long long AlgGrayCodeLL (unsigned long long g)
 Computes the Gray code of the given value. More...
 
unsigned int AlgGrayCodeInv (unsigned int g)
 Computes the inverse Gray code, ie the value corresponding to the given Gray code. More...
 
unsigned long long AlgGrayCodeInvLL (unsigned long long g)
 Computes the inverse Gray code, ie the value corresponding to the given Gray code. More...
 
void AlgHilbertIndex (unsigned int *h, unsigned int *p, int n, int o)
 Computes the Hilbert index of a point in n dimensions. More...
 
void AlgHilbertIndexInv (unsigned int *h, unsigned int *p, int n, int o)
 Computes the coordinates of the point in n dimensions corresponding to the given Hilbert index. More...
 

Detailed Description

Function Documentation

unsigned int AlgBitSetCount ( unsigned long  gMsk)

Counts the number of bits set in the given mask.

Returns
Number of bits set.
Parameters
gMskGiven bit mask.
int AlgBitMostSigSet ( unsigned long  gMsk)

Finds the most significant bit set in the given mask. The value returned will be zero if the mask was zero one if the mask had the value 1 or higher integer if the most significant bit set in the mask is greater.

Returns
Most significant bit set in the given mask.
Parameters
gMskGiven bit mask.

Referenced by WlzGreySetHilbertRankValues().

int AlgBitMostSigSetLL ( unsigned long long  gMsk)

Finds the most significant bit set in the given mask. The value returned will be zero if the mask was zero one if the mask had the value 1 or higher integer if the most significant bit set in the mask is greater.

Returns
Most significant bit set in the given mask.
Parameters
gMskGiven bit mask.
unsigned int AlgBitSetPositions ( unsigned int *  posA,
unsigned long  gMsk 
)

Counts the number of bits set in the given mask and sets the first elements of the given bit position array.

Returns
Number of bits set.
Parameters
posABit set position array, MUST have a length >= the number of bits in the unsigned long bit mask.
gMskGiven bit mask.
unsigned int AlgBitRotateRight ( unsigned int  g,
unsigned int  n,
unsigned int  d 
)

Rotates the given bit mask d places to the right (towards less significant bits) where there are n valid bits in the given bit mask.

Returns
Bitmask rotated right.
Parameters
gGiven bit mask.
nNumber of valid bits in the bit mask.
dNumber of places to rotate right.
unsigned long AlgBitNextNOfM ( unsigned long  curMsk,
int  n,
int  m 
)

Computes a bit mask which has n bits set and is <= maxMsk, the new bit mask is the next after the given current mask. The maximum number of bits that can be stored in an unsigned long is assumed to be 32. If the actual number is less than this then this code won't work, if it's higher everything should be fine. This function can be used together with AlgBitSetPositions() to select all ordered combinations of N of M. Eg to select all ordered combinations of 3 out of 5 this function would return 00111, 01011, 01101, 01110, 10110, 11010, 11100.

Returns
Next bit mask for n bits, or zero on error.
Parameters
curMskCurrent mask value. If the current value is zero then the first valid mask will be computed, otherwise the current mask is assumed to be valid.
nNumber of bits to be set.
mMaximum number of bits to use.
int AlgBitNextSet ( unsigned long  msk,
int  idC 
)

Computes the index of the next bit set in the given mask using the index to the current bit as the start index. maxMsk, the new bit mask is the next after the given current mask.

Returns
Index of the next bit set in the given mask, will be -ve if no next bit set.
Parameters
mskGiven bit mask.
idCCurrent bit index, -ve to find first bit set.
int AlgBitNextPowerOfTwo ( unsigned int *  dstP2I,
unsigned int  gI 
)

Computes the next integer that is >= the given integer and has only a single bit set.

Returns
Index of the single bit that should be set for an unsigned integer that's >= the given int.
Parameters
dstP2IDestination ptr for integer that's >= the given integer and is a power of two.
gIGiven integer.

Referenced by AlgAutoCorrelate2D(), AlgBitIsPowerOfTwo(), AlgCrossCorrelate2D(), WlzAutoCor(), WlzFourierTransformObj(), WlzLBTBalanceDomain2D(), WlzLBTBalanceDomain3D(), WlzMakeLBTDomain2D(), WlzMakeLBTDomain3D(), WlzMakeTiledValuesObj2D(), WlzMakeTiledValuesObj3D(), and WlzRegCCorObjs().

int AlgBitIsPowerOfTwo ( unsigned int  gI)

Checks that the given integer is an integral power of two.

Returns
Non zero if the given integer is an integral power of two.
Parameters
gIGiven integer.

References AlgBitNextPowerOfTwo().

unsigned int AlgGrayCode ( unsigned int  g)

Computes the Gray code of the given value.

Returns
Gray code of the given integer.
Parameters
gGiven integer.
unsigned long long AlgGrayCodeLL ( unsigned long long  g)

Computes the Gray code of the given value.

Returns
Gray code of the given integer.
Parameters
gGiven long integer.
unsigned int AlgGrayCodeInv ( unsigned int  g)

Computes the inverse Gray code, ie the value corresponding to the given Gray code.

Returns
Integer corresponding to the given Gray code.
Parameters
gGiven Gray code.
unsigned long long AlgGrayCodeInvLL ( unsigned long long  g)

Computes the inverse Gray code, ie the value corresponding to the given Gray code.

Returns
Integer corresponding to the given Gray code.
Parameters
gGiven Gray code.
void AlgHilbertIndex ( unsigned int *  h,
unsigned int *  p,
int  n,
int  o 
)

Computes the Hilbert index of a point in n dimensions.

Parameters
hHilbert index (set on return).
pPosition of the n dimensional point.
nNumber of dimensions.
oOrder (number of bits for coordinate).

Referenced by WlzGreySetHilbertRankValues().

void AlgHilbertIndexInv ( unsigned int *  h,
unsigned int *  p,
int  n,
int  o 
)

Computes the coordinates of the point in n dimensions corresponding to the given Hilbert index.

Parameters
hThe given Hilbert index.
pDecoded point coordinates (set on return).
nNumber of dimensions.
oOrder (number of bits for coordinate).