Skip to content

Instantly share code, notes, and snippets.

@H2CO3
Created February 29, 2016 22:20
Show Gist options
  • Save H2CO3/ef11bede0f7a8ec9bfb7 to your computer and use it in GitHub Desktop.
Save H2CO3/ef11bede0f7a8ec9bfb7 to your computer and use it in GitHub Desktop.
// cloud must be sorted beforehand
size_t num_rows = 10;
size_t num_cols = 10;
size_t min_x = … // find from cloud
size_t max_x = … // find from cloud
size_t dx = (max_x - min_x) / num_rows;
size_t min_y = … // find from cloud
size_t max_y = … // find from cloud
size_t dy = (max_y - min_y) / num_cols;
vector<vector<Point>> rows(num_rows);
for (size_t i = 0, row = 0; i < cloud.size(); i++) {
if (cloud.points[i].x > min_x + row * dx) {
row++;
}
rows[row].push_back(cloud.points[i]);
}
vector<vector<vector<Point>>> table(rows.size());
for (size_t row = 0; row < rows.size(); row++) {
table[row] = vector<vector<Point>>(num_cols);
for (size_t j = 0, col = 0; j < rows[row].size(); j++) {
if (rows[row][j].y > min_y + col * dy) {
col++;
}
table[row][col].push_back(rows[row][j]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment