23 #include <sys/times.h> 25 #include <sys/types.h> 41 std::cin.getline(bChar, 255);
42 std::string result = bChar;
46 std::string
combineStrings(std::vector<std::string> &input, std::string delimiter)
49 for (
unsigned int i=0; i<input.size(); i++)
53 if (i+1 < input.size())
64 if((dp = opendir(dir.c_str())) == NULL)
66 std::cout <<
"Error(" << errno <<
") opening " << dir << std::endl;
70 if (dir.length() > 0 && dir[dir.length()-1] !=
'/')
73 while ((dirp = readdir(dp)) != NULL)
76 files.push_back(dir + std::string(dirp->d_name));
78 files.push_back(std::string(dirp->d_name));
85 std::string
boolToString(
bool value){
if (value)
return "true";
return "false"; }
88 std::vector<std::string>& tokens,
89 const std::string& delimiters)
92 std::string::size_type lastPos = str.find_first_not_of(delimiters, 0);
94 std::string::size_type pos = str.find_first_of(delimiters, lastPos);
96 while (std::string::npos != pos || std::string::npos != lastPos)
99 tokens.push_back(str.substr(lastPos, pos - lastPos));
101 lastPos = str.find_first_not_of(delimiters, pos);
103 pos = str.find_first_of(delimiters, lastPos);
110 std::string
strreplace(
const std::string &stringSearchString,
const std::string &stringReplaceString, std::string stringStringToReplace)
112 std::string::size_type pos = stringStringToReplace.find(stringSearchString, 0);
113 int intLengthSearch = stringSearchString.length();
114 int intLengthReplacment = stringReplaceString.length();
116 while(std::string::npos != pos)
118 stringStringToReplace.replace(pos, intLengthSearch, stringReplaceString);
119 pos = stringStringToReplace.find(stringSearchString, pos + intLengthReplacment);
122 return stringStringToReplace;
125 void strreplaceWithCondition(
const std::string &stringSearchString,
const std::string &stringReplaceString, std::string &stringStringToReplace, std::string condition)
127 if (condition.length() == 0)
129 stringStringToReplace =
strreplace(stringSearchString, stringReplaceString, stringStringToReplace);
133 std::string::size_type pos = stringStringToReplace.find(stringSearchString, 0);
134 int intLengthSearch = stringSearchString.length();
135 int intLengthReplacment = stringReplaceString.length();
137 while(std::string::npos != pos)
139 if (pos > 0 && stringStringToReplace[pos] == condition[0])
141 pos = stringStringToReplace.find(stringSearchString, pos + 1);
144 stringStringToReplace.replace(pos, intLengthSearch, stringReplaceString);
145 pos = stringStringToReplace.find(stringSearchString, pos + intLengthReplacment);
153 va_start(argp, format);
154 vsprintf(buffer, format, argp);
161 void strToArray(std::string text, std::vector<double> &result, std::string delimiter)
163 std::vector<std::string> tokens;
166 for (
unsigned int i=0; i<tokens.size(); i++)
170 result.push_back(atof(tokens[i].c_str()));
178 values[0] = matrix.
a[12];
179 values[1] = matrix.
a[13];
180 values[2] = matrix.
a[14];
182 values[3] = matrix.
a[0];
183 values[4] = matrix.
a[1];
184 values[5] = matrix.
a[2];
186 values[6] = matrix.
a[4];
187 values[7] = matrix.
a[5];
188 values[8] = matrix.
a[6];
190 values[9] = matrix.
a[8];
191 values[10] = matrix.
a[9];
192 values[11] = matrix.
a[10];
197 matrix.
a[12] = values[0];
198 matrix.
a[13] = values[1];
199 matrix.
a[14] = values[2];
202 matrix.
a[0] = values[3];
203 matrix.
a[1] = values[4];
204 matrix.
a[2] = values[5];
207 matrix.
a[4] = values[6];
208 matrix.
a[5] = values[7];
209 matrix.
a[6] = values[8];
212 matrix.
a[8] = values[9];
213 matrix.
a[9] = values[10];
214 matrix.
a[10] = values[11];
220 std::vector<std::string> tokens;
222 if (tokens.size() == 0)
224 return strcasecmp(tokens[0].c_str(), end.c_str()) == 0;
230 std::vector<std::string> tokens;
232 if (tokens.size() == 0)
234 return strcasecmp(tokens.back().c_str(), end.c_str()) == 0;
250 matrix.
a[12] = values[0];
251 matrix.
a[13] = values[1];
252 matrix.
a[14] = values[2];
259 if (values.size() > 3)
262 if (values.size() > 4)
265 if (values.size() > 5)
276 if (values.size() > 0)
278 matrix.
a[12] = values[0];
279 if (values.size() > 1)
281 matrix.
a[13] = values[1];
282 if (values.size() > 2)
284 matrix.
a[14] = values[2];
285 }
else matrix.
a[14] = 0.0;
286 }
else matrix.
a[13] = 0.0;
287 }
else matrix.
a[12] = 0.0;
296 values[0] = matrix.
a[12];
297 values[1] = matrix.
a[13];
298 values[2] = matrix.
a[14];
299 values[3] = tmp.
x * angle;
300 values[4] = tmp.
y * angle;
301 values[5] = tmp.
z * angle;
309 values[0] = matrix.
a[12];
310 values[1] = matrix.
a[13];
311 values[2] = matrix.
a[14];
312 values[3] = tmp.
x * angle;
313 values[4] = tmp.
y * angle;
314 values[5] = tmp.
z * angle;
331 std::string
strtrim(std::string& s,
const std::string& drop)
333 std::string r=s.erase(s.find_last_not_of(drop)+1);
334 return r.erase(0,r.find_first_not_of(drop));
353 static struct timeval tstart;
354 static struct timezone tz;
355 gettimeofday(&tstart, &tz);
356 return tstart.tv_sec*1000 + tstart.tv_usec / 1000;
362 std::vector<std::pair<double, unsigned int> > angles;
void strtokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters)
double strToDouble(const char *text, double value=0.0)
std::string printToString(const char *format,...)
std::string waitForReturn(std::string msg="Press any key.\n")
std::string combineStrings(std::vector< std::string > &input, std::string delimiter=" ")
std::string strtrim(std::string &s, const std::string &drop=" ")
void vectorToMatrix6(CMatrix &matrix, const double *values)
static void getMatrixFromRotation(CMatrix &mat, const CVec &axis, double angle)
Transforms axis-angle representation into homogenous matrix representation.
std::string strreplace(const std::string &stringSearchString, const std::string &stringReplaceString, std::string stringStringToReplace)
static void getRotationFromMatrix(const CMatrix &mat, CVec &axis, double &angle)
Transforms homogenous matrix into axis-angle representation.
int getDirectoryFiles(std::string dir, std::vector< std::string > &files, bool appendDir=false)
bool stringEndsWith(std::string text, std::string end, std::string sep="_")
std::string boolToString(bool value)
void matrixToVector6(const CMatrix &matrix, double *values)
void vectorToMatrix(CMatrix &matrix, const std::vector< double > &values)
void strToArray(std::string text, std::vector< double > &result, std::string delimiter=" ")
bool stringStartsWith(std::string text, std::string end, std::string sep="_")
void getConvexHullXY(std::vector< CVec > &points, std::vector< CVec > &hull)
void matrixToArray(const CMatrix &matrix, std::vector< double > &values)
void matrixToVector(const CMatrix &matrix, std::vector< double > &values)
void arrayToMatrix(CMatrix &matrix, std::vector< double > &values)
unsigned long getTickCount()
void strreplaceWithCondition(const std::string &stringSearchString, const std::string &stringReplaceString, std::string &stringStringToReplace, std::string condition="")