WIP: Curves: Merge by distance #118616

Closed
Falk David wants to merge 5 commits from filedescriptor/blender:curves-merge-by-distance into main

When changing the target branch, be careful to rebase the branch in your fork to match. See documentation.
Member

This implements a way to merge points along curves by distance. The algorithm only looks at neightboring points, since we can't create loops in curves.

TODOs

  • Add option to make sure end-points stay in place.
  • Add option to potentially merge curves at their end points.
  • Point selection only makes sense if the ranges are contigous, which the code is not checking for.
This implements a way to merge points along curves by distance. The algorithm only looks at neightboring points, since we can't create loops in curves. TODOs - [ ] Add option to make sure end-points stay in place. - [ ] Add option to potentially merge curves at their end points. - [ ] Point selection only makes sense if the ranges are contigous, which the code is not checking for.
Falk David added 4 commits 2024-02-22 14:40:43 +01:00
Falk David requested review from Hans Goudey 2024-02-22 14:43:41 +01:00
Iliya Katushenock reviewed 2024-02-22 14:44:45 +01:00
@ -0,0 +172,4 @@
KDTree_1d *tree = BLI_kdtree_1d_new(selection.size());
/* The selection is an IndexMask of the points just in this curve. */
selection.foreach_index_optimized<int64_t>([&](const int64_t i, const int64_t pos) {
BLI_kdtree_1d_insert(tree, pos, &distances[i - points.first()]);

Can this be replaced by using points length cache of curve and binary search? See Sample Curve node as example..

Can this be replaced by using points length cache of curve and binary search? See `Sample Curve` node as example..
Author
Member

Maybe, not sure. I would love to not have to implement the BLI_kdtree_1d_calc_duplicates_fast though.

Maybe, not sure. I would love to not have to implement the `BLI_kdtree_1d_calc_duplicates_fast` though.

As i can see, this would be something like this:

const Span<float> lengths = src_curves.evaluated_lengths_for_curve(curve_i);
IndexRange::from_begin_end_inclusive(current_i, std::lower_bound(lengths[current_i], lengths.end(), lengths[current_i] + merge_distance));
As i can see, this would be something like this: ```Cpp const Span<float> lengths = src_curves.evaluated_lengths_for_curve(curve_i); IndexRange::from_begin_end_inclusive(current_i, std::lower_bound(lengths[current_i], lengths.end(), lengths[current_i] + merge_distance)); ```
Author
Member

I don't know.. Feels like using the kd-tree here is more consistent. This shouldn't be a bottleneck.

I don't know.. Feels like using the kd-tree here is more consistent. This shouldn't be a bottleneck.
Falk David added 1 commit 2024-02-22 14:45:15 +01:00
Member

For the modifiers, currently I would generally rather not generalize the behavior much. Sharing code seems less important-- it's easier if we just do whatever the old modifiers did. That would decouple the modifier's behavior from whatever decisions we make in new code. In other words, it would be good to avoid having to think about replacing the old modifiers at the same time as "what should merge curves by distance do?".

Maybe that just comes down to changing the name of the PR and moving the code.

For the modifiers, currently I would generally rather not generalize the behavior much. Sharing code seems less important-- it's easier if we just do whatever the old modifiers did. That would decouple the modifier's behavior from whatever decisions we make in new code. In other words, it would be good to avoid having to think about replacing the old modifiers at the same time as "what should merge curves by distance do?". Maybe that just comes down to changing the name of the PR and moving the code.
Author
Member

For reference, this is the old code: BKE_gpencil_stroke_merge_distance. I could try and implement that logic instead.
This particular PR wouldn't only be used for the modifier, but also for the operator. I could move the code to somewhere else, but it feels like that's where it should be in any case (with future improvements).

For reference, this is the old code: `BKE_gpencil_stroke_merge_distance`. I could try and implement that logic instead. This particular PR wouldn't only be used for the modifier, but also for the operator. I could move the code to somewhere else, but it feels like that's where it should be in any case (with future improvements).
Author
Member

Moved the code to #118546. Closing this.

Moved the code to https://projects.blender.org/blender/blender/pulls/118546. Closing this.
Falk David closed this pull request 2024-03-28 11:31:10 +01:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: blender/blender#118616
No description provided.