GetCartVectors.m 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. % GetCartVectors.m
  2. %
  3. % This function returns an nx3 arrays of cartesian vectors for the eye direction
  4. % within the FOV of the headset, the eye direction in the world coordinates and
  5. % the head direction in the world.
  6. %
  7. % input:
  8. % data - ARFF data
  9. % metadata - metadata of ARFF data
  10. % attributes - attributes of ARFF data
  11. %
  12. % output:
  13. % eyeFovVec - nx3 (x,y,z) array corresponding to FOV vector of gaze centered
  14. % around the middle of the video corresponding to (1,0,0) vector
  15. % eyeHeadVec - nx3 (x,y,z) array corresponding to the direction of the eye in
  16. % the world. That is the head+eye position
  17. % headVec - nx3 (x,y,z) array corresponding to the direction of the head in
  18. % the world
  19. function [eyeFovVec, eyeHeadVec, headVec] = GetCartVectors(data, metadata, attributes)
  20. c_xName = 'x';
  21. c_yName = 'y';
  22. c_xHeadName = 'x_head';
  23. c_yHeadName = 'y_head';
  24. c_angleHeadName = 'angle_deg_head';
  25. xInd = GetAttPositionArff(attributes, c_xName);
  26. yInd = GetAttPositionArff(attributes, c_yName);
  27. xHeadInd = GetAttPositionArff(attributes, c_xHeadName);
  28. yHeadInd = GetAttPositionArff(attributes, c_yHeadName);
  29. angleHeadInd = GetAttPositionArff(attributes, c_angleHeadName);
  30. eyeFovVec = zeros(size(data,1),3);
  31. eyeHeadVec = zeros(size(data,1),3);
  32. headVec = zeros(size(data,1),3);
  33. for ind=1:size(data,1)
  34. [horHeadRads, verheadRads] = EquirectToSpherical(data(ind, xHeadInd), data(ind, yHeadInd), metadata.width_px, metadata.height_px);
  35. curHeadVec = SphericalToCart(horHeadRads, verheadRads);
  36. headVec(ind,:) = curHeadVec;
  37. angleHeadRads = data(ind, angleHeadInd) * pi / 180;
  38. videoVec = [-1; 0; 0]; % middle of the video is considered its center
  39. rot = HeadToVideoRot(curHeadVec, angleHeadRads, videoVec);
  40. rot = rot';
  41. [horGazeRads, verGazeRads] = EquirectToSpherical(data(ind, xInd), data(ind, yInd), metadata.width_px, metadata.height_px);
  42. gazeVec = SphericalToCart(horGazeRads, verGazeRads);
  43. eyeHeadVec(ind,:) = gazeVec;
  44. gazeWithinVec = RotatePoint(rot, gazeVec);
  45. eyeFovVec(ind,:) = gazeWithinVec(:);
  46. end
  47. end