The Original CHomP Software
Public Member Functions | Private Member Functions | Private Attributes | List of all members
chomp::homology::tNeighbors< coordtype > Class Template Reference

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. More...
 
 tNeighbors (const tNeighbors< coordtype > &r)
 The copy constructor. More...
 
tNeighborsoperator= (const tNeighbors< coordtype > &r)
 The assignment operator. More...
 
 ~tNeighbors ()
 The destructor. More...
 
coordtype * get ()
 Returns the next neighbor. More...
 
void reset ()
 Resets the neighbors to the first one. More...
 
void set (coordtype *_source)
 Redefines the source (and doesn't change other variables). More...
 

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. More...
 
void deallocate ()
 Deallocates any memory previously allocated for this object. More...
 

Private Attributes

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

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 1449 of file pointset.h.

Constructor & Destructor Documentation

◆ tNeighbors() [1/2]

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 1525 of file pointset.h.

1527{
1528 initialize (_source, _dim, _wrap);
1529 return;
1530} /* tNeighbors::tNeighbors */
void initialize(const coordtype *_source=NULL, int _dim=0, const coordtype *_wrap=NULL)
Initializes the internal data of an object of this class.
Definition: pointset.h:1503

◆ tNeighbors() [2/2]

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

The copy constructor.

Definition at line 1533 of file pointset.h.

1534{
1535 initialize (n. source, n. dim, n. wrap);
1536 return;
1537} /* tNeighbors::tNeighbors */
const coordtype * source
A pointer to the source point (not allocated!).
Definition: pointset.h:1480
const coordtype * wrap
The space wrapping (if needed).
Definition: pointset.h:1489
int dim
The dimension of the space.
Definition: pointset.h:1477

◆ ~tNeighbors()

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

The destructor.

Definition at line 1549 of file pointset.h.

1560{
1561 deallocate ();
1562 return;
1563} /* tNeighbors::~tNeighbors */
void deallocate()
Deallocates any memory previously allocated for this object.
Definition: pointset.h:1549

Member Function Documentation

◆ deallocate()

template<class coordtype >
void chomp::homology::tNeighbors< coordtype >::deallocate
private

Deallocates any memory previously allocated for this object.

Definition at line 1549 of file pointset.h.

1550{
1551 if (neighbor)
1552 delete [] neighbor;
1553 if (counters)
1554 delete [] counters;
1555 return;
1556} /* tNeighbors::deallocate */
signed char * counters
The current counters.
Definition: pointset.h:1486
coordtype * neighbor
The coordinates of a created neighbor.
Definition: pointset.h:1483

◆ get()

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 1584 of file pointset.h.

1585{
1586 // if the initialization was incorrect, return NULL
1587 if (!dim || !counters || !neighbor || !source)
1588 return NULL;
1589
1590 // compute the next set of counters
1591 // and return NULL if this is the end
1592 int cur = 0;
1593 while ((cur < dim) && (counters [cur] == -1))
1594 counters [cur ++] = 0;
1595 if (cur >= dim)
1596 return NULL;
1597 counters [cur] = counters [cur] ?
1598 (signed char) -1 : (signed char) 1;
1599
1600 // compute the neighbor corresponding to these counters
1601 for (int i = 0; i < dim; ++ i)
1602 neighbor [i] = (coordtype) (source [i] + counters [i]);
1603
1604 // wrap the neighbor's coordinates if required
1605 if (wrap)
1607
1608 // return the neighbor's coordinates
1609 return neighbor;
1610
1611} /* tNeighbors::get */
void wrapcoord(coordtype *destination, const coordtype *source, const coordtype *wrap, int dim)
Wraps coordinates stored in 'c' accordint to the wrap table 'wrap' and store the result in the table ...
Definition: pointset.h:119

References chomp::homology::wrapcoord().

◆ initialize()

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 1503 of file pointset.h.

1505{
1506 source = _source;
1507 wrap = _wrap;
1508 dim = _dim;
1509 if (dim <= 0)
1510 {
1511 dim = 0;
1512 neighbor = NULL;
1513 counters = NULL;
1514 return;
1515 }
1516 neighbor = new coordtype [dim];
1517 counters = new signed char [dim];
1518 if (!neighbor || !counters)
1519 throw "Can't allocate memory for neighbors.";
1520 reset ();
1521 return;
1522} /* tNeighbors::initialize */
void reset()
Resets the neighbors to the first one.
Definition: pointset.h:1566

◆ operator=()

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

The assignment operator.

Definition at line 1540 of file pointset.h.

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

◆ reset()

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

Resets the neighbors to the first one.

Definition at line 1566 of file pointset.h.

1567{
1568 if (counters)
1569 {
1570 for (int i = 0; i < dim; ++ i)
1571 counters [i] = 0;
1572 }
1573 return;
1574} /* tNeighbors::reset */

◆ set()

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

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

Definition at line 1577 of file pointset.h.

1578{
1579 source = _source;
1580 return;
1581} /* tNeighbors::set */

Member Data Documentation

◆ counters

template<class coordtype >
signed char* chomp::homology::tNeighbors< coordtype >::counters
private

The current counters.

Definition at line 1486 of file pointset.h.

◆ dim

template<class coordtype >
int chomp::homology::tNeighbors< coordtype >::dim
private

The dimension of the space.

Definition at line 1477 of file pointset.h.

◆ neighbor

template<class coordtype >
coordtype* chomp::homology::tNeighbors< coordtype >::neighbor
private

The coordinates of a created neighbor.

Definition at line 1483 of file pointset.h.

◆ source

template<class coordtype >
const coordtype* chomp::homology::tNeighbors< coordtype >::source
private

A pointer to the source point (not allocated!).

Definition at line 1480 of file pointset.h.

◆ wrap

template<class coordtype >
const coordtype* chomp::homology::tNeighbors< coordtype >::wrap
private

The space wrapping (if needed).

Definition at line 1489 of file pointset.h.


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