3 RRTExt8::KdNode::KdNode(RRTNode *n)
10 void RRTExt8::delete_kd_nodes(KdNode *n)
14 if (n->left() != nullptr)
15 delete_kd_nodes(n->left());
16 if (n->right() != nullptr)
17 delete_kd_nodes(n->right());
21 void RRTExt8::store_node(RRTNode *n, KdNode *&r, int l)
25 else if (l % 3 == 0 && n->x() < r->node()->x())
26 store_node(n, r->left(), l + 1);
28 store_node(n, r->right(), l + 1);
29 else if (l % 3 == 1 && n->y() < r->node()->y())
30 store_node(n, r->left(), l + 1);
32 store_node(n, r->right(), l + 1);
33 else if (l % 3 == 0 && n->h() < r->node()->h())
34 store_node(n, r->left(), l + 1);
36 store_node(n, r->right(), l + 1);
39 void RRTExt8::nn(RRTNode *&n, RRTNode &t, KdNode *r, int l, double &d)
43 if (this->cost_search(*r->node(), t) < d) {
45 d = this->cost_search(*r->node(), t);
47 if (l % 3 == 0 && t.x() < r->node()->x()) {
48 nn(n, t, r->left(), l + 1, d);
49 if (r->node()->x() - t.x() < d)
50 nn(n, t, r->right(), l + 1, d);
51 } else if (l % 3 == 0) {
52 nn(n, t, r->right(), l + 1, d);
53 if (t.x() - r->node()->x() < d)
54 nn(n, t, r->left(), l + 1, d);
55 } else if (l % 3 == 1 && t.y() < r->node()->y()) {
56 nn(n, t, r->left(), l + 1, d);
57 if (r->node()->y() - t.y() < d)
58 nn(n, t, r->right(), l + 1, d);
59 } else if (l % 3 == 1) {
60 nn(n, t, r->right(), l + 1, d);
61 if (t.y() - r->node()->y() < d)
62 nn(n, t, r->left(), l + 1, d);
63 } else if (l % 3 == 2 && t.h() < r->node()->h()) {
64 nn(n, t, r->left(), l + 1, d);
65 if (r->node()->h() - t.h() < d)
66 nn(n, t, r->right(), l + 1, d);
68 nn(n, t, r->right(), l + 1, d);
69 if (t.h() - r->node()->h() < d)
70 nn(n, t, r->left(), l + 1, d);
75 std::vector<RRTNode*>& n,
84 if (this->cost_search(*r->node(), t) < d) {
85 n.push_back(r->node());
87 if (l % 3 == 0 && t.x() < r->node()->x()) {
88 this->nv(n, t, r->left(), l + 1, d);
89 if (r->node()->x() - t.x() < d)
90 this->nv(n, t, r->right(), l + 1, d);
91 } else if (l % 3 == 0) {
92 this->nv(n, t, r->right(), l + 1, d);
93 if (t.x() - r->node()->x() < d)
94 this->nv(n, t, r->left(), l + 1, d);
95 } else if (l % 3 == 1 && t.y() < r->node()->y()) {
96 this->nv(n, t, r->left(), l + 1, d);
97 if (r->node()->y() - t.y() < d)
98 this->nv(n, t, r->right(), l + 1, d);
99 } else if (l % 3 == 1) {
100 this->nv(n, t, r->right(), l + 1, d);
101 if (t.y() - r->node()->y() < d)
102 this->nv(n, t, r->left(), l + 1, d);
103 } else if (l % 3 == 2 && t.h() < r->node()->h()) {
104 this->nv(n, t, r->left(), l + 1, d);
105 if (r->node()->h() - t.h() < d)
106 this->nv(n, t, r->right(), l + 1, d);
108 this->nv(n, t, r->right(), l + 1, d);
109 if (t.h() - r->node()->h() < d)
110 this->nv(n, t, r->left(), l + 1, d);
119 void RRTExt8::deinit()
121 this->delete_kd_nodes(this->kdroot_);
124 void RRTExt8::store_node(RRTNode n)
127 RRTNode *sn = &this->nodes().back();
128 this->store_node(sn, this->kdroot_, 0);
131 RRTNode *RRTExt8::nn(RRTNode &t)
133 RRTNode *n = &this->nodes().front();
135 this->nn(n, t, this->kdroot_, 0, d);
139 std::vector<RRTNode *> RRTExt8::nv(RRTNode &t)
141 double cost = std::min(GAMMA(this->nodes().size()), 0.2);
142 std::vector<RRTNode *> n;
143 this->nv(n, t, this->kdroot_, 0, cost);