<commit_before>#include "RansacLineDetectorOnGraphs.h"

RansacLineDetectorOnGraphs::RansacLineDetectorOnGraphs()
{
  // initialize some stuff here
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:draw_edgels_field", "", false);
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:draw_lines_field", "", false);
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:fit_and_draw_circle_field", "", false);

  getDebugParameterList().add(&params);
}

RansacLineDetectorOnGraphs::~RansacLineDetectorOnGraphs()
{
  getDebugParameterList().remove(&params);
}

void RansacLineDetectorOnGraphs::execute()
{
  getLinePercept().reset();
  getLinePerceptTop().reset();

  DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:draw_edgels_field",
    FIELD_DRAWING_CONTEXT;

    for(const Edgel& e: getLineGraphPercept().edgels)
    {
      PEN("FF0000",2);

      if(e.point.x > 0 || e.point.y > 0) {
        CIRCLE(e.point.x, e.point.y, 25);
      }
      PEN("000000",0.1);
      LINE(e.point.x, e.point.y, e.point.x + e.direction.x*100.0, e.point.y + e.direction.y*100.0);
    }
  );

  graphEdgels.clear();
  graphEdgelsTop.clear();
  for (size_t subgraph_id = 0; subgraph_id<getLineGraphPercept().lineGraphs.size(); subgraph_id++) {
    std::vector<GraphEdgel> subgraphEdgels;
    subgraphEdgels.reserve(getLineGraphPercept().lineGraphs[subgraph_id].size());
    for (size_t edgel_id = 0; edgel_id<getLineGraphPercept().lineGraphs[subgraph_id].size(); edgel_id++) {
      GraphEdgel graphEdgel;
      graphEdgel.subgraph_id = subgraph_id;
      graphEdgel.edgel_id = edgel_id;
      graphEdgel.line_id = -1;
      subgraphEdgels.push_back(graphEdgel);
    }
    graphEdgels.push_back(subgraphEdgels);
  }
  for (size_t subgraph_id = 0; subgraph_id<getLineGraphPercept().lineGraphsTop.size(); subgraph_id++) {
    std::vector<GraphEdgel> subgraphEdgels;
    subgraphEdgels.reserve(getLineGraphPercept().lineGraphsTop[subgraph_id].size());
    for (size_t edgel_id = 0; edgel_id<getLineGraphPercept().lineGraphsTop[subgraph_id].size(); edgel_id++) {
      GraphEdgel graphEdgel;
      graphEdgel.subgraph_id = subgraph_id;
      graphEdgel.edgel_id = edgel_id;
      graphEdgel.line_id = -1;
      subgraphEdgels.push_back(graphEdgel);
    }
    graphEdgelsTop.push_back(subgraphEdgels);
  }

  for (std::vector<GraphEdgel>& subgraphEdgels: graphEdgels) {
    Math::LineSegment result;
    if (ransac(result, subgraphEdgels, getLineGraphPercept().lineGraphs)) {
      LinePercept::FieldLineSegment fieldLine;
      fieldLine.lineOnField = result;
      getLinePercept().extended_lines.push_back(fieldLine);

      getLinePercept().short_lines.push_back(fieldLine);
    }
  }

  for (std::vector<GraphEdgel>& subgraphEdgels: graphEdgelsTop) {
    Math::LineSegment result;
    if (ransac(result, subgraphEdgels, getLineGraphPercept().lineGraphsTop)) {
      LinePercept::FieldLineSegment fieldLine;
      fieldLine.lineOnField = result;
      getLinePerceptTop().extended_lines.push_back(fieldLine);

      // Top and Bottom graphs are provided in Bottom Line Percept
      getLinePercept().short_lines.push_back(fieldLine);
    }
  }

  DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:draw_lines_field",
    FIELD_DRAWING_CONTEXT;

    if (!getLinePercept().extended_lines.empty()) {
      for(const LinePercept::FieldLineSegment& line: getLinePercept().extended_lines)
      {
        PEN("FF0000", 30);
        LINE(
          line.lineOnField.begin().x, line.lineOnField.begin().y,
          line.lineOnField.end().x, line.lineOnField.end().y);
      }
    }
    if (!getLinePerceptTop().extended_lines.empty()) {
      for(const LinePercept::FieldLineSegment& line: getLinePerceptTop().extended_lines)
      {
        PEN("0000FF", 30);
        LINE(
          line.lineOnField.begin().x, line.lineOnField.begin().y,
          line.lineOnField.end().x, line.lineOnField.end().y);
      }
    }

    for(const std::vector<GraphEdgel>& subgraphEdgels : graphEdgels) {
      for (const GraphEdgel& ge : subgraphEdgels) {
        if(ge.line_id > -1) {
          PEN("00FF00", 5);
        } else {
          PEN("FF0000", 5);
        }
        const EdgelD& e = getLineGraphPercept().lineGraphs[ge.subgraph_id][ge.edgel_id];
        CIRCLE(e.point.x, e.point.y, 25);
      }
    }
    for(const std::vector<GraphEdgel>& subgraphEdgels : graphEdgelsTop) {
      for (const GraphEdgel& ge : subgraphEdgels) {
        if(ge.line_id > -1) {
          PEN("00FF00", 5);
        } else {
          PEN("FF0000", 5);
        }
        const EdgelD& e = getLineGraphPercept().lineGraphsTop[ge.subgraph_id][ge.edgel_id];
        CIRCLE(e.point.x, e.point.y, 25);
      }
    }
  );

  DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:fit_and_draw_circle_field",
    FIELD_DRAWING_CONTEXT;
    // fit ellipse
    Ellipse circResult;

    if (ransacEllipse(circResult, graphEdgels, getLineGraphPercept().lineGraphs)) {
      double c[2];
      circResult.getCenter(c);

      double a[2];
      circResult.axesLength(a);
<commit_msg>provide center circle<commit_after>#include "RansacLineDetectorOnGraphs.h"

RansacLineDetectorOnGraphs::RansacLineDetectorOnGraphs()
{
  // initialize some stuff here
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:draw_edgels_field", "", false);
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:draw_lines_field", "", false);
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:fit_and_draw_circle_field", "", false);
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:draw_circle_field", "", false);
  DEBUG_REQUEST_REGISTER("Vision:RansacLineDetectorOnGraphs:draw_circle_field_top", "", false);

  getDebugParameterList().add(&params);
}

RansacLineDetectorOnGraphs::~RansacLineDetectorOnGraphs()
{
  getDebugParameterList().remove(&params);
}

void RansacLineDetectorOnGraphs::execute()
{
  getLinePercept().reset();
  getLinePerceptTop().reset();

  DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:draw_edgels_field",
    FIELD_DRAWING_CONTEXT;

    for(const Edgel& e: getLineGraphPercept().edgels)
    {
      PEN("FF0000",2);

      if(e.point.x > 0 || e.point.y > 0) {
        CIRCLE(e.point.x, e.point.y, 25);
      }
      PEN("000000",0.1);
      LINE(e.point.x, e.point.y, e.point.x + e.direction.x*100.0, e.point.y + e.direction.y*100.0);
    }
  );

  graphEdgels.clear();
  graphEdgelsTop.clear();
  for (size_t subgraph_id = 0; subgraph_id<getLineGraphPercept().lineGraphs.size(); subgraph_id++) {
    std::vector<GraphEdgel> subgraphEdgels;
    subgraphEdgels.reserve(getLineGraphPercept().lineGraphs[subgraph_id].size());
    for (size_t edgel_id = 0; edgel_id<getLineGraphPercept().lineGraphs[subgraph_id].size(); edgel_id++) {
      GraphEdgel graphEdgel;
      graphEdgel.subgraph_id = subgraph_id;
      graphEdgel.edgel_id = edgel_id;
      graphEdgel.line_id = -1;
      subgraphEdgels.push_back(graphEdgel);
    }
    graphEdgels.push_back(subgraphEdgels);
  }
  for (size_t subgraph_id = 0; subgraph_id<getLineGraphPercept().lineGraphsTop.size(); subgraph_id++) {
    std::vector<GraphEdgel> subgraphEdgels;
    subgraphEdgels.reserve(getLineGraphPercept().lineGraphsTop[subgraph_id].size());
    for (size_t edgel_id = 0; edgel_id<getLineGraphPercept().lineGraphsTop[subgraph_id].size(); edgel_id++) {
      GraphEdgel graphEdgel;
      graphEdgel.subgraph_id = subgraph_id;
      graphEdgel.edgel_id = edgel_id;
      graphEdgel.line_id = -1;
      subgraphEdgels.push_back(graphEdgel);
    }
    graphEdgelsTop.push_back(subgraphEdgels);
  }

  for (std::vector<GraphEdgel>& subgraphEdgels: graphEdgels) {
    Math::LineSegment result;
    if (ransac(result, subgraphEdgels, getLineGraphPercept().lineGraphs)) {
      LinePercept::FieldLineSegment fieldLine;
      fieldLine.lineOnField = result;
      getLinePercept().extended_lines.push_back(fieldLine);

      getLinePercept().short_lines.push_back(fieldLine);
    }
  }

  for (std::vector<GraphEdgel>& subgraphEdgels: graphEdgelsTop) {
    Math::LineSegment result;
    if (ransac(result, subgraphEdgels, getLineGraphPercept().lineGraphsTop)) {
      LinePercept::FieldLineSegment fieldLine;
      fieldLine.lineOnField = result;
      getLinePerceptTop().extended_lines.push_back(fieldLine);

      // Top and Bottom graphs are provided in Bottom Line Percept
      getLinePercept().short_lines.push_back(fieldLine);
    }
  }

  Ellipse circResult;

  getLinePercept().middleCircleWasSeen = false;

  if (ransacEllipse(circResult, graphEdgels, getLineGraphPercept().lineGraphs)) {
    getLinePercept().middleCircleWasSeen = true;

    double c[2];
    circResult.getCenter(c);
    getLinePercept().middleCircleCenter.x = c[0];
    getLinePercept().middleCircleCenter.y = c[1];

    DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:draw_circle_field",
      FIELD_DRAWING_CONTEXT;
      double a[2];
      circResult.axesLength(a);

      PEN("009900", 50);

      CIRCLE(c[0], c[1], 30);
      OVAL_ROTATED(c[0], c[1], a[0], a[1], circResult.rotationAngle());
    );
  }

  if (ransacEllipse(circResult, graphEdgelsTop, getLineGraphPercept().lineGraphsTop)) {
    getLinePercept().middleCircleWasSeen = true;

    double c[2];
    circResult.getCenter(c);
    getLinePercept().middleCircleCenter.x = c[0];
    getLinePercept().middleCircleCenter.y = c[1];

    DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:draw_circle_field_top",
      FIELD_DRAWING_CONTEXT;
      double a[2];
      circResult.axesLength(a);

      PEN("009900", 50);

      CIRCLE(c[0], c[1], 30);
      OVAL_ROTATED(c[0], c[1], a[0], a[1], circResult.rotationAngle());
    );
  }

  if (ransacEllipse(circResult, graphEdgels, getLineGraphPercept().lineGraphs)) {
    double c[2];
    circResult.getCenter(c);

    double a[2];
    circResult.axesLength(a);
  }


  DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:draw_lines_field",
    FIELD_DRAWING_CONTEXT;

    if (!getLinePercept().extended_lines.empty()) {
      for(const LinePercept::FieldLineSegment& line: getLinePercept().extended_lines)
      {
        PEN("FF0000", 30);
        LINE(
          line.lineOnField.begin().x, line.lineOnField.begin().y,
          line.lineOnField.end().x, line.lineOnField.end().y);
      }
    }
    if (!getLinePerceptTop().extended_lines.empty()) {
      for(const LinePercept::FieldLineSegment& line: getLinePerceptTop().extended_lines)
      {
        PEN("0000FF", 30);
        LINE(
          line.lineOnField.begin().x, line.lineOnField.begin().y,
          line.lineOnField.end().x, line.lineOnField.end().y);
      }
    }

    for(const std::vector<GraphEdgel>& subgraphEdgels : graphEdgels) {
      for (const GraphEdgel& ge : subgraphEdgels) {
        if(ge.line_id > -1) {
          PEN("00FF00", 5);
        } else {
          PEN("FF0000", 5);
        }
        const EdgelD& e = getLineGraphPercept().lineGraphs[ge.subgraph_id][ge.edgel_id];
        CIRCLE(e.point.x, e.point.y, 25);
      }
    }
    for(const std::vector<GraphEdgel>& subgraphEdgels : graphEdgelsTop) {
      for (const GraphEdgel& ge : subgraphEdgels) {
        if(ge.line_id > -1) {
          PEN("00FF00", 5);
        } else {
          PEN("FF0000", 5);
        }
        const EdgelD& e = getLineGraphPercept().lineGraphsTop[ge.subgraph_id][ge.edgel_id];
        CIRCLE(e.point.x, e.point.y, 25);
      }
    }
  );



  DEBUG_REQUEST("Vision:RansacLineDetectorOnGraphs:fit_and_draw_circle_field",
    FIELD_DRAWING_CONTEXT;
    // fit ellipse
    Ellipse circResult;

    if (ransacEllipse(circResult, graphEdgels, getLineGraphPercept().lineGraphs)) {
      double c[2];
      circResult.getCenter(c);

      double a[2];
      circResult.axesLength(a);

{'fraction_non_alphanumeric': 0.13384141120054804, 'fraction_numerical': 0.01575612262373694, 'mean_word_length': 3.840033153750518, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '3114886', 'n_tokens_mistral': 4396, 'n_tokens_neox': 4137, 'n_words': 526}