33#include "chomp/system/config.h"
34#include "chomp/system/textfile.h"
35#include "chomp/cubes/pointset.h"
36#include "chomp/struct/hashsets.h"
37#include "chomp/system/timeused.h"
38#include "chomp/system/arg.h"
51using namespace chomp::homology;
59Join PointSets, ver. 0.02. Copyright (C) 1997-2020 by Pawel Pilarczyk.\n\
60This is free software. No warranty. Consult 'license.txt' for details.";
63Call with: infile1.cub ... infileN.cub prefix.\n\
64The program reads the sets of points in the given files,\n\
65and joins these sets which are topologically disjoint, that is,\n\
66can be separted back by taking their connected components.\n\
67The resulting sets are written to prefix001.cub, prefix002.cub, etc.\n\
68Switches and additional arguments:\n\
69-d N - the minimal distance between the sets (default: 1),\n\
70-s N - don't join the largest N input sets,\n\
71-h - display this brief help information only and exit.\n\
72For more information ask the author at http://www.PawelPilarczyk.com/.";
88 return (x. p -> size () > y. p -> size ());
96int psetbold (pointset &p,
int howmany,
bool debug =
false)
101 int_t maxpoint = p. size ();
103 sout <<
"\n" << howmany <<
" - " << maxpoint;
105 std::cout <<
"\n==========\n" << p <<
"\n==========\n";
106 while (cur < maxpoint)
109 neighbors n (p [cur ++], p. dimension ());
111 while ((c = n. get ()) != 0)
117 for (
int i = 0; i < p. dimension (); ++ i)
118 sout << (i ?
" " :
"(") << c [i];
129 if (countneighbors (p, c, INSIDE, 1))
139bool disjoint (
const pointset &p,
const pointset &q)
141 if (p. size () > q. size ())
143 for (int_t i = 0; i < p. size (); ++ i)
145 if (q. check (p [i]))
153int joinsets (
char *innames [],
int nnames,
char *prefix,
int distance,
159 if (firstset >= nnames)
160 firstset = nnames - 1;
163 sout <<
"Reading " << nnames <<
" input files... ";
164 std::vector <pointsetptr> p (nnames);
166 for (
int i = 0; i < nnames; ++ i)
168 std::ifstream in (innames [i]);
170 fileerror (innames [i]);
171 p [i]. p =
new pointset;
173 count += p [i]. p -> size ();
175 sout << count <<
" points total read.\n";
178 std::sort (p. begin (), p. end ());
181 sout <<
"Enhancing the sets... ";
182 pointset **bold =
new pointset * [nnames];
183 for (
int i = firstset; i < nnames; ++ i)
185 bold [i] =
new pointset;
186 bold [i] -> add (*(p [i]. p));
192 sout <<
"Joining the sets... ";
194 for (
int i = firstset; i < nsets; ++ i)
196 for (
int j = firstset; j < nsets; ++ j)
198 if ((i == j) || !
disjoint (*(bold [i]), *(p [j]. p)))
200 bold [i] -> add (*(bold [j]));
202 p [i]. p -> add (*(p [j]. p));
205 for (
int k = j; k < nsets; ++ k)
207 bold [k] = bold [k + 1];
208 p [k]. p = p [k + 1]. p;
215 sout <<
"Writing " << nsets <<
" files... ";
216 for (
int n = 0; n < nsets; ++ n)
219 std::ostringstream s;
221 for (
int digit = 10000; digit > 1; digit /= 10)
222 if (((n + 1) < digit) && (nsets >= digit))
224 s << (n + 1) <<
".cub";
227 std::ofstream out (s. str (). c_str ());
229 fileerror (s. str (). c_str (),
"create");
247int main (
int argc,
char *argv [])
255 arg (a,
"d", distance);
256 arg (a,
"s", firstset);
257 arg (a, NULL, filenames, nnames,
maxnames);
260 argstreamprepare (a);
261 int argresult = a. analyze (argc, argv);
266 sout <<
title <<
'\n';
275 sout <<
"Call with '--help' for help.\n";
289 joinsets (filenames, nnames - 1, filenames [nnames - 1],
294 catch (
const char *msg)
296 sout <<
"ERROR: " << msg <<
'\n';
299 catch (
const std::exception &e)
301 sout <<
"ERROR: " << e. what () <<
'\n';
306 sout <<
"ABORT: An unknown error occurred.\n";
const coordinate * operator[](int i)
int psetbold(pointset &p, int howmany, bool debug=false)
int main(int argc, char *argv[])
The main function of the program.
int joinsets(char *innames[], int nnames, char *prefix, int distance, int firstset)
Joins the sets of cubes.
bool operator<(const pointsetptr &x, const pointsetptr &y)
bool disjoint(const pointset &p, const pointset &q)