45#ifndef _CHOMP_CUBES_POINTSET_H_
46#define _CHOMP_CUBES_POINTSET_H_
69template <
class coordtype>
73template <
class coordtype>
77template <
class coordtype>
97template <
class coordtype>
98inline int thesame (
const coordtype *c1,
const coordtype *c2,
int dim)
100 for (
int i = 0; i < dim; ++ i)
101 if (c1 [i] != c2 [i])
107template <
class coordtype>
108inline void copycoord (coordtype *destination,
const coordtype *source,
111 for (
int i = 0; i < dim; ++ i)
112 destination [i] = source [i];
118template <
class coordtype>
119inline void wrapcoord (coordtype *destination,
const coordtype *source,
120 const coordtype *wrap,
int dim)
122 if (!destination || !source)
123 throw "Trying to wrap NULL coordinates.";
125 for (
int i = 0; i < dim; ++ i)
129 (coordtype) (source [i] % wrap [i]);
130 if (destination [i] < 0)
131 destination [i] += wrap [i];
134 destination [i] = source [i];
143 const double *wrap,
int dim)
145 if (!destination || !source)
146 throw "Trying to wrap NULL coordinates.";
148 throw "Wrapping 'double' coordinates not implemented yet!";
179template <
class coordtype>
183 for (
int i = 0; i < dim; ++ i)
185 key ^=
static_cast<int_t> ((c [i] > 0) ? c [i] : -c [i]) <<
192 return (key % hashsize);
197template <
class coordtype>
201 for (
int i = 0; i < dim; ++ i)
202 add ^=
static_cast<int_t> ((c [i] > 0) ? c [i] : -c [i]) <<
203 (((i << 4) + 3) % 21);
208 return (add % (hashsize - 1) + 1);
213template <
class coordtype>
216 if ((x >= 0) || ((
double) (coordtype) x == x))
217 return (coordtype) x;
219 return -(coordtype) (-x) - 1;
225template <
class coordtype>
226inline void roundpoint (
const double *p, coordtype *c,
const double *grid,
231 for (
int i = 0; i < dim; ++ i)
232 c [i] = rounddown<coordtype> (p [i] / grid [i]);
236 for (
int i = 0; i < dim; ++ i)
237 c [i] = rounddown<coordtype> (p [i]);
244template <
class coordtype>
245inline void cubemiddle (coordtype *c,
double *p,
double *grid,
int dim)
249 for (
int i = 0; i < dim; ++ i)
250 p [i] = (c [i] + 0.5) * grid [i];
254 for (
int i = 0; i < dim; ++ i)
261template <
class coordtype>
264 coordtype *temp =
new coordtype [dim];
267 throw (errormessage ? errormessage :
268 "Can't allocate memory for a temporary point.");
281template <
class coordtype>
282int countneighbors (
const tPointset<coordtype> &p,
const coordtype *c,
283 int which =
INSIDE,
int maxcount = 0);
286template <
class coordtype>
289 int which =
INSIDE,
int maxcount = 0);
292template <
class coordtype>
299template <
class coordtype>
304template <
class coordtype>
309template <
class coordtype>
314template <
class coordtype>
319template <
class coordtype>
324template <
class coordtype>
329template <
class coordtype>
338template <
class coordtype>
346template <
class coordtype>
347int read (std::istream &in, coordtype *c,
int maxdim);
352template <
class coordtype>
353int write (std::ostream &out,
const coordtype *c,
int dim,
354 char parenthesis = 40,
char closing = 0);
364template <
class coordtype>
365int readcubeorcell (std::istream &in, coordtype *left, coordtype *right,
366 int maxdim,
int *type = NULL);
371template <
class coordtype>
372int_t read (textfile &f, tPointset<coordtype> &p,
374 coordtype *wrap = NULL,
int maxdim = 0,
int quiet = 0,
375 tPointset<coordtype> *notthese = NULL);
379template <
class coordtype>
380int_t read (std::istream &in, tPointset<coordtype> &p,
382 coordtype *wrap = NULL,
int maxdim = 0,
int quiet = 0,
383 tPointset<coordtype> *notthese = NULL);
387template <
class coordtype>
388int_t read (textfile &f, tPointset<coordtype> &p,
389 coordtype *wrap,
int maxdim,
390 int quiet = 0, tPointset<coordtype> *notthese = NULL);
394template <
class coordtype>
395int_t read (std::istream &in, tPointset<coordtype> &p,
396 coordtype *wrap,
int maxdim,
397 int quiet = 0, tPointset<coordtype> *notthese = NULL);
400template <
class coordtype>
401textfile &
operator >> (textfile &f, tPointset<coordtype> &p);
404template <
class coordtype>
405std::istream &
operator >> (std::istream &in, tPointset<coordtype> &p);
410template <
class coordtype>
411int_t write (std::ostream &out, tPointset<coordtype> &p,
412 int_t first = 0,
int_t howmany = -1,
int quiet = 0);
415template <
class coordtype>
416std::ostream &
operator << (std::ostream &out, tPointset<coordtype> &p);
467 out <<
"hashing: " << s. hashhits <<
" hits, avg " <<
468 ((s. hashhits + s. hashmisses) / s. hashhits) <<
"." <<
469 ((s. hashhits + s. hashmisses) * 10 / s. hashhits) % 10 <<
470 " attempts (" << s. rehashcount <<
" times rehashed)";
480template <
class coordtype>
526 double *
gridsize (
int direction,
double g);
530 const coordtype *
wrapspace (
const coordtype *w = NULL);
532 const coordtype *
wrapspace (coordtype w);
534 const coordtype *
wrapspace (
int direction, coordtype w);
544 int check (
const coordtype *c)
const;
557 coordtype *
getpoint (coordtype *c)
const;
572 int remove (
const coordtype *c);
676 int_t *addposition = NULL,
int wrapped = 0)
const;
687template <
class coordtype>
690template <
class coordtype>
693template <
class coordtype>
698template <
class coordtype>
708 delete [] defaultgrid;
711 delete [] defaultwrap;
723template <
class coordtype>
728 if ((direction < 0) || (direction >= dim) || !dim || (g <= 0))
734 grid =
new double [dim];
736 throw "Can't allocate memory for the grid.";
737 for (
int i = 0; i < dim; ++ i)
742 if (dim != defaultdim)
743 defaultdimension (dim);
748 defaultgrid =
new double [dim];
750 throw "Can't alloc mem for the default grid.";
751 for (
int i = 0; i < dim; ++ i)
752 defaultgrid [i] = grid [i];
756 grid [direction] = g;
757 defaultgrid [direction] = g;
763template <
class coordtype>
767 for (
int i = 0; i < dim; ++ i)
774template <
class coordtype>
782 for (
int i = 0; i < dim; ++ i)
789template <
class coordtype>
791 (
int direction, coordtype w)
795 if ((direction < 0) || (direction >= dim) || !dim || (w < 0))
801 wrap =
new coordtype [dim];
803 throw "Can't alloc mem for the wrap table.";
804 for (
int i = 0; i < dim; ++ i)
809 if (dim != defaultdim)
810 defaultdimension (dim);
815 defaultwrap =
new coordtype [dim];
817 throw "Can't alloc mem for the def. WrapTab.";
818 for (
int i = 0; i < dim; ++ i)
819 defaultwrap [i] = wrap [i];
823 wrap [direction] = w;
824 defaultwrap [direction] = w;
830template <
class coordtype>
834 for (
int i = 0; i < dim; ++ i)
841template <
class coordtype>
849 for (
int i = 0; i < dim; ++ i)
850 wrapspace (i, w [i]);
856template <
class coordtype>
861 defaultdimension (d);
864 if (!npoints && (d > 0))
872 gridsize (defaultgrid);
876 wrapspace (defaultwrap);
890template <
class coordtype>
896template <
class coordtype>
902template <
class coordtype>
908template <
class coordtype>
915 std::swap (
this -> minimal, other. minimal);
916 std::swap (
this -> maximal, other. maximal);
917 std::swap (
this -> wereremoved, other. wereremoved);
919 std::swap (
this -> npoints, other. npoints);
920 std::swap (
this -> ntables, other. ntables);
921 std::swap (
this -> tablepoints, other. tablepoints);
922 std::swap (
this -> tables, other. tables);
926 std::swap (
this -> hashsize, other. hashsize);
927 std::swap (
this -> hashcleared, other. hashcleared);
928 std::swap (
this -> hashtable, other. hashtable);
929 std::swap (
this -> initsize, other. initsize);
939template <
class coordtype>
942 if ((n < 0) || (n >= npoints))
945 return (tables [n / tablepoints] + (n % tablepoints) * dim);
948template <
class coordtype>
950 int_t *addpos,
int wrapped)
const
957 if (!wrapped && wrap)
960 throw "Unable to wrap point's coordinates.";
970 ++ (stat -> hashhits);
974 while ((number = hashtable [pos]) != -1)
976 if ((number >= 0) &&
thesame ((*
this) [number], c, dim))
978 if (addpos && (*addpos < 0) && (number == -2))
982 pos = (pos + add) % hashsize;
983 ++ (stat -> hashmisses);
990template <
class coordtype>
996 else if (!npoints && initsize && !hashsize)
1000 if (newsize <= npoints + npoints / 5)
1007 if ((x < 0) && (newsize >= 16384))
1008 throw "Pointset too large for a 16-bit prog.";
1012 if (hashsize && !quiet)
1013 sout <<
"(Changing the hashing table from " << hashsize <<
1014 " to " << newsize <<
" at " << npoints <<
" points) ";
1016 sout <<
"(Using a hashing table for " << newsize <<
" ";
1021 delete [] hashtable;
1022 hashtable =
new int_t [hashsize];
1024 throw "Can't allocate memory for a hashing table.";
1025 for (
int_t i = 0; i < hashsize; ++ i)
1030 for (
int_t j = 0; j < npoints; ++ j)
1032 int_t n = hashfindpoint ((*
this) [j], NULL, 1);
1033 if (hashtable [n] != -1)
1034 throw "A repeated point found in the hashing table.";
1038 ++ (stat -> rehashcount);
1041 sout <<
"points.)\n";
1046template <
class coordtype>
1055 throw "Trying to add a point of unknown dimension.";
1061 temp = allocatepoint<coordtype> (dim);
1067 if (hashsize - hashcleared <= npoints + npoints / 5)
1072 int_t pos = hashfindpoint (c, &addpos, 1);
1075 if (hashtable [pos] >= 0)
1076 return hashtable [pos];
1081 for (
int i = 0; i < dim; ++ i)
1082 if (minimal [i] > c [i])
1083 minimal [i] = c [i];
1087 minimal = allocatepoint<coordtype> (dim);
1093 for (
int i = 0; i < dim; ++ i)
1094 if (maximal [i] < c [i])
1095 maximal [i] = c [i];
1099 maximal = allocatepoint<coordtype> (dim);
1107 if (hashtable [pos] == -2)
1110 hashtable [pos] = npoints;
1114 int_t tablenumber = npoints / tablepoints;
1117 if (tablenumber >= ntables)
1119 int_t moretables = (ntables << 1) + 13;
1120 coordtype **newtables =
new coordtype * [moretables];
1122 throw "Unable to alloc a table for tables.";
1123 for (
int_t i = 0; i < moretables; ++ i)
1124 newtables [i] = (i < ntables) ? (tables [i]) :
1129 ntables = moretables;
1133 if (tables [tablenumber] == NULL)
1135 tables [tablenumber] =
new coordtype [tablepoints * dim];
1136 if (!tables [tablenumber])
1137 throw "Unable to alloc a table for coords.";
1142 ((npoints % tablepoints) * dim), c, dim);
1146 return (npoints ++);
1149template <
class coordtype>
1157 throw "Trying to add a point of unknown dimension.";
1159 temp = allocatepoint<coordtype> (dim);
1164template <
class coordtype>
1168 int_t size = p. size ();
1169 for (
int_t i = 0; i < size; ++ i)
1170 this -> add (p [i]);
1174template <
class coordtype>
1181 if (initialsize < 0)
1187 if (initialsize <= 0)
1189 else if (initialsize > 10000)
1190 tablepoints = 10000;
1192 tablepoints =
static_cast<int> (initialsize);
1201 dimension (defaultdimension ());
1202 gridsize (defaultgrid);
1203 wrapspace (defaultwrap);
1210 initsize = initialsize + initialsize / 5 + 3;
1222template <
class coordtype>
1225 initialize (initialsize, bequiet);
1229template <
class coordtype>
1232 initialize (p. size (), p. quiet);
1237template <
class coordtype>
1241 for (
int_t i = 0; i < ntables; ++ i)
1244 delete [] (tables [i]);
1267 delete [] hashtable;
1275template <
class coordtype>
1282 initialize (p. size (), p. quiet);
1287template <
class coordtype>
1294template <
class coordtype>
1302 int_t pos = hashfindpoint (c);
1305 return ((pos >= 0) ? hashtable [pos] :
static_cast<int_t> (-1));
1308template <
class coordtype>
1314 throw "Cannot round point's coordinates.";
1316 int_t pos = hashfindpoint (temp);
1317 return ((pos >= 0) ? hashtable [pos] :
static_cast<int_t> (-1));
1320template <
class coordtype>
1323 return ((n >= 0) && (n < npoints));
1326template <
class coordtype>
1329 return (getnumber (c) != -1);
1332template <
class coordtype>
1335 return (getnumber (c) != -1);
1338template <
class coordtype>
1344template <
class coordtype>
1347 return (*
this) [getnumber (c)];
1350template <
class coordtype>
1353 return (*
this) [getnumberRounded (c)];
1356template <
class coordtype>
1359 coordtype *coord = (*this) [n];
1362 for (
int i = 0; i < dim; ++ i)
1363 c [i] = (grid ? grid [i] : 1.0) * (0.5 + coord [i]);
1369template <
class coordtype>
1372 if ((n < 0) || (n >= npoints))
1377 coordtype *coord = (*this) [n];
1378 int_t pos = hashfindpoint (coord);
1381 hashtable [pos] = -2;
1384 if (n != npoints - 1)
1386 coordtype *lastcoord = (*this) [npoints - 1];
1387 int_t lastpos = hashfindpoint (lastcoord);
1388 hashtable [lastpos] = n;
1393 int_t tablenumber = npoints / tablepoints;
1394 if ((tablenumber + 2 < ntables) && tables [tablenumber + 2])
1396 delete [] (tables [tablenumber + 2]);
1397 tables [tablenumber + 2] = NULL;
1407 if (hashcleared > npoints + 13)
1413template <
class coordtype>
1416 return remove (getnumber (c));
1419template <
class coordtype>
1422 return remove (getnumberRounded (c));
1425template <
class coordtype>
1428 int_t size = p. size ();
1429 for (
int_t i = 0; i < size; ++ i)
1434template <
class coordtype>
1448template <
class coordtype>
1453 tNeighbors (
const coordtype *_source = NULL,
int _dim = 0,
1454 const coordtype *_wrap = NULL);
1473 void set (coordtype *_source);
1492 void initialize (
const coordtype *_source = NULL,
1493 int _dim = 0,
const coordtype *_wrap = NULL);
1502template <
class coordtype>
1504 const coordtype *_wrap)
1516 neighbor =
new coordtype [dim];
1517 counters =
new signed char [dim];
1518 if (!neighbor || !counters)
1519 throw "Can't allocate memory for neighbors.";
1524template <
class coordtype>
1526 const coordtype *_wrap)
1528 initialize (_source, _dim, _wrap);
1532template <
class coordtype>
1535 initialize (n. source, n. dim, n. wrap);
1539template <
class coordtype>
1544 initialize (n. source, n. dim, n. wrap);
1548template <
class coordtype>
1558template <
class coordtype>
1565template <
class coordtype>
1570 for (
int i = 0; i < dim; ++ i)
1576template <
class coordtype>
1583template <
class coordtype>
1587 if (!dim || !counters || !neighbor || !source)
1593 while ((cur < dim) && (counters [cur] == -1))
1594 counters [cur ++] = 0;
1597 counters [cur] = counters [cur] ?
1598 (
signed char) -1 : (
signed char) 1;
1601 for (
int i = 0; i < dim; ++ i)
1602 neighbor [i] = (coordtype) (source [i] + counters [i]);
1606 wrapcoord (neighbor, neighbor, wrap, dim);
1625template <
class coordtype>
1631 const coordtype *_right = NULL,
int _dim = 0);
1667 const coordtype *_right = NULL,
int _dim = 0);
1676template <
class coordtype>
1678 const coordtype *_right,
int _dim)
1690 point =
new coordtype [dim];
1692 throw "Can't allocate memory for a rectangle.";
1698template <
class coordtype>
1702 initialize (_left, _right, _dim);
1706template <
class coordtype>
1709 initialize (r. left, r. right, r. dim);
1713template <
class coordtype>
1717 initialize (r. left, r. right, r. dim);
1721template <
class coordtype>
1729template <
class coordtype>
1736template <
class coordtype>
1739 for (
int i = 0; i < dim; ++ i)
1740 point [i] = left [i];
1745template <
class coordtype>
1752 for (
int i = 0; i < dim; ++ i)
1753 if (left [i] >= right [i])
1760 while ((cur < dim) && (++ (point [cur]) >= right [cur]))
1762 point [cur] = left [cur];
1784template <
class coordtype>
1786 int which,
int maxcount)
1798 while ((c = neigh. get ()) != NULL)
1811 if (maxcount && (count >= maxcount))
1818template <
class coordtype>
1821 int which,
int maxcount)
1823 if ((q. empty ()) || (p. dimension () != q. dimension ()))
1825 else if (p. empty ())
1830 while ((c = neigh. get ()) != NULL)
1834 if (p. check (c) || q. check (c))
1839 if (!p. check (c) && !q. check (c))
1843 if (maxcount && (count >= maxcount))
1850template <
class coordtype>
1857template <
class coordtype>
1862 if (n >= p. size ())
1866 int_t size = p. size ();
1880 if (n >= p. size ())
1893template <
class coordtype>
1895 int_t n,
int direction)
1899 if (n >= p. size ())
1903 while (n < p. size ())
1916 if (n >= p. size ())
1929template <
class coordtype>
1933 int_t size = p. size ();
1934 for (
int_t i = 0; i < size; ++ i)
1936 coordtype *c = p [i];
1943template <
class coordtype>
1954 boundary -> dimension (p. dimension ());
1955 boundary -> gridsize (p. gridsize ());
1956 boundary -> wrapspace (p. wrapspace ());
1964template <
class coordtype>
1969 while ((c = neigh. get ()) != NULL)
1975template <
class coordtype>
1983template <
class coordtype>
1986 int_t size = p. size ();
1987 for (
int_t i = 0; i < size; ++ i)
1993template <
class coordtype>
2001 switch (f. checkchar ())
2027 c [n ++] = (coordtype) f. readnumber ();
2031 switch (f. checkchar ())
2047 if ((f. checkchar () <
'0') ||
2048 (f. checkchar () >
'9'))
2058template <
class coordtype>
2059int read (std::istream &in, coordtype *c,
int maxdim)
2062 return read (f, c, maxdim);
2072template <
class coordtype>
2085 while ((in. peek () != closing) && (cur < maxdim))
2088 if (in. peek () ==
'+')
2092 if ((in. peek () !=
'-') && !std::isdigit (in. peek ()))
2102 coord [cur] = (coordtype) number;
2103 if (coord [cur] != number)
2108 if (closing ==
'\n')
2110 while ((in. peek () ==
' ') ||
2111 (in. peek () ==
'\t') ||
2112 (in. peek () ==
'\r'))
2119 if (in. peek () ==
',')
2131 if (in. peek () == closing)
2133 else if ((closing ==
'\n') && (in. peek () == EOF))
2141template <
class coordtype>
2147template <
class coordtype>
2148int write (std::ostream &out,
const coordtype *c,
int dim,
char parenthesis,
2152 if (parenthesis != 0)
2156 for (
int i = 0; i < dim; ++ i)
2166 else if (parenthesis)
2170 closing = parenthesis;
2172 closing = (char) ch;
2179template <
class coordtype>
2181 int maxdim,
int *type)
2201 if (((in. peek () !=
'x') && (in. peek () !=
'X')) ||
2205 for (
int i = 0; i < dim; ++ i)
2206 right [i] = (coordtype) (left [i] + 1);
2213 right [0] = (dim < 2) ? left [0] : left [1];
2216 while ((in. peek () ==
'x') || (in. peek () ==
'X'))
2219 throw "Too many intervals in a product.";
2223 if ((d <= 0) || !in)
2224 throw "Can't read a product of intervals.";
2225 left [dim] = temp [0];
2226 right [dim] = (d < 2) ? temp [0] : temp [1];
2239 in. clear (in. rdstate () & ~std::ios::failbit);
2249 if (!leftdim || !rightdim)
2250 throw "Can't read a cell.";
2251 else if (leftdim != rightdim)
2252 throw "Different dim of left & right point.";
2257 if (in. get () != closing)
2258 throw "Can't read the closing bracket of a cell.";
2266template <
class coordtype>
2269 coordtype *wrap,
int maxdim,
int quiet,
2279 coordtype *temp = allocatepoint<coordtype> (maxdim + 1);
2282 int dim = p. empty () ? 0 : p. dimension ();
2284 if (notthese && !notthese -> empty ())
2287 dim = notthese -> dimension ();
2288 else if (dim != notthese -> dimension ())
2291 sout <<
"Error: Dimensions not the same.\n";
2299 if ((howmany >= 0) && (count >= howmany))
2307 while ((f. checkchar () != 40) && (f. checkchar () != 91) &&
2308 (f. checkchar () != 123) && (f. checkchar () != EOF))
2312 if (f. checkchar () == EOF)
2319 int n =
read (f, temp, maxdim + 1);
2323 sout <<
"Line " << f. linenumber () <<
2324 ": The point has too many " <<
2332 if (!first && dim && n && (n != dim))
2335 sout <<
"Line " << f. linenumber () <<
2336 ": Incorrect point dimension.\n";
2345 if (p. dimension () != dim)
2356 p. wrapspace (wrap);
2359 if (!notthese || !notthese -> check (temp))
2366template <
class coordtype>
2368 int_t first,
int_t howmany, coordtype *wrap,
int maxdim,
2372 return read (f, p, first, howmany, wrap, maxdim, quiet, notthese);
2375template <
class coordtype>
2377 coordtype *wrap,
int maxdim,
2380 return read (f, p, 0, -1, wrap, maxdim, quiet, notthese);
2383template <
class coordtype>
2388 return read (f, p, wrap, maxdim, quiet, notthese);
2391template <
class coordtype>
2398template <
class coordtype>
2406template <
class coordtype>
2411 int dim = p. dimension ();
2414 out <<
"; The set contains " << p. size () <<
" points.\n";
2416 out <<
"; Not writing first " << first <<
" points.\n";
2418 out <<
"; Writing at most " << howmany <<
" points.\n";
2421 if (dim && p. gridsize ())
2423 for (
int i = 0; i < dim; ++ i)
2424 out << (i ?
", " :
"; Grid size: ") <<
2430 if (p. gethashsize ())
2431 out <<
"; Hashing table size: " <<
2432 p. gethashsize () <<
" entries.\n";
2434 if (p. stat -> hashhits)
2435 out <<
"; Hashing statistics: " <<
2436 ((p. stat -> hashhits + p. stat -> hashmisses) /
2437 p. stat -> hashhits) <<
'.' <<
2438 ((p. stat -> hashhits + p. stat -> hashmisses) * 10 /
2439 p. stat -> hashhits) % 10 <<
" trials per point, " <<
2440 p. stat -> rehashcount <<
" times rehashed.\n";
2442 if (p. minimal && p. maximal)
2444 out <<
"; The coordinates " <<
2445 (p. wereremoved ?
"varied" :
"vary") <<
" from ";
2446 write (out, p. minimal, dim);
2448 write (out, p. maximal, dim);
2454 out <<
"; Work time: " << (tm - p. stat -> creationtime) <<
2459 out <<
"; Warning: Points were removed, " <<
2460 "so their original order may be distorted.\n";
2464 out <<
"dimension " << p. dimension () <<
'\n';
2467 int_t size = p. size ();
2468 for (
int_t i = first; i < size; ++ i)
2470 if ((howmany >= 0) && (count >= howmany))
2472 write (out, p [i], dim);
2480template <
class coordtype>
This is a small class used only to collect and display statistics on how successful the hashing proce...
std::time_t creationtime
A variable which stores the creation time of each object.
unsigned long hashmisses
The number of unsuccessful attempts to identify an object in a hashing table.
unsigned long hashhits
The number of successful attempts to identify an object in a hashing table.
psethashstat()
The constructor.
unsigned long rehashcount
The number of times the size of the hashing table was changed and all the elements had to be put in t...
This class can be used for iterating point's neighbors.
tNeighbors & operator=(const tNeighbors< coordtype > &r)
The assignment operator.
coordtype * get()
Returns the next neighbor.
const coordtype * source
A pointer to the source point (not allocated!).
void set(coordtype *_source)
Redefines the source (and doesn't change other variables).
const coordtype * wrap
The space wrapping (if needed).
tNeighbors(const coordtype *_source=NULL, int _dim=0, const coordtype *_wrap=NULL)
The only possible constructor for new objects.
~tNeighbors()
The destructor.
signed char * counters
The current counters.
void reset()
Resets the neighbors to the first one.
void initialize(const coordtype *_source=NULL, int _dim=0, const coordtype *_wrap=NULL)
Initializes the internal data of an object of this class.
void deallocate()
Deallocates any memory previously allocated for this object.
int dim
The dimension of the space.
coordtype * neighbor
The coordinates of a created neighbor.
This class represents a set of points in R^n with integer coordinates.
int_t getnumber(const coordtype *c) const
~tPointset()
The destructor.
coordtype * getpointRounded(double *c) const
bool empty() const
Returns true if and only if the set of points is empty.
int quiet
Returns the number of points by simply projecting the set onto an integer number.
double * gridsize(double *g=0)
Gets or sets the size of the grid in R^n.
tPointset(int_t initialsize=0, int bequiet=1)
Default constructor for a set of points with the initial size of the set defined here if an upper bou...
int_t size() const
Returns the number of points in the set.
int_t add(const coordtype *c)
int_t hashfindpoint(const coordtype *c, int_t *addposition=NULL, int wrapped=0) const
const coordtype * wrapspace(const coordtype *w=NULL)
int dimension() const
Returns the dimension of points.
static double * defaultgrid
void rehash(int_t newsize=0)
static int defaultdimension(int d=0)
Sets or gets the default dimension of points.
coordtype * operator[](int_t n) const
coordtype CoordType
The type of coordinates.
int_t gethashsize() const
int_t addRounded(double *c)
void initialize(int_t initialsize, int bequiet)
int removeRounded(const double *c)
int_t getnumberRounded(const double *c) const
coordtype * getpoint(int_t n) const
tPointset & operator=(const tPointset< coordtype > &p)
The assignment operator.
static coordtype * defaultwrap
int checkRounded(const double *c) const
void swap(tPointset< coordtype > &other)
Swaps the data with another object of the same type.
coordtype * getpointMiddle(int_t n, double *c) const
This class can be used for iterating a rectangular set of points, given its left and right bound.
void reset()
Resets the current point to the first one in the range.
int dim
The dimension of the space.
tRectangle(const coordtype *_left=NULL, const coordtype *_right=NULL, int _dim=0)
The only possible constructor for new objects.
int firstpoint
Should the 0 pointer be returned after the last point?
~tRectangle()
The destructor.
const coordtype * left
A pointer to the left point (not allocated!).
void initialize(const coordtype *_left=NULL, const coordtype *_right=NULL, int _dim=0)
Initializes the internal data of an object of this class.
tRectangle(const tRectangle< coordtype > &r)
The copy constructor.
tRectangle & operator=(const tRectangle< coordtype > &r)
The assignment operator.
void deallocate()
Deallocates any memory previously allocated for this object.
const coordtype * get()
Returns the next point in the recatngle.
const coordtype * right
A pointer to the right point (not allocated!).
coordtype * point
The coordinates of a created point.
A class for reading text data from a text file.
This file contains some precompiler definitions which indicate the operating system and/or compiler u...
int int_t
Index type for indexing arrays, counting cubes, etc.
int readcubeorcell(std::istream &in, coordtype *left, coordtype *right, int maxdim, int *type=NULL)
Reads a cube or a cell from a text file.
coordtype rounddown(double x)
Rounds down the given real number to an integral type.
void ignoreline(std::istream &in)
Ignores the input characters until the end of a line, including this end of the line.
void cubemiddle(coordtype *c, double *p, double *grid, int dim)
Computes the middle of a cube with its left lower etc.
outputstream sout
A replacement for standard output stream, with optional logging and other features provided by the cl...
int closingparenthesis(int ch)
Returns the matching closing parenthesis for the given opening one or EOF if none.
void enhancepoint(tPointset< coordtype > &p, coordtype *c)
Enhances the set by adding the neighborhood of the point with given coordinates.
void roundpoint(const double *p, coordtype *c, const double *grid, int dim)
Rounds down the double coordinates of a point to integer ones.
tRectangle< coordinate > rectangle
The rectangle class with the default type of coordinates.
std::ostream & operator<<(std::ostream &out, const bincube< Dim, twoPower > &b)
void wrapcoord(coordtype *destination, const coordtype *source, const coordtype *wrap, int dim)
Wraps coordinates stored in 'c' accordint to the wrap table 'wrap' and store the result in the table ...
int write(std::ostream &out, const coordtype *c, int dim, char parenthesis=40, char closing=0)
bool numberisprime(unsigned n)
Verifies if the given number is a prime number.
tPointset< coordtype > * computeboundary(tPointset< coordtype > &p)
Creates the set of all the boundary points with the 'new' operator.
tPointset< coordinate > pointset
The pointset class with the default type of coordinates.
coordtype * allocatepoint(int dim, char *errormessage=NULL)
Allocate a point with 'new'. In case of failure throw an error message.
int readparenthesis(std::istream &in)
Reads an opening parenthesis from the input file.
tNeighbors< coordinate > neighbors
The neighbors class with the default type of coordinates.
int_t findboundarypoint(tPointset< coordtype > &p, int_t n, int direction=1)
Finds a boundary point starting at the given one.
int thesame(const coordtype *c1, const coordtype *c2, int dim)
Compare two points. Returns true iff they have the same coordinates.
void enhance(tPointset< coordtype > &p)
Enhances the set of points by adding to it all the neighbors of all the points in the set.
short int coordinate
The default type of coordinates.
int readcoordinates(std::istream &in, coordtype *coord, int maxdim, int closing)
Reads the coordinates of a point.
int read(textfile &f, coordtype *c, int maxdim)
Reads a point from a text file and removes a pair of parentheses, braces or brackets if present.
std::istream & operator>>(std::istream &in, bincube< Dim, twoPower > &b)
int attheborder(const tPointset< coordtype > &p, const coordtype *c)
Verifies if the point is at the border of a given set.
int_t pointhashkey(const coordtype *c, int dim, int_t hashsize)
Generates the main hashing key for points.
void ignorecomments(std::istream &in)
Ignores white characters (spaces, tabulators, CRs and LFs), as well as comments from the input text f...
void copycoord(coordtype *destination, const coordtype *source, int dim)
Copies the coordinates of one point to another.
unsigned ceilprimenumber(unsigned n)
Computes the smallest prime number greater than or equal to the given number.
int countneighbors(const tPointset< coordtype > &p, const coordtype *c, int which=1, int maxcount=0)
Counts how many neighbors of the point there are in the set, depending on 'which': 1 = in the set,...
int_t pointhashadd(const coordtype *c, int dim, int_t hashsize)
Generates the second hashing key for points.
void wrapcoord< double >(double *destination, const double *source, const double *wrap, int dim)
Wraps coordinates stored in 'c' accordint to the wrap table 'wrap' and store the result in the table ...
void swap(mwWorkerData &data1, mwWorkerData &data2)
This namespace contains the entire CHomP library interface.
This file contains some useful functions related to the text input/output procedures.