Tree.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * Copyright (C) 2011-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5 *
6 * ArmarX is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * ArmarX is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 *
18 * @package RobotComponents
19 * @author Raphael Grimm ( raphael dot grimm at kit dot edu )
20 * @date 2015
21 * @copyright http://www.gnu.org/licenses/gpl.txt
22 * GNU General Public License
23 */
24#pragma once
25
26#include <deque>
27#include <vector>
28
30
31#include <RobotComponents/interface/components/MotionPlanning/Tasks/RRTConnect/DataStructures.h>
32
33namespace armarx::rrtconnect
34{
35 struct NodeType
36 {
37 using ConfigType = VectorXf;
38
40 {
41 }
42
44 NodeId parent;
45 };
46
47 class Tree
48 {
49 public:
50 using ConfigType = VectorXf;
51
52 Tree() : nodes(1)
53 {
54 }
55
56 Tree(std::size_t maximalWorkerCount) : nodes(maximalWorkerCount)
57 {
58 }
59
60 /**
61 * @brief Sets the maximal worker count to the given value.
62 * This value has to be set before the tree's useage. and should never be set twice.
63 * @param count The new count.
64 */
65 void
66 setMaximalWorkerCount(std::size_t count)
67 {
68 nodes.resize(count);
69 }
70
71 void setRoot(const ConfigType& root);
72
73 const std::deque<std::deque<NodeType>>&
74 getNodes() const
75 {
76 return nodes;
77 }
78
79 std::vector<ConfigType> getReversedPathTo(NodeId nodeId) const;
80 std::vector<ConfigType> getPathTo(const NodeId& nodeId) const;
81
82 const NodeType&
83 getNode(const NodeId& nodeId) const
84 {
85 ARMARX_CHECK_EXPRESSION(static_cast<std::size_t>(nodeId.workerId) < nodes.size());
86 ARMARX_CHECK_EXPRESSION(static_cast<std::size_t>(nodeId.nodeSubId) <
87 nodes.at(nodeId.workerId).size());
88 return nodes.at(nodeId.workerId).at(nodeId.nodeSubId);
89 }
90
91 void
92 addNode(const ConfigType& cfg, const NodeId& parent, std::size_t workerId)
93 {
94 ARMARX_CHECK_EXPRESSION(workerId < nodes.size());
95 nodes.at(workerId).emplace_back(cfg, parent);
96 ++size;
97 }
98
99 NodeId getNearestNeighbour(const ConfigType& cfg);
100
101 std::size_t
102 getSize() const
103 {
104 return size;
105 }
106
107 void
108 applyUpdate(const PerTreeUpdate& u, Ice::Long workerId)
109 {
110 for (const auto& n : u.nodes)
111 {
112 addNode(n.config, n.parent, workerId);
113 }
114 }
115
116 private:
117 static const NodeId ROOT_NODE_ID;
118 std::deque<std::deque<NodeType>> nodes;
119 std::size_t size = 0;
120 };
121} // namespace armarx::rrtconnect
void setMaximalWorkerCount(std::size_t count)
Sets the maximal worker count to the given value.
Definition Tree.h:66
std::size_t getSize() const
Definition Tree.h:102
NodeId getNearestNeighbour(const ConfigType &cfg)
Definition Tree.cpp:73
VectorXf ConfigType
Definition Tree.h:50
const NodeType & getNode(const NodeId &nodeId) const
Definition Tree.h:83
std::vector< ConfigType > getPathTo(const NodeId &nodeId) const
std::vector< ConfigType > getReversedPathTo(NodeId nodeId) const
Definition Tree.cpp:51
const std::deque< std::deque< NodeType > > & getNodes() const
Definition Tree.h:74
Tree(std::size_t maximalWorkerCount)
Definition Tree.h:56
void addNode(const ConfigType &cfg, const NodeId &parent, std::size_t workerId)
Definition Tree.h:92
void setRoot(const ConfigType &root)
Definition Tree.cpp:37
void applyUpdate(const PerTreeUpdate &u, Ice::Long workerId)
Definition Tree.h:108
#define ARMARX_CHECK_EXPRESSION(expression)
This macro evaluates the expression and if it turns out to be false it will throw an ExpressionExcept...
NodeType(ConfigType cfg, NodeId parent)
Definition Tree.h:39