10 #ifndef CICPCRITERIAERD_IMPL_H
11 #define CICPCRITERIAERD_IMPL_H
13 namespace mrpt {
namespace graphslam {
namespace deciders {
18 template<
class GRAPH_T>
21 m_search_disk_color(142, 142, 56),
22 m_laser_scans_color(0, 20, 255),
23 m_is_using_3DScan(false)
37 this->logFmt(LVL_DEBUG,
"Initialized class object");
41 template<
class GRAPH_T>
48 mrpt::obs::CActionCollectionPtr action,
49 mrpt::obs::CSensoryFramePtr observations,
50 mrpt::obs::CObservationPtr observation ) {
57 bool registered_new_node =
false;
60 registered_new_node =
true;
62 this->logFmt(LVL_DEBUG,
"New node has been registered!");
65 if (observation.present()) {
68 static_cast<mrpt::obs::CObservation2DRangeScanPtr
>(observation);
73 static_cast<mrpt::obs::CObservation3DRangeScanPtr
>(observation);
88 if (registered_new_node) {
92 this->logFmt(LVL_DEBUG,
93 "Added laser scans of nodeID: %lu",
99 this->logFmt(LVL_DEBUG,
100 "Added laser scans of nodeID: %lu",
116 if (registered_new_node) {
118 std::set<mrpt::utils::TNodeID> nodes_to_check_ICP;
123 this->logFmt(LVL_DEBUG,
124 "Found * %lu * nodes close to nodeID %lu",
125 nodes_to_check_ICP.size(),
126 this->m_graph->nodeCount()-1);
130 registered_new_node =
false;
144 template<
class GRAPH_T>
146 const std::set<mrpt::utils::TNodeID>& nodes_set) {
148 using namespace mrpt;
153 CObservation2DRangeScanPtr curr_laser_scan;
159 curr_laser_scan = search->second;
163 if (curr_laser_scan) {
166 node_it = nodes_set.begin();
167 node_it != nodes_set.end(); ++node_it) {
172 CObservation2DRangeScanPtr prev_laser_scan;
177 prev_laser_scan = search->second;
195 "ICP constraint between NON-successive nodes: " <<
196 *node_it <<
" => " << curr_nodeID <<
199 "\tgoodness = " << icp_info.
goodness);
209 if (
absDiff(curr_nodeID, *node_it) >
210 params.LC_min_nodeid_diff) {
221 template<
class GRAPH_T>
223 const std::set<mrpt::utils::TNodeID>& nodes_set) {
230 CObservation3DRangeScanPtr curr_laser_scan;
236 curr_laser_scan = search->second;
240 if (curr_laser_scan) {
243 node_it = nodes_set.begin();
244 node_it != nodes_set.end(); ++node_it) {
249 CObservation3DRangeScanPtr prev_laser_scan;
254 prev_laser_scan = search->second;
271 if (
absDiff(curr_nodeID, *node_it) >
params.LC_min_nodeid_diff) {
283 template<
class GRAPH_T>
295 template<
class GRAPH_T>
297 std::set<mrpt::utils::TNodeID> *nodes_set,
308 double curr_distance = this->
m_graph->
nodes[nodeID].distanceTo(
311 nodes_set->insert(nodeID);
322 template<
class GRAPH_T>
324 const std::map<std::string, bool>& events_occurred) {
329 if (events_occurred.find(
params.keystroke_laser_scans)->second) {
336 template<
class GRAPH_T>
344 this->logFmt(mrpt::utils::LVL_INFO,
"Toggling LaserScans visualization...");
348 if (
params.visualize_laser_scans) {
349 CRenderizablePtr
obj = scene->getByName(
"laser_scan_viz");
350 obj->setVisibility(!
obj->isVisible());
363 template<
class GRAPH_T>
365 std::map<std::string, int>* edge_types_to_num)
const {
373 template<
class GRAPH_T>
377 this->logFmt(mrpt::utils::LVL_DEBUG,
"Initializing visuals");
382 "Configuration parameters aren't loaded yet");
385 "Toggle LaserScans Visualization");
388 if (
params.ICP_max_distance > 0) {
391 CDiskPtr
obj = CDisk::Create();
393 obj->setPose(initial_pose);
394 obj->setName(
"ICP_max_distance");
396 obj->setDiskRadius(
params.ICP_max_distance,
params.ICP_max_distance-0.1);
404 if (
params.visualize_laser_scans) {
408 laser_scan_viz->enablePoints(
true);
409 laser_scan_viz->enableLine(
true);
410 laser_scan_viz->enableSurface(
true);
411 laser_scan_viz->setSurfaceColor(
417 laser_scan_viz->setName(
"laser_scan_viz");
419 scene->insert(laser_scan_viz);
439 template<
class GRAPH_T>
453 CRenderizablePtr
obj = scene->getByName(
"ICP_max_distance");
454 CDiskPtr disk_obj =
static_cast<CDiskPtr
>(
obj);
468 CRenderizablePtr
obj = scene->getByName(
"laser_scan_viz");
469 CPlanarLaserScanPtr laser_scan_viz =
static_cast<CPlanarLaserScanPtr
>(
obj);
483 laser_scan_viz->setPose(
487 laser_scan_viz->setPose(
CPose3D(
488 laser_scan_viz->getPoseX(), laser_scan_viz->getPoseY(), -0.15,
489 DEG2RAD(laser_scan_viz->getPoseYaw()),
490 DEG2RAD(laser_scan_viz->getPosePitch()),
491 DEG2RAD(laser_scan_viz->getPoseRoll())
503 template<
class GRAPH_T>
508 using namespace mrpt;
510 this->logFmt(LVL_ERROR,
511 "Cannot toggle visibility of specified object.\n "
512 "Make sure that the corresponding visualization flag ( %s "
513 ") is set to true in the .ini file.\n",
521 template<
class GRAPH_T>
527 params.loadFromConfigFileName(source_fname,
528 "EdgeRegistrationDeciderParameters");
529 this->logFmt(LVL_DEBUG,
"Successfully loaded parameters. ");
533 int min_verbosity_level =
source.read_int(
534 "EdgeRegistrationDeciderParameters",
537 this->setMinLoggingLevel(VerbosityLevel(min_verbosity_level));
541 template<
class GRAPH_T>
550 template<
class GRAPH_T>
559 stringstream class_props_ss;
560 class_props_ss <<
"ICP Goodness-based Registration Procedure Summary: " << std::endl;
565 const std::string output_res = this->getLogAsString();
571 *report_str += class_props_ss.str();
574 *report_str += time_res;
577 *report_str += output_res;
588 template<
class GRAPH_T>
591 keystroke_laser_scans(
"l"),
592 has_read_config(false)
595 template<
class GRAPH_T>
599 template<
class GRAPH_T>
604 out.
printf(
"------------------[ Goodness-based ICP Edge Registration ]------------------\n");
605 out.
printf(
"ICP goodness threshold = %.2f%% \n", ICP_goodness_thresh*100);
606 out.
printf(
"ICP max radius for edge search = %.2f\n", ICP_max_distance);
607 out.
printf(
"Min. node difference for LC = %lu\n", LC_min_nodeid_diff);
608 out.
printf(
"Visualize laser scans = %d\n", visualize_laser_scans);
609 out.
printf(
"3DScans Image Directory = %s\n", scans_img_external_dir.c_str());
613 template<
class GRAPH_T>
619 LC_min_nodeid_diff =
source.read_int(
620 "GeneralConfiguration",
621 "LC_min_nodeid_diff",
623 ICP_max_distance =
source.read_double(
627 ICP_goodness_thresh =
source.read_double(
629 "ICP_goodness_thresh",
631 visualize_laser_scans =
source.read_bool(
632 "VisualizationParameters",
633 "visualize_laser_scans",
635 scans_img_external_dir =
source.read_string(
637 "scan_images_external_directory",
640 has_read_config =
true;
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
void getAllNodes(std::set< TNodeID > &lstNode_IDs) const
Return a list of all the node_ID's of the graph, generated from all the nodes that appear in the list...
void insertEdge(TNodeID from_nodeID, TNodeID to_nodeID, const edge_t &edge_value)
Insert an edge (from -> to) with the given edge value.
global_poses_t nodes
The nodes (vertices) of the graph, with their estimated "global" (with respect to root) position,...
size_t nodeCount() const
Return number of nodes in the list nodes of global coordinates (may be different that all nodes appea...
virtual void updateVisuals()
Update the relevant visual features in CDisplayWindow.
mrpt::utils::CTimeLogger m_time_logger
Time logger instance.
mrpt::graphslam::CWindowObserver * m_win_observer
CWindowObserver object for monitoring various visual-oriented events.
mrpt::graphslam::CWindowManager * m_win_manager
Pointer to the CWindowManager object used to store visuals-related instances.
virtual void initializeVisuals()
Initialize visual objects in CDisplayWindow (e.g.
virtual void initializeLoggers(const std::string &name)
Initialize the COutputLogger, CTimeLogger instances given the name of the decider/optimizer at hand.
static const std::string report_sep
virtual void notifyOfWindowEvents(const std::map< std::string, bool > &events_occurred)
Get a list of the window events that happened since the last call.
mrpt::gui::CDisplayWindow3D * m_win
Window to use.
static const std::string header_sep
Separator string to be used in debugging messages.
typename mrpt::graphs::CNetworkOfPoses2DInf * m_graph
Pointer to the graph that is under construction.
void addTextMessage(const double x, const double y, const std::string &text, const mrpt::utils::TColorf &color=mrpt::utils::TColorf(1.0, 1.0, 1.0), const size_t unique_index=0)
Wrapper around the CDisplayWindow3D::addTextMessage method, so that the user does not have to specify...
void assignTextMessageParameters(double *offset_y, int *text_index)
Assign the next available offset_y and text_index for the textMessage under construction.
void registerKeystroke(const std::string key_str, const std::string key_desc)
Make new keystrokes available in the help message box.
virtual void getDescriptiveReport(std::string *report_str) const
virtual void registerNewEdge(const mrpt::utils::TNodeID &from, const mrpt::utils::TNodeID &to, const constraint_t &rel_edge)
Register a new constraint/edge in the current graph.
ICP-based Edge Registration.
void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
void initializeVisuals()
Initialize visual objects in CDisplayWindow (e.g.
mrpt::obs::CObservation3DRangeScanPtr m_last_laser_scan3D
void registerNewEdge(const mrpt::utils::TNodeID &from, const mrpt::utils::TNodeID &to, const constraint_t &rel_edge)
Register a new constraint/edge in the current graph.
int m_text_index_search_disk
void getEdgesStats(std::map< std::string, int > *edge_types_to_num) const
Fill the given map with the type of registered edges as well as the corresponding number of registrat...
void checkRegistrationCondition2D(const std::set< mrpt::utils::TNodeID > &nodes_set)
void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
std::map< mrpt::utils::TNodeID, mrpt::obs::CObservation2DRangeScanPtr > m_nodes_to_laser_scans2D
mrpt::obs::CObservation2DRangeScanPtr m_fake_laser_scan2D
GRAPH_T::constraint_t constraint_t
Handy typedefs.
void loadParams(const std::string &source_fname)
Fetch the latest observation that the current instance received (most probably during a call to the u...
std::map< mrpt::utils::TNodeID, mrpt::obs::CObservation3DRangeScanPtr > m_nodes_to_laser_scans3D
mrpt::utils::TColor m_search_disk_color
see Constructor for initialization
void getNearbyNodesOf(std::set< mrpt::utils::TNodeID > *nodes_set, const mrpt::utils::TNodeID &cur_nodeID, double distance)
Get a list of the nodeIDs whose position is within a certain distance to the specified nodeID.
mrpt::utils::TColor m_laser_scans_color
see Constructor for initialization
mrpt::obs::CObservation2DRangeScanPtr m_last_laser_scan2D
void dumpVisibilityErrorMsg(std::string viz_flag, int sleep_time=500)
void toggleLaserScansVisualization()
togle the LaserScans visualization on and off
void notifyOfWindowEvents(const std::map< std::string, bool > &events_occurred)
Get a list of the window events that happened since the last call.
bool updateState(mrpt::obs::CActionCollectionPtr action, mrpt::obs::CSensoryFramePtr observations, mrpt::obs::CObservationPtr observation)
Generic method for fetching the incremental action/observation readings from the calling function.
std::map< std::string, int > m_edge_types_to_nums
void updateVisuals()
Update the relevant visual features in CDisplayWindow.
double m_offset_y_search_disk
GRAPH_T::constraint_t::type_value pose_t
type of underlying poses (2D/3D).
void checkRegistrationCondition3D(const std::set< mrpt::utils::TNodeID > &nodes_set)
virtual void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
virtual void loadParams(const std::string &source_fname)
Fetch the latest observation that the current instance received (most probably during a call to the u...
size_t m_last_total_num_nodes
Keep track of the total number of registered nodes since the last time class method was called.
void getICPEdge(const mrpt::obs::CObservation2DRangeScan &from, const mrpt::obs::CObservation2DRangeScan &to, constraint_t *rel_edge, const mrpt::poses::CPose2D *initial_pose=NULL, mrpt::slam::CICP::TReturnInfo *icp_info=NULL)
Align the 2D range scans provided and fill the potential edge that can transform the one into the oth...
bool convert3DTo2DRangeScan(mrpt::obs::CObservation3DRangeScanPtr &scan3D_in, mrpt::obs::CObservation2DRangeScanPtr *scan2D_out=NULL)
Wrapper around the CObservation3DRangeScan::convertTo2DScan corresponding method.
void forceRepaint()
Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method.
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
mrpt::opengl::COpenGLScenePtr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement,...
static CPlanarLaserScanPtr Create()
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
This class allows loading and storing values and vectors of different types from a configuration text...
This class allows loading and storing values and vectors of different types from "....
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
std::string getStatsAsText(const size_t column_width=80) const
Dump all stats to a multi-line text string.
void enter(const char *func_name)
Start of a named section.
double leave(const char *func_name)
End of a named section.
const Scalar * const_iterator
GLsizei GLsizei GLuint * obj
GLenum const GLfloat * params
GLsizei const GLchar ** string
GLsizei GLsizei GLchar * source
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
uint64_t TNodeID
The type for node IDs in graphs of different types.
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.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
#define ASSERTMSG_(f, __ERROR_MSG)
This base provides a set of functions for maths stuff.
T absDiff(const T &lhs, const T &rhs)
Absolute difference between two numbers.
This namespace contains representation of robot actions and observations.
The namespace for 3D scene representation and rendering.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values,...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
void loadFromConfigFile(const mrpt::utils::CConfigFileBase &source, const std::string §ion)
This method load the options from a ".ini"-like file or memory-stored string list.
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form,...
The ICP algorithm return information.
unsigned short nIterations
The number of executed iterations until convergence.
float goodness
A goodness measure for the alignment, it is a [0,1] range indicator of percentage of correspondences.
A RGB color - floats in the range [0,1].