34 CHierarchicalMHMap::~CHierarchicalMHMap()
78 for (it=m_nodes.begin();it!=m_nodes.end();it++)
82 n = static_cast<uint32_t>(arcCount());
84 for (it2=m_arcs.begin();it2!=m_arcs.end();it2++)
107 CHMHMapNodePtr node = CHMHMapNode::Create(
this);
116 CHMHMapArcPtr arc = CHMHMapArc::Create( CHMHMapNodePtr(),CHMHMapNodePtr(),
THypothesisIDSet() ,
this);
135 it = m_nodes.find( node->
getID() );
137 if (it!=m_nodes.end())
138 if ( node == it->second.pointer() )
150 if (it!=m_arcs.end())
157 void CHierarchicalMHMap::onNodeAddition(CHMHMapNodePtr &node)
162 if ( it!=m_nodes.end() )
171 m_nodes[ node->m_ID ] = node;
178 void CHierarchicalMHMap::onArcAddition(CHMHMapArcPtr &arc)
183 if (it==m_arcs.end())
184 m_arcs.push_back( arc );
194 CSimpleDatabaseTablePtr
table;
195 size_t j,numnodes,numarcs;
197 std::map<size_t,CHMHMapNodePtr> nodemap;
199 typedef std::pair<size_t,CHMHMapNodePtr> IDPair;
201 std::map<size_t,CHMHMapNode::TNodeID> nodeanotmap;
203 typedef std::pair<size_t,CHMHMapNode::TNodeID> IDnodeanotPair;
208 numnodes=
table->getRecordCount();
211 std::vector<std::string> node_anots;
213 for (j=0;j<numnodes;j++)
216 node=CHMHMapNode::Create(
this);
217 node->m_label=
table->get(j,
"nodename");
218 nodemap.insert(IDPair( atoi(
table->get(j,
"id").c_str()),node) );
219 node->m_nodeType.setType(
table->get(j,
"nodetype"));
221 printf(
"Loaded node %s\n",node->m_label.c_str());
224 std::deque<std::string> lista;
227 for (
size_t r=0;
r<lista.size();
r++)
228 nodeanotmap.insert(IDnodeanotPair((
size_t)atoi(lista[
r].c_str()),node->getID()));
235 numarcs=
table->getRecordCount();
236 printf(
"Loading arcs\n");
237 for (j=0;j<numarcs;j++)
239 CHMHMapArcPtr arc,arcrev;
241 from=atoi(
table->get(j,
"from").c_str());
242 to=atoi(
table->get(j,
"to").c_str());
245 CHMHMapNodePtr nodefrom,nodeto;
246 nodemapit=nodemap.find(from);
247 nodefrom=nodemapit->second;
248 std::cout<<
"finding nodes"<<std::endl;
250 nodemapit=nodemap.find(to);
251 nodeto=nodemapit->second;
252 std::cout<<
"added arc from "<< nodefrom->m_label <<
" to " <<nodeto->m_label<<std::endl;
254 arc=CHMHMapArc::Create(nodefrom,nodeto,0,
this);
255 arc->m_arcType.setType(
table->get(j,
"arctype"));
259 if (atoi(
table->get(j,
"bidirectional").c_str())==1)
261 printf(
"Creating bidirectional arc\n");
262 arcrev=CHMHMapArc::Create(nodeto,nodefrom,0,
this);
263 arcrev->m_arcType.setType(
table->get(j,
"arctype"));
270 std::cout<<
"Graph with ["<<numnodes<<
"] nodes and ["<<numarcs<<
"] arcs loaded successfully."<<std::endl;
273 size_t numannot=
table->getRecordCount();
274 printf(
"Loading annotations\n");
275 for (
size_t j=0;j<numannot;j++)
277 string type=
table->get(j,
"annotation-type");
278 string value=
table->get(j,
"annotation-value");
279 nodeanotmapit =nodeanotmap.find(atoi(
table->get(j,
"id").c_str()));
281 if (nodeanotmapit!=nodeanotmap.end())
283 if (
type==
"placePose")
286 o->fromString(
value);
288 CHMHMapNodePtr node=getNodeByID(nodeanotmapit->second);
304 void CHierarchicalMHMap::dumpAsXMLfile(
std::string fileName)
const 307 CSimpleDatabaseTablePtr tablenodes,tablearcs,tableannots;
314 tablenodes->addField(
"id");
315 tablenodes->addField(
"nodename");
316 tablenodes->addField(
"nodetype");
317 tablenodes->addField(
"annotation-list");
319 tablearcs->addField(
"id");
320 tablearcs->addField(
"from");
321 tablearcs->addField(
"to");
322 tablearcs->addField(
"arctype");
323 tablearcs->addField(
"bidirectional");
324 tablearcs->addField(
"annotation-list");
327 tableannots->addField(
"id");
328 tableannots->addField(
"annotation-type");
329 tableannots->addField(
"annotation-value");
332 printf(
"Generating nodes\n");
335 i=tablenodes->appendRecord();
336 tablenodes->set(i,
"nodename",it->second->m_label.c_str());
337 tablenodes->set(i,
"id",
format(
"%i",static_cast<int>(it->second->getID())));
338 tablenodes->set(i,
"nodetype",it->second->m_nodeType.getType());
340 tablenodes->set(i,
"annotation-list",
".");
343 size_t j=tableannots->appendRecord();
344 tableannots->set(j,
"id",
format(
"%u",static_cast<unsigned int>(j)));
345 tableannots->set(j,
"annotation-type",ann->name.c_str());
350 CPoint2DPtr o = CPoint2DPtr(ann->value);
357 tableannots->set(j,
"annotation-value",str);
358 if (tablenodes->get(j,
"annotation-list")==
".")
359 tablenodes->set(i,
"annotation-list",
format(
"%u",static_cast<unsigned int>(j)));
361 tablenodes->set(i,
"annotation-list",tablenodes->get(j,
"annotation-list")+
format(
"%u",static_cast<unsigned int>(j)));
366 printf(
"Generating arcs (%u)\n",static_cast<unsigned int>(m_arcs.size()));
375 fromid=(int)(*it)->getNodeFrom();
376 toid=(int)(*it)->getNodeTo();
379 i=tablearcs->appendRecord();
380 tablearcs->set(i,
"id",
format(
"%u",static_cast<unsigned int>(i)));
381 tablearcs->set(i,
"from",
format(
"%u",static_cast<unsigned int>(fromid)));
382 tablearcs->set(i,
"to",
format(
"%u",static_cast<unsigned int>(toid)));
383 tablearcs->set(i,
"arctype",(*it)->m_arcType.getType());
389 i=tableannots->appendRecord();
390 tableannots->set(i,
"id",
format(
"%u",static_cast<unsigned int>(i)));
391 tableannots->set(i,
"annotation-type",ann->name.c_str());
397 printf(
"Generating XML file\n");
static CPoint2DPtr Create()
Classes for serialization, sockets, ini-file manipulation, streams, list of properties-values, timewatch, extensions to STL.
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
std::map< CHMHMapNode::TNodeID, CHMHMapNodePtr > TNodeList
A map between node IDs and nodes (used in HMT-SLAM).
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::string BASE_IMPEXP format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
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...
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...
CSimpleDatabaseTablePtr getTable(const std::string &tableName)
Returns the table with the indicated name.
std::string BASE_IMPEXP 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...
CSimpleDatabaseTablePtr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
TNodeID getID() const
Reads the ID of the node (read-only property)
GLenum GLsizei GLenum format
A class for representing an arc between two nodes in a hierarchical, multi-hypothesis map...
GLsizei const GLfloat * value
#define NODE_ANNOTATION_PLACE_POSE
unsigned __int32 uint32_t
void BASE_IMPEXP tokenize(const std::string &inString, const std::string &inDelimiters, std::deque< std::string > &outTokens, bool skipBlankTokens=true) MRPT_NO_THROWS
Tokenizes a string according to a set of delimiting characters.
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.