Privacy
An open-source, flexible 3D physical simulation framework
mars::utils Namespace Reference

Classes

class  Color
 
class  Mutex
 
class  MutexLocker
 
struct  PthreadConditionWrapper
 
struct  PthreadMutexWrapper
 
struct  PthreadReadWriteLockWrapper
 
struct  PthreadThreadWrapper
 
class  ReadWriteLock
 
class  ReadWriteLocker
 
struct  sRotation
 
class  TCPBaseSocket
 
class  TCPConnection
 
class  TCPServer
 
class  Thread
 
class  WaitCondition
 

Typedefs

typedef Eigen::Quaternion< double, Eigen::DontAlign > Quaternion
 
typedef Eigen::Matrix< double, 3, 1, Eigen::DontAlign > Vector
 
typedef Eigen::Matrix< double, 3, 3, Eigen::DontAlign > Tensor
 

Enumerations

enum  ApproximationFunction {
  FUNCTION_PIPE, FUNCTION_POLYNOM2, FUNCTION_POLYNOM3, FUNCTION_POLYNOM4,
  FUNCTION_POLYNOM5, FUNCTION_GAUSSIAN, FUNCTION_UNKNOWN
}
 
enum  ApproximationFunction2D { FUNCTION_UNKNOWN2D, FUNCTION_POLYNOM2D1, FUNCTION_POLYNOM2D2 }
 
enum  MutexType { MUTEX_TYPE_NORMAL, MUTEX_TYPE_ERRORCHECKED, MUTEX_TYPE_RECURSIVE }
 
enum  MutexError {
  MUTEX_ERROR_NO_ERROR =0, MUTEX_ERROR_NO_VALID_MUTEX, MUTEX_ERROR_BUSY, MUTEX_ERROR_DEADLOCK,
  MUTEX_ERROR_RECURSIVE_LIMIT, MUTEX_ERROR_DONT_OWN, MUTEX_ERROR_UNKNOWN
}
 
enum  ReadWriteLockMode { READWRITELOCK_MODE_READ, READWRITELOCK_MODE_WRITE }
 
enum  SocketFlags {
  SOCKET_FLAG_UDP = 0x01, SOCKET_FLAG_NONBLOCKING = 0x02, SOCKET_FLAG_REUSEADDR = 0x04, SOCKET_FLAG_NODELAY = 0x08,
  SOCKET_FLAG_BROADCAST = 0x10, SOCKET_FLAG_KEEPALIVE = 0x20, SOCKET_FLAG_NOSIGNAL = 0x40
}
 
enum  SocketError {
  SOCKET_SUCCESS = 0, SOCKET_HOST_NOT_FOUND = -1, SOCKET_CREATE_FAILED = -2, SOCKET_BIND_FAILED = -3,
  SOCKET_LISTEN_FAILED = -4, SOCKET_ACCEPT_FAILED = -5, SOCKET_SELECT_FAILED = -6, SOCKET_TIMEOUT = -7,
  SOCKET_CONNECTION_FAILED = -8, SOCKET_CONNECTION_BROKEN = -9, SOCKET_CONNECTION_CLOSED = -10, SOCKET_INVALID_SOCKET = -11,
  SOCKET_ALREADY_CONNECTED = -12, SOCKET_WOULD_BLOCK = -126, SOCKET_UNSPECIFIED_ERROR = -127
}
 
enum  WaitConditionError {
  WAITCOND_NO_ERROR =0, WAITCOND_TIMEOUT, WAITCOND_UNSPECIFIED, WAITCOND_INTERNAL_ERROR,
  WAITCOND_UNKNOWN
}
 

Functions

ApproximationFunction getApproximationFunctionFromString (std::string s)
 
ApproximationFunction2D getApproximationFunction2DFromString (std::string s)
 
double pipe (double *x, std::vector< double > *c)
 
double polynom2 (double *x, std::vector< double > *c)
 
double polynom3 (double *x, std::vector< double > *c)
 
double polynom4 (double *x, std::vector< double > *c)
 
double polynom5 (double *x, std::vector< double > *c)
 
double gaussian (double *x, std::vector< double > *c)
 
double polynom2D1 (double *x, double *y, std::vector< double > *c)
 
double polynom2D2 (double *x, double *y, std::vector< double > *c)
 
double getYaw (const Quaternion &q)
 
double angleBetween (const Vector &v1, const Vector &v2, Vector *axis=NULL)
 Angle between two vectors. More...
 
Quaternion eulerToQuaternion (const Vector &euler_v)
 
sRotation quaternionTosRotation (const Quaternion &value)
 
Vector slerp (const Vector &from, const Vector &to, double t)
 
Vector lerp (const Vector &from, const Vector &to, double t)
 
void vectorToSpherical (const Vector &v, double *r, double *theta, double *phi)
 
Vector getProjection (const Vector &v1, const Vector &v2)
 
Vector vectorFromSpherical (double r, double theta, double phi)
 
bool vectorFromConfigItem (ConfigItem *item, Vector *v)
 
void vectorToConfigItem (ConfigItem *item, Vector *v)
 
bool quaternionFromConfigItem (ConfigItem *item, Quaternion *q)
 
void quaternionToConfigItem (ConfigItem *item, Quaternion *q)
 
void inertiaTensorToConfigItem (ConfigItem *item, double *inertia)
 
double random_number (double min, double max, int digits)
 
double random_normal_number (double mean, double std, double low, double high)
 
double beta_distribution (double *x, std::vector< double > *c)
 
double gamma_distribution (double *x, std::vector< double > *c)
 
bool isNormalized (const Vector &vec)
 
Vector scaleVectorToLength (const Vector &vec, const double &length)
 
Quaternion angleAxisToQuaternion (double angle, const Vector &axis)
 
Quaternion eulerToQuaternion (const sRotation &rot)
 
double distanceSquaredBetween (const Vector &v1, const Vector &v2)
 
double distanceBetween (const Vector &v1, const Vector &v2)
 
template<typename T >
Quaternion quaternionFromMembers (T q)
 
template<typename T >
Quaternion quaternionFromXYZWArray (T q)
 
template<typename T >
Quaternion quaternionFromWXYZArray (T q)
 
bool matchPattern (const std::string &pattern, const std::string &str)
 basic pattern matching function More...
 
std::string trim (const std::string &str)
 remove leading and trailing whitespaces More...
 
void handleFilenamePrefix (std::string *file, const std::string &prefix)
 
std::string pathJoin (const std::string &path1, const std::string &path2)
 
void removeFilenamePrefix (std::string *file)
 given a filepath "bla/da/fnord/foobar.baz" this will remove everything before and including the last slash "/" resulting in "foobar.baz". More...
 
void removeFilenameSuffix (std::string *file)
 given a filename "foobar.baz" this will remove the extension (including the dot ".") resulting in "foobar". More...
 
std::string getFilenameSuffix (const std::string &file)
 given a filename "foobar.baz" this will return ".baz" More...
 
std::string getCurrentWorkingDir ()
 
std::string getPathOfFile (const std::string &filename)
 
unsigned int createDirectory (const std::string &dir, int mode=0755)
 creates a directory at the given path. More...
 
std::vector< std::string > explodeString (const char c, const std::string &s)
 
std::string replaceString (const std::string &source, const std::string &s1, const std::string &s2)
 
std::string toupper (const std::string &s)
 
std::string tolower (const std::string &s)
 
double radToDeg (const double &r)
 converts an angle given in radians to degrees. More...
 
float radToDeg (const float &r)
 
double degToRad (const double &d)
 converts an angle given in degrees to radians. More...
 
float degToRad (const float &d)
 
template<typename T >
std::string numToStr (T Number)
 
long long getTime ()
 
long long getTimeDiff (long long start)
 returns the time difference between now and a given reference. More...
 
void msleep (unsigned int milliseconds)
 sleeps for at least the specified time. More...
 
bool pathExists (const std::string &path)
 check whether a file or directory exists. More...
 
void ZERO_ROTATION (sRotation &a)
 
unsigned short ntoh (const unsigned short &val)
 
unsigned long ntoh (const unsigned long &val)
 
unsigned short hton (const unsigned short &val)
 
unsigned long hton (const unsigned long &val)
 
bool isBigEndian ()
 

Variables

static const int EULER_AXIS_1 = 2
 
static const int EULER_AXIS_2 = 0
 
static const int EULER_AXIS_3 = 1
 
const double SQRT2PI = 2.5066282746310002
 
