Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// Smoothes the specified data.
- /// </summary>
- /// <param name="begin">The begin.</param>
- /// <param name="end">The end.</param>
- /// <param name="destination">The destination.</param>
- template <typename Itertype, typename DestItertype>
- void Analyze::smooth( Itertype begin, Itertype end, DestItertype& destination ) {
- auto spots_to_skip { 3 };
- // determine the starting and stopping points for our smoothing process
- auto current = next ( begin, spots_to_skip );
- auto smooth_end = prev ( end, spots_to_skip );
- // direct insert the first 3 elements
- copy ( begin, current, back_inserter ( destination ) );
- // smooth the rest of the elements up to the last three
- transform ( current, smooth_end, back_inserter ( destination ),
- [&]( auto val ) -> int {
- auto result = ( *prev(current, 3) + *prev(current, 2) * 2 + *prev(current, 1) * 3 + val * 3 + *next(current, 1) * 3 +
- *next(current, 2) * 2 + *next(current, 3) ) / 15;
- current = next ( current );
- return result;
- } );
- // direct insert the last three elements
- copy ( smooth_end, end, back_inserter ( destination ) );
- }
Advertisement
Add Comment
Please, Sign In to add comment