-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGpuDemoUtils.hpp
43 lines (35 loc) · 1.23 KB
/
GpuDemoUtils.hpp
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
#pragma once
#include <string>
#include <iostream>
#include <fstream>
#include "chrono/core/ChVector.h"
void tokenizeCSVLine(std::ifstream& istream, std::vector<float>& data) {
std::string line;
std::getline(istream, line); // load in current line
std::stringstream lineStream(line);
std::string cell;
// iterate over cells
while (std::getline(lineStream, cell, ',')) {
data.push_back(std::stof(cell));
}
}
// load sphere positions from a checkpoint file
template <typename T>
std::vector<chrono::ChVector<T>> loadPositionCheckpoint(std::string infile) {
// file stream to load in
std::ifstream ptFile(infile);
std::vector<chrono::ChVector<T>> sphere_positions;
std::string tmp_line;
std::getline(ptFile, tmp_line); // skip first header line
// TODO look ahead and reserve space to avoid push_backs
while (ptFile.good()) {
std::vector<float> line_data;
tokenizeCSVLine(ptFile, line_data);
if (line_data.size() != 0){
chrono::ChVector<> curr_pos(line_data.at(0), line_data.at(1),line_data.at(2));
sphere_positions.push_back(curr_pos);
}
}
return sphere_positions;
}
// load sphere positions from a checkpoint file