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;
59 if (this->m_last_total_num_nodes < this->
m_graph->nodeCount()) {
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(),
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;
181 this->
m_graph->nodes[*node_it];
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>
291 this->
m_graph->insertEdge(from, to, rel_edge);
295 template<
class GRAPH_T>
297 std::set<mrpt::utils::TNodeID> *nodes_set,
306 nodeID < this->
m_graph->nodeCount()-1;
308 double curr_distance = this->
m_graph->nodes[nodeID].distanceTo(
309 this->
m_graph->nodes[cur_nodeID]);
311 nodes_set->insert(nodeID);
316 this->
m_graph->getAllNodes(*nodes_set);
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);
457 this->
m_graph->nodes[this->m_graph->nodeCount()-1]);
468 CRenderizablePtr
obj = scene->getByName(
"laser_scan_viz");
469 CPlanarLaserScanPtr laser_scan_viz =
static_cast<CPlanarLaserScanPtr
>(
obj);
482 if (search != this->
m_graph->nodes.end()) {
483 laser_scan_viz->setPose(
484 this->
m_graph->nodes[this->m_graph->nodeCount()-1]);
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;
virtual void notifyOfWindowEvents(const std::map< std::string, bool > &events_occurred)
Get a list of the window events that happened since the last call.
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...
void unlockAccess3DScene()
Unlocks the access to the internal 3D scene.
std::map< mrpt::utils::TNodeID, mrpt::obs::CObservation2DRangeScanPtr > m_nodes_to_laser_scans2D
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
ICP-based Edge Registration.
mrpt::gui::CDisplayWindow3D * m_win
Window to use.
void notifyOfWindowEvents(const std::map< std::string, bool > &events_occurred)
Get a list of the window events that happened since the last call.
virtual void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
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...
void dumpVisibilityErrorMsg(std::string viz_flag, int sleep_time=500)
This class allows loading and storing values and vectors of different types from ".ini" files easily.
void checkRegistrationCondition2D(const std::set< mrpt::utils::TNodeID > &nodes_set)
static const std::string header_sep
Separator string to be used in debugging messages.
GRAPH_T::constraint_t constraint_t
Handy typedefs.
Declares a class derived from "CObservation" that encapsules a 3D range scan measurement, as from a time-of-flight range camera or any other RGBD sensor.
mrpt::graphslam::CWindowObserver * m_win_observer
CWindowObserver object for monitoring various visual-oriented events.
size_t m_last_total_num_nodes
Keep track of the total number of registered nodes since the last time class method was called...
const Scalar * const_iterator
mrpt::utils::TColor m_search_disk_color
see Constructor for initialization
void registerKeystroke(const std::string key_str, const std::string key_desc)
Make new keystrokes available in the help message box.
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...
GLsizei GLsizei GLuint * obj
void toggleLaserScansVisualization()
togle the LaserScans visualization on and off
This class allows loading and storing values and vectors of different types from a configuration text...
mrpt::graphslam::CWindowManager * m_win_manager
Pointer to the CWindowManager object used to store visuals-related instances.
float goodness
A goodness measure for the alignment, it is a [0,1] range indicator of percentage of correspondences...
mrpt::opengl::COpenGLScenePtr & get3DSceneAndLock()
Gets a reference to the smart shared pointer that holds the internal scene (carefuly read introductio...
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
This base provides a set of functions for maths stuff.
int m_text_index_search_disk
uint64_t TNodeID
The type for node IDs in graphs of different types.
virtual void initializeVisuals()
Initialize visual objects in CDisplayWindow (e.g.
#define MRPT_UNUSED_PARAM(a)
Can be used to avoid "not used parameters" warnings from the compiler.
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...
mrpt::obs::CObservation2DRangeScanPtr m_last_laser_scan2D
mrpt::obs::CObservation2DRangeScanPtr m_fake_laser_scan2D
static const std::string report_sep
std::string getStatsAsText(const size_t column_width=80) const
Dump all stats to a multi-line text string.
void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
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.
This namespace contains representation of robot actions and observations.
double m_offset_y_search_disk
uint64_t TNodeID
The type for node IDs in graphs of different types.
virtual void initializeLoggers(const std::string &name)
Initialize the COutputLogger, CTimeLogger instances given the name of the decider/optimizer at hand...
GRAPH_T * m_graph
Pointer to the graph that is under construction.
std::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
unsigned short nIterations
The number of executed iterations until convergence.
GLsizei const GLchar ** string
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void dumpToTextStream(mrpt::utils::CStream &out) const
This method should clearly display all the contents of the structure in textual form, sending it to a CStream.
mrpt::utils::TColor m_laser_scans_color
see Constructor for initialization
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...
std::map< std::string, int > m_edge_types_to_nums
void forceRepaint()
Repaints the window. forceRepaint, repaint and updateWindow are all aliases of the same method...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
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.
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.
A "CObservation"-derived class that represents a 2D range scan measurement (typically from a laser sc...
mrpt::utils::CTimeLogger m_time_logger
Time logger instance.
virtual void getDescriptiveReport(std::string *report_str) const
Fill the provided string with a detailed report of the decider/optimizer state.
A class used to store a 3D pose (a 3D translation + a rotation in 3D).
static CPlanarLaserScanPtr Create()
virtual void updateVisuals()
Update the relevant visual features in CDisplayWindow.
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::utils::CSerializable) is of t...
std::map< mrpt::utils::TNodeID, mrpt::obs::CObservation3DRangeScanPtr > m_nodes_to_laser_scans3D
The ICP algorithm return information.
The namespace for 3D scene representation and rendering.
void printParams() const
Print the problem parameters - relevant to the decider/optimizer to the screen in a unified/compact w...
GLsizei GLsizei GLchar * source
A RGB color - floats in the range [0,1].
double leave(const char *func_name)
End of a named section.
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...
T absDiff(const T &lhs, const T &rhs)
Absolute difference between two numbers.
GRAPH_T::constraint_t::type_value pose_t
type of underlying poses (2D/3D).
void updateVisuals()
Update the relevant visual features in CDisplayWindow.
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 enter(const char *func_name)
Start of a named section.
#define MRPT_LOG_DEBUG_STREAM(__CONTENTS)
#define ASSERTMSG_(f, __ERROR_MSG)
GLenum const GLfloat * params
bool convert3DTo2DRangeScan(mrpt::obs::CObservation3DRangeScanPtr &scan3D_in, mrpt::obs::CObservation2DRangeScanPtr *scan2D_out=NULL)
Wrapper around the CObservation3DRangeScan::convertTo2DScan corresponding method. ...
double BASE_IMPEXP distance(const TPoint2D &p1, const TPoint2D &p2)
Gets the distance between two points in a 2D space.
virtual int printf(const char *fmt,...) MRPT_printf_format_check(2
Writes a string to the stream in a textual form.
void loadParams(const std::string &source_fname)
Fetch the latest observation that the current instance received (most probably during a call to the u...
void assignTextMessageParameters(double *offset_y, int *text_index)
Assign the next available offset_y and text_index for the textMessage under construction.
mrpt::obs::CObservation3DRangeScanPtr m_last_laser_scan3D
void initializeVisuals()
Initialize visual objects in CDisplayWindow (e.g.
void checkRegistrationCondition3D(const std::set< mrpt::utils::TNodeID > &nodes_set)