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++)
104 it = m_nodes.find(node->
getID());
106 if (it != m_nodes.end())
107 if (node == it->second.get()) m_nodes.erase(it);
118 if (it != m_arcs.end()) m_arcs.erase(it);
129 if (it != m_nodes.end())
138 m_nodes[node->m_ID] = node;
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;
165 using IDPair = std::pair<size_t, CHMHMapNode::Ptr>;
167 std::map<size_t, CHMHMapNode::TNodeID> nodeanotmap;
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 = mrpt::make_aligned_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 (
size_t r = 0;
r < lista.size();
r++)
194 IDnodeanotPair((
size_t)atoi(lista[
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 = mrpt::make_aligned_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 = mrpt::make_aligned_shared<CHMHMapArc>(
227 nodeto, nodefrom, 0,
this);
228 arcrev->m_arcType =
table->get(j,
"arctype");
233 std::cout <<
"Graph with [" << numnodes <<
"] nodes and [" << numarcs
234 <<
"] arcs loaded successfully." << std::endl;
237 size_t numannot =
table->getRecordCount();
238 printf(
"Loading annotations\n");
239 for (
size_t j = 0; j < numannot; j++)
241 string type =
table->get(j,
"annotation-type");
242 string value =
table->get(j,
"annotation-value");
243 nodeanotmapit = nodeanotmap.find(atoi(
table->get(j,
"id").c_str()));
245 if (nodeanotmapit != nodeanotmap.end())
247 if (
type ==
"placePose")
250 o->fromString(
value);
254 node->m_annotations.set(
264 void CHierarchicalMHMap::dumpAsXMLfile(
std::string fileName)
const 274 tablenodes->addField(
"id");
275 tablenodes->addField(
"nodename");
276 tablenodes->addField(
"nodetype");
277 tablenodes->addField(
"annotation-list");
279 tablearcs->addField(
"id");
280 tablearcs->addField(
"from");
281 tablearcs->addField(
"to");
282 tablearcs->addField(
"arctype");
283 tablearcs->addField(
"bidirectional");
284 tablearcs->addField(
"annotation-list");
286 tableannots->addField(
"id");
287 tableannots->addField(
"annotation-type");
288 tableannots->addField(
"annotation-value");
291 printf(
"Generating nodes\n");
295 i = tablenodes->appendRecord();
296 tablenodes->set(i,
"nodename", it->second->m_label.c_str());
298 i,
"id",
format(
"%i", static_cast<int>(it->second->getID())));
299 tablenodes->set(i,
"nodetype", it->second->m_nodeType);
301 tablenodes->set(i,
"annotation-list",
".");
303 it->second->m_annotations.begin();
304 ann != it->second->m_annotations.end(); ++ann)
306 size_t j = tableannots->appendRecord();
308 j,
"id",
format(
"%u", static_cast<unsigned int>(j)));
309 tableannots->set(j,
"annotation-type", ann->name.c_str());
315 std::dynamic_pointer_cast<
CPoint2D>(ann->value);
320 std::vector<uint8_t>
v;
322 str.resize(
v.size());
325 tableannots->set(j,
"annotation-value", str);
326 if (tablenodes->get(j,
"annotation-list") ==
".")
328 i,
"annotation-list",
329 format(
"%u", static_cast<unsigned int>(j)));
332 i,
"annotation-list",
333 tablenodes->get(j,
"annotation-list") +
334 format(
"%u", static_cast<unsigned int>(j)));
339 printf(
"Generating arcs (%u)\n", static_cast<unsigned int>(m_arcs.size()));
345 fromid = (int)(*it)->getNodeFrom();
346 toid = (int)(*it)->getNodeTo();
348 i = tablearcs->appendRecord();
349 tablearcs->set(i,
"id",
format(
"%u", static_cast<unsigned int>(i)));
351 i,
"from",
format(
"%u", static_cast<unsigned int>(fromid)));
352 tablearcs->set(i,
"to",
format(
"%u", static_cast<unsigned int>(toid)));
353 tablearcs->set(i,
"arctype", (*it)->m_arcType);
356 (*it)->m_annotations.begin();
357 ann != (*it)->m_annotations.end(); ++ann)
359 i = tableannots->appendRecord();
361 i,
"id",
format(
"%u", static_cast<unsigned int>(i)));
362 tableannots->set(i,
"annotation-type", ann->name.c_str());
368 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)
This must be inserted in 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. ...
std::vector< TPropertyValueIDTriplet >::const_iterator const_iterator
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.
#define IS_CLASS(ptrObj, class_name)
Evaluates to true if the given pointer to an object (derived from mrpt::rtti::CObject) is of the give...
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.
const Scalar * const_iterator
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".