Exemple #1
0
MainWindow::MainWindow(const Ped::Model &model) : model(model)
{

	// The Window 
	graphicsView = new QGraphicsView();

	setCentralWidget(graphicsView);

	// A surface for managing a large number of 2D graphical items
	scene = new QGraphicsScene(QRect(0,0,800,600),this);

	// Connect
	graphicsView->setScene(scene);


	// Paint on surface
	scene->setBackgroundBrush(Qt::black);
	//graphicsscene->setItemIndexMethod(QGraphicsScene::NoIndex);


	for (int x=0; x<=800; x+=cellsizePixel)
	{
		scene->addLine(x,0,x,800, QPen(Qt::gray));
	}

	// Now add the horizontal lines, paint them green
	for (int y=0; y<=800; y+=cellsizePixel)
	{
		scene->addLine(0,y,800,y, QPen(Qt::gray));
	}

	// Create viewAgents with references to the position of the model counterparts
	const std::vector<Ped::Tagent*> &agents = model.getAgents();

	std::vector<Ped::Tagent*>::const_iterator it;
	for (it = agents.begin(); it != agents.end(); it++) 
	{
		viewAgents.push_back(new ViewAgent(*it,scene));  
	}

	////////////
	/// NEW
	///////////////////////////////////////////////
	const int heatmapSize = model.getHeatmapSize();
	QPixmap pixmapDummy = QPixmap(heatmapSize, heatmapSize);
	pixmap = scene->addPixmap(pixmapDummy);
	////////////
	/// END NEW
	///////////////////////////////////////////////

	paint();
	graphicsView->show(); // Redundant? 
}
MainWindow::MainWindow(const Ped::Model &model) : model(model)
{
  // The Window 
  graphicsView = new QGraphicsView();

  setCentralWidget(graphicsView);

  // A surface for managing a large number of 2D graphical items
  scene = new QGraphicsScene(QRect(0,0,800,600),this);
  
  // Connect
  graphicsView->setScene(scene);

  for (int x=0; x<=800; x+=cellsizePixel)
  {
    scene->addLine(x,0,x,800, QPen(Qt::gray));
  }

 // Now add the horizontal lines, paint them green
  for (int y=0; y<=800; y+=cellsizePixel)
  {
    scene->addLine(0,y,800,y, QPen(Qt::gray));
  }

  // Create viewAgents with references to the position of the model counterparts
  auto &agents = model.getAgents();
  for(auto agent : agents)
  {
    viewAgents.push_back(new ViewAgent(agent, scene));
  }

#ifdef ASSIGNMENT_4
  const int heatmapSize = model.getHeatmapSize();
  QPixmap pixmapDummy = QPixmap(heatmapSize, heatmapSize);
  pixmap = scene->addPixmap(pixmapDummy);
#endif
  
  paint();
  graphicsView->show(); // Redundant? 
}
Exemple #3
0
int main(int argc, char*argv[]) { 
  bool timing_mode = 0;
  int i = 1;
  QString scenefile = "scenario.xml";
  Ped::IMPLEMENTATION implementation = Ped::SEQ;
  int number_of_threads = 4;

  // Argument handling
  while(i < argc)
  {
    if(argv[i][0] == '-' && argv[i][1] == '-')
    {
      if(strcmp(&argv[i][2],"timing-mode") == 0)
      {
	cout << "Timing mode on\n";
	timing_mode = true;
      }
      else if (strcmp(&argv[i][2],"threads") == 0)
      {
	implementation = Ped::PTHREAD;
      }
      else if (strcmp(&argv[i][2],"omp") == 0)
      {
	implementation = Ped::OMP;
      }
      else if(strcmp(&argv[i][2],"help") == 0)
      {
	cout << "Usage: " << argv[0] << " [--help] [--timing-mode] [--threads |#threads]] [--omp] [scenario]" << endl;
	return 0;
      }
      else
      {
	cerr << "Unrecognized command: \"" << argv[i] << "\". Ignoring ..." << endl;
      }
    }
    else // Assume it is a path to scenefile or the number of threads to be used
    {
      int old_number_of_threads = number_of_threads;
      number_of_threads = atoi(argv[i]);
      if (number_of_threads == 0) // The argument was not a number
      {
	scenefile = argv[i];
	number_of_threads = old_number_of_threads;
      }
    }
    
    i+=1;
  }

  // Reading the scenario file and setting up the crowd simulation model
  Ped::Model model;
  ParseScenario parser(scenefile);
  model.setup(parser.getAgents(), implementation, number_of_threads);

  // GUI related set ups
  QApplication app(argc, argv);
  MainWindow mainwindow(model);

  // Default number of steps to simulate
  const int maxNumberOfStepsToSimulate = 10000;
  PedSimulation *simulation = new PedSimulation(model, mainwindow);

  cout << "Demo setup complete, running ..." << endl;
  int retval = 0;
  // Timing of simulation
  std::chrono::time_point<std::chrono::system_clock> start,stop;
  start = std::chrono::system_clock::now();

  if(timing_mode)
  {
    // Simulation mode to use when profiling (without any GUI)
    simulation->runSimulationWithoutQt(maxNumberOfStepsToSimulate);
  }
  else
  {
    // Simulation mode to use when visualizing
    mainwindow.show();
    simulation->runSimulationWithQt(maxNumberOfStepsToSimulate);
    retval = app.exec();
  }

  // End timing
  stop = std::chrono::system_clock::now();
  std::chrono::duration<double> elapsed_seconds = stop-start;
  cout << "Time: " << elapsed_seconds.count() << " seconds." << endl;

  cout << "Done" << endl;
  delete (simulation);
  return retval;
}