Main MRPT website > C++ reference for MRPT 1.9.9
CHMHMapArc.cpp
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2017, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 
10 #include "hmtslam-precomp.h" // Precomp header
11 
12 using namespace mrpt;
13 using namespace mrpt::slam;
14 using namespace mrpt::hmtslam;
15 
17 
18 /*---------------------------------------------------------------
19  Constructor
20  ---------------------------------------------------------------*/
22  const CHMHMapNode::TNodeID& from, const CHMHMapNode::TNodeID& to,
23  const THypothesisIDSet& hyps, CHierarchicalMHMap* parent)
24  : m_hypotheses(hyps),
25  m_nodeFrom(from),
26  m_nodeTo(to),
27  m_parent(parent),
28  m_arcType(ARC_TYPES, DEFAULT_ARC_TYPE),
29  m_annotations()
30 {
31  // parent will be nullptr only inside a ">>" operation, as a temporal
32  // initialization of an empty object with the default constructor:
33  // To the graph:
34 }
35 
36 /*---------------------------------------------------------------
37  Other constructor
38  ---------------------------------------------------------------*/
39 CHMHMapArc::CHMHMapArc(
40  CHMHMapNode::Ptr& from, CHMHMapNode::Ptr& to, const THypothesisIDSet& hyps,
41  CHierarchicalMHMap* parent)
42  : m_hypotheses(hyps),
43  m_nodeFrom(),
44  m_nodeTo(),
45  m_parent(parent),
46  m_arcType(ARC_TYPES, DEFAULT_ARC_TYPE),
47  m_annotations()
48 {
49  if (from) m_nodeFrom = from->getID();
50  if (to) m_nodeTo = to->getID();
51 
52  // parent will be nullptr only inside a ">>" operation, as a temporal
53  // initialization of an empty object with the default constructor:
54 }
55 
56 /*---------------------------------------------------------------
57  Destructor
58  ---------------------------------------------------------------*/
60 {
61  CHMHMapNode::Ptr node;
62  // To the nodes:
63  if ((node = m_parent->getNodeByID(m_nodeFrom)))
64  node->onArcDestruction(this);
65  if ((node = m_parent->getNodeByID(m_nodeTo))) node->onArcDestruction(this);
66 
67  // To the graph:
68  if (m_parent.get()) m_parent->onArcDestruction(this);
69 }
70 
71 /*---------------------------------------------------------------
72  onNodeDestruction
73  ---------------------------------------------------------------*/
75 {
77 
78  // Check if arc is from/to this node:
79  if (node->getID() == m_nodeFrom) m_nodeFrom = AREAID_INVALID;
80  if (node->getID() == m_nodeTo) m_nodeTo = AREAID_INVALID;
81 
82  MRPT_END
83 }
84 
85 /*---------------------------------------------------------------
86  writeToStream
87  ---------------------------------------------------------------*/
88 void CHMHMapArc::writeToStream(mrpt::utils::CStream& out, int* version) const
89 {
90  if (version)
91  *version = 0;
92  else
93  {
95  << m_hypotheses;
96  }
97 }
98 
99 /*---------------------------------------------------------------
100  readFromStream
101  ---------------------------------------------------------------*/
103 {
104  switch (version)
105  {
106  case 0:
107  {
109 
110  in >> m_nodeFrom >> m_nodeTo >> type >> m_annotations >>
111  m_hypotheses;
112 
114 
115  // Find my smart pointer in the HMT map: we MUST have only 1 smrt.
116  // pointer pointing to the same object!!
117  CHMHMapArc::Ptr myPtr;
118  for (TArcList::const_iterator it = m_parent->m_arcs.begin();
119  it != m_parent->m_arcs.end(); ++it)
120  {
121  if (it->get() == this)
122  {
123  myPtr = *it;
124  break;
125  }
126  }
127  ASSERTMSG_(myPtr, "I cannot be found in my parent HMT map!")
128 
129  CHMHMapNode::Ptr node;
130  // It's not necessary since at ::Create this is already done
131  // (but...check!)
132  // m_parent->onArcAddition(this);
133 
134  // To the nodes:
135  if ((node = m_parent->getNodeByID(m_nodeFrom)))
136  node->onArcAddition(myPtr);
137  if ((node = m_parent->getNodeByID(m_nodeTo)))
138  node->onArcAddition(myPtr);
139  }
140  break;
141  default:
143  };
144 }
145 
146 /*---------------------------------------------------------------
147  TArcList::debugDump
148  ---------------------------------------------------------------*/
150 {
151  printf("Dumping arcs list: %u elements\n", (unsigned int)size());
152  for (iterator i = begin(); i != end(); ++i)
153  {
154  printf(
155  "\t'%s'\t-> '%s'\n",
156  (*i)->m_parent->getNodeByID((*i)->getNodeFrom())->m_label.c_str(),
157  (*i)->m_parent->getNodeByID((*i)->getNodeTo())->m_label.c_str());
158  }
159 }
160 
162 {
163  uint32_t i, n;
164  in >> n;
165  BASE::clear();
166  for (i = 0; i < n; i++)
167  {
168  CHMHMapArc::Ptr theObj = mrpt::make_aligned_shared<CHMHMapArc>();
169  in >> *theObj;
170  this->push_back(theObj);
171  }
172 }
174 {
175  out << static_cast<uint32_t>(this->size());
176  for (const_iterator i = begin(); i != end(); ++i) out << **i;
177 }
THypothesisIDSet m_hypotheses
The hypothesis IDs under which this arc exists.
Definition: CHMHMapArc.h:43
void setType(const std::string &type)
Sets the currently selected type.
void read(utils::CStream &in)
Definition: CHMHMapArc.cpp:161
std::shared_ptr< CHMHMapArc > Ptr
Definition: CHMHMapArc.h:38
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.
utils::CMHPropertiesValuesList m_annotations
The annotations of the arc, see the general description of the class for possible properties and valu...
Definition: CHMHMapArc.h:106
GLenum GLsizei n
Definition: glext.h:5074
Scalar * iterator
Definition: eigen_plugins.h:26
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:29
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
#define ARC_TYPES
Used in constructor of mrpt::hmtslam::CHMHMapArc.
CHMHMapNode::TNodeID m_nodeTo
Definition: CHMHMapArc.h:48
const Scalar * const_iterator
Definition: eigen_plugins.h:27
#define AREAID_INVALID
utils::CTypeSelector m_arcType
The type of the arc, the possibilities are:
Definition: CHMHMapArc.h:101
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:189
CHMHMapNode::TNodeID m_nodeFrom
The origin/target nodes for this arc.
Definition: CHMHMapArc.h:48
This base class is used to provide a unified interface to files,memory buffers,..Please see the deriv...
Definition: CStream.h:41
A set of hypothesis IDs, used for arcs and nodes in multi-hypothesis hybrid maps. ...
#define MRPT_END
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
GLuint GLuint end
Definition: glext.h:3528
uint64_t TNodeID
The type for node IDs in graphs of different types.
Definition: types_simple.h:49
virtual ~CHMHMapArc()
Destructor.
Definition: CHMHMapArc.cpp:59
void writeToStream(mrpt::utils::CStream &out, int *getVersion) const override
Introduces a pure virtual method responsible for writing to a CStream.
Definition: CHMHMapArc.cpp:88
void readFromStream(mrpt::utils::CStream &in, int version) override
Introduces a pure virtual method responsible for loading from a CStream This can not be used directly...
Definition: CHMHMapArc.cpp:102
GLsizei const GLchar ** string
Definition: glext.h:4101
std::string getType() const
Gets the currently selected type, from the set of posibilities.
#define MRPT_START
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLuint in
Definition: glext.h:7274
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
Definition: CHMHMapNode.h:42
A class for representing an arc between two nodes in a hierarchical, multi-hypothesis map...
Definition: CHMHMapArc.h:31
GLsizeiptr size
Definition: glext.h:3923
unsigned __int32 uint32_t
Definition: rptypes.h:47
#define ASSERTMSG_(f, __ERROR_MSG)
GLuint GLuint GLsizei GLenum type
Definition: glext.h:3528
A class for representing a node in a hierarchical, multi-hypothesis map.
Definition: CHMHMapNode.h:36
#define DEFAULT_ARC_TYPE
mrpt::utils::safe_ptr< CHierarchicalMHMap > m_parent
The hierarchical graph in which this object is into.
Definition: CHMHMapArc.h:51
void onNodeDestruction(CHMHMapNode *node)
Event handler to be called just before a node is being destroyed: it should be called only for nodes ...
Definition: CHMHMapArc.cpp:74
void write(utils::CStream &out) const
Definition: CHMHMapArc.cpp:173



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019