DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Data Structures | Public Types | Public Member Functions | Static Public Member Functions | Static Protected Member Functions | Protected Attributes | Private Member Functions
DGtal::Labels< L, TWord > Class Template Reference

#include <Labels.h>

Inheritance diagram for DGtal::Labels< L, TWord >:
Inheritance graph
[legend]
Collaboration diagram for DGtal::Labels< L, TWord >:
Collaboration graph
[legend]

Data Structures

class  ConstEnumerator

Public Types

typedef TWord Word
typedef Labels< L, WordSelf
typedef unsigned int Label
typedef Label SizeType
typedef ConstEnumerator ConstIterator
typedef ConstIterator const_iterator

Public Member Functions

 ~Labels ()
 Labels ()
 Labels (const Self &other)
Selfoperator= (const Self &other)
bool test (Label l) const
Selfset (Label l, bool val=true)
Selfreset (Label l)
Selfflip (Label l)
Selfreset ()
SizeType count () const
void getLabels (std::vector< Label > &labels) const
SizeType index (Label l) const
ConstIterator begin () const
ConstIterator end () const
void selfDisplay (std::ostream &out) const
bool isValid () const

Static Public Member Functions

static SizeType size ()

Static Protected Member Functions

static SizeType _word (Label l)
static SizeType _digit (Label l)
static Word _mask (Label l)

Protected Attributes

Word myLabels [__DGTAL_LABELS_NBWORDS]

Private Member Functions

 BOOST_STATIC_ASSERT ((L >=1))

Detailed Description

template<unsigned int L, typename TWord = DGtal::uint8_t>
class DGtal::Labels< L, TWord >

Aim: Stores a set of labels in {O..L-1} as a sequence of bits.

Description of template class 'Labels'

This class is useful to stores a set of numbers as a characteristic set. It is very similar to a bitset, except it provides more functions, like giving the index of a label (i.e., if (1, 5, 6, 13, 20) are the labels, then 1 has index 0, 5 has index 1, 6 has index 2, 13 has index 3, 20 has index 4.)

Template Parameters:
Lis the maximum number of labels.
TWordthe integer used to store the labels (if L >= log_2( digits( TWord ) ) then several consecutive words are stored.)
See also:
bitset

Definition at line 69 of file Labels.h.


Member Typedef Documentation

template<unsigned int L, typename TWord = DGtal::uint8_t>
typedef ConstIterator DGtal::Labels< L, TWord >::const_iterator

Definition at line 195 of file Labels.h.

template<unsigned int L, typename TWord = DGtal::uint8_t>
typedef ConstEnumerator DGtal::Labels< L, TWord >::ConstIterator

Definition at line 194 of file Labels.h.

template<unsigned int L, typename TWord = DGtal::uint8_t>
typedef unsigned int DGtal::Labels< L, TWord >::Label

Definition at line 77 of file Labels.h.

template<unsigned int L, typename TWord = DGtal::uint8_t>
typedef Labels<L, Word> DGtal::Labels< L, TWord >::Self

Definition at line 76 of file Labels.h.

template<unsigned int L, typename TWord = DGtal::uint8_t>
typedef Label DGtal::Labels< L, TWord >::SizeType

Definition at line 78 of file Labels.h.

template<unsigned int L, typename TWord = DGtal::uint8_t>
typedef TWord DGtal::Labels< L, TWord >::Word

Definition at line 75 of file Labels.h.


Constructor & Destructor Documentation

template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::~Labels ( )
inline

Destructor.

Definition at line 207 of file Labels.ih.

