-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tile helper functions #145
Open
CCInc
wants to merge
15
commits into
main
Choose a base branch
from
helpers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+165
−5
Open
Changes from 9 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
03e3690
Small static library fixes
CCInc cfcbb95
Add voxelkey Span helper function
CCInc 3b5f796
Add more Span helpers
CCInc 0597393
Add tile helpers
CCInc 7b21c8d
Merge remote-tracking branch 'origin/static-lib-fixes' into helpers
CCInc c657f76
Update
CCInc 34da76c
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 2f2aae7
Fix compilation
CCInc 0837e46
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] f7825fc
Add check for non-finite x/y/z values when packing
CCInc c5f9a36
Add check for setting non-finite x/y/z values to points
CCInc 320dec2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 83e5c81
have GetNearestDepth return int
CCInc 4d2e997
Merge branch 'helpers' of github.com:RockRobotic/copc-lib into helpers
CCInc 302acdb
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#ifndef CPP_INCLUDE_COPC_LIB_GEOMETRY_HELPERS | ||
#define CPP_INCLUDE_COPC_LIB_GEOMETRY_HELPERS | ||
|
||
#include <cmath> | ||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace copc | ||
{ | ||
|
||
namespace las | ||
{ | ||
class LasHeader; | ||
} | ||
class Box; | ||
|
||
enum RoundStrategy | ||
{ | ||
NEAREST, | ||
PREFER_LARGER_TILE, | ||
PREFER_SMALLER_TILE | ||
}; | ||
|
||
// Returns the nearest depth to the requested tile size | ||
const double GetNearestDepth(double tile_size, const las::LasHeader &header, | ||
RoundStrategy rounding = RoundStrategy::NEAREST); | ||
|
||
const std::vector<copc::Box> GetPossibleTilesAtDepth(int32_t target_depth, const las::LasHeader &header); | ||
const std::vector<copc::Box> GetPossibleTilesWithSize(double target_tile_size, const las::LasHeader &header); | ||
|
||
} // namespace copc | ||
|
||
#endif /* CPP_INCLUDE_COPC_LIB_GEOMETRY_HELPERS */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
#include "copc-lib/geometry/helpers.hpp" | ||
#include "copc-lib/hierarchy/key.hpp" | ||
#include "copc-lib/las/header.hpp" | ||
|
||
#include <limits> | ||
|
||
namespace copc | ||
{ | ||
|
||
const double GetNearestDepth(double tile_size, const las::LasHeader &header, RoundStrategy rounding) | ||
{ | ||
double depth = std::log2(header.Span() / tile_size); | ||
int nearest_depth; | ||
if (rounding == RoundStrategy::NEAREST) | ||
nearest_depth = std::lround(depth); | ||
else if (rounding == RoundStrategy::PREFER_LARGER_TILE) | ||
nearest_depth = (int)std::floor(depth); | ||
else if (rounding == RoundStrategy::PREFER_SMALLER_TILE) | ||
nearest_depth = (int)std::ceil(depth); | ||
return std::max(0, nearest_depth); | ||
} | ||
|
||
// Generates a vector of Boxes that tile the dataset in its entirety | ||
// Note that points in the same node may fall within different tiles, | ||
// due to rounding | ||
// Additionally, some boxes may contain no points at all, since | ||
// we cannot know for certain whether a tile has points without actually loading it | ||
const std::vector<copc::Box> GetPossibleTilesAtDepth(int32_t target_depth, const las::LasHeader &header) | ||
{ | ||
std::vector<copc::Box> possible_tiles; | ||
|
||
// We can compute the maximum VoxelKey coordinate based on the depth | ||
int max_possible_coord = std::pow(2, target_depth); | ||
// But then, we can limit the search space in each dimension, | ||
// since not every dimension will use the full span | ||
// (since the span is based on the axis with the largest range) | ||
double tile_size = header.Span() / max_possible_coord; | ||
int max_x_coord = (int)std::ceil((header.max.x - header.min.x) / tile_size); | ||
int max_y_coord = (int)std::ceil((header.max.y - header.min.y) / tile_size); | ||
int max_z_coord = (int)std::ceil((header.max.z - header.min.z) / tile_size); | ||
|
||
for (int x = 0; x < max_x_coord; x++) | ||
for (int y = 0; y < max_y_coord; y++) | ||
for (int z = 0; z < max_z_coord; z++) | ||
{ | ||
auto box = copc::Box(copc::VoxelKey(target_depth, x, y, z), header); | ||
// To avoid the same point falling into two boxes when the point's coordinates | ||
// are the exact same as the box's limit, | ||
// we offset the minimum coordinate in each dimension by the smallest possible | ||
// floating point value so that two neighboring boxes don't have the exact same max and min | ||
// but, don't do that to the first coordinate in each dimension since there's no other box | ||
// for that point to fall in | ||
if (x != 0) | ||
box.x_min = std::nextafter(box.x_min, std::numeric_limits<double>::max()); | ||
if (y != 0) | ||
box.y_min = std::nextafter(box.y_min, std::numeric_limits<double>::max()); | ||
if (z != 0) | ||
box.z_min = std::nextafter(box.z_min, std::numeric_limits<double>::max()); | ||
possible_tiles.push_back(box); | ||
} | ||
return possible_tiles; | ||
} | ||
|
||
const std::vector<copc::Box> GetPossibleTilesWithSize(double target_tile_size, const las::LasHeader &header) | ||
leo-stan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
std::vector<copc::Box> possible_tiles; | ||
|
||
int max_num_tiles = header.Span() / target_tile_size; | ||
|
||
for (int x = 0; x < max_num_tiles; x++) | ||
for (int y = 0; y < max_num_tiles; y++) | ||
for (int z = 0; z < max_num_tiles; z++) | ||
{ | ||
double x_min = target_tile_size * x + header.min.x; | ||
double y_min = target_tile_size * y + header.min.y; | ||
double z_min = target_tile_size * z + header.min.z; | ||
double x_max = x_min + target_tile_size; | ||
double y_max = y_min + target_tile_size; | ||
double z_max = z_min + target_tile_size; | ||
auto box = copc::Box(x_min, y_min, z_min, x_max, y_max, z_max); | ||
// To avoid the same point falling into two boxes when the point's coordinates | ||
// are the exact same as the box's limit, | ||
// we offset the minimum coordinate in each dimension by the smallest possible | ||
// floating point value so that two neighboring boxes don't have the exact same max and min | ||
// but, don't do that to the first coordinate in each dimension since there's no other box | ||
// for that point to fall in | ||
if (x != 0) | ||
box.x_min = std::nextafter(box.x_min, std::numeric_limits<double>::max()); | ||
if (y != 0) | ||
box.y_min = std::nextafter(box.y_min, std::numeric_limits<double>::max()); | ||
if (z != 0) | ||
box.z_min = std::nextafter(box.z_min, std::numeric_limits<double>::max()); | ||
possible_tiles.push_back(box); | ||
} | ||
return possible_tiles; | ||
} | ||
|
||
} // namespace copc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some tests for these shiny new functions? 🙃