Skip to content

Commit bbf3cee

Browse files
committed
WIP-ADD functions for coloring
1 parent 890590d commit bbf3cee

File tree

3 files changed

+132
-16
lines changed

3 files changed

+132
-16
lines changed

src/gh/components/DF_vizualization/code.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import diffCheck
1414
from diffCheck import diffcheck_bindings
1515
from diffCheck import df_cvt_bindings
16-
from diffCheck import df_error_estimation
16+
from diffCheck import df_error_estimation, df_vizualization
1717

1818
import diffCheck.df_util
1919

@@ -30,18 +30,22 @@ def RunScript(self,
3030
ghenv.Component.AddRuntimeMessage(RML.Warning, "Please provide both objects of type point clouds to compare")
3131
return None
3232

33-
#temp
34-
o_source = []
35-
o_target = []
36-
33+
# check if target is a pcl
3734
o_source = [df_cvt_bindings.cvt_dfcloud_2_rhcloud(src) for src in i_results.source]
35+
36+
# by default we color the target
37+
min_value = min(min(sublist) for sublist in i_results.distances)
38+
max_value = max(max(sublist) for sublist in i_results.distances)
39+
40+
o_source = [df_vizualization.add_color(src, dist, min_value, max_value) for src, dist in zip(o_source, i_results.distances)]
41+
3842
o_target = [df_cvt_bindings.cvt_dfcloud_2_rhcloud(trg) for trg in i_results.target]
3943

4044
o_legend = []
41-
42-
#color the source pointcloud based on viz_settings
4345

44-
#make a legend
46+
# color the source pointcloud based on viz_settings
47+
48+
#make a legend
4549

4650
return o_source, o_target, o_legend
4751

src/gh/diffCheck/diffCheck/df_vizualization.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import open3d as o3d
88
from diffCheck import diffcheck_bindings
99
import Rhino.Geometry as rg
10+
import System.Drawing
1011

1112
class DFVizSettings:
1213
"""
@@ -21,3 +22,53 @@ def __init__(self, source_valueType, target_valueType, upper_threshold, lower_th
2122
self.upper_threshold = upper_threshold
2223
self.lower_threshold = lower_threshold
2324
self.palette = palette
25+
26+
27+
def interpolate_color(color1, color2, t):
28+
"""Interpolate between two colors."""
29+
30+
r = int(color1.R + (color2.R - color1.R) * t)
31+
g = int(color1.G + (color2.G - color1.G) * t)
32+
b = int(color1.B + (color2.B - color1.B) * t)
33+
return System.Drawing.Color.FromArgb(r, g, b)
34+
35+
36+
def value_to_color(value, min_value, max_value):
37+
"""Map a value to a color based on a spectral colormap."""
38+
39+
# Define the spectral colormap (simplified)
40+
colormap = [
41+
System.Drawing.Color.FromArgb(0, 0, 255), # Blue
42+
System.Drawing.Color.FromArgb(0, 255, 255), # Cyan
43+
System.Drawing.Color.FromArgb(0, 255, 0), # Green
44+
System.Drawing.Color.FromArgb(255, 255, 0), # Yellow
45+
System.Drawing.Color.FromArgb(255, 0, 0), # Red
46+
System.Drawing.Color.FromArgb(255, 0, 255) # Magenta
47+
]
48+
49+
# Normalize the value within the range
50+
if min_value == max_value:
51+
t = 0.5
52+
else:
53+
t = (value - min_value) / (max_value - min_value)
54+
55+
# Determine the segment in the colormap
56+
n = len(colormap) - 1
57+
idx = int(t * n)
58+
if idx >= n:
59+
idx = n - 1
60+
t = (t * n) - idx
61+
62+
# Interpolate between the two colors
63+
color1 = colormap[idx]
64+
color2 = colormap[idx + 1]
65+
66+
return interpolate_color(color1, color2, t)
67+
68+
69+
def add_color(pcd, values, min_value, max_values):
70+
71+
for i, p in enumerate(pcd):
72+
mapped_color = value_to_color(values[i], min_value, max_values)
73+
p.Color = mapped_color
74+
return pcd

0 commit comments

Comments
 (0)