Reputation: 11
I have a calcaneal (bone) mesh on which i've determined multiple landmarks.
One of these landmarks is the top of the bone (max_landmark). I want to measure the height of the bone from that landmark. This is the starting point of the ray.
I am casting a ray from that landmark down to another line I've calculated, the endpoint of this line is closest_point_on_line. This is the direction of the ray.
I'm using t_hit to get the hitpoint where the ray has hit the calcaneal mesh and from there I calculate the XYZ coordinates.
However: the hit point is super close to the starting point and has almost the exact same coordinates.
Here is the ray casting part of the code:
# Create a RaycastingScene
scene = o3d.t.geometry.RaycastingScene()
# Load the calcaneus mesh from file
mesh_calcaneus = o3d.io.read_triangle_mesh(os.path.join(root_folder_calcaneus, calcaneus_filename))
# Convert the loaded mesh to TriangleMesh
mesh_calcaneus_tri = o3d.t.geometry.TriangleMesh.from_legacy(mesh_calcaneus)
# Add the calcaneus mesh to the scene
scene.add_triangles(mesh_calcaneus_tri)
# Convert the TriangleMesh back to a legacy TriangleMesh for visualization
mesh_calcaneus_for_visualization = mesh_calcaneus_tri.to_legacy()
# Compute the direction of the ray from max_landmark to closest_point_on_line
ray_direction = [(closest_point_on_line[0] - max_landmark[0]),
(closest_point_on_line[1] - max_landmark[1]),
(closest_point_on_line[2] - max_landmark[2])]
# Define the desired length of the ray
desired_ray_length = 10000000.0 # Adjust this value as needed
# Normalize the direction vector
ray_direction_normalized = np.array(ray_direction) / np.linalg.norm(ray_direction)
# Extend the length of the ray by scaling the normalized direction vector
ray_direction = ray_direction_normalized * desired_ray_length
# Construct the tensor representing the rays
ray_direction = np.array(ray_direction) # Convert to numpy array for concatenation
print(f"ray_direction is {ray_direction}")
print(f"max_landmark = {max_landmark}")
# Reshape to ensure at least 2 dimensions
new_line_rays = o3d.core.Tensor([[max_landmark[0],max_landmark[1],max_landmark[2], ray_direction[0], ray_direction[1],ray_direction[2]]],dtype=o3d.core.Dtype.Float32)
ans = scene.cast_rays(new_line_rays)
# Get intersection points along each ray
intersection_points = ans['t_hit'].numpy()
# Extract intersection points with non-zero t_hit values
valid_intersection_points = intersection_points[intersection_points > 0]
# Get the corresponding XYZ coordinates
intersection_coordinates = new_line_rays[valid_intersection_points, :3]
intersection_coordinates_np = intersection_coordinates.numpy() # Convert to NumPy array
# intersection_coordinates_np = np.array(intersection_coordinates)
# print(f"Intersection Coordinates: {intersection_coordinates_np}")
# Create a point cloud to visualize intersection landmarks
intersection_landmark_cloud = o3d.geometry.PointCloud()
intersection_landmark_cloud.points = o3d.utility.Vector3dVector(intersection_coordinates_np)
intersection_landmark_cloud.paint_uniform_color([1, 0, 0])
I also add some photo's to visualize what i am trying to do.
enter image description here
I've tried printing all the values and see where the problems lay, however, this didn't yield much. I've also thoroughly looked through the documentation of the raycasting from open3d but I didn't get wiser from this too.
I have tried to make the length of the ray very large, and to be very secure in the input of the new_line_rays to ensure that they are in the right direction. I've also tried flipping the ray direction to see if it's in the right way
Upvotes: 1
Views: 369