GestureRecognitionToolkit  Version: 0.1.0
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
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 getCxx11Enabled ()
 
static bool sleep (const unsigned int &numMilliseconds)
 
static Float scale (const Float &x, const Float &minSource, const Float &maxSource, const Float &minTarget, const Float &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 float &v)
 
static std::string toString (const double &v)
 
static std::string toString (const long double &v)
 
static int stringToInt (const std::string &s)
 
static double stringToDouble (const std::string &s)
 
static Float stringToFloat (const std::string &s)
 
static bool stringToBool (const std::string &s)
 
static bool stringEndsWith (const std::string &str, const std::string &ending)
 
static Float limit (const Float value, const Float minValue, const Float maxValue)
 
static Float sum (const VectorFloat &x)
 
static Float dotProduct (const VectorFloat &a, const VectorFloat &b)
 
static Float euclideanDistance (const VectorFloat &a, const VectorFloat &b)
 
static Float manhattanDistance (const VectorFloat &a, const VectorFloat &b)
 
static Float cosineDistance (const VectorFloat &a, const VectorFloat &b)
 
static VectorFloat scale (const VectorFloat &x, const Float minSource, const Float maxSource, const Float minTarget=0, const Float maxTarget=1, const bool constrain=false)
 
static VectorFloat normalize (const VectorFloat &x)
 
static VectorFloat limit (const VectorFloat &x, const Float minValue, const Float maxValue)
 
static Float getMin (const VectorFloat &x)
 
static unsigned int getMinIndex (const VectorFloat &x)
 
static Float getMax (const VectorFloat &x)
 
static unsigned int getMaxIndex (const VectorFloat &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 Float x, const Float y, Float &r, Float &theta)
 
static void polarToCart (const Float r, const Float theta, Float &x, Float &y)
 
static bool parseDirectory (const std::string directoryPath, const std::string type, std::vector< std::string > &filenames)
 Parses a directory and returns a list of filenames in that directory that match the file type. A wildcard (.*) can be used to indicate any file in the directory. Multiple filetypes can be searched for by seperating the file type via |. For example: *.csv|*.grt will return any CSV or GRT files in the directory. More...
 

Detailed Description

Definition at line 45 of file Util.h.

Member Enumeration Documentation

A list of operating systems.

Definition at line 398 of file Util.h.

Constructor & Destructor Documentation

Util::Util ( )
inline

Default constructor.

Definition at line 50 of file Util.h.

Util::~Util ( )
inline

Default destructor.

Definition at line 55 of file Util.h.

Member Function Documentation

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

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

Parameters
xthe x cartesian value
ythe y cartesian value
rthe return radius value
thetathe return theta value
Returns
void

Definition at line 342 of file Util.cpp.

Float Util::cosineDistance ( const VectorFloat a,
const VectorFloat 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
athe first vector for the cosine distance
athe second vector for the cosine distance
Returns
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 208 of file Util.cpp.

Float Util::dotProduct ( const VectorFloat a,
const VectorFloat b 
)
static

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

Parameters
athe first vector for the dot product
athe 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 178 of file Util.cpp.

Float Util::euclideanDistance ( const VectorFloat a,
const VectorFloat b 
)
static

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

Parameters
athe first vector for the euclidean distance
athe second vector for the euclidean distance
Returns
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 188 of file Util.cpp.

bool Util::getCxx11Enabled ( )
static
Returns
returns true if the GRT has been compiled with C++ 11 support, false otherwise

Definition at line 25 of file Util.cpp.

Float Util::getMax ( const VectorFloat x)
static

Gets the maximum value in the input vector.

Parameters
xthe vector of values you want to find the maximum value for
Returns
the maximum value in the input vector, this will be INF if the input vector size is 0

Definition at line 280 of file Util.cpp.

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

Gets the maximum value in the input vector.

Parameters
xthe vector of values you want to find the maximum value for
Returns
the maximum value in the input vector, this will be INF if the input vector size is 0

Definition at line 315 of file Util.cpp.

unsigned int Util::getMaxIndex ( const VectorFloat x)
static

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

Parameters
xthe vector of values you want to find the maximum index value for
Returns
the index of the maximum value in the vector

Definition at line 291 of file Util.cpp.

Float Util::getMin ( const VectorFloat x)
static

Gets the minimum value in the input vector.

Parameters
xthe vector of values you want to find the minimum value for
Returns
the minimum value in the input vector, this will be INF if the input vector size is 0

Definition at line 256 of file Util.cpp.

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

Gets the minimum value in the input vector.

Parameters
xthe vector of values you want to find the minimum value for
Returns
the minimum value in the input vector, this will be INF if the input vector size is 0

Definition at line 304 of file Util.cpp.

static unsigned int Util::getMinIndex ( const VectorFloat x)
static

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

Parameters
xthe vector of values you want to find the minimum index value for
Returns
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 326 of file Util.cpp.

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

Converts an int to a string.

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

Definition at line 61 of file Util.cpp.

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

Converts an unsigned int to a string.

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

Definition at line 67 of file Util.cpp.

Float Util::limit ( const Float  value,
const Float  minValue,
const Float  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
valuethe input value that should be limited
minValuethe minimum value that should be limited
maxValuethe maximum value that should be limited
Returns
the limited double input value

Definition at line 164 of file Util.cpp.

VectorFloat Util::limit ( const VectorFloat x,
const Float  minValue,
const Float  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
xthe vector of values you want to limit
minValuethe minimum value
maxValuethe maximum value
Returns
the limited input vector

Definition at line 248 of file Util.cpp.

Float Util::manhattanDistance ( const VectorFloat a,
const VectorFloat 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
athe first vector for the manhattan distance
athe second vector for the manhattan distance
Returns
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 198 of file Util.cpp.

VectorFloat Util::normalize ( const VectorFloat x)
static

Normalizes the input vector x so the sum is 1.

Parameters
xthe vector of values you want to normalize
Returns
the normalized input vector (the sum of which should be 1)

Definition at line 231 of file Util.cpp.

bool Util::parseDirectory ( const std::string  directoryPath,
const std::string  type,
std::vector< std::string > &  filenames 
)
static

Parses a directory and returns a list of filenames in that directory that match the file type. A wildcard (.*) can be used to indicate any file in the directory. Multiple filetypes can be searched for by seperating the file type via |. For example: *.csv|*.grt will return any CSV or GRT files in the directory.

Note
only supported on OSX or Linux systems at this time.
Parameters
directoryPaththe path of the directory you want to search (can be relative or absolute)
typesets the file type that should be searched for (e.g. .csv)
filenameswill return a list of filenames found in the directory
Returns
returns true if the directory was parsed, false otherwise

Definition at line 397 of file Util.cpp.

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

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

Parameters
rthe radius polar value
thetathe theta polar value
xthe return x value
ythe return y value
Returns
void

Definition at line 392 of file Util.cpp.

Float Util::scale ( const Float &  x,
const Float &  minSource,
const Float &  maxSource,
const Float &  minTarget,
const Float &  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
xthe input value to be scaled
minSourcethe minimum source value (that x originates from)
maxSourcethe maximum source value (that x originates from)
minTargetthe minimum target value (that x will be scaled to)
maxTargetthe maximum target value (that x will be scaled to)
constrainif true, then the value will be constrained to the minSource and maxSource
Returns
the scaled value

Definition at line 52 of file Util.cpp.

VectorFloat Util::scale ( const VectorFloat x,
const Float  minSource,
const Float  maxSource,
const Float  minTarget = 0,
const Float  maxTarget = 1,
const bool  constrain = false 
)
static

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

Parameters
xthe input value to be scaled
minSourcethe minimum source value (that x originates from)
maxSourcethe maximum source value (that x originates from)
minTargetthe minimum target value (that x will be scaled to)
maxTargetthe maximum target value (that x will be scaled to)
constrainif true, then the value will be constrained to the minSource and maxSource
Returns
the scaled input vector

Definition at line 222 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 33 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
strthe string you want to query
endingthe ending you want to search for
Returns
bool: returns true if the input string ends with the ending, false otherwise

Definition at line 156 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
sthe value you want to convert to a bool
Returns
bool: the value as a bool

Definition at line 146 of file Util.cpp.

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

Converts a string to a double.

Parameters
sthe value you want to convert to a double
Returns
the value as a double

Definition at line 139 of file Util.cpp.

Float Util::stringToFloat ( const std::string &  s)
static

Converts a string to a float.

Parameters
sthe value you want to convert to a float
Returns
the value as a float

Definition at line 132 of file Util.cpp.

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

Converts a string to an int.

Parameters
sthe value you want to convert to an int
Returns
int: the value as an int

Definition at line 125 of file Util.cpp.

Float Util::sum ( const VectorFloat x)
static

Computes the sum of the vector x.

Parameters
xthe vector of values you want to sum
Returns
double: the sum of the input vector x

Definition at line 170 of file Util.cpp.

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

Converts an unsigned int to a string.

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

Definition at line 73 of file Util.cpp.

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

Converts an unsigned int to a string.

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

Definition at line 79 of file Util.cpp.

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

Converts a long to a string.

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

Definition at line 85 of file Util.cpp.

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

Converts an unsigned long to a string.

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

Definition at line 91 of file Util.cpp.

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

Converts an unsigned long long to a string.

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

Definition at line 97 of file Util.cpp.

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

Converts a boolean to a string.

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

Definition at line 103 of file Util.cpp.

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

Converts a float to a string.

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

Definition at line 119 of file Util.cpp.

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

Converts a double to a string.

Parameters
vthe value you want to convert to a string
Returns
std::string: the value as a string
std::string Util::toString ( const long double &  v)
static

Converts a long double to a string.

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

Definition at line 113 of file Util.cpp.


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