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);
79 void RRTExt8::deinit()
81 this->delete_kd_nodes(this->kdroot_);
84 void RRTExt8::store_node(RRTNode n)
87 RRTNode *sn = &this->nodes().back();
88 this->store_node(sn, this->kdroot_, 0);
91 RRTNode *RRTExt8::nn(RRTNode &t)
93 RRTNode *n = &this->nodes().front();
95 this->nn(n, t, this->kdroot_, 0, d);
99 std::vector<RRTNode *> RRTExt8::nv(RRTNode &t)
101 std::vector<RRTNode *> nv;