/* * convergence implementation * * Copyright (C) Jochen Sprickerhof, Peter Schneider * * Released under the GPL version 3. * */ /** * @file * @brief Implementation for generating a convergence graph of a scanseries frame * @author Jochen Sprickerhof. Institute of Computer Science, University of Osnabrueck, Germany. * @author Peter Schneider. Institute of Computer Science, University of Koblenz, Germany. */ #include using std::exception; #include "slam6d/scan.h" #include "slam6d/convergence.h" /** * Storing the base directory */ string filepath; /** * Explains the usage of this program's command line parameters * @param prog name of the program */ void usage(char* prog) { #ifndef _MSC_VER const string bold("\033[1m"); const string normal("\033[m"); #else const string bold(""); const string normal(""); #endif cout << endl << "Usage: " << prog << " [-s NR] filepath, [-z NR] convergence type" << endl << endl; cout << " -s NR generate convergence-data for frame NR" << endl << endl; cout << " -z NR type of convergence (0 = global, 1 = local)" << endl << endl; exit(1); } /** * A function that parses the command-line arguments and sets the respective flags. * * @param argc the number of arguments * @param argv the arguments * @param dir parsing result - the directory * @param start parsing result - starting at scan number 'start' * @param type parsing result - the type of convergence that should be stored (lokal, global) * @return 0, if the parsing was successful, 1 otherwise */ int parseArgs(int argc,char **argv, string &dir, int &frame, int &type) { frame = 0; type = 0; int c; // from unistd.h extern char *optarg; extern int optind; cout << endl; while ((c = getopt (argc, argv, "s:z:m:M:p:wt")) != -1) switch (c) { case 's': frame = atoi(optarg); if (frame < 0) { cerr << "Error: Cannot generate data of a negative frame number.\n"; exit(1); } break; case 'z': type = atoi(optarg); if (type > 2 || type < 0) { cerr << "Error: only global (0) or local (1) available.\n"; exit(1); } break; case '?': usage(argv[0]); return 1; default: abort (); } if (optind != argc-1) { cerr << "\n*** Directory missing ***" << endl; usage(argv[0]); } dir = argv[optind]; #ifndef _MSC_VER if (dir[dir.length()-1] != '/') dir = dir + "/"; #else if (dir[dir.length()-1] != '\\') dir = dir + "\\"; #endif return 0; } void getLocalConvergence(ifstream *inputFile, ofstream *outputFile) { double transMat[16]; int type; double rPos[3]; double rPosTheta[3]; cout<<"starting local convergence"<> transMat >> type; if(type == Scan::ICP) { Matrix4ToEuler(transMat, rPosTheta, rPos); (*outputFile)<> transMat >> type; Matrix4ToEuler(transMat, rPosTheta, rPos); Matrix4ToQuat(transMat, quat); if((initial || type != Scan::INVALID) && type != Scan::ICPINACTIVE) { initial = false; (*outputFile) << sqrt(Dist2(rPosOrg, rPos))/100.0 << " " << quat_dist(quatOrg, quat) << " " << type << endl; } //(*outputFile) << sqrt(Dist2(rPosOrg, rPos))/100.0 << " " << quat_dist(quatOrg, quat) << " " << type << endl; } catch (const exception &e) { break; } } } void getGlobalConvergence(ifstream *inputFile, ofstream *outputFile) { double transMat[16]; int type; bool lumYetFound = false; double rPos[3]; double rPosTheta[3]; cout<<"starting global convergence"<> transMat >> type; if(type == Scan::LUM) { lumYetFound = true; Matrix4ToEuler(transMat, rPosTheta, rPos); (*outputFile)<close(); outputFile->open("xyz.con", ios::trunc); } } } catch (const exception &e) { break; } } } /* * A function that read the .frame files created by slam6D * * @param dir the directory * @param frameNr frame number that should be read */ void readFrames(string dir, int frameNr, int convType) { ifstream frame_in; ofstream xyz_out; xyz_out.open("xyz.con"); string frameFileName; frameFileName = dir + "scan" + to_string(frameNr,3) + ".frames"; cout << "Reading Frame for convergence data " << frameFileName << "..."<