bool OBStereo::ContainsRef(const OBStereo::Refs &refs, unsigned long id) { for (ConstRefIter i = refs.begin(); i != refs.end(); ++i) if (*i == id) return true; return false; }
void OBStereo::Permutate(OBStereo::Refs &refs, int i, int j) { if (i < 0 || i >= refs.size()) return; if (j < 0 || j >= refs.size()) return; unsigned long id = refs.at(i); refs[i] = refs.at(j); refs[j] = id; }
bool hasSameWinding(const OBStereo::Refs &refs1, const OBStereo::Refs &refs2) { OB_REQUIRE( refs1.size() == 3 ); OB_REQUIRE( refs2.size() == 3 ); int Ni1 = OBStereo::NumInversions(refs1); int Ni2 = OBStereo::NumInversions(refs2); return ((Ni1 + Ni2) % 2 == 0); }
OBStereo::Refs OBStereo::Permutated(const OBStereo::Refs &refs, int i, int j) { if (i < 0 || i >= refs.size()) return refs; if (j < 0 || j >= refs.size()) return refs; OBStereo::Refs result(refs); result[i] = refs.at(j); result[j] = refs.at(i); return result; }
bool OBStereo::ContainsSameRefs(const OBStereo::Refs &refs1, const OBStereo::Refs &refs2) { if (refs1.size() != refs2.size()) return false; int count = 0; for (ConstRefIter i = refs1.begin(); i != refs1.end(); ++i) for (ConstRefIter j = refs2.begin(); j != refs2.end(); ++j) if (*i == *j) { count++; break; } return (count == refs1.size()); }
int OBStereo::NumInversions(const OBStereo::Refs &refs) { OBStereo::Refs invVec; // the inversion vector OBStereo::ConstRefIter i, j; for (i = refs.begin(); i != refs.end(); ++i) { int e = 0; // ith element // loop over elements to the right for (j = i; j != refs.end(); ++j) // increment e if element to the right is lower if (*j < *i) e++; invVec.push_back(e); } int sum = 0; for (OBStereo::RefIter k = invVec.begin(); k != invVec.end(); ++k) sum += *k; return sum; }