Skip to content

Commit 890590d

Browse files
committed
WIP-FIX change inputs for cloud2cloud comparison to lists
1 parent 106187f commit 890590d

File tree

4 files changed

+189
-269
lines changed

4 files changed

+189
-269
lines changed

src/gh/components/DF_cloud_to_cloud_distance/code.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,33 @@
2020

2121
class CloudToCloudDistance(component):
2222
def RunScript(self,
23-
i_cloud_source: rg.PointCloud,
24-
i_cloud_target: rg.PointCloud):
23+
i_cloud_source: typing.List[rg.PointCloud],
24+
i_cloud_target: typing.List[rg.PointCloud]):
2525
"""
2626
The cloud-to-cloud component computes the distance between each point in the source point cloud and its nearest neighbour in thr target point cloud.
2727
28-
:param i_cloud_source: source point cloud
29-
:param i_cloud_target: target point cloud to align to
28+
:param i_cloud_source: a list of source point cloud
29+
:param i_cloud_target: a list of target point cloud to align to
3030
3131
:return o_distances : list of calculated distances for each point
3232
:return o_mse: the average squared difference between corresponding points of source and target
3333
:return o_max_deviation: the max deviation between source and target (Hausdorff Distance)
3434
:return o_min_deviation: the min deviation between source and target
3535
:return o_std_deviation: the standard deviation between source and target
3636
"""
37+
3738
if i_cloud_source is None or i_cloud_target is None:
3839
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide both objects of type point clouds to compare")
3940
return None
4041

4142
# conversion
42-
df_cloud_source = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud_source)
43-
df_cloud_target = df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cloud_target)
43+
df_cloud_source_list = [df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cl_s) for i_cl_s in i_cloud_source]
44+
df_cloud_target_list = [df_cvt_bindings.cvt_rhcloud_2_dfcloud(i_cl_t) for i_cl_t in i_cloud_target]
4445

4546
# calculate distances
46-
o_results = df_error_estimation.cloud_2_cloud_distance(df_cloud_source, df_cloud_target)
47+
o_results = df_error_estimation.cloud_2_cloud_comparison(df_cloud_source_list, df_cloud_target_list)
4748

48-
return o_results.distances_to_target, o_results.distances_to_target_mse, o_results.distances_to_target_max_deviation, o_results.distances_to_target_min_deviation, o_results.distances_to_target_sd_deviation, o_results
49+
return o_results.distances, o_results.distances_mse, o_results.distances_max_deviation, o_results.distances_min_deviation, o_results.distances_sd_deviation, o_results
4950

5051

5152
if __name__ == "__main__":

src/gh/components/DF_vizualization/code.py

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
class Vizualization(component):
2222
def RunScript(self,
2323
i_results,
24-
i_target_flag,
25-
i_source_flag,
2624
i_viz_settings):
2725
"""
2826
sth sth
@@ -32,38 +30,25 @@ def RunScript(self,
3230
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide both objects of type point clouds to compare")
3331
return None
3432

35-
if i_target_flag == False:
36-
#if user doesn't want to vizualize results on the target return the original geo
37-
#now only implemented for PCD
38-
o_target = df_cvt_bindings.cvt_dfcloud_2_rhcloud(i_results.target)
39-
o_target_legend = []
40-
else:
41-
#color the target pointcloud based on viz_settings
33+
#temp
34+
o_source = []
35+
o_target = []
4236

43-
#make a legend
37+
o_source = [df_cvt_bindings.cvt_dfcloud_2_rhcloud(src) for src in i_results.source]
38+
o_target = [df_cvt_bindings.cvt_dfcloud_2_rhcloud(trg) for trg in i_results.target]
4439

45-
pass
40+
o_legend = []
41+
42+
#color the source pointcloud based on viz_settings
4643

47-
if i_source_flag == False:
48-
#if user doesn't want to vizualize results on the target return the original geo
49-
#now only implemented for PCD
50-
o_source = df_cvt_bindings.cvt_dfcloud_2_rhcloud(i_results.source)
51-
o_source_legend = []
52-
else:
53-
#color the source pointcloud based on viz_settings
44+
#make a legend
5445

55-
#make a legend
56-
57-
pass
58-
59-
return o_source, o_target, o_source_legend, o_target_legend
46+
return o_source, o_target, o_legend
6047

6148

6249
if __name__ == "__main__":
6350
com = Vizualization()
64-
o_source, o_target, o_source_legend, o_target_legend = com.RunScript(
51+
o_source, o_target, o_legend, = com.RunScript(
6552
i_results,
66-
i_target_flag,
67-
i_source_flag,
6853
i_viz_settings
6954
)

src/gh/diffCheck/diffCheck/df_error_estimation.py

Lines changed: 39 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,31 @@
88
from diffCheck import diffcheck_bindings
99
import Rhino.Geometry as rg
1010

11-
def cloud_2_cloud_distance(source, target, signed=False):
11+
12+
def cloud_2_cloud_distance(source, target, invert=False):
1213
"""
13-
Compute the Euclidean distance for every point of a source pcd to its closest point on a target pointcloud
14+
Compute the Euclidean distance for every point of a source pcd to its
15+
closest point on a target pointcloud
1416
"""
15-
distances_to_target = np.asarray(source.compute_distance(target))
16-
distances_to_source = np.asarray(target.compute_distance(source))
17+
if invert:
18+
distances = np.asarray(target.compute_distance(source))
19+
else:
20+
distances = np.asarray(source.compute_distance(target))
1721

18-
return DFVizResults(source, target, distances_to_target, distances_to_source)
22+
return distances
23+
24+
25+
def cloud_2_cloud_comparison(source_list, target_list, invert=False):
26+
"""
27+
Compute the Euclidean distance for every point of a source pcd to its
28+
closest point on a target pointcloud
29+
"""
30+
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)
34+
35+
return results
1936

2037

2138
def cloud_2_mesh_distance(source, target, signed=False):
@@ -102,20 +119,24 @@ class DFVizResults:
102119
This class compiles the resluts of the error estimation into one object
103120
"""
104121

105-
def __init__(self, source, target, distances_to_target, distances_to_source):
122+
def __init__(self):
123+
124+
self.source = []
125+
self.target = []
106126

107-
self.source = source
108-
self.target = target
127+
self.distances_mse = []
128+
self.distances_max_deviation = []
129+
self.distances_min_deviation = []
130+
self.distances_sd_deviation = []
131+
self.distances = []
109132

110-
self.distances_to_target_mse = np.sqrt(np.mean(distances_to_target ** 2))
111-
self.distances_to_target_max_deviation = np.max(distances_to_target)
112-
self.distances_to_target_min_deviation = np.min(distances_to_target)
113-
self.distances_to_target_sd_deviation = np.std(distances_to_target)
114-
self.distances_to_target = distances_to_target.tolist()
133+
def add(self, source, target, distances):
115134

116-
self.distances_to_source_mse = np.sqrt(np.mean(distances_to_source ** 2))
117-
self.distances_to_source_max_deviation = np.max(distances_to_source)
118-
self.distances_to_source_min_deviation = np.min(distances_to_source)
119-
self.distances_to_source_sd_deviation = np.std(distances_to_source)
120-
self.distances_to_source = distances_to_source.tolist()
135+
self.source.append(source)
136+
self.target.append(target)
121137

138+
self.distances_mse.append(np.sqrt(np.mean(distances ** 2)))
139+
self.distances_max_deviation.append(np.max(distances))
140+
self.distances_min_deviation.append(np.min(distances))
141+
self.distances_sd_deviation.append(np.std(distances))
142+
self.distances.append(distances.tolist())

0 commit comments

Comments
 (0)