bool IsVectorOfImplicationsIdentical(std::vector<FCA::Implication> v1, std::vector<FCA::Implication> v2) { std::vector<std::pair<std::vector<std::string>, std::vector<std::string> > > v1p(v1.size()), v2p(v2.size()); for (size_t i = 0; i < v1.size(); ++i) { v1p[i].first = v1[i].Premise(); v1p[i].second = v1[i].Conclusion(); } for (size_t i = 0; i < v2.size(); ++i) { v2p[i].first = v2[i].Premise(); v2p[i].second = v2[i].Conclusion(); } std::sort(v1p.begin(), v1p.end()); std::sort(v2p.begin(), v2p.end()); for (size_t i = 0; i < v1p.size(); ++i) { std::sort(v1p[i].first.begin(), v1p[i].first.end()); std::sort(v1p[i].second.begin(), v1p[i].second.end()); } for (size_t i = 0; i < v1p.size(); ++i) { std::sort(v2p[i].first.begin(), v2p[i].first.end()); std::sort(v2p[i].second.begin(), v2p[i].second.end()); } return v1p == v2p; }
bool RenderableObject::IsInstance(RenderableObject& model) { // First test is the number of indices if (m_indices_size != model.m_indices_size) return false; // Second test is the number of buffers if (m_buffers.size() != model.m_buffers.size()) return false; // Third test buffers size for (BufferMap::const_iterator it = m_buffers.begin(); it != m_buffers.end(); it++) { BufferMap::const_iterator it2 = model.m_buffers.find(it->first); if (it2 == model.m_buffers.end()) return false; if (it2->second.dimension != it->second.dimension) return false; if (it2->second.size != it->second.size) return false; } // Last step : Check buffer contents // * Check if they needs to compute the transformation bool needTransformation = false; Math::CMatrix4 transformationMatrix; if (m_buffers.find(VERTEX_ATTRIBUT) != m_buffers.end() && m_buffers[VERTEX_ATTRIBUT].size >= 11) { Logger::Log() << "[INFO] Try to find the transformations ... \n"; RenderableBuffer b1 = m_buffers[VERTEX_ATTRIBUT]; RenderableBuffer b2 = model.m_buffers[VERTEX_ATTRIBUT]; if (b1.buffer[0] != b2.buffer[0]) { needTransformation = true; // Frist matrix Math::TVector3F v1(b1.buffer[0], b1.buffer[1], b1.buffer[2]); Math::TVector3F v2(b1.buffer[3], b1.buffer[4], b1.buffer[5]); Math::TVector3F v3(b1.buffer[6], b1.buffer[7], b1.buffer[8]); Math::TVector3F v4 = v1 + ((v2 - v1) ^ (v3 - v1)); Math::CMatrix4 t1(v1.x, v2.x, v3.x, v4.x, v1.y, v2.y, v3.y, v4.y, v1.z, v2.z, v3.z, v4.z, 1, 1, 1, 1); // second matrix Math::TVector3F v1p(b2.buffer[0], b2.buffer[1], b2.buffer[2]); Math::TVector3F v2p(b2.buffer[3], b2.buffer[4], b2.buffer[5]); Math::TVector3F v3p(b2.buffer[6], b2.buffer[7], b2.buffer[8]); Math::TVector3F v4p = v1p + ((v2p - v1p) ^ (v3p - v1p)); Math::CMatrix4 t2(v1p.x, v2p.x, v3p.x, v4p.x, v1p.y, v2p.y, v3p.y, v4p.y, v1p.z, v2p.z, v3p.z, v4p.z, 1, 1, 1, 1); transformationMatrix = t1.Inverse() * t2; Logger::Log() << "[INFO] Transform matrice : \n" << transformationMatrix; } } for (BufferMap::const_iterator it = m_buffers.begin(); it != m_buffers.end(); it++) { BufferMap::const_iterator it2 = model.m_buffers.find(it->first); Logger::Log() << "[INFO] INSTANCE : " << it->first << " buffer check instance ... \n"; for (int i = 0; i < it->second.size; i++) { if (!needTransformation) { if (it->second.buffer[i] != it2->second.buffer[i]) { Logger::Log() << "[INFO] Buffer difference detected : " << i << " ( " << it->second.buffer[i] << " != " << it2->second.buffer[i] << " )\n"; return false; } } else { if (it->first == VERTEX_ATTRIBUT || it->first == NORMAL_ATTRIBUT || it->first == TANGENT_ATTRIBUT || it->first == BITANGENT_ATTRIBUT) { // Construct the Vector Math::TVector4F v1(it->second.buffer[i], it->second.buffer[i + 1], it->second.buffer[i + 2], 1.0); Math::TVector4F v2(it2->second.buffer[i], it2->second.buffer[i + 1], it2->second.buffer[i + 2], 1.0); Math::TVector4F vTrans = transformationMatrix.Transform(v1); vTrans /= vTrans.w; if (v2 != vTrans) { Logger::Log() << "[INFO] Buffer difference detected : " << i << " ( " << v2 << " != " << vTrans << " )\n"; return false; } // Must add two steps i += 2; } else { // XXX: Somes copy from other tests if (it->second.buffer[i] != it2->second.buffer[i]) { Logger::Log() << "[INFO] Buffer difference detected : " << i << " ( " << it->second.buffer[i] << " != " << it2->second.buffer[i] << " )\n"; return false; } } } } } // All tests is Ok so Model is an instance return true; }