C++ (Qt)struct CMesh { void Append( const CMesh & ); // импорт данных void Clear( void ); // освобождает память занимаемую данными CShape * CreateShape( void ) const; // создает др. (внешнюю) структуру // данные float mFriction;//... контейнеры и.т.п};typedef std::vector <CMesh *> TMeshPtrVec;typedef std::vector <CShape *> TShapePtrVec;
C++ (Qt)// staticvoid CMesh::CreateShapes( TMeshPtrVec & mesh, TShapePtrVec & shape ){ ...}
C++ (Qt)bool myBinaryPredicate(CMesh* a, CMesh* b) { return (a->mFriction == b->mFriction);} bool compare (CMesh* a, CMesh* b) { return (a->mFriction < b->mFriction); } void CMesh::CreateShapes( TMeshPtrVec & mesh, TShapePtrVec & shape ){ TMeshPtrVec v = mesh; TMeshPtrVec::iterator it = unique_copy (mesh.begin(), mesh.end(), v.begin(), myBinaryPredicate); sort (v.begin(), it, compare); it=unique_copy (v.begin(), it, v.begin(), myBinaryPredicate); v.resize( it - v.begin()); /* v - теперь содержит указатели на CMesh c уникальными значениями mFriction *//* Дальше все действия с ним.. */}
C++ (Qt)bool CompareFriction( const CMesh * m0, const CMesh * m1 ){ return m0->mFriction < m1->mFriction;} bool NextRange( const TMeshPtrVec & vec, size_t & beg, size_t & end ){ if (end >= vec.size()) return false; beg = end; for (end = beg + 1; end < vec.size(); ++end) if (vec[end]->mFriction != vec[beg]->mFriction) break; return true;} void CMesh::CreateShapes( TMeshPtrVec & mesh, TShapePtrVec & shape ){ std::sort(mesh.begin(), mesh.end(), CompareFriction); size_t beg, end = 0; while (NextRange(vec, beg, end)) { for (size_t i = beg + 1; i < end; ++i) { vec[beg]->Append(*vec[i]); vec[i]->Clear(); } shape.push_back(vec[beg]->CreateShape()); }}
C++ (Qt)class MyFunctor{public: CMesh * operator()(CMesh *a, CMesh *b) { if ((a->mFriction == b->mFriction) && (a->mFriction == m_unique_friction.back()) && m_tag) { a->Append(b); b->Clear(); return a; } return 0; } bool frictionIsContains(float f) { vector<double>::iterator it = find(m_unique_friction.begin(), m_unique_friction.end(), f); if (it != m_unique_friction.end()) { m_unique_friction.push_back(f); m_tag = true; return m_tag; } m_tag = false; return m_tag;}private:vector<float> m_unique_friction;bool m_tag;}; void CMesh::CreateShapes( TMeshPtrVec & mesh, TShapePtrVec & shape ){ TMeshPtrVec::iterator it = mesh.begin(); MyFunctor func; for (; it != mesh.end(); ++it) { if (!func.frictionIsContains((*it)->mFriction)) continue; CMesh *cm = accumulate(it, mesh.end(), func); shape.push_back(cm->CreateShape()); }}
C++ (Qt).. CMesh *cm = accumulate(it, mesh.end(), func);..
C++ (Qt) CMesh *cm = accumulate(it, mesh.end(), *it, func);
C++ (Qt)class MyFunctor{public: CMesh * operator()(CMesh *a, CMesh *b) { if ((a->mFriction == b->mFriction) && (a->mFriction == m_unique_friction.back()) && m_tag) { a->Append(b); b->Clear(); } return a; } bool frictionIsContains(float f) { vector<float>::iterator it = find(m_unique_friction.begin(), m_unique_friction.end(), f); if (it == m_unique_friction.end()) { m_unique_friction.push_back(f); m_tag = true; return !m_tag; } m_tag = false; return !m_tag;}private:vector<float> m_unique_friction;bool m_tag;}; void CMesh::CreateShapes( TMeshPtrVec & mesh, TShapePtrVec & shape ){ TMeshPtrVec::iterator it = mesh.begin(); MyFunctor func; for (; it != mesh.end(); ++it) { if (func.frictionIsContains((*it)->mFriction)) continue; CMesh *cm = accumulate(it, mesh.end(), *it, func); shape.push_back(cm->CreateShape()); }}