Skip to content
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

Check collision between a mesh and a set of points. #119

Open
ambitious-octopus opened this issue Apr 27, 2023 · 0 comments
Open

Check collision between a mesh and a set of points. #119

ambitious-octopus opened this issue Apr 27, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@ambitious-octopus
Copy link

Good job the package you are developing is very interesting, I appreciate your work. 👍

I am looking for a fast way to compute the collision between a mesh and a set of points. I am currently using the RaycastingScene() class from open3d. Unfortunately, the computation turns out to be quite slow for what I need. I was wondering if your package offers a more efficient system for the computation I need. I welcome suggestions on how to make this computation more efficient.
This is a minimal example with open3d:

import open3d as o3d
import numpy as np

mesh = o3d.geometry.TriangleMesh.create_sphere(0.2)
frame = o3d.geometry.TriangleMesh.create_coordinate_frame(0.3)

points = np.array([[-0.1, -0.1, -0.1],
                   [0.05, 0.05, 0.05],
                   [0.01, 0.01, 0.01],
                   [0.1, 0.1, 0.1],
                   [0.2, 0.2, 0.2]])

pcd = o3d.geometry.PointCloud(o3d.utility.Vector3dVector(points))
pcd.paint_uniform_color([1, 0, 0])

scene = o3d.t.geometry.RaycastingScene()
mesh_legacy = o3d.t.geometry.TriangleMesh.from_legacy(mesh)
_ = scene.add_triangles(mesh_legacy)  # we do not need the geometry ID for mesh

query_points = points.astype(np.float32)
occupancy = scene.compute_occupancy(query_points, 16)
print(occupancy.numpy())

o3d.visualization.draw_geometries([mesh, frame, pcd])

I have seen this script before, but unfortunately I get an error (issue #118):

import cupoch as cph
import copy
import time
import numpy as np
import os
import sys
dir_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.join(dir_path, "../misc"))
import meshes
cubic_size = 1.0
voxel_resolution = 128.0
mesh = meshes.bunny()
target = cph.geometry.VoxelGrid.create_from_triangle_mesh_within_bounds(
mesh,
voxel_size=cubic_size / voxel_resolution,
min_bound=(-cubic_size / 2, -cubic_size / 2, -cubic_size / 2),
max_bound=(cubic_size / 2, cubic_size / 2, cubic_size / 2),
)
vis = cph.visualization.Visualizer()
vis.create_window()
vis.add_geometry(target)
query = copy.deepcopy(target)
query.translate([-0.15, 0.0, 0.0])
dh = 0.02
for i in range(15):
query.translate([dh, 0.0, 0.0])
ans = cph.collision.compute_intersection(target, query, 0.0)
print(ans)
target.paint_uniform_color([1.0, 1.0, 1.0])
query.paint_uniform_color([1.0, 1.0, 1.0])
target.paint_indexed_color(ans.get_first_collision_indices(), [1.0, 0.0, 0.0])
query.paint_indexed_color(ans.get_second_collision_indices(), [0.0, 1.0, 0.0])
if i == 0:
vis.add_geometry(query)
vis.update_geometry(target)
vis.update_geometry(query)
vis.poll_events()
vis.update_renderer()
time.sleep(0.1)
vis.destroy_window()

Thank you for your support.

@neka-nat neka-nat added the enhancement New feature or request label Jun 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants