EquirectangularToHead.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // EquirectangularToHead.cpp
  2. #include "EquirectangularToHead.h"
  3. #include "../arffHelper/ArffUtil.h"
  4. #include <iostream>
  5. #include <memory>
  6. using namespace std;
  7. EquirectangularToHead::EquirectangularToHead(Arff *arff) : m_pArff(arff)
  8. {
  9. }
  10. EquirectangularToHead::~EquirectangularToHead()
  11. {
  12. }
  13. unique_ptr<Arff> EquirectangularToHead::Convert()
  14. {
  15. const char *c_horHeadAttName = "x_head";
  16. const char *c_verHeadAttName = "y_head";
  17. unique_ptr<Arff> convertedArff(new Arff());
  18. convertedArff->SetWidthPx(m_pArff->WidthPx());
  19. convertedArff->SetHeightPx(m_pArff->HeightPx());
  20. convertedArff->SetRelation(m_pArff->GetRelation());
  21. convertedArff->AddColumn("time", "integer");
  22. convertedArff->AddColumn("x", "numeric");
  23. convertedArff->AddColumn("y", "numeric");
  24. convertedArff->AddColumn("confidence", "numeric");
  25. int xInd, yInd, timeInd, confInd;
  26. bool res = ArffUtil::GetTXYCindex(m_pArff, timeInd, xInd, yInd, confInd);
  27. int xHeadInd, yHeadInd;
  28. res &= m_pArff->GetAttIndex(c_horHeadAttName, xHeadInd);
  29. res &= m_pArff->GetAttIndex(c_verHeadAttName, yHeadInd);
  30. if (!res)
  31. {
  32. cout << "ERROR: could not find time, or x, or y, or confidence, or " << c_horHeadAttName << ", or " << c_verHeadAttName << " in the provided ARFF file." << endl;
  33. exit(-1);
  34. }
  35. for (auto entry : *m_pArff)
  36. {
  37. vector<double> row;
  38. row.push_back(entry[timeInd]);
  39. row.push_back(entry[xHeadInd]);
  40. row.push_back(entry[yHeadInd]);
  41. row.push_back(entry[confInd]);
  42. convertedArff->AddRow(row);
  43. }
  44. return move(convertedArff);
  45. }