Choreonoid  1.8
LinkTraverse.h
Go to the documentation of this file.
1 
7 #ifndef CNOID_BODY_LINK_TRAVERSE_H
8 #define CNOID_BODY_LINK_TRAVERSE_H
9 
10 #include <vector>
11 #include "exportdecl.h"
12 
13 namespace cnoid {
14 
15 class Link;
16 
17 class CNOID_EXPORT LinkTraverse
18 {
19 public:
20  typedef std::vector<Link*> container;
21 
22  LinkTraverse();
23  LinkTraverse(int size);
24  LinkTraverse(Link* root, bool doUpward = false, bool doDownward = true);
25  LinkTraverse(const LinkTraverse& org);
26 
27  virtual ~LinkTraverse();
28 
29  void clear();
30 
31  virtual void find(Link* root, bool doUpward = false, bool doDownward = true);
32 
33  void append(Link* link, bool isDownward = true);
34 
35  bool remove(Link* link);
36 
38  Link* prependRootAdjacentLinkToward(Link* link);
39 
40  int numLinks() const {
41  return static_cast<int>(links_.size());
42  }
43 
44  bool empty() const {
45  return links_.empty();
46  }
47 
48  std::size_t size() const {
49  return links_.size();
50  }
51 
52  Link* rootLink() const {
53  return (links_.empty() ? nullptr : links_.front());
54  }
55 
56  Link* link(int index) const {
57  return links_[index];
58  }
59 
60  Link* operator[] (int index) const {
61  return links_[index];
62  }
63 
64  const std::vector<Link*>& links() const { return links_; }
65 
66  typedef container::iterator iterator;
67  typedef container::const_iterator const_iterator;
68 
69  iterator begin() { return links_.begin(); }
70  iterator end() { return links_.end(); }
71  const_iterator begin() const { return links_.begin(); }
72  const_iterator end() const { return links_.end(); }
73 
79  bool isDownward(int index) const {
80  return (index >= numUpwardConnections);
81  }
82 
83  void calcForwardKinematics(bool calcVelocity = false, bool calcAcceleration = false) const;
84 
85 protected:
86  std::vector<Link*> links_;
88 
89 private:
90  void traverse(Link* link, bool doUpward, bool doDownward, bool isUpward, Link* prev);
91  Link* findRootAdjacentLink(Link* link, Link* prev, Link* root, bool& isUpward);
92 };
93 
94 }
95 
96 #endif
cnoid::LinkTraverse::end
iterator end()
Definition: LinkTraverse.h:70
cnoid::LinkTraverse::begin
const_iterator begin() const
Definition: LinkTraverse.h:71
cnoid::LinkTraverse::container
std::vector< Link * > container
Definition: LinkTraverse.h:20
cnoid::LinkTraverse::numLinks
int numLinks() const
Definition: LinkTraverse.h:40
cnoid::LinkTraverse::link
Link * link(int index) const
Definition: LinkTraverse.h:56
cnoid::LinkTraverse::begin
iterator begin()
Definition: LinkTraverse.h:69
cnoid::LinkTraverse::rootLink
Link * rootLink() const
Definition: LinkTraverse.h:52
cnoid::LinkTraverse::empty
bool empty() const
Definition: LinkTraverse.h:44
cnoid::LinkTraverse::end
const_iterator end() const
Definition: LinkTraverse.h:72
cnoid
Definition: AbstractSceneLoader.h:11
cnoid::LinkTraverse
Definition: LinkTraverse.h:17
cnoid::LinkTraverse::links
const std::vector< Link * > & links() const
Definition: LinkTraverse.h:64
cnoid::LinkTraverse::numUpwardConnections
int numUpwardConnections
Definition: LinkTraverse.h:87
cnoid::LinkTraverse::links_
std::vector< Link * > links_
Definition: LinkTraverse.h:86
cnoid::LinkTraverse::isDownward
bool isDownward(int index) const
Definition: LinkTraverse.h:79
cnoid::LinkTraverse::const_iterator
container::const_iterator const_iterator
Definition: LinkTraverse.h:67
cnoid::LinkTraverse::size
std::size_t size() const
Definition: LinkTraverse.h:48
cnoid::LinkTraverse::iterator
container::iterator iterator
Definition: LinkTraverse.h:66