ConvectionKernels_PackedCovarianceMatrix.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #pragma once
  2. #ifndef __CVTT_COVARIANCEMATRIX_H__
  3. #define __CVTT_COVARIANCEMATRIX_H__
  4. namespace cvtt
  5. {
  6. namespace Internal
  7. {
  8. template<int TMatrixSize>
  9. class PackedCovarianceMatrix
  10. {
  11. public:
  12. // 0: xx,
  13. // 1: xy, yy
  14. // 3: xz, yz, zz
  15. // 6: xw, yw, zw, ww
  16. // ... etc.
  17. static const int PyramidSize = (TMatrixSize * (TMatrixSize + 1)) / 2;
  18. typedef ParallelMath::Float MFloat;
  19. PackedCovarianceMatrix()
  20. {
  21. for (int i = 0; i < PyramidSize; i++)
  22. m_values[i] = ParallelMath::MakeFloatZero();
  23. }
  24. void Add(const ParallelMath::Float *vec, const ParallelMath::Float &weight)
  25. {
  26. int index = 0;
  27. for (int row = 0; row < TMatrixSize; row++)
  28. {
  29. for (int col = 0; col <= row; col++)
  30. {
  31. m_values[index] = m_values[index] + vec[row] * vec[col] * weight;
  32. index++;
  33. }
  34. }
  35. }
  36. void Product(MFloat *outVec, const MFloat *inVec)
  37. {
  38. for (int row = 0; row < TMatrixSize; row++)
  39. {
  40. MFloat sum = ParallelMath::MakeFloatZero();
  41. int index = (row * (row + 1)) >> 1;
  42. for (int col = 0; col < TMatrixSize; col++)
  43. {
  44. sum = sum + inVec[col] * m_values[index];
  45. if (col >= row)
  46. index += col + 1;
  47. else
  48. index++;
  49. }
  50. outVec[row] = sum;
  51. }
  52. }
  53. private:
  54. ParallelMath::Float m_values[PyramidSize];
  55. };
  56. }
  57. }
  58. #endif