Skip to content

Commit

Permalink
Indication of positive and negative curvature values.
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Jan 14, 2023
1 parent f37346d commit f47a96c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
26 changes: 18 additions & 8 deletions nodes/viz/viewer_draw_surface.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,26 +213,36 @@ class SvSurfaceViewerDrawNode(SverchCustomTreeNode, bpy.types.Node):
update = updateNode)

curvature_types = [
('GAUSS', "Gauss", "Gauss curvature", 0),
('MEAN', "Mean", "Mean curvature", 1),
('GAUSS', "Gauss", "Gauss curvature - product of minimum and maximum curvature", 0),
('MEAN', "Mean", "Mean curvature - average between minimum and maximum curvature", 1),
('MAX', "Maximum", "Maximum curvature", 2),
('MIN', "Minimum", "Minimum curvature", 3),
('DIFF', "Difference", "Difference between maximum and minimum curvature", 4)
]

curvature_type : EnumProperty(
name = "Curvature type",
description = "Type of surface curvature to be indicated by color",
items = curvature_types,
default = 'GAUSS',
update = updateNode)

curvature_color: FloatVectorProperty(
name = "Curvature color",
curvature_max_color: FloatVectorProperty(
name = "Maximum curvature color",
description = "Color to be used to indicate positive curvature values",
default = (0.9, 0.1, 0.0, 1.0),
size = 4, min = 0.0, max = 1.0,
subtype = 'COLOR',
update = updateNode)

curvature_min_color: FloatVectorProperty(
name = "Minimum curvature color",
description = "Color to be used to indicate negative curvature values",
default = (0.0, 0.1, 0.9, 1.0),
size = 4, min = 0.0, max = 1.0,
subtype = 'COLOR',
update = updateNode)

light_vector: FloatVectorProperty(
name='Light Direction', subtype='DIRECTION', min=0, max=1, size=3,
default=(0.2, 0.6, 0.4), update=updateNode)
Expand Down Expand Up @@ -278,10 +288,10 @@ def draw_buttons(self, context, layout):

row = grid.row(align=True)
row.prop(self, 'draw_curvature', icon='EVENT_C', text='')
row.prop(self, 'curvature_color', text='')
row.prop(self, 'curvature_type', text='')
#if self.draw_curvature:
# grid.prop(self, 'curvature_type', text="Type")
row.prop(self, 'curvature_max_color', text='')
row.prop(self, 'curvature_min_color', text='')
if self.draw_curvature:
grid.prop(self, 'curvature_type', text="Type")

row = layout.row(align=True)
row.scale_y = 4.0 if self.prefs_over_sized_buttons else 1
Expand Down
40 changes: 27 additions & 13 deletions utils/surface/bakery.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,30 +123,44 @@ def __init__(self, node, surface, resolution_u, resolution_v):
curvature_values = calc.mean()
elif node.curvature_type == 'MAX':
c1, c2 = calc.values()
curvature_values = np.max((abs(c1), abs(c2)), axis=0)
#curvature_values = np.max((abs(c1), abs(c2)), axis=0)
curvature_values = np.max((c1, c2), axis=0)
elif node.curvature_type == 'MIN':
c1, c2 = calc.values()
curvature_values = np.min((abs(c1), abs(c2)), axis=0)
#curvature_values = np.min((abs(c1), abs(c2)), axis=0)
curvature_values = np.min((c1, c2), axis=0)
else: # DIFF
c1, c2 = calc.values()
m = np.min((abs(c1), abs(c2)), axis=0)
M = np.max((abs(c1), abs(c2)), axis=0)
m = np.min((c1, c2), axis=0)
M = np.max((c1, c2), axis=0)
#m = np.min((abs(c1), abs(c2)), axis=0)
#M = np.max((abs(c1), abs(c2)), axis=0)
curvature_values = M - m

curvature_values[np.isnan(curvature_values)] = 0
min_curvature = curvature_values.min()
max_curvature = curvature_values.max()
surface_colors = np.zeros((resolution_u*resolution_v, 4))
surface_colors[:] = main_color
max_color = np.array(node.curvature_max_color)
min_color = np.array(node.curvature_min_color)
if (max_curvature - min_curvature) < 1e-4:
surface_colors = np.empty((resolution_u*resolution_v, 4))
surface_colors[:] = main_color
curvature = (max_curvature + min_curvature)*0.5
if curvature > 0:
surface_colors[:] = max_color
if curvature < 0:
surface_colors[:] = min_color
else:
c = (curvature_values - min_curvature) / (max_curvature - min_curvature)
print(f"C: min {min_curvature}, max {max_curvature}, c {c}")
c = c[np.newaxis].T
max_color = np.array(node.curvature_color)
min_color = 2*main_color - max_color
#print(f"C: min {min_color}, avg {main_color}, max {max_color}")
surface_colors = (1 - c)*min_color + c*max_color
if max_curvature > 0:
positive = (curvature_values > 0)
c = curvature_values[positive] / max_curvature
c = c[np.newaxis].T
surface_colors[positive] = (1 - c)*main_color + c*max_color
if min_curvature < 0:
negative = (curvature_values < 0)
c = (min_curvature - curvature_values[negative]) / min_curvature
c = c[np.newaxis].T
surface_colors[negative] = (1 - c)*min_color + c*main_color
else:
surface_colors = np.empty((resolution_u*resolution_v, 4))
surface_colors[:] = main_color
Expand Down
3 changes: 0 additions & 3 deletions utils/surface/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,6 @@ def gauss(self):
curvature = np.zeros_like(numerator)
good = (denominator != 0)
curvature[good] = numerator[good] / denominator[good]
print(f"G: num {numerator}")
print(f"G: den {denominator}")
print(f"G: c {curvature}")
return curvature

def curvature_along_direction(self, v1, v2):
Expand Down

0 comments on commit f47a96c

Please sign in to comment.