コード例 #1
0
IndexArrayPtr PGL::determine_faces_from_edges(const Point2ArrayPtr& points, const std::vector<std::pair<uint32_t, uint32_t> >& edges)
{
	typedef Wm5::PlanarGraph<Vector2> Graph;
	Graph graph;
	int i = 0;
	for (Point2Array::const_iterator it = points->begin(); it != points->end(); ++it)
		graph.InsertVertex(*it,i++);
	for (std::vector<std::pair<uint32_t, uint32_t> >::const_iterator itedge = edges.begin(); itedge != edges.end(); ++itedge)
		graph.InsertEdge(itedge->first,itedge->second);

	std::vector<Graph::Primitive*> mPrimitives;
	graph.ExtractPrimitives(mPrimitives);


	IndexArrayPtr result(new IndexArray());
	for (std::vector<Graph::Primitive*>::const_iterator itPrim = mPrimitives.begin(); itPrim != mPrimitives.end(); ++itPrim){
		if ((*itPrim)->Type == Graph::PT_MINIMAL_CYCLE){
			Index lresult;
			for (std::vector<std::pair<Vector2,int> >::const_iterator itSequence = (*itPrim)->Sequence.begin(); itSequence != (*itPrim)->Sequence.end(); ++itSequence)
				lresult.push_back(itSequence->second);
			result->push_back(lresult);
		}
	}

	return result;
}
コード例 #2
0
ファイル: mcb.cpp プロジェクト: mosquitoboat/forceTile
void Load(Graph& mGraph, vector<Graph::Primitive*>& mPrimitives)
{
    // std::string path = Environment::GetPathR("tri.txt");
    //std::ifstream inFile(path.c_str());
    ifstream inFile("./PlanarGraph.txt");

	//ofstream verify;
  //verify.open("verify.txt",ios::out|ios::app);

    int numVertices;
    inFile >> numVertices;
    //verify<< numVertices<<"\n";
    int i;

    for (i = 0; i < numVertices; ++i)
    {
        double x, y;
        inFile >> x;
        inFile >> y;
      // verify<< x <<"\t"<< y <<"\n";
        //y = GetHeight() - 1 - y;
        mGraph.InsertVertex(Vec2(x, y), i);
    }

    int numEdges;
    inFile >> numEdges;
     //verify<< numEdges<<"\n";
    for (i = 0; i < numEdges; ++i)
    {
        int v0, v1;
        inFile >> v0;
        inFile >> v1;
       // verify<< v0 <<"\t"<< v1 <<"\n";
        mGraph.InsertEdge(v0, v1);
    }

#ifdef EXTRACT_PRIMITIVES
    mGraph.ExtractPrimitives(mPrimitives);
#endif

}