30 CHierarchicalMHMap::~CHierarchicalMHMap() {
clear(); }
58 void CHierarchicalMHMap::writeToStream(
72 for (it = m_nodes.begin(); it != m_nodes.end(); it++)
76 n = static_cast<uint32_t>(arcCount());
78 for (it2 = m_arcs.begin(); it2 != m_arcs.end(); it2++) out << *(*it2);
98 for (i = 0; i <
n; i++)
108 for (i = 0; i <
n; i++)
131 it = m_nodes.find(node->
getID());
133 if (it != m_nodes.end())
134 if (node == it->second.get()) m_nodes.erase(it);
145 if (it != m_arcs.end()) m_arcs.erase(it);
156 if (it != m_nodes.end())
165 m_nodes[node->m_ID] = node;
177 if (it == m_arcs.end())
178 m_arcs.push_back(arc);
188 size_t j, numnodes, numarcs;
190 std::map<size_t, CHMHMapNode::Ptr> nodemap;
192 typedef std::pair<size_t, CHMHMapNode::Ptr> IDPair;
194 std::map<size_t, CHMHMapNode::TNodeID> nodeanotmap;
196 typedef std::pair<size_t, CHMHMapNode::TNodeID> IDnodeanotPair;
201 numnodes =
table->getRecordCount();
204 std::vector<std::string> node_anots;
206 for (j = 0; j < numnodes; j++)
209 node = mrpt::make_aligned_shared<CHMHMapNode>(
this);
210 node->m_label =
table->get(j,
"nodename");
211 nodemap.insert(IDPair(atoi(
table->get(j,
"id").c_str()), node));
212 node->m_nodeType.setType(
table->get(j,
"nodetype"));
214 printf(
"Loaded node %s\n", node->m_label.c_str());
216 std::deque<std::string> lista;
219 for (
size_t r = 0;
r < lista.size();
r++)
221 IDnodeanotPair((
size_t)atoi(lista[
r].c_str()), node->getID()));
227 numarcs =
table->getRecordCount();
228 printf(
"Loading arcs\n");
229 for (j = 0; j < numarcs; j++)
233 from = atoi(
table->get(j,
"from").c_str());
234 to = atoi(
table->get(j,
"to").c_str());
237 nodemapit = nodemap.find(from);
238 nodefrom = nodemapit->second;
239 std::cout <<
"finding nodes" << std::endl;
241 nodemapit = nodemap.find(to);
242 nodeto = nodemapit->second;
243 std::cout <<
"added arc from " << nodefrom->m_label <<
" to " 244 << nodeto->m_label << std::endl;
246 arc = mrpt::make_aligned_shared<CHMHMapArc>(nodefrom, nodeto, 0,
this);
247 arc->m_arcType.setType(
table->get(j,
"arctype"));
250 if (atoi(
table->get(j,
"bidirectional").c_str()) == 1)
252 printf(
"Creating bidirectional arc\n");
253 arcrev = mrpt::make_aligned_shared<CHMHMapArc>(
254 nodeto, nodefrom, 0,
this);
255 arcrev->m_arcType.setType(
table->get(j,
"arctype"));
260 std::cout <<
"Graph with [" << numnodes <<
"] nodes and [" << numarcs
261 <<
"] arcs loaded successfully." << std::endl;
264 size_t numannot =
table->getRecordCount();
265 printf(
"Loading annotations\n");
266 for (
size_t j = 0; j < numannot; j++)
268 string type =
table->get(j,
"annotation-type");
269 string value =
table->get(j,
"annotation-value");
270 nodeanotmapit = nodeanotmap.find(atoi(
table->get(j,
"id").c_str()));
272 if (nodeanotmapit != nodeanotmap.end())
274 if (
type ==
"placePose")
277 o->fromString(
value);
281 node->m_annotations.set(
291 void CHierarchicalMHMap::dumpAsXMLfile(
std::string fileName)
const 301 tablenodes->addField(
"id");
302 tablenodes->addField(
"nodename");
303 tablenodes->addField(
"nodetype");
304 tablenodes->addField(
"annotation-list");
306 tablearcs->addField(
"id");
307 tablearcs->addField(
"from");
308 tablearcs->addField(
"to");
309 tablearcs->addField(
"arctype");
310 tablearcs->addField(
"bidirectional");
311 tablearcs->addField(
"annotation-list");
313 tableannots->addField(
"id");
314 tableannots->addField(
"annotation-type");
315 tableannots->addField(
"annotation-value");
318 printf(
"Generating nodes\n");
322 i = tablenodes->appendRecord();
323 tablenodes->set(i,
"nodename", it->second->m_label.c_str());
325 i,
"id",
format(
"%i", static_cast<int>(it->second->getID())));
326 tablenodes->set(i,
"nodetype", it->second->m_nodeType.getType());
328 tablenodes->set(i,
"annotation-list",
".");
330 it->second->m_annotations.begin();
331 ann != it->second->m_annotations.end(); ++ann)
333 size_t j = tableannots->appendRecord();
335 j,
"id",
format(
"%u", static_cast<unsigned int>(j)));
336 tableannots->set(j,
"annotation-type", ann->name.c_str());
342 std::dynamic_pointer_cast<
CPoint2D>(ann->value);
349 tableannots->set(j,
"annotation-value", str);
350 if (tablenodes->get(j,
"annotation-list") ==
".")
352 i,
"annotation-list",
353 format(
"%u", static_cast<unsigned int>(j)));
356 i,
"annotation-list",
357 tablenodes->get(j,
"annotation-list") +
358 format(
"%u", static_cast<unsigned int>(j)));
363 printf(
"Generating arcs (%u)\n", static_cast<unsigned int>(m_arcs.size()));
369 fromid = (int)(*it)->getNodeFrom();
370 toid = (int)(*it)->getNodeTo();
372 i = tablearcs->appendRecord();
373 tablearcs->set(i,
"id",
format(
"%u", static_cast<unsigned int>(i)));
375 i,
"from",
format(
"%u", static_cast<unsigned int>(fromid)));
376 tablearcs->set(i,
"to",
format(
"%u", static_cast<unsigned int>(toid)));
377 tablearcs->set(i,
"arctype", (*it)->m_arcType.getType());
380 (*it)->m_annotations.begin();
381 ann != (*it)->m_annotations.end(); ++ann)
383 i = tableannots->appendRecord();
385 i,
"id",
format(
"%u", static_cast<unsigned int>(i)));
386 tableannots->set(i,
"annotation-type", ann->name.c_str());
392 printf(
"Generating XML file\n");
void asString(std::string &s) const
Returns a human-readable textual representation of the object (eg: "[0.02 1.04]" ) ...
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
std::shared_ptr< CPoint2D > Ptr
std::shared_ptr< CHMHMapArc > Ptr
std::vector< TPropertyValueIDTriplet >::const_iterator const_iterator
#define COMMON_TOPOLOG_HYP
The virtual base class which provides a unified interface for all persistent objects in MRPT...
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
bool loadFromXML(const std::string &fileName)
Loads the content of this database from a a XML file.
GLenum GLsizei GLenum GLenum const GLvoid * table
const Scalar * const_iterator
bool saveAsXML(const std::string &fileName) const
Saves this database as a XML file.
void clear()
Clear the contents of this container.
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
A set of hypothesis IDs, used for arcs and nodes in multi-hypothesis hybrid maps. ...
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
std::shared_ptr< CSimpleDatabaseTable > Ptr
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
CSimpleDatabaseTable::Ptr getTable(const std::string &tableName)
Returns the table with the indicated name.
GLsizei const GLchar ** string
A class used to store a 2D point.
This class impements a very simple database system.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
void tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
GLdouble GLdouble GLdouble r
#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::string ObjectToString(const CSerializable *o)
Used to pass MRPT objects into a CORBA-like object (strings).
The most high level class for storing hybrid, multi-hypothesis maps in a graph-based model...
TNodeID getID() const
Reads the ID of the node (read-only property)
std::shared_ptr< CHMHMapNode > Ptr
GLenum GLsizei GLenum format
A class for representing an arc between two nodes in a hierarchical, multi-hypothesis map...
std::map< CHMHMapNode::TNodeID, std::shared_ptr< CHMHMapNode > > TNodeList
A map between node IDs and nodes (used in HMT-SLAM).
GLsizei const GLfloat * value
#define NODE_ANNOTATION_PLACE_POSE
unsigned __int32 uint32_t
CSimpleDatabaseTable::Ptr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
A class for storing a sequence of arcs (a path).
GLuint GLuint GLsizei GLenum type
A class for representing a node in a hierarchical, multi-hypothesis map.