std::map<Crag::Node, Crag::Node> CragStackCombiner::copyNodes(const Crag& source, Crag& target) { std::map<Crag::Node, Crag::Node> nodeMap; for (Crag::NodeIt i(source); i != lemon::INVALID; ++i) { Crag::Node n = target.addNode(); ExplicitVolume<unsigned char> volume = source.getVolume(i); if (!volume.getBoundingBox().isZero()) target.getVolume(n) = volume; nodeMap[i] = n; } for (Crag::EdgeIt e(source); e != lemon::INVALID; ++e) { Crag::Node u = nodeMap[source.u(e)]; Crag::Node v = nodeMap[source.v(e)]; target.addAdjacencyEdge(u, v); } for (Crag::SubsetArcIt a(source); a != lemon::INVALID; ++a) { Crag::Node s = nodeMap[source.toRag(source.getSubsetGraph().source(a))]; Crag::Node t = nodeMap[source.toRag(source.getSubsetGraph().target(a))]; target.addSubsetArc(s, t); } return nodeMap; }
std::set<Crag::Node> collectLeafNodes(const Crag& crag, Crag::Node n) { std::set<Crag::Node> leafNodes; if (crag.isLeafNode(n)) { leafNodes.insert(n); } else { for (Crag::SubsetInArcIt e(crag, crag.toSubset(n)); e != lemon::INVALID; ++e) { Crag::Node child = crag.toRag(crag.getSubsetGraph().source(e)); std::set<Crag::Node> leafs = collectLeafNodes(crag, child); for (Crag::Node l : leafs) leafNodes.insert(l); } } return leafNodes; }