44"""
55
66import numpy as np
7- import open3d as o3d
87from diffCheck import diffcheck_bindings
98import Rhino .Geometry as rg
109
1110
12- def cloud_2_cloud_distance ( source , target , invert = False ):
11+ def cloud_2_cloud_comparison ( source_list , target_list ):
1312 """
1413 Compute the Euclidean distance for every point of a source pcd to its
1514 closest point on a target pointcloud
1615 """
17- if invert :
18- distances = np .asarray (target .compute_distance (source ))
19- else :
20- distances = np .asarray (source .compute_distance (target ))
16+ results = DFVizResults ()
17+ for source , target in zip (source_list , target_list ):
18+ distances = cloud_2_cloud_distance (source , target )
19+ results .add (source , target , distances )
20+
21+ return results
22+
2123
22- return distances
24+ def cloud_2_cloud_distance (source , target ):
25+ """
26+ Compute the Euclidean distance for every point of a source pcd to its
27+ closest point on a target pointcloud
28+ """
29+
30+ return np .asarray (source .compute_distance (target ))
2331
2432
25- def cloud_2_cloud_comparison ( source_list , target_list , invert = False ):
33+ def cloud_2_rhino_mesh_comparison ( cloud_source_list , rhino_mesh_target_list , signed_flag , swap ):
2634 """
2735 Compute the Euclidean distance for every point of a source pcd to its
2836 closest point on a target pointcloud
2937 """
3038 results = DFVizResults ()
31- for source , target in zip (source_list , target_list ):
32- distances = cloud_2_cloud_distance (source , target , invert )
33- results .add (source , target , distances )
39+
40+ for source , target in zip (cloud_source_list , rhino_mesh_target_list ):
41+ if swap :
42+ # this mean we want to vizualize the result on the target mesh
43+ distances = rhino_mesh_2_cloud_distance (target , source , signed_flag )
44+ else :
45+ # this means we want to vizualize the result on the source pcd
46+ distances = cloud_2_rhino_mesh_distance (source , target , signed_flag )
47+
48+ if swap :
49+ results .add (target , source , distances )
50+ else :
51+ results .add (source , target , distances )
3452
3553 return results
3654
3755
38- def cloud_2_mesh_distance (source , target , signed = False ):
56+ # def cloud_2_mesh_distance(source, target, signed=False):
57+ # """
58+ # Calculate the distance between every point of a source pcd to its closest point on a target DFMesh
59+ # """
60+
61+ # # for every point on the PCD compute the point_2_mesh_distance
62+ # if signed:
63+ # distances = np.asarray(target.compute_distance(source, is_abs=False))
64+ # else:
65+ # distances = np.asarray(target.compute_distance(source, is_abs=True))
66+
67+ # return distances
68+
69+ def rhino_mesh_2_cloud_distance (source , target , signed = False ):
3970 """
40- Calculate the distance between every point of a source pcd to its closest point on a target DFMesh
71+ Calculate the distance between every vertex of a Rhino Mesh to its closest point on a PCD
4172 """
73+ #make a Df point cloud containing all the vertices of the source rhino mesh
74+ df_pcd_from_mesh_vertices = diffcheck_bindings .dfb_geometry .DFPointCloud ()
75+ df_pcd_from_mesh_vertices .points = [[pt .X , pt .Y , pt .Z ] for pt in source .Vertices ]
76+ #calculate the distances
77+ distances = np .asarray (df_pcd_from_mesh_vertices .compute_distance (target ))
4278
43- # for every point on the PCD compute the point_2_mesh_distance
4479 if signed :
45- distances = np .asarray (target .compute_distance (source , is_abs = False ))
46- else :
47- distances = np .asarray (target .compute_distance (source , is_abs = True ))
80+ for p in target .points :
81+
82+ rhp = rg .Point3d (p [0 ], p [1 ], p [2 ])
83+ closest_meshPoint = source .ClosestMeshPoint (rhp , 1000 )
84+ closest_point = closest_meshPoint .Point
85+ distance = rhp .DistanceTo (closest_point )
86+ # Calculate the direction from target to source
87+ direction = rhp - closest_point
88+ # Calculate the signed distance
89+ normal = source .NormalAt (closest_meshPoint )
90+ dot_product = direction * normal
91+ if dot_product < 0 :
92+ distance = - distance
93+
94+ return np .asarray (distances )
4895
49- return distances
5096
5197def cloud_2_rhino_mesh_distance (source , target , signed = False ):
5298 """
@@ -61,7 +107,6 @@ def cloud_2_rhino_mesh_distance(source, target, signed=False):
61107 rhp = rg .Point3d (p [0 ], p [1 ], p [2 ])
62108 closest_meshPoint = target .ClosestMeshPoint (rhp , 1000 )
63109 closest_point = closest_meshPoint .Point
64- face_Index = closest_meshPoint .FaceIndex
65110 distance = rhp .DistanceTo (closest_point )
66111
67112 if signed :
@@ -78,42 +123,6 @@ def cloud_2_rhino_mesh_distance(source, target, signed=False):
78123 return np .asarray (distances )
79124
80125
81- # def compute_mse(distances):
82- # """
83- # Calculate mean squared distance
84- # """
85- # mse = np.sqrt(np.mean(distances ** 2))
86-
87- # return mse
88-
89-
90- # def compute_max_deviation(distances):
91- # """
92- # Calculate max deviation of distances
93- # """
94- # max_deviation = np.max(distances)
95-
96- # return max_deviation
97-
98-
99- # def compute_min_deviation(distances):
100- # """
101- # Calculate min deviation of distances
102- # """
103-
104- # min_deviation = np.min(distances)
105-
106- # return min_deviation
107-
108-
109- # def compute_standard_deviation(distances):
110- # """
111- # Calculate standard deviation of distances
112- # """
113- # standard_deviation = np.std(distances)
114-
115- # return standard_deviation
116-
117126class DFVizResults :
118127 """
119128 This class compiles the resluts of the error estimation into one object
0 commit comments