Animation: Gaussian Smooth operator for Graph Editor #105635

Merged
Christoph Lendenfeld merged 15 commits from ChrisLend/blender:graph_gauss_smooth into main 2023-03-24 12:11:33 +01:00

Add a Gaussian smoothing operator to supersede the current smoothing operator in the graph editor.

Advantage over the current implementation:

  • Supports modal operations.
  • Is independent of key density. (Current implementation gets wrong results when there is not a key on every frame)
  • More options in the redo panel
  • More predictable Impulse Response

Option in the redo panel to change

  • Filter Width: How far out on each side of a key the code checks to average key values
  • Sigma: The shape of the bell curve, lower values make a sharper bell curve reducing the smoothing effect. Too High values will make the code behave like an average filter as the curve in the -1/1 range will almost be flat.

Impulse Response
image
image

The operator can be called from the Slider Operators Menu.
image

On a technical note, the operator needs to store additional data when running in modal to avoid allocating/deallocating data on every modal run. For that reason the tGraphSliderOp struct has been extended with void *operator_data and void (*free_operator_data)(void *operator_data). The former is the data and the latter is a function responsible for freeing that data.


revived from old patch: https://archive.blender.org/developer/D16778

Add a Gaussian smoothing operator to supersede the current smoothing operator in the graph editor. Advantage over the current implementation: * Supports modal operations. * Is independent of key density. (Current implementation gets wrong results when there is not a key on every frame) * More options in the redo panel * More predictable Impulse Response Option in the redo panel to change * Filter Width: How far out on each side of a key the code checks to average key values * Sigma: The shape of the bell curve, lower values make a sharper bell curve reducing the smoothing effect. Too High values will make the code behave like an average filter as the curve in the -1/1 range will almost be flat. Impulse Response ![image](/attachments/03b503b5-0075-4c89-a933-e1a478e86a82) ![image](/attachments/9aa7f4bc-2431-43b3-b998-b0fc4e445d2f) The operator can be called from the Slider Operators Menu. ![image](/attachments/bf44bde0-b4d2-44d2-b48e-786cb2425741) On a technical note, the operator needs to store additional data when running in modal to avoid allocating/deallocating data on every modal run. For that reason the `tGraphSliderOp` struct has been extended with `void *operator_data` and `void (*free_operator_data)(void *operator_data)`. The former is the data and the latter is a function responsible for freeing that data. ------ revived from old patch: https://archive.blender.org/developer/D16778
Christoph Lendenfeld added 1 commit 2023-03-10 14:01:33 +01:00
Hans Goudey changed title from Wip: Animation: Gauss Smooth operator for Graph Editor to WIP: Animation: Gauss Smooth operator for Graph Editor 2023-03-10 17:25:48 +01:00
Christoph Lendenfeld added 1 commit 2023-03-16 15:31:46 +01:00
Christoph Lendenfeld added 2 commits 2023-03-17 09:11:13 +01:00
Christoph Lendenfeld added 1 commit 2023-03-17 09:37:26 +01:00
Christoph Lendenfeld added 3 commits 2023-03-17 11:31:57 +01:00
Christoph Lendenfeld added 2 commits 2023-03-17 11:56:43 +01:00
Christoph Lendenfeld added 1 commit 2023-03-17 12:08:44 +01:00
Christoph Lendenfeld changed title from WIP: Animation: Gauss Smooth operator for Graph Editor to Animation: Gauss Smooth operator for Graph Editor 2023-03-17 12:16:26 +01:00
Christoph Lendenfeld added this to the Animation & Rigging project 2023-03-17 12:16:40 +01:00
Christoph Lendenfeld added the
Module
Animation & Rigging
label 2023-03-17 12:16:48 +01:00
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-03-17 12:16:54 +01:00
Author
Member

Video Demo

Video Demo

It should be Gaussian instead of Gauss. If there is only one smooth filter, the term Gaussian is quite technical and should be left to the tooltip only. If there are multiple smoothing filters, it's still better to put it last like Smooth (Gaussian).

It should be Gaussian instead of Gauss. If there is only one smooth filter, the term Gaussian is quite technical and should be left to the tooltip only. If there are multiple smoothing filters, it's still better to put it last like `Smooth (Gaussian)`.
First-time contributor

I'm also agree with the term Gaussian.

I'm also agree with the term Gaussian.
Author
Member

I'm also agree with the term Gaussian.

