#include <usg_common.h> /* cos */
|
#include <graph.h>
|
#include <IndirectAlg.h>
|
#include <fstream>
|
using namespace std;
|
char *ltrim(char *str, const char *seps)
|
{
|
size_t totrim;
|
if (seps == NULL) {
|
seps = "\t\n\v\f\r ";
|
}
|
totrim = strspn(str, seps);
|
if (totrim > 0) {
|
size_t len = strlen(str);
|
if (totrim == len) {
|
str[0] = '\0';
|
}
|
else {
|
memmove(str, str + totrim, len + 1 - totrim);
|
}
|
}
|
return str;
|
}
|
|
char *rtrim(char *str, const char *seps)
|
{
|
int i;
|
if (seps == NULL) {
|
seps = "\t\n\v\f\r ";
|
}
|
i = strlen(str) - 1;
|
while (i >= 0 && strchr(seps, str[i]) != NULL) {
|
str[i] = '\0';
|
i--;
|
}
|
return str;
|
}
|
|
char *trim(char *str, const char *seps)
|
{
|
return ltrim(rtrim(str, seps), seps);
|
}
|
|
|
int test2() {
|
// IndirectAlg indirectAlg({ {{0.0, 0.0}, {1000.0, 0.0}}, {{1000.0, 0.0}, {1000.0, 1000.0}}, {{1000.0, 1000.0}, {0.0, 1000.0}}, {{0.0, 1000.0}, {0.0, 0.0}} }, 5, {1, 1});
|
/**
|
* @points 组成观测区域的彼此相邻的点
|
* @_direction 正确行进的方向方向
|
* @_keepTime 保持时间
|
* @ minDistance 最小移动距离
|
*/
|
IndirectAlg indirectAlg((std::initializer_list<Point>){{0.0, 0.0}, {1000.0, 0.0}, {1000.0, 1000.0}, {0.0, 1000.0} },
|
{1, 1}, 5, 1);
|
|
int i = 0;
|
// time_t start_time;
|
srand((unsigned) time(0));
|
|
double rx, ry;
|
bool isRetrograde;
|
//起点
|
Point start = {0, 0};
|
//传入的流数据记录信息Record
|
Record record;
|
record.id = 1; //目标ID
|
record.timestamp = time(0); //时间戳
|
record.coordinate = start; // 坐标
|
// time(&start_time);
|
//判断是否逆行
|
while(!(isRetrograde = indirectAlg.isRetrograde(record)) ) {
|
rx = ((double)(rand()%10))/100000;
|
ry = ((double)(rand()%10))/100000;
|
|
//std::cout << timestamp << ":" << << "isRetrograde" << isRetrograde;
|
// err_msg(0, "%ld : {%f, %f} %d\n", record.timestamp, record.coordinate.x, record.coordinate.y, isRetrograde);
|
record.timestamp = time(0);
|
|
//if (difftime(time(0), start_time) > 1)
|
if (i > 10)
|
{
|
record.coordinate = {record.coordinate.x - rx , record.coordinate.y - ry};
|
} else {
|
record.coordinate = {record.coordinate.x + rx , record.coordinate.y + ry};
|
}
|
|
if (i > 100)
|
break;
|
|
sleep(1);
|
i++;
|
}
|
printf("return %ld : {%f, %f} %d\n", record.timestamp, record.coordinate.x, record.coordinate.y, isRetrograde);
|
return 0;
|
}
|
|
void test3() {
|
|
std::ifstream fin("test.txt");
|
char line[1024];
|
//std::string line;
|
char *targetIdStr;
|
char *timestampStr;
|
char *targetStr;
|
char *targetStrBegin;
|
char *targetStrEnd;
|
char *targetPointXstr;
|
char *targetPointYstr;
|
//{"x":148,"y":45},{"x":148,"y":539},{"x":769,"y":539},{"x":769,"y":45}
|
//{148, 45}, {148, 539}, {769, 539}, {769, 45}
|
Record record;
|
IndirectAlg indirectAlg((std::initializer_list<Point>){}, {621, 0}, 3, 0);
|
|
// const char *delim = " ";
|
while(fin.getline(line, 1024)) {
|
// printf("line=%s\n", line);
|
if(strlen(trim(line, NULL))== 0)
|
continue;
|
if(*line == '#') {
|
continue;
|
}
|
|
|
|
targetStrBegin = strchr(line, '{');
|
targetStrEnd = strchr(line, '}');
|
|
|
|
*targetStrBegin = 0;
|
*targetStrEnd = 0;
|
|
targetIdStr = strtok(line, " ");
|
timestampStr = strtok(NULL, " ");
|
|
targetStr = targetStrBegin + 1;
|
|
targetPointXstr = strtok(targetStr, " ");
|
targetPointYstr = strtok(NULL, " ");
|
//std::cout << targetIdStr << "," << timestampStr << "," << targetPointXstr << "," << targetPointYstr << std::endl;
|
record.id = targetIdStr;
|
record.timestamp = atol(timestampStr);
|
record.coordinate.x = strtod(targetPointXstr, 0);
|
record.coordinate.y = strtod(targetPointYstr, 0);
|
|
if ( indirectAlg.isRetrograde(record)) {
|
std::cout << record.id << "," << record.timestamp << "," << record.coordinate.x << "," << record.coordinate.y << std::endl;
|
}
|
// while(token) {
|
// puts(token);
|
// token = strtok(NULL, " ");
|
// }
|
|
// printf("key = %s, value=%s\n", key, value);
|
}
|
fin.close();
|
}
|
|
|
int main() {
|
test3();
|
|
|
}
|