The Original CHomP Software
Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
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>

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. More...
 
typedef tCubeVar< coordtype >::PointBase PointBase
 The point base (for wrapping and tabulating coordinates). More...
 

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

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

Private Member Functions

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

Private Attributes

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

Friends

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

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 67 of file cellvar.h.

Member Typedef Documentation

◆ CoordType

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

The type of the coordinates.

Definition at line 71 of file cellvar.h.

◆ PointBase

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

The point base (for wrapping and tabulating coordinates).

Definition at line 82 of file cellvar.h.

Member Enumeration Documentation

◆ OutputBitValues

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 140 of file cellvar.h.

141 {
142 BitProduct = 0x01, // unset => two vertices
143 BitSpace = 0x02
144 };

Constructor & Destructor Documentation

◆ tCellVar() [1/7]

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

The constructor of an empty cubical cell.

Definition at line 216 of file cellvar.h.

217: tab (0), n (0)
218{
219 return;
220} /* tCellVar::tCellVar */
int_t n
High 6 bits = the dimension of the space.
Definition: cellvar.h:166
coordtype * tab
The lower left etc. corner of the cell.
Definition: cellvar.h:161

◆ tCellVar() [2/7]

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 223 of file cellvar.h.

225{
226 initialize (c1, c2, spcdim, celldim);
227 return;
228} /* tCellVar::tCellVar */
void initialize(const coordtype *c1, const coordtype *c2, int spcdim, int celldim=-1)
Initializes a new cell given its two corners.
Definition: cellvar.h:182

◆ tCellVar() [3/7]

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 397 of file cellvar.h.

399{
400 // prepare tables for coordinates of the cubical cell
401 coordtype left [MaxDim];
402 coordtype right [MaxDim];
403
404 // get the coordinates of minimal vertices of both cubes
405 coordtype c1 [MaxDim];
406 q1. coord (c1);
407 coordtype c2 [MaxDim];
408 q2. coord (c2);
409
410 // get the dimension of the space and check for consistency
411 int spcdim = q1. dim ();
412 if (spcdim != q2. dim ())
413 throw "Trying to intersect cubes of different dimension.";
414
415 // calculate the coordinates of both vertices of the cubical cell
416 // and the dimension of the cubical cell
417 int celldim = 0;
418 const coordtype *wrap = PointBase::getwrapping (spcdim);
419 for (int i = 0; i < spcdim; ++ i)
420 {
421 if (c1 [i] == c2 [i])
422 {
423 left [i] = c1 [i];
424 right [i] = c1 [i];
425 ++ right [i];
426 ++ celldim;
427 }
428 else if ((c1 [i] - c2 [i] == -1) || (wrap && wrap [i] &&
429 (c1 [i] - c2 [i] == wrap [i] - 1)))
430 {
431 left [i] = c2 [i];
432 right [i] = c2 [i];
433 }
434 else if ((c1 [i] - c2 [i] == 1) || (wrap && wrap [i] &&
435 (c1 [i] - c2 [i] == -wrap [i] + 1)))
436 {
437 left [i] = c1 [i];
438 right [i] = c1 [i];
439 }
440 else
441 throw "The cubes do not intersect.";
442 }
443
444 // initialize the data of the cube
445 initialize (left, right, spcdim, celldim);
446
447 return;
448} /* tCellVar::tCellVar */
static const int MaxDim
The maximal dimension of a cell.
Definition: cellvar.h:74
int dim() const
Returns the dimension of the cubical cell.
Definition: cellvar.h:231
static const coordtype * getwrapping(int d)
Returns the space wrapping for the given dimension.
Definition: pointbas.h:299

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

◆ tCellVar() [4/7]

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 474 of file cellvar.h.

478{
479 // get the coordinates of minimal vertex of the cube
480 const coordtype *left = q. tab + 1;
481
482 // prepare a table for coordinates of the other vertex of the cell
483 coordtype right [MaxDim];
484
485 // get the dimension of the space and of the cell
486 int d = q. dim ();
487
488 // calculate the coordinates of other vertex of the cell
489 for (int i = 0; i < d; ++ i)
490 right [i] = left [i] + ((i < facedim) ? 1 : 0);
491
492 // initialize the cell
493 initialize (left, right, d, facedim);
494 return;
495} /* tCellVar::tCellVar */

◆ tCellVar() [5/7]

