Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends

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

This class defines cubical cell in R^n with edges parallel to the axes and with size 0 or 1 in each direction. More...

#include <cellvar.h>

List of all members.

Public Types

enum  OutputBitValues { BitProduct = 0x01, BitSpace = 0x02 }
 

Bit masks that define how to output the cell.

More...
typedef coordtype CoordType
 The type of the coordinates.
typedef tCubeVar< coordtype >
::PointBase 
PointBase
 The point base (for wrapping and tabulating coordinates).

Public Member Functions

 tCellVar ()
 The constructor of an empty cubical cell.
 tCellVar (const coordtype *c1, const coordtype *c2, int spcdim, int celldim=-1)
 The constructor of a cell spanning from one point to another.
 tCellVar (const tCubeVar< coordtype > &q1, const tCubeVar< coordtype > &q2)
 The constructor of a cell as an intersection of two cubes.
 tCellVar (const tCubeVar< coordtype > &q, int facedim)
 The constructor of an arbitrary k-dimensional face of a full cube.
 tCellVar (const tCubeVar< coordtype > &q)
 The constructor of a full-dimensional cubical cell.
 tCellVar (const tCellVar< coordtype > &q, int offset, int ncoords)
 The constructor of a projection of a cell to the given number of coordinates that start at the given offset.
 tCellVar (const tCellVar< coordtype > &c)
 The copy constructor.
tCellVar< coordtype > & operator= (const tCellVar< coordtype > &c)
 The assignment operator.
int dim () const
 Returns the dimension of the cubical cell.
int spacedim () const
 Returns the dimension of the embedding space of the cubical cell.
coordtype * leftcoord (coordtype *c) const
 Fills in the given table with the right corner coordinates.
coordtype * rightcoord (coordtype *c) const
 Fills in the given table with the right corner coordinates.
int_t hashkey1 () const
 Returns hashing key no. 1 required by the hashing set template.
int_t hashkey2 () const
 Return shashing key no. 2 required by the hashing set template.

Static Public Member Functions

static const char * name ()
 Returns the name of the objects represented by this class.
static const char * pluralname ()
 Returns the plural name of the objects represented by this class.

Static Public Attributes

static const int MaxDim
 The maximal dimension of a cell.
static const int MaxSpaceDim = tCubeVar<coordtype>::MaxDim
 The maximal dimension of the embedding space of a cell.
static int OutputBits = 0
 The output bits which determine how a cell is written.

Private Member Functions

void initialize (const coordtype *c1, const coordtype *c2, int spcdim, int celldim=-1)
 Initializes a new cell given its two corners.

Private Attributes

coordtype * tab
 The lower left etc. corner of the cell.
int_t n
 High 6 bits = the dimension of the space.

Friends

int operator== (const tCellVar< coordtype > &c1, const tCellVar< coordtype > &c2)
 Verifies if two cells are identical.

Detailed Description

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

This class defines cubical cell in R^n with edges parallel to the axes and with size 0 or 1 in each direction.

In this implementation, an array is allocated for the coordinates of the minimal vertex of a cell.

Definition at line 68 of file cellvar.h.


Member Typedef Documentation

template<class coordtype>
typedef coordtype chomp::homology::tCellVar< coordtype >::CoordType

The type of the coordinates.

Definition at line 72 of file cellvar.h.

template<class coordtype>
typedef tCubeVar<coordtype>::PointBase chomp::homology::tCellVar< coordtype >::PointBase

The point base (for wrapping and tabulating coordinates).

Definition at line 83 of file cellvar.h.


Member Enumeration Documentation

template<class coordtype>
enum chomp::homology::tCellVar::OutputBitValues

Bit masks that define how to output the cell.

If 'BitProduct' is set, then the cell is displayed as a Cartesian product of intervals. Otherwise, it is indicated by two opposite vertices. If 'BitSpace' is set, the space is inserted in the output.

Enumerator:
BitProduct 
BitSpace 

Definition at line 141 of file cellvar.h.

        {
                BitProduct = 0x01,      // unset => two vertices
                BitSpace = 0x02
        };


Constructor & Destructor Documentation

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar (  )  [inline]

The constructor of an empty cubical cell.

Definition at line 217 of file cellvar.h.

: tab (0), n (0)
{
        return;
} /* tCellVar::tCellVar */

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const coordtype *  c1,
const coordtype *  c2,
int  spcdim,
int  celldim = -1 
) [inline]

The constructor of a cell spanning from one point to another.

Definition at line 225 of file cellvar.h.

{
        initialize (c1, c2, spcdim, celldim);
        return;
} /* tCellVar::tCellVar */

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const tCubeVar< coordtype > &  q1,
const tCubeVar< coordtype > &  q2 
) [inline]

The constructor of a cell as an intersection of two cubes.

Definition at line 387 of file cellvar.h.

References chomp::homology::tPointBase< coordtype >::getwrapping().

{
        // prepare tables for coordinates of the cubical cell
        coordtype left [MaxDim];
        coordtype right [MaxDim];

        // get the coordinates of minimal vertices of both cubes
        coordtype c1 [MaxDim];
        q1. coord (c1);
        coordtype c2 [MaxDim];
        q2. coord (c2);

        // get the dimension of the space and check for consistency
        int spcdim = q1. dim ();
        if (spcdim != q2. dim ())
                throw "Trying to intersect cubes of different dimension.";

        // calculate the coordinates of both vertices of the cubical cell
        // and the dimension of the cubical cell
        int celldim = 0;
        const coordtype *wrap = PointBase::getwrapping (spcdim);
        for (int i = 0; i < spcdim; ++ i)
        {
                if (c1 [i] == c2 [i])
                {
                        left [i] = c1 [i];
                        right [i] = c1 [i];
                        ++ right [i];
                        ++ celldim;
                }
                else if ((c1 [i] - c2 [i] == -1) || (wrap && wrap [i] &&
                        (c1 [i] - c2 [i] == wrap [i] - 1)))
                {
                        left [i] = c2 [i];
                        right [i] = c2 [i];
                }
                else if ((c1 [i] - c2 [i] == 1) || (wrap && wrap [i] &&
                        (c1 [i] - c2 [i] == -wrap [i] + 1)))
                {
                        left [i] = c1 [i];
                        right [i] = c1 [i];
                }
                else
                        throw "The cubes do not intersect.";
        }

        // initialize the data of the cube
        initialize (left, right, spcdim, celldim);

        return;
} /* tCellVar::tCellVar */

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const tCubeVar< coordtype > &  q,
int  facedim 
) [inline]

The constructor of an arbitrary k-dimensional face of a full cube.

Definition at line 463 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::dim(), chomp::homology::tCellVar< coordtype >::initialize(), chomp::homology::tCellVar< coordtype >::MaxDim, and chomp::homology::tCellVar< coordtype >::tab.

       : This function is not as efficient as it could be. Instead of using
// the "initialize" function, it should create the data structures itself.
{
        // get the coordinates of minimal vertex of the cube
        const coordtype *left = q. tab + 1;

        // prepare a table for coordinates of the other vertex of the cell
        coordtype right [MaxDim];

        // get the dimension of the space and of the cell
        int d = q. dim ();

        // calculate the coordinates of other vertex of the cell
        for (int i = 0; i < d; ++ i)
                right [i] = left [i] + ((i < facedim) ? 1 : 0);

        // initialize the cell
        initialize (left, right, d, facedim);
        return;
} /* tCellVar::tCellVar */

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const tCubeVar< coordtype > &  q  )  [inline, explicit]

The constructor of a full-dimensional cubical cell.

Definition at line 440 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::dim(), chomp::homology::tCellVar< coordtype >::initialize(), chomp::homology::tCellVar< coordtype >::MaxDim, and chomp::homology::tCellVar< coordtype >::tab.

       : This function is not as efficient as it could be. Instead of using
// the "initialize" function, it should create the data structures itself.
{
        // get the coordinates of minimal vertex of the cube
        const coordtype *left = q. tab + 1;

        // get the dimension of the space and of the cell
        int d = q. dim ();

        // prepare a table for coordinates of the other vertex of the cell
        coordtype right [MaxDim];

        // calculate the coordinates of other vertex of the cell
        for (int i = 0; i < d; ++ i)
                right [i] = left [i] + 1;

        // initialize the cell
        initialize (left, right, d, d);
        return;
} /* tCellVar::tCellVar */

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const tCellVar< coordtype > &  q,
int  offset,
int  ncoords 
) [inline]

The constructor of a projection of a cell to the given number of coordinates that start at the given offset.

Definition at line 250 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::initialize(), chomp::homology::tCellVar< coordtype >::MaxDim, chomp::homology::tCellVar< coordtype >::n, chomp::homology::NumBits, chomp::homology::tCellVar< coordtype >::rightcoord(), and chomp::homology::tCellVar< coordtype >::tab.

{
        int spcdim = static_cast<int> (q. n >> NumBits);
        if ((offset < 0) || (ncoords <= 0) || (offset + ncoords > spcdim))
                throw "Wrong cell projection requested.";
        coordtype right [MaxDim];
        q. rightcoord (right);
        initialize (q. tab + offset, right + offset, ncoords);
//      *** More efficient [unfinished, yet] ***
//      tab = new coordtype [spcdim];
//      if (!tab)
//              throw "Not enough memory to create a projected cell.";
//      for (int i = 0; i < spcdim; ++ i)
//              tab [i] = q. tab [i];
//      [...]
        return;
} /* tCellVar::tCellVar */

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const tCellVar< coordtype > &  c  )  [inline]

The copy constructor.

Definition at line 270 of file cellvar.h.

References chomp::homology::copycoord(), chomp::homology::tCellVar< coordtype >::n, chomp::homology::tCellVar< coordtype >::spacedim(), and chomp::homology::tCellVar< coordtype >::tab.

{
        n = q. n;
        tab = new coordtype [spacedim ()];
        if (!tab)
                throw "Not enough memory to copy a cubical cell.";
        copycoord (tab, q. tab, spacedim ());
        return;
} /* tCellVar::tCellVar */


Member Function Documentation

template<class coordtype >
int chomp::homology::tCellVar< coordtype >::dim (  )  const [inline]

Returns the dimension of the cubical cell.

Definition at line 232 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::n, and chomp::homology::NumBits.

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

{
        int count = 0;
        for (int i = 0; i < NumBits; ++ i)
        {
                if (n & (static_cast<int_t> (1) << i))
                        ++ count;
        }
        return count;
} /* tCellVar::dim */

template<class coordtype >
int_t chomp::homology::tCellVar< coordtype >::hashkey1 (  )  const [inline]

Returns hashing key no. 1 required by the hashing set template.

Definition at line 332 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::n, chomp::homology::tCellVar< coordtype >::spacedim(), and chomp::homology::tCellVar< coordtype >::tab.

{
        switch (spacedim ())
        {
        case 0:
                return 0;
        case 1:
                return (static_cast<int_t> (tab [0]) << 12) ^ n;
        case 2:
                return (((static_cast<int_t> (tab [0])) << 18) +
                        ((static_cast<int_t> (tab [1])) << 6)) ^ n;
        default:
                return (((static_cast<int_t> (tab [0])) << 18) +
                        ((static_cast<int_t> (tab [1])) << 6) +
                        ((static_cast<int_t> (tab [2])) >> 6)) ^ n;
        }
} /* tCellVar::hashkey1 */

template<class coordtype >
int_t chomp::homology::tCellVar< coordtype >::hashkey2 (  )  const [inline]

Return shashing key no. 2 required by the hashing set template.

Definition at line 351 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::n, chomp::homology::tCellVar< coordtype >::spacedim(), and chomp::homology::tCellVar< coordtype >::tab.

{
        int d = spacedim ();
        switch (d)
        {
        case 0:
                return 0;
        case 1:
                return (static_cast<int_t> (tab [0]) << 3) ^ (n << 5);
        case 2:
                return ((static_cast<int_t> (tab [0]) >> 1) +
                        (static_cast<int_t> (tab [1]) << 13)) ^ (n << 5);
        default:
                return (((static_cast<int_t> (tab [d - 1])) << 20) +
                        ((static_cast<int_t> (tab [d - 2])) << 9) +
                        ((static_cast<int_t> (tab [d - 3])) >> 1)) ^
                        (n << 5);
        }
} /* tCellVar::hashkey2 */

template<class coordtype >
void chomp::homology::tCellVar< coordtype >::initialize ( const coordtype *  c1,
const coordtype *  c2,
int  spcdim,
int  celldim = -1 
) [inline, private]

Initializes a new cell given its two corners.

Definition at line 183 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::MaxDim, chomp::homology::tCellVar< coordtype >::n, chomp::homology::NumBits, chomp::homology::tCellVar< coordtype >::tab, and chomp::homology::tPointBase< coordtype >::wrapcopy().

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

{
        // test the validity of the dimension
        if (spcdim <= 0)
                throw "Non-positive dimension of the space.";
        else if (spcdim >= MaxDim)
                throw "Too high dimension of a cell.";

        // initialize the internal number with the space dimension
        n = static_cast<int_t> (spcdim) << NumBits;

        // prepare a table for coordinates if necessary
        tab = new coordtype [spcdim];
        if (!tab)
                throw "Not enough memory to create a cell.";

        // copy the left corner coordinates to the cell
        PointBase::wrapcopy (tab, c1, spcdim);

        // prepare wrapped right coordinates for the detection of cell bits
        coordtype r [MaxDim];
        PointBase::wrapcopy (r, c2, spcdim);

        // set the bits of the cell
        for (int i = 0; i < spcdim; ++ i)
        {
                if (tab [i] != r [i])
                        n |= (static_cast<int_t> (1) << i);
        }
        return;
} /* tCellVar::initialize */

template<class coordtype >
coordtype * chomp::homology::tCellVar< coordtype >::leftcoord ( coordtype *  c  )  const [inline]

Fills in the given table with the right corner coordinates.

Definition at line 305 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::spacedim(), and chomp::homology::tCellVar< coordtype >::tab.

{
        if (!c)
                throw "Null pointer to save left coordinates.";
        int d = spacedim ();
        for (int i = 0; i < d; ++ i)
                c [i] = tab [i];
        return c;
} /* tCellVar::leftcoord */

template<class coordtype >
const char * chomp::homology::tCellVar< coordtype >::name (  )  [static]

Returns the name of the objects represented by this class.

Definition at line 372 of file cellvar.h.

{
        return "cubical cell";
} /* tCellVar::name */

template<class coordtype >
tCellVar< coordtype > & chomp::homology::tCellVar< coordtype >::operator= ( const tCellVar< coordtype > &  c  )  [inline]

The assignment operator.

Definition at line 282 of file cellvar.h.

References chomp::homology::copycoord().

{
        // determine the new dimension
        int d = q. spacedim ();

        // allocate a new table if the dimension is to be changed
        if (d != spacedim ())
        {
                if (tab)
                        delete [] tab;
                tab = new coordtype [d];
                if (!tab)
                        throw "Not enough memory to copy a cubical cell.";
        }

        // copy the data of the cubical cell
        copycoord (tab, q. tab, d);
        n = q. n;

        return *this;
} /* tCellVar::operator = */

template<class coordtype >
const char * chomp::homology::tCellVar< coordtype >::pluralname (  )  [static]

Returns the plural name of the objects represented by this class.

Definition at line 378 of file cellvar.h.

{
        return "cubical cells";
} /* tCellVar::pluralname */

template<class coordtype >
coordtype * chomp::homology::tCellVar< coordtype >::rightcoord ( coordtype *  c  )  const [inline]

Fills in the given table with the right corner coordinates.

Definition at line 316 of file cellvar.h.

References chomp::homology::tCellVar< coordtype >::n, chomp::homology::tCellVar< coordtype >::spacedim(), chomp::homology::tCellVar< coordtype >::tab, and chomp::homology::tPointBase< coordtype >::wrapcoord().

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

{
        if (!c)
                throw "Null pointer to save right coordinates.";
        int d = spacedim ();
        for (int i = 0; i < d; ++ i)
        {
                c [i] = tab [i];
                if (n & (static_cast<int_t> (1) << i))
                        ++ (c [i]);
        }
        PointBase::wrapcoord (c, d);
        return c;
} /* tCellVar::rightcoord */

template<class coordtype >
int chomp::homology::tCellVar< coordtype >::spacedim (  )  const [inline]

Friends And Related Function Documentation

template<class coordtype>
int operator== ( const tCellVar< coordtype > &  c1,
const tCellVar< coordtype > &  c2 
) [friend]

Verifies if two cells are identical.

Definition at line 153 of file cellvar.h.

        {
                return ((c1. n == c2. n) && ((c1. n == 0) ||
                        thesame (c1. tab, c2. tab, c1. spacedim ())));
        } /* operator == */


Member Data Documentation

template<class coordtype>
const int chomp::homology::tCellVar< coordtype >::MaxDim [static]
Initial value:
 
                (tCubeVar<coordtype>::MaxDim < MaxBasDim) ?
                tCubeVar<coordtype>::MaxDim : MaxBasDim

The maximal dimension of a cell.

Definition at line 75 of file cellvar.h.

Referenced by chomp::homology::tCellVar< coordtype >::initialize(), and chomp::homology::tCellVar< coordtype >::tCellVar().

template<class coordtype>
const int chomp::homology::tCellVar< coordtype >::MaxSpaceDim = tCubeVar<coordtype>::MaxDim [static]

The maximal dimension of the embedding space of a cell.

Definition at line 80 of file cellvar.h.

template<class coordtype>
int_t chomp::homology::tCellVar< coordtype >::n [private]
template<class coordtype>
int chomp::homology::tCellVar< coordtype >::OutputBits = 0 [static]

The output bits which determine how a cell is written.

Definition at line 148 of file cellvar.h.

template<class coordtype>
coordtype* chomp::homology::tCellVar< coordtype >::tab [private]

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