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


C++ Graph::GetNodeByPos方法代码示例

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


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

示例1: calculateWayPoint

void Manager::calculateWayPoint(){
	vector<Waypoint> vecWaypoints;

	Graph gr = _map->GetGraphFromGrid();

	AStar a;
	Node* start = gr.GetNodeByPos(_slam->BestPrticle()->GetX(), _slam->BestPrticle()->GetY());
	Node* end = gr.GetNodeByPos(40, 47);
	vector<Node*> vec = a.GetShortestPath(start, end);
	for (int i = vec.size() - 1; i > 0; --i) {
		Waypoint wp(vec.operator [](i)->getXPos(),vec.operator [](i)->getYPos());
		cout << "AStar path: (" << wp.getX() << "," << wp.getY() << ")" << endl;
		vecWaypoints.push_back(wp);
	}
	cout << "Finished AStar path" << endl;

	this->_robot->SetWaypointVector(vecWaypoints);
}
开发者ID:benor1470,项目名称:newRobotics,代码行数:18,代码来源:Manager.cpp

示例2: GetGraphFromGrid

Graph MapHelp::GetGraphFromGrid() {
	cout << "start Grid to Graph" << endl;

	vector<Waypoint> way;
	Graph gr;
	int NodeID = 0;
	for (int i = 0; i < this->GetBlownGridMap()->GetHeight(); ++i) {
		for (int j = 0; j < this->GetBlownGridMap()->GetWidth(); ++j) {
			gr.InsertVertex(NodeID, 5, j, i, false);
//			cout << "node " << NodeID << " x: " << i << " y: " << j
//					<< " value: " << this->GetBlownGridMap()->GetValue(j, i)
//					<< endl;
			NodeID++;
		}
	}
	for (int i = 0; i < this->GetBlownGridMap()->GetHeight(); ++i) {
		for (int j = 0; j < this->GetBlownGridMap()->GetWidth(); ++j) {
			// For each cell:
			int ij = this->GetBlownGridMap()->GetValue(j, i);

			if (ij == 0) {
				// Iterate over the closest neighbours 3x3 matrix:+s
				for (int k = i - 1; k <= i + 1; k++) {
					for (int m = j - 1; m <= j + 1; m++) {
						// node name: k,m
						//
						if (k < 0 || m < 0
								|| k >= this->GetBlownGridMap()->GetHeight()
								|| m >= this->GetBlownGridMap()->GetWidth()) {
						} else {
							int km = this->GetBlownGridMap()->GetValue(m, k);//[k][m];

							//blownMapMatrix[k][m]
							//if (node [k,m]=white AND [i,j]=white AND [k,m]!=[i,j]) -> add edge
							if (km == 0 && (k != i || m != j)) {
								//add edge
								// from ij to km
								//gr.InsertEdge(gr.GetNodeByPos(i, j)->GetData(), gr.GetNodeByPos(k, m)->GetData(), 1);
//								cout << "Parent: " << i << " " << j << " Son: "
//										<< k << " " << m << endl;
								gr.AddSuccessor(
										gr.GetNodeByPos(j, i)->GetData(),
										gr.GetNodeByPos(m, k)->GetData());
//								cout << gr.GetNodeByPos(j, i)->GetSuccessors().size() << endl;
							}
						}
					}
				}
			}
		}
	}
	cout << "Finished Grid to Graph" << endl;
	return gr;
}
开发者ID:benor1470,项目名称:newRobotics,代码行数:54,代码来源:MapHelp.cpp


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