inline void PolygonMesh<ScalarParam,dimensionParam,VertexDataParam,EdgeDataParam,FaceDataParam>::set( const typename PolygonMesh<ScalarParam,dimensionParam,VertexDataParam,EdgeDataParam,FaceDataParam>::Point sVertices[], const int faceVertexIndices[]) { /* Some local typedefs: */ typedef Misc::HashTable<VertexPair,Edge*> EdgeHasher; /* Destroy existing mesh: */ numVertices=0; delete[] vertices; vertices=0; numEdges=0; delete[] edges; edges=0; numFaces=0; delete[] faces; faces=0; /* Determine number of vertices, faces and edges: */ for(const int* viPtr=faceVertexIndices;viPtr[0]>=0;++viPtr) { /* Process a single face: */ int numFaceVertices=0; while(viPtr[0]>=0) { if(numVertices<viPtr[0]+1) numVertices=viPtr[0]+1; ++numFaceVertices; ++viPtr; } ++numFaces; numEdges+=numFaceVertices; } /* Create vertices: */ vertices=new Vertex[numVertices]; for(int i=0;i<numVertices;++i) vertices[i].position=sVertices[i]; /* Create edges and faces: */ edges=new Edge[numEdges]; faces=new Face[numFaces]; Edge* ePtr=edges; Face* fPtr=faces; EdgeHasher edgeHash((numEdges*2)/3); for(const int* viPtr=faceVertexIndices;viPtr[0]>=0;++viPtr) { /* Process a single face: */ Edge* firstEdge=ePtr; Edge* lastEdge=0; int startVertexIndex=viPtr[0]; int firstVertexIndex=startVertexIndex; while(viPtr[0]>=0) { ePtr->start=&vertices[startVertexIndex]; vertices[startVertexIndex].edge=ePtr; ePtr->face=fPtr; if(lastEdge!=0) lastEdge->faceSucc=ePtr; lastEdge=ePtr; int endVertexIndex=viPtr[1]>=0?viPtr[1]:firstVertexIndex; VertexPair vp(startVertexIndex,endVertexIndex); typename EdgeHasher::Iterator opIt=edgeHash.findEntry(vp); if(opIt.isFinished()) { /* Add edge to hash table: */ edgeHash.setEntry(typename EdgeHasher::Entry(vp,ePtr)); ePtr->opposite=0; } else { /* Link edge to opposite edge: */ ePtr->opposite=opIt->getDest(); opIt->getDest()->opposite=ePtr; } startVertexIndex=endVertexIndex; ++ePtr; ++viPtr; } lastEdge->faceSucc=firstEdge; fPtr->edge=firstEdge; ++fPtr; } }
std::vector<std::vector <int> > EdgeFinder::CalcEdges(std::string agent) { int agentIndex = 0; for(std::vector<std::string>::size_type i = 0; i != namesTrans.size(); i++) { if(agent == namesTrans[i]) { agentIndex = i; break; } } /* The standard situation is that frameCount is 0; For other situations we will make if conditionals */ int frameCount = 0; // Initializing some variables and objects if(networkType == "Ego Network - Static") { frameCount = sourceCollection->GetBegin() - 1; } std::vector<MatrixMulti> currentCollection = sourceCollection->GetCollection(); std::vector<std::string> rowNames = namesTrans; // The dimension of the tables is equal to the number of names unsigned int dim = rowNames.size(); // The size of this hash table is always based on the dimensions // of the underlying matrices. HashClass edgeHash(dim); int step = 1; int max = currentCollection.size(); loadProgress = new ProgressBar(0, 1, max); loadProgress->setAttribute(Qt::WA_DeleteOnClose); loadProgress->setModal(true); loadProgress->show(); // Beginning of the loop std::vector<MatrixMulti>::iterator it; for(it = currentCollection.begin(); it != currentCollection.end(); it++) { // currentMatrix is the current adjacency matrix MatrixMulti currentMatrix = *it; const std::vector<std::vector <short> > currentData = currentMatrix.GetPartData(); std::vector<short> currentRow = currentData[agentIndex]; std::vector<short> neighbors; for(std::vector<short>::size_type i = 0; i != currentRow.size(); i++) { int currentCell = currentRow[i]; // We don't want to include self loops if(currentCell > 0 && agentIndex != i) { std::vector<int> tempVec; tempVec.push_back(agentIndex); tempVec.push_back(i); neighbors.push_back(i); /* We can use tempVec as the key name, but we'll copy it for now, because we are going to change tempVec later. Just to be sure...*/ std::vector<int> keyname = tempVec; /* Let's first check whether the keyname in question is already in use If so, then we need to check whether the edge is from the same frame In that case we don't want to do anything with it. If it is from the same frame, then the last entry in the vector at the index should be of the same value as the current value if frameCount.*/ if(edgeHash.InUse(keyname)) { std::vector<int> tempVec = edgeHash.Get(keyname); if(networkType == "Ego Network - Static") { if(tempVec[tempVec.size() - 1] != frameCount) { tempVec[2] = tempVec[2] + 1; tempVec.push_back((short)frameCount); edgeHash.Set(keyname, tempVec); } } else { if(tempVec[tempVec.size() - 2] != frameCount) { tempVec.push_back(frameCount); tempVec.push_back(currentCell); edgeHash.Set(keyname, tempVec); } } } else { if(networkType == "Ego Network - Static") { tempVec.push_back(1); tempVec.push_back(frameCount); edgeHash.Set(keyname, tempVec); } else { tempVec.push_back(frameCount); tempVec.push_back(currentCell); edgeHash.Set(keyname, tempVec); } } } } for(std::vector<int>::size_type i = 0; i != neighbors.size(); i++) { int currentNeighbor = neighbors[i]; std::vector<short> currentRow = currentData[currentNeighbor]; for(std::vector<short>::size_type j = 0; j != currentRow.size(); j++) { int currentCell = currentRow[j]; // In this case we also don't want the edge with the original ego if(currentCell > 0 && currentNeighbor != j && j != agentIndex) { std::vector<int> tempVec; tempVec.push_back(currentNeighbor); tempVec.push_back(j); sort(tempVec.begin(), tempVec.end()); std::vector<int> keyname = tempVec; if(edgeHash.InUse(keyname)) { std::vector<int> tempVec = edgeHash.Get(keyname); if(networkType == "Ego Network - Static") { if(tempVec[tempVec.size() - 1] != frameCount) { tempVec[2] = tempVec[2] + 1; tempVec.push_back(frameCount); edgeHash.Set(keyname, tempVec); } } else { if(tempVec[tempVec.size() - 2] != frameCount) { tempVec.push_back(frameCount); tempVec.push_back(currentCell); edgeHash.Set(keyname, tempVec); } } } else { if(networkType == "Ego Network - Static") { tempVec.push_back(1); tempVec.push_back(frameCount); edgeHash.Set(keyname, tempVec); } else { tempVec.push_back(frameCount); tempVec.push_back(currentCell); edgeHash.Set(keyname, tempVec); } } } } } loadProgress->setProgress(step); step++; frameCount++; } loadProgress->close(); delete loadProgress; return edgeHash.GetData(); }