static bool reduceGraphEquivalences(NGHolder &g, EquivalenceType eq_type) { // create a list of equivalence classes to check WorkQueue work_queue(num_vertices(g)); // get information on every vertex in the graph // new vertices are allocated here, and stored in infos ptr_vector<VertexInfo> infos = getVertexInfos(g); // partition the graph auto classes = partitionGraph(infos, work_queue, g, eq_type); // do equivalence processing equivalence(classes, work_queue, eq_type); // replace equivalent classes with single vertices // new vertices are (possibly) allocated here, and stored in infos return mergeEquivalentClasses(classes, infos, g); }
int CXXSurface::upLoadSphere(CXXSphereElement &theSphere, double probeRadius, const int sense){ int oldVertexCount; CXXCoord theCentre = theSphere.centre(); vector<int, CXX::CXXAlloc<int> > equivalence(theSphere.nVertices()); vector<int, CXX::CXXAlloc<int> > uniqueAndDrawn(theSphere.nVertices()); int nDrawn = 0; for (unsigned i=0; i< theSphere.nVertices(); i++){ CXXCoord comp1(theSphere.vertex(i).vertex()); uniqueAndDrawn[i] = 0; if (theSphere.vertex(i).doDraw()){ uniqueAndDrawn[i] = 1; if (uniqueAndDrawn[i]){ equivalence[i] = nDrawn++; } } } static const std::string vertexName("vertices"); static const std::string accessiblesName("accessibles"); static const std::string normalsName("normals"); { oldVertexCount = numberOfVertices(); vertices.resize(oldVertexCount+nDrawn); int verticesHandle = getVectorHandle(vertexName); int accessiblesHandle = getVectorHandle(accessiblesName); int normalsHandle = getVectorHandle(normalsName); int iDraw = 0; for (unsigned int i=0; i< theSphere.nVertices(); i++){ if (uniqueAndDrawn[i]){ CXXCoord vertexCoord = theSphere.vertex(i).vertex(); if (sense == CXXSphereElement::Contact){ vertices[oldVertexCount+iDraw].setCoord(accessiblesHandle, vertexCoord); CXXCoord normal = vertexCoord - theCentre; CXXCoord diff(normal); diff *= (theSphere.radius() - probeRadius) / theSphere.radius(); normal.normalise(); vertices[oldVertexCount+iDraw].setCoord(normalsHandle, normal); CXXCoord vertex = theCentre + diff; vertices[oldVertexCount+iDraw].setCoord(verticesHandle, vertex); } else if (sense == CXXSphereElement::Reentrant) { vertices[oldVertexCount+iDraw].setCoord(verticesHandle, vertexCoord); CXXCoord normal = theCentre - vertexCoord; normal.normalise(); vertices[oldVertexCount+iDraw].setCoord(normalsHandle, normal); vertices[oldVertexCount+iDraw].setCoord(accessiblesHandle, theCentre); } else if (sense == CXXSphereElement::VDW) { vertices[oldVertexCount+iDraw].setCoord(verticesHandle, vertexCoord); CXXCoord normal = vertexCoord - theCentre; normal.normalise(); vertices[oldVertexCount+iDraw].setCoord(normalsHandle, normal); vertices[oldVertexCount+iDraw].setCoord(accessiblesHandle, vertexCoord+normal); } else if (sense == CXXSphereElement::Accessible) { vertices[oldVertexCount+iDraw].setCoord(verticesHandle, vertexCoord); CXXCoord normal = vertexCoord - theCentre; normal.normalise(); vertices[oldVertexCount+iDraw].setCoord(normalsHandle, normal); vertices[oldVertexCount+iDraw].setCoord(accessiblesHandle, vertexCoord); } iDraw++; } } } //Add atom pointers to the surface { void *atomBuffer[nDrawn];// = new void*[nDrawn]; int iDraw = 0; for (unsigned int i=0; i< theSphere.nVertices(); i++){ if (uniqueAndDrawn[i]){ mmdb::PAtom anAtom; if ((anAtom = theSphere.vertex(i).getAtom())!=0 ){ atomBuffer[iDraw] = (void *) anAtom; } else atomBuffer[iDraw] = (void *) theSphere.getAtom(); iDraw++; } } updateWithPointerData(nDrawn, "atom", oldVertexCount, atomBuffer); //delete [] atomBuffer; } // Add triangles to surface { int triangleBuffer[theSphere.nFlatTriangles()*3];// = new int[theSphere.nFlatTriangles()*3]; int drawCount = 0; std::list<CXXSphereFlatTriangle, CXX::CXXAlloc<CXXSphereFlatTriangle> >::const_iterator trianglesEnd = theSphere.getFlatTriangles().end(); for (std::list<CXXSphereFlatTriangle, CXX::CXXAlloc<CXXSphereFlatTriangle> >::const_iterator triangle = theSphere.getFlatTriangles().begin(); triangle != trianglesEnd; ++triangle){ const CXXSphereFlatTriangle &theTriangle(*triangle); if (theTriangle.doDraw()){ if (sense == CXXSphereElement::Contact || sense == CXXSphereElement::VDW || sense == CXXSphereElement::Accessible){ for (unsigned int j=0; j<3; j++){ int index = equivalence[theTriangle[2-j]]; triangleBuffer[3*drawCount+j] = index + oldVertexCount; } } else { for (unsigned int j=0; j<3; j++){ int index = equivalence[theTriangle[j]]; triangleBuffer[3*drawCount+j] = index + oldVertexCount; } } drawCount++; } } extendTriangles(triangleBuffer, drawCount); //delete [] triangleBuffer; } return 0; }