PaintGaze.cpp 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. // PaintGaze.cpp
  2. #include "PaintGaze.h"
  3. #include "../arffHelper/ArffUtil.h"
  4. #include "Unused.h"
  5. #include <iostream>
  6. #define INTERVAL_DURATION 100000 // 100ms
  7. using namespace std;
  8. // PUBLIC SLOTS:
  9. void PaintGaze::HandleTime(int time, QObject *pSender)
  10. {
  11. if (pSender == this)
  12. return;
  13. SetCurrentTime(time);
  14. }
  15. void PaintGaze::HandleToggleView()
  16. {
  17. if (m_pArff && m_pSecArff)
  18. {
  19. swap(m_pArff, m_pSecArff);
  20. GetSetup();
  21. }
  22. }
  23. // PUBLIC:
  24. PaintGaze::PaintGaze() : m_pArff(NULL), m_pSecArff(NULL)
  25. {
  26. SetCurrentTime(0);
  27. SetInterval(INTERVAL_DURATION);
  28. }
  29. void PaintGaze::SetData(Arff &arff)
  30. {
  31. m_pArff = &arff;
  32. GetSetup();
  33. }
  34. void PaintGaze::SetFovData(Arff &arff)
  35. {
  36. m_pSecArff = &arff;
  37. }
  38. void PaintGaze::SetCurrentTime(long int currentTime)
  39. {
  40. m_currentTime = currentTime;
  41. CalculateIntervals();
  42. }
  43. void PaintGaze::SetInterval(long int intervalDuration)
  44. {
  45. m_intervalDuration = intervalDuration;
  46. CalculateIntervals();
  47. }
  48. void PaintGaze::Paint(QPainter *painter, QSize size)
  49. {
  50. if (m_pArff == NULL)
  51. return;
  52. int rows, columns;
  53. m_pArff->Size(rows, columns);
  54. if (rows > 0)
  55. {
  56. painter->setPen(QPen(Qt::gray, 1.3*size.width()/1000.0));
  57. int circleSize = size.width()/60;
  58. int halfCircleSize = circleSize/2;
  59. int xPos, yPos; // x,y position on the drawing area
  60. double videoAspectRatio = (double)m_videoWidth/(double)m_videoHeight;
  61. double areaAspectRatio = (double)size.width()/(double)size.height();
  62. int width, height, xDisp, yDisp;
  63. if (videoAspectRatio > areaAspectRatio){
  64. width = size.width();
  65. xDisp = 0;
  66. height = width/videoAspectRatio;
  67. yDisp = (size.height()-height)/2;
  68. }
  69. else{
  70. height = size.height();
  71. yDisp = 0;
  72. width = height*videoAspectRatio;
  73. xDisp = (size.width()-width)/2;
  74. }
  75. bool changedColor = false;
  76. int position=-1;
  77. for(int i=m_endPoint; i>=m_startPoint; i--)
  78. {
  79. if ((*m_pArff)[i][m_timeInd]<m_currentTime && !changedColor){
  80. painter->setPen(QPen(Qt::red, 3.5*size.height()/1000.0));
  81. position = i;
  82. changedColor = true;
  83. }
  84. xPos = (int)(xDisp+((double)width/m_videoWidth)*(*m_pArff)[i][m_xInd]);
  85. yPos = (int)(yDisp+((double)height/m_videoHeight)*(*m_pArff)[i][m_yInd]);
  86. painter->drawEllipse(xPos-halfCircleSize, yPos-halfCircleSize, circleSize, circleSize);
  87. }
  88. if (position != -1){
  89. painter->setPen(QPen(Qt::green, 3.5*size.height()/1000.0));
  90. xPos = (int)(xDisp+((double)width/m_videoWidth)*(*m_pArff)[position][m_xInd]);
  91. yPos = (int)(yDisp+((double)height/m_videoHeight)*(*m_pArff)[position][m_yInd]);
  92. painter->drawEllipse(xPos-halfCircleSize, yPos-halfCircleSize, circleSize, circleSize);
  93. }
  94. }
  95. }
  96. // PRIVATE:
  97. void PaintGaze::CalculateIntervals()
  98. {
  99. m_endPoint = 0;
  100. m_startPoint = 0;
  101. if (m_pArff == NULL)
  102. return;
  103. int rows, columns;
  104. m_pArff->Size(rows, columns);
  105. if (rows == 0)
  106. return;
  107. m_endPoint = ArffUtil::FindPosition(m_pArff, m_timeInd, m_currentTime + m_intervalDuration);
  108. m_startPoint = ArffUtil::FindPosition(m_pArff, m_timeInd, m_currentTime - m_intervalDuration);
  109. }
  110. void PaintGaze::GetSetup()
  111. {
  112. int confInd;
  113. bool res = ArffUtil::GetTXYCindex(m_pArff, m_timeInd, m_xInd, m_yInd, confInd);
  114. UNUSED(res);
  115. m_videoWidth = m_pArff->WidthPx();
  116. m_videoHeight = m_pArff->HeightPx();
  117. CalculateIntervals();
  118. }