bool Grid::isConsistent() { bool result = true; if(Col1().isConsistent()){result=false;} if(Col2().isConsistent()){result=false;} if(Col3().isConsistent()){result=false;} if(Col4().isConsistent()){result=false;} if(Col5().isConsistent()){result=false;} if(Col6().isConsistent()){result=false;} if(Col7().isConsistent()){result=false;} if(Col8().isConsistent()){result=false;} if(Col9().isConsistent()){result=false;} if(Row1().isConsistent()){result=false;} if(Row2().isConsistent()){result=false;} if(Row3().isConsistent()){result=false;} if(Row4().isConsistent()){result=false;} if(Row5().isConsistent()){result=false;} if(Row6().isConsistent()){result=false;} if(Row7().isConsistent()){result=false;} if(Row8().isConsistent()){result=false;} if(Row9().isConsistent()){result=false;} if(GetNO().isConsistent()){result=false;} if(GetN().isConsistent()){result=false;} if(GetNE().isConsistent()){result=false;} if(GetO().isConsistent()){result=false;} if(GetC().isConsistent()){result=false;} if(GetE().isConsistent()){result=false;} if(GetSO().isConsistent()){result=false;} if(GetS().isConsistent()){result=false;} if(GetSE().isConsistent()){result=false;} return result; }
// First pass of the Union-Find labeling algorithm. Attributes labels // to zones in a forward manner (i.e. by looking only at a subset of the // neighbors). template<uint connectivity> void FirstPass(const std::vector<uint>& img, std::vector<uint>& res, uint xLen, uint yLen, std::map<uint, node *>& labToNode, uint &currLabel) { uint left, up, leftup, rightup, curr, currPos, leftC, upC, leftupC, rightupC; for (int i = 0; i < (int)yLen; ++i) { for (int j = 0; j < (int)xLen; ++j) { if (i == 0 && j == 0) continue; currPos = i * xLen + j; curr = img[currPos]; left = GetW(currPos, xLen); up = GetN(currPos, xLen); leftC = left == ERROR_CODE ? OUT_COLOR : img[left]; upC = up == ERROR_CODE ? OUT_COLOR : img[up]; std::vector<uint> match; if (leftC == curr) match.push_back(res[left]); if (upC == curr) match.push_back(res[up]); if (connectivity == 8) { leftup = GetNW(currPos, xLen); rightup = GetNE(currPos, xLen); leftupC = leftup == ERROR_CODE ? OUT_COLOR : img[leftup]; rightupC = rightup == ERROR_CODE ? OUT_COLOR : img[rightup]; if (leftupC == curr) match.push_back(res[leftup]); if (rightupC == curr) match.push_back(res[rightup]); } if (match.size() == 0) { res[currPos] = currLabel; AddLabel(currLabel, labToNode); } else { std::sort(match.begin(), match.end()); uint ref = match[0]; res[currPos] = ref; for (int i = 1; i < (int)match.size(); ++i) { if (match[i] != ref) { Union(ref, match[i], labToNode); } } } } } }
Row Grid::Row2() { RowHolder rH = GetNO().MiddleRow(), rC = GetN().MiddleRow(), rB = GetNE().MiddleRow(); return Row(rH, rC, rB); }
Row Grid::Row3() { RowHolder rH = GetNO().BottomRow(), rC = GetN().BottomRow(), rB = GetNE().BottomRow(); return Row(rH, rC, rB); }
Row Grid::Row1() { RowHolder rH = GetNO().TopRow(), rC = GetN().TopRow(), rB = GetNE().TopRow(); return Row(rH, rC, rB); }
Column Grid::Col9() { ColumnHolder sH = GetNE().RightColumn(), sC = GetE().RightColumn(), sB = GetSE().RightColumn(); return Column(sH, sC, sB); }
Column Grid::Col8() { ColumnHolder sH = GetNE().MiddleColumn(), sC = GetE().MiddleColumn(), sB = GetSE().MiddleColumn(); return Column(sH, sC, sB); }
Column Grid::Col7() { ColumnHolder sH = GetNE().LeftColumn(), sC = GetE().LeftColumn(), sB = GetSE().LeftColumn(); return Column(sH, sC, sB); }
void Grid::Print() { // Method to print the grid in the console std::cout << std::endl; // 1st row std::cout << GetNO().GetNO() << " " << GetNO().GetN() << " " << GetNO().GetNE() << " " << GetN().GetNO() << " " << GetN().GetN() << " " << GetN().GetNE() << " " << GetNE().GetNO() << " " << GetNE().GetN() << " " << GetNE().GetNE() << std::endl; // 2nd row std::cout << GetNO().GetO() << " " << GetNO().GetC() << " " << GetNO().GetE() << " " << GetN().GetO() << " " << GetN().GetC() << " " << GetN().GetE() << " " << GetNE().GetO() << " " << GetNE().GetC() << " " << GetNE().GetE() << std::endl; // 3rd row std::cout << GetNO().GetSO() << " " << GetNO().GetS() << " " << GetNO().GetSE() << " " << GetN().GetSO() << " " << GetN().GetS() << " " << GetN().GetSE() << " " << GetNE().GetSO() << " " << GetNE().GetS() << " " << GetNE().GetSE() << std::endl; // 4th row std::cout << GetO().GetNO() << " " << GetO().GetN() << " " << GetO().GetNE() << " " << GetC().GetNO() << " " << GetC().GetN() << " " << GetC().GetNE() << " " << GetE().GetNO() << " " << GetE().GetN() << " " << GetE().GetNE() << std::endl; // 5th row std::cout << GetO().GetO() << " " << GetO().GetC() << " " << GetO().GetE() << " " << GetC().GetO() << " " << GetC().GetC() << " " << GetC().GetE() << " " << GetE().GetO() << " " << GetE().GetC() << " " << GetE().GetE() << std::endl; // 6th row std::cout << GetO().GetSO() << " " << GetO().GetS() << " " << GetO().GetSE() << " " << GetC().GetSO() << " " << GetC().GetS() << " " << GetC().GetSE() << " " << GetE().GetSO() << " " << GetE().GetS() << " " << GetE().GetSE() << std::endl; // 7th row std::cout << GetSO().GetNO() << " " << GetSO().GetN() << " " << GetSO().GetNE() << " " << GetS().GetNO() << " " << GetS().GetN() << " " << GetS().GetNE() << " " << GetSE().GetNO() << " " << GetSE().GetN() << " " << GetSE().GetNE() << std::endl; // 8th row std::cout << GetSO().GetO() << " " << GetSO().GetC() << " " << GetSO().GetE() << " " << GetS().GetO() << " " << GetS().GetC() << " " << GetS().GetE() << " " << GetSE().GetO() << " " << GetSE().GetC() << " " << GetSE().GetE() << std::endl; // 9th row std::cout << GetSO().GetSO() << " " << GetSO().GetS() << " " << GetSO().GetSE() << " " << GetS().GetSO() << " " << GetS().GetS() << " " << GetS().GetSE() << " " << GetSE().GetSO() << " " << GetSE().GetS() << " " << GetSE().GetSE() << std::endl; std::cout << std::endl; }