1 #pragma once // Ensure that file is included only once in a single compilation.
20 template <
unsigned int dim,
21 template <
typename...>
typename vectorT = std::vector,
23 typename index_t = decltype(std::declval<vectorT>().size())>
26 using float_t =
typename pointT::value_type;
28 hy_assert(filename.substr(filename.size() - 4, filename.size()) ==
".pts",
29 "The given file needs to be a .pts file for this function to be applicable!");
33 const index_t left, right;
34 Pair(
const index_t left_,
const index_t right_) : left(left_), right(right_) {}
37 std::ifstream infile(filename);
38 std::istringstream linestream;
39 std::string line, keyword, equal_sign;
41 unsigned int space_dim;
45 vectorT<pointT> points;
46 vectorT<Pair> connections;
47 std::deque<index_t> search;
50 while (keyword !=
"Space_Dim" && std::getline(infile, line))
52 linestream = std::istringstream(line);
53 linestream >> keyword;
55 linestream >> equal_sign >> space_dim;
58 "The keyword Space_Dim has not been found in the file " << filename <<
"!");
59 hy_assert(equal_sign ==
"=",
"The keyword " << keyword <<
" has not been followd by = symbol!");
61 "Space_Dim in " << filename <<
" is " << space_dim <<
", but should be " << dim <<
"!");
63 while (keyword !=
"Epsilon" && std::getline(infile, line))
65 linestream = std::istringstream(line);
66 linestream >> keyword;
68 linestream >> equal_sign >> epsilon;
71 "The keyword Space_Dim has not been found in the file " << filename <<
"!");
72 hy_assert(equal_sign ==
"=",
"The keyword " << keyword <<
" has not been followd by = symbol!");
73 hy_assert(epsilon > 0,
"Epsilon needs to be larger than zeros, but is " << epsilon <<
"!");
75 while (keyword !=
"POINTS:" && std::getline(infile, line))
77 linestream = std::istringstream(line);
78 linestream >> keyword;
82 "The keyword 'POINTS:' has not been found in the file " << filename <<
"!");
84 while (std::getline(infile, line))
86 linestream = std::istringstream(line);
87 for (
unsigned int dimension = 0; dimension < dim; ++dimension)
88 linestream >> pt[dimension];
92 std::sort(points.begin(), points.end());
93 hy_assert(std::adjacent_find(points.begin(), points.end()) == points.end(),
94 "Points must be unique in given file!");
96 vectorT<bool> bool_vec(points.size(),
false);
100 while (!search.empty())
102 index = search.front();
104 for (index_t ind =
index;
105 ind >= 0 && ind < points.size() && std::abs(points[
index][0] - points[ind][0]) < epsilon;
108 (!bool_vec[ind] || std::find(search.begin(), search.end(), ind) != search.end()))
111 search.push_back(ind);
112 bool_vec[ind] =
true;
113 connections.push_back(Pair(
index, ind));
115 for (index_t ind =
index;
116 ind >= 0 && ind < points.size() && std::abs(points[
index][0] - points[ind][0]) < epsilon;
119 (!bool_vec[ind] || std::find(search.begin(), search.end(), ind) != search.end()))
122 search.push_back(ind);
123 bool_vec[ind] =
true;
124 connections.push_back(Pair(
index, ind));
129 filename = filename +
".geo";
130 std::ofstream outfile(filename);
132 outfile <<
"Space_Dim = " << dim <<
";" << std::endl;
133 outfile <<
"HyperEdge_Dim = 1;" << std::endl << std::endl;
134 outfile <<
"N_Points = " << points.size() <<
";" << std::endl;
135 outfile <<
"N_HyperNodes = " << points.size() <<
";" << std::endl;
136 outfile <<
"N_HyperEdges = " << connections.size() <<
";" << std::endl << std::endl;
137 outfile <<
"POINTS:" << std::endl;
138 for (
unsigned int i = 0; i < points.size(); ++i)
139 outfile << points[i];
140 outfile << std::endl <<
"HYPERNODES_OF_HYPEREDGES:" << std::endl;
141 for (
unsigned int i = 0; i < connections.size(); ++i)
142 outfile << connections[i].left <<
" " << connections[i].right << std::endl;
143 outfile << std::endl <<
"TYPES_OF_HYPERFACES:" << std::endl;
144 for (
unsigned int i = 0; i < connections.size(); ++i)
145 outfile << connections[i].left <<
" " << connections[i].right << std::endl;
146 outfile << std::endl <<
"POINTS_OF_HYPEREDGES:" << std::endl;
147 for (
unsigned int i = 0; i < connections.size(); ++i)
148 outfile << connections[i].left <<
" " << connections[i].right << std::endl;
152 for (
unsigned int i = 0; i < bool_vec.size(); ++i)
153 hy_assert(bool_vec[i],
"All points need to belong to one graph, but " << i <<
" does not!");