GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
GRT::Util Class Reference

Public Types

enum  OperatingSystems { OS_UNKNOWN =0, OS_OSX, OS_LINUX, OS_WINDOWS }
 

Public Member Functions

 Util ()
 
 ~Util ()
 

Static Public Member Functions

static bool sleep (const unsigned int &numMilliseconds)
 
static double scale (const double &x, const double &minSource, const double &maxSource, const double &minTarget, const double &maxTarget, const bool constrain=false)
 
static std::string intToString (const int &i)
 
static std::string intToString (const unsigned int &i)
 
static std::string toString (const int &i)
 
static std::string toString (const unsigned int &i)
 
static std::string toString (const long &i)
 
static std::string toString (const unsigned long &i)
 
static std::string toString (const unsigned long long &i)
 
static std::string toString (const bool &b)
 
static std::string toString (const double &v)
 
static std::string toString (const long double &v)
 
static std::string toString (const float &v)
 
static int stringToInt (const std::string &s)
 
static double stringToDouble (const std::string &s)
 
static bool stringToBool (const std::string &s)
 
static bool stringEndsWith (const std::string &str, const std::string &ending)
 
static double limit (const double value, const double minValue, const double maxValue)
 
static double sum (const std::vector< double > &x)
 
static double dotProduct (const std::vector< double > &a, const std::vector< double > &b)
 
static double euclideanDistance (const std::vector< double > &a, const std::vector< double > &b)
 
static double manhattanDistance (const std::vector< double > &a, const std::vector< double > &b)
 
static double cosineDistance (const std::vector< double > &a, const std::vector< double > &b)
 
static std::vector< double > scale (const std::vector< double > &x, const double minSource, const double maxSource, const double minTarget=0, const double maxTarget=1, const bool constrain=false)
 
static std::vector< double > normalize (const std::vector< double > &x)
 
static std::vector< double > limit (const std::vector< double > &x, const double minValue, const double maxValue)
 
static double getMin (const std::vector< double > &x)
 
static unsigned int getMinIndex (const std::vector< double > &x)
 
static double getMax (const std::vector< double > &x)
 
static unsigned int getMaxIndex (const std::vector< double > &x)
 
static unsigned int getMin (const std::vector< unsigned int > &x)
 
static unsigned int getMax (const std::vector< unsigned int > &x)
 
static unsigned int getOS ()
 
static void cartToPolar (const double x, const double y, double &r, double &theta)
 
static void polarToCart (const double r, const double theta, double &x, double &y)
 

Detailed Description

Definition at line 49 of file Util.h.

Member Enumeration Documentation

A list of operating systems.

Definition at line 375 of file Util.h.

Constructor & Destructor Documentation

GRT::Util::Util ( )
inline

Default constructor.

Definition at line 54 of file Util.h.

GRT::Util::~Util ( )
inline

Default destructor.

Definition at line 59 of file Util.h.

Member Function Documentation

void Util::cartToPolar ( const double  x,
const double  y,
double &  r,
double &  theta 
)
static

Converts the cartesian values {x y} into polar values {r theta}

Parameters
constdouble x: the x cartesian value
constdouble y: the y cartesian value
double&r: the return radius value
double&theta: the return theta value
Returns
void

Definition at line 327 of file Util.cpp.

double Util::cosineDistance ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
static

Computes the cosine distance between the two input vectors. The two input vectors must have the same size. The cosine distance can be used as a similarity measure, the distance ranges from −1 meaning exactly opposite, to 1 meaning exactly the same, with 0 usually indicating independence, and in-between values indicating intermediate similarity or dissimilarity.

Parameters
conststd::vector<double> &a: the first vector for the cosine distance
conststd::vector<double> &a: the second vector for the cosine distance
Returns
double: the cosine distance between the two input vectors, if the two input vectors are not the same size then the dist will be INF

Definition at line 193 of file Util.cpp.

double Util::dotProduct ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
static

Computes the dot product between the two input vectors. The two input vectors must have the same size.

Parameters
conststd::vector<double> &a: the first vector for the dot product
conststd::vector<double> &a: the second vector for the dot product
Returns
double: the dot product between the two input vectors, if the two input vectors are not the same size then the dist will be INF

Definition at line 163 of file Util.cpp.

double Util::euclideanDistance ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
static

Computes the euclidean distance between the two input vectors. The two input vectors must have the same size.

Parameters
conststd::vector<double> &a: the first vector for the euclidean distance
conststd::vector<double> &a: the second vector for the euclidean distance
Returns
double: the euclidean distance between the two input vectors, if the two input vectors are not the same size then the dist will be INF

Definition at line 173 of file Util.cpp.

double Util::getMax ( const std::vector< double > &  x)
static

Gets the maximum value in the input vector.

Parameters
conststd::vector<double> &x: the vector of values you want to find the maximum value for
Returns
double: the maximum value in the input vector, this will be INF if the input vector size is 0

Definition at line 265 of file Util.cpp.

unsigned int Util::getMax ( const std::vector< unsigned int > &  x)
static

Gets the maximum value in the input vector.

Parameters
conststd::vector<unsigned int> &x: the vector of values you want to find the maximum value for
Returns
unsigned int: the maximum value in the input vector, this will be INF if the input vector size is 0

Definition at line 300 of file Util.cpp.

unsigned int Util::getMaxIndex ( const std::vector< double > &  x)
static

Gets the index of the maximum value in the input vector.

Parameters
conststd::vector<double> &x: the vector of values you want to find the maximum index value for
Returns
unsigned int: the index of the maximum value in the vector

Definition at line 276 of file Util.cpp.

double Util::getMin ( const std::vector< double > &  x)
static

Gets the minimum value in the input vector.

Parameters
conststd::vector<double> &x: the vector of values you want to find the minimum value for
Returns
double: the minimum value in the input vector, this will be INF if the input vector size is 0

Definition at line 241 of file Util.cpp.

unsigned int Util::getMin ( const std::vector< unsigned int > &  x)
static

Gets the minimum value in the input vector.

Parameters
conststd::vector<unsigned int> &x: the vector of values you want to find the minimum value for
Returns
unsigned int: the minimum value in the input vector, this will be INF if the input vector size is 0

Definition at line 289 of file Util.cpp.

static unsigned int GRT::Util::getMinIndex ( const std::vector< double > &  x)
static

Gets the index of the minimum value in the input vector.

Parameters
conststd::vector<double> &x: the vector of values you want to find the minimum index value for
Returns
unsigned int: the index of the minimum value in the vector
unsigned int Util::getOS ( )
static

Gets the current operating system as a Util::OperatingSystems enum.

Returns
unsigned int: the current operating system (which will be one of the Util::OperatingSystems enums)

Definition at line 311 of file Util.cpp.

std::string Util::intToString ( const int &  i)
static

Converts an int to a string.

Parameters
constint i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 53 of file Util.cpp.

std::string Util::intToString ( const unsigned int &  i)
static

Converts an unsigned int to a string.

Parameters
constunsigned int i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 59 of file Util.cpp.

double Util::limit ( const double  value,
const double  minValue,
const double  maxValue 
)
static

Limits the input value so it is between the range of minValue and maxValue. If the input value is below the minValue then the output of the function will be the minValue. If the input value is above the maxValue then the output of the function will be the maxValue. Otherwise, the out of the function will be the input.

Parameters
constdouble value: the input value that should be limited
constdouble minValue: the minimum value that should be limited
constdouble maxValue: the maximum value that should be limited
Returns
the limited double input value

Definition at line 149 of file Util.cpp.

std::vector< double > Util::limit ( const std::vector< double > &  x,
const double  minValue,
const double  maxValue 
)
static

Limits the input data x so each element is within the range [minValue maxValue]. Returns a new vector with the limited data.

Parameters
conststd::vector<double> &x: the vector of values you want to limit
constminValue: the minimum value
constmaxValue: the maximum value
Returns
std::vector<double>: the limited input vector

Definition at line 233 of file Util.cpp.

double Util::manhattanDistance ( const std::vector< double > &  a,
const std::vector< double > &  b 
)
static

Computes the manhattan distance between the two input vectors. The two input vectors must have the same size. The manhattan distance is also known as the L1 norm, taxicab distance, city block distance, or rectilinear distance.

Parameters
conststd::vector<double> &a: the first vector for the manhattan distance
conststd::vector<double> &a: the second vector for the manhattan distance
Returns
double: the manhattan distance between the two input vectors, if the two input vectors are not the same size then the dist will be INF

Definition at line 183 of file Util.cpp.

std::vector< double > Util::normalize ( const std::vector< double > &  x)
static

Normalizes the input vector x so the sum is 1.

Parameters
conststd::vector<double> &x: the vector of values you want to normalize
Returns
std::vector<double>: the normalized input vector (the sum of which will be 1)

Definition at line 216 of file Util.cpp.

void Util::polarToCart ( const double  r,
const double  theta,
double &  x,
double &  y 
)
static

Converts the polar values {r theta} into the cartesian values {x y}.

Parameters
constdouble r: the radius polar value
constdouble theta: the theta polar value
double&x: the return x value
double&y: the return y value
Returns
void

