in IsometricPatternMatcher/HexGridFitting.cpp [554:583]
int HexGridFitting::determineRotation(const Eigen::Matrix3Xi& cubeCoor1,
const Eigen::Matrix3Xi& cubeCoor2,
const Eigen::Matrix3Xi& cubeCoorDiff) {
CHECK(cubeCoor1.cols() == cubeCoor2.cols())
<< "cubeCoor should have same size";
size_t rotIdx = 0; // number of left 60 degree
Eigen::VectorXi inlierNumber(6);
inlierNumber.fill(0);
for (int i = 0; i < cubeCoor1.cols(); i++) {
if ((cubeCoor1(0, i) != std::numeric_limits<int>::max()) &&
(cubeCoor2(0, i) != std::numeric_limits<int>::max())) {
// we only use shared dot to determine the rotation
for (rotIdx = 0; rotIdx < 6; ++rotIdx) {
if (cubeCoor1.col(i) ==
doLeftRotate(cubeCoor2.col(i), rotIdx) + cubeCoorDiff) {
inlierNumber(rotIdx) += 1;
}
}
}
}
// determine best rotation index
int bestNumber = 0;
for (int i = 0; i < 6; ++i) {
if (bestNumber < inlierNumber(i)) {
bestNumber = inlierNumber(i);
rotIdx = i;
}
}
return rotIdx;
}