const double EPSILON = Eigen::NumTraits<double>::epsilon()
 
const int INVALID_SOCKET = -1
 
const double defaultTimeout = -1.
 

Typedef Documentation

◆ Quaternion

typedef Eigen::Quaternion<double, Eigen::DontAlign> mars::utils::Quaternion

Definition at line 56 of file Quaternion.h.

◆ Tensor

typedef Eigen::Matrix<double, 3, 3, Eigen::DontAlign> mars::utils::Tensor

Definition at line 44 of file Vector.h.

◆ Vector

typedef Eigen::Matrix<double, 3, 1, Eigen::DontAlign> mars::utils::Vector

Definition at line 43 of file Vector.h.

Enumeration Type Documentation

◆ ApproximationFunction

Enumerator
FUNCTION_PIPE 
FUNCTION_POLYNOM2 
FUNCTION_POLYNOM3 
FUNCTION_POLYNOM4 
FUNCTION_POLYNOM5 
FUNCTION_GAUSSIAN 
FUNCTION_UNKNOWN 

Definition at line 35 of file mathUtils.h.

◆ ApproximationFunction2D

Enumerator
FUNCTION_UNKNOWN2D 
FUNCTION_POLYNOM2D1 
FUNCTION_POLYNOM2D2 

Definition at line 47 of file mathUtils.h.

◆ MutexError

Enumerator
MUTEX_ERROR_NO_ERROR 
MUTEX_ERROR_NO_VALID_MUTEX 
MUTEX_ERROR_BUSY 
MUTEX_ERROR_DEADLOCK 
MUTEX_ERROR_RECURSIVE_LIMIT 
MUTEX_ERROR_DONT_OWN 
MUTEX_ERROR_UNKNOWN 

Definition at line 37 of file Mutex.h.

◆ MutexType

Enumerator
MUTEX_TYPE_NORMAL 
MUTEX_TYPE_ERRORCHECKED 
MUTEX_TYPE_RECURSIVE 

Definition at line 31 of file Mutex.h.

◆ ReadWriteLockMode

Enumerator
READWRITELOCK_MODE_READ 
READWRITELOCK_MODE_WRITE 

Definition at line 27 of file ReadWriteLocker.h.

◆ SocketError

Enumerator
SOCKET_SUCCESS 
SOCKET_HOST_NOT_FOUND 
SOCKET_CREATE_FAILED 
SOCKET_BIND_FAILED 
SOCKET_LISTEN_FAILED 
SOCKET_ACCEPT_FAILED 
SOCKET_SELECT_FAILED 
SOCKET_TIMEOUT 
SOCKET_CONNECTION_FAILED 
SOCKET_CONNECTION_BROKEN 
SOCKET_CONNECTION_CLOSED 
SOCKET_INVALID_SOCKET 
SOCKET_ALREADY_CONNECTED 
SOCKET_WOULD_BLOCK 
SOCKET_UNSPECIFIED_ERROR 

Definition at line 56 of file Socket.h.

◆ SocketFlags

Enumerator
SOCKET_FLAG_UDP 
SOCKET_FLAG_NONBLOCKING 
SOCKET_FLAG_REUSEADDR 
SOCKET_FLAG_NODELAY 
SOCKET_FLAG_BROADCAST 
SOCKET_FLAG_KEEPALIVE 
SOCKET_FLAG_NOSIGNAL 

Definition at line 44 of file Socket.h.

◆ WaitConditionError

Enumerator
WAITCOND_NO_ERROR 
WAITCOND_TIMEOUT 
WAITCOND_UNSPECIFIED 
WAITCOND_INTERNAL_ERROR 
WAITCOND_UNKNOWN 

Definition at line 31 of file WaitCondition.h.

Function Documentation

◆ angleAxisToQuaternion()

Quaternion mars::utils::angleAxisToQuaternion ( double  angle,
const Vector axis 
)
inline

Definition at line 88 of file mathUtils.h.

◆ angleBetween()

double mars::utils::angleBetween ( const Vector v1,
const Vector v2,
Vector axis = NULL 
)

Angle between two vectors.

Parameters
[in]vVector to which we want to know the angle
[out]axisIf axis != NULL the axis of rotation will be stored here.
Returns
The angle between this and v in radian.

Definition at line 107 of file mathUtils.cpp.

◆ beta_distribution()

