MCPcopy Create free account
hub / github.com/KumarRobotics/sloam / _doProjection

Method _doProjection

sloam/src/segmentation/inference.cpp:80–165  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

78}
79
80std::vector<std::vector<float>> Segmentation::_doProjection(const std::vector<float>& scan, const uint32_t& num_points){
81
82 // std::vector<float> invalid_input = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f};
83 std::vector<float> invalid_input = {0.0f};
84
85 std::vector<float> ranges;
86 std::vector<float> xs;
87 std::vector<float> ys;
88 std::vector<float> zs;
89 std::vector<float> intensitys;
90
91 std::vector<float> proj_xs_tmp;
92 std::vector<float> proj_ys_tmp;
93
94 for (uint32_t i = 0; i < num_points; i++) {
95 float x = scan[4 * i];
96 float y = scan[4 * i + 1];
97 float z = scan[4 * i + 2];
98 float intensity = scan[4 * i + 3];
99 float range = std::sqrt(x*x+y*y+z*z);
100 ranges.push_back(range);
101 xs.push_back(x);
102 ys.push_back(y);
103 zs.push_back(z);
104 intensitys.push_back(intensity);
105
106 // get angles
107 float yaw = -std::atan2(y, x);
108 float pitch = std::asin(z / range);
109
110 // get projections in image coords
111 float proj_x = 0.5 * (yaw / M_PI + 1.0); // in [0.0, 1.0]
112 float proj_y = 1.0 - (pitch + std::abs(_fov_down)) / _fov; // in [0.0, 1.0]
113
114 // scale to image size using angular resolution
115 proj_x *= _img_w; // in [0.0, W]
116 proj_y *= _img_h; // in [0.0, H]
117
118 // round and clamp for use as index
119 proj_x = std::floor(proj_x);
120 proj_x = std::min(_img_w - 1.0f, proj_x);
121 proj_x = std::max(0.0f, proj_x); // in [0,W-1]
122 proj_xs_tmp.push_back(proj_x);
123
124 proj_y = std::floor(proj_y);
125 proj_y = std::min(_img_h - 1.0f, proj_y);
126 proj_y = std::max(0.0f, proj_y); // in [0,H-1]
127 proj_ys_tmp.push_back(proj_y);
128 }
129
130 // stope a copy in original order
131 proj_xs = proj_xs_tmp;
132 proj_ys = proj_ys_tmp;
133
134 // order in decreasing depth
135 std::vector<size_t> orders = sort_indexes(ranges);
136 std::vector<float> sorted_proj_xs;
137 sorted_proj_xs.reserve(num_points);

Callers

nothing calls this directly

Calls 1

sort_indexesFunction · 0.85

Tested by

no test coverage detected