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
2 changed files with 2 additions and 2 deletions
Showing only changes of commit 58756c8936 - Show all commits

View File

@ -431,8 +431,8 @@ void smooth_fcurve_segment(FCurve *fcu,
const int segment_start_x = fcu->bezt[segment->start_index].vec[1][0];
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. */
double filter_result = samples[sample_index] * kernel[0];

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.
for (int j = 1; j <= kernel_size; 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; } ```
const double kernel_value = kernel[j];
filter_result += samples[sample_index + j] * kernel_value;

View File

@ -195,7 +195,7 @@ static void graph_slider_exit(bContext *C, wmOperator *op)
return;
}
if (gso->operator_data) {
if (gso->free_operator_data != NULL) {
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`.
}