The Original CHomP Software
cubefix.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_CUBEFIX_H_
37#define _CHOMP_CUBES_CUBEFIX_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 <int dimfix, class coordtype>
59class tCellFix;
60
61
62// --------------------------------------------------
63// ------------ Cube of fixed dimension -------------
64// --------------------------------------------------
65
70template <int dimfix, class coordtype>
72{
73public:
75 typedef coordtype CoordType;
76
79
81 static const int MaxDim = 512;
82
85
88
90 tCubeFix (const coordtype *c, int dim = 0);
91
93 tCubeFix (int number, int dim);
94
97
101
103 int dim () const;
104
106// template <class intType>
107// intType *coord (intType *c) const;
108 coordtype *coord (coordtype *c) const;
109
111 int_t hashkey1 () const;
112
114 int_t hashkey2 () const;
115
117 static const char *name ();
118
120 static const char *pluralname ();
121
125 {
126 return thesame (c1. tab, c2. tab, dimfix);
127 }
128
129 // friend class: cubical cell
130 friend class tCellFix<dimfix, coordtype>;
131
132private:
134 coordtype tab [dimfix];
135
136}; /* class tCubeFix */
137
138// --------------------------------------------------
139
140template <int dimfix, class coordtype>
142{
143 return;
144} /* tCubeFix::tCubeFix */
145
146template <int dimfix, class coordtype>
148 (const coordtype *c, int dim)
149{
150 if (dim && ((dim != dimfix) || (dim < 0)))
151 throw "Wrong dimension of a fixed-dim cube.";
152 PointBase::wrapcopy (tab, c, dimfix);
153 return;
154} /* tCubeFix::tCubeFix */
155
156template <int dimfix, class coordtype>
158{
159 throw "Unable to construct a cube from a number.";
160} /* tCubeFix::tCubeFix */
161
162template <int dimfix, class coordtype>
165{
166 for (int i = 0; i < dimfix; ++ i)
167 tab [i] = c. tab [i];
168 return;
169} /* tCubeFix::tCubeFix */
170
171template <int dimfix, class coordtype>
174{
175 for (int i = 0; i < dimfix; ++ i)
176 tab [i] = c. tab [i];
177 return *this;
178} /* tCubeFix::operator = */
179
180template <int dimfix, class coordtype>
182{
183 return dimfix;
184} /* tCubeFix::dim */
185
186//template <int dimfix, class coordtype>
187//template <class intType>
188//inline intType *tCubeFix<dimfix,coordtype>::coord (intType *c) const
189//{
190// for (int i = 0; i < dimfix; ++ i)
191// c [i] = static_cast<const intType> (tab [i]);
192// return c;
193//} /* tCubeFix::coord */
194
195template <int dimfix, class coordtype>
196inline coordtype *tCubeFix<dimfix,coordtype>::coord (coordtype *c) const
197{
198 for (int i = 0; i < dimfix; ++ i)
199 c [i] = tab [i];
200 return c;
201} /* tCubeFix::coord */
202
203template <int dimfix, class coordtype>
205{
206 switch (dimfix)
207 {
208 case 1:
209 return static_cast<int_t> (tab [0]) << 12;
210 case 2:
211 return ((static_cast<int_t> (tab [0])) << 18) +
212 ((static_cast<int_t> (tab [1])) << 6);
213 default:
214 return ((static_cast<int_t> (tab [0])) << 18) +
215 ((static_cast<int_t> (tab [1])) << 6) +
216 ((static_cast<int_t> (tab [2])) >> 6);
217 }
218} /* tCubeFix::hashkey1 */
219
220template <int dimfix, class coordtype>
222{
223 return c. hashkey1 ();
224} /* hashkey1 */
225
226template <int dimfix, class coordtype>
228{
229 switch (dimfix)
230 {
231 case 1:
232 return static_cast<int_t> (tab [0]) << 3;
233 case 2:
234 return (static_cast<int_t> (tab [0]) >> 1) +
235 (static_cast<int_t> (tab [1]) << 13);
236 default:
237 return ((static_cast<int_t> (tab [dimfix - 1])) << 20) +
238 ((static_cast<int_t> (tab [dimfix - 2])) << 9) +
239 ((static_cast<int_t> (tab [dimfix - 3])) >> 1);
240 }
241} /* tCubeFix::hashkey2 */
242
243template <int dimfix, class coordtype>
245{
246 return c. hashkey2 ();
247} /* hashkey2 */
248
249template <int dimfix, class coordtype>
251{
252 return "cube";
253} /* tCubeFix::name */
254
255template <int dimfix, class coordtype>
257{
258 return "cubes";
259} /* tCubeFix::pluralname */
260
262template <int dim1, int dim2, class coordtype>
264 const tCubeFix<dim2,coordtype> &c2)
265{
266 return !(c1 == c2);
267} /* operator != */
268
269// --------------------------------------------------
270
272template <int dim1, int dim2, class coordtype>
274 (const tCubeFix<dim1,coordtype> &c1,
275 const tCubeFix<dim2,coordtype> &c2)
276{
277 coordtype coord [dim1 + dim2];
278 c1. coord (coord);
279 c2. coord (coord + dim1);
280 return tCubeFix<dim1+dim2,coordtype> (coord);
281} /* operator * */
282
283// --------------------------------------------------
284
288template <int dimfix, class coordtype>
289inline std::ostream &operator << (std::ostream &out,
291{
292 return WriteCube (out, c);
293} /* operator << */
294
298template <int dimfix, class coordtype>
299inline std::istream &operator >> (std::istream &in,
301{
302 return ReadCubeFix (in, c, dimfix);
303} /* operator >> */
304
306template <int dimfix, class coordtype>
307inline std::istream &operator >> (std::istream &in,
309{
310 return ReadCubes (in, s);
311} /* operator >> */
312
314template <int dimfix, class coordtype>
315inline std::istream &operator >> (std::istream &in,
317{
318 return ReadCubicalMap (in, m);
319} /* operator >> */
320
321
322} // namespace homology
323} // namespace chomp
324
325#endif // _CHOMP_CUBES_CUBEFIX_H_
326
328
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: cellfix.h:69
This class defines a hypercube in R^n with edges parallel to the axes and with size 1 in each directi...
Definition: cubefix.h:72
int_t hashkey1() const
Returns hashing key no. 1 required by the hashing set template.
Definition: cubefix.h:204
tCellFix< dimfix, coordtype > CellType
The type of a cell related to this cube type.
Definition: cubefix.h:78
coordtype CoordType
The type of coordinates of a cube.
Definition: cubefix.h:75
tCubeFix(int number, int dim)
The constructor of a cube from a number (invalid in this class).
Definition: cubefix.h:157
tWrapBase< coordtype > PointBase
The point base (for wrapping and tabulating coordinates).
Definition: cubefix.h:84
coordtype * coord(coordtype *c) const
Fills out the coordinate table with the cube's coordinates.
Definition: cubefix.h:196
tCubeFix(const coordtype *c, int dim=0)
The constructor of a cube from a table of coordinates.
Definition: cubefix.h:148
tCubeFix(const tCubeFix< dimfix, coordtype > &c)
The copy constructor.
Definition: cubefix.h:164
friend int operator==(const tCubeFix< dimfix, coordtype > &c1, const tCubeFix< dimfix, coordtype > &c2)
The operator == for cubes.
Definition: cubefix.h:123
coordtype tab[dimfix]
A table with the coordinates of the minimal vertex of the cube.
Definition: cubefix.h:134
int dim() const
Returns the dimension of the cube.
Definition: cubefix.h:181
static const char * name()
Returns the name of the objects represented by this class.
Definition: cubefix.h:250
static const char * pluralname()
Returns the plural name of the objects represented by this class.
Definition: cubefix.h:256
static const int MaxDim
The maximal dimension of a cube (unused).
Definition: cubefix.h:81
tCubeFix()
The default constructor.
Definition: cubefix.h:141
int_t hashkey2() const
Returns hashing key no. 2 required by the hashing set template.
Definition: cubefix.h:227
static void wrapcopy(coordtype *dest, const coordtype *src, int dim)
Copies the coordinates and wraps them if necessary.
Definition: pointbas.h:322
This class is a simplified version of the point base class used only for the space wrapping support.
Definition: pointbas.h:471
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
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
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
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
std::istream & ReadCubeFix(std::istream &in, cubetype &c, int dimfix)
Reads a cube from the input text stream.
Definition: cubemain.h:90
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.