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