@@ -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
0 commit comments