2 * SPDX-FileCopyrightText: 2021 Jiri Vlasak <jiri.vlasak.2@cvut.cz>
4 * SPDX-License-Identifier: GPL-3.0-only
9 void RRTExt4::Cell::nn(RRTNode *t, RRTNode **nn, RRTS *p)
11 double cost = p->cost_search(**nn, *t);
12 for (auto f: this->nodes()) {
13 if (p->cost_search(*f, *t) < cost) {
15 cost = p->cost_search(*f, *t);
20 void RRTExt4::Cell::store_node(RRTNode *n)
22 this->nodes_.push_back(n);
23 this->changed_ = true;
30 unsigned int RRTExt4::xi(RRTNode n)
32 if (n.x() >= this->x_max_)
33 return GRID_MAX_XI - 1;
34 if (n.x() <= this->x_min_)
36 return (unsigned int) (floor(n.x() - this->x_min_) / GRID);
39 unsigned int RRTExt4::yi(RRTNode n)
41 if (n.y() > this->y_max_)
42 return GRID_MAX_YI - 1;
43 if (n.y() <= this->y_min_)
45 return (unsigned int) (floor(n.y() - this->y_min_) / GRID);
51 this->x_min_ = this->nodes().back().x() - GRID_WIDTH / 2;
52 this->x_max_ = this->nodes().back().x() + GRID_WIDTH / 2;
53 this->y_min_ = this->nodes().back().y() - GRID_HEIGHT / 2;
54 this->y_max_ = this->nodes().back().y() + GRID_HEIGHT / 2;
57 void RRTExt4::deinit()
59 for (unsigned int i = 0; i < GRID_MAX_XI; i++)
60 for (unsigned int j = 0; j < GRID_MAX_YI; j++)
61 this->grid_[i][j].nodes().clear();
64 void RRTExt4::store_node(RRTNode n)
67 RRTNode *sn = &this->nodes().back();
68 this->grid_[this->xi(n)][this->yi(n)].store_node(sn);
71 RRTNode *RRTExt4::nn(RRTNode &t)
73 RRTNode *nn = &this->nodes().front();
74 unsigned int txi = this->xi(t);
75 unsigned int tyi = this->yi(t);
77 while (this->cost_search(*nn, t) > l * GRID) {
82 if (xi_max > GRID_MAX_XI - 1)
83 xi_max = GRID_MAX_XI - 1;
88 if (yi_max > GRID_MAX_YI - 1)
89 yi_max = GRID_MAX_YI - 1;
90 for (int xi = xi_min; xi <= xi_max; xi++) {
91 this->grid_[xi][yi_max].nn(&t, &nn, this);
93 for (int xi = xi_min; xi <= xi_max; xi++) {
94 this->grid_[xi][yi_min].nn(&t, &nn, this);
96 for (int yi = yi_min + 1; yi <= yi_max - 1; yi++) {
97 this->grid_[xi_min][yi].nn(&t, &nn, this);
99 for (int yi = yi_min + 1; yi <= yi_max - 1; yi++) {
100 this->grid_[xi_max][yi].nn(&t, &nn, this);
107 std::vector<RRTNode *> RRTExt4::nv(RRTNode &t)
109 std::vector<RRTNode *> nv;
110 unsigned int txi = this->xi(t);
111 unsigned int tyi = this->yi(t);
113 double cost = std::min(GAMMA(this->nodes().size()), ETA);
114 for (auto f: this->grid_[txi][tyi].nodes())
115 if (this->cost_search(*f, t) < cost)