35#ifndef _CHOMP_CUBES_CELLVAR_H_
36#define _CHOMP_CUBES_CELLVAR_H_
66template <
class coordtype>
88 tCellVar (
const coordtype *c1,
const coordtype *c2,
89 int spcdim,
int celldim = -1);
119 coordtype *
leftcoord (coordtype *c)
const;
131 static const char *
name ();
155 return ((c1.
n == c2.
n) && ((c1.
n == 0) ||
169 void initialize (
const coordtype *c1,
const coordtype *c2,
170 int spcdim,
int celldim = -1);
176template<
class coordtype>
181template <
class coordtype>
183 const coordtype *c2,
int spcdim,
int)
187 throw "Non-positive dimension of the space.";
188 else if (spcdim >= MaxDim)
189 throw "Too high dimension of a cell.";
195 tab =
new coordtype [spcdim];
197 throw "Not enough memory to create a cell.";
203 coordtype r [MaxDim];
207 for (
int i = 0; i < spcdim; ++ i)
209 if (tab [i] != r [i])
210 n |= (
static_cast<int_t> (1) << i);
215template <
class coordtype>
222template <
class coordtype>
224 (
const coordtype *c1,
const coordtype *c2,
int spcdim,
int celldim)
226 initialize (c1, c2, spcdim, celldim);
230template <
class coordtype>
234 for (
int i = 0; i <
NumBits; ++ i)
236 if (n & (
static_cast<int_t> (1) << i))
242template <
class coordtype>
245 return static_cast<int> (n >>
NumBits);
248template <
class coordtype>
250 int offset,
int ncoords)
252 int spcdim =
static_cast<int> (q. n >>
NumBits);
253 if ((offset < 0) || (ncoords <= 0) || (offset + ncoords > spcdim))
254 throw "Wrong cell projection requested.";
255 coordtype right [MaxDim];
256 q. rightcoord (right);
257 initialize (q. tab + offset, right + offset, ncoords);
268template <
class coordtype>
272 tab =
new coordtype [spacedim ()];
274 throw "Not enough memory to copy a cubical cell.";
279template <
class coordtype>
284 int d = q. spacedim ();
287 if (d != spacedim ())
291 tab =
new coordtype [d];
293 throw "Not enough memory to copy a cubical cell.";
303template <
class coordtype>
307 throw "Null pointer to save left coordinates.";
309 for (
int i = 0; i < d; ++ i)
314template <
class coordtype>
318 throw "Null pointer to save right coordinates.";
320 for (
int i = 0; i < d; ++ i)
323 if (n & (
static_cast<int_t> (1) << i))
330template <
class coordtype>
338 return (
static_cast<int_t> (tab [0]) << 12) ^ n;
340 return (((
static_cast<int_t> (tab [0])) << 18) +
341 ((
static_cast<int_t> (tab [1])) << 6)) ^ n;
343 return (((
static_cast<int_t> (tab [0])) << 18) +
344 ((
static_cast<int_t> (tab [1])) << 6) +
345 ((
static_cast<int_t> (tab [2])) >> 6)) ^ n;
349template <
class coordtype>
355template <
class coordtype>
364 return (
static_cast<int_t> (tab [0]) << 3) ^ (n << 5);
366 return ((
static_cast<int_t> (tab [0]) >> 1) +
367 (
static_cast<int_t> (tab [1]) << 13)) ^ (n << 5);
369 return (((
static_cast<int_t> (tab [d - 1])) << 20) +
370 ((
static_cast<int_t> (tab [d - 2])) << 9) +
371 ((
static_cast<int_t> (tab [d - 3])) >> 1)) ^
376template <
class coordtype>
382template <
class coordtype>
385 return "cubical cell";
388template <
class coordtype>
391 return "cubical cells";
396template <
class coordtype>
401 coordtype left [MaxDim];
402 coordtype right [MaxDim];
405 coordtype c1 [MaxDim];
407 coordtype c2 [MaxDim];
411 int spcdim = q1. dim ();
412 if (spcdim != q2. dim ())
413 throw "Trying to intersect cubes of different dimension.";
419 for (
int i = 0; i < spcdim; ++ i)
421 if (c1 [i] == c2 [i])
428 else if ((c1 [i] - c2 [i] == -1) || (wrap && wrap [i] &&
429 (c1 [i] - c2 [i] == wrap [i] - 1)))
434 else if ((c1 [i] - c2 [i] == 1) || (wrap && wrap [i] &&
435 (c1 [i] - c2 [i] == -wrap [i] + 1)))
441 throw "The cubes do not intersect.";
445 initialize (left, right, spcdim, celldim);
450template <
class coordtype>
456 const coordtype *left = q. tab + 1;
462 coordtype right [MaxDim];
465 for (
int i = 0; i < d; ++ i)
466 right [i] = left [i] + 1;
469 initialize (left, right, d, d);
473template <
class coordtype>
480 const coordtype *left = q. tab + 1;
483 coordtype right [MaxDim];
489 for (
int i = 0; i < d; ++ i)
490 right [i] = left [i] + ((i < facedim) ? 1 : 0);
493 initialize (left, right, d, facedim);
500template <
class coordtype>
510template <
class coordtype>
516 int d1 = c1. spacedim (), d2 = c2. spacedim ();
518 throw "Too high dimension of a Cartesian product of cells.";
525 c1. leftcoord (left);
526 c1. rightcoord (right);
529 c2. leftcoord (left + d1);
530 c2. rightcoord (right + d1);
534 c1. dim () + c2. dim ());
538template <
class coordtype>
546template <
class coordtype>
556template <
class coordtype>
558 int i,
bool onlyexisting)
564template <
class coordtype>
572template <
class coordtype>
579template <
class coordtype>
This file contains the definition of a bitfield class which works an array of bits.
This file contains the definition of some functions that are common for all types of cubical cells,...
This file contains classes and functions related to algebraic chain complexes and chain maps,...
This class defines cubical cell in R^n with edges parallel to the axes and with size 0 or 1 in each d...
friend int operator==(const tCellVar< coordtype > &c1, const tCellVar< coordtype > &c2)
Verifies if two cells are identical.
tCubeVar< coordtype >::PointBase PointBase
The point base (for wrapping and tabulating coordinates).
int_t hashkey2() const
Return shashing key no. 2 required by the hashing set template.
static int OutputBits
The output bits which determine how a cell is written.
int_t n
High 6 bits = the dimension of the space.
coordtype * tab
The lower left etc. corner of the cell.
static const int MaxDim
The maximal dimension of a cell.
coordtype * leftcoord(coordtype *c) const
Fills in the given table with the right corner coordinates.
OutputBitValues
Bit masks that define how to output the cell.
tCellVar()
The constructor of an empty cubical cell.
coordtype CoordType
The type of the coordinates.
int dim() const
Returns the dimension of the cubical cell.
tCellVar< coordtype > & operator=(const tCellVar< coordtype > &c)
The assignment operator.
static const char * pluralname()
Returns the plural name of the objects represented by this class.
void initialize(const coordtype *c1, const coordtype *c2, int spcdim, int celldim=-1)
Initializes a new cell given its two corners.
static const char * name()
Returns the name of the objects represented by this class.
coordtype * rightcoord(coordtype *c) const
Fills in the given table with the right corner coordinates.
int spacedim() const
Returns the dimension of the embedding space of the cubical cell.
int_t hashkey1() const
Returns hashing key no. 1 required by the hashing set template.
static const int MaxSpaceDim
The maximal dimension of the embedding space of a cell.
This class defines a hypercube in R^n with edges parallel to the axes and with size 1 in each directi...
static void wrapcoord(coordtype *c, int dim)
Wraps the given coordinates if necessary.
static const coordtype * getwrapping(int d)
Returns the space wrapping for the given dimension.
static void wrapcopy(coordtype *dest, const coordtype *src, int dim)
Copies the coordinates and wraps them if necessary.
This class is a simplified version of the point base class used only for the space wrapping support.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
This file defines full cubes whose embedding space dimension is not known apriori and therefore the a...
This file contains a definition of a general geometric complex which represents a polyhedron.
int int_t
Index type for indexing arrays, counting cubes, etc.
This file contains the definition of the container "hashedset" which can be used to represent a set o...
This file defines a class "integer" which represents the ring of integers or the field of integers mo...
int CubicalBoundaryCoef(const celltype &q, int i)
Returns the i-th coefficient in the boundary of a cubical cell.
const int MaxBasDim
The maximal dimension that can be used if the high bits of an integer store the value of the dimensio...
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
int_t hashkey2(const hashNumber< Number > &n)
The second hashing key.
celltype CubicalBoundaryCell(const celltype &q, int i, bool onlyexisting)
Returns the i-th boundary element of a cell.
const int NumBits
The number of bits in an integer number that remain to be used for other purposes,...
int boundarylength(const tCellBase< coordtype > &q)
Returns the length of the boundary of a cell.
int thesame(const coordtype *c1, const coordtype *c2, int dim)
Compare two points. Returns true iff they have the same coordinates.
std::ostream & WriteCubicalCell(std::ostream &out, const celltype &c)
Writes a cubical cell to the output stream in the text form.
tCellBase< coordtype > boundarycell(const tCellBase< coordtype > &q, int i, bool onlyexisting)
Computes the i-th boundary element of a cell.
bool operator!=(const typename bincube< Dim, twoPower >::neighborhood_iterator &x1, const typename bincube< Dim, twoPower >::neighborhood_iterator &x2)
std::istream & operator>>(std::istream &in, bincube< Dim, twoPower > &b)
int_t hashkey1(const hashNumber< Number > &n)
The first hashing key.
void copycoord(coordtype *destination, const coordtype *source, int dim)
Copies the coordinates of one point to another.
std::istream & ReadCubicalCell(std::istream &in, celltype &c)
Reads a cubical cell form the input text stream.
int CubicalBoundaryLength(const celltype &q)
Returns the length of the boundary of a cubical cell.
int boundarycoef(const tCellBase< coordtype > &q, int i)
Returns the i-th coefficient in the boundary of a cell.
This namespace contains the entire CHomP library interface.
This file contains the definition of a point base class which is used for indexing all the points (n-...
This file contains the definition of a set of n-dimensional points with integer coordinates and sever...
This file contains some useful functions related to the text input/output procedures.