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


C++ Environment::addPoint方法代码示例

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


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

示例1: main

int main() {
//	srand(time(NULL));
	Environment env;
	Point *point = new Point();
	ofstream pointFile("point.txt");
	ofstream linkFile("link.txt");
	ifstream inFile("timelist.txt");
	queue<tuple<int, int, int>> data;
	int id1, id2, times;
	while (!inFile.eof()) {
		string line;
		getline(inFile, line);
		sscanf_s(line.c_str(), "%d %d %d", &id1, &id2, &times);
		tuple<int, int, int> tu(id1, id2, times);
		data.push(tu);
	}
	cout << data.size() << endl;
	point->id = 1;
	for (int i = 0; i < 3; i++) {
		point->pos[i] = 0.0;
	}
	env.init(point);
	bool allPointAdded = false;
	int step = 0;
	for ( step = 0; step < 30000; step++) {
		env.update();
		//		Sleep(100);
		if (step % 1000 == 0) {
			cout << "energy: " << env.getEnergy() << endl;
			cout << step << ' ' << env.timePassed << ' ' << env.timeSlice << endl;
		}
		while (!data.empty() && get<2>(data.front()) <= env.timePassed / TIMESLICE) {
			id1 = get<0>(data.front());
			id2 = get<1>(data.front());
			env.addPoint(id1, "", id2, "");
			data.pop();
		}
		if (data.empty()) {
			// if all points were added
			break;
		}
		if (step % 100 == 0) {
			pointFile << step / 100 << '\n';
			for (Point *p : env.points) {
				pointFile << p->pos[0] << '\t' << p->pos[1] << '\t' << p->pos[2] << '\t' << p->radius << '\n';
			}
			linkFile << step / 100 << '\n';
			for (Link *l : env.links) {
				linkFile << l->first->pos[0] << '\t' << l->first->pos[1] << '\t' << l->first->pos[2] << '\t';
				linkFile << l->second->pos[0] << '\t' << l->second->pos[1] << '\t' << l->second->pos[2] << '\n';
			}
		}
	}
	cout << "perpare skeleton env" << endl;
	// treat a group of points as one point
	Environment *skeletonEnv = env.getSkeleton();
	cout << "Skeleton Enviroment!!" << endl;
	cout << skeletonEnv->points.size() << " points " << skeletonEnv->links.size() << " links" << endl;
	for (; step < 30000; step++) {
		skeletonEnv->update();
		if (step % 1000 == 0) {
			cout << "enerty: " << skeletonEnv->getEnergy() << endl;
			cout << step << ' ' << skeletonEnv->timePassed << ' ' << skeletonEnv->timeSlice << endl;
		}
		if (step % 100 == 0) {
			pointFile << step / 100 << '\n';
			for (Point *p : skeletonEnv->points) {
				pointFile << p->pos[0] << '\t' << p->pos[1] << '\t' << p->pos[2] << '\t' << p->radius << '\n';
			}
			linkFile << step / 100 << '\n';
			for (Link *l : skeletonEnv->links) {
				linkFile << l->first->pos[0] << '\t' << l->first->pos[1] << '\t' << l->first->pos[2] << '\t';
				linkFile << l->second->pos[0] << '\t' << l->second->pos[1] << '\t' << l->second->pos[2] << '\n';
			}
		}
	}
	pointFile.close();
	return 0;
}
开发者ID:richard-liang,项目名称:DataCloud,代码行数:79,代码来源:DataCloud.cpp

示例2: buildEnvironment