double mars::utils::beta_distribution ( double *  x,
std::vector< double > *  c 
)

◆ createDirectory()

unsigned int mars::utils::createDirectory ( const std::string &  dir,
int  mode = 0755 
)

creates a directory at the given path.

On platforms that support it you can also specify the mode. returns 0 if creation fails returns 1 if creation was successful returns 2 if directory already exists

Definition at line 174 of file misc.cpp.

◆ degToRad() [1/2]

double mars::utils::degToRad ( const double &  d)
inline

converts an angle given in degrees to radians.

Parameters
dangle in degrees
Returns
angle in radians

Definition at line 55 of file misc.h.

◆ degToRad() [2/2]

float mars::utils::degToRad ( const float &  d)
inline

Definition at line 57 of file misc.h.

◆ distanceBetween()

double mars::utils::distanceBetween ( const Vector v1,
const Vector v2 
)
inline

Definition at line 103 of file mathUtils.h.

◆ distanceSquaredBetween()

double mars::utils::distanceSquaredBetween ( const Vector v1,
const Vector v2 
)
inline

Definition at line 101 of file mathUtils.h.

◆ eulerToQuaternion() [1/2]

Quaternion mars::utils::eulerToQuaternion ( const sRotation rot)
inline

Definition at line 93 of file mathUtils.h.

◆ eulerToQuaternion() [2/2]

Quaternion mars::utils::eulerToQuaternion ( const Vector euler_v)

Definition at line 133 of file mathUtils.cpp.

◆ explodeString()

std::vector< std::string > mars::utils::explodeString ( const char  c,
const std::string &  s 
)

Definition at line 225 of file misc.cpp.

◆ gamma_distribution()

double mars::utils::gamma_distribution ( double *  x,
std::vector< double > *  c 
)

◆ gaussian()

double mars::utils::gaussian ( double *  x,
std::vector< double > *  c 
)

Definition at line 74 of file mathUtils.cpp.

◆ getApproximationFunction2DFromString()

ApproximationFunction2D mars::utils::getApproximationFunction2DFromString ( std::string  s)

Definition at line 43 of file mathUtils.cpp.

◆ getApproximationFunctionFromString()

ApproximationFunction mars::utils::getApproximationFunctionFromString ( std::string  s)

Definition at line 33 of file mathUtils.cpp.

◆ getCurrentWorkingDir()

std::string mars::utils::getCurrentWorkingDir ( )

Definition at line 153 of file misc.cpp.

◆ getFilenameSuffix()

std::string mars::utils::getFilenameSuffix ( const std::string &  file)

given a filename "foobar.baz" this will return ".baz"

Definition at line 144 of file misc.cpp.

◆ getPathOfFile()

std::string mars::utils::getPathOfFile ( const std::string &  filename)

Definition at line 164 of file misc.cpp.

◆ getProjection()

Vector mars::utils::getProjection ( const Vector v1,
const Vector v2 
)

Definition at line 253 of file mathUtils.cpp.

◆ getTime()

long long mars::utils::getTime ( )
inline
Returns
current time in milliseconds

Definition at line 71 of file misc.h.

◆ getTimeDiff()

long long mars::utils::getTimeDiff ( long long  start)
inline

returns the time difference between now and a given reference.

Parameters
startreference time
Returns
time difference between now and start in milliseconds

Definition at line 88 of file misc.h.

◆ getYaw()

double mars::utils::getYaw ( const Quaternion q)

Definition at line 102 of file mathUtils.cpp.

◆ handleFilenamePrefix()

void mars::utils::handleFilenamePrefix ( std::string *  file,
const std::string &  prefix 
)

Definition at line 108 of file misc.cpp.

◆ hton() [1/2]

unsigned short mars::utils::hton ( const unsigned short &  val)

Definition at line 64 of file Socket.cpp.

◆ hton() [2/2]

unsigned long mars::utils::hton ( const unsigned long &  val)

Definition at line 66 of file Socket.cpp.

◆ inertiaTensorToConfigItem()

void mars::utils::inertiaTensorToConfigItem ( ConfigItem item,
double *  inertia 
)

Definition at line 295 of file mathUtils.cpp.

◆ isBigEndian()

bool mars::utils::isBigEndian ( )

Definition at line 69 of file Socket.cpp.

