tree.hpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef KDL_TREE_HPP
00023 #define KDL_TREE_HPP
00024
00025 #include "segment.hpp"
00026 #include "chain.hpp"
00027
00028 #include <string>
00029 #include <map>
00030
00031 namespace KDL
00032 {
00033
00034 class TreeElement;
00035 typedef std::map<std::string,TreeElement> SegmentMap;
00036
00037 class TreeElement
00038 {
00039 private:
00040 TreeElement(const std::string& name):segment(name), q_nr(0)
00041 {};
00042 public:
00043 Segment segment;
00044 unsigned int q_nr;
00045 SegmentMap::const_iterator parent;
00046 std::vector<SegmentMap::const_iterator > children;
00047 TreeElement(const Segment& segment_in,const SegmentMap::const_iterator& parent_in,unsigned int q_nr_in)
00048 {
00049 q_nr=q_nr_in;
00050 segment=segment_in;
00051 parent=parent_in;
00052 };
00053 static TreeElement Root(const std::string& root_name)
00054 {
00055 return TreeElement(root_name);
00056 };
00057 };
00058
00065 class Tree
00066 {
00067 private:
00068 SegmentMap segments;
00069 int nrOfJoints;
00070 int nrOfSegments;
00071
00072 std::string root_name;
00073
00074 bool addTreeRecursive(SegmentMap::const_iterator root, const std::string& hook_name);
00075
00076 public:
00080 Tree(const std::string& root_name="root");
00081 Tree(const Tree& in);
00082 Tree& operator= (const Tree& arg);
00083
00094 bool addSegment(const Segment& segment, const std::string& hook_name);
00095
00105 bool addChain(const Chain& chain, const std::string& hook_name);
00106
00116 bool addTree(const Tree& tree, const std::string& hook_name);
00117
00126 unsigned int getNrOfJoints()const
00127 {
00128 return nrOfJoints;
00129 };
00130
00135 unsigned int getNrOfSegments()const {return nrOfSegments;};
00136
00144 SegmentMap::const_iterator getSegment(const std::string& segment_name)const
00145 {
00146 return segments.find(segment_name);
00147 };
00153 SegmentMap::const_iterator getRootSegment()const
00154 {
00155 return segments.find(root_name);
00156 };
00157
00167 bool getChain(const std::string& chain_root, const std::string& chain_tip, Chain& chain)const;
00168
00169
00170 const SegmentMap& getSegments()const
00171 {
00172 return segments;
00173 }
00174
00175 virtual ~Tree(){};
00176
00177 };
00178 }
00179 #endif
00180
00181
00182
00183
00184