void buildEnvironment()
{
    /*
    *----*----*--------*
    |    |    |        |
    |  A .    |   D    |
    |    |    |        |
    *----*  C |        |
    |    |    *---   --*
|  B .   .             |
    |    |    .   E    |
    *----*-------------*
    */
    
    // Points
    env.addPoint(core::Pointf(0, 0));     // 0
    env.addPoint(core::Pointf(0, 10));    // 1
    env.addPoint(core::Pointf(10, 10));   // 2
    env.addPoint(core::Pointf(10, 0));    // 3
    env.addPoint(core::Pointf(5, 0));     // 4
    env.addPoint(core::Pointf(10, -10));  // 5
    env.addPoint(core::Pointf(0, -10));   // 6
    env.addPoint(core::Pointf(-5, -10));  // 7
    env.addPoint(core::Pointf(-5, -7));   // 8
    env.addPoint(core::Pointf(-10, -10)); // 9
    env.addPoint(core::Pointf(-10, 0));   // 10
    env.addPoint(core::Pointf(-5, 0));    // 11
    env.addPoint(core::Pointf(-5, -3));   // 12
    env.addPoint(core::Pointf(-5, 3));    // 13
    env.addPoint(core::Pointf(-10, 10));  // 14
    env.addPoint(core::Pointf(-5, 10));   // 15
    env.addPoint(core::Pointf(-5, 7));    // 16
    env.addPoint(core::Pointf(3, 0));     // 17
    
    // Walls
    env.addWall(Wall (14, 10, 0.0));       // 0    
    env.addWall(Wall (15, 14, 0.0));       // 1    
    env.addWall(Wall (1, 15, 0.0));        // 2    
    env.addWall(Wall (2, 1, 0.0));         // 3    
    env.addWall(Wall (3, 2, 0.0));         // 4    
    env.addWall(Wall (5, 3, 0.0));         // 5    
    env.addWall(Wall (6, 5, 0.0));         // 6    
    env.addWall(Wall (7, 6, 0.0));         // 7    
    env.addWall(Wall (9, 7, 0.0));         // 8    
    env.addWall(Wall (10, 9, 0.0));        // 9    
    env.addWall(Wall (10, 11, 0.0));       // 10    
    env.addWall(Wall (15, 16, 0.0));       // 11
    env.addWall(Wall (13, 11, 0.0));       // 12
    env.addWall(Wall (11, 12, 0.0));       // 13
    env.addWall(Wall (8, 7, 0.0));         // 14
    env.addWall(Wall (0, 1, 0.0));         // 15
    env.addWall(Wall (17, 0, 0.0));        // 16
    env.addWall(Wall (3, 4, 0.0));         // 17
    env.addWall(Wall (8, 12, INFINITY));  // 18
    env.addWall(Wall (0, 6, INFINITY));   // 19
    env.addWall(Wall (17, 4, INFINITY));  // 20
    env.addWall(Wall (16, 13, INFINITY)); // 21
    
    // Rooms
    Room rA, rB, rC, rD, rE;
    rA.setIdx(0);
    rB.setIdx(1);
    rC.setIdx(2);
    rD.setIdx(3);
    rE.setIdx(4);
    
    // Room A
    rA.addWall(0,   1);
    rA.addWall(1,   1);
    rA.addWall(11, -1);
    rA.addWall(21, -1);
    rA.addWall(12, -1);
    rA.addWall(10,  1);
    
    env.addRoom(rA);
    
    // Room B
    rB.addWall(8,   1);
    rB.addWall(14, -1);
    rB.addWall(18,  1);
    rB.addWall(13, -1);
    rB.addWall(10, -1);
    rB.addWall(9,   1);
    
    env.addRoom(rB);

    // Room C
    rC.addWall(2,   1);
    rC.addWall(11,  1);
    rC.addWall(21,  1);
    rC.addWall(12,  1);
    rC.addWall(13,  1);
    rC.addWall(18, -1);
    rC.addWall(14,  1);
    rC.addWall(7,   1);
    rC.addWall(19, -1);
    rC.addWall(15,  1);
    
    env.addRoom(rC);

//.........这里部分代码省略.........
开发者ID:Bk8,项目名称:BeamTracing,代码行数:101,代码来源:main.cpp


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