Skeletal Animation Multithread Face
Classes | Public Member Functions | Static Public Member Functions | List of all members
Utils Class Reference

Class Utils. More...

#include <utils.h>

Classes

struct  Range
 Range stucture. More...
 

Public Member Functions

 Utils ()
 Constructor. More...
 

Static Public Member Functions

static double deg2rad (double deg)
 Convert degrees to rad. More...
 
static std::vector< int > analog_str_buf_to_int_vec (const std::string &str)
 Convert comma-delimited string to int vector of analog values. More...
 
static std::vector< double > analog_str_buf_to_double_vec (const std::string &str)
 Convert comma-delimited string to double vector of analog values. More...
 
static Eigen::MatrixXd load_matrix_data (std::string filename)
 Load Eigen double matrix from csv file. More...
 

Detailed Description

Class Utils.

This class includes some generic function that are used in various places inside the project.

Definition at line 16 of file utils.h.

Constructor & Destructor Documentation

◆ Utils()

Utils::Utils ( )

Constructor.

Member Function Documentation

◆ analog_str_buf_to_double_vec()

std::vector< double > Utils::analog_str_buf_to_double_vec ( const std::string &  str)
static

Convert comma-delimited string to double vector of analog values.

Return a vector of doubles from a comma-delimited string.

Parameters
strThe comma-delimited string.
Returns
std::vector<int> The output vector of doubles.

Definition at line 34 of file utils.cpp.

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}
Here is the caller graph for this function:

◆ analog_str_buf_to_int_vec()

std::vector< int > Utils::analog_str_buf_to_int_vec ( const std::string &  str)
static

Convert comma-delimited string to int vector of analog values.

Return a vector of integers from a comma-delimited string. (could have been templated if you can template stoi and stod).

Parameters
strThe comma-delimited string.
Returns
std::vector<int> The output vector of integers.

Definition at line 9 of file utils.cpp.

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}

◆ deg2rad()

static double Utils::deg2rad ( double  deg)
inlinestatic

Convert degrees to rad.

Definition at line 30 of file utils.h.

30{ return (deg * (M_PI / 180.0)); }
Here is the caller graph for this function:

◆ load_matrix_data()

Eigen::MatrixXd Utils::load_matrix_data ( std::string  filename)
static

Load Eigen double matrix from csv file.

Load Eigen Matrix from csv file.

Parameters
filename
Returns
Eigen::MatrixXd The matrix to be read.

Definition at line 59 of file utils.cpp.

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}
Here is the caller graph for this function:

The documentation for this class was generated from the following files: