Page MenuHome

Correction of catmull_rom::interpolate
ClosedPublic

Authored by Mattias Fredriksson (Osares) on Sep 17 2022, 10:02 PM.

Details

Summary

Corrected interpolation of integer POD types for catmull_rom::interpolate() as implemented in D14481.

Problem description

attribute_math::DefaultMixer<T>::mix_in() assumes and asserts positive weights but the basis function for Catmull-Rom splines generate negative weights (see plot below). Passing negative weights will yield correct result as sum(weights) = 1 (after multiplication by 0.5) but the assert is still triggered in debug builds. This patch adjusts the behavior by extending attribute::mix#() with mix4(). The benefit over using mix#() over a DefaultMixer is that the result no longer need to be divided by the weight sum, instead utilizing that the basis weight sum is constant (see plot).

Changes

  • Added mix4() and updated catmull_rom::interpolate() to use it.
  • Removed TODOs from catmull_rom functions.
  • Moved mix#() definitions to be ordered as mix2(), mix3(), mix4() in the header.

Implementation specifics

catmull_rom::interpolate() uses a constexpr to differentiate between POD types which multiplies the result with 0.5 after weighting the values, this reduces the number of multiplications for 1D, 2D, 3D vectors (https://godbolt.org/z/8M1z9Pxx6). While this could be considered unnecessary I didn't want to change the original behavior as it could influence performance (did not measure performance here as this should ensure the logic is ~identical for FP types).

The template specializations for mix4() is defined in the header, this doesn't have to be the case but it is the current behavior. Not sure if moving the template specializations would prevent inlining and impact performance as it might be cleaner to put them in the .cc file with default implementations for floating point POD types.

Diff Detail

Repository
rB Blender
Branch
catmull_rom_interpolation (branched from master)
Build Status
Buildable 23815
Build 23815: arc lint + arc unit

Event Timeline

Mattias Fredriksson (Osares) requested review of this revision.Sep 17 2022, 10:02 PM
Mattias Fredriksson (Osares) created this revision.
Mattias Fredriksson (Osares) retitled this revision from Correction of catmull_rom::interpolate and TODO cleanup to Correction of catmull_rom::interpolate.Sep 17 2022, 11:11 PM
Mattias Fredriksson (Osares) edited the summary of this revision. (Show Details)
Mattias Fredriksson (Osares) edited the summary of this revision. (Show Details)
  • Normalize weights after mix for simple FP types

Great improvement, thanks for the patch!

This revision is now accepted and ready to land.Sep 17 2022, 11:37 PM