77import open3d as o3d
88from diffCheck import diffcheck_bindings
99import Rhino .Geometry as rg
10+ import System .Drawing
1011
1112class 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