本文整理汇总了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]);
//.........这里部分代码省略.........