Definition at line 377 of file Util.cpp.

double Util::scale ( const double &  x,
const double &  minSource,
const double &  maxSource,
const double &  minTarget,
const double &  maxTarget,
const bool  constrain = false 
)
static

Performs minmax scaling. The input value (x) will be scaled from the source range to the target range.

Parameters
doublex: the input value to be scaled
constdouble minSource: the minimum source value (that x originates from)
constdouble maxSource: the maximum source value (that x originates from)
constdouble minTarget: the minimum target value (that x will be scaled to)
constdouble maxTarget: the maximum target value (that x will be scaled to)
constbool constrain: if true, then the value will be constrained to the minSource and maxSource
Returns
the scaled value

Definition at line 44 of file Util.cpp.

std::vector< double > Util::scale ( const std::vector< double > &  x,
const double  minSource,
const double  maxSource,
const double  minTarget = 0,
const double  maxTarget = 1,
const bool  constrain = false 
)
static

Scales the vector from a source range to the new target range

Parameters
doublex: the input value to be scaled
constdouble minSource: the minimum source value (that x originates from)
constdouble maxSource: the maximum source value (that x originates from)
constdouble minTarget: the minimum target value (that x will be scaled to)
constdouble maxTarget: the maximum target value (that x will be scaled to)
constbool constrain: if true, then the value will be constrained to the minSource and maxSource
Returns
std::vector<double>: the scaled input vector

Definition at line 207 of file Util.cpp.

bool Util::sleep ( const unsigned int &  numMilliseconds)
static

A cross platform function to cause a function to sleep for a set number of milliseconds.

Parameters
constunsigned int numMilliseconds: the number of milliseconds to sleep for, 1000 milliseconds = 1 second.
Returns
returns true if the sleep function was called successfully, false otherwise

Definition at line 25 of file Util.cpp.

bool Util::stringEndsWith ( const std::string &  str,
const std::string &  ending 
)
static

Checks if the string (str) ends with a specific ending (such as .csv).

Parameters
conststd::string &str: the string you want to query
conststd::string &ending: the ending you want to search for
Returns
bool: returns true if the input string ends with the ending, false otherwise

Definition at line 141 of file Util.cpp.

bool Util::stringToBool ( const std::string &  s)
static

Converts a string to a boolean. Any string that matches true, True, TRUE, t, T, or 1 will return true, anything else will return false.

Parameters
conststd::string &s: the value you want to convert to a bool
Returns
bool: the value as a bool

Definition at line 131 of file Util.cpp.

double Util::stringToDouble ( const std::string &  s)
static

Converts a string to a double.

Parameters
conststd::string &s: the value you want to convert to a double
Returns
double: the value as a double

Definition at line 124 of file Util.cpp.

int Util::stringToInt ( const std::string &  s)
static

Converts a string to an int.

Parameters
conststd::string &s: the value you want to convert to an int
Returns
int: the value as an int

Definition at line 117 of file Util.cpp.

double Util::sum ( const std::vector< double > &  x)
static

Computes the sum of the vector x.

Parameters
conststd::vector<double> &x: the vector of values you want to sum
Returns
double: the sum of the input vector x

Definition at line 155 of file Util.cpp.

std::string Util::toString ( const int &  i)
static

Converts an unsigned int to a string.

Parameters
constunsigned int i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 65 of file Util.cpp.

std::string Util::toString ( const unsigned int &  i)
static

Converts an unsigned int to a string.

Parameters
constunsigned int i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 71 of file Util.cpp.

std::string Util::toString ( const long &  i)
static

Converts a long to a string.

Parameters
constlong i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 77 of file Util.cpp.

std::string Util::toString ( const unsigned long &  i)
static

Converts an unsigned long to a string.

Parameters
constunsigned long i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 83 of file Util.cpp.

std::string Util::toString ( const unsigned long long &  i)
static

Converts an unsigned long long to a string.

Parameters
constunsigned long long i: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 89 of file Util.cpp.

std::string Util::toString ( const bool &  b)
static

Converts a boolean to a string.

Parameters
constbool b: the value you want to convert to a string
Returns
std::string: the boolan as a string

Definition at line 95 of file Util.cpp.

std::string Util::toString ( const double &  v)
static

Converts a double to a string.

Parameters
constdouble v: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 99 of file Util.cpp.

std::string Util::toString ( const long double &  v)
static

Converts a long double to a string.

Parameters
constlong double v: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 105 of file Util.cpp.

std::string Util::toString ( const float &  v)
static

Converts a float to a string.

Parameters
constfloat v: the value you want to convert to a string
Returns
std::string: the value as a string

Definition at line 111 of file Util.cpp.


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