34 std::string obj_name=
"") {
40 if (obj_name.empty()) {
41 cout <<
"Clearing entire scene." << endl;
45 CRenderizable::Ptr
obj = scene->getByName(obj_name);
47 scene->removeObject(obj);
62 std::string obj_name=
"") {
67 template<
class RENDERIZABLE_OBJECT>
69 const RENDERIZABLE_OBJECT& o,
70 const std::string& obj_name=
"",
75 CSetOfObjects::Ptr
obj = CSetOfObjects::Create();
78 obj->setPose(obj_pose);
80 if (!obj_name.empty()) {
81 obj->setName(obj_name);
97 obj->setLocation(0, 0, 0);
104 using namespace mrpt;
110 obj->setColor(0.7, 0.7, 0.7);
111 obj->setLocation(0, 0, 0);
129 mrpt::utils::COutputLogger* logger_in,
133 m_conn_manager(logger_in, nh_in),
136 quit_keypress2(
"Ctrl+c"),
137 map_merge_keypress(
"n"),
138 save_map_merging_results(true)
168 "Compute next available grid-merging");
176 for (neighbors_t::iterator n_it =
m_neighbors.begin();
191 m_logger->logFmt(LVL_WARN,
"Exiting...");
198 const GraphSlamAgents& nearby_slam_agents =
203 for (GraphSlamAgents::_list_type::const_iterator
204 it = nearby_slam_agents.list.begin();
205 it != nearby_slam_agents.list.end();
207 const GraphSlamAgent& gsa = *it;
211 return (neighbor->agent == gsa);
213 typename neighbors_t::iterator n_it = find_if(
223 "Initialized NeighborAgentMapProps instance for agent %s...",
224 latest_neighbor->
agent.topic_namespace.data.c_str());
229 latest_neighbor->
agent.topic_namespace.data);
237 bool continue_exec =
true;
238 for (map<TNeighborAgentMapProps*, CWindowManager*>::const_iterator
245 std::map<std::string, bool> events_map;
254 if (!win_manager->
isOpen() ||
257 continue_exec =
false;
264 std::map<std::string, bool> events_map;
276 return continue_exec;
283 m_logger->logFmt(LVL_WARN,
"In mergeMaps.");
293 for (neighbors_t::const_iterator n_it =
m_neighbors.begin();
307 COccupancyGridMap2D::Ptr map = COccupancyGridMap2D::Create();
308 m_logger->logFmt(LVL_INFO,
"Adding map of agent \"%s\" to the stack",
309 neighbor.
agent.topic_namespace.data.c_str());
314 mrpt_gridmaps.insert(make_pair(*n_it, map));
319 CSetOfLines::Ptr curr_traj = CSetOfLines::Create();
320 curr_traj->setPose(
CPose3D(0,0,0.3,0,0,0));
321 curr_traj->setLineWidth(1.5);
322 curr_traj->setColor(
TColorf(0,0,1));
325 curr_traj->appendLine(
329 for (nav_msgs::Path::_poses_type::const_iterator
333 curr_traj->appendLineStrip(pth_it->pose.position.x, pth_it->pose.position.y, 0);
338 scene->insert(curr_traj);
348 auto tmp = CSetOfLines::Ptr(dynamic_cast<CSetOfLines*>(curr_traj->clone()));
351 mrpt_trajectories.insert(make_pair(&neighbor, curr_traj));
358 if (mrpt_gridmaps.size() >= 2) {
360 m_logger->logFmt(LVL_INFO,
"Executing map merging for [%lu] gridmaps",
361 static_cast<unsigned long>(mrpt_gridmaps.size()));
362 int merge_counter = 0;
365 std::string output_dir_fname =
"map_merger_results";
368 "Saving map-merging results to \"%s\"",
369 output_dir_fname.c_str());
380 m_logger->logFmt(LVL_INFO,
"Initializing gridmaps output directory.\n");
386 COccupancyGridMap2D::Ptr fused_map = COccupancyGridMap2D::Create();
387 fused_map->copyMapContentFrom(*mrpt_gridmaps.begin()->second);
395 m_logger->logFmt(LVL_INFO,
"Clearing the fused map visuals");
400 CSetOfObjects::Ptr first_map_obj = CSetOfObjects::Create();
401 fused_map->getAs3DObject(first_map_obj);
404 first_map_obj->setName(
format(
"map_%s",
405 mrpt_gridmaps.begin()->first->agent.topic_namespace.data.c_str()));
406 fused_scene->insert(first_map_obj);
415 ss << output_dir_fname <<
"/" <<
"map" << merge_counter;
416 (mrpt_gridmaps.begin()->second)->saveMetricMapRepresentationToFile(ss.str());
421 double off_z_step = 1;
431 for (neighbors_t::const_iterator
435 neighbor_to_is_used[*n_it] =
false;
436 neighbor_to_rel_pose[*n_it] =
CPose2D();
443 for (maps_t::iterator
444 m_it = std::next(mrpt_gridmaps.begin());
445 m_it != mrpt_gridmaps.end();
446 ++m_it, ++merge_counter) {
456 "Trying to align the maps, initial estimation: %s",
458 const CPosePDF::Ptr pdf_tmp = gridmap_aligner.
AlignPDF(
459 fused_map.get(), curr_gridmap,
461 &run_time, &results);
462 m_logger->logFmt(LVL_INFO,
"Elapsed Time: %f", run_time);
465 CPosePDFSOG::Ptr pdf_out = CPosePDFSOG::Create();
466 pdf_out->copyFrom(*pdf_tmp);
469 pdf_out->getMostLikelyCovarianceAndMean(cov_out, pose_out);
476 neighbor_to_rel_pose.at(curr_neighbor) = pose_out;
477 neighbor_to_is_used.at(curr_neighbor) =
true;
485 ss << output_dir_fname <<
"/" <<
"map" << merge_counter;
492 ss << output_dir_fname <<
"/" <<
"fusing_proc_with" 493 <<
"_" << merge_counter;
494 COccupancyGridMap2D::saveAsEMFTwoMapsWithCorrespondences(
504 "Adding map to the fused map visualiztion using transformation %s",
506 CSetOfObjects::Ptr curr_map_obj = CSetOfObjects::Create();
508 curr_map_obj->setName(
format(
"map_%s",
509 curr_neighbor->
agent.topic_namespace.data.c_str()));
510 curr_map_obj->setPose(pose_out +
CPose3D(0,0,off_z,0,0,0));
512 fused_scene->insert(curr_map_obj);
525 for (trajectories_t::const_iterator
526 it = mrpt_trajectories.begin();
527 it != mrpt_trajectories.end();
532 if (!neighbor_to_is_used.at(curr_neighbor)) {
533 m_logger->logFmt(LVL_WARN,
"Skipping visualizing trajectory of agent %s in the fused map",
534 curr_neighbor->
agent.topic_namespace.data.c_str());
538 CSetOfLines::Ptr curr_traj = it->second;
539 m_logger->logFmt(LVL_WARN,
"Adding #%lu lines...",
540 static_cast<unsigned long>(curr_traj->getLineCount()));
543 CPose3D rel_pose(neighbor_to_rel_pose.at(curr_neighbor));
545 rel_pose +=
CPose3D(0,0,off_z,0,0,0);
548 curr_traj->setPose(rel_pose);
549 curr_traj->setName(
format(
"traj_%s", curr_neighbor->
agent.topic_namespace.data.c_str()));
552 fused_scene->insert(curr_traj);
564 std::string fname = output_dir_fname +
"/" +
"output_scene.3DScene";
565 fused_scene->saveToFile(fname);
596 "GraphSlam building procedure", 800, 600);
601 COpenGLViewport::Ptr main_view = scene->getViewport(
"main");
611 m_logger->logFmt(LVL_DEBUG,
"Initialized CDisplayWindow3D...");
void saveMetricMapRepresentationToFile(const std::string &filNamePrefix) const MRPT_OVERRIDE
bool BASE_IMPEXP createDirectory(const std::string &dirName)
std::string quit_keypress1
std::map< TNeighborAgentMapProps *, CWindowManager * > m_neighbors_to_windows
void monitorKeystrokes(mrpt::graphslam::CWindowObserver *win_observer)
Compact method for monitoring the given keystrokes for the given observer.
const mrpt::poses::CPose3D EMPTY_POSE
void getAs3DObject(mrpt::opengl::CSetOfObjectsPtr &outObj) const MRPT_OVERRIDE
float ransac_minSetSizeRatio
bool save_map_merging_results
std::string map_merge_keypress
mrpt::slam::CGridMapAligner::TConfigParams m_alignment_options
mrpt::graphslam::detail::CConnectionManager m_conn_manager
void setWindowObserverPtr(mrpt::graphslam::CWindowObserver *obsever_in)
void setWindowTitle(const std::string &str) MRPT_OVERRIDE
void addToWindow(mrpt::gui::CDisplayWindow3D *win, const RENDERIZABLE_OBJECT &o, const std::string &obj_name="", const mrpt::poses::CPose3D &obj_pose=EMPTY_POSE)
CMapMerger(mrpt::utils::COutputLogger *logger_in, ros::NodeHandle *nh_in)
void observeBegin(CObservable &obj)
mrpt::poses::CPosePDFPtr AlignPDF(const mrpt::maps::CMetricMap *m1, const mrpt::maps::CMetricMap *m2, const mrpt::poses::CPosePDFGaussian &initialEstimationPDF, float *runningTime=NULL, void *info=NULL)
std::string getGridMapAlignmentResultsAsString(const mrpt::poses::CPosePDF &pdf, const mrpt::slam::CGridMapAligner::TReturnInfo &ret_info)
TAlignerMethod methodSelection
mrpt::opengl::COpenGLScenePtr & get3DSceneAndLock()
nav_msgs::Path::ConstPtr nav_robot_trajectory
Trajectory of the correspondign agent - in ROS form.
void addAxis(mrpt::gui::CDisplayWindow3D *win)
std::map< TNeighborAgentMapProps *, COccupancyGridMap2D::Ptr > maps_t
std::string m_global_ns
Topic namespace under which current node is going to be publishing.
mrpt::graphslam::CWindowManager * m_fused_map_win_manager
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
const mrpt_msgs::GraphSlamAgent & agent
Pointer to the GraphSlamAgent instance of the neighbor.
neighbors_t m_neighbors
CConnectionManager instance for fetching the running graphSLAM agents.
static CGridPlaneXYPtr Create(float xMin, float xMax, float yMin, float yMax, float z=0, float frequency=1, float lineWidth=1.3f, bool antiAliasing=true)
bool isEssentiallyZero(const mrpt::poses::CPose2D &p)
std::map< TNeighborAgentMapProps *, mrpt::opengl::CSetOfLines::Ptr > trajectories_t
Robot trajectory visual object type.
bool convert(const mrpt_msgs::ObservationRangeBeacon &_msg, const mrpt::poses::CPose3D &_pose, mrpt::obs::CObservationBeaconRanges &_obj)
Struct holding a COccupancyGridMap2D (as well as subscribers for updating it) for a specific running ...
std::vector< CMatrixD > results
mrpt::gui::CDisplayWindow3D * win
nav_msgs::OccupancyGrid::ConstPtr nav_map
Map generated by the corresponding agent - in ROS form.
void returnEventsStruct(std::map< std::string, bool > *codes_to_pressed, bool reset_keypresses=true)
mrpt::utils::TColorf getNextTColorf()
mrpt::graphslam::CWindowObserver * observer
mrpt::slam::CGridMapAligner::TConfigParams options
void unlockAccess3DScene()
void getNearbySlamAgents(mrpt_msgs::GraphSlamAgents *agents_vec, bool ignore_self=true)
Fill the given vector with the SLAM Agents that the current manager can see and communicate with...
void addSupWidgets(mrpt::gui::CDisplayWindow3D *win)
static CAST_TO::Ptr from(const CAST_FROM_PTR &ptr)
std::map< TNeighborAgentMapProps *, mrpt::poses::CPose2D > neighbor_to_rel_pose_t
mrpt::gui::CDisplayWindow3DPtr win
bool BASE_IMPEXP deleteFilesInDirectory(const std::string &s, bool deleteDirectoryAsWell=false)
void registerKeystroke(const std::string key_str, const std::string key_desc)
void setCDisplayWindow3DPtr(mrpt::gui::CDisplayWindow3D *win_in)
std::string quit_keypress2
static CAxisPtr Create(float xmin, float ymin, float zmin, float xmax, float ymax, float zmax, float frecuency=1, float lineWidth=3, bool marks=false)
void dumpToConsole() const
mrpt::utils::COutputLogger * m_logger
bool updateState()
Query and fetch the list of new graphSLAM agents.
bool BASE_IMPEXP directoryExists(const std::string &fileName)
void setPos(int x, int y) MRPT_OVERRIDE
void addGrid(mrpt::gui::CDisplayWindow3D *win)
bool removeObjectFrom3DScene(mrpt::gui::CDisplayWindow3D *win, std::string obj_name="")
ROSCPP_DECL bool search(const std::string &ns, const std::string &key, std::string &result)
mrpt::utils::TMatchingPairList correspondences
mrpt::graphslam::CWindowManager * initWindowVisuals()
std::map< TNeighborAgentMapProps *, bool > neighbor_to_is_used_t
void asString(std::string &s) const