10 #ifndef CGRAPHSLAMHANDLER_IMPL_H
11 #define CGRAPHSLAMHANDLER_IMPL_H
19 template <
class GRAPH_T>
23 const bool enable_visuals )
25 m_options_checker(options_checker),
26 m_do_save_results(true),
27 m_has_set_fnames(false),
28 m_enable_visuals(enable_visuals)
47 template <
class GRAPH_T>
57 "Application will exit when the display window is closed.");
58 bool break_exec =
false;
62 std::this_thread::sleep_for(100ms);
87 "Releasing CDisplayWindow3D instance...");
95 "Releasing CWindowObserver instance...");
103 "Releasing CWindowManager instance...");
110 template <
class GRAPH_T>
117 using namespace mrpt;
121 output_dir_fname.c_str());
135 stringstream question;
138 question <<
"Directory exists. Choose between the "
139 <<
"following options" << std::endl;
140 question <<
"\t 1: Rename current folder and start new "
141 <<
"output directory (default)" << std::endl;
142 question <<
"\t 2: Remove existing contents and continue execution "
144 question <<
"\t 3: Handle potential conflict manually "
145 "(Halts program execution)"
147 question <<
"\t [ 1 | 2 | 3 ] --> ";
148 std::cout << question.str();
150 getline(cin, answer);
152 answer_int = atoi(&answer[0]);
180 string dst_fname = output_dir_fname + cur_date_validstr;
186 renameFile(output_dir_fname, dst_fname, &error_msg);
189 "\nError while trying to rename the output "
211 template <
class GRAPH_T>
227 template <
class GRAPH_T>
232 mrpt::format(
"\nConfiguration file not found: \n%s\n", fname.c_str()));
239 "GeneralConfiguration",
"user_decides_about_output_dir",
false,
false);
241 "GeneralConfiguration",
"output_dir_fname",
"graphslam_results",
false);
243 cfg_file.
read_bool(
"GeneralConfiguration",
"save_graph",
true,
false);
245 cfg_file.
read_bool(
"GeneralConfiguration",
"save_3DScene",
true,
false);
247 cfg_file.
read_bool(
"GeneralConfiguration",
"save_map",
true,
false);
249 "GeneralConfiguration",
"save_graph_fname",
"output_graph.graph",
252 "GeneralConfiguration",
"save_3DScene_fname",
"scene.3DScene",
false);
254 "GeneralConfiguration",
"save_map_fname",
"output_map",
false);
257 template <
class GRAPH_T>
262 using namespace mrpt;
269 "\nNode Registration Decider %s is not available.\n",
270 node_reg_str.c_str()));
274 "\nEdge Registration Decider %s is not available.\n",
275 edge_reg_str.c_str()));
278 format(
"\nOptimizer %s is not available\n", optimizer_str.c_str()));
289 template <
class GRAPH_T>
297 template <
class GRAPH_T>
304 stringstream ss_out(
"");
306 ss_out <<
"\n------------[ graphslam-engine_app Parameters ]------------"
310 ss_out <<
"User decides about output dir? = "
314 ss_out <<
"Generate .graph file? = "
316 ss_out <<
"Generate .3DScene file? = "
334 template <
class GRAPH_T>
344 template <
class GRAPH_T>
353 template <
class GRAPH_T>
360 m_engine->generateReportFiles(output_dir_fname);
366 m_engine->saveGraph(&save_graph_fname);
372 m_engine->save3DScene(&save_3DScene_fname);
384 template <
class GRAPH_T>
388 mrpt::make_aligned_shared<mrpt::maps::COccupancyGridMap2D>();
391 map->saveMetricMapRepresentationToFile(fname);
394 template <
class GRAPH_T>
405 size_t curr_rawlog_entry;
409 bool cont_exec =
true;
410 while (CRawlog::getActionObservationPairOrObservation(
411 arch, action, observations, observation, curr_rawlog_entry) &&
416 cont_exec =
m_engine->_execGraphSlamStep(
417 action, observations, observation, curr_rawlog_entry);
423 template <
class GRAPH_T>
453 template <
class GRAPH_T>
456 std::map<std::string, bool> events_occurred;
460 bool request_to_exit = events_occurred.find(
"Ctrl+c")->second;
462 return !request_to_exit;
static uint64_t getCurrentTime()
std::string m_save_map_fname
void setResultsDirName(const std::string &dirname)
Override the results directory filename that was initially set in the .ini file.
void execute()
Method to be called for parsing the rawlog file provided and for running graphSLAM using that informa...
mrpt::graphslam::CGraphSlamEngine< GRAPH_T > * m_engine
Pointer to the engine instance.
mrpt::gui::CDisplayWindow3D * m_win
mrpt::graphslam::apps::TUserOptionsChecker< GRAPH_T > * m_options_checker
TUserOptionsChecker instance whose task is to evaluate the Registration Decider, Optimizer instances ...
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.
std::string m_rawlog_fname
mrpt::graphslam::CWindowObserver * m_win_observer
std::string m_save_3DScene_fname
void readConfigFname(const std::string &fname)
Read configuration variables for the current graphSLAM execution from a .ini file.
void saveResults(const std::string &output_dir_fname)
void initEngine(const std::string &node_reg_str, const std::string &edge_reg_str, const std::string &optimizer_str)
CGraphSlamHandler(mrpt::system::COutputLogger *logger, mrpt::graphslam::apps::TUserOptionsChecker< GRAPH_T > *options_checker, const bool enable_visuals)
Constructor.
void initVisualization()
Initialize visualization (e.g.
void saveMap(const std::string &fname)
void initOutputDir(const std::string &output_dir_fname="graphslam_results")
Initialize (clean up and create new files) the output directory.
std::string m_save_graph_fname
void printParams() const
Print in a formatted manner the general configuraiton variables for the current graphSLAM execution.
mrpt::graphslam::CWindowManager * m_win_manager
mrpt::system::COutputLogger * m_logger
std::string getParamsAsString() const
std::string m_output_dir_fname
~CGraphSlamHandler()
Destructor.
bool queryObserverForEvents()
Query the CWindowObserver instance for any pressed keys that might be of interest (e....
bool m_user_decides_about_output_dir
bool read_bool(const std::string §ion, const std::string &name, bool defaultValue, bool failIfNotFound=false) const
std::string read_string(const std::string §ion, const std::string &name, const std::string &defaultValue, bool failIfNotFound=false) const
This class allows loading and storing values and vectors of different types from "....
Main file for the GraphSlamEngine.
Class acts as a container for storing pointers to mrpt::gui::CDisplayWindow3D, mrpt::graphslam::CWind...
void setCDisplayWindow3DPtr(mrpt::gui::CDisplayWindow3D *win_in)
Store the CDisplayWindow3D pointer in the CWindowManager instance.
void setWindowObserverPtr(mrpt::graphslam::CWindowObserver *obsever_in)
Store the CWindowObserver pointer in the CWindowManager instance.
Monitor events in the visualization window.
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...
bool isOpen()
Returns false if the user has already closed the window.
A graphical user interface (GUI) for efficiently rendering 3D scenes in real-time.
void forceRepaint()
Repaints the window.
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
void setPos(int x, int y) override
Changes the position of the window on the screen.
mrpt::opengl::COpenGLScene::Ptr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
std::shared_ptr< COccupancyGridMap2D > Ptr
std::shared_ptr< CActionCollection > Ptr
std::shared_ptr< CObservation > Ptr
std::shared_ptr< CSensoryFrame > Ptr
std::shared_ptr< COpenGLScene > Ptr
std::shared_ptr< COpenGLViewport > Ptr
void observeBegin(CObservable &obj)
Starts the subscription of this observer to the given object.
Versatile class for consistent logging and management of output messages.
void logFmt(const VerbosityLevel level, const char *fmt,...) const MRPT_printf_format_check(3
Alternative logging method, which mimics the printf behavior.
#define ASSERTDEB_(f)
Defines an assertion mechanism - only when compiled in debug.
#define ASSERTDEBMSG_(f, __ERROR_MSG)
GLenum GLsizei GLenum format
GLsizei const GLchar ** string
bool deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell=false)
Delete all the files in a given directory (nothing done if directory does not exists,...
bool createDirectory(const std::string &dirName)
Creates a directory.
bool renameFile(const std::string &oldFileName, const std::string &newFileName, std::string *error_msg=nullptr)
Renames a file - If the target path is different and the filesystem allows it, it will be moved to th...
std::string fileNameStripInvalidChars(const std::string &filename, const char replacement_to_invalid_chars='_')
Replace invalid filename chars by underscores ('_') or any other user-given char.
bool directoryExists(const std::string &fileName)
Test if a given directory exists (it fails if the given path refers to an existing file).
bool fileExists(const std::string &fileName)
Test if a given file (or directory) exists.
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
std::string trim(const std::string &str)
Removes leading and trailing spaces.
mrpt::Clock::time_point TTimeStamp
A system independent time type, it holds the the number of 100-nanosecond intervals since January 1,...
std::string timeToString(const mrpt::system::TTimeStamp t)
Convert a timestamp into this textual form (UTC): HH:MM:SS.MMMMMM.
SLAM methods related to graphs of pose constraints.
Classes for creating GUI windows for 2D and 3D visualization.
This namespace contains representation of robot actions and observations.
The namespace for 3D scene representation and rendering.
CArchiveStreamBase< STREAM > archiveFrom(STREAM &s)
Helper function to create a templatized wrapper CArchive object for a: MRPT's CStream,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Class containing the declarations of supplementary methods that can be used in application-related co...