-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcurveReader.cc
More file actions
70 lines (60 loc) · 1.98 KB
/
curveReader.cc
File metadata and controls
70 lines (60 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm> // For std::find_if, std::erase
#include <cctype> // For std::isspace
#include "curveReader.h"
// Function to trim leading and trailing whitespace
std::string trim(std::string s) {
// Trim leading whitespace
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
return !std::isspace(ch);
}));
// Trim trailing whitespace
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
return !std::isspace(ch);
}).base(), s.end());
return s;
}
bool parseBool(const std::string& str) {
return (str == "1" || str == "true" || str == "True" || str == "TRUE");
}
template <typename T>
void printVec(std::string name, std::vector<T>& vec) {
std::cerr << name << " ";
for( auto v : vec ) std::cerr << v << " ";
std::cerr << "\n";
}
void CurveReader::printCurveInfo(CurveInfo& c) {
printVec("x", c.x);
printVec("y", c.y);
printVec("isOnCurve", c.isOnCurve);
printVec("isMdlVtx", c.isMdlVtx);
printVec("tcAngle", c.tcAngle);
}
CurveReader::CurveInfo CurveReader::readCurveInfo(const std::string& filename) {
CurveReader::CurveInfo c;
std::ifstream file(filename);
std::string line;
if (!file.is_open()) {
std::cerr << "Failed to open file: " << filename << std::endl;
return c;
}
// Read header
std::getline(file, line);
while (std::getline(file, line)) {
std::istringstream ss(line);
std::string token;
double ignored;
std::getline(ss, token, ','); c.x.push_back(std::stod(token));
std::getline(ss, token, ','); c.y.push_back(std::stod(token));
std::getline(ss, token, ','); ignored = std::stod(token); //z
std::getline(ss, token, ','); c.isOnCurve.push_back(parseBool(trim(token)));
std::getline(ss, token, ','); c.tcAngle.push_back(std::stod(token));
std::getline(ss, token, ','); c.isMdlVtx.push_back(parseBool(trim(token)));
}
file.close();
return c;
}