Jarquafelmu

Untitled

Mar 15th, 2019
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. /// <summary>
  2. /// Smoothes the specified data.
  3. /// </summary>
  4. /// <param name="begin">The begin.</param>
  5. /// <param name="end">The end.</param>
  6. /// <param name="destination">The destination.</param>
  7. template <typename Itertype, typename DestItertype>
  8. void Analyze::smooth( Itertype begin, Itertype end, DestItertype& destination ) {
  9.   auto spots_to_skip { 3 };
  10.  
  11.   // determine the starting and stopping points for our smoothing process
  12.   auto current = next ( begin, spots_to_skip );
  13.   auto smooth_end = prev ( end, spots_to_skip );
  14.  
  15.   // direct insert the first 3 elements
  16.   copy ( begin, current, back_inserter ( destination ) );
  17.  
  18.   // smooth the rest of the elements up to the last three
  19.   transform ( current, smooth_end, back_inserter ( destination ),
  20.   [&]( auto val ) -> int {
  21.     auto result = ( *prev(current, 3) + *prev(current, 2) * 2 + *prev(current, 1) * 3 + val * 3 + *next(current, 1) * 3 +
  22.                     *next(current, 2) * 2 + *next(current, 3) ) / 15;
  23.     current = next ( current );
  24.     return result;
  25.   } );
  26.  
  27.   // direct insert the last three elements
  28.   copy ( smooth_end, end, back_inserter ( destination ) );
  29. }
Advertisement
Add Comment
Please, Sign In to add comment