◆ isNormalized()

bool mars::utils::isNormalized ( const Vector vec)
inline

Definition at line 72 of file mathUtils.h.

◆ lerp()

Vector mars::utils::lerp ( const Vector from,
const Vector to,
double  t 
)

Definition at line 235 of file mathUtils.cpp.

◆ matchPattern()

bool mars::utils::matchPattern ( const std::string &  pattern,
const std::string &  str 
)

basic pattern matching function

Parameters
patternThe pattern that should be found in str.
strThe string in which to search for the pattern.
Returns
true if pattern is found in str. false otherwise

The pattern may contain the wildcard "*" (asterisk) to mean zero or more of any character. Other wildcards are currently not supported. Examples:

  • matchPattern("foo", "foo") -> true
  • matchPattern("foo", "fo") -> false
  • matchPattern("foo*", "foo") -> true
  • matchPattern("foo*", "foobar") -> true
  • matchPattern("foo*", "what is foo") -> false
  • matchPattern("*wh*is*foo*", "what is foo") -> true
Note
Escaping wildcards is currently not supported.

Definition at line 56 of file misc.cpp.

◆ msleep()

void mars::utils::msleep ( unsigned int  milliseconds)
inline

sleeps for at least the specified time.

Parameters
millisecondstime to sleep in milliseconds

Definition at line 96 of file misc.h.

◆ ntoh() [1/2]

unsigned short mars::utils::ntoh ( const unsigned short &  val)

Definition at line 60 of file Socket.cpp.

◆ ntoh() [2/2]

unsigned long mars::utils::ntoh ( const unsigned long &  val)

Definition at line 62 of file Socket.cpp.

◆ numToStr()

template<typename T >
std::string mars::utils::numToStr ( Number)

Definition at line 61 of file misc.h.

◆ pathExists()

bool mars::utils::pathExists ( const std::string &  path)
inline

check whether a file or directory exists.

Parameters
pathThe filesystem path to check.
Returns
true if path is a valid file or directory. false otherwise.
Note
This function does not check for neither read nor write access. Merely for existance.

Definition at line 112 of file misc.h.

◆ pathJoin()

std::string mars::utils::pathJoin ( const std::string &  path1,
const std::string &  path2 
)

Definition at line 112 of file misc.cpp.

◆ pipe()

double mars::utils::pipe ( double *  x,
std::vector< double > *  c 
)

Definition at line 50 of file mathUtils.cpp.

◆ polynom2()

double mars::utils::polynom2 ( double *  x,
std::vector< double > *  c 
)

Definition at line 54 of file mathUtils.cpp.

◆ polynom2D1()

double mars::utils::polynom2D1 ( double *  x,
double *  y,
std::vector< double > *  c 
)

Definition at line 87 of file mathUtils.cpp.

◆ polynom2D2()

double mars::utils::polynom2D2 ( double *  x,
double *  y,
std::vector< double > *  c 
)

Definition at line 92 of file mathUtils.cpp.

◆ polynom3()

double mars::utils::polynom3 ( double *  x,
std::vector< double > *  c 
)

Definition at line 58 of file mathUtils.cpp.

◆ polynom4()

double mars::utils::polynom4 ( double *  x,
std::vector< double > *  c 
)

Definition at line 62 of file mathUtils.cpp.

◆ polynom5()

double mars::utils::polynom5 ( double *  x,
std::vector< double > *  c 
)

Definition at line 67 of file mathUtils.cpp.

◆ quaternionFromConfigItem()

bool mars::utils::quaternionFromConfigItem ( ConfigItem item,
Quaternion q 
)

Definition at line 280 of file mathUtils.cpp.

◆ quaternionFromMembers()

template<typename T >
Quaternion mars::utils::quaternionFromMembers ( q)

Definition at line 119 of file mathUtils.h.

◆ quaternionFromWXYZArray()

template<typename T >
Quaternion mars::utils::quaternionFromWXYZArray ( q)

Definition at line 129 of file mathUtils.h.

◆ quaternionFromXYZWArray()

template<typename T >
Quaternion mars::utils::quaternionFromXYZWArray ( q)

Definition at line 124 of file mathUtils.h.

◆ quaternionToConfigItem()

void mars::utils::quaternionToConfigItem ( ConfigItem item,
Quaternion q 
)

