From d3877aabd3a49e8d2d5c14777a7418e31232f749 Mon Sep 17 00:00:00 2001 From: "Ilya V. Portnov" Date: Sat, 2 Nov 2024 19:41:34 +0500 Subject: [PATCH] Use sqrt() and curvature_clip for more uniform distribution. --- nodes/curve/adaptive_plot_mk2.py | 11 +++++++++++ utils/adaptive_curve.py | 13 +++++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/nodes/curve/adaptive_plot_mk2.py b/nodes/curve/adaptive_plot_mk2.py index e9bbb00f40..3797c48753 100644 --- a/nodes/curve/adaptive_plot_mk2.py +++ b/nodes/curve/adaptive_plot_mk2.py @@ -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' @@ -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) diff --git a/utils/adaptive_curve.py b/utils/adaptive_curve.py index cf353f8d52..278195dca7 100644 --- a/utils/adaptive_curve.py +++ b/utils/adaptive_curve.py @@ -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): @@ -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) @@ -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]