当前位置: 首页>>代码示例>>C++>>正文


C++ GEdge::setWeight方法代码示例

本文整理汇总了C++中GEdge::setWeight方法的典型用法代码示例。如果您正苦于以下问题:C++ GEdge::setWeight方法的具体用法?C++ GEdge::setWeight怎么用?C++ GEdge::setWeight使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GEdge的用法示例。


在下文中一共展示了GEdge::setWeight方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: importGraph

/* Import a graph from a file.
 * Requires:
 * 	@nodes		The list to be filled with the nodes
 * 	@container	The container to put the vertexs
 * 	@edges		The list of edges to be filled
 * 	@fname		The filename
 * Returns:
 * 	true		on success
 * 	false		otherwise
 */
bool TriNavMeshBuilder::importGraph(std::vector<GNode *> &nodes,
		PolyStructsContainer<sm::Vertex *> &container,
		PolyStructsContainer<Triangle *> &triangles,
		std::vector<GEdge *> &edges,
		const Ogre::String &fname)
{
	std::ifstream in;
	in.open(fname.c_str());

	if(!in.is_open()){
		debugERROR("Error while opening the file %s\n", fname.c_str());
		return false;
	}

	if(!container.isEmpty()){
		debugWARNING("Warning, Vertex container is not empty\n");
		ASSERT(false);
	}
	if(!triangles.isEmpty()){
		debugWARNING("Warning, triangles is not empty\n");
		ASSERT(false);
	}

	// first read the vertexs list
	std::vector<sm::Vertex *> vertexs;
	int aux;
	in >> aux;
	ASSERT(aux > 0);
	vertexs.reserve(aux);

	for(int i = 0; i < aux; ++i){
		sm::Vertex *v = new sm::Vertex;
		in >> v->x;
		in >> v->y;
		vertexs.push_back(v);
	}

	ASSERT(in.good());

	// now read the number of nodes
	nodes.clear();
	in >> aux;
	nodes.reserve(aux);
	std::vector<Triangle *> triangVec;
	int i1, i2, i3;
	for(int i = 0; i < aux; ++i){
		in >> i1;
		in >> i2;
		in >> i3;
		ASSERT(i1 < vertexs.size() && i2 < vertexs.size() && i3 < vertexs.size());
		Triangle *t = new Triangle(vertexs[i1], vertexs[i2], vertexs[i3]);
		triangVec.push_back(t);

		GNode *node = new GNode(t);
		nodes.push_back(node);
	}
	ASSERT(in.good());

	// now get all the edges
	edges.clear();
	in >> aux;
	ASSERT(aux > 0);
	edges.reserve(aux);
	bool ok = false;
	float weight;
	for(int i = 0; i < aux; ++i){
		in >> i1;
		in >> i2;
		in >> weight;
		if(i1 >= nodes.size() || i2 >= nodes.size()){
			debugRED("i1: %d, size: %zd, i2: %d, size: %zd\n", i1, nodes.size(),
					i2, nodes.size());
			ASSERT(i1 < nodes.size() && i2 < nodes.size());
		}
		GNode *n1 = nodes[i1], *n2 = nodes[i2];

		GEdge *e = new GEdge(n1,n2);
		ok = n1->setNewEdge(e);
		ASSERT(ok);
		ok = n2->setNewEdge(e);
		ASSERT(ok);
		edges.push_back(e);
		e->setWeight(weight);

	}


	// Save the triangles and the vertexs
	for(int i = vertexs.size()-1; i >= 0; --i){
		container.addObj(vertexs[i]);
//.........这里部分代码省略.........
开发者ID:agudpp,项目名称:CordobaZombie,代码行数:101,代码来源:TriNavMeshBuilder.cpp


注:本文中的GEdge::setWeight方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。