MayaFlux 0.5.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ derivative()

template<typename T >
template<size_t N>
T MayaFlux::Kinesis::MotionChannel< T >::derivative ( )
inline

Compute the N-th derivative, routed through a configured HampelFilter for that order if one exists.

Template Parameters
NDerivative order, forwarded to Differential::backward_difference
Returns
The derivative, filtered if filter_order(N, ...) was called, unfiltered otherwise

Idempotent within a single update() cycle: the result for a given N is computed once and cached against the current generation counter (incremented every update()), and repeat calls to derivative<N>() before the next update() return the cached value rather than recomputing. This matters specifically because a configured HampelFilter's accept() has side effects (it may push into its own window or advance its rejection counter); calling derivative<N>() twice per frame without memoization would run accept() twice against the same underlying data in the same frame and silently corrupt the filter's state.

Definition at line 185 of file MotionChannel.hpp.

186 {
187 auto cached = m_derivative_cache.find(N);
188 if (cached != m_derivative_cache.end() && cached->second.generation == m_generation)
189 return cached->second.value;
190
191 const T raw = backward_difference<N>(m_history, m_last_dt);
192 T result = raw;
193 auto it = m_filters.find(N);
194 if (it != m_filters.end())
195 result = it->second->accept(raw);
196
197 m_derivative_cache[N] = DerivativeCacheEntry { m_generation, result };
198 return result;
199 }
#define N(method_name, full_type_name)
Definition Creator.hpp:106
Memory::HistoryBuffer< T > m_history
std::map< size_t, std::unique_ptr< HampelFilter< T > > > m_filters
std::map< size_t, DerivativeCacheEntry > m_derivative_cache

References MayaFlux::Kinesis::MotionChannel< T >::m_derivative_cache, MayaFlux::Kinesis::MotionChannel< T >::m_filters, MayaFlux::Kinesis::MotionChannel< T >::m_generation, MayaFlux::Kinesis::MotionChannel< T >::m_history, MayaFlux::Kinesis::MotionChannel< T >::m_last_dt, and N.

Referenced by MayaFlux::Kinesis::channel_curvature().

+ Here is the caller graph for this function: