ProjectEquirect2Fov.m 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. % ProjectEquirect2Fov.m
  2. %
  3. % This function projects the gaze from the equirectangular representation into
  4. % the FOV and returns the new data. The change is indicated throught the
  5. % relation name, which is set to gaze_fov.
  6. %
  7. % input:
  8. % data - data from the ARFF file
  9. % metadata - metadata from the ARFF file
  10. % attributes - attributes from the ARFF file
  11. % relation - relation from the ARFF file
  12. %
  13. % output:
  14. % fovData - converted data to fov
  15. % fovMetadata - new metadata describing the experiment
  16. % fovAttributes - new attributes describing the data
  17. % fovRelation - new relation set to gaze_fov
  18. function [fovData, fovMetadata, fovAttributes, fovRelation] = ProjectEquirect2Fov(data, metadata, attributes, relation)
  19. assert(strcmp(relation, 'gaze_360'), 'Data do not come from equirectangular experiment');
  20. % Proccess the FOV vectors
  21. [eyeFovVec] = GetCartVectors(data, metadata, attributes); % rotation at (-1,0,0) point
  22. widthFovDeg = str2num(GetMetaExtraValueArff(metadata, 'fov_width_deg'));
  23. widthFovRads = widthFovDeg * pi / 180;
  24. heightFovDeg = str2num(GetMetaExtraValueArff(metadata, 'fov_height_deg'));
  25. heightFovRads = heightFovDeg * pi / 180;
  26. widthFovPx = str2num(GetMetaExtraValueArff(metadata, 'fov_width_px'));
  27. heightFovPx = str2num(GetMetaExtraValueArff(metadata, 'fov_height_px'));
  28. xFov = zeros(size(data,1),1);
  29. yFov = zeros(size(data,1),1);
  30. for i=1:size(data,1)
  31. [horRads, verRads] = CartToSpherical(eyeFovVec(i,:));
  32. if (horRads < 0)
  33. horRads = 2*pi + horRads;
  34. end
  35. horRads = horRads - pi; % reference vector at (-1,0,0)
  36. verRads = verRads - pi/2;
  37. xFov(i) = widthFovPx * (horRads + widthFovRads / 2) / widthFovRads;
  38. yFov(i) = heightFovPx * (verRads + heightFovRads / 2) / heightFovRads;
  39. end
  40. fovMetadata.width_px = widthFovPx;
  41. fovMetadata.height_px = heightFovPx;
  42. fovMetadata.distance_mm = 80;
  43. ppdx = fovMetadata.width_px / widthFovDeg;
  44. fovMetadata.width_mm = ppd2distance(ppdx, fovMetadata.width_px, fovMetadata.distance_mm);
  45. ppdy = fovMetadata.height_px / heightFovDeg;
  46. fovMetadata.height_mm = ppd2distance(ppdy, fovMetadata.height_px, fovMetadata.distance_mm);
  47. fovMetadata.extra = {};
  48. fovAttributes = {};
  49. fovData = zeros(size(data,1),0);
  50. timeInd = GetAttPositionArff(attributes, 'time');
  51. [fovData, fovAttributes] = AddAttArff(fovData, fovAttributes, data(:,timeInd), attributes{timeInd,1}, attributes{timeInd,2});
  52. [fovData, fovAttributes] = AddAttArff(fovData, fovAttributes, xFov, 'x', 'Numeric');
  53. [fovData, fovAttributes] = AddAttArff(fovData, fovAttributes, yFov, 'y', 'Numeric');
  54. confInd = GetAttPositionArff(attributes, 'confidence');
  55. [fovData, fovAttributes] = AddAttArff(fovData, fovAttributes, data(:,confInd), attributes{confInd,1}, attributes{confInd,2});
  56. fovRelation = 'gaze_fov';
  57. end