Esempio n. 1
0
/**
 * Returns whether two vertices are connected in the graph.
 * @param u - one vertex
 * @param v - another vertex
 * @param functionName - the name of the calling function to return
 *  in the event of an error
 */
void Graph::assertConnected(Vertex u, Vertex v, string functionName) const
{
    EdgeMap uEdges = graph.at(u);
    if (uEdges.find(v) == uEdges.end())
        error(functionName + " called on unconnected vertices");

    EdgeMap vEdges = graph.at(v);
    if (vEdges.find(u) == vEdges.end())
        error(functionName + " called on unconnected vertices");
}
Esempio n. 2
0
void makeEdgeMap(int num_tris, const int3 tri_ndxs[],
                 int num_verts, const float3 v[])
{
    for (int i=0; i<num_tris; i++) {
        for (int j=0; j<3; j++) {
            Edge e(v[tri_ndxs[i][j]], v[tri_ndxs[i][(j+1)%3]]);
            EdgeMap::iterator e_iter = edge_map.find(e);
            if (e_iter != edge_map.end()) {
                e_iter->second.push_back(i);
            } else {
                FaceList face_list(1,i);
                edge_map[e] = face_list;
            }
        }
    }

    for (int i=0; i<num_tris; i++) {
        printf("tri: %d\n", i);
        for (int j=0; j<3; j++) {
            printf("  edg: %d\n", j);
            pair<int,int> ndx(tri_ndxs[i][j], tri_ndxs[i][(j+1)%3]);
            if (ndx.first > ndx.second) {
                std::swap(ndx.first, ndx.second);
            }
            Edge e(v[ndx.first], v[ndx.second]);
            FaceList face_list = edge_map[e];
            for (FaceList::iterator iter = face_list.begin(); iter != face_list.end(); iter++) {
                int face = *iter;
                if (face != i) {
                    printf("    other %d\n", face);
                    bool found_match = false;
                    for (int z=0; z<3; z++) {
                        pair<int,int> ndx2(tri_ndxs[face][z], tri_ndxs[face][(z+1)%3]);
                        if (ndx2.first > ndx2.second) {
                            std::swap(ndx2.first, ndx2.second);
                        }

                        if (ndx == ndx2) {
                            printf("match\n");
                            found_match = true;
                            break;
                        }
                    }
                    if (!found_match) {
                        int3 ndxs = tri_ndxs[face];
                        for (int z=0; z<3; z++) {
                            if (all(e.v0 == v[ndxs[z]])) {
                                printf("        ndx=%d\n", z);
                            } else if (all(e.v1 == v[ndxs[z]])) {
                                printf("        ndx=%d\n", z);
                            }
                        }
                    }
                }
            }
        }
    }
}
Esempio n. 3
0
 /**
 * Return first path found from start vertex to end vertex
 * as a vector of edges, or NULL of no such path is found.
 */
 bool findDfsVertexPath(vector<Vertex*> &path, Vertex *start, const Vertex *end) const
 {
     path.clear();
     if (mEdges.find(start) != mEdges.end()) {
         path.push_back(start);
         return findDfsVertexPathRec(path, end);
     }
     return false;
 }
Esempio n. 4
0
 /**
 * Return first path found from start vertex to end vertex
 * as a vector of edges, or NULL of no such path is found.
 */
 bool findDfsVertexPathMarking(vector<Vertex*> &path, Vertex *start, const Vertex *end)
 {
     mMarks.clear();
     path.clear();
     if (mEdges.find(start) != mEdges.end()) {
         mMarks.insert(start);
         path.push_back(start);
         return findDfsVertexPathMarkingRec(path, end);
     }
     return false;
 }
Esempio n. 5
0
 /**
 *  Add an edge if both vertices are non-NULL and distinct
 */
 bool addEdge(Vertex *vertA, Vertex *vertB) 
 {
     if (vertA == NULL || vertB == NULL || vertA == vertB)
         return false;                   // no side effects on failure
     addVertex(vertA);
     addVertex(vertB);
     if (mEdges.find(vertA) == mEdges.end()) {
         mEdges.insert(EdgeMap::value_type(vertA, new VertSet()));
     }
     VertSet *nexts = mEdges.at(vertA);
     return   nexts->insert(vertB).second;
 }
Esempio n. 6
0
void edgemapwork(void){
    EdgeMap::const_iterator iter;
    //set up halfedge sym pointer
    for(iter = edgemap.begin(); iter != edgemap.end(); iter++){
	EdgeMap::const_iterator iter1;
	EdgeMap::const_iterator iter2;
	Pair p1(iter->first.a,iter->first.b);
	Pair p2(iter->first.b,iter->first.a);
	iter1 = edgemap.find(p1);
	iter2 = edgemap.find(p2);
	iter2->second->sym = iter1->second;
    }	
}
Esempio n. 7
0
 /**
  * Find best predecessor found so far to the specified node
  *
  * @param n Node as destination to find best predecessor for
  *
  * @return Predecessor node
  */
 gcc_pure
 Node GetPredecessor(const Node node) const {
   // Try to find the given node in the node_parent_map
   edge_const_iterator it = edges.find(node);
   if (it == edges.end())
     // first entry
     // If the node wasn't found
     // -> Return the given node itself
     return node;
   else
     // If the node was found
     // -> Return the parent node
     return it->second.parent;
 }
Esempio n. 8
0
void PolyMesh::buildEdges( Face* f, osg::Vec3Array* refArray, EdgeMap& emap )
{
    osg::Vec3 p1, p2;
    unsigned int size = f->_pts.size();
    for ( unsigned int i=0; i<size; ++i )
    {
        unsigned int i1=(*f)(i%size), i2=(*f)((i+1)%size);
        if ( i1<refArray->size() ) p1 = (*refArray)[i1];
        else p1 = (*f)[i%size];
        if ( i2<refArray->size() ) p2 = (*refArray)[i2];
        else p2 = (*f)[(i+1)%size];

        PolyMesh::Segment p = getSegment( p1, p2 );
        if ( emap.find(p)==emap.end() )
            emap[p] = new PolyMesh::Edge( p.first, p.second );
        emap[p]->hasFace( f, true );
    }
}
Esempio n. 9
0
/**
 * Inserts an edge between two vertices.
 * A boolean is returned for use with the random graph generation.
 * Hence, an error is not thrown when it fails to insert an edge.
 * @param u - one vertex the edge is connected to
 * @param v - the other vertex the edge is connected to
 * @return whether inserting the edge was successful
 */
bool Graph::insertEdge(Vertex u, Vertex v)
{
    assertExists(u, __func__);
    assertExists(v, __func__);

    EdgeMap uEdges = graph[u];

    // "fail" silently for random graph generation
    if (uEdges.find(v) != uEdges.end())
        return false;

    Edge uEdge(u, v, -1, "");
    graph[u].insert(make_pair(v, uEdge));

    Edge vEdge(v, u, -1, "");
    graph[v].insert(make_pair(u, vEdge));

    return true;
}
void Foam::syncTools::combine
(
    EdgeMap<T>& edgeValues,
    const CombineOp& cop,
    const edge& index,
    const T& val
)
{
    typename EdgeMap<T>::iterator iter = edgeValues.find(index);

    if (iter != edgeValues.end())
    {
        cop(iter(), val);
    }
    else
    {
        edgeValues.insert(index, val);
    }
}
Esempio n. 11
0
    bool findDfsVertexPathRec(vector<Vertex*> &path, const Vertex *end) const
    {
        Vertex *lastVert = path.back();
        if (lastVert == end)
            return  true;

        if (mEdges.find(lastVert) != mEdges.end()) {
            VertSet *nexts = mEdges.at(lastVert);
            for (auto it = nexts->begin(); it != nexts->end(); ++it) {                
                path.push_back(*it);
                bool found = findDfsVertexPathRec(path, end);
                if ( found )
                    return found;
                else
                    path.pop_back();
            }
        }
        return false;
    }
Esempio n. 12
0
  /**
   * Add node to search queue
   *
   * @param n Destination node to add
   * @param pn Previous node
   * @param e Edge distance (previous to this)
   * @return false if this link was worse than an existing one
   */
  bool Push(const Node node, const Node parent, unsigned edge_value = 0) {
    // Try to find the given node n in the EdgeMap
    edge_iterator it = edges.find(node);
    if (it == edges.end())
      // first entry
      // If the node wasn't found
      // -> Insert a new node
      it = edges.insert(std::make_pair(node, Edge(parent, edge_value))).first;
    else if (it->second.value > edge_value)
      // If the node was found and the new value is smaller
      // -> Replace the value with the new one
      it->second = Edge(parent, edge_value);
    else
      // If the node was found but the new value is higher or equal
      // -> Don't use this new leg
      return false;

    q.push(Value(edge_value, it));
    return true;
  }
Esempio n. 13
0
bool Foam::triSurfaceMesh::addFaceToEdge
(
    const edge& e,
    EdgeMap<label>& facesPerEdge
)
{
    EdgeMap<label>::iterator eFnd = facesPerEdge.find(e);
    if (eFnd != facesPerEdge.end())
    {
        if (eFnd() == 2)
        {
            return false;
        }
        eFnd()++;
    }
    else
    {
        facesPerEdge.insert(e, 1);
    }
    return true;
}
Esempio n. 14
0
void facedeleter(){
    if(selectedFace >= 0){

	for(int i= selectedFace; i < numfaces-1 ; i++){
	    // basically assign it to the next face (can't delete last face though)
	    faxes[i].listEdge = faxes[i+1].listEdge;
	    faxes[i].ver = faxes[i+1].ver;
	    faxes[i].numedges = faxes[i+1].numedges;
	}
	faxes.pop_back(); // pop one out calling the destructor
	// delete pointers to this face
	for(int i = 0; i < faxes[selectedFace].numedges; i++){
	    Pair p(faxes[selectedFace].ver[(i+1) % (faxes[selectedFace].numedges)].id, faxes[selectedFace].ver[i].id);
	    EdgeMap::const_iterator iter;
	    iter = edgemap.find(p);
	    iter->second->thisface = NULL;
	}
	--numfaces;
	selectedFace = -1;
    }
}
Esempio n. 15
0
    bool findDfsVertexPathMarkingRec(vector<Vertex*> &path, const Vertex *end)
    {
        Vertex *lastVert = path.back();
        if (lastVert == end)
            return  true;

        if (mEdges.find(lastVert) != mEdges.end()) {
            VertSet *nexts = mEdges.at(lastVert);
            for (VertSet::iterator it = nexts->begin(); it != nexts->end(); ++it) {
                Vertex *vert = *it;
                if (mMarks.find(vert) == mMarks.end()) {
                    mMarks.insert(vert);
                    path.push_back(vert);
                    bool found = findDfsVertexPathMarkingRec(path, end);
                    if ( found )
                        return found;
                    else
                        path.pop_back();
                }
            }
        }
        return false;
    }