This class can be used for iterating point's neighbors. More...
#include <pointset.h>
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. | |
tNeighbors & | operator= (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). |
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.
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 */
chomp::homology::tNeighbors< coordtype >::tNeighbors | ( | const tNeighbors< coordtype > & | r | ) |
The copy constructor.
Definition at line 1488 of file pointset.h.
References chomp::homology::tNeighbors< coordtype >::dim, chomp::homology::tNeighbors< coordtype >::initialize(), chomp::homology::tNeighbors< coordtype >::source, and chomp::homology::tNeighbors< coordtype >::wrap.
{ initialize (n. source, n. dim, n. wrap); return; } /* tNeighbors::tNeighbors */
chomp::homology::tNeighbors< coordtype >::~tNeighbors< coordtype > | ( | ) |
The destructor.
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.
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 */
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 */
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 = */
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().
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 */
signed char* chomp::homology::tNeighbors< coordtype >::counters [private] |
The current counters.
Definition at line 1441 of file pointset.h.
Referenced by chomp::homology::tNeighbors< coordtype >::deallocate(), chomp::homology::tNeighbors< coordtype >::get(), chomp::homology::tNeighbors< coordtype >::initialize(), and chomp::homology::tNeighbors< coordtype >::reset().
int chomp::homology::tNeighbors< coordtype >::dim [private] |
The dimension of the space.
Definition at line 1432 of file pointset.h.
Referenced by chomp::homology::tNeighbors< coordtype >::get(), chomp::homology::tNeighbors< coordtype >::initialize(), chomp::homology::tNeighbors< coordtype >::reset(), and chomp::homology::tNeighbors< coordtype >::tNeighbors().
coordtype* chomp::homology::tNeighbors< coordtype >::neighbor [private] |
The coordinates of a created neighbor.
Definition at line 1438 of file pointset.h.
Referenced by chomp::homology::tNeighbors< coordtype >::deallocate(), chomp::homology::tNeighbors< coordtype >::get(), and chomp::homology::tNeighbors< coordtype >::initialize().
const coordtype* chomp::homology::tNeighbors< coordtype >::source [private] |
A pointer to the source point (not allocated!).
Definition at line 1435 of file pointset.h.
Referenced by chomp::homology::tNeighbors< coordtype >::get(), chomp::homology::tNeighbors< coordtype >::initialize(), chomp::homology::tNeighbors< coordtype >::set(), and chomp::homology::tNeighbors< coordtype >::tNeighbors().
const coordtype* chomp::homology::tNeighbors< coordtype >::wrap [private] |
The space wrapping (if needed).
Definition at line 1444 of file pointset.h.
Referenced by chomp::homology::tNeighbors< coordtype >::get(), chomp::homology::tNeighbors< coordtype >::initialize(), and chomp::homology::tNeighbors< coordtype >::tNeighbors().