-
Notifications
You must be signed in to change notification settings - Fork 68
/
Traversal.h
216 lines (185 loc) · 7.87 KB
/
Traversal.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// SPDX-FileCopyrightText: Fondazione Istituto Italiano di Tecnologia (IIT)
// SPDX-License-Identifier: BSD-3-Clause
#ifndef IDYNTREE_TRAVERSAL_H
#define IDYNTREE_TRAVERSAL_H
#include <iDynTree/Indices.h>
#include <vector>
namespace iDynTree
{
class IJoint;
class Link;
class Model;
/**
* Class that represents a traversal of a set of links of a Model.
* The traversal is represented by an ordered vector of links.
* For a given model, the traversal is always built in such a way
* that there exist a spanning tree that has as a root the first link
* (with traversal index 0) of the traversal, and such that every link comes
* after its spanning tree parent.
*
* For every link in the traversal are provided:
* * a pointer to the link itself
* * a pointer to the parent link in the spanning tree
* * a pointer to the joint connecting the link to the parent
*
* For the first link of the traversal (i.e. base of the traversal)
* there is not spanning tree parent, so the point to the parent link/joint are NULL.
*
*
* \ingroup iDynTreeModel
*/
class Traversal
{
private:
std::vector<const Link *> links;
std::vector<const Link *> parents;
std::vector<const IJoint *> toParentJoints;
std::vector<int> linkIndexToTraversalIndex;
/**
* Copy constructor is forbidden
*/
Traversal(const Traversal & other);
/**
* Copy operator is forbidden
*/
Traversal& operator=(const Traversal &other);
public:
Traversal();
~Traversal();
/**
* Get the number of visited links.
*
* @return the number of links in the Traversal
*/
unsigned int getNrOfVisitedLinks() const;
/**
* Get the traversalIndex-th link of the traversal.
*
* @return a pointer to the traversalIndex-th link of the traversal.
*/
const Link * getLink(const TraversalIndex traversalIndex) const;
/**
* Get the base link of the traversal.
*
* @note this is equivalent to getLink(0), as the base link
* is by definition the first link of the traversal.
* @return a pointer to the base link of the traversal.
*/
const Link * getBaseLink() const;
/**
* Get the parent link of the traversalIndex-th link of the traversal.
*
* @return a pointer to the parent link of the traversalIndex-th link of the traversal.
*/
const Link * getParentLink(const TraversalIndex traversalIndex) const;
/**
* Get the joint connecting the traversalIndex-th link of the traversal
* to its parent.
*
* @return a pointer to the joint connecting the link traversalIndex-th link of the traversal.
*/
const IJoint * getParentJoint(const TraversalIndex traversalIndex) const;
/**
* Get the parent link of the link with index linkIndex of the traversal.
*
* @return a pointer to the parent link of the traversalIndex-th link of the traversal.
*/
const Link * getParentLinkFromLinkIndex(const LinkIndex linkIndex) const;
/**
* Get the joint connecting the link with index linkIndex
* to its parent.
*
* @return a pointer to the joint connecting the link traversalIndex-th link of the traversal.
*/
const IJoint * getParentJointFromLinkIndex(const LinkIndex linkIndex) const;
/**
* Get the traversal index of the specified link
*
* @return the traversalIndex of the specified link, or TRAVERSAL_INDEX_INVALID if the link does not belong to the traversal.
*/
TraversalIndex getTraversalIndexFromLinkIndex(const LinkIndex linkIndex) const;
/**
* Reset the Traversal.
*
* After a call to reset, the Traversal will contain
* no visited links, so it needs to be approprately populated
* with the addTraversalBase and addTraversalElement methods.
*
* @param[in] nrOfLinksInModel total number of links in the model,
* not the number of visited links in the Traversal.
* @return true if all went well, false otherwise
*/
bool reset(const unsigned int nrOfLinksInModel);
/**
* Reset the Traversal.
*
* After a call to reset, all the pointers in the Traversal are set
* to 0, and the Traversal should be approprialy populated with the
* setters before use.
*
* @param[in] model Model on which this traversal will be used,
* used to initialize the internal data structure
* using the getNrOfLinks() method.
*
* @return true if all went well, false otherwise
*/
bool reset(const Model & model);
/**
* Add a base to traversal.
*
* Equivalent to addTraversalElement(link,NULL,NULL), but
* will print an error and return false if it is called with a
* traversal that already has a base, i.e. getNrOfVisitedLinks() > 0
*
* @param[in] link a pointer to the base link
* @return true if all went well, false otherwise
*/
bool addTraversalBase(const Link * link);
/**
* Add an element to the traversal.
*
* After a call to this method, the getNrOfVisitedLinks()
* will be increased of 1 unit.
*
* @param[in] link a pointer to the link to add to the traversal
* @param[in] jointToParent a pointer to the joint that connects
* the added link to its parent in this traversal
* @param[in] parentLink a pointer to the parent on this link in this traversal.
* It should be a link already contained in this traversal.
* @return true if all went well, false otherwise.
*/
bool addTraversalElement(const Link * link,
const IJoint * jointToParent,
const Link * parentLink);
/**
* \brief Check if a link is the parent of another link for this traversal.
*
*
* @param[in] parentCandidate the link candidate to be the parent of childCandidate.
* @param[in] childCandidate the link candidate to be a child of parentCandidate.
* @return true if parentCandidate is actually the parent of childCandidate, false otherwise.
*/
bool isParentOf(const LinkIndex parentCandidate, const LinkIndex childCandidate) const;
/**
* \brief Get the child link (according to the traversal) of a Joint.
*
* @param[in] m_model the considered model.
* @param[in] jntIdx the index of the joint of which we want to get the child link.
* @return the index of the child link if all went well, LINK_INVALID_INDEX otherwise .
*/
LinkIndex getChildLinkIndexFromJointIndex(const Model & model, const JointIndex jntIdx) const;
/**
* \brief Get the parent link (according to the traversal) of a Joint.
*
* @param[in] m_model the considered model.
* @param[in] jntIdx the index of the joint of which we want to get the parent link.
* @return the index of the parent link if all went well, LINK_INVALID_INDEX otherwise .
*/
LinkIndex getParentLinkIndexFromJointIndex(const Model & model, const JointIndex jntIdx) const;
/**
* Return a human-readable representation of the traversal.
*/
std::string toString(const Model & model) const;
};
}
#endif /* IDYNTREE_TRAVERSAL_H */