DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Data Structures | Public Types | Public Member Functions | Data Fields | Static Public Attributes | Protected Member Functions | Protected Attributes | Static Protected Attributes
DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey > Class Template Reference

#include <ImageContainerByHashTree.h>

Collaboration diagram for DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >:
Collaboration graph
[legend]

Data Structures

class  Iterator
class  Node

Public Types

typedef
ImageContainerByHashTree
< TDomain, TValue, THashKey > 
Self
typedef THashKey HashKey
typedef TDomain Domain
typedef Domain::Point Point
typedef Domain::Vector Vector
typedef Domain::Integer Integer
typedef Domain::Size Size
typedef Domain::Dimension Dimension
typedef Point Vertex
typedef TValue Value
typedef ConstRangeAdapter
< typename
Domain::ConstIterator, Self,
Value
ConstRange
typedef SetValueIterator< SelfOutputIterator

Public Member Functions

 BOOST_CONCEPT_ASSERT ((CDomain< TDomain >))
 BOOST_STATIC_ASSERT ((boost::is_same< Domain, HyperRectDomain< SpaceND< dimension, Integer > > >::value))
 BOOST_CONCEPT_ASSERT ((CLabel< TValue >))
 ImageContainerByHashTree (const unsigned int hashKeySize, const unsigned int depth, const Value defaultValue)
 ImageContainerByHashTree (const unsigned int hashKeySize, const Point &p1, const Point &p2, const Value defaultValue)
 ImageContainerByHashTree (const Domain &aDomain, const unsigned int hashKeySize=3, const Value defaultValue=NumberTraits< Value >::ZERO)
const Domaindomain () const
ConstRange range () const
OutputIterator outputIterator ()
Value get (const HashKey key) const
Value operator() (const HashKey key) const
Value operator() (const Point &aPoint) const
Value get (const Point &aPoint) const
Value upwardGet (const HashKey key) const
Value reverseGet (const HashKey key) const
void setValue (const HashKey key, const Value object)
void setValue (const Point &aPoint, const Value object)
unsigned int getSpanSize () const
unsigned int getDepth () const
bool isKeyValid (HashKey key) const
bool checkIntegrity (HashKey key=ROOT_KEY, bool leafAbove=false) const
HashKey getKey (const Point &aPoint) const
unsigned int getKeyDepth (HashKey key) const
int * getCoordinatesFromKey (HashKey key) const
void printState (std::ostream &out, bool displayKeys=false) const
void printTree (HashKey key, std::ostream &out, bool displayKeys) const
void printInternalState (std::ostream &out, unsigned int nbBits=0) const
void printInfo (std::ostream &out) const
unsigned int getNbEmptyLists () const
double getAverageCollisions () const
unsigned int getMaxCollisions () const
unsigned int getNbNodes (unsigned int intermediateKey) const
unsigned int getNbNodes () const
Iterator begin ()
Iterator end ()
void selfDisplay (std::ostream &out)
bool isValid () const
std::string className () const
NodegetNode (const HashKey key) const

Data Fields

int myDebugCounter
Point myOrigin
Morton< HashKey, PointmyMorton

Static Public Attributes

static const Domain::Dimension dimension = Domain::dimension
static const Domain::Dimension dim = Domain::dimension
static const unsigned int NbChildrenPerNode = POW<2, dimension>::VALUE
static const HashKey ROOT_KEY = static_cast<HashKey>(1)

Protected Member Functions

template<typename C >
void recursiveDraw (HashKey key, const double p1[2], const double len, Board2D &board, const C &cmap) const
HashKey getIntermediateKey (const HashKey key) const
NodeaddNode (const Value object, const HashKey key)
bool removeNode (HashKey key)
void recursiveRemoveNode (HashKey key, unsigned int nbRecursions)
void setDepth (unsigned int depth)
Value blendChildren (HashKey key) const

Protected Attributes

Domain myDomain
Node ** myData
unsigned int myKeySize
unsigned int myArraySize
unsigned int myTreeDepth
unsigned int mySpanSize
HashKey myDepthMask
HashKey myPreComputedIntermediateMask

Static Protected Attributes

static const unsigned int myN = POW<2,dim>::VALUE

Detailed Description

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
class DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >

Model of CImageContainer implementing the association key<->Value using a hash tree. This class provides a built-in iterator.

Description of template class 'ImageContainerByHashTree'

Todo:
doc here

The ImageContainerByHashTree relies on a tree model implemented using a hash table based on Morton Codes. A Morton hash key is obtained from coordinates by interleaving the binary representations of the coordinate values. This means the coordinates have to be of integer type for the morton code to be valid.

The data can be accessed using keys, coordinates or Iterators provided by the container.

The parent of a given key can be found by simply shifting to the left the key's bits by it's dimension. exemples: for an octree (N = 3) the parent key of the key 1110100001 is 1110100. for a quadtree (N = 2) the parent key of the key 10010111 is 100101.

It is then easy to determine, for a N-Dimmensionnal container, all the children keys of a given key, by concatenating any combination of N bits at the right side of the key (least important bits). exemple: for a quadtree (N = 2) 1010100, 1010101, 1010110 and 1010111 are the children of 10101.

In order to disgard any ambiguous case, we need to make the assertion that the root of the hash is at key 1. Else we would have to deal with the problem of the key 00000..0 which would have one of it's children equal to 0 and so on... This means that we need to set the key's N*maxDepth bit to 1 after interleaving the corrdinates bit for key generation.

Note that not any combination of bits is valid. We saw the exemple of the key 0, and there are other cases of invalidity. For a key to be valid, the last set bit (most important set bit) must be at a position of the form k*N with N the Dimmension of the Domain and k a positive integer. exemples: for an octree(N = 3) 1, 1000, 1010111 are valid keys, whereas 0, 10, 11101 are not !

Warning ! For performances this container's access method never check for a key's validity. Trying to access an invalid key may destroy the validity of the tree's structure and/or get the program stuck into an infinite loop.

The method isKeyValid(..) is provided to verify the validity of a key. Note that using this security strongly affects performances.

Template Parameters:
TDomaintype of domains
TValuetype for image values THashKey type to store Morton keys (default: DGtal::uint64_t)
See also:
testImageContainerByHashTree.cpp

Definition at line 124 of file ImageContainerByHashTree.h.


Member Typedef Documentation

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef ConstRangeAdapter<typename Domain::ConstIterator, Self, Value > DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ConstRange

Definition at line 161 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef Domain::Dimension DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Dimension

Definition at line 144 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef TDomain DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Domain

Definition at line 139 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef THashKey DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::HashKey

Definition at line 135 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef Domain::Integer DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Integer

Definition at line 142 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef SetValueIterator<Self> DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::OutputIterator

output iterator

Definition at line 164 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef Domain::Point DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Point

Definition at line 140 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef ImageContainerByHashTree<TDomain, TValue, THashKey> DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Self

Definition at line 128 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef Domain::Size DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Size

Definition at line 143 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef TValue DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Value

Definition at line 160 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef Domain::Vector DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Vector

Definition at line 141 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
typedef Point DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Vertex

Definition at line 145 of file ImageContainerByHashTree.h.


Constructor & Destructor Documentation

template<typename Domain , typename Value , typename HashKey >
DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::ImageContainerByHashTree ( const unsigned int  hashKeySize,
const unsigned int  depth,
const Value  defaultValue 
)
inline

The constructor from a hashKeySize, a depth and a defaultValue.

Parameters:
hashKeySizeNumber of bit of the hash key. This parameter is important as it influences the amount of collisions in the hash table. A value K creates an array of length 2^K with potential unused cells so a compromise between speed and memory usage is to be done here.
depthDetermines the maximum depth of the tree and thus qthe "size" of the image. Each span then extends from 0 to 2^depth.
defaultValueIn order for the tree to be valid it needs a default value at the root (key = 1)

Definition at line 63 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::addNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, DGtal::Trace::error(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myArraySize, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myOrigin, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myPreComputedIntermediateMask, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ROOT_KEY, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::setDepth(), and DGtal::trace.

: myDomain( Domain() ), myKeySize ( hashKeySize )
{
//Consistency check of the hashKeysize
ASSERT ( hashKeySize <= sizeof ( HashKey ) *8 );
myOrigin = Point::zero;
myPreComputedIntermediateMask = ~ ( static_cast<HashKey> ( ~0 ) << myKeySize );
unsigned int acceptedDepth = ( ( sizeof ( HashKey ) * 8 - 1 ) / dim );
if ( depth > acceptedDepth )
{
trace.error() << "ImageContainerByHashTree::Constructor: error !" << endl;
trace.error() << "requested depth too high for the key type" << endl;
trace.error() << "accepted: " << acceptedDepth << " Requested: " << depth << endl;
setDepth ( acceptedDepth );
}
else
setDepth ( depth );
//init the array
myData = new Node*[myArraySize];
for ( unsigned i = 0; i < myArraySize; ++i )
myData[i] = 0;
addNode ( defaultValue, ROOT_KEY );
}
template<typename Domain , typename Value , typename HashKey >
DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::ImageContainerByHashTree ( const unsigned int  hashKeySize,
const Point p1,
const Point p2,
const Value  defaultValue 
)
inline

The constructor from a hashKeySize, a defaultValue and a pair of points. In this case, the depth of the tree is given by the logarithm of the domain size defined by the two points.

Parameters:
hashKeySizeNumber of bit of the hash key. This parameter is important as it influences the amount of collisions in the hash table. A value K creates an array of length 2^K with potential unused cells so a compromise between speed and memory usage is to be done here.
p1First point of the image bounding box.
p1Second point of the image bounding box.
defaultValueIn order for the tree to be valid it needs a default value at the root (key = 1)

Definition at line 147 of file ImageContainerByHashTree.ih.

References DGtal::Trace::error(), and DGtal::trace.

: myDomain( p1, p2 ), myKeySize ( hashKeySize ), myOrigin ( p1 )
{
//Consistency check of the hashKeysize
ASSERT ( hashKeySize <= sizeof ( HashKey ) *8 );
myPreComputedIntermediateMask = ~ ( static_cast<HashKey> ( ~0 ) << myKeySize );
int maxSize = 0;
for ( unsigned int i = 0; i < dim; ++i )
if ( maxSize < p1[i] - p2[i] )
maxSize = p1[i] - p2[i];
unsigned int depth = (unsigned int)(ceil ( log ( (double) maxSize ) / log((double) 2.0) ));
unsigned int acceptedDepth = ( ( sizeof ( HashKey ) * 8 - 1 ) / dim );
if ( depth > acceptedDepth )
{
trace.error() << "ImageContainerByHashTree::Constructor: error !"
<< " requested depth too high for the key type" << endl;
trace.error() << "accepted: " << acceptedDepth
<< " Requested: " << depth << endl;
setDepth ( acceptedDepth );
}
else
setDepth ( depth );
//init the array
myArraySize = 1 << hashKeySize;
myData = new Node*[myArraySize];
for ( unsigned int i = 0; i < myArraySize; ++i )
myData[i] = 0;
//add the default value
addNode ( defaultValue, ROOT_KEY );
}
template<typename Domain , typename Value , typename HashKey >
DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::ImageContainerByHashTree ( const Domain aDomain,
const unsigned int  hashKeySize = 3,
const Value  defaultValue = NumberTraits<Value>::ZERO 
)
inline

The constructor from a domain, a defaultValue (default value: 0) and a hashKeySize (default value: 3). In this case, the depth of the tree is given by the logarithm of the domain size defined by the two points.

Parameters:
aDomainthe image domain
hashKeySizeNumber of bit of the hash key. This parameter is important as it influences the amount of collisions in the hash table. A value K creates an array of length 2^K with potential unused cells so a compromise between speed and memory usage is to be done here (default: 3).
defaultValueIn order for the tree to be valid it needs a default value at the root (key = 1)

Definition at line 101 of file ImageContainerByHashTree.ih.

References DGtal::Trace::error(), and DGtal::trace.

:
myDomain(aDomain), myKeySize ( hashKeySize )
{
myOrigin = aDomain.lowerBound() ;
//Consistency check of the hashKeysize
ASSERT ( hashKeySize <= sizeof ( HashKey ) *8 );
Point p1 = myDomain.lowerBound();
Point p2 = myDomain.upperBound();
myPreComputedIntermediateMask = ~ ( static_cast<HashKey> ( ~0 ) << myKeySize );
int maxSize = 0;
for ( unsigned int i = 0; i < dim; ++i )
if ( maxSize < p1[i] - p2[i] )
maxSize = p1[i] - p2[i];
unsigned int depth = (unsigned int)(ceil ( log ( (double) maxSize ) / log((double) 2.0) ));
unsigned int acceptedDepth = ( ( sizeof ( HashKey ) * 8 - 1 ) / dim );
if ( depth > acceptedDepth )
{
trace.error() << "ImageContainerByHashTree::Constructor: error !"
<< " requested depth too high for the key type" << endl;
trace.error() << "accepted: " << acceptedDepth
<< " Requested: " << depth << endl;
setDepth ( acceptedDepth );
}
else
setDepth ( depth );
//init the array
myArraySize = 1 << hashKeySize;
myData = new Node*[myArraySize];
for ( unsigned int i = 0; i < myArraySize; ++i )
myData[i] = 0;
//add the default value
addNode ( defaultValue, ROOT_KEY );
}

Member Function Documentation

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Node* DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::addNode ( const Value  object,
const HashKey  key 
)
inlineprotected

Add a Node to the tree. This method is very used when writing in the tree (set method). As detailed in the inner class Node, nodes are pairs (value,key)

Parameters:
objecta object (value)
keya hashtree key
Returns:
a pointer to the node list.

Definition at line 671 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getIntermediateKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::setNext().

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree().

{
Node* n = getNode(key);
if (n)
{
n->getObject() = object;
//n->setObject(object);
return n;
}
n = new Node(object, key);
n->setNext(myData[key2]);
myData[key2] = n;
return n;
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Iterator DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::begin ( )
inline

Returns an iterator to the first value as stored in the container.

Definition at line 542 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myArraySize, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData.

{
return Iterator(myData, 0, myArraySize);
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::blendChildren ( HashKey  key) const
protected

Recursively get the value of all the leafs below and blend it to get the value of a parent node. This is called in the get() method when it has been determined that the leafs are deeper than the requested key.

Definition at line 813 of file ImageContainerByHashTree.ih.

References DGtal::Morton< THashKey, TPoint >::childrenKeys(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myMorton, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN.

{
Node* n = getNode ( key );
if ( n )
{
return n->getObject();
}
else
{
HashKey children[myN];
myMorton.childrenKeys ( key, children );
float result = 0;
for ( unsigned int i = 0; i < myN; ++i )
{
result += blendChildren ( children[i] );
}
return static_cast<Value> ( result / myN );
}
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::BOOST_CONCEPT_ASSERT ( (CDomain< TDomain >)  )

domain

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::BOOST_CONCEPT_ASSERT ( (CLabel< TValue >)  )

values range

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::BOOST_STATIC_ASSERT ( (boost::is_same< Domain, HyperRectDomain< SpaceND< dimension, Integer > > >::value)  )

domain should be rectangular

template<typename Domain , typename Value , typename HashKey >
bool DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::checkIntegrity ( HashKey  key = ROOT_KEY,
bool  leafAbove = false 
) const

Checks recursively that the sub-tree starting with key is valid. A tree is valid if there's one (and only one) leaf for each position at maximal depth.

Parameters:
keythe key
leafAbove

Definition at line 836 of file ImageContainerByHashTree.ih.

References DGtal::Bits::bitString(), DGtal::Morton< THashKey, TPoint >::childrenKeys(), DGtal::Trace::error(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getKeyDepth(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode(), DGtal::Trace::info(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::isKeyValid(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myMorton, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth, and DGtal::trace.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::isValid().

{
trace.info() << "Checking key=" << key << endl;
if ( !isKeyValid ( key ) )
{
trace.error() << "checkIntegrity->invalid key " << Bits::bitString ( key );
trace.info() << endl;
ASSERT ( 1 == 0 );
}
Node* n = getNode ( key );
if ( ( n != 0 ) && ( leafAbove ) )
{
trace.error() << "ImageContainerByHashTree::checkIntegrity - error:" << endl
<< "at key " << Bits::bitString ( key ) << endl
<< "several leafs found" << endl;
return false;
}
if ( getKeyDepth ( key ) >= myTreeDepth )
{
if ( leafAbove || n )
{
return true;
}
else
{
trace.error() << "ImageContainerByHashTree::checkIntegrity - error:" << endl
<< "at key " << Bits::bitString ( key ) << endl
<< "no leaf found" << endl;
return false;
}
}
HashKey children[myN];
myMorton.childrenKeys ( key, children );
bool returnValue = true;
for ( unsigned int i = 0; i < myN; ++i )
returnValue &= checkIntegrity ( children[i], ( n || leafAbove ) );
return returnValue;
}
template<typename Domain , typename Value , typename HashKey >
std::string DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::className ( ) const
inline

Default drawing style object.

Returns:
the dyn. alloc. default style for this object.
the style name used for drawing this object.

Definition at line 806 of file ImageContainerByHashTree.ih.

{
return "ImageContainerByHashTree";
}
template<typename Domain , typename Value , typename HashKey >
const ImageContainerByHashTree< Domain, Value, HashKey >::Domain & DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::domain ( ) const
inline

Copy contructor.

Parameters:
otherobject to copy. Assignment.
otherobject to copy. Destructor Free the memory allocated by myData
Returns:
the domain associated to the image.

Definition at line 194 of file ImageContainerByHashTree.ih.

{
return myDomain;
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Iterator DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::end ( )
inline

Returns an iterator to the last value as stored in the container.

Definition at line 550 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myArraySize, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData.

{
return Iterator(myData, myArraySize, myArraySize);
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::get ( const HashKey  key) const
inline

Returns the value corresponding to a key.

This is the generic method working with any valid key. For efficiency no check is performed on the key so be careful when calling this method. If the leafs are deeper than the requested key, this method will recursively browse through the children nodes and compute a average of each child's value using blendChildren(..) which is very slow. Thus performances are much better when accessing a leaf from a deeper key (needs no blending).

Parameters:
keythe haskkey
Returns:
the value

Definition at line 322 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject().

{
HashKey iterKey = key;
// node above the requested node
while ( iterKey != 0 )
{
Node* n = getNode ( iterKey );
if ( n )
return n->getObject();
iterKey >>= dim;
}
//if the node is deeper than the one requested
return blendChildren ( key );
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::get ( const Point aPoint) const
inline

Returns the value at a given coordinate using upwardGet().

Parameters:
aPointThe point
Returns:
the value

Definition at line 369 of file ImageContainerByHashTree.ih.

{
return get ( getKey ( aPoint ) );
}
template<typename Domain , typename Value , typename HashKey >
double DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getAverageCollisions ( ) const
inline

Returns The average number of collisions in the hash table, without counting the empty places.

Definition at line 757 of file ImageContainerByHashTree.ih.

References DGtal::Trace::error(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbNodes(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize, and DGtal::trace.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

{
double count = 0;
double nbLists = 0;
unsigned int arraySize = 1 << myKeySize;
for ( unsigned int i = 0; i < arraySize; ++i )
{
if ( myData[i] )
{
count += getNbNodes ( i ) - 1;
nbLists++;
}
}
if ( nbLists == 0 )
{
trace.error() << "ImageContainerByHashTree::getAverageCollision() - error" << endl
<< "the container is empty !" << endl;
return 0;
}
return count / nbLists;
}
template<typename Domain , typename Value , typename HashKey >
int * DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getCoordinatesFromKey ( HashKey  key) const
inline

Definition at line 539 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, and DGtal::Bits::mask().

{
//remove the first bit equal 1
for ( int i = ( sizeof ( HashKey ) << 3 ) - 1; i >= 0; --i )
{
if ( key & Bits::mask<HashKey> ( i ) )
{
key &= ~Bits::mask<HashKey> ( i );
break;
}
}
int* coordinates = new int[dim];
//deinterleave the bits
for ( unsigned int i = 0; i < dim; ++i )
{
coordinates[i] = 0;
for ( unsigned int bitPos = 0; bitPos < ( sizeof ( HashKey ) << 3 ) / dim; ++bitPos )
{
if ( key & Bits::mask ( bitPos*dim + i ) )
{
coordinates[i] |= Bits::mask<HashKey> ( bitPos );
}
}
}
return coordinates;
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getDepth ( ) const
inline

Returns the tree's depth.

Returns:
the depth

Definition at line 371 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth.

{
return myTreeDepth;
}
template<typename Domain , typename Value , typename HashKey >
HashKey DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getIntermediateKey ( const HashKey  key) const
inlineprotected

This is part of the hash function. It is called whenever a key is accessed. The mask used to compute the result is precomputed in the constructor for efficiency.

Parameters:
keya node in the hashtree.

Definition at line 418 of file ImageContainerByHashTree.ih.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::addNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::removeNode().

{
}
template<typename Domain , typename Value , typename HashKey >
HashKey DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getKey ( const Point aPoint) const
inline

Definition at line 401 of file ImageContainerByHashTree.ih.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

{
HashKey result = 0;
Point currentPos = aPoint - myOrigin;
myMorton.interleaveBits ( currentPos, result );
// by convention, the root node has the key 0..01
// it makes it easy to determine the depth of a node by it's key (looking
// at the position of the most significant bit that is equal to 1)
result |= myDepthMask;
return result;
}
template<typename Domain , typename Value , typename HashKey >
unsigned int DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getKeyDepth ( HashKey  key) const
inline

Definition at line 525 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::isKeyValid(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printTree().

{
for ( int i = ( sizeof ( HashKey ) << 3 ) - 1; i >= 0; --i )
if ( key & ( static_cast<HashKey> ( 1 ) << i ) )
{
return ( i ) / dim;
}
return 0;
}
template<typename Domain , typename Value , typename HashKey >
unsigned int DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getMaxCollisions ( ) const
inline

Returns the highest number of collisions in the hash table.

Definition at line 784 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbNodes(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

{
unsigned int count = 0;
unsigned int arraySize = 1 << myKeySize;
for ( unsigned int i = 0; i < arraySize; ++i )
{
if ( myData[i] )
{
unsigned int collision = getNbNodes ( i ) - 1;
if ( collision > count )
{
count = collision;
}
}
}
return count;
}
template<typename Domain , typename Value , typename HashKey >
unsigned int DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getNbEmptyLists ( ) const
inline

Returns the number of empty places in the hash table.

Definition at line 741 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

{
unsigned int count = 0;
unsigned int arraySize = 1 << myKeySize;
for ( unsigned int i = 0; i < arraySize; ++i )
{
if ( !myData[i] )
count++;
}
return count;
}
template<typename Domain , typename Value , typename HashKey >
unsigned int DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getNbNodes ( unsigned int  intermediateKey) const
inline

Returns the number of elements for a given key of the hash table.

Parameters:
intermediateKeya hashtree key.

Definition at line 702 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getNext(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData.

{
if ( !myData[intermediateKey] )
{
return 0;
}
else
{
unsigned int count = 1;
Node* n = myData[intermediateKey]->getNext();
while ( n )
{
++count;
n = n->getNext();
}
return count;
}
}
template<typename Domain , typename Value , typename HashKey >
unsigned int DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::getNbNodes ( ) const
inline

Returns the total amount of elements in the container.

Definition at line 726 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getAverageCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getMaxCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

{
unsigned int count = 0;
unsigned int arraySize = 1 << myKeySize;
for ( unsigned int i = 0; i < arraySize; ++i )
{
count += getNbNodes ( i );
}
return count;
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Node* DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode ( const HashKey  key) const
inline

Returns a pointer to the node corresponding to the key. If it does'nt exist, returns 0. This method is called VERY often, and thus should operate as fast as possible.

Parameters:
keyThe key.
Returns:
the pointer to the node corresponding to the key.

Definition at line 695 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getIntermediateKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getNext(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::addNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::blendChildren(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity(), DGtal::Display2DFactory::drawImageRecursive(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printTree().

{
Node* iter = myData[getIntermediateKey(key)];
while (iter != 0)
{
if (iter->getKey() == key)
return iter;
iter = iter->getNext();
}
return 0;
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getSpanSize ( ) const
inline

Returns the size of a dimension (the container represents a line, a square, a cube, etc. depending on the dimmension so no need for distinctions between width, height, ect.)

Returns:
the dimension size

Definition at line 362 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::mySpanSize.

Referenced by DGtal::Display2DFactory::drawImageHashTree(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

{
return mySpanSize;
}
template<typename Domain , typename Value , typename HashKey >
bool DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::isKeyValid ( HashKey  key) const
inline

Returns true if the key is valid. A key is valid if the the most important bit that is equal to 1 is at a position of the type dim*k with dim the dimmension of the container (template parameter) and k a strictly positive integer.

Parameters:
keythe key
Returns:
the boolean result

Definition at line 570 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getKeyDepth(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity().

{
if ( !key )
return false;
if ( getKeyDepth ( key ) > myTreeDepth )
return false;
int i = ( sizeof ( HashKey ) << 3 ) - 1;
for ( ; i >= 0; --i )
if ( key & ( static_cast<HashKey> ( 1 ) << i ) )
break;
if ( i % dim )
{
return false;
}
return true;
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
bool DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::isValid ( ) const
inline

Definition at line 557 of file ImageContainerByHashTree.h.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity().

{
return checkIntegrity();
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::operator() ( const HashKey  key) const
inline

Returns the value at a given key.

Parameters:
keythe hash key used as an index.
Returns:
the value

Definition at line 309 of file ImageContainerByHashTree.ih.

{
return get ( key );
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::operator() ( const Point aPoint) const
inline

Returns the value at a given point.

Parameters:
aPointThe point
Returns:
the value

Definition at line 315 of file ImageContainerByHashTree.ih.

{
return get ( aPoint );
}
template<typename Domain , typename Value , typename HashKey >
ImageContainerByHashTree< Domain, Value, HashKey >::OutputIterator DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::outputIterator ( )
inline
Returns:
an output iterator used to write values.

Definition at line 212 of file ImageContainerByHashTree.ih.

{
return OutputIterator( *this );
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::printInfo ( std::ostream &  out) const
inline

Prints informations about the state of the container without displaying the data:

- Nunber of elements in the tree.
- Amount of unused disk space due to blanks in the hash table.
- The dimmension.
- The number of bits of the HashKey.
- The size of the image.
- The average and the maximum amount of collisions.
- The total memory usage.
Parameters:
outoutput stream.

Definition at line 683 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getAverageCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getMaxCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbEmptyLists(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbNodes(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getSpanSize(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::selfDisplay().

{
unsigned int nbNodes = getNbNodes();
unsigned int totalSize = sizeof ( *this ) + ( 1 << myKeySize ) * sizeof ( Node* ) + nbNodes * sizeof ( Node );
out << "[ImageContainerByHashTree]: Dimension=" << ( int ) dim << ", HashKey size="
<< myKeySize << ", Depth=" << myTreeDepth << ", image size=" << getSpanSize()
<< "^" << ( int ) dim << " (" << std::pow ( ( double ) getSpanSize(), ( double ) dim ) *sizeof ( Value )
<< " bytes)" << ", " << nbNodes << " nodes" << ", Empty lists=" << getNbEmptyLists()
<< " (" << getNbEmptyLists() *sizeof ( Node* ) << " bytes)" << ", Average collisions=" << getAverageCollisions()
<< ", Max collisions " << getMaxCollisions()
<< ", total memory usage=" << totalSize << " bytes" << endl;
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::printInternalState ( std::ostream &  out,
unsigned int  nbBits = 0 
) const
inline

Prints the state of the container in a way that displays the hash table and every node as it is stored in memory instead of the usual tree representation.

Parameters:
outoutput stream.
nbBits

Definition at line 641 of file ImageContainerByHashTree.ih.

References DGtal::Bits::bitString(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getAverageCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getMaxCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbEmptyLists(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbNodes(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getNext(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getSpanSize(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myDepthMask, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth.

{
out << "ImageContainerByHashTree::printInternalState ----------------------------------" << endl;
out << "| <template> dim = " << dim << " myN = " << myN << endl;
out << "| tree depth = " << myTreeDepth << " mask = " << Bits::bitString ( myDepthMask ) << endl;
for ( unsigned int i = 0; i < ( 1 << myKeySize ); ++i )
{
out << "| " << Bits::bitString ( i, myKeySize ) << " [";
if ( myData[i] )
{
out << "-]->(";
if ( nbBits )
out << Bits::bitString ( myData[i]->getKey(), nbBits ) << ":";
out << myData[i]->getObject() << ")";
Node* iter = myData[i]->getNext();
while ( iter )
{
out << "->(";
if ( nbBits )
out << Bits::bitString ( myData[i]->getKey(), nbBits ) << ":";
out << iter->getObject() << ")";
iter = iter->getNext();
}
out << endl;
}
else
{
cout << "x]" << endl;
}
}
out << "| image size: " << getSpanSize() << "^" << dim << " (" << std::pow ( getSpanSize(), dim ) *sizeof ( Value ) << " bytes)" << endl;
out << "| " << getNbNodes() << " nodes - Empty lists: " << getNbEmptyLists() << " (" << getNbEmptyLists() *sizeof ( Node* ) << " bytes)" << endl;
out << "| Average collisions: " << getAverageCollisions() << " - Max collisions " << getMaxCollisions() << endl;
out << "----------------------------------------------------------------" << endl;
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::printState ( std::ostream &  out,
bool  displayKeys = false 
) const
inline

Definition at line 597 of file ImageContainerByHashTree.ih.

References DGtal::Bits::bitString(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myDepthMask, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printTree(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ROOT_KEY.

{
out << "ImageContainerByHashTree::printState" << endl;
out << "depth: " << myTreeDepth << " (" << Bits::bitString ( myDepthMask ) << ")" << endl;
out << "dim: " << dim << "myN: " << myN << endl;
printTree ( ROOT_KEY, out, displayKeys );
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::printTree ( HashKey  key,
std::ostream &  out,
bool  displayKeys 
) const
inline

Prints the sub-tree starting with the node corresponding to key.

Parameters:
keyroot of the subtree to display
outoutput stream.
displayKeysboolean to decide if keys are displayed .

Definition at line 608 of file ImageContainerByHashTree.ih.

References DGtal::Bits::bitString(), DGtal::Morton< THashKey, TPoint >::childrenKeys(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getKeyDepth(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myMorton, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printState().

{
unsigned int level = getKeyDepth ( key );
for ( unsigned int i = 0; i < level; ++i )
out << " ";
Node* n = getNode ( key );
if ( n )
{
out << " < " << n->getObject() << " > ";
if ( displayKeys )
out << Bits::bitString ( key, 8 );
out << endl;
}
else
{
out << " < x > ";
if ( displayKeys )
out << Bits::bitString ( key, 8 );
out << endl;
}
if ( level < myTreeDepth )
{
HashKey children[myN];
myMorton.childrenKeys ( key, children );
for ( unsigned int i = 0; i < myN; ++i )
printTree ( children[i], out, displayKeys );
}
}
template<typename Domain , typename Value , typename HashKey >
ImageContainerByHashTree< Domain, Value, HashKey >::ConstRange DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::range ( ) const
inline
Returns:
an instance of ConstRange used to iterate over the values.

Definition at line 203 of file ImageContainerByHashTree.ih.

{
return ConstRange( myDomain.begin(), myDomain.end(), *this );
}
template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
template<typename C >
void DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::recursiveDraw ( HashKey  key,
const double  p1[2],
const double  len,
Board2D board,
const C &  cmap 
) const
protected
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::recursiveRemoveNode ( HashKey  key,
unsigned int  nbRecursions 
)
inlineprotected

Recusrively calls RemoveNode on the key and its children.

Parameters:
keyThe key.
nbRecursionsthe number of recursions performed.

Definition at line 489 of file ImageContainerByHashTree.ih.

References DGtal::Morton< THashKey, TPoint >::childrenKeys(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myMorton, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::removeNode().

{
if ( removeNode ( key ) )
return;
if ( --nbRecursions > 0 )
{
HashKey children[myN];
myMorton.childrenKeys ( key, children );
for ( unsigned int i = 0; i < myN; ++i )
{
recursiveRemoveNode ( children[i], nbRecursions );
}
}
}
template<typename Domain , typename Value , typename HashKey >
bool DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::removeNode ( HashKey  key)
inlineprotected

Remove the node corresponding to a key. Returns false if the node doesn't exist.

Parameters:
keyThe key

Definition at line 458 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getIntermediateKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getNext(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::setNext().

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::recursiveRemoveNode().

{
HashKey key2 = getIntermediateKey ( key );
Node* iter = myData[key2];
// if the node is the first in the list we have to modify the pointer stored in myData
if ( iter && ( iter->getKey() == key ) )
{
myData[key2] = iter->getNext();
delete iter;
return true;
}
while ( iter )
{
Node* next = iter->getNext();
if ( next )
{
if ( next->getKey() == key )
{
iter->setNext ( next->getNext() );
delete next;
return true;
}
}
iter = iter->getNext();
}
return false;
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::reverseGet ( const HashKey  key) const
inline

A attempt to do the same thing as get(HashKey) but looking for deeper leafs in the first place instead of doing this in the second place. It hasn't show better results so far.

Parameters:
keyThe key.
Returns:
the value

Definition at line 341 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject().

{
HashKey iterKey = key;
// node above the requested node
HashKey limit = myDepthMask << 1;
while ( iterKey < limit )
{
Node* n = getNode ( iterKey );
if ( n )
return blendChildren ( key );
iterKey <<= dim;
}
iterKey = key;
while ( iterKey != 0 )
{
Node* n = getNode ( iterKey );
if ( n )
return n->getObject();
iterKey >>= dim;
}
return 0;
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::selfDisplay ( std::ostream &  out)
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 892 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo().

{
printInfo ( out );
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::setDepth ( unsigned int  depth)
inlineprotected

Set the (maximum) depth of the tree and precompute a mask used for some calculations. The depth of the tree must be known because accessing the data from coordinates depends on it.

Parameters:
depththe maxumum depth.

Definition at line 513 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myDepthMask, DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::mySpanSize, and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree().

{
myTreeDepth = depth;
mySpanSize = 1 << depth;
//precompute the mask
myDepthMask = static_cast<HashKey> ( 1 ) << dim * depth;
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::setValue ( const HashKey  key,
const Value  object 
)
inline

Sets the value of an element in the container, creating it if necessary. In order to keep the tree's coherence this method may add and remove several other nodes in the tree so performances strongly depend on wether or not and how much the tree's structure needs to be modified. For efficiency no check is performed on the key

Parameters:
keyThe key
objectThe associated object

Definition at line 230 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject().

{
HashKey brothers[myN-1];
bool broValue = ( key != static_cast<HashKey> ( 1 ) );
myMorton.brotherKeys ( key, brothers );
for ( unsigned int i = 0; i < myN - 1; ++ i )
{
Node* n = getNode ( brothers[i] );
if ( ! ( n && ( n->getObject() == value ) ) )
{
broValue = false;
break;
}
}
if ( broValue )
{
setValue ( myMorton.parentKey ( key ), value );
return;
}
// if the key already exists
Node* n = getNode ( key );
if ( n )
{
n->getObject() = value;
return;
}
//if there's a leaf above the requested node
HashKey iterKey = key;
std::list< HashKey > nodeList;
while ( iterKey != 0 )
{
// cerr << "while(iter)..." << endl;
n = getNode ( iterKey );
if ( n )
{
Value tempVal = n->getObject();
if ( tempVal == value )
return;
removeNode ( iterKey );
for ( typename std::list< HashKey >::iterator it = nodeList.begin();
it != nodeList.end();
it++ )
{
// cerr << "adding a node ("<< bits::bitString(*it, 8)<<")" << endl;
addNode ( tempVal, *it );
}
addNode ( value, key );
//cerr << "return " << endl;
return;
}
else
{
//cerr << " + " << endl;
HashKey brothersH[myN-1];
myMorton.brotherKeys ( iterKey, brothersH );
for ( unsigned int i = 0; i < myN - 1; ++i )
{
nodeList.push_front ( brothersH[i] );
}
}
iterKey >>= dim;
}
addNode ( value, key );
unsigned int nbRecur = myTreeDepth - getKeyDepth ( key ) + 1;
HashKey children[myN];
myMorton.childrenKeys ( key, children );
for ( unsigned int i = 0; i < myN; ++i )
recursiveRemoveNode ( children[i], nbRecur );
return;
}
template<typename Domain , typename Value , typename HashKey >
void DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::setValue ( const Point aPoint,
const Value  object 
)
inline

Sets the value of an element in the container, creating it if necessary. In order to keep the tree's coherence this method may add and remove several other nodes in the tree so performances strongly depend on wether or not and how much the tree's structure needs to be modified. For efficiency no check is performed on the coordinates

Parameters:
keyThe point
objectthe associated object

Definition at line 221 of file ImageContainerByHashTree.ih.

{
setValue ( getKey ( aPoint ), value );
}
template<typename Domain , typename Value , typename HashKey >
Value DGtal::ImageContainerByHashTree< Domain, Value, HashKey >::upwardGet ( const HashKey  key) const
inline

Returns the value corresponding to a key making the assumption that the key is at same depth or deeper than the leaf we are looking for.

Parameters:
keyThe key.
Returns:
the value.

Definition at line 378 of file ImageContainerByHashTree.ih.

References DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getNext(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::Node::getObject().

{
//cerr << "ImageContainerByHashTree::upWardGet" << endl;
HashKey aKey = key;
while ( aKey )
{
HashKey key2 = getIntermediateKey ( aKey );
Node* iter = myData[key2];
while ( iter != 0 )
{
if ( iter->getKey() == aKey )
return iter->getObject();
iter = iter->getNext();
}
aKey >>= dim; // transorm the key to search in an upper level
}
}

Field Documentation

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
const Domain::Dimension DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dim = Domain::dimension
static

Definition at line 149 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getCoordinatesFromKey(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getKeyDepth(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::isKeyValid(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printState(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::setDepth().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
const Domain::Dimension DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::dimension = Domain::dimension
static

static constants

Definition at line 148 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myArraySize
protected

Definition at line 760 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::begin(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::end(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Node** DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myData
protected

The array of linked lists containing all the data

Definition at line 751 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::addNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::begin(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::end(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getAverageCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getMaxCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbEmptyLists(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbNodes(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNode(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::removeNode().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myDebugCounter

Definition at line 395 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
HashKey DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myDepthMask
protected

Precoputed masks to avoid recalculating it all the time

Definition at line 781 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printState(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::setDepth().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Domain DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myDomain
protected

The image domain

Definition at line 746 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myKeySize
protected

The size of the intermediate hashkey. The bigger the less collisions, but at the same time the more chances to have unused memory allocated.

Definition at line 758 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getAverageCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getMaxCollisions(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbEmptyLists(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getNbNodes(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Morton<HashKey, Point> DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myMorton

The morton code computer.

Definition at line 786 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::blendChildren(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity(), DGtal::Display2DFactory::drawImageRecursive(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printTree(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::recursiveRemoveNode().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
const unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myN = POW<2,dim>::VALUE
staticprotected

Definition at line 771 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::blendChildren(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printState(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printTree(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::recursiveRemoveNode().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
Point DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myOrigin

Definition at line 775 of file ImageContainerByHashTree.h.

Referenced by DGtal::Display2DFactory::drawImageHashTree(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
HashKey DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myPreComputedIntermediateMask
protected

Definition at line 782 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::mySpanSize
protected

Definition at line 767 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getSpanSize(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::setDepth().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::myTreeDepth
protected

The depth of the tree

Definition at line 765 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::checkIntegrity(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::getDepth(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::isKeyValid(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInfo(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printInternalState(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printState(), DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printTree(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::setDepth().

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
const unsigned int DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::NbChildrenPerNode = POW<2, dimension>::VALUE
static

Definition at line 150 of file ImageContainerByHashTree.h.

template<typename TDomain, typename TValue, typename THashKey = typename DGtal::uint64_t>
const HashKey DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ROOT_KEY = static_cast<HashKey>(1)
static

Definition at line 151 of file ImageContainerByHashTree.h.

Referenced by DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::ImageContainerByHashTree(), and DGtal::ImageContainerByHashTree< TDomain, TValue, THashKey >::printState().


The documentation for this class was generated from the following files: