Beispiel #1
0
/*
 * Find and mark L edges which are "covered" by the result area (if any).
 * L edges at nodes which also have A edges can be checked by checking
 * their depth at that node.
 * L edges at nodes which do not have A edges can be checked by doing a
 * point-in-polygon test with the previously computed result areas.
 */
void
LineBuilder::findCoveredLineEdges()
{
// first set covered for all L edges at nodes which have A edges too
    map<Coordinate*, Node*, CoordinateLessThen>& nodeMap = op->getGraph().getNodeMap()->nodeMap;
    map<Coordinate*, Node*, CoordinateLessThen>::iterator it = nodeMap.begin();
    map<Coordinate*, Node*, CoordinateLessThen>::iterator endIt = nodeMap.end();
    for(; it != endIt; ++it) {
        Node* node = it->second;
        //node.print(System.out);
        assert(dynamic_cast<DirectedEdgeStar*>(node->getEdges()));
        DirectedEdgeStar* des = static_cast<DirectedEdgeStar*>(node->getEdges());
        des->findCoveredLineEdges();
        //((DirectedEdgeStar*)node->getEdges())->findCoveredLineEdges();
    }

    /*
     * For all L edges which weren't handled by the above,
     * use a point-in-poly test to determine whether they are covered
     */
    vector<EdgeEnd*>* ee = op->getGraph().getEdgeEnds();
    for(size_t i = 0, s = ee->size(); i < s; ++i) {
        assert(dynamic_cast<DirectedEdge*>((*ee)[i]));
        DirectedEdge* de = static_cast<DirectedEdge*>((*ee)[i]);
        Edge* e = de->getEdge();
        if(de->isLineEdge() && !e->isCoveredSet()) {
            bool isCovered = op->isCoveredByA(de->getCoordinate());
            e->setCovered(isCovered);
        }
    }
}
Beispiel #2
0
/*
 * Removes a node from the graph, along with any associated
 * DirectedEdges and Edges.
 */
void
PlanarGraph::remove(Node *node)
{
    // unhook all directed edges
    vector<DirectedEdge*> &outEdges=node->getOutEdges()->getEdges();
    for(unsigned int i=0; i<outEdges.size(); ++i) {
        DirectedEdge *de =outEdges[i];
        DirectedEdge *sym = de->getSym();
        // remove the diredge that points to this node
        if (sym!=NULL) remove(sym);
        // remove this diredge from the graph collection
        for(unsigned int j=0; j<dirEdges.size(); ++j) {
            if (dirEdges[j]==de) {
                dirEdges.erase(dirEdges.begin()+j);
                --j;
            }
        }
        Edge *edge=de->getEdge();
        if (edge!=NULL) {
            for(unsigned int k=0; k<edges.size(); ++k) {
                if(edges[k]==edge) {
                    edges.erase(edges.begin()+k);
                    --k;
                }
            }
        }
    }
    // remove the node from the graph
    nodeMap.remove(node->getCoordinate());
    //nodes.remove(node);
}
Beispiel #3
0
void WeightedDigraph::addEdge(const DirectedEdge &e)
{
    if(e.from() >= V() || e.to() >= V())
        return;
    
    ++edgeCount;
    array[e.from()].push(e);
}
std::deque<DirectedEdge> *Djikstra::pathTo(int v){
    if(!hasPathTo(v))
         return 0;
    std::deque<DirectedEdge> *path =  new std::deque<DirectedEdge>();
    for(DirectedEdge e = edgeTo[v]; e.from() || e.to() || e.Getweight(); e =edgeTo[e.from()])
        path->push_front(e);
    return path;
}
void EdgeWeightDigraph::addEdge(const DirectedEdge &e)
{
	if (e.from() >= getArrSize())
		return;

	arr[e.from()].push_back(e);
	this->edge++; // 边的个数加1
}
Beispiel #6
0
/*
 * Removes DirectedEdge from its from-Node and from this PlanarGraph. Note:
 * This method does not remove the Nodes associated with the DirectedEdge,
 * even if the removal of the DirectedEdge reduces the degree of a Node to
 * zero.
 */
void
PlanarGraph::remove(DirectedEdge *de)
{
    DirectedEdge *sym = de->getSym();
    if (sym!=NULL) sym->setSym(NULL);
    de->getFromNode()->getOutEdges()->remove(de);
    for(unsigned int i=0; i<dirEdges.size(); ++i) {
        if(dirEdges[i]==de) {
            dirEdges.erase(dirEdges.begin()+i);
            --i;
        }
    }
}
Beispiel #7
0
/*public*/
bool
Node::isIncidentEdgeInResult() const
{
	testInvariant();

	if (!edges) return false;

	EdgeEndStar::iterator it=edges->begin();
	EdgeEndStar::iterator endIt=edges->end();
	for ( ; it!=endIt; ++it)
	{
		assert(*it);
		assert(dynamic_cast<DirectedEdge *>(*it));
		DirectedEdge *de = static_cast<DirectedEdge *>(*it);
		if ( de->getEdge()->isInResult() ) return true;
	}
	return false;
}
std::deque<DirectedEdge> *BellmanFord::pathTo(int v){
    if(!hasPathTo(v))
        return 0;
    std::deque<DirectedEdge> *path = new std::deque<DirectedEdge>();
    for(DirectedEdge e = edgeTo[v];e.from() || e.to() || e.Getweight(); e=edgeTo[e.from()] ){
        int w = e.from();
        w++;w--;
        path->push_front(e);
    }
    return path;
}