Curves: Add simplify_curve_attribute
function
#118560
No reviewers
Labels
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset System
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Code Documentation
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
FBX
Interest
Freestyle
Interest
Geometry Nodes
Interest
glTF
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 & 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
Viewport & EEVEE
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Asset Browser Project
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
Asset System
Module
Core
Module
Development Management
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Module
Viewport & EEVEE
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Severity
High
Severity
Low
Severity
Normal
Severity
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
4 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: blender/blender#118560
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "filedescriptor/blender:curves-resample-adaptive"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Compute an index masks of points to remove to simplify the curve attribute using the Ramer-Douglas-Peucker algorithm.
The Ramer-Douglas-Peucker algorithm finds a set of points in a polyline to remove so that the overall shape of the polyline is similar. How similar can be controlled by the distance
epsilon
.The function takes a
GSpan
so it can be used with any attribute (that has a typefloat
,float2
, orfloat3
).On monkey character with the simplify modifier, this crashes at an assertion:
inside
in
Not sure about why exactly.
Nice. Where is this intended to be used?
curves_ramer_douglas_peucker_simplify
might be nice. The "resample" functions are all about sampling evenly spaced points on the curve currently. It could be helpful to keep that distinction. Especially since this is just removing points.@ -514,0 +609,4 @@
/* Distance functions for `ramer_douglas_peucker_simplify`. */
const auto dist_function_positions =
[positions](int64_t first_index, int64_t last_index, int64_t index) {
[positions]
->[&]
@ -514,0 +607,4 @@
const VArray<bool> cyclic = src_curves.cyclic();
const OffsetIndices<int> points_by_curve = src_curves.points_by_curve();
/* Distance functions for `ramer_douglas_peucker_simplify`. */
In case this function can be replaced by any other, i'd like to see some notes about interface of this. Mainly this due to this is additional reference level in a hot loop. In other word, if there is no resaon to use other function, its metter to inline this function in
ramer_douglas_peucker
. Or by using template, or just by movedist_to_line_v3
call to the loop.Originally, there where different distance functions.
Ideally, you want the resulting curves to look almost the same. This means that you need to take into account changes in thickness, opacity, color, etc.
I'm not sure what a good API for this would be. "Compute distances for these attributes too".
This is intended to be used for the grease pencil modifier. Maybe we can use it for the operator too at some point.
@blender-bot build
Just to make sure, it is something similar to #114628?
No, De Casteljau's algorithm is something different.
@blender-bot build
Curves: Add resample adaptive algorithmto WIP: Curves: Add resample adaptive algorithmInteresting to check this is geometry node with support of multiple attributes in
dist_function
@ -0,0 +45,4 @@
float max_dist = -1.0f;
int max_index = -1;
for (const int64_t index : inside_range) {
const float dist = dist_function(sub_range.first(), sub_range.last(), index);
BLI_assert(dist >= 0.0f);
@ -0,0 +76,4 @@
return;
}
const bool is_last_segment_selected = (curve_selection.first() && curve_selection.last());
(curve_selection.first() && curve_selection.last())
->curve_selection.first() && curve_selection.last()
I think a better approach might be something similar to
smooth_curve_attribute
:IndexMask
of points that can be removed based on some input attribute (GSpan
).float
, andfloat3
separately.This means that we can combine the
IndexMask
s together to actaully remove points.It's important that you can remove detail based on multiple attributes together. E.g. simplify a grease pencil stroke based on position, radius and opacity without loosing critical detail like the radii getting larger or the stroke end opacity fading out.
Sound like how
update_elimination_mask_for_close_points
are work.Looks like that is a similar idea yes.
@blender-bot build
WIP: Curves: Add resample adaptive algorithmto Curves: Add resample adaptive algorithmCurves: Add resample adaptive algorithmto Curves: Add `simplify_curve_attribute` function@ -0,0 +13,4 @@
namespace blender::geometry {
/* Computes a "perpendicular distance" value for the generic attribute data based on the
/**
with a newline@ -0,0 +57,4 @@
/* Mark all points to be kept. */
points_to_delete.slice(range).fill(false);
Stack<IndexRange> stack;
Maybe give this a slightly larger inline buffer to avoid allocations for every curve
@ -0,0 +130,4 @@
const OffsetIndices<int> points_by_curve,
const VArray<bool> &cyclic,
const float epsilon,
GSpan attribute_data,
const GSpan attribute_data
@ -0,0 +138,4 @@
points_by_curve, curves_selection, true, points_to_delete.as_mutable_span());
curves_selection.foreach_index(GrainSize(512), [&](const int64_t curve_i) {
const IndexRange points = points_by_curve[curve_i];
if (epsilon > 0.0f) {
Can you return early at the beginning of this function in this case rather than checking inside the loop?
@ -0,0 +144,4 @@
if constexpr (std::is_same_v<T, float> || std::is_same_v<T, float2> ||
std::is_same_v<T, float3>)
{
curve_simplifiy(points,
It seems clearer to slice all the input data so it's all local to the curve in
curve_simplifiy
@ -0,0 +3,4 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "BLI_array_utils.hh"
#include "BLI_math_geom.h"
Unused?
@ -0,0 +4,4 @@
#include "BLI_array_utils.hh"
#include "BLI_math_geom.h"
#include "BLI_set.hh"
Unused.
@ -0,0 +31,4 @@
const int64_t last_index,
const int64_t index)
{
const float3 ray_dir = positions[last_index] - positions[first_index];
Not sure how compiler will inline this function, but part of things inside of this one can be computed once outside of loop.
Seems like that wouldn't make a difference.
@ -0,0 +65,4 @@
if (sub_range.size() < 3) {
continue;
}
const IndexRange inside_range = sub_range.drop_front(1).drop_back(1);
@HooglyBoogly / @filedescriptor
Can we use
MutableSpan<bool>
instead ofIndexRange
directly, do you think its might be better?The index manipulation in this function was finicky to get right, so I was trying not to change it too much 😅. I would welcome any improvement.
@blender-bot build