48 ep16Post *ep16Post::readJSON(
const std::string &ifname)
50 std::cout <<
"Reading JSON file" << std::endl;
51 std::ifstream inputStream(ifname);
54 std::cerr <<
"Error opening file " << ifname << std::endl;
59 std::cerr <<
"Input File must be in .json format" << std::endl;
63 jsoncons::json inputjson;
64 inputStream >> inputjson;
67 if (inputjson.is_array())
70 <<
"Warning: Input is an array. Only first element will be processed" 72 inputjson = inputjson[0];
75 ep16Post *ep =
new ep16Post(inputjson);
81 ep16Post *ep16Post::readJSON(
const jsoncons::json &inputjson,
int& ret)
83 ep16Post *ep =
new ep16Post(inputjson);
88 int ep16Post::readJSON()
90 std::cout <<
"Post-porcessing EP16-csc output files." << std::endl;
94 if (!_jstrm.contains(
"Number of Task"))
96 std::cerr <<
"Number of Task field is not defined.\n";
100 if (!_jstrm.contains(
"Task"))
102 std::cerr <<
"Task field is not defined.\n";
107 if (_jstrm[
"Task"].is_array())
111 for (
const auto &jtask : _jstrm[
"Task"].array_range())
113 task = jtask[
"Type"].as<std::string>();
114 if (task !=
"erode triangulation" && task !=
"erode" && task !=
"triangulation")
115 ret = procErode(jtask);
118 std::cerr <<
"Unknown post-process task " << task << std::endl;
124 std::cerr <<
"Problem occured during Task " << task << std::endl;
132 int ep16Post::procErode(
const jsoncons::json &jtsk)
135 int nClst = jtsk[
"Number of Cluster"].as<
int>();
136 std::string ofClStem = jtsk[
"Output Stem"].as<std::string>();
140 if (!jtsk.contains(
"Input File"))
142 std::cerr <<
"An input file should be provided.\n";
145 fname = jtsk[
"Input File"].as<std::string>();
147 io::trim_chars<' ','\t'>,
148 io::no_quote_escape<','>,
149 io::throw_on_overflow,
150 io::single_line_comment<'#'> > csv(fname);
152 csv.read_header(io::ignore_extra_column,
"ELM#",
"MAT",
"X",
"Y",
"Z");
155 std::vector<kmeans::Point> pnts;
156 std::vector<size_t> elmIds, matIds;
158 while(csv.read_row(elm, mat, x, y, z))
162 kmeans::Point p(x,y,z);
164 elmIds.push_back(elm);
165 matIds.push_back(mat);
169 auto kmeans =
new kmeans::KMeans(nClst, _kmeans_max_itr);
172 bool ret = kmeans->run();
175 std::cout <<
"Kmeans analysis failed.\n";
178 kmeans->printMeans();
179 pnts = kmeans->getPoints();
183 for (
int iClst=0; iClst<nClst; iClst++)
185 std::vector<quickhull::Vector3<double> > clPntCrd;
186 for (
auto pit=pnts.begin(); pit!=pnts.end(); pit++)
188 if (pit->cluster_ == iClst)
191 quickhull::Vector3<double>(pit->data_[0], pit->data_[1], pit->data_[2]) );
195 cont->computeConvexHull();
196 std::stringstream ss;
198 std::string clFName = ofClStem + ss.str();
199 cont->toSTL(clFName);
std::string find_ext(const std::string &fname)
An implementation of convex container object for point The class implements methods to generate a con...