10 #ifndef CGRAPHSLAMHANDLER_IMPL_H 11 #define CGRAPHSLAMHANDLER_IMPL_H 16 template<
class GRAPH_T>
18 mrpt::utils::COutputLogger* logger,
20 const bool enable_visuals):
22 m_options_checker(options_checker),
23 m_do_save_results(true),
24 m_has_set_fnames(false),
25 m_enable_visuals(enable_visuals)
42 template<
class GRAPH_T>
46 m_logger->logFmt(LVL_WARN,
"graphslam-engine has finished.");
51 "Application will exit when the display window is closed.");
52 bool break_exec =
false;
71 m_logger->logFmt(LVL_DEBUG,
"Releasing CDisplayWindow3D instance...");
76 m_logger->logFmt(LVL_DEBUG,
"Releasing CWindowObserver instance...");
81 m_logger->logFmt(LVL_DEBUG,
"Releasing CWindowManager instance...");
85 m_logger->logFmt(LVL_INFO,
"Exited.");
88 template<
class GRAPH_T>
98 "Setting up output directory: %s", output_dir_fname.c_str());
110 stringstream question;
113 question <<
"Directory exists. Choose between the " 114 <<
"following options" << std::endl;
115 question <<
"\t 1: Rename current folder and start new " 116 <<
"output directory (default)" << std::endl;
117 question <<
"\t 2: Remove existing contents and continue execution " 119 question <<
"\t 3: Handle potential conflict manually " 120 "(Halts program execution)" << std::endl;
121 question <<
"\t [ 1 | 2 | 3 ] --> ";
122 std::cout << question.str();
124 getline(cin, answer);
126 answer_int = atoi(&answer[0]);
136 m_logger->logFmt(LVL_INFO,
"Deleting existing files...");
151 string dst_fname = output_dir_fname + cur_date_validstr;
153 "Renaming directory to: %s", dst_fname.c_str());
155 bool did_rename =
renameFile(output_dir_fname, dst_fname, &error_msg);
157 format(
"\nError while trying to rename the output directory: %s",
158 error_msg.c_str()) );
165 m_logger->logFmt(LVL_INFO,
"Creating the new directory structure...");
170 m_logger->logFmt(LVL_INFO,
"Finished initializing output directory.");
176 template<
class GRAPH_T>
193 template<
class GRAPH_T>
198 mrpt::format(
"\nConfiguration file not found: \n%s\n", fname.c_str()));
200 m_logger->logFmt(LVL_INFO,
"Reading the .ini file... ");
205 "GeneralConfiguration",
206 "user_decides_about_output_dir",
209 "GeneralConfiguration",
211 "graphslam_results",
false);
213 "GeneralConfiguration",
217 "GeneralConfiguration",
221 "GeneralConfiguration",
225 "GeneralConfiguration",
227 "output_graph.graph",
false);
229 "GeneralConfiguration",
230 "save_3DScene_fname",
231 "scene.3DScene",
false);
233 "GeneralConfiguration",
235 "output_map",
false);
239 template<
class GRAPH_T>
244 using namespace mrpt;
250 format(
"\nNode Registration Decider %s is not available.\n",
251 node_reg_str.c_str()) );
254 format(
"\nEdge Registration Decider %s is not available.\n",
255 edge_reg_str.c_str()) );
258 format(
"\nOptimizer %s is not available\n",
259 optimizer_str.c_str()) );
276 template<
class GRAPH_T>
283 template<
class GRAPH_T>
289 stringstream ss_out(
"");
291 ss_out <<
"\n------------[ graphslam-engine_app Parameters ]------------" 295 ss_out <<
"User decides about output dir? = " 298 ss_out <<
"Output directory = " 301 ss_out <<
"Generate .graph file? = " 304 ss_out <<
"Generate .3DScene file? = " 308 ss_out <<
"Generated .graph filename = " 313 ss_out <<
"Generated .3DScene filename = " 316 ss_out <<
"Rawlog filename = " 323 template<
class GRAPH_T>
332 template<
class GRAPH_T>
339 "Overriding .ini Results directory -> %s...",
343 template<
class GRAPH_T>
349 m_logger->logFmt(LVL_INFO,
"Generating overall report...");
350 m_engine->generateReportFiles(output_dir_fname);
355 m_engine->saveGraph(&save_graph_fname);
360 m_engine->save3DScene(&save_3DScene_fname);
368 m_logger->logFmt(LVL_INFO,
"Generated report.");
371 template<
class GRAPH_T>
373 mrpt::maps::COccupancyGridMap2DPtr map =
377 map->saveMetricMapRepresentationToFile(fname);
380 template<
class GRAPH_T>
388 CActionCollectionPtr action;
389 CSensoryFramePtr observations;
390 CObservationPtr observation;
391 size_t curr_rawlog_entry;
394 bool cont_exec =
true;
395 while (CRawlog::getActionObservationPairOrObservation(
400 curr_rawlog_entry) && cont_exec) {
404 cont_exec =
m_engine->_execGraphSlamStep(
411 m_logger->logFmt(LVL_WARN,
"Finished graphslam execution.");
416 template<
class GRAPH_T>
426 "GraphSlam building procedure", 800, 600);
431 COpenGLViewportPtr main_view = scene->getViewport(
"main");
436 m_logger->logFmt(LVL_DEBUG,
"Initialized CDisplayWindow3D...");
437 m_logger->logFmt(LVL_DEBUG,
"Listening to CDisplayWindow3D events...");
447 template<
class GRAPH_T>
450 std::map<std::string, bool> events_occurred;
454 bool request_to_exit = events_occurred.find(
"Ctrl+c")->second;
456 return !request_to_exit;
void setResultsDirName(const std::string &dirname)
Override the results directory filename that was initially set in the .ini file.
uint64_t TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1...
void setCDisplayWindow3DPtr(mrpt::gui::CDisplayWindow3D *win_in)
Store the CDisplayWindow3D pointer in the CWindowManager instance.
void readConfigFname(const std::string &fname)
Read configuration variables for the current graphSLAM execution from a .ini file.
virtual bool checkRegistrationDeciderExists(std::string given_reg, std::string reg_type) const
Check if the given registrator decider exists in the vector of deciders.
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
void printParams() const
Print in a formatted manner the general configuraiton variables for the current graphSLAM execution...
bool BASE_IMPEXP createDirectory(const std::string &dirName)
Creates a directory.
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::string m_rawlog_fname
optimizers_t optimizers_map
std::string m_save_graph_fname
This namespace provides a OS-independent interface to many useful functions: filenames manipulation...
bool m_user_decides_about_output_dir
mrpt::system::TTimeStamp BASE_IMPEXP getCurrentTime()
Returns the current (UTC) system time.
void setWindowObserverPtr(mrpt::graphslam::CWindowObserver *obsever_in)
Store the CWindowObserver pointer in the CWindowManager instance.
void saveResults(const std::string &output_dir_fname)
This class allows loading and storing values and vectors of different types from ".ini" files easily.
edge_regs_t edge_regs_map
node_regs_t node_regs_map
bool queryObserverForEvents()
Query the CWindowObserver instance for any pressed keys that might be of interest (e...
std::string m_output_dir_fname
bool BASE_IMPEXP fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
void returnEventsStruct(std::map< std::string, bool > *codes_to_pressed, bool reset_keypresses=true)
Return a map of key code to a boolean indicating whether it was pressed since the previous time the c...
std::string BASE_IMPEXP timeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
std::string BASE_IMPEXP fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores ('_') or any other user-given char. ...
std::string m_save_map_fname
std::string getParamsAsString() const
void initVisualization()
Initialize visualization (e.g.
mrpt::opengl::COpenGLScenePtr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
SLAM methods related to graphs of pose constraints.
CGraphSlamHandler(mrpt::utils::COutputLogger *logger, mrpt::graphslam::apps::TUserOptionsChecker< GRAPH_T > *options_checker, const bool enable_visuals)
Constructor.
void BASE_IMPEXP sleep(int time_ms) MRPT_NO_THROWS
An OS-independent method for sending the current thread to "sleep" for a given period of time...
bool isOpen()
Returns false if the user has already closed the window.
void observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Main file for the GraphSlamEngine.
This namespace contains representation of robot actions and observations.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void saveMap(const std::string &fname)
void setPos(int x, int y) MRPT_OVERRIDE
Changes the position of the window on the screen.
GLsizei const GLchar ** string
mrpt::graphslam::CWindowManager * m_win_manager
void forceRepaint()
Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method...
static COccupancyGridMap2DPtr Create()
void execute()
Method to be called for parsing the rawlog file provided and for running graphSLAM using that informa...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
mrpt::gui::CDisplayWindow3D * m_win
mrpt::utils::COutputLogger * m_logger
Monitor events in the visualization window.
void setFNames(const std::string &ini_fname, const std::string &rawlog_fname, const std::string &ground_truth_fname=std::string())
Set the relevant filenames for instantiating CGraphSlamEngine instance.
The namespace for 3D scene representation and rendering.
bool BASE_IMPEXP deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell=false)
Delete all the files in a given directory (nothing done if directory does not exists, or path is a file).
std::string BASE_IMPEXP trim(const std::string &str)
Removes leading and trailing spaces.
GLenum GLsizei GLenum format
Classes for creating GUI windows for 2D and 3D visualization.
virtual bool checkOptimizerExists(std::string given_opt) const
Check if the given optimizer exists in the vector of optimizers.
bool BASE_IMPEXP directoryExists(const std::string &fileName)
Test if a given directory exists (it fails if the given path refers to an existing file)...
void initEngine(const std::string &node_reg_str, const std::string &edge_reg_str, const std::string &optimizer_str)
std::string m_save_3DScene_fname
mrpt::graphslam::CGraphSlamEngine< GRAPH_T > * m_engine
Pointer to the engine instance.
void initOutputDir(const std::string &output_dir_fname="graphslam_results")
Initialize (clean up and create new files) the output directory.
#define ASSERTMSG_(f, __ERROR_MSG)
mrpt::graphslam::CWindowObserver * m_win_observer
~CGraphSlamHandler()
Destructor.
bool BASE_IMPEXP renameFile(const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=NULL)
Renames a file - If the target path is different and the filesystem allows it, it will be moved to th...
Class acts as a container for storing pointers to mrpt::gui::CDisplayWindow3D, mrpt::graphslam::CWind...
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
mrpt::graphslam::apps::TUserOptionsChecker< GRAPH_T > * m_options_checker
TUserOptionsChecker instance whose task is to evaluate the Registration Decider, Optimizer instances ...