Scheduled service maintenance on November 22


On Friday, November 22, 2024, between 06:00 CET and 18:00 CET, GIN services will undergo planned maintenance. Extended service interruptions should be expected. We will try to keep downtimes to a minimum, but recommend that users avoid critical tasks, large data uploads, or DOI requests during this time.

We apologize for any inconvenience.

EquirectangularToFovGaze.cpp 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. // EquirectangularToFovGaze.cpp
  2. #include "EquirectangularToFovGaze.h"
  3. #include "Util.h"
  4. #define PI 3.14159265
  5. using namespace std;
  6. EquirectangularToFovGaze::EquirectangularToFovGaze(Arff *pArff) :
  7. EquirectangularToFovBase(pArff)
  8. {
  9. }
  10. /*virtual*/ EquirectangularToFovGaze::~EquirectangularToFovGaze()
  11. {
  12. }
  13. unique_ptr<Arff> EquirectangularToFovGaze::Convert()
  14. {
  15. unique_ptr<Arff> convertedArff(new Arff());
  16. convertedArff->SetWidthPx(m_fovWidthPx);
  17. convertedArff->SetHeightPx(m_fovHeightPx);
  18. convertedArff->AddColumn("time", "integer");
  19. convertedArff->AddColumn("x", "numeric");
  20. convertedArff->AddColumn("y", "numeric");
  21. convertedArff->AddColumn("confidence", "numeric");
  22. int rows, columns;
  23. m_pArff->Size(rows, columns);
  24. //DataPoint iniPoint, convPoint;
  25. for (unsigned int ind=0; ind < (unsigned int)rows; ind++)
  26. {
  27. double xHead, yHead, tiltHead;
  28. GetHeadPos(ind, &xHead, &yHead, &tiltHead);
  29. double horHeadRads, verHeadRads;
  30. EquirectangularToSpherical(xHead, yHead, m_pArff->WidthPx(), m_pArff->HeightPx(), &horHeadRads, &verHeadRads);
  31. Vec3 headVec(0,0,0);
  32. SphericalToCartesian(horHeadRads, verHeadRads, &headVec);
  33. Vec3 vidVec(-1,0,0); // middle of the video is the center
  34. double tiltHeadRads = tiltHead * PI / 180;
  35. Matrix33 rot = HeadToVideoRotation(headVec, tiltHeadRads, vidVec);
  36. rot = Transpose(rot);
  37. // Convert gaze to FOV coordinates
  38. double xGaze, yGaze;
  39. GetEyePos(ind, &xGaze, &yGaze);
  40. double horGazeRads, verGazeRads;
  41. EquirectangularToSpherical(xGaze, yGaze, m_pArff->WidthPx(), m_pArff->HeightPx(), &horGazeRads, &verGazeRads);
  42. Vec3 GazeVec(0,0,0);
  43. SphericalToCartesian(horGazeRads, verGazeRads, &GazeVec);
  44. Vec3 rotGazeVec = RotatePoint(rot, GazeVec);
  45. double rotHorRads, rotVerRads;
  46. CartesianToSpherical(rotGazeVec, &rotHorRads, &rotVerRads);
  47. double xFov, yFov;
  48. SphericalToFov(rotHorRads, rotVerRads, &xFov, &yFov);
  49. vector<double> row;
  50. row.push_back((*m_pArff)[ind][m_timeInd]);
  51. row.push_back(xFov);
  52. row.push_back(yFov);
  53. row.push_back((*m_pArff)[ind][m_confInd]);
  54. convertedArff->AddRow(row);
  55. }
  56. return move(convertedArff);
  57. }
  58. // PRIVATE:
  59. void EquirectangularToFovGaze::SphericalToFov(double horRads, double verRads, double *x, double *y)
  60. {
  61. // Change them to [0, 2*pi) and [0, pi) range
  62. horRads = horRads < 0? 2*PI + horRads: horRads;
  63. verRads = verRads < 0? PI + verRads: verRads;
  64. // convert them from the middle of the video to the start of the coordinates
  65. horRads -= PI;
  66. verRads -= PI / 2.0;
  67. double fovHorRads = m_fovWidthDeg * PI / 180.0;
  68. double fovVerRads = m_fovHeightDeg * PI / 180.0;
  69. *x = m_fovWidthPx * (horRads + fovHorRads / 2.0) / fovHorRads;
  70. *y = m_fovHeightPx * (verRads + fovVerRads / 2.0) / fovVerRads;
  71. }