8 mInflationMarkers = NULL;
10 mCachedDistances = NULL;
16 delete[] mInflationMarkers;
17 delete[] mCachedCosts;
18 delete[] mCachedDistances;
26 mCellInflationRadius = radius;
28 mCachedCosts =
new signed char*[mCellInflationRadius + 2];
29 mCachedDistances =
new double*[mCellInflationRadius + 2];
31 for(
unsigned int i = 0; i < mCellInflationRadius + 2; i++)
33 mCachedCosts[i] =
new signed char[mCellInflationRadius + 2];
34 mCachedDistances[i] =
new double[mCellInflationRadius + 2];
35 for(
unsigned int j = 0; j < mCellInflationRadius + 2; j++)
37 double d = sqrt(i*i + j*j);
38 mCachedDistances[i][j] = d;
39 d /= mCellInflationRadius;
41 mCachedCosts[i][j] = (1.0 - d) * mCostObstacle;
49 unsigned int dx = abs(mx - src_x);
50 unsigned int dy = abs(my - src_y);
51 if(dx > mCellInflationRadius + 1 || dy > mCellInflationRadius + 1)
53 ROS_ERROR(
"Error in distanceLookup! Asked for (%d, %d), but CellInflationRadius is %d!", dx, dy, mCellInflationRadius);
56 return mCachedDistances[dx][dy];
62 unsigned int dx = abs(mx - src_x);
63 unsigned int dy = abs(my - src_y);
64 if(dx > mCellInflationRadius + 1 || dy > mCellInflationRadius + 1)
66 ROS_ERROR(
"Error in costLookup! Asked for (%d, %d), but CellInflationRadius is %d!", dx, dy, mCellInflationRadius);
69 return mCachedCosts[dx][dy];
79 int mapSize = mGridMap->
getSize();
81 if(mInflationMarkers)
delete[] mInflationMarkers;
82 mInflationMarkers =
new unsigned char[mapSize];
83 for(
int i = 0; i < mapSize; i++)
85 mInflationMarkers[i] = 0;
89 while(!mInflationQueue.empty()) mInflationQueue.pop();
93 if(mGridMap->getData(
index) > 0)
96 mGridMap->getCoordinates(sx, sy,
index);
97 enqueueObstacle(
index, sx, sy);
98 }
else if(mGridMap->getData(
index) == -1)
100 mInflationMarkers[
index] = 1;
106 while(!mInflationQueue.empty())
108 CellData cell = mInflationQueue.top();
109 mInflationQueue.pop();
111 if(!mGridMap->getCoordinates(x, y, cell.
index))
continue;
113 enqueueObstacle(cell.
index-1, cell.
sx, cell.
sy);
114 if(x < mGridMap->getWidth() - 1)
115 enqueueObstacle(cell.
index+1, cell.
sx, cell.
sy);
117 enqueueObstacle(cell.
index-mGridMap->getWidth(), cell.
sx, cell.
sy);
118 if(y < mGridMap->getHeight() - 1)
119 enqueueObstacle(cell.
index+mGridMap->getWidth(), cell.
sx, cell.
sy);
123 ROS_DEBUG(
"Finished inflation. (%d cells)", count);
129 if(!mGridMap->getCoordinates(mx, my, index))
return;
130 if(mInflationMarkers[index] != 0)
return;
132 double distance = distanceLookup(mx, my, sx, sy);
134 ROS_INFO(
"Tried to add cell (%u, %u) -> (%u, %u) to inflation queue!", sx, sy, mx, my);
136 if(distance > mCellInflationRadius)
return;
138 CellData cell(distance, index, sx, sy);
139 mInflationQueue.push(cell);
140 mInflationMarkers[
index] = 1;
141 signed char value = costLookup(mx, my, sx, sy);
142 mGridMap->setData(index, value);
CellData(double d, double i, unsigned int sx, unsigned int sy)
TFSIMD_FORCE_INLINE const tfScalar & y() const
double distance(double x0, double y0, double x1, double y1)
TFSIMD_FORCE_INLINE const tfScalar & x() const