diffCheckOrg / diffCheck

diffCheck is a CAD-integrated tool for evaluating digital timber fabrication processes.
GNU General Public License v3.0
1 stars 1 forks source link

Adding API functions for compute distance (mesh-cloud cloud-mesh) #31

Closed 9and3 closed 2 weeks ago

9and3 commented 2 weeks ago

This PR introduces the 2 functions for calculating the distances for df evaluation.

Following @eleniv3d 's suggestions on slack, instead of exposing the ktrees I prefered to wrap open3d functions around two functions that returns list of distances:

(*) both have signed distances, if the is_abs is True it's only positive (**) for this one, it's based on raytracing (@mariklad mentioned it at one moment thanks!) and conversion to tensors, it's basically a point-to-plane. Both should be quite fast.

Here's an example file:

#! python3

import Rhino
import Rhino.Geometry as rg

import diffCheck
from diffCheck import diffcheck_bindings
import diffCheck.df_cvt_bindings
import diffCheck.df_geometries

df_mesh = diffCheck.df_cvt_bindings.cvt_rhmesh_2_dfmesh(i_rh_mesh)
df_cloud = diffCheck.df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_rh_cloud)

mesh_to_cloud_distances = df_mesh.compute_distance(target_cloud=df_cloud, is_abs=True)
print(f"Max distance mesh-to-cloud: {max(mesh_to_cloud_distances)}")
print(f"Min distance mesh-to-cloud: {min(mesh_to_cloud_distances)}")

cloud_to_cloud_distances = df_cloud.compute_distance(target_cloud=df_cloud, is_abs=True)
print(f"Max distance cloud-to-cloud: {max(cloud_to_cloud_distances)}")
print(f"Min distance cloud-to-cloud: {min(cloud_to_cloud_distances)}")

gh_snap4

9and3 commented 2 weeks ago

@DamienGilliard these are the functions you could use too in your segmentation!

eleniv3d commented 2 weeks ago

@9and3 hey! are you sure the ComputePointCloudDistance computes by default a signed distance? it is my impression that this is not the case so the is_abs toggle doesn't affect the result. :) For the Mesh it works as expected.

9and3 commented 2 weeks ago

it is my impression that this is not the case so the is_abs toggle doesn't affect the result.

You are completely right @eleniv3d , thanks for spotting this out! I opened a new PR fix #32 that removes the is_abs bool parameter since it makes sense to have it only on mesh-cloud comparison imo (by having an inside-out to sign on the distances).