std::vector<CEdge> CPathFinder::getAllEdges() const { std::vector<CEdge> edges; for (size_t first = 0; first < pointsAmount; ++first) { for (size_t second = first + 1; second < pointsAmount; ++second) { edges.push_back(CEdge(first, second, calculateDistance(points[first], points[second]))); } } return edges; }
void CGraph::addEdge(int fromIndex , int toIndex, int length, bool bDirected) { if(mCount == 0 ) AppUtility::showAssert ("Zero mCount, Set #of Graph vertices"); CAdjecencyNode * pNode = new CAdjecencyNode(toIndex,length); mAdjList[fromIndex].m_Nodes.push_back(pNode); if (mbNeedEdgeAsDataModel) { mEdgeList.push_back(CEdge(fromIndex,toIndex,length)); } if(!bDirected) { //Adding edge from 'To' to 'From' CAdjecencyNode * pNode = new CAdjecencyNode(fromIndex,length); mAdjList[toIndex].m_Nodes.push_back(pNode); if (mbNeedEdgeAsDataModel) { mEdgeList.push_back(CEdge(toIndex,fromIndex,length)); } } }
// Find Coarse Edges list<CVertex> CMeshCreation::InitPolygon(list<CVertex> pList) { mEdgeLength = 0.05f; CVertex st = *pList.begin(); dt.insert(Point2(st.mPos[0], st.mPos[1])); CVertex ed; m2DMesh.mVertexList.push_back(st); for (list<CVertex>::iterator it = pList.begin(); it != pList.end(); it++) { ed = *it; float len = (ed.mPos[0] - st.mPos[0])*(ed.mPos[0] - st.mPos[0]) + (ed.mPos[1] - st.mPos[1])*(ed.mPos[1] - st.mPos[1]); if (len > mEdgeLength*mEdgeLength) { m2DMesh.mVertexList.push_back(CVertex(ed)); m2DMesh.mEdgeList.push_back(CEdge(m2DMesh.mVertexList.size() - 1, m2DMesh.mVertexList.size())); Point2 p0(st.mPos[0], st.mPos[1]); Point2 p1(ed.mPos[0], ed.mPos[1]); dt.insert(p1); vSegments.push_back(Segment2(p0, p1)); st = ed; } } // st + ed st = *pList.begin(); ed = m2DMesh.mVertexList.back(); m2DMesh.mVertexList.push_back(st); Point2 p0(st.mPos[0], st.mPos[1]); Point2 p1(ed.mPos[0], ed.mPos[1]); //dt.insert(p0); vSegments.push_back(Segment2(p1, p0)); return m2DMesh.mVertexList; }
void CGraph::addEdgeUndirected(const CEdge &newEdge) { addEdge(newEdge); addEdge(CEdge(newEdge.secondVertexIndex, newEdge.firstVertexIndex, newEdge.weight)); }
bool ClipMesh::processFaces( const Plane& clippingPlane ) { // the mesh straddles the plane. a new convex polygon face will be // generated. add it now and insert edges when they are visited. const size_t fNew = _faces.size(); _faces.push_back(CFace()); CFace& faceNew = _faces[fNew]; faceNew.normal = -clippingPlane.normal; // process the faces for( unsigned int currFace = 0; currFace < fNew; ++currFace ) { CFace& face = _faces[currFace]; if( !face.visible ) { continue; } // determine if the face is on the negative side, the positive side, // or split by the clipping plane. the occurs members are set to zero // to help find the end points of the polyline that results from clipping // a face. //assert(face.edges.size() >= 2 ); // unexpected condition if( face.edges.size() < 2 ) { return false; } std::set<int>::const_iterator iter = face.edges.begin(); const std::set<int>::const_iterator end = face.edges.end(); while( iter != end ) { const int e = *iter++; CEdge& edge = _edges[e]; //assert(edge.visible); // unexpected condition if( !edge.visible ) { return false; } _vertices[edge.vertex[0]].occurs = 0; _vertices[edge.vertex[1]].occurs = 0; } int vStart; int vFinal; if( getOpenPolyline(face, vStart, vFinal) ) { // polyline is open, close it up const size_t eNew = _edges.size(); _edges.push_back(CEdge()); CEdge& edgeNew = _edges[eNew]; edgeNew.vertex[0] = vStart; edgeNew.vertex[1] = vFinal; edgeNew.faces[0] = currFace; edgeNew.faces[1] = fNew; // add new edge to polygons face.edges.insert(eNew); faceNew.edges.insert(eNew); } } // process 'faceNew' to make sure it is a simple polygon (theoretically // convex, but numerically may be slightly not convex). floating-point // round-off errors can cause the new face from the last loop to be // needle-like with a collapse of two edges into a single edge. this // block guarantees the invariant face is always a simple polygon. if( !postProcess(fNew, faceNew) ) { return false; } if( faceNew.edges.size() < 3 ) { // face is completely degenerate, remote it from mesh _faces.pop_back(); } return true; }