Find the points within `radius` of a ray, ie, the vertical distance from the point to ray <= radius. Returns: list of list of list: b -> m -> n_idx Note: Our algorithm is very simple. In order to be parallelized on gpu easily, we want to every thread to have as few branching conditions (if/else) as possible. We will: - parallelize on ray - do the same thing for all rays. - ignore all points ou
| 801 | // 5. given grid idxs for each ray, gather point idxs |
| 802 | // |
| 803 | std::vector<llist> find_neighbor_points_of_rays( |
| 804 | torch::Tensor points, // (b, n, 3), float |
| 805 | torch::Tensor ray_origins, // (b, m, 3), float |
| 806 | torch::Tensor ray_directions, // (b, m, 3), float |
| 807 | torch::Tensor ray_radius, // (b,), float |
| 808 | torch::Tensor grid_size, // (b, 3), long |
| 809 | torch::Tensor grid_center, // (b, 3), float |
| 810 | torch::Tensor grid_width, // (b, 3), float |
| 811 | float t_min = 0., |
| 812 | float t_max = 1.e12, |
| 813 | std::string version = "v2" // v2 is faster |
| 814 | ) { |
| 815 | |
| 816 | assert(grid_size.dtype() == torch::kLong); |
| 817 | |
| 818 | auto batch_size = ray_origins.size(0); |
| 819 | auto n_points = points.size(1); |
| 820 | auto n_rays = ray_origins.size(1); |
| 821 | auto device = ray_origins.device(); |
| 822 | auto total_cells = torch::prod(grid_size, -1); // (b,) long |
| 823 | |
| 824 | // get grid idx of each point |
| 825 | auto start = high_resolution_clock::now(); |
| 826 | auto tmp_grid_out = get_grid_idx( |
| 827 | points, |
| 828 | grid_size, |
| 829 | grid_center, |
| 830 | grid_width, |
| 831 | "ind" |
| 832 | ); |
| 833 | torch::Tensor & grid_idxs = tmp_grid_out[0]; // (b, n), long [0, total_cells-1] |
| 834 | torch::Tensor & valid_mask = tmp_grid_out[1]; // (b, n), bool |
| 835 | auto stop = high_resolution_clock::now(); |
| 836 | auto duration = duration_cast<microseconds>(stop - start); |
| 837 | // std::cout<<"get_grid_idx: "<<duration.count()<<std::endl; |
| 838 | |
| 839 | |
| 840 | // gather points belonging to each cell |
| 841 | start = high_resolution_clock::now(); |
| 842 | std::vector<idxmap> all_cell2pidx = gather_points( |
| 843 | grid_idxs, // (b, n) |
| 844 | total_cells, // (b,) |
| 845 | valid_mask // (b, n) |
| 846 | ); // b -> gidx -> point_idxs |
| 847 | stop = high_resolution_clock::now(); |
| 848 | duration = duration_cast<microseconds>(stop - start); |
| 849 | // std::cout<<"gather points: "<<duration.count()<<std::endl; |
| 850 | |
| 851 | |
| 852 | // gather the cells intersected by the ray |
| 853 | start = high_resolution_clock::now(); |
| 854 | std::vector<idxmap> all_ray2gidxs; |
| 855 | if (version.compare("v1") == 0) { |
| 856 | all_ray2gidxs = std::move(grid_ray_intersection( |
| 857 | ray_origins, |
| 858 | ray_directions, |
| 859 | ray_radius, |
| 860 | grid_size, |
nothing calls this directly
no test coverage detected