int ChainSilhouetteIterator::traverse(const AdjacencyIterator& ait) { AdjacencyIterator it(ait); ViewVertex *nextVertex = getVertex(); // we can't get a NULL nextVertex here, it was intercepted before if (nextVertex->getNature() & Nature::T_VERTEX) { TVertex *tvertex = (TVertex *)nextVertex; ViewEdge *mate = (tvertex)->mate(getCurrentEdge()); while (!it.isEnd()) { ViewEdge *ve = *it; if (ve == mate) { result = ve; return 0; } ++it; } result = 0; return 0; } if (nextVertex->getNature() & Nature::NON_T_VERTEX) { //soc NonTVertex *nontvertex = (NonTVertex*)nextVertex; ViewEdge *newEdge(0); // we'll try to chain the edges by keeping the same nature... // the preseance order is : SILHOUETTE, BORDER, CREASE, SUGGESTIVE, VALLEY, RIDGE Nature::EdgeNature natures[6] = { Nature::SILHOUETTE, Nature::BORDER, Nature::CREASE, Nature::SUGGESTIVE_CONTOUR, Nature::VALLEY, Nature::RIDGE }; for (unsigned int i = 0; i < 6; ++i) { if (getCurrentEdge()->getNature() & natures[i]) { int n = 0; while (!it.isEnd()) { ViewEdge *ve = *it; if (ve->getNature() & natures[i]) { ++n; newEdge = ve; } ++it; } if (n == 1) { result = newEdge; } else { result = 0; } return 0; } } } result = 0; return 0; }
bool PushRelabel::push(uint32 vertex) { FlowEdge &edge = getCurrentEdge(vertex), &oppositeEdge = getOppositeCurrentEdge(vertex); if (edge.getResidual() <= 0 || height[edge.getFromVertex()] <= height[edge.getToVertex()]) return false; int64 delta = std::min(excess[vertex], edge.getResidual()); excess[edge.getFromVertex()] -= delta; excess[edge.getToVertex()] += delta; edge.addFlow(delta); oppositeEdge.addFlow(-delta); return true; }
int ChainPredicateIterator::traverse(const AdjacencyIterator& ait) { AdjacencyIterator it(ait); // Iterates over next edges to see if one of them respects the predicate: while (!it.isEnd()) { ViewEdge *ve = *it; if (_unary_predicate->operator()(*ve) < 0) return -1; if (_unary_predicate->result) { if (_binary_predicate->operator()(*(getCurrentEdge()), *(ve)) < 0) return -1; if (_binary_predicate->result) { result = ve; return 0; } } ++it; } result = 0; return 0; }