int HexGridFitting::getBinarycode()

in IsometricPatternMatcher/HexGridFitting.cpp [730:755]


int HexGridFitting::getBinarycode(
    const Eigen::Vector2i& centerRQ,
    int layer) {  // the number of layers that the neighours are used to
                  // deternmine the binary code of the center
  std::vector<double> colorNeighbour;
  for (int r = -layer; r <= layer; ++r) {
    for (int q = -layer; q <= layer; ++q) {
      if (r + q >= -layer && r + q <= layer && r + centerRQ.x() >= 0 &&
          r + centerRQ.x() < indexMap_.rows() && q + centerRQ.y() >= 0 &&
          q + centerRQ.y() < indexMap_.cols()) {
        if (indexMap_(r + centerRQ.x(), q + centerRQ.y()) != -1)
          colorNeighbour.push_back(
              intensity_(indexMap_(r + centerRQ.x(), q + centerRQ.y())));
      }
    }                               // end c
  }                                 // end r
  if (colorNeighbour.size() > 2) {  // more than two neighbours
    std::sort(colorNeighbour.begin(), colorNeighbour.end());
    double colorMedian =
        (*colorNeighbour.begin() + colorNeighbour.back()) / 2.0;
    return intensity_(indexMap_(centerRQ.x(), centerRQ.y())) > colorMedian ? 1
                                                                           : 0;
  } else {
    return 2;
  }
}