-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added array traits to support default point types. Documentation and examples updated. Map traits return type fix. Added SplitterMidpoint unit tests.
- Loading branch information
Showing
15 changed files
with
525 additions
and
254 deletions.
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
add_executable(kd_tree_minimal kd_tree_minimal.cpp) | ||
set_default_target_properties(kd_tree_minimal) | ||
target_link_libraries(kd_tree_minimal PUBLIC PicoTree::PicoTree) | ||
function(add_demo_executable TARGET_NAME) | ||
add_executable(${TARGET_NAME} ${TARGET_NAME}.cpp) | ||
set_default_target_properties(${TARGET_NAME}) | ||
target_link_libraries(${TARGET_NAME} PRIVATE pico_toolshed) | ||
endfunction() | ||
|
||
add_executable(kd_tree_traits kd_tree_traits.cpp) | ||
set_default_target_properties(kd_tree_traits) | ||
target_link_libraries(kd_tree_traits PUBLIC PicoTree::PicoTree) | ||
add_demo_executable(kd_tree_minimal) | ||
|
||
add_executable(kd_tree_search kd_tree_search.cpp) | ||
set_default_target_properties(kd_tree_search) | ||
target_link_libraries(kd_tree_search PUBLIC pico_toolshed) | ||
add_demo_executable(kd_tree_creation) | ||
|
||
add_demo_executable(kd_tree_search) | ||
|
||
add_demo_executable(kd_tree_dynamic_arrays) | ||
|
||
add_demo_executable(kd_tree_custom_point_type) | ||
|
||
add_demo_executable(kd_tree_custom_space_type) | ||
|
||
add_demo_executable(kd_tree_custom_search_visitor) |
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,79 @@ | ||
#include <iostream> | ||
#include <pico_tree/array_traits.hpp> | ||
#include <pico_tree/kd_tree.hpp> | ||
#include <pico_tree/vector_traits.hpp> | ||
|
||
// This application demonstrates how a KdTree can take its input point set. | ||
// Although all of the examples use an std::vector<> as the input for building a | ||
// KdTree, they will work with any of the inputs supported by this library | ||
// (e.g., Eigen::Matrix<>). | ||
|
||
template <typename Tree> | ||
void QueryTree(Tree const& tree) { | ||
float query[3] = {4.0f, 4.0f, 4.0f}; | ||
pico_tree::Neighbor<int, float> nn; | ||
tree.SearchNn(query, nn); | ||
|
||
std::cout << "Index closest point: " << nn.index << std::endl; | ||
} | ||
|
||
auto MakePointSet() { | ||
std::vector<std::array<float, 3>> points{ | ||
{0.0f, 1.0f, 2.0f}, {3.0f, 4.0f, 5.0f}}; | ||
|
||
return points; | ||
} | ||
|
||
// The KdTree takes the input by value. In this example, creating a KdTree | ||
// results in a copy of the input point set. | ||
void BuildKdTreeWithCopy() { | ||
int max_leaf_size = 12; | ||
auto points = MakePointSet(); | ||
|
||
pico_tree::KdTree<std::vector<std::array<float, 3>>> tree( | ||
points, max_leaf_size); | ||
|
||
QueryTree(tree); | ||
} | ||
|
||
// The KdTree takes the input by value. In this example, the point sets are not | ||
// copied but moved into the KdTree. This prevents a copy. | ||
void BuildKdTreeWithMove() { | ||
int max_leaf_size = 12; | ||
auto points = MakePointSet(); | ||
|
||
pico_tree::KdTree<std::vector<std::array<float, 3>>> tree1( | ||
std::move(points), max_leaf_size); | ||
|
||
pico_tree::KdTree<std::vector<std::array<float, 3>>> tree2( | ||
MakePointSet(), max_leaf_size); | ||
|
||
QueryTree(tree1); | ||
QueryTree(tree2); | ||
} | ||
|
||
// The KdTree takes the input by value. In this example, the input is taken by | ||
// reference. This prevents a copy. | ||
void BuildKdTreeWithReference() { | ||
int max_leaf_size = 12; | ||
auto points = MakePointSet(); | ||
|
||
// By reference. | ||
pico_tree::KdTree<std::reference_wrapper<std::vector<std::array<float, 3>>>> | ||
tree1(points, max_leaf_size); | ||
|
||
// By const reference. | ||
pico_tree::KdTree< | ||
std::reference_wrapper<std::vector<std::array<float, 3>> const>> | ||
tree2(points, max_leaf_size); | ||
|
||
QueryTree(tree1); | ||
QueryTree(tree2); | ||
} | ||
|
||
int main() { | ||
BuildKdTreeWithReference(); | ||
BuildKdTreeWithMove(); | ||
BuildKdTreeWithCopy(); | ||
return 0; | ||
} |
Oops, something went wrong.