43 Expander(p_calc, nx, ny), pending_(NULL), precise_(false) {
49 priorityIncrement_ = 2 * neutral_cost_;
52 DijkstraExpansion::~DijkstraExpansion() {
63 void DijkstraExpansion::setSize(
int xs,
int ys) {
64 Expander::setSize(xs, ys);
68 pending_ =
new bool[ns_];
69 memset(pending_, 0, ns_ *
sizeof(
bool));
80 bool DijkstraExpansion::calculatePotentials(
unsigned char* costs,
double start_x,
double start_y,
double end_x,
double end_y,
81 int cycles,
float* potential) {
84 threshold_ = lethal_cost_;
85 currentBuffer_ = buffer1_;
87 nextBuffer_ = buffer2_;
89 overBuffer_ = buffer3_;
91 memset(pending_, 0, ns_ *
sizeof(
bool));
92 std::fill(potential, potential + ns_,
POT_HIGH);
95 int k = toIndex(start_x, start_y);
99 double dx = start_x - (int)start_x, dy = start_y - (
int)start_y;
100 dx = floorf(dx * 100 + 0.5) / 100;
101 dy = floorf(dy * 100 + 0.5) / 100;
102 potential[k] = neutral_cost_ * 2 * dx * dy;
103 potential[k+1] = neutral_cost_ * 2 * (1-dx)*dy;
104 potential[k+nx_] = neutral_cost_*2*dx*(1-dy);
105 potential[k+nx_+1] = neutral_cost_*2*(1-dx)*(1-dy);
129 int startCell = toIndex(end_x, end_y);
131 for (; cycle < cycles; cycle++)
134 if (currentEnd_ == 0 && nextEnd_ == 0)
139 if (currentEnd_ > nwv)
143 int *pb = currentBuffer_;
146 pending_[*(pb++)] =
false;
152 updateCell(costs, potential, *pb++);
155 currentEnd_ = nextEnd_;
158 currentBuffer_ = nextBuffer_;
162 if (currentEnd_ == 0) {
163 threshold_ += priorityIncrement_;
164 currentEnd_ = overEnd_;
167 currentBuffer_ = overBuffer_;
172 if (potential[startCell] <
POT_HIGH)
190 #define INVSQRT2 0.707106781
192 inline void DijkstraExpansion::updateCell(
unsigned char* costs,
float* potential,
int n) {
196 float c = getCost(costs, n);
197 if (c >= lethal_cost_)
200 float pot = p_calc_->calculatePotential(potential, c, n);
203 if (pot < potential[n]) {
204 float le =
INVSQRT2 * (float)getCost(costs, n - 1);
205 float re =
INVSQRT2 * (float)getCost(costs, n + 1);
206 float ue =
INVSQRT2 * (float)getCost(costs, n - nx_);
207 float de =
INVSQRT2 * (float)getCost(costs, n + nx_);
210 if (pot < threshold_)
212 if (potential[n - 1] > pot + le)
214 if (potential[n + 1] > pot + re)
216 if (potential[n - nx_] > pot + ue)
218 if (potential[n + nx_] > pot + de)
222 if (potential[n - 1] > pot + le)
224 if (potential[n + 1] > pot + re)
226 if (potential[n - nx_] > pot + ue)
228 if (potential[n + nx_] > pot + de)