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-2018, 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 
87 {
89 }
90 
93 {
94  switch (version)
95  {
96  case 0:
97  {
100 
101  // Find my smart pointer in the HMT map: we MUST have only 1 smrt.
102  // pointer pointing to the same object!!
103  CHMHMapArc::Ptr myPtr;
104  for (TArcList::const_iterator it = m_parent->m_arcs.begin();
105  it != m_parent->m_arcs.end(); ++it)
106  {
107  if (it->get() == this)
108  {
109  myPtr = *it;
110  break;
111  }
112  }
113  ASSERTMSG_(myPtr, "I cannot be found in my parent HMT map!");
114 
115  CHMHMapNode::Ptr node;
116  // It's not necessary since at ::Create this is already done
117  // (but...check!)
118  // m_parent->onArcAddition(this);
119 
120  // To the nodes:
121  if ((node = m_parent->getNodeByID(m_nodeFrom)))
122  node->onArcAddition(myPtr);
123  if ((node = m_parent->getNodeByID(m_nodeTo)))
124  node->onArcAddition(myPtr);
125  }
126  break;
127  default:
129  };
130 }
131 
132 /*---------------------------------------------------------------
133  TArcList::debugDump
134  ---------------------------------------------------------------*/
136 {
137  printf("Dumping arcs list: %u elements\n", (unsigned int)size());
138  for (iterator i = begin(); i != end(); ++i)
139  {
140  printf(
141  "\t'%s'\t-> '%s'\n",
142  (*i)->m_parent->getNodeByID((*i)->getNodeFrom())->m_label.c_str(),
143  (*i)->m_parent->getNodeByID((*i)->getNodeTo())->m_label.c_str());
144  }
145 }
146 
148 {
149  uint32_t i, n;
150  in >> n;
151  BASE::clear();
152  for (i = 0; i < n; i++)
153  {
154  CHMHMapArc::Ptr theObj = mrpt::make_aligned_shared<CHMHMapArc>();
155  in >> *theObj;
156  this->push_back(theObj);
157  }
158 }
160 {
161  out << static_cast<uint32_t>(this->size());
162  for (const_iterator i = begin(); i != end(); ++i) out << **i;
163 }
n
GLenum GLsizei n
Definition: glext.h:5074
mrpt::hmtslam::TArcList::write
void write(mrpt::serialization::CArchive &out) const
Definition: CHMHMapArc.cpp:159
mrpt::hmtslam::CHMHMapArc::m_parent
mrpt::safe_ptr< CHierarchicalMHMap > m_parent
The hierarchical graph in which this object is into.
Definition: CHMHMapArc.h:51
begin
EIGEN_STRONG_INLINE iterator begin()
Definition: eigen_plugins.h:29
mrpt::containers::clear
void clear()
Clear the contents of this container.
Definition: ts_hash_map.h:188
const_iterator
const Scalar * const_iterator
Definition: eigen_plugins.h:27
mrpt::hmtslam::CHMHMapArc::m_annotations
CMHPropertiesValuesList m_annotations
The annotations of the arc, see the general description of the class for possible properties and valu...
Definition: CHMHMapArc.h:106
mrpt::hmtslam::CHMHMapArc::~CHMHMapArc
virtual ~CHMHMapArc()
Destructor.
Definition: CHMHMapArc.cpp:59
mrpt::hmtslam::CHMHMapArc::Ptr
std::shared_ptr< CHMHMapArc > Ptr
Definition: CHMHMapArc.h:38
mrpt::hmtslam::CHMHMapArc::serializeFrom
void serializeFrom(mrpt::serialization::CArchive &in, uint8_t serial_version) override
Pure virtual method for reading (deserializing) from an abstract archive.
Definition: CHMHMapArc.cpp:91
mrpt::hmtslam::CHMHMapNode::getID
TNodeID getID() const
Reads the ID of the node (read-only property)
Definition: CHMHMapNode.cpp:133
mrpt::hmtslam::TArcList::read
void read(mrpt::serialization::CArchive &in)
Definition: CHMHMapArc.cpp:147
mrpt::hmtslam::CHMHMapArc::m_nodeFrom
CHMHMapNode::TNodeID m_nodeFrom
The origin/target nodes for this arc.
Definition: CHMHMapArc.h:48
mrpt::hmtslam::CHMHMapNode
A class for representing a node in a hierarchical, multi-hypothesis map.
Definition: CHMHMapNode.h:36
end
GLuint GLuint end
Definition: glext.h:3528
mrpt::graphs::TNodeID
uint64_t TNodeID
A generic numeric type for unique IDs of nodes or entities.
Definition: TNodeID.h:17
mrpt::hmtslam::CHMHMapArc::m_arcType
std::string m_arcType
The type of the arc, the possibilities are:
Definition: CHMHMapArc.h:101
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
uint8_t
unsigned char uint8_t
Definition: rptypes.h:41
mrpt::hmtslam::CHMHMapArc::m_hypotheses
THypothesisIDSet m_hypotheses
The hypothesis IDs under which this arc exists.
Definition: CHMHMapArc.h:43
hmtslam-precomp.h
mrpt::serialization::CArchive
Virtual base class for "archives": classes abstracting I/O streams.
Definition: CArchive.h:48
DEFAULT_ARC_TYPE
#define DEFAULT_ARC_TYPE
Definition: HMT_SLAM_common.h:34
push_back
EIGEN_STRONG_INLINE void push_back(Scalar val)
Insert an element at the end of the container (for 1D vectors/arrays)
Definition: eigen_plugins.h:134
mrpt::hmtslam::CHMHMapArc::onNodeDestruction
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
mrpt::hmtslam
Classes related to the implementation of Hybrid Metric Topological (HMT) SLAM.
Definition: CHierarchicalMapMHPartition.h:30
mrpt::hmtslam::TArcList::debugDump
void debugDump()
Definition: CHMHMapArc.cpp:135
MRPT_START
#define MRPT_START
Definition: exceptions.h:262
mrpt::hmtslam::CHMHMapArc::m_nodeTo
CHMHMapNode::TNodeID m_nodeTo
Definition: CHMHMapArc.h:48
mrpt::hmtslam::THypothesisIDSet
A set of hypothesis IDs, used for arcs and nodes in multi-hypothesis hybrid maps.
Definition: HMT_SLAM_common.h:78
mrpt::hmtslam::CHMHMapArc::serializeGetVersion
uint8_t serializeGetVersion() const override
Must return the current versioning number of the object.
Definition: CHMHMapArc.cpp:85
IMPLEMENTS_SERIALIZABLE
#define IMPLEMENTS_SERIALIZABLE(class_name, base, NameSpace)
This must be inserted in all CSerializable classes implementation files.
Definition: CSerializable.h:114
ASSERTMSG_
#define ASSERTMSG_(f, __ERROR_MSG)
Defines an assertion mechanism.
Definition: exceptions.h:101
AREAID_INVALID
#define AREAID_INVALID
Definition: HMT_SLAM_common.h:43
mrpt::hmtslam::CHMHMapArc
A class for representing an arc between two nodes in a hierarchical, multi-hypothesis map.
Definition: CHMHMapArc.h:31
mrpt::hmtslam::CHMHMapNode::Ptr
std::shared_ptr< CHMHMapNode > Ptr
Definition: CHMHMapNode.h:42
MRPT_END
#define MRPT_END
Definition: exceptions.h:266
ARC_TYPES
#define ARC_TYPES
Used in constructor of mrpt::hmtslam::CHMHMapArc.
Definition: HMT_SLAM_common.h:33
in
GLuint in
Definition: glext.h:7274
iterator
Scalar * iterator
Definition: eigen_plugins.h:26
MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION
#define MRPT_THROW_UNKNOWN_SERIALIZATION_VERSION(__V)
For use in CSerializable implementations.
Definition: exceptions.h:90
mrpt::slam
Definition: CMultiMetricMapPDF.h:27
mrpt::hmtslam::CHierarchicalMHMap
The most high level class for storing hybrid, multi-hypothesis maps in a graph-based model.
Definition: CHierarchicalMHMap.h:29
size
GLsizeiptr size
Definition: glext.h:3923
uint32_t
unsigned __int32 uint32_t
Definition: rptypes.h:47
mrpt::hmtslam::CHMHMapArc::serializeTo
void serializeTo(mrpt::serialization::CArchive &out) const override
Pure virtual method for writing (serializing) to an abstract archive.
Definition: CHMHMapArc.cpp:86



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST