The Original CHomP Software
cubebase.h
Go to the documentation of this file.
1
3
16
17// Copyright (C) 1997-2020 by Pawel Pilarczyk.
18//
19// This file is part of my research software package. This is free software:
20// you can redistribute it and/or modify it under the terms of the GNU
21// General Public License as published by the Free Software Foundation,
22// either version 3 of the License, or (at your option) any later version.
23//
24// This software is distributed in the hope that it will be useful,
25// but WITHOUT ANY WARRANTY; without even the implied warranty of
26// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27// GNU General Public License for more details.
28//
29// You should have received a copy of the GNU General Public License
30// along with this software; see the file "license.txt". If not,
31// please, see <https://www.gnu.org/licenses/>.
32
33// Started in January 2002. Last revision: October 24, 2013.
34
35
36#ifndef _CHOMP_CUBES_CUBEBASE_H_
37#define _CHOMP_CUBES_CUBEBASE_H_
38
39#include "chomp/system/config.h"
47
48#include <iostream>
49#include <fstream>
50#include <cstdlib>
51#include <cstring>
52
53namespace chomp {
54namespace homology {
55
56
57// a friend class template
58template <class coordtype>
59class tCellBase;
60
61
62// --------------------------------------------------
63// -------------- Cube with PointBase ---------------
64// --------------------------------------------------
65
70template <class coordtype>
72{
73public:
75 typedef coordtype CoordType;
76
79
81 static const int MaxDim = MaxBasDim;
82
85
87 tCubeBase ();
88
90 tCubeBase (const coordtype *c, int dim);
91
94 tCubeBase (int_t number, int dim);
95
98
100 tCubeBase<coordtype> &operator =
101 (const tCubeBase<coordtype> &c);
102
104 int dim () const;
105
107// template <class intType>
108// intType *coord (intType *c) const;
109 coordtype *coord (coordtype *c) const;
110
112 int_t hashkey1 () const;
113
115 int_t hashkey2 () const;
116
118 static const char *name ();
119
121 static const char *pluralname ();
122
123 // --- friends: ---
124
126 friend inline int operator == (const tCubeBase<coordtype> &c1,
127 const tCubeBase<coordtype> &c2)
128 {
129 return c1. n == c2. n;
130 } /* operator == */
131
132 // friend class: cubical cell
133 friend class tCellBase<coordtype>;
134
135private:
137 int_t num () const;
138
143
144}; /* class tCubeBase */
145
146// --------------------------------------------------
147
148template <class coordtype>
150{
151 return (n & NumMask);
152} /* tCubeBase::num */
153
154// --------------------------------------------------
155
156template <class coordtype>
158: n (0)
159{
160 return;
161} /* tCubeBase::tCubeBase */
162
163template <class coordtype>
164inline tCubeBase<coordtype>::tCubeBase (const coordtype *c,
165 int dim)
166{
167 if (dim <= 0)
168 throw "Non-positive dimension of a cube.";
169 if (dim >= MaxDim)
170 throw "Too high space dimension.";
171 n = PointBase::number (c, dim);
172 if (n < 0)
173 throw "Negative number of a cube.";
174 n |= (static_cast<int_t> (dim) << NumBits);
175 return;
176} /* tCubeBase::tCubeBase */
177
178template <class coordtype>
180{
181 n = number | (static_cast<int_t> (dim) << NumBits);
182 return;
183} /* tCubeBase::tCubeBase */
184
185template <class coordtype>
187{
188 n = c. n;
189 return;
190} /* tCubeBase::tCubeBase */
191
192template <class coordtype>
194 (const tCubeBase<coordtype> &c)
195{
196 n = c. n;
197 return *this;
198} /* tCubeBase::operator = */
199
200template <class coordtype>
201inline int tCubeBase<coordtype>::dim () const
202{
203 return static_cast<int> (n >> NumBits);
204} /* tCubeBase::dim */
205
206//template <class coordtype>
207//template <class intType>
208//inline intType *tCubeBase<coordtype>::coord (intType *c) const
209//{
210// int d = dim ();
211// const coordtype *tab = PointBase::coord (num (), d);
212// for (int i = 0; i < d; ++ i)
213// c [i] = static_cast<const intType> (tab [i]);
214// return c;
215//} /* tCubeBase::coord */
216
217template <class coordtype>
218inline coordtype *tCubeBase<coordtype>::coord (coordtype *c) const
219{
220 int d = dim ();
221 const coordtype *tab = PointBase::coord (num (), d);
222 for (int i = 0; i < d; ++ i)
223 c [i] = tab [i];
224 return c;
225} /* tCubeBase::coord */
226
227template <class coordtype>
229{
230 return static_cast<int_t>
231 (((n ^ 0x55555555u) << 17) ^ ((n ^ 0xAA00AA00u) << 7) ^
232 ((n ^ 0x00AA00AAu) >> 7));
233} /* tCubeBase::hashkey1 */
234
235template <class coordtype>
237{
238 return c. hashkey1 ();
239} /* hashkey1 */
240
241template <class coordtype>
243{
244 return static_cast<int_t>
245 (((n ^ 0xAAAAAAAAu) << 18) ^ ((n ^ 0x55005500u) >> 8) ^
246 ((n ^ 0x00550055u) << 10));
247} /* tCubeBase::hashkey2 */
248
249template <class coordtype>
251{
252 return c. hashkey2 ();
253} /* hashkey2 */
254
255template <class coordtype>
256inline const char *tCubeBase<coordtype>::name ()
257{
258 return "cube";
259} /* tCubeBase::name */
260
261template <class coordtype>
263{
264 return "cubes";
265} /* tCubeBase::pluralname */
266
267// --------------------------------------------------
268
270template <class coordtype>
272 const tCubeBase<coordtype> &c2)
273{
274 return !(c1 == c2);
275} /* operator != */
276
277// --------------------------------------------------
278
280template <class coordtype>
282 const tCubeBase<coordtype> &c2)
283{
284 int dim1 = c1. dim (), dim2 = c2. dim ();
285 if (dim1 + dim2 >= tCubeBase<coordtype>::MaxDim)
286 throw "Dimension too high to concatenate coordinates.";
287 coordtype coord [tCubeBase<coordtype>::MaxDim];
288 c1. coord (coord);
289 c2. coord (coord + dim1);
290 return tCubeBase<coordtype> (coord, dim1 + dim2);
291} /* operator * */
292
293// --------------------------------------------------
294
298template <class coordtype>
299inline std::ostream &operator << (std::ostream &out,
300 const tCubeBase<coordtype> &c)
301{
302 return WriteCube (out, c);
303} /* operator << */
304
308template <class coordtype>
309inline std::istream &operator >> (std::istream &in, tCubeBase<coordtype> &c)
310{
311 return ReadCube (in, c);
312} /* operator >> */
313
315template <class coordtype>
316inline std::istream &operator >> (std::istream &in,
318{
319 return ReadCubes (in, s);
320} /* operator >> */
321
323template <class coordtype>
324inline std::istream &operator >> (std::istream &in,
326{
327 return ReadCubicalMap (in, m);
328} /* operator >> */
329
330
331} // namespace homology
332} // namespace chomp
333
334#endif // _CHOMP_CUBES_CUBEBASE_H_
335
337
This file contains the definition of a bitfield class which works an array of bits.
This is a template for a set of objects of the given type.
Definition: hashsets.h:185
This class defines a multivalued map.
Definition: hashsets.h:945
This class defines cubical cell in R^n with edges parallel to the axes and with size 0 or 1 in each d...
Definition: cellbase.h:69
This class defines a hypercube in R^n with edges parallel to the axes and with size 1 in each directi...
Definition: cubebase.h:72
coordtype CoordType
The type of coordinates of a cube.
Definition: cubebase.h:75
tCubeBase()
The default constructor.
Definition: cubebase.h:157
tCellBase< coordtype > CellType
The type of a cell related to this cube type.
Definition: cubebase.h:78
int_t hashkey2() const
Returns hashing key no. 2 required by the hashing set template.
Definition: cubebase.h:242
int_t n
The number that represents the full cube.
Definition: cubebase.h:142
static const char * pluralname()
Returns the plural name of the objects represented by this class.
Definition: cubebase.h:262
static const int MaxDim
The maximal dimension of a cube.
Definition: cubebase.h:81
int dim() const
Returns the dimension of the cube.
Definition: cubebase.h:201
friend int operator==(const tCubeBase< coordtype > &c1, const tCubeBase< coordtype > &c2)
The operator == for cubes.
Definition: cubebase.h:126
static const char * name()
Returns the name of the objects represented by this class.
Definition: cubebase.h:256
int_t num() const
Returns the actual number of the cube in the point base.
Definition: cubebase.h:149
coordtype * coord(coordtype *c) const
Fills out the coordinate table with the cube's coordinates.
Definition: cubebase.h:218
tPointBase< coordtype > PointBase
The point base (for wrapping and tabulating coordinates).
Definition: cubebase.h:84
int_t hashkey1() const
Returns hashing key no. 1 required by the hashing set template.
Definition: cubebase.h:228
This class keeps a common set of points which are indexed for the use of other classes,...
Definition: pointbas.h:102
static const coordtype * coord(int_t number, int d)
Retrieves the coordinates of the given point.
Definition: pointbas.h:183
static int_t number(const coordtype *c, int d)
Returns the number of the point with given coordinates.
Definition: pointbas.h:211
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
This file contains the definition of some functions that are common for all types of cubes,...
int int_t
Index type for indexing arrays, counting cubes, etc.
Definition: config.h:115
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...
std::ostream & WriteCube(std::ostream &out, const cubetype &c)
Writes a cube to the output stream in the text mode.
Definition: cubemain.h:69
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
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
Definition: bincube.h:907
std::istream & ReadCubes(std::istream &in, cubsettype &s)
Reads a set of cubes and ignores the line at the beginning of the file which starts with the letter '...
Definition: cubemain.h:193
int_t hashkey2(const hashNumber< Number > &n)
The second hashing key.
Definition: bincube.h:1036
tCellBase< coordtype > operator*(const tCellBase< coordtype > &c1, const tCellBase< coordtype > &c2)
Computes the Cartesian product of two cells.
Definition: cellbase.h:438
const int NumBits
The number of bits in an integer number that remain to be used for other purposes,...
Definition: pointbas.h:71
std::istream & ReadCube(std::istream &in, cubetype &c)
Reads a cube from the input text stream.
Definition: cubemain.h:184
bool operator!=(const typename bincube< Dim, twoPower >::neighborhood_iterator &x1, const typename bincube< Dim, twoPower >::neighborhood_iterator &x2)
Definition: bincube.h:794
std::istream & operator>>(std::istream &in, bincube< Dim, twoPower > &b)
Definition: bincube.h:914
int_t hashkey1(const hashNumber< Number > &n)
The first hashing key.
Definition: bincube.h:1029
const int_t NumMask
The mask of the bits remaining after the dimension bits are excluded.
Definition: pointbas.h:77
std::istream & ReadCubicalMap(std::istream &in, mvmap< tCube, tCube > &m)
Reads a combinatorial cubical multivalued map from an input text stream.
Definition: cubemain.h:211
This namespace contains the entire CHomP library interface.
Definition: bitmaps.h:51
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.