Пример #1
0
bool Intersection::operator !=(const Intersection &p2) const{

	if(this->id != p2.getID())
		return true;

	return false;
}
Пример #2
0
void loadMap() {

	gv = new GraphViewer(WIDTH, HEIGHT, false);
	gv->setBackground("res/background2.png");
	gv->createWindow(WIDTH, HEIGHT);
	gv->setVertexSize(0.1, 0.1);

	//gv->defineVertexColor(DEFAULT_COLOR);
	//gv->defineEdgeColor(DEFAULT_COLOR);

	float x, y;
	int ids, idd;

	for(unsigned i=0; i<map->getNumVertex(); i++){

		Intersection source = map->getVertexSet()[i]->getIntersection();
		ids = source.getID();

		x = convertGeoCordToPixel(source.getCoord().x, source.getCoord().y)[0];
		y = convertGeoCordToPixel(source.getCoord().x, source.getCoord().y)[1];

		gv->addNode(ids, x, y);

		ostringstream convert;
		convert << ids;

		gv->setVertexLabel(ids, convert.str());

		if(source.getIP()){ //interest points a azul

			gv->setVertexColor(ids, "blue");
		}

		else // outros a vermelho
			gv->setVertexColor(ids, "red");


		for(unsigned j=0; j<map->getVertexSet()[i]->getAdj().size(); j++){

			Intersection dest = map->getVertexSet()[i]->getAdj()[j].getDest()->getIntersection();
			idd = dest.getID();

			x = convertGeoCordToPixel(dest.getCoord().x, dest.getCoord().y)[0];
			y = convertGeoCordToPixel(dest.getCoord().x, dest.getCoord().y)[1];

			gv->addNode(idd, x, y);

			ostringstream convert2;
			convert2 << idd;

			gv->setVertexLabel(idd, convert2.str());
			gv->setVertexColor(idd, "green");

			gv->addEdge(map->getVertexSet()[i]->getAdj()[j].getID(), ids, idd, EdgeType::DIRECTED);
			gv->setEdgeLabel(map->getVertexSet()[i]->getAdj()[j].getID(), map->getVertexSet()[i]->getAdj()[j].getName());

		}

	}

	gv->rearrange();

	return;

}
void MapGenerator::addMapPieceToMap(char* string, Map* map){
		
	if (string[0] == 'e'){
		//endpoint
		int ID;
		double x, y;
		char direction;
		Direction d;
		sscanf(string, "e,%d,%lf,%lf,%c\n", &ID, &x, &y, &direction);
		
		printf("Added endpoint to map. ID=%d, x=%lf, y=%lf, direction=%c\n", ID, x, y, direction);
		switch(direction){
		case 'n':
			d = NORTH;
			break;
		case 's':
			d = SOUTH;
			break;
		case 'e':
			d = EAST;
			break;
		case 'w':
			d = WEST;
			break;
		default:
			d = NORTH;
		}
		
		EndPoint* endPoint = new EndPoint(ID, x, y, d);
		
		map->endPoints[map->numEndPoints] = endPoint;
		map->numEndPoints++;
	}
	else if (string[0] == 'i'){
	
		//intersection
		int ID;
		double x, y;
		sscanf(string, "i,%d,%lf,%lf\n", &ID, &x, &y);
		printf("Added intersection to map. ID=%d, x=%lf, y=%lf\n", ID, x, y);
		Intersection* intersection = new Intersection(ID, x, y);
		map->intersections[map->numIntersections] = intersection;
		map->numIntersections++;
	}
	else if (string[0] == 'r'){
		
		//road
		printf("road\n");
		char atype, btype;
		int aID, bID;
		int atbLanes, btaLanes;
		sscanf(string, "r,%c%d,%c%d,%d,%d", &atype, &aID, &btype, &bID, &atbLanes, &btaLanes);
		printf("Added road to map PointAType=%c, PointAID=%d, PointBType=%c, PointBID=%d, #lanes from A to B=%d, #lanes from B to A=%d\n", atype, aID, btype, bID, atbLanes, btaLanes);
		
		MapPiece *pointA = NULL, *pointB = NULL;
		
		//find the points
		EndPoint* currentEndPoint;
		Intersection* currentIntersection;

		for (int i = 0; i < map->numEndPoints; i++){
		
			currentEndPoint = map->endPoints[i];
		
			if (currentEndPoint->getID() == aID){
				pointA = currentEndPoint;
			}
			if (currentEndPoint->getID() == bID){
				pointB = currentEndPoint;
			}
		}

		printf("trying intersection\n");
		for (int i = 0; i < map->numIntersections; i++){
		
			currentIntersection = map->intersections[i];
		
			if (currentIntersection->getID() == aID){
				pointA = currentIntersection;
				
			}
			if (currentIntersection->getID() == bID){
				pointB = currentIntersection;
			}
		}
		
		//create the road
		Road* road = new Road(pointA, pointB, atbLanes, btaLanes);
		map->roads[map->numRoads] = road;
		map->numRoads++;
		
		if (atype == 'e'){
			((EndPoint*)pointA)->setRoad(road);
		}
		else if (atype == 'i'){
			if (road->getPointA() == pointA){
				((Intersection*)pointA)->setRoad(road, road->getDirection());
			}
			else{
				((Intersection*)pointA)->setRoad(road, -road->getDirection());
			}
		}
		if (btype == 'e'){
			((EndPoint*)pointB)->setRoad(road);
		}
		else if (btype == 'i'){
			if (road->getPointB() == pointB){
				((Intersection*)pointB)->setRoad(road, -road->getDirection());
			}
			else{
				((Intersection*)pointB)->setRoad(road, road->getDirection());
			}
		}
	}
	
	return;
}