29 CHierarchicalMHMap::CHierarchicalMHMap() =
default;
33 CHierarchicalMHMap::~CHierarchicalMHMap() {
clear(); }
45 uint8_t CHierarchicalMHMap::serializeGetVersion()
const {
return 0; }
50 for (
const auto&
n : m_nodes) out << *
n.second;
54 for (
const auto&
a : m_arcs) out << *
a;
57 void CHierarchicalMHMap::serializeFrom(
71 for (i = 0; i <
n; i++)
81 for (i = 0; i <
n; i++)
102 TNodeList::iterator it;
104 it = m_nodes.find(node->
getID());
106 if (it != m_nodes.end())
107 if (node == it->second.get()) m_nodes.erase(it);
117 auto it = m_arcs.find_ptr_to(arc);
118 if (it != m_arcs.end()) m_arcs.erase(it);
127 auto it = m_nodes.find(node->m_ID);
129 if (it != m_nodes.end())
138 m_nodes[node->m_ID] = node;
148 auto it = m_arcs.find(arc);
150 if (it == m_arcs.end())
151 m_arcs.push_back(arc);
161 size_t j, numnodes, numarcs;
163 std::map<size_t, CHMHMapNode::Ptr> nodemap;
164 std::map<size_t, CHMHMapNode::Ptr>::iterator nodemapit;
165 using IDPair = std::pair<size_t, CHMHMapNode::Ptr>;
167 std::map<size_t, CHMHMapNode::TNodeID> nodeanotmap;
168 std::map<size_t, CHMHMapNode::TNodeID>::iterator nodeanotmapit;
169 using IDnodeanotPair = std::pair<size_t, CHMHMapNode::TNodeID>;
174 numnodes =
table->getRecordCount();
177 std::vector<std::string> node_anots;
179 for (j = 0; j < numnodes; j++)
182 node = std::make_shared<CHMHMapNode>(
this);
183 node->m_label =
table->get(j,
"nodename");
184 nodemap.insert(IDPair(atoi(
table->get(j,
"id").c_str()), node));
185 node->m_nodeType =
table->get(j,
"nodetype");
187 printf(
"Loaded node %s\n", node->m_label.c_str());
189 std::deque<std::string> lista;
192 for (
auto&
r : lista)
194 IDnodeanotPair((
size_t)atoi(
r.c_str()), node->getID()));
200 numarcs =
table->getRecordCount();
201 printf(
"Loading arcs\n");
202 for (j = 0; j < numarcs; j++)
206 from = atoi(
table->get(j,
"from").c_str());
207 to = atoi(
table->get(j,
"to").c_str());
210 nodemapit = nodemap.find(from);
211 nodefrom = nodemapit->second;
212 std::cout <<
"finding nodes" << std::endl;
214 nodemapit = nodemap.find(to);
215 nodeto = nodemapit->second;
216 std::cout <<
"added arc from " << nodefrom->m_label <<
" to " 217 << nodeto->m_label << std::endl;
219 arc = std::make_shared<CHMHMapArc>(nodefrom, nodeto, 0,
this);
220 arc->m_arcType =
table->get(j,
"arctype");
223 if (atoi(
table->get(j,
"bidirectional").c_str()) == 1)
225 printf(
"Creating bidirectional arc\n");
226 arcrev = std::make_shared<CHMHMapArc>(nodeto, nodefrom, 0,
this);
227 arcrev->m_arcType =
table->get(j,
"arctype");
232 std::cout <<
"Graph with [" << numnodes <<
"] nodes and [" << numarcs
233 <<
"] arcs loaded successfully." << std::endl;
236 size_t numannot =
table->getRecordCount();
237 printf(
"Loading annotations\n");
238 for (
size_t ja = 0; ja < numannot; ja++)
240 string type =
table->get(ja,
"annotation-type");
241 string value =
table->get(ja,
"annotation-value");
242 nodeanotmapit = nodeanotmap.find(atoi(
table->get(ja,
"id").c_str()));
244 if (nodeanotmapit != nodeanotmap.end())
246 if (
type ==
"placePose")
249 o->fromString(
value);
253 node->m_annotations.set(
263 void CHierarchicalMHMap::dumpAsXMLfile(
std::string fileName)
const 273 tablenodes->addField(
"id");
274 tablenodes->addField(
"nodename");
275 tablenodes->addField(
"nodetype");
276 tablenodes->addField(
"annotation-list");
278 tablearcs->addField(
"id");
279 tablearcs->addField(
"from");
280 tablearcs->addField(
"to");
281 tablearcs->addField(
"arctype");
282 tablearcs->addField(
"bidirectional");
283 tablearcs->addField(
"annotation-list");
285 tableannots->addField(
"id");
286 tableannots->addField(
"annotation-type");
287 tableannots->addField(
"annotation-value");
290 printf(
"Generating nodes\n");
291 for (
const auto& m_node : m_nodes)
293 i = tablenodes->appendRecord();
294 tablenodes->set(i,
"nodename", m_node.second->m_label.c_str());
296 i,
"id",
format(
"%i", static_cast<int>(m_node.second->getID())));
297 tablenodes->set(i,
"nodetype", m_node.second->m_nodeType);
299 tablenodes->set(i,
"annotation-list",
".");
300 for (
auto ann = m_node.second->m_annotations.begin();
301 ann != m_node.second->m_annotations.end(); ++ann)
303 size_t j = tableannots->appendRecord();
305 j,
"id",
format(
"%u", static_cast<unsigned int>(j)));
306 tableannots->set(j,
"annotation-type", ann->name.c_str());
312 std::dynamic_pointer_cast<
CPoint2D>(ann->value);
317 std::vector<uint8_t>
v;
319 str.resize(
v.size());
322 tableannots->set(j,
"annotation-value", str);
323 if (tablenodes->get(j,
"annotation-list") ==
".")
325 i,
"annotation-list",
326 format(
"%u", static_cast<unsigned int>(j)));
329 i,
"annotation-list",
330 tablenodes->get(j,
"annotation-list") +
331 format(
"%u", static_cast<unsigned int>(j)));
336 printf(
"Generating arcs (%u)\n", static_cast<unsigned int>(m_arcs.size()));
338 for (
const auto& m_arc : m_arcs)
342 fromid = (int)m_arc->getNodeFrom();
343 toid = (int)m_arc->getNodeTo();
345 i = tablearcs->appendRecord();
346 tablearcs->set(i,
"id",
format(
"%u", static_cast<unsigned int>(i)));
348 i,
"from",
format(
"%u", static_cast<unsigned int>(fromid)));
349 tablearcs->set(i,
"to",
format(
"%u", static_cast<unsigned int>(toid)));
350 tablearcs->set(i,
"arctype", m_arc->m_arcType);
352 for (
auto ann = m_arc->m_annotations.begin();
353 ann != m_arc->m_annotations.end(); ++ann)
355 i = tableannots->appendRecord();
357 i,
"id",
format(
"%u", static_cast<unsigned int>(i)));
358 tableannots->set(i,
"annotation-type", ann->name.c_str());
364 printf(
"Generating XML file\n");
bool saveAsXML(const std::string &fileName) const
Saves this database as a XML file.
#define COMMON_TOPOLOG_HYP
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
This class impements a very simple database system.
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
To be added to all CSerializable-classes implementation files.
GLenum GLsizei GLenum GLenum const GLvoid * table
void ObjectToOctetVector(const CSerializable *o, std::vector< uint8_t > &out_vector)
Converts (serializes) an MRPT object into an array of bytes.
void WriteAs(const TYPE_FROM_ACTUAL &value)
CSimpleDatabaseTable::Ptr createTable(const std::string &name)
Creates a new table in the DB, initially empty.
void tokenize(const std::string &inString, const std::string &inDelimiters, OUT_CONTAINER &outTokens, bool skipBlankTokens=true) noexcept
Tokenizes a string according to a set of delimiting characters.
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
#define ASSERT_(f)
Defines an assertion mechanism.
A set of hypothesis IDs, used for arcs and nodes in multi-hypothesis hybrid maps. ...
#define IS_CLASS(obj, class_name)
True if the given reference to object (derived from mrpt::rtti::CObject) is of the given class...
GLsizei const GLchar ** string
A class used to store a 2D point.
Classes for 2D/3D geometry representation, both of single values and probability density distribution...
CSimpleDatabaseTable::Ptr getTable(const std::string &tableName)
Returns the table with the indicated name.
Virtual base class for "archives": classes abstracting I/O streams.
GLdouble GLdouble GLdouble r
std::string format(const char *fmt,...) MRPT_printf_format_check(1
A std::string version of C sprintf.
The most high level class for storing hybrid, multi-hypothesis maps in a graph-based model...
The virtual base class which provides a unified interface for all persistent objects in MRPT...
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
GLubyte GLubyte GLubyte a
void clear()
Clear the contents of this container.
GLuint GLuint GLsizei GLenum type
A class for representing a node in a hierarchical, multi-hypothesis map.
bool loadFromXML(const std::string &fileName)
Loads the content of this database from a a XML file.
void memcpy(void *dest, size_t destSize, const void *src, size_t copyCount) noexcept
An OS and compiler independent version of "memcpy".