Public Member Functions | Private Member Functions | Private Attributes

chomp::homology::tNeighbors< coordtype > Class Template Reference

This class can be used for iterating point's neighbors. More...

#include <pointset.h>

List of all members.

Public Member Functions

 tNeighbors (const coordtype *_source=NULL, int _dim=0, const coordtype *_wrap=NULL)
 The only possible constructor for new objects.
 tNeighbors (const tNeighbors< coordtype > &r)
 The copy constructor.
tNeighborsoperator= (const tNeighbors< coordtype > &r)
 The assignment operator.
 ~tNeighbors ()
 The destructor.
coordtype * get ()
 Returns the next neighbor.
void reset ()
 Resets the neighbors to the first one.
void set (coordtype *_source)
 Redefines the source (and doesn't change other variables).

Private Member Functions

void initialize (const coordtype *_source=NULL, int _dim=0, const coordtype *_wrap=NULL)
 Initializes the internal data of an object of this class.
void deallocate ()
 Deallocates any memory previously allocated for this object.

Private Attributes

int dim
 The dimension of the space.
const coordtype * source
 A pointer to the source point (not allocated!).
coordtype * neighbor
 The coordinates of a created neighbor.
signed char * counters
 The current counters.
const coordtype * wrap
 The space wrapping (if needed).

Detailed Description

template<class coordtype>
class chomp::homology::tNeighbors< coordtype >

This class can be used for iterating point's neighbors.

The source point must exist all the time you use this structure for this point.

Definition at line 1404 of file pointset.h.


Constructor & Destructor Documentation

template<class coordtype >
chomp::homology::tNeighbors< coordtype >::tNeighbors ( const coordtype *  _source = NULL,
int  _dim = 0,
const coordtype *  _wrap = NULL 
)

The only possible constructor for new objects.

Definition at line 1480 of file pointset.h.

References chomp::homology::tNeighbors< coordtype >::initialize().

{
        initialize (_source, _dim, _wrap);
        return;
} /* tNeighbors::tNeighbors */

template<class coordtype >
chomp::homology::tNeighbors< coordtype >::tNeighbors ( const tNeighbors< coordtype > &  r  ) 
template<class coordtype >
chomp::homology::tNeighbors< coordtype >::~tNeighbors< coordtype > (  ) 

The destructor.


Member Function Documentation

template<class coordtype >
void chomp::homology::tNeighbors< coordtype >::deallocate (  )  [private]

Deallocates any memory previously allocated for this object.

Definition at line 1504 of file pointset.h.

References chomp::homology::tNeighbors< coordtype >::counters, and chomp::homology::tNeighbors< coordtype >::neighbor.

{
        if (neighbor)
                delete [] neighbor;
        if (counters)
                delete [] counters;
        return;
} /* tNeighbors::deallocate */

template<class coordtype >
coordtype * chomp::homology::tNeighbors< coordtype >::get (  ) 

Returns the next neighbor.

If no more neighbors are available then returns 0 and rewinds to the first neighbor.

Definition at line 1539 of file pointset.h.

References chomp::homology::tNeighbors< coordtype >::counters, chomp::homology::tNeighbors< coordtype >::dim, chomp::homology::tNeighbors< coordtype >::neighbor, chomp::homology::tNeighbors< coordtype >::source, chomp::homology::tNeighbors< coordtype >::wrap, and chomp::homology::wrapcoord().

{
        // if the initialization was incorrect, return NULL
        if (!dim || !counters || !neighbor || !source)
                return NULL;

        // compute the next set of counters
        // and return NULL if this is the end
        int cur = 0;
        while ((cur < dim) && (counters [cur] == -1))
                counters [cur ++] = 0;
        if (cur >= dim)
                return NULL;
        counters [cur] = counters [cur] ?
                (signed char) -1 : (signed char) 1;

        // compute the neighbor corresponding to these counters
        for (int i = 0; i < dim; ++ i)
                neighbor [i] = (coordtype) (source [i] + counters [i]);

        // wrap the neighbor's coordinates if required
        if (wrap)
                wrapcoord (neighbor, neighbor, wrap, dim);

        // return the neighbor's coordinates
        return neighbor;

} /* tNeighbors::get */

template<class coordtype >
void chomp::homology::tNeighbors< coordtype >::initialize ( const coordtype *  _source = NULL,
int  _dim = 0,
const coordtype *  _wrap = NULL 
) [private]

Initializes the internal data of an object of this class.

Definition at line 1458 of file pointset.h.

References chomp::homology::tNeighbors< coordtype >::counters, chomp::homology::tNeighbors< coordtype >::dim, chomp::homology::tNeighbors< coordtype >::neighbor, chomp::homology::tNeighbors< coordtype >::reset(), chomp::homology::tNeighbors< coordtype >::source, and chomp::homology::tNeighbors< coordtype >::wrap.

Referenced by chomp::homology::tNeighbors< coordtype >::tNeighbors().

{
        source = _source;
        wrap = _wrap;
        dim = _dim;
        if (dim <= 0)
        {
                dim = 0;
                neighbor = NULL;
                counters = NULL;
                return;
        }
        neighbor = new coordtype [dim];
        counters = new signed char [dim];
        if (!neighbor || !counters)
                throw "Can't allocate memory for neighbors.";
        reset ();
        return;
} /* tNeighbors::initialize */

template<class coordtype >
tNeighbors< coordtype > & chomp::homology::tNeighbors< coordtype >::operator= ( const tNeighbors< coordtype > &  r  ) 

The assignment operator.

Definition at line 1496 of file pointset.h.

{
        deallocate ();
        initialize (n. source, n. dim, n. wrap);
        return *this;
} /* tNeighbors::operator = */

template<class coordtype >
void chomp::homology::tNeighbors< coordtype >::reset ( void   ) 

Resets the neighbors to the first one.

Definition at line 1521 of file pointset.h.

References chomp::homology::tNeighbors< coordtype >::counters, and chomp::homology::tNeighbors< coordtype >::dim.

Referenced by chomp::homology::tNeighbors< coordtype >::initialize().

{
        if (counters)
        {
                for (int i = 0; i < dim; ++ i)
                        counters [i] = 0;
        }
        return;
} /* tNeighbors::reset */

template<class coordtype >
void chomp::homology::tNeighbors< coordtype >::set ( coordtype *  _source  ) 

Redefines the source (and doesn't change other variables).

Definition at line 1532 of file pointset.h.

References chomp::homology::tNeighbors< coordtype >::source.

{
        source = _source;
        return;
} /* tNeighbors::set */


Member Data Documentation

template<class coordtype>
signed char* chomp::homology::tNeighbors< coordtype >::counters [private]
template<class coordtype>
int chomp::homology::tNeighbors< coordtype >::dim [private]
template<class coordtype>
coordtype* chomp::homology::tNeighbors< coordtype >::neighbor [private]
template<class coordtype>
const coordtype* chomp::homology::tNeighbors< coordtype >::source [private]
template<class coordtype>
const coordtype* chomp::homology::tNeighbors< coordtype >::wrap [private]

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