Example #1
0
// Add an undirected edge between the location of the a anchor and the location of the b anchor
void graph::addUndirEdge(anchor a, anchor b) {
  edges.push_back(graphEdge(a, b, false));
}
Example #2
0
bool CPlanarGraph::LoadGraphFromXML(const char* fileName, bool flagDetectFaces /* = true */, bool flagIgnoreIndiv /* = true */)
{
	// Clear the current graph...
	ClearGraph();

	TiXmlDocument doc;
	bool loadFlag = doc.LoadFile(fileName);
	if ( loadFlag == false )
	{
		std::cout << "Failed to load graph from " << fileName << "!\n";
		return loadFlag;
	}
	//doc.Print();

	TiXmlNode* xmlRoot = 0;
	xmlRoot = doc.RootElement();
	assert( xmlRoot );

	TiXmlNode* xmlNode = xmlRoot->FirstChild();
	while ( xmlNode != 0 )
	{
		if ( strcmp(xmlNode->Value(), "Node") == 0 )
		{
			// Parse a node...
			CGraphNode graphNode;
			float px, py;
			int rx = xmlNode->ToElement()->QueryFloatAttribute("px", &px);
			int ry = xmlNode->ToElement()->QueryFloatAttribute("py", &py);
			if ( rx != TIXML_SUCCESS || ry != TIXML_SUCCESS )
			{
				graphNode.RandomlyInitPos();
			}
			else
			{
				graphNode.SetPos(px, py);
			}
			int type;
			int r = xmlNode->ToElement()->QueryIntAttribute("type", &type);
			if ( r == TIXML_SUCCESS )
			{
				graphNode.SetType(type);
			}
			int boundary;
			int rb = xmlNode->ToElement()->QueryIntAttribute("boundary", &boundary);
			if ( rb == TIXML_SUCCESS )
			{
				graphNode.SetBoundaryType(boundary);
			}
			int fixed;
			int rf = xmlNode->ToElement()->QueryIntAttribute("fix", &fixed);
			if ( rf == TIXML_SUCCESS && fixed != 0 )
			{
				graphNode.SetFlagFixed(true);
			}
			const char* str = xmlNode->ToElement()->Attribute("name");
			if ( *str != '\0' )
			{
				graphNode.SetName(str);
			}
			AddGraphNode(graphNode);
		}
		else if ( strcmp(xmlNode->Value(), "Edge") == 0 )
		{
			// Parse an edge...
			int idx0 = -1;
			int idx1 = -1;
			int r0 = xmlNode->ToElement()->QueryIntAttribute("node0", &idx0);
			int r1 = xmlNode->ToElement()->QueryIntAttribute("node1", &idx1);
			if ( r0 != TIXML_SUCCESS )
			{
				const char* str = xmlNode->ToElement()->Attribute("name0");
				idx0 = FindNodeAccordingToName(str);
			}
			if ( r1 != TIXML_SUCCESS )
			{
				const char* str = xmlNode->ToElement()->Attribute("name1");
				idx1 = FindNodeAccordingToName(str);
			}
			if ( idx0 >= 0 && idx1 >= 0 )
			{
				CGraphEdge graphEdge(idx0, idx1);
				AddGraphEdge(graphEdge);
			}
		}

		// Move to the next sibling...
		xmlNode = xmlNode->NextSibling();
	}

	SetNodeNeighbors();
	if ( flagIgnoreIndiv == true )
	{
		RemoveIndividualNodes();
	}
	if ( flagDetectFaces == false )
	{
		return loadFlag;
	}
	//PrintGraph();

	// Step 1: Detect faces of the planar graph...
	DetectFaces();
	return loadFlag;
}
Example #3
0
// Add a directed edge from the location of the from anchor to the location of the to anchor
void graph::addDirEdge(anchor from, anchor to) {
  //cout << "graph::addDirEdge("<<from.getID()<<" => "<<to.getID()<<")"<<endl;
  edges.push_back(graphEdge(from, to, true)); 
}