Skeletal Animation Multithread Face
utils.cpp
Go to the documentation of this file.
1#include "../include/utils.h"
2
9std::vector<int> Utils::analog_str_buf_to_int_vec(const std::string& str)
10{
11 // Initialize data vector
12 std::vector<int> data_vec;
13
14 // Initialize string stream
15 std::stringstream ss(str);
16
17 // Get data and convert to analog
18 while (ss.good())
19 {
20 std::string substr;
21 std::getline(ss, substr, ',');
22 data_vec.push_back(std::stoi(substr));
23 }
24
25 return data_vec;
26}
27
34std::vector<double> Utils::analog_str_buf_to_double_vec(const std::string& str)
35{
36 // Initialize data vector
37 std::vector<double> data_vec;
38
39 // Initialize string stream
40 std::stringstream ss(str);
41
42 // Get data and convert to analog
43 while (ss.good())
44 {
45 std::string substr;
46 std::getline(ss, substr, ',');
47 data_vec.push_back(std::stod(substr));
48 }
49
50 return data_vec;
51}
52
59Eigen::MatrixXd Utils::load_matrix_data(std::string filename)
60{
61 // Matrix entries
62 std::vector<double> matrix_entries;
63
64 // In this object we store the data from the matrix
65 std::ifstream matrix_data_file(filename);
66
67 // This variable is used to store the row of the matrix that contains commas
68 std::string matrix_row_string;
69
70 // This variable is used to store the matrix entry;
71 std::string matrix_entry;
72
73 // This variable is used to track the number of rows
74 int matrix_row_number = 0;
75
76 /* We read a row by row of matrix_data_file and store every line into the
77 lstring variable matrix_row_string */
78 while (std::getline(matrix_data_file, matrix_row_string))
79 {
80 // Convert matrixRowString that is a string to a stream variable.
81 std::stringstream matrix_row_string_stream(matrix_row_string);
82
83 /* here we read pieces of the stream matrix_row_string_stream until every
84 comma, and store the resulting character into the matrix_entry */
85
86 while (std::getline(matrix_row_string_stream, matrix_entry, ','))
87 {
88 /* Here we convert the string to double and fill in the row vector
89 storing all the matrix entries */
90 matrix_entries.push_back(stod(matrix_entry));
91 }
92
93 // Update the column numbers
94 matrix_row_number++;
95 }
96
97 /* Here we convet the vector variable into the matrix and return the
98 resulting object, note that matrix_entris.data() is the pointer to the
99 first memory location at which the entries of the vector matrixEntries are
100 stored */
101
102 return Eigen::Map< Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic,
103 Eigen::RowMajor>>(matrix_entries.data(), matrix_row_number,
104 matrix_entries.size() / matrix_row_number);
105}
static Eigen::MatrixXd load_matrix_data(std::string filename)
Load Eigen double matrix from csv file.
Definition: utils.cpp:59
static std::vector< double > analog_str_buf_to_double_vec(const std::string &str)
Convert comma-delimited string to double vector of analog values.
Definition: utils.cpp:34
static std::vector< int > analog_str_buf_to_int_vec(const std::string &str)
Convert comma-delimited string to int vector of analog values.
Definition: utils.cpp:9