Definition at line 288 of file mathUtils.cpp.

◆ quaternionTosRotation()

sRotation mars::utils::quaternionTosRotation ( const Quaternion value)

Definition at line 163 of file mathUtils.cpp.

◆ radToDeg() [1/2]

double mars::utils::radToDeg ( const double &  r)
inline

converts an angle given in radians to degrees.

Parameters
rangle in radians
Returns
angle in degrees

Definition at line 45 of file misc.h.

◆ radToDeg() [2/2]

float mars::utils::radToDeg ( const float &  r)
inline

Definition at line 47 of file misc.h.

◆ random_normal_number()

double mars::utils::random_normal_number ( double  mean,
double  std,
double  low,
double  high 
)

Definition at line 313 of file mathUtils.cpp.

◆ random_number()

double mars::utils::random_number ( double  min,
double  max,
int  digits 
)

Definition at line 307 of file mathUtils.cpp.

◆ removeFilenamePrefix()

void mars::utils::removeFilenamePrefix ( std::string *  file)

given a filepath "bla/da/fnord/foobar.baz" this will remove everything before and including the last slash "/" resulting in "foobar.baz".

Definition at line 128 of file misc.cpp.

◆ removeFilenameSuffix()

void mars::utils::removeFilenameSuffix ( std::string *  file)

given a filename "foobar.baz" this will remove the extension (including the dot ".") resulting in "foobar".

Definition at line 136 of file misc.cpp.

◆ replaceString()

std::string mars::utils::replaceString ( const std::string &  source,
const std::string &  s1,
const std::string &  s2 
)

Definition at line 236 of file misc.cpp.

◆ scaleVectorToLength()

Vector mars::utils::scaleVectorToLength ( const Vector vec,
const double &  length 
)
inline

Definition at line 75 of file mathUtils.h.

◆ slerp()

Vector mars::utils::slerp ( const Vector from,
const Vector to,
double  t 
)

Definition at line 195 of file mathUtils.cpp.

◆ tolower()

std::string mars::utils::tolower ( const std::string &  s)

Definition at line 255 of file misc.cpp.

◆ toupper()

std::string mars::utils::toupper ( const std::string &  s)

Definition at line 247 of file misc.cpp.

◆ trim()

std::string mars::utils::trim ( const std::string &  str)

remove leading and trailing whitespaces

Definition at line 94 of file misc.cpp.

◆ vectorFromConfigItem()

bool mars::utils::vectorFromConfigItem ( ConfigItem item,
Vector v 
)

Definition at line 267 of file mathUtils.cpp.

◆ vectorFromSpherical()

Vector mars::utils::vectorFromSpherical ( double  r,
double  theta,
double  phi 
)

Definition at line 261 of file mathUtils.cpp.

◆ vectorToConfigItem()

void mars::utils::vectorToConfigItem ( ConfigItem item,
Vector v 
)

Definition at line 274 of file mathUtils.cpp.

◆ vectorToSpherical()

void mars::utils::vectorToSpherical ( const Vector v,
double *  r,
double *  theta,
double *  phi 
)

Definition at line 242 of file mathUtils.cpp.

◆ ZERO_ROTATION()

void mars::utils::ZERO_ROTATION ( sRotation a)
inline

Definition at line 52 of file Quaternion.h.

Variable Documentation

◆ defaultTimeout

const double mars::utils::defaultTimeout = -1.

Definition at line 42 of file Socket.h.

◆ EPSILON

const double mars::utils::EPSILON = Eigen::NumTraits<double>::epsilon()

Definition at line 70 of file mathUtils.h.

◆ EULER_AXIS_1

const int mars::utils::EULER_AXIS_1 = 2
static

Definition at line 98 of file mathUtils.cpp.

◆ EULER_AXIS_2

const int mars::utils::EULER_AXIS_2 = 0
static

Definition at line 99 of file mathUtils.cpp.

◆ EULER_AXIS_3

const int mars::utils::EULER_AXIS_3 = 1
static

Definition at line 100 of file mathUtils.cpp.

◆ INVALID_SOCKET

const int mars::utils::INVALID_SOCKET = -1

Definition at line 41 of file Socket.h.

◆ SQRT2PI

const double mars::utils::SQRT2PI = 2.5066282746310002

Definition at line 57 of file mathUtils.h.