-
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
base: main
Are you sure you want to change the base?
Changes from all commits
7d128ab
ed41da8
c0c67dc
b986930
1bb9f8e
44203bc
9f43de0
aa1c1ce
acffc2b
1fa4de6
b2b4f39
ad5039f
d9ae2da
4b173cf
0cf9fea
ad44e09
d150477
9e75039
b0dec30
b72f570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| from find_ipctk import ipctk | ||
| import meshio | ||
| import polyscope as ps | ||
| from polyscope import imgui | ||
| import numpy as np | ||
|
|
||
| import pathlib | ||
|
|
||
| mesh = meshio.read(pathlib.Path(__file__).parents[2] / "tests/data/puffer-ball/20.ply") # noqa | ||
|
|
||
| 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() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| Id,Parent,Name,Time (ms),Count | ||
| 7,,LBVH::detect_edge_edge_candidates,331.688,6 | ||
| 8,,LBVH::detect_edge_face_candidates,209.872,6 | ||
| 9,,LBVH::detect_edge_vertex_candidates,139.502,6 | ||
| 10,,LBVH::detect_face_face_candidates,100.436,6 | ||
| 11,,LBVH::detect_face_vertex_candidates,131.918,6 | ||
| 12,,LBVH::detect_vertex_vertex_candidates,17.2223,6 | ||
| 13,,LBVH::init_bvh,21.2826,18 | ||
| 14,13,build_hierarchy,8.12017,18 | ||
| 15,13,compute_morton_codes,1.76938,18 | ||
| 16,13,populate_boxes,2.26558,18 | ||
| 17,13,sort_morton_codes,5.25754,18 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| import pandas as pd | ||
| import plotly.express as px | ||
| import pathlib | ||
|
|
||
| def plot(csv_path): | ||
| df = pd.read_csv(csv_path, 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_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 | ||
|
|
||
| plot(pathlib.Path(__file__).parent / "lbvh_profile.csv") |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| #include <common.hpp> | ||
|
|
||
| #include <ipc/broad_phase/lbvh.hpp> | ||
|
|
||
| using namespace ipc; | ||
|
|
||
| void define_lbvh(py::module_& m) | ||
| { | ||
| py::class_<LBVH::Node>(m, "LBVH_Node") | ||
| .def_readonly("aabb_min", &LBVH::Node::aabb_min) | ||
| .def_readonly("aabb_max", &LBVH::Node::aabb_max) | ||
| .def_readonly("left", &LBVH::Node::left) | ||
| .def_readonly("right", &LBVH::Node::right) | ||
|
Comment on lines
+12
to
+13
|
||
| .def_property_readonly("is_leaf", &LBVH::Node::is_leaf) | ||
| .def_property_readonly("is_inner", &LBVH::Node::is_inner) | ||
| .def_property_readonly("is_valid", &LBVH::Node::is_valid); | ||
|
|
||
| py::class_<LBVH, BroadPhase, std::shared_ptr<LBVH>>(m, "LBVH") | ||
| .def(py::init()) | ||
| .def_property_readonly("vertex_nodes", &LBVH::vertex_nodes) | ||
| .def_property_readonly("edge_nodes", &LBVH::edge_nodes) | ||
| .def_property_readonly("face_nodes", &LBVH::face_nodes); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.