{
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Labels ( )
inline

Constructor.

Definition at line 213 of file Labels.ih.

References DGtal::Labels< L, TWord >::reset().

{
reset();
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Labels ( const Self other)
inline

Copy constructor.

Parameters:
otherthe object to clone.

Definition at line 220 of file Labels.ih.

References DGtal::Labels< L, TWord >::myLabels.

{
std::copy( other.myLabels, other.myLabels + __DGTAL_LABELS_NBWORDS,
}

Member Function Documentation

template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::SizeType DGtal::Labels< L, TWord >::_digit ( Label  l)
inlinestaticprotected

Returns the bit at which is the label l.

Definition at line 192 of file Labels.ih.

Referenced by DGtal::Labels< L, TWord >::_mask(), and DGtal::Labels< L, TWord >::index().

{
return __DGTAL_LABEL_DIGIT_INDEX( l );
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Word DGtal::Labels< L, TWord >::_mask ( Label  l)
inlinestaticprotected

Returns the mask for the label l (1 << _digit( l )).

Definition at line 200 of file Labels.ih.

References DGtal::Labels< L, TWord >::_digit().

Referenced by DGtal::Labels< L, TWord >::flip(), DGtal::Labels< L, TWord >::index(), DGtal::Labels< L, TWord >::reset(), DGtal::Labels< L, TWord >::set(), and DGtal::Labels< L, TWord >::test().

{
return ( (Word) 1 ) << _digit( l );
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::SizeType DGtal::Labels< L, TWord >::_word ( Label  l)
inlinestaticprotected

Returns the word in which is the label l.

Definition at line 184 of file Labels.ih.

Referenced by DGtal::Labels< L, TWord >::flip(), DGtal::Labels< L, TWord >::index(), DGtal::Labels< L, TWord >::reset(), DGtal::Labels< L, TWord >::set(), and DGtal::Labels< L, TWord >::test().

{
return __DGTAL_LABEL_WORD_INDEX( l );
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::ConstIterator DGtal::Labels< L, TWord >::begin ( ) const
inline
Returns:
an iterator pointing on the first valid label.

Definition at line 357 of file Labels.ih.

References DGtal::Labels< L, TWord >::myLabels.

{
return ConstIterator( myLabels, 0 );
}
template<unsigned int L, typename TWord = DGtal::uint8_t>
DGtal::Labels< L, TWord >::BOOST_STATIC_ASSERT ( (L >=1)  )
private
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::SizeType DGtal::Labels< L, TWord >::count ( ) const
inline
Returns:
the number of labels sets.

Definition at line 291 of file Labels.ih.

References DGtal::Labels< L, TWord >::myLabels, and DGtal::Bits::nbSetBits().

{
SizeType n = 0;
const Word* p1 = myLabels;
const Word* p2 = myLabels + __DGTAL_LABELS_NBWORDS;
while ( p1 != p2 )
n += Bits::nbSetBits( *p1++ );
return n;
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::ConstIterator DGtal::Labels< L, TWord >::end ( ) const
inline
Returns:
an iterator pointing after the last valid label.

Definition at line 366 of file Labels.ih.

References DGtal::Labels< L, TWord >::myLabels.

{
return ConstIterator( myLabels, __DGTAL_LABELS_NBWORDS );
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Self & DGtal::Labels< L, TWord >::flip ( Label  l)
inline

Flips l in or out of the set.

Parameters:
lany label in 0..L-1
Returns:
a reference on this.

Definition at line 281 of file Labels.ih.

References DGtal::Labels< L, TWord >::_mask(), DGtal::Labels< L, TWord >::_word(), and DGtal::Labels< L, TWord >::myLabels.

{
myLabels[ _word( l ) ] ^= _mask( l );
return *this;
}
template<unsigned int L, typename TWord >
void DGtal::Labels< L, TWord >::getLabels ( std::vector< Label > &  labels) const
inline

As output, labels[0] contains the label of index 0, labels[1] the label of index 1, and so on.

Parameters:
labels(modified) the (ordered) labels set.

Definition at line 314 of file Labels.ih.

References DGtal::Bits::firstSetBit(), DGtal::Labels< L, TWord >::index(), DGtal::Bits::leastSignificantBit(), and DGtal::Labels< L, TWord >::myLabels.

Referenced by DGtal::Labels< L, TWord >::selfDisplay().

{
labels.clear();
register Word w;
register Word fsb;
const Word* p1 = myLabels;
const Word* p2 = myLabels + __DGTAL_LABELS_NBWORDS;
Label l = 0;
while ( p1 != p2 )
{
w = *p1++;
while ( w ) // extract labels within word
{
fsb = Bits::firstSetBit( w );
labels.push_back( l + Bits::leastSignificantBit( fsb ) );
w -= fsb;
ASSERT( index( labels.back() ) == ( labels.size() - 1 ) );
}
l += __DGTAL_WORD_NBDIGITS;
}
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::SizeType DGtal::Labels< L, TWord >::index ( Label  l) const
inline
Parameters:
lany label in 0..L-1
Returns:
the index of the label l in this set, starting from 0. If the label is not set, returns L (ie. size()).

Definition at line 340 of file Labels.ih.

References DGtal::Labels< L, TWord >::_digit(), DGtal::Labels< L, TWord >::_mask(), DGtal::Labels< L, TWord >::_word(), DGtal::Bits::indexInSetBits(), DGtal::Labels< L, TWord >::myLabels, and DGtal::Bits::nbSetBits().

Referenced by DGtal::Labels< L, TWord >::getLabels().

{
ASSERT( l < L );
const Word* p1 = myLabels;
const Word* p2 = myLabels + _word( l );
register SizeType i = 0;
while ( p1 != p2 )
i += Bits::nbSetBits( *p1++ );
return ( _mask( l ) & *p1 )
? i + Bits::indexInSetBits( *p1, _digit( l ) ) - 1
: L;
}
template<unsigned int L, typename TWord >
bool DGtal::Labels< L, TWord >::isValid ( ) const
inline

Checks the validity/consistency of the object.

Returns:
'true' if the object is valid, 'false' otherwise.

Definition at line 404 of file Labels.ih.

{
return true;
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Self & DGtal::Labels< L, TWord >::operator= ( const Self other)
inline

Assignment.

Parameters:
otherthe object to copy.
Returns:
a reference on 'this'.

Definition at line 229 of file Labels.ih.

References DGtal::Labels< L, TWord >::myLabels.

{
if ( this != &other )
std::copy( other.myLabels, other.myLabels + __DGTAL_LABELS_NBWORDS,
return *this;
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Self & DGtal::Labels< L, TWord >::reset ( Label  l)
inline

Removes l from the set.

Parameters:
lany label in 0..L-1
Returns:
a reference on this.

Definition at line 272 of file Labels.ih.

References DGtal::Labels< L, TWord >::_mask(), DGtal::Labels< L, TWord >::_word(), and DGtal::Labels< L, TWord >::myLabels.

{
myLabels[ _word( l ) ] &= ~_mask( l );
return *this;
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Self & DGtal::Labels< L, TWord >::reset ( )
inline

Clears the set.

Returns:
a reference on this.

Definition at line 240 of file Labels.ih.

References DGtal::Labels< L, TWord >::myLabels.

Referenced by DGtal::Labels< L, TWord >::Labels().

{
Word* p1 = myLabels;
Word* p2 = myLabels + __DGTAL_LABELS_NBWORDS;
while ( p1 != p2 )
*p1++ = (Word) 0;
return *this;
}
template<unsigned int L, typename TWord >
void DGtal::Labels< L, TWord >::selfDisplay ( std::ostream &  out) const
inline

Writes/Displays the object on an output stream.

Parameters:
outthe output stream where the object is written.

Definition at line 382 of file Labels.ih.

References DGtal::Labels< L, TWord >::getLabels().

{
std::vector<Label> v;
this->getLabels( v );
if ( v.empty() )
out << "()";
else
{
out << "(" << v[ 0 ];
for ( SizeType i = 1; i < v.size(); ++i )
out << "," << v[ i ];
out << ")";
}
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::Self & DGtal::Labels< L, TWord >::set ( Label  l,
bool  val = true 
)
inline

If val is true, inserts l in the set, otherwise removes it.

Parameters:
lany label in 0..L-1
valeither true or false.
Returns:
a reference on this.

Definition at line 260 of file Labels.ih.

References DGtal::Labels< L, TWord >::_mask(), DGtal::Labels< L, TWord >::_word(), and DGtal::Labels< L, TWord >::myLabels.

{
if ( val )
myLabels[ _word( l ) ] |= _mask( l );
else
myLabels[ _word( l ) ] &= ~_mask( l );
return *this;
}
template<unsigned int L, typename TWord >
DGtal::Labels< L, TWord >::SizeType DGtal::Labels< L, TWord >::size ( )
inlinestatic
Returns:
the total maximum possible number of labels sets, i.e. template parameter L.

Definition at line 305 of file Labels.ih.

{
return L;
}
template<unsigned int L, typename TWord >
bool DGtal::Labels< L, TWord >::test ( Label  l) const
inline
Parameters:
lany label in 0..L-1
Returns:
'true' iff this label is set.

Definition at line 252 of file Labels.ih.

References DGtal::Labels< L, TWord >::_mask(), DGtal::Labels< L, TWord >::_word(), and DGtal::Labels< L, TWord >::myLabels.

{
return _mask( l ) & myLabels[ _word( l ) ];
}

Field Documentation

template<unsigned int L, typename TWord = DGtal::uint8_t>
Word DGtal::Labels< L, TWord >::myLabels[__DGTAL_LABELS_NBWORDS]
protected

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