ConvectionKernels_AggregatedError.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #pragma once
  2. #ifndef __CVTT_AGGREGATEDERROR_H__
  3. #define __CVTT_AGGREGATEDERROR_H__
  4. #include "ConvectionKernels_ParallelMath.h"
  5. namespace cvtt
  6. {
  7. namespace Internal
  8. {
  9. template<int TVectorSize>
  10. class AggregatedError
  11. {
  12. public:
  13. typedef ParallelMath::UInt16 MUInt16;
  14. typedef ParallelMath::UInt31 MUInt31;
  15. typedef ParallelMath::Float MFloat;
  16. AggregatedError()
  17. {
  18. for (int ch = 0; ch < TVectorSize; ch++)
  19. m_errorUnweighted[ch] = ParallelMath::MakeUInt31(0);
  20. }
  21. void Add(const MUInt16 &channelErrorUnweighted, int ch)
  22. {
  23. m_errorUnweighted[ch] = m_errorUnweighted[ch] + ParallelMath::ToUInt31(channelErrorUnweighted);
  24. }
  25. MFloat Finalize(uint32_t flags, const float channelWeightsSq[TVectorSize]) const
  26. {
  27. if (flags & cvtt::Flags::Uniform)
  28. {
  29. MUInt31 total = m_errorUnweighted[0];
  30. for (int ch = 1; ch < TVectorSize; ch++)
  31. total = total + m_errorUnweighted[ch];
  32. return ParallelMath::ToFloat(total);
  33. }
  34. else
  35. {
  36. MFloat total = ParallelMath::ToFloat(m_errorUnweighted[0]) * channelWeightsSq[0];
  37. for (int ch = 1; ch < TVectorSize; ch++)
  38. total = total + ParallelMath::ToFloat(m_errorUnweighted[ch]) * channelWeightsSq[ch];
  39. return total;
  40. }
  41. }
  42. private:
  43. MUInt31 m_errorUnweighted[TVectorSize];
  44. };
  45. }
  46. }
  47. #endif