Skip to content

Commit

Permalink
Use sqrt() and curvature_clip for more uniform distribution.
Browse files Browse the repository at this point in the history
  • Loading branch information
portnov committed Nov 2, 2024
1 parent 1b5d7cd commit 91a4124
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
11 changes: 11 additions & 0 deletions nodes/curve/adaptive_plot_mk2.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,22 @@ def update_sockets(self, context):
default = False,
update = update_sockets)

curvature_clip : FloatProperty(
name = "Curvature Clip",
min = 0.0,
default = 100.0,
update = updateNode)

def draw_buttons(self, context, layout):
row = layout.row(align=True)
row.prop(self, 'by_curvature', toggle=True)
row.prop(self, 'by_length', toggle=True)
layout.prop(self, 'random')

def draw_buttons_ext(self, context, layout):
self.draw_buttons(context, layout)
layout.prop(self, 'curvature_clip')

def sv_init(self, context):
self.inputs.new('SvCurveSocket', "Curve")
self.inputs.new('SvStringsSocket', "Count").prop_name = 'count'
Expand Down Expand Up @@ -95,6 +105,7 @@ def process(self):
resolution = resolution,
by_length = self.by_length,
by_curvature = self.by_curvature,
curvature_clip = self.curvature_clip,
random = self.random,
seed = seed)
n = len(new_t)
Expand Down
13 changes: 9 additions & 4 deletions utils/adaptive_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
from sverchok.utils.sv_logging import sv_logger
from sverchok.utils.math import distribute_int
from sverchok.utils.geom import CubicSpline
from sverchok.utils.curve import SvCurveLengthSolver, CurvatureIntegral
from sverchok.utils.integrate import TrapezoidIntegral
from sverchok.utils.curve import SvCurveLengthSolver


class CurvePopulationController(object):
Expand Down Expand Up @@ -173,7 +174,7 @@ def populate_curve_old(curve, samples_t, by_length = False, by_curvature = True,
new_t = np.sort(new_t)
return new_t

def populate_curve(curve, n_points, resolution=100, by_length = False, by_curvature = True, random=False, seed=None):
def populate_curve(curve, n_points, resolution=100, by_length = False, by_curvature = True, curvature_clip=100.0, random=False, seed=None):
t_min, t_max = curve.get_u_bounds()
factors = np.zeros((resolution,))
ts = np.linspace(t_min, t_max, num=resolution)
Expand All @@ -182,8 +183,12 @@ def populate_curve(curve, n_points, resolution=100, by_length = False, by_curvat
lengths = np.cumsum(np.insert(lengths, 0, 0))
factors += lengths / lengths[-1]
if by_curvature:
integral = CurvatureIntegral(curve, resolution, rescale_curvature = True)
factors += integral.values
curvatures = curve.curvature_array(ts)
curvatures = np.clip(curvatures, 0.0, curvature_clip)
integral = TrapezoidIntegral(ts, ts, np.sqrt(curvatures))
#integral = TrapezoidIntegral(ts, ts, curvatures)
integral.calc()
factors += integral.summands
if not by_length and not by_curvature:
factors = np.linspace(0.0, 1.0, num=resolution)
factors /= factors[-1]
Expand Down

0 comments on commit 91a4124

Please sign in to comment.