as Gaussian smoothing is based on an amplitude and a width of effect (which is mainly its 2\times\sigma or width) it would be good if it can be controllable by user.

that's what's in the redo panel :)

> I'm also agree with the term Gaussian. > > as Gaussian smoothing is based on an amplitude and a width of effect (which is mainly its $2\times\sigma$ or width) it would be good if it can be controllable by user. that's what's in the redo panel :)

Feels to me like this one is a candidate for when you activate it the slider should start at 0 instead of 50%, what do you guys think?

Or optionally

middle of the slider (start) is 0 influence, if you go towards positive it will gaussian smooth, but if you go negative it will do the opposite like make the current curves more pushed?

Feels to me like this one is a candidate for when you activate it the slider should start at 0 instead of 50%, what do you guys think? Or optionally middle of the slider (start) is 0 influence, if you go towards positive it will gaussian smooth, but if you go negative it will do the opposite like make the current curves more pushed?

Add a Gaussian smoothing operator to supersede the current smoothing operator in the graph editor.

Please update the patch description with some info about what made the current smoothing operator undesirable, and in which ways the new one is better.

> Add a Gaussian smoothing operator to supersede the current smoothing operator in the graph editor. Please update the patch description with some info about what made the current smoothing operator undesirable, and in which ways the new one is better.
Sybren A. Stüvel requested changes 2023-03-21 17:34:23 +01:00
Sybren A. Stüvel left a comment
Member

Some minor remarks. The filter seems to work well, but I'll leave the final judgement of that to @BClark .

Some minor remarks. The filter seems to work well, but I'll leave the final judgement of that to @BClark .
@ -394,1 +394,4 @@
}
/* ---------------- */
void get_1d_gauss_kernel(const float sigma, const int kernel_size, double *r_kernel)

For non-static functions, I think it might be better to move the ED_anim_... prefixes.

For non-static functions, I think it might be better to move the `ED_anim_...` prefixes.
@ -395,0 +395,4 @@
/* ---------------- */
void get_1d_gauss_kernel(const float sigma, const int kernel_size, double *r_kernel)
{

You could add

BLI_assert(sigma > 0.0f);
BLI_assert(kernel_size > 0);

to document the assumptions of the code. If sigma == 0 it'll cause some nice division issues.

You could add ```c BLI_assert(sigma > 0.0f); BLI_assert(kernel_size > 0); ``` to document the assumptions of the code. If `sigma == 0` it'll cause some nice division issues.
dr.sybren marked this conversation as resolved
@ -395,0 +396,4 @@
void get_1d_gauss_kernel(const float sigma, const int kernel_size, double *r_kernel)
{
double norm = 1.0 / (M_2_SQRTPI * sigma);

I think you can remove norm from the calculations completely. Since you normalise the end result anyway, this constant factor doesn't have an impact on the final result.

I think you can remove `norm` from the calculations completely. Since you normalise the end result anyway, this constant factor doesn't have an impact on the final result.
@ -395,0 +397,4 @@
void get_1d_gauss_kernel(const float sigma, const int kernel_size, double *r_kernel)
{
double norm = 1.0 / (M_2_SQRTPI * sigma);
double sigma_sq = 2.0 * sigma * sigma;

const

`const`
@ -395,0 +415,4 @@
/* Normalize kernel values. */
for (int i = 0; i < kernel_size; i++) {
r_kernel[i] = r_kernel[i] / sum;
r_kernel[i] /= sum;
```c r_kernel[i] /= sum; ```
dr.sybren marked this conversation as resolved
@ -396,0 +426,4 @@
const int kernel_size,
double *kernel)
{
for (int i = segment->start_index; i < segment->start_index + segment->length; i++) {

segment->start_index + segment->length and fcu->bezt[segment->start_index].vec[1][0] don't change during the loop, so you can store them in a constant outside of the loop and use that instead.

`segment->start_index + segment->length` and `fcu->bezt[segment->start_index].vec[1][0]` don't change during the loop, so you can store them in a constant outside of the loop and use that instead.
dr.sybren marked this conversation as resolved
@ -396,0 +433,4 @@
double filter_result = 0;
/* Apply the kernel. */
for (int j = -kernel_size; j <= kernel_size; j++) {
filter_result += samples[sample_index + j] * kernel[abs(j)];

What do you think would be faster? The current approach? Or halving the loop and avoiding the call to abs(j)?

    double filter_result = samples[sample_index] * kernel[0];
    for (int j = 1; j <= kernel_size; j++) {
      const double kernel_value = kernel[j];
      filter_result += samples[sample_index + j] * kernel_value;
      filter_result += samples[sample_index - j] * kernel_value;
    }
What do you think would be faster? The current approach? Or halving the loop and avoiding the call to `abs(j)`? ```c double filter_result = samples[sample_index] * kernel[0]; for (int j = 1; j <= kernel_size; j++) { const double kernel_value = kernel[j]; filter_result += samples[sample_index + j] * kernel_value; filter_result += samples[sample_index - j] * kernel_value; } ```
@ -1056,0 +1073,4 @@
ListBase anim_data; /* bAnimListElem */
} tGaussOperatorData;
typedef struct tFCurveSegmentLink {

Document what this struct contains / what it's for.

Document what this struct contains / what it's for.
Christoph Lendenfeld requested review from Brad Clark 2023-03-23 10:03:07 +01:00
Christoph Lendenfeld added 1 commit 2023-03-23 11:33:34 +01:00
Christoph Lendenfeld changed title from Animation: Gauss Smooth operator for Graph Editor to Animation: Gaussian Smooth operator for Graph Editor 2023-03-23 15:00:56 +01:00
Christoph Lendenfeld added 1 commit 2023-03-23 15:14:02 +01:00
Christoph Lendenfeld requested review from Sybren A. Stüvel 2023-03-23 15:27:28 +01:00
Sybren A. Stüvel approved these changes 2023-03-24 10:43:46 +01:00
Sybren A. Stüvel left a comment
Member

Just two small notes, no need to re-review after addressing.

Just two small notes, no need to re-review after addressing.
@ -396,0 +432,4 @@
for (int i = segment->start_index; i < segment_end_index; i++) {
const int sample_index = (int)(fcu->bezt[i].vec[1][0] - segment_start_x) + kernel_size;
double filter_result = samples[sample_index] * kernel[0];
/* Apply the kernel. */

This comment should swap with the line above it, as double filter_result = samples[sample_index] * kernel[0]; is already part of applying the kernel.

This comment should swap with the line above it, as `double filter_result = samples[sample_index] * kernel[0];` is already part of applying the kernel.
@ -192,2 +196,4 @@
}
if (gso->operator_data) {
gso->free_operator_data(gso->operator_data);

I think it's better to do a NULL check on gso->free_operator_data itself. Calling gso->free_operator_data(...) is guaranteed to crash if that pointer is NULL, whereas gso->free_operator_data(NULL) might be fine, depending on the implementation of that function.

It also simplifies the API, in that, regardless of any other field, the function is simply called when it's not-NULL.

I think it's better to do a `NULL` check on `gso->free_operator_data` itself. Calling `gso->free_operator_data(...)` is guaranteed to crash if that pointer is `NULL`, whereas `gso->free_operator_data(NULL)` might be fine, depending on the implementation of that function. It also simplifies the API, in that, regardless of any other field, the function is simply called when it's not-`NULL`.
Christoph Lendenfeld force-pushed graph_gauss_smooth from a4208969b0 to 5bcbc28f73 2023-03-24 11:43:54 +01:00 Compare
Author
Member

seems like I messed up with git
reverting and force pushing fixed it

seems like I messed up with git reverting and force pushing fixed it
Christoph Lendenfeld added 1 commit 2023-03-24 11:46:58 +01:00
Christoph Lendenfeld merged commit 5d5027db03 into main 2023-03-24 12:11:33 +01:00
Christoph Lendenfeld deleted branch graph_gauss_smooth 2023-03-24 12:11:34 +01:00
Brecht Van Lommel reviewed 2023-03-24 12:42:22 +01:00
@ -1056,0 +1141,4 @@
ED_slider_status_string_get(gso->slider, slider_string, UI_MAX_DRAW_STR);
strcpy(mode_str, TIP_("Gauss Smooth"));

Change this to:

const char *mode_str = TIP_("Gaussian Smooth");

It's using the old name now. Copying to a small fixed buffer like that can very easily overflow, but you don't need to copy at all.

Change this to: ``` const char *mode_str = TIP_("Gaussian Smooth"); ``` It's using the old name now. Copying to a small fixed buffer like that can very easily overflow, but you don't need to copy at all.
Author
Member

sorry missed that one
will fix it shortly

sorry missed that one will fix it shortly
Sybren A. Stüvel removed this from the Animation & Rigging project 2023-03-24 15:02:15 +01:00
Sign in to join this conversation.
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
5 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#105635
No description provided.