-
Notifications
You must be signed in to change notification settings - Fork 39
Parallel CPU LBVH Implementation #188
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
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
7d128ab
Add Linear Bounding Volume Hierarchy (LBVH) implementation and profil…
zfergus ed41da8
Enhance profiler functionality and integrate into LBVH and BVH implem…
zfergus c0c67dc
Fix Linux and Window build
zfergus b986930
Fix 2D case
zfergus 1bb9f8e
Refactor Morton code functions to support 2D points and improve bit e…
zfergus 44203bc
Add concurrent queue for parallel candidate detection in LBVH
zfergus 9f43de0
Merge branch 'main' into lbvh
zfergus aa1c1ce
Merge branch 'main' into lbvh
zfergus acffc2b
Update Python version matrix to include 3.14 for pull requests
zfergus 1fa4de6
Fix clang-tidy errors
zfergus b2b4f39
Address copilot comments
zfergus ad5039f
Refactor LBVH Node Structure and Add SIMD Traversal
zfergus d9ae2da
Fix test LBVH::build
zfergus 4b173cf
Fix LBVH in 2D
zfergus 0cf9fea
Enhance profiler functionality with CSV output and improve code struc…
zfergus ad44e09
Use 1ULL for bit-shift constants in Morton functions
zfergus d150477
Resolve Copilot comments
zfergus 9e75039
Resolve compiler warnings on linux
zfergus b0dec30
Put inf inside lambda in aabb.cpp
zfergus b72f570
Refactor Puffer-Ball test cases to use accessible mesh paths and upda…
zfergus b906cf4
Refactor AABB to use a fixed size Array3d
zfergus 9a61fc4
Fix edges in examples/profiler.py
zfergus 5f2cd23
Fix GH Action errors
zfergus ce61a18
Update LBVH documentation
zfergus 213467a
Update profile.py
zfergus 6872f95
Update benchmark test case descriptions
zfergus 91ff457
Deprecate BVH and optimize LBVH and merges
zfergus 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,26 @@ | ||
| # pybind11_json (https://github.com/pybind/pybind11_json) | ||
| # License: MIT | ||
| if(TARGET pybind11::json) | ||
| return() | ||
| endif() | ||
|
|
||
| message(STATUS "Third-party: creating target 'pybind11::json'") | ||
|
|
||
| include(CPM) | ||
| CPMAddPackage( | ||
| URI "gh:pybind/pybind11_json#0.2.15" | ||
| DOWNLOAD_ONLY YES | ||
| ) | ||
|
|
||
| add_library(pybind11_json INTERFACE) | ||
| add_library(pybind11::json ALIAS pybind11_json) | ||
|
|
||
| target_include_directories(pybind11_json INTERFACE | ||
| "$<BUILD_INTERFACE:${pybind11_json_SOURCE_DIR}/include>" | ||
| ) | ||
|
|
||
| include(pybind11) | ||
| target_link_libraries(pybind11_json INTERFACE pybind11::pybind11) | ||
|
|
||
| include(json) | ||
| target_link_libraries(pybind11_json INTERFACE nlohmann_json::nlohmann_json) |
This file contains hidden or 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,85 @@ | ||
| from find_ipctk import ipctk | ||
| import meshio | ||
| import polyscope as ps | ||
| from polyscope import imgui | ||
| import numpy as np | ||
|
|
||
| import pathlib | ||
|
|
||
| import argparse | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--mesh", | ||
| type=pathlib.Path, | ||
| default=(pathlib.Path(__file__).parents[2] / "tests/data/puffer-ball/20.ply")) | ||
| args = parser.parse_args() | ||
|
|
||
| mesh = meshio.read(args.mesh) | ||
|
|
||
| lbvh = ipctk.LBVH() | ||
| lbvh.build(mesh.points, np.array([], dtype=int), mesh.cells_dict["triangle"]) | ||
|
|
||
| ps.init() | ||
|
|
||
| ps.set_give_focus_on_show(True) | ||
|
|
||
| ps_mesh = ps.register_surface_mesh( | ||
| "mesh", | ||
| mesh.points, | ||
| mesh.cells_dict["triangle"] | ||
| ) | ||
|
|
||
| nodes = lbvh.face_nodes | ||
|
|
||
|
|
||
| def traverse_lbvh(node, max_depth): | ||
| if node.is_inner and max_depth > 0: | ||
| V_left, E_left = traverse_lbvh(nodes[node.left], max_depth - 1) | ||
| V_right, E_right = traverse_lbvh(nodes[node.right], max_depth - 1) | ||
| return np.vstack([V_left, V_right]), np.vstack([E_left, E_right + V_left.shape[0]]) | ||
|
|
||
| E = np.array([ | ||
| [0, 1], | ||
| [0, 2], | ||
| [0, 3], | ||
| [1, 5], | ||
| [1, 4], | ||
| [2, 4], | ||
| [2, 6], | ||
| [3, 5], | ||
| [3, 6], | ||
| [7, 4], | ||
| [7, 5], | ||
| [7, 6], | ||
| ]) | ||
| V = np.array([ | ||
| node.aabb_min, | ||
| [node.aabb_min[0], node.aabb_min[1], node.aabb_max[2]], | ||
| [node.aabb_min[0], node.aabb_max[1], node.aabb_min[2]], | ||
| [node.aabb_max[0], node.aabb_min[1], node.aabb_min[2]], | ||
| [node.aabb_min[0], node.aabb_max[1], node.aabb_max[2]], | ||
| [node.aabb_max[0], node.aabb_min[1], node.aabb_max[2]], | ||
| [node.aabb_max[0], node.aabb_max[1], node.aabb_min[2]], | ||
| node.aabb_max | ||
| ]) | ||
| return V, E | ||
|
|
||
|
|
||
| max_depth = 0 | ||
| bvh_nodes, bvh_edges = traverse_lbvh(nodes[0], max_depth=max_depth) | ||
|
|
||
| ps.register_curve_network("bvh", bvh_nodes, bvh_edges) | ||
|
|
||
|
|
||
| def foo(): | ||
| global max_depth | ||
| changed, max_depth = imgui.SliderInt("max depth", max_depth, 0, 20) | ||
| if changed: | ||
| bvh_nodes, bvh_edges = traverse_lbvh(nodes[0], max_depth=max_depth) | ||
| ps.register_curve_network("bvh", bvh_nodes, bvh_edges) | ||
|
|
||
|
|
||
| ps.set_user_callback(foo) | ||
|
|
||
| ps.show() |
This file contains hidden or 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,81 @@ | ||
| import pandas as pd | ||
| import plotly.express as px | ||
| import pathlib | ||
| from io import StringIO | ||
|
|
||
| from find_ipctk import ipctk | ||
|
|
||
| def plot_profiler(title=None): | ||
| df = pd.read_csv(StringIO(ipctk.profiler().csv), na_filter=False) | ||
| # df["Time (s)"] = df["Time (ms)"] / 1000.0 | ||
| # df["Parent"] = df["Parent"].astype(str) | ||
| # df["Id"] = df["Id"].astype(str) | ||
|
|
||
| fig = px.sunburst( | ||
| df, | ||
| ids="Id", | ||
| names="Name", | ||
| parents="Parent", | ||
| values="Time (ms)", | ||
| branchvalues="total", | ||
| color="Parent", | ||
| ) | ||
| fig.update_traces( | ||
| hovertemplate="<b>%{label}</b><br>Time (ms): %{value}<br>Call Count: %{customdata[0]}<br>Percentage of Parent: %{percentParent:.2%}", | ||
| customdata=df[["Count"]].values, | ||
| # tiling=dict( | ||
| # orientation='v' | ||
| # ) | ||
| ) | ||
| fig.update_layout( | ||
| title=title or "Profiler Results", | ||
| title_x=0.5, | ||
| title_y=0.95, | ||
| margin=dict(t=0, l=0, r=0, b=0), | ||
| width=800, | ||
| height=800, | ||
| template="plotly_white", | ||
| ) | ||
| # fig.write_image(f"icicle_{pathlib.Path(csv_path).stem}.png", scale=2) | ||
| # fig.write_image(f"sunburst_{pathlib.Path(csv_path).stem}.png", scale=2) | ||
| fig.show() | ||
| return fig | ||
|
|
||
| if __name__ == "__main__": | ||
| # plot(pathlib.Path(__file__).parent / "lbvh_profile.csv") | ||
|
|
||
| import meshio | ||
| import argparse | ||
| import numpy as np | ||
|
|
||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument( | ||
| "--mesh", | ||
| type=pathlib.Path, | ||
| default=(pathlib.Path(__file__).parents[2] / "tests/data/puffer-ball/20.ply")) | ||
| parser.add_argument( | ||
| "--method", | ||
| type=str, | ||
| default="lvbh") | ||
| args = parser.parse_args() | ||
|
|
||
| mesh = meshio.read(args.mesh) | ||
| faces = mesh.cells_dict["triangle"] | ||
|
|
||
| edges = ipctk.edges(faces) | ||
| # indices = np.lexsort((edges[:, 1], edges[:, 0])) | ||
| # edges = edges[indices] | ||
|
|
||
| # indices = np.lexsort((faces[:, 2], faces[:, 1], faces[:, 0])) | ||
| # faces = faces[indices] | ||
|
|
||
| if args.method.lower() == "bvh": | ||
| bp = ipctk.BVH() | ||
| elif args.method.lower() == "lbvh": | ||
| bp = ipctk.LBVH() | ||
|
|
||
| bp.build(mesh.points, edges, faces) | ||
|
|
||
| candidates = bp.detect_collision_candidates() | ||
|
|
||
| plot_profiler(title=args.mesh.parent.name + "/" + args.mesh.name) |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.