<commit_before>/*!
 * \bundle.cpp
 * \brief method definitions for working with bundles
 *
 * A bundle is a group of ar markers attached to an object. Bundles are defined in an xml file and
 * used by ar_track_avlar for robustness against occlusion. The bundle class defined here is used
 * for parsing these xml files to obtain information needed for projecting the bundle onto a map to
 * aid in obstacle avoidance.
 *
 * \author <NAME>, WPI - <EMAIL>
 * \date June 26, 2014
 */

#include <rail_ceiling/bundle.h>

using namespace std;

Bundle::Bundle()
{
}

bool Bundle::parseBundle(char* filepath)
{

  //TODO: This is messy. Make it cleaner.

  TiXmlDocument doc(filepath);
  if (!doc.LoadFile())
  {
    ROS_ERROR("Failed to load bundle from %s", filepath);
    return false;
  }
  TiXmlHandle hDoc(&doc);
  TiXmlElement* pElem;
  TiXmlHandle hRoot(0);

  pElem = hDoc.FirstChildElement().Element();
  if (!pElem)
    return false;
  int markerCount;
  pElem->QueryIntAttribute("markers", &markerCount);
  //ROS_INFO("%s %d",pElem->Value(),markerCount);

  // save this for later
  hRoot = TiXmlHandle(pElem);

  //first marker
  TiXmlHandle markerRoot = hRoot.FirstChild("marker");
  TiXmlElement* pMarkersNode = markerRoot.Element();

  //save marker id
  pMarkersNode->QueryIntAttribute("index", &id);
  //ROS_INFO("first %s id: %d",pMarkersNode->Value(), id);

  //save marker size
  TiXmlElement* pCornersNode = markerRoot.FirstChild().Element();
  pCornersNode->QueryFloatAttribute("x", &markerSize);
  markerSize = 2 * abs(markerSize);
  //ROS_INFO("first %s, marker size: %f",pCornersNode->Value(), markerSize);

  //go to second marker to get width and height
  float temp1;
  float temp2;
  pMarkersNode = pMarkersNode->NextSiblingElement();
  //ROS_INFO("second %s id: %d",pMarkersNode->Value(), id);
  pCornersNode = pMarkersNode->FirstChildElement();
  pCornersNode->QueryFloatAttribute("x", &temp1);
  pCornersNode = pCornersNode->NextSiblingElement();
  pCornersNode->QueryFloatAttribute("x", &temp2);
  bundleWidth = ((abs(temp1) + abs(temp2)) / 2) / 100;
  //ROS_INFO("%s %f",pCornersNode->Value(), bundleWidth);
  pCornersNode->QueryFloatAttribute("y", &temp1);
  pCornersNode = pCornersNode->NextSiblingElement();
  pCornersNode->QueryFloatAttribute("y", &temp2);
  bundleHeight = ((abs(temp1) + abs(temp2)) / 2) / 100;
  //ROS_INFO("%s %f",pCornersNode->Value(), bundleHeight);

  return true;
}
<commit_msg>Commenting<commit_after>/*!
 * \bundle.cpp
 * \brief method definitions for working with bundles
 *
 * A bundle is a group of ar markers attached to an object. Bundles are defined in an xml file and
 * used by ar_track_avlar for robustness against occlusion. The bundle class defined here is used
 * for parsing these xml files to obtain information needed for projecting the bundle onto a map to
 * aid in obstacle avoidance.
 *
 * \author <NAME>, WPI - <EMAIL>
 * \date June 26, 2014
 */

#include <rail_ceiling/bundle.h>

using namespace std;

Bundle::Bundle()
{
}

bool Bundle::parseBundle(char* filepath)
{

  //load the xml document
  TiXmlDocument doc(filepath);
  if (!doc.LoadFile())
  {
    ROS_ERROR("Failed to load bundle from %s", filepath);
    return false;
  }
  TiXmlHandle hDoc(&doc);
  TiXmlElement* pElem;
  TiXmlHandle hRoot(0);

  //get the first xml element in the document
  pElem = hDoc.FirstChildElement().Element();
  if (!pElem)
    return false;
  int markerCount;
  pElem->QueryIntAttribute("markers", &markerCount);
  //ROS_INFO("%s %d",pElem->Value(),markerCount);

  // save the root for later
  hRoot = TiXmlHandle(pElem);

  //find first marker
  TiXmlHandle markerRoot = hRoot.FirstChild("marker");
  TiXmlElement* pMarkersNode = markerRoot.Element();

  //save marker id
  pMarkersNode->QueryIntAttribute("index", &id);
  //ROS_INFO("first %s id: %d",pMarkersNode->Value(), id);

  //save marker size
  TiXmlElement* pCornersNode = markerRoot.FirstChild().Element();
  pCornersNode->QueryFloatAttribute("x", &markerSize);
  markerSize = 2 * abs(markerSize);
  //ROS_INFO("first %s, marker size: %f",pCornersNode->Value(), markerSize);

  //go to second marker, calculate bundle width and height
  float temp1;
  float temp2;
  pMarkersNode = pMarkersNode->NextSiblingElement();
  //ROS_INFO("second %s id: %d",pMarkersNode->Value(), id);
  pCornersNode = pMarkersNode->FirstChildElement();
  pCornersNode->QueryFloatAttribute("x", &temp1);
  pCornersNode = pCornersNode->NextSiblingElement();
  pCornersNode->QueryFloatAttribute("x", &temp2);
  bundleWidth = ((abs(temp1) + abs(temp2)) / 2) / 100;
  //ROS_INFO("%s %f",pCornersNode->Value(), bundleWidth);
  pCornersNode->QueryFloatAttribute("y", &temp1);
  pCornersNode = pCornersNode->NextSiblingElement();
  pCornersNode->QueryFloatAttribute("y", &temp2);
  bundleHeight = ((abs(temp1) + abs(temp2)) / 2) / 100;
  //ROS_INFO("%s %f",pCornersNode->Value(), bundleHeight);

  ROS_INFO("Loaded bundle from %s {ar_id=%d marker_size=%f bundle_width=%f bundle_height=%f}", filepath, id, markerSize,
           bundleWidth, bundleHeight);

  return true;
}

{'fraction_non_alphanumeric': 0.14173073132268874, 'fraction_numerical': 0.010250344963532427, 'mean_word_length': 4.5514223194748356, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3461060', 'n_tokens_mistral': 1749, 'n_tokens_neox': 1641, 'n_words': 444}