bool operator()(GroupType const& x, GroupType const& y) const { if (x->empty() || y->empty()) return true; // doesn't matter if one or both are empty; if ((*x)[0]->start() < (*y)[0]->start()) return true; if ((*x)[0]->start() > (*y)[0]->start()) return false; return (*x)[0]->stop() < (*y)[0]->stop(); }
/** * Make composite clusters from the merged groups. * @return Merged composite clusters. */ std::list<boost::shared_ptr<CompositeCluster> > makeCompositeClusters() { std::list<boost::shared_ptr<CompositeCluster> > composites; for(auto i = m_groups.begin(); i != m_groups.end(); ++i) { GroupType::value_type& labelSet = *i; auto composite = boost::make_shared<CompositeCluster>(); for(auto j = labelSet.begin(); j != labelSet.end(); ++j) { boost::shared_ptr<ICluster>& cluster = m_register[(*j)]; composite->add(cluster); } composites.push_back(composite); } return composites; }
/** * Inserts a pair of disjoint elements. Determines whether they can be used to * reorder existing sets of lables. * @param a : One part of pair * @param b : Other part of pair * @return : true if a new cluster was required for the insertion. */ bool insert(const DisjointElement &a, const DisjointElement &b) { const size_t &aLabel = a.getRoot(); const size_t &bLabel = b.getRoot(); bool newItem = true; GroupType containingAny; GroupType containingNone; // ------------- Find equivalent sets for (auto &cluster : m_groups) { if (cluster.find(aLabel) != cluster.end()) { containingAny.push_back(cluster); } else if (cluster.find(bLabel) != cluster.end()) { containingAny.push_back(cluster); } else { containingNone.push_back(cluster); // Current iterated set contains // NEITHER of these labels. It can // therfore be ignored. } } // ------------ Process equivalent sets if (containingAny.empty()) { // Neither label is yet known to any set. We must add a new set for these GroupType::value_type newSet; newSet.insert(aLabel); newSet.insert(bLabel); m_groups.push_back(newSet); } else { // At least one set already contains at least one label. We merge all such // sets into a master set. // implement copy and swap. Rebuild the sets. GroupType temp = containingNone; GroupType::value_type masterSet; masterSet.insert(aLabel); // Incase it doesn't already contain a masterSet.insert(bLabel); // Incase it doesn't already contain b for (auto &childSet : containingAny) { masterSet.insert(childSet.begin(), childSet.end()); // Build the master set. } temp.push_back(masterSet); m_groups = temp; // Swap. newItem = false; } return newItem; }