Skip to content

Commit e0c78f5

Browse files
authored
Merge pull request #6 from leggedrobotics/fix/cell_indexing
fix cell indexing
2 parents 4cf7b3b + ee73d15 commit e0c78f5

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

elevation_mapping_cupy/script/custom_kernels.py

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ def map_utils(resolution, width, height, sensor_noise_factor, min_valid_distance
1313
1414
return max(min(x, max_x), min_x);
1515
}
16-
__device__ float16 round(float16 x) {
17-
return (int)x + (int)(2 * (x - (int)x));
16+
__device__ int get_x_idx(float16 x, float16 center) {
17+
int i = (x - center) / ${resolution} + 0.5 * ${width};
18+
return i;
1819
}
19-
__device__ int get_xy_idx(float16 x, float16 center) {
20-
const float resolution = ${resolution};
21-
int i = round((x - center) / resolution);
20+
__device__ int get_y_idx(float16 y, float16 center) {
21+
int i = (y - center) / ${resolution} + 0.5 * ${height};
2222
return i;
2323
}
2424
__device__ bool is_inside(int idx) {
@@ -33,8 +33,8 @@ def map_utils(resolution, width, height, sensor_noise_factor, min_valid_distance
3333
return true;
3434
}
3535
__device__ int get_idx(float16 x, float16 y, float16 center_x, float16 center_y) {
36-
int idx_x = clamp(get_xy_idx(x, center_x) + ${width} / 2, 0, ${width} - 1);
37-
int idx_y = clamp(get_xy_idx(y, center_y) + ${height} / 2, 0, ${height} - 1);
36+
int idx_x = clamp(get_x_idx(x, center_x), 0, ${width} - 1);
37+
int idx_y = clamp(get_y_idx(y, center_y), 0, ${height} - 1);
3838
return ${width} * idx_x + idx_y;
3939
}
4040
__device__ int get_map_idx(int idx, int layer_n) {
@@ -515,14 +515,21 @@ def polygon_mask_kernel(width, height, resolution):
515515
__device__ float16 round(float16 x) {
516516
return (int)x + (int)(2 * (x - (int)x));
517517
}
518-
__device__ int get_xy_idx(float16 x, float16 center) {
518+
__device__ int get_x_idx(float16 x, float16 center) {
519+
const float resolution = ${resolution};
520+
const float width = ${width};
521+
int i = (x - center) / resolution + 0.5 * width;
522+
return i;
523+
}
524+
__device__ int get_y_idx(float16 y, float16 center) {
519525
const float resolution = ${resolution};
520-
int i = round((x - center) / resolution);
526+
const float height = ${height};
527+
int i = (y - center) / resolution + 0.5 * height;
521528
return i;
522529
}
523530
__device__ int get_idx(float16 x, float16 y, float16 center_x, float16 center_y) {
524-
int idx_x = clamp(get_xy_idx(x, center_x) + ${width} / 2, 0, ${width} - 1);
525-
int idx_y = clamp(get_xy_idx(y, center_y) + ${height} / 2, 0, ${height} - 1);
531+
int idx_x = clamp(get_x_idx(x, center_x), 0, ${width} - 1);
532+
int idx_y = clamp(get_y_idx(y, center_y), 0, ${height} - 1);
526533
return ${width} * idx_x + idx_y;
527534
}
528535

elevation_mapping_cupy/src/elevation_mapping_wrapper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ void ElevationMappingWrapper::setParameters(ros::NodeHandle& nh) {
7777
resolution_ = py::cast<float>(param_.attr("get_value")("resolution"));
7878
map_length_ = py::cast<float>(param_.attr("get_value")("map_length"));
7979
map_n_ = static_cast<int>(round(map_length_ / resolution_));
80+
map_length_ = resolution_ * map_n_; // get true length after rounding
8081

8182
nh.param<bool>("enable_normal", enable_normal_, false);
8283
nh.param<bool>("enable_normal_color", enable_normal_color_, false);

0 commit comments

Comments
 (0)