Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://github.com/RMonica/Hybrid_HMD_Tracking_RS
09 October 2024, 07:19:50 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • refs/heads/master
    No releases to show
  • 0abb08a
  • /
  • src
  • /
  • tracking_compute_stats.cpp
Raw File Download Save again
Take a new snapshot of a software origin

If the archived software origin currently browsed is not synchronized with its upstream version (for instance when new commits have been issued), you can explicitly request Software Heritage to take a new snapshot of it.

Use the form below to proceed. Once a request has been submitted and accepted, it will be processed as soon as possible. You can then check its processing state by visiting this dedicated page.
swh spinner

Processing "take a new snapshot" request ...

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:6f70fac6b0f1d3592b01bcac56997e61b8118c02
origin badgedirectory badge
swh:1:dir:64641fa369e2f30e00c95980e9e55de9c491536e
origin badgerevision badge
swh:1:rev:0a8db14161db9bc4e579790279580a9bb68755bc
origin badgesnapshot badge
swh:1:snp:0203d2f7ea07552ec1a63af56f020f4b91fd3b0a

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Generate software citation in BibTex format (requires biblatex-software package)
Generating citation ...
Tip revision: 0a8db14161db9bc4e579790279580a9bb68755bc authored by RMonica on 08 October 2024, 13:23:12 UTC
Minor changes in scripts for compatibility.
Tip revision: 0a8db14
tracking_compute_stats.cpp
/*
 * Copyright 2022-2024 Riccardo Monica
 * 
 * This software is distributed under the 3-clause BSD license.
 * You should have received a copy of the 3-clause BSD license
 * along with this software. If not, see
 * <https://opensource.org/license/bsd-3-clause>
 */

#include <fstream>
#include <sstream>
#include <iostream>
#include <stdint.h>
#include <string>
#include <vector>

typedef uint64_t uint64;
typedef std::vector<std::string> StringVector;

struct ParsedLine
{
  uint64 frame_count;
  float pos_error = -1; // -1 if none
  float rot_error = -1;
  float pos_diff = -1;
  float rot_diff = -1;
  float pos_vib = -1;
  float rot_vib = -1;
  double comp_time = -1;
  bool lost = false;
};

template <typename T>
T MaybeParse(std::istream & istr, const T default_value)
{
  std::string w;
  istr >> w;
  if (istr)
  {
    std::istringstream iss(w);
    T f;
    iss >> f;
    if (iss)
      return f;
  }
  return default_value;
}

ParsedLine ParseLine(const std::string & line)
{
  std::istringstream istr(line);
  ParsedLine result;

  istr >> result.frame_count;
  result.pos_error = MaybeParse(istr, -1.0f);
  result.rot_error = MaybeParse(istr, -1.0f);
  result.pos_diff = MaybeParse(istr, -1.0f);
  result.rot_diff = MaybeParse(istr, -1.0f);
  result.pos_vib = MaybeParse(istr, -1.0f);
  result.rot_vib = MaybeParse(istr, -1.0f);
  std::string lost_str;
  istr >> lost_str;
  result.lost = (lost_str == "YES");
  result.comp_time = MaybeParse(istr, -1.0);

  if (!istr)
  {
    std::cout << "Error: Unable to parse line: \"" << line << "\"" << std::endl;
    std::exit(5);
  }

  return result;
}

StringVector ReadFileLines(std::istream & ifile)
{
  StringVector result;
  std::string line;
  while (std::getline(ifile, line))
    result.push_back(line);
  return result;
}

int main(int argc, char ** argv)
{
  if (argc < 7)
  {
    std::cout << "Usage: tracking_compute_stats errors.txt range_min range_max errors_stats.txt MODE line" << std::endl;
    std::exit(1);
  }

  const std::string errors_filename = argv[1];
  const std::string range_min_str = argv[2];
  const std::string range_max_str = argv[3];
  const std::string errors_stats_filename = argv[4];
  const std::string mode = argv[5];
  const std::string outfile_line_str = argv[6];

  StringVector error_stats_strings;
  {
    std::cout << "Reading file " << errors_stats_filename << std::endl;
    std::ifstream esfile(errors_stats_filename.c_str());
    if (!esfile)
      std::cout << "  File not existing, it will be created." << std::endl;
    if (esfile)
      error_stats_strings = ReadFileLines(esfile);
  }

  uint64 range_min;
  uint64 range_max;
  uint64 outfile_line;
  try
  {
    range_min = std::stoi(range_min_str);
    range_max = std::stoi(range_max_str);
    outfile_line = std::stoi(outfile_line_str);
  }
  catch (std::exception e)
  {
    std::cout << "Input parsing error: " << e.what() << std::endl;
    std::exit(1);
  }

  std::cout << "range: [" << range_min << " - " << range_max << "]" << std::endl;

  std::cout << "Opening file: " << errors_filename << std::endl;
  std::ifstream efile(errors_filename.c_str());
  if (!efile)
  {
    std::cout << "Could not open input file: " << errors_filename << std::endl;
    std::exit(2);
  }

  float pos_error_sum = 0.0f;
  float rot_error_sum = 0.0f;
  uint64 error_count = 0;

  float pos_vib_sum = 0.0f;
  float rot_vib_sum = 0.0f;
  uint64 vib_count = 0;

  double comp_time_sum = 0.0f;
  uint64 comp_time_count = 0;

  uint64 frame_count = 0;
  bool header = true;
  std::string line;
  while (std::getline(efile, line))
  {
    if (header)
    {
      header = false;
      continue;
    }

    if (frame_count >= range_min && frame_count < range_max)
    {
      ParsedLine parsed_line = ParseLine(line);

      if (parsed_line.rot_error != -1.0f && parsed_line.pos_error != -1.0f)
      {
        pos_error_sum += parsed_line.pos_error;
        rot_error_sum += parsed_line.rot_error;
        error_count++;
      }

      if (parsed_line.pos_vib != -1.0f && parsed_line.rot_vib != -1.0f)
      {
        pos_vib_sum += parsed_line.pos_vib;
        rot_vib_sum += parsed_line.rot_vib;
        vib_count++;
      }

      if (parsed_line.comp_time != -1.0)
      {
        comp_time_sum += parsed_line.comp_time;
        comp_time_count++;
      }
    }

    frame_count++;
  }

  pos_error_sum /= error_count;
  rot_error_sum /= error_count;

  pos_vib_sum /= vib_count;
  rot_vib_sum /= vib_count;

  comp_time_sum /= comp_time_count;

  std::cout << "Error: p " << pos_error_sum << " r " << rot_error_sum << std::endl;
  std::cout << "Vib: p " << pos_vib_sum << " r " << rot_vib_sum << std::endl;

  if (error_stats_strings.size() <= outfile_line)
    error_stats_strings.resize(outfile_line + 1);
  error_stats_strings[outfile_line] =
    mode + "\t" + std::to_string(range_min) + "\t" + std::to_string(range_max) + "\t" +
    std::to_string(pos_error_sum) + "\t" + std::to_string(rot_error_sum) + "\t" +
    std::to_string(pos_vib_sum) + "\t" + std::to_string(rot_vib_sum) + "\t" +
    std::to_string(comp_time_sum * 1000.0);

  std::cout << "Writing file: " << errors_stats_filename << std::endl;
  std::ofstream ofile(errors_stats_filename.c_str());
  if (!ofile)
  {
    std::cout << "Could not create output file: " << errors_stats_filename << std::endl;
    std::exit(3);
  }
  for (const std::string & s : error_stats_strings)
    ofile << s << "\n";

  return 0;
}

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API