template<class coordtype >
chomp::homology::tCellVar< coordtype >::tCellVar ( const tCubeVar< coordtype > &  q)
inlineexplicit

The constructor of a full-dimensional cubical cell.

Definition at line 451 of file cellvar.h.

454{
455 // get the coordinates of minimal vertex of the cube
456 const coordtype *left = q. tab + 1;
457
458 // get the dimension of the space and of the cell
459 int d = q. dim ();
460
461 // prepare a table for coordinates of the other vertex of the cell
462 coordtype right [MaxDim];
463
464 // calculate the coordinates of other vertex of the cell
465 for (int i = 0; i < d; ++ i)
466 right [i] = left [i] + 1;
467
468 // initialize the cell
469 initialize (left, right, d, d);
470 return;
471} /* tCellVar::tCellVar */

◆ tCellVar() [6/7]

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 249 of file cellvar.h.

251{
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);
258// *** More efficient [unfinished, yet] ***
259// tab = new coordtype [spcdim];
260// if (!tab)
261// throw "Not enough memory to create a projected cell.";
262// for (int i = 0; i < spcdim; ++ i)
263// tab [i] = q. tab [i];
264// [...]
265 return;
266} /* tCellVar::tCellVar */
coordtype * rightcoord(coordtype *c) const
Fills in the given table with the right corner coordinates.
Definition: cellvar.h:315
const int NumBits
The number of bits in an integer number that remain to be used for other purposes,...
Definition: pointbas.h:71

References chomp::homology::NumBits.

◆ tCellVar() [7/7]

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

The copy constructor.

Definition at line 269 of file cellvar.h.

270{
271 n = q. n;
272 tab = new coordtype [spacedim ()];
273 if (!tab)
274 throw "Not enough memory to copy a cubical cell.";
275 copycoord (tab, q. tab, spacedim ());
276 return;
277} /* tCellVar::tCellVar */
int spacedim() const
Returns the dimension of the embedding space of the cubical cell.
Definition: cellvar.h:243
void copycoord(coordtype *destination, const coordtype *source, int dim)
Copies the coordinates of one point to another.
Definition: pointset.h:108

References chomp::homology::copycoord().

Member Function Documentation

◆ dim()

template<class coordtype >
int chomp::homology::tCellVar< coordtype >::dim
inline

Returns the dimension of the cubical cell.

Definition at line 231 of file cellvar.h.

232{
233 int count = 0;
234 for (int i = 0; i < NumBits; ++ i)
235 {
236 if (n & (static_cast<int_t> (1) << i))
237 ++ count;
238 }
239 return count;
240} /* tCellVar::dim */
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115

References chomp::homology::NumBits.

◆ hashkey1()

template<class coordtype >
int_t chomp::homology::tCellVar< coordtype >::hashkey1
inline

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

Definition at line 331 of file cellvar.h.

332{
333 switch (spacedim ())
334 {
335 case 0:
336 return 0;
337 case 1:
338 return (static_cast<int_t> (tab [0]) << 12) ^ n;
339 case 2:
340 return (((static_cast<int_t> (tab [0])) << 18) +
341 ((static_cast<int_t> (tab [1])) << 6)) ^ n;
342 default:
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;
346 }
347} /* tCellVar::hashkey1 */

◆ hashkey2()

template<class coordtype >
int_t chomp::homology::tCellVar< coordtype >::hashkey2
inline

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

Definition at line 356 of file cellvar.h.

357{
358 int d = spacedim ();
359 switch (d)
360 {
361 case 0:
362 return 0;
363 case 1:
364 return (static_cast<int_t> (tab [0]) << 3) ^ (n << 5);
365 case 2:
366 return ((static_cast<int_t> (tab [0]) >> 1) +
367 (static_cast<int_t> (tab [1]) << 13)) ^ (n << 5);
368 default:
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)) ^
372 (n << 5);
373 }
374} /* tCellVar::hashkey2 */

◆ initialize()

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

Initializes a new cell given its two corners.

Definition at line 182 of file cellvar.h.

184{
185 // test the validity of the dimension
186 if (spcdim <= 0)
187 throw "Non-positive dimension of the space.";
188 else if (spcdim >= MaxDim)
189 throw "Too high dimension of a cell.";
190
191 // initialize the internal number with the space dimension
192 n = static_cast<int_t> (spcdim) << NumBits;
193
194 // prepare a table for coordinates if necessary
195 tab = new coordtype [spcdim];
196 if (!tab)
197 throw "Not enough memory to create a cell.";
198
199 // copy the left corner coordinates to the cell
200 PointBase::wrapcopy (tab, c1, spcdim);
201
202 // prepare wrapped right coordinates for the detection of cell bits
203 coordtype r [MaxDim];
204 PointBase::wrapcopy (r, c2, spcdim);
205
206 // set the bits of the cell
207 for (int i = 0; i < spcdim; ++ i)
208 {
209 if (tab [i] != r [i])
210 n |= (static_cast<int_t> (1) << i);
211 }
212 return;
213} /* tCellVar::initialize */
static void wrapcopy(coordtype *dest, const coordtype *src, int dim)
Copies the coordinates and wraps them if necessary.
Definition: pointbas.h:322

References chomp::homology::NumBits, and chomp::homology::tPointBase< coordtype >::wrapcopy().

◆ leftcoord()

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 304 of file cellvar.h.

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

◆ name()

template<class coordtype >
const char * chomp::homology::tCellVar< coordtype >::name
static

Returns the name of the objects represented by this class.

Definition at line 383 of file cellvar.h.

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

◆ operator=()

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

The assignment operator.

Definition at line 280 of file cellvar.h.

282{
283 // determine the new dimension
284 int d = q. spacedim ();
285
286 // allocate a new table if the dimension is to be changed
287 if (d != spacedim ())
288 {
289 if (tab)
290 delete [] tab;
291 tab = new coordtype [d];
292 if (!tab)
293 throw "Not enough memory to copy a cubical cell.";
294 }
295
296 // copy the data of the cubical cell
297 copycoord (tab, q. tab, d);
298 n = q. n;
299
300 return *this;
301} /* tCellVar::operator = */

References chomp::homology::copycoord().

◆ pluralname()

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 389 of file cellvar.h.

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

◆ rightcoord()

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 315 of file cellvar.h.

316{
317 if (!c)
318 throw "Null pointer to save right coordinates.";
319 int d = spacedim ();
320 for (int i = 0; i < d; ++ i)
321 {
322 c [i] = tab [i];
323 if (n & (static_cast<int_t> (1) << i))
324 ++ (c [i]);
325 }
327 return c;
328} /* tCellVar::rightcoord */
static void wrapcoord(coordtype *c, int dim)
Wraps the given coordinates if necessary.
Definition: pointbas.h:311

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

◆ spacedim()

template<class coordtype >
int chomp::homology::tCellVar< coordtype >::spacedim
inline

Returns the dimension of the embedding space of the cubical cell.

Definition at line 243 of file cellvar.h.

244{
245 return static_cast<int> (n >> NumBits);
246} /* tCellVar::spacedim */

References chomp::homology::NumBits.

Friends And Related Function Documentation

◆ operator==

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

Verifies if two cells are identical.

Definition at line 152 of file cellvar.h.

154 {
155 return ((c1. n == c2. n) && ((c1. n == 0) ||
156 thesame (c1. tab, c2. tab, c1. spacedim ())));
157 } /* operator == */
int thesame(const coordtype *c1, const coordtype *c2, int dim)
Compare two points. Returns true iff they have the same coordinates.
Definition: pointset.h:98

Member Data Documentation

◆ MaxDim

template<class coordtype >
const int chomp::homology::tCellVar< coordtype >::MaxDim
static
Initial value:
=
static const int MaxDim
The maximal dimension of a cube.
Definition: cubevar.h:81
const int MaxBasDim
The maximal dimension that can be used if the high bits of an integer store the value of the dimensio...
Definition: pointbas.h:89

The maximal dimension of a cell.

Definition at line 74 of file cellvar.h.

◆ MaxSpaceDim

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 79 of file cellvar.h.

◆ n

template<class coordtype >
int_t chomp::homology::tCellVar< coordtype >::n
private

High 6 bits = the dimension of the space.

Remaining bits set to 1 iff the cell has width 1 in the specified direction.

Definition at line 166 of file cellvar.h.

◆ OutputBits

template<class coordtype >
int chomp::homology::tCellVar< coordtype >::OutputBits = 0
static

The output bits which determine how a cell is written.

Definition at line 147 of file cellvar.h.

◆ tab

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

The lower left etc. corner of the cell.

Definition at line 161 of file cellvar.h.


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