Add interface to trains. Ready to plot from files..

parent b130f1be
......@@ -159,6 +159,7 @@ set( HDR
src/IO/TraVisToClient.h
forms/Settings.h
src/SaxParser.h
src/train.h
src/Debug.h
src/Frame.h
src/InteractorStyle.h
......
......@@ -57,8 +57,7 @@ int OutputHandler::GetErrors()
void OutputHandler::Write(const string& str)
{
if (this != NULL)
cout << str << endl;
cout << str << endl;
}
void OutputHandler::ProgressBar(double TotalPeds, double NowPeds)
......@@ -157,10 +156,10 @@ FileHandler::~FileHandler()
void FileHandler::Write(const string& str)
{
if (this != NULL) {
// if (this != NULL) {
_pfp << str << endl;
_pfp.flush();
}
// }
if (str.find("ERROR") != string::npos)
{
......
......@@ -808,8 +808,15 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
}
SyncData* dataset=NULL;
extern_trajectories_firstSet.clearFrames();
vtkSmartPointer<vtkSphereSource> org = vtkSphereSource::New();
org->SetRadius(10);
// extern_mysphere = org;
switch(groupID) {
case 1:
Debug::Messages("handling first set");
......@@ -855,6 +862,8 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
else if(fileName.endsWith(".txt",Qt::CaseInsensitive))
{
QString source_file= wd + QDir::separator() + SaxParser::extractSourceFileTXT(fileName);
QString ttt_file= wd + QDir::separator() + SaxParser::extractTrainTimeTableFileTXT(fileName);
QString tt_file= wd + QDir::separator() + SaxParser::extractTrainTypeFileTXT(fileName);
QString goal_file=wd + QDir::separator() + SaxParser::extractGoalFileTXT(fileName);
QFileInfo check_file(source_file);
if( !(check_file.exists() && check_file.isFile()) )
......@@ -864,7 +873,7 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
else
Debug::Messages("INFO: MainWindow::addPedestrianGroup: source name: <%s>", source_file.toStdString().c_str());
check_file = source_file;
check_file = goal_file;
if( !(check_file.exists() && check_file.isFile()) )
{
Debug::Messages("WARNING: MainWindow::addPedestrianGroup: goal name: <%s> not found!", goal_file.toStdString().c_str());
......@@ -873,6 +882,25 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
Debug::Messages("INFO: MainWindow::addPedestrianGroup: goal name: <%s>", goal_file.toStdString().c_str());
check_file = ttt_file;
if( !(check_file.exists() && check_file.isFile()) )
{
Debug::Messages("WARNING: MainWindow::addPedestrianGroup: ttt name: <%s> not found!", ttt_file.toStdString().c_str());
}
else
Debug::Messages("INFO: MainWindow::addPedestrianGroup: ttt name: <%s>", ttt_file.toStdString().c_str());
check_file = tt_file;
if( !(check_file.exists() && check_file.isFile()) )
{
Debug::Messages("WARNING: MainWindow::addPedestrianGroup: tt name: <%s> not found!", tt_file.toStdString().c_str());
}
else
Debug::Messages("INFO: MainWindow::addPedestrianGroup: tt name: <%s>", tt_file.toStdString().c_str());
// ------ parsing sources
QFile file(source_file);
QXmlInputSource source(&file);
......@@ -881,14 +909,30 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
reader.setContentHandler(&handler);
reader.parse(source);
file.close();
// -----
// // ---- parsing goals
// -----
QFile file2(goal_file);
QXmlInputSource source2(&file2);
reader.parse(source2);
file2.close();
// -----
// // ---- parsing goals
// -----
// parsing trains
// train type
std::map<int, std::shared_ptr<TrainTimeTable> > trainTimeTable;
std::map<std::string, std::shared_ptr<TrainType> > trainTypes;
SaxParser::LoadTrainType(tt_file.toStdString(), trainTypes);
extern_trainTypes = trainTypes;
bool ret = SaxParser::LoadTrainTimetable(ttt_file.toStdString(), trainTimeTable);
if(!ret) std::cout << "hmmm\n";
extern_trainTimeTables = trainTimeTable;
for(auto tab: trainTimeTable)
std::cout << "tab: " << tab.first << "\n";
for(auto tab: trainTypes)
std::cout << "type: " << tab.first << "\n";
if(false==SaxParser::ParseTxtFormat(fileName, dataset,&frameRate))
return false;
......
This diff is collapsed.
......@@ -35,6 +35,12 @@
#include <vector>
#include "SyncData.h"
#include"geometry/GeometryFactory.h"
#include "tinyxml/tinyxml.h"
#include "general/Macros.h"
#include "train.h"
......@@ -90,6 +96,14 @@ public:
/// parse a vtk file
static bool ParseGradientFieldVTK(QString fileName, GeometryFactory& geoFac);
/// Trains
static bool LoadTrainTimetable(std::string filename, std::map<int, std::shared_ptr<TrainTimeTable> > & trainTimeTables);
static std::shared_ptr<TrainTimeTable> parseTrainTimeTableNode(TiXmlElement * e);
static std::shared_ptr<TrainType> parseTrainTypeNode(TiXmlElement * e);
static QString extractTrainTypeFileTXT(QString &filename);
static QString extractTrainTimeTableFileTXT(QString &filename);
static bool LoadTrainType(std::string Filename, std::map<std::string, std::shared_ptr<TrainType> > & trainTypes);
private:
//clear the mo
......
......@@ -138,6 +138,17 @@ Frame* SyncData::getFrame( int i)
}
vtkSmartPointer<vtkSphereSource> SyncData::getTTT()
{
return _ttt;
}
void SyncData::setTTT(vtkSmartPointer<vtkSphereSource> s)
{
_ttt = s;
}
Frame* SyncData::getNextFrame()
{
......@@ -193,8 +204,8 @@ Frame* SyncData::getNextFrame()
/***
* This method is for convenience only.
* The normal way to get the previous frame is:
* 1. either set the variable extern_update_step to a negative value;
* 2. using the function getFrame(int frameNumber). one may first get
* 1. either set the variable extern_update_step to a negative value;
* 2. using the function getFrame(int frameNumber). one may first get
* the current framecursor position using getFrameCursor()
*/
//Frame* SyncData::getPreviousFrame()
......
......@@ -42,7 +42,8 @@
#include <memory>
#include <vector>
#include <map>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
class QObject;
class QStringList;
......@@ -84,6 +85,9 @@ public:
/// return the frame at position i
Frame* getFrame(int i);
vtkSmartPointer<vtkSphereSource> getTTT();
void setTTT(vtkSmartPointer<vtkSphereSource> s);
/// return a pointer to the next frame
Frame* getNextFrame();
......@@ -166,6 +170,8 @@ private:
//std::vector<Frame*> _frames;
std::map <int, Frame*> _frames;
//std::map<int, std::unique_ptr<Frame> > _frames;
vtkSmartPointer<vtkSphereSource> _ttt;
};
#endif /* SYNCDATA_H_ */
......@@ -76,7 +76,7 @@
#include <vtkWindowToImageFilter.h>
#include <vtkActor.h>
#include <vtkLightKit.h>
#include <vtkPolyLine.h>
#include "geometry/FacilityGeometry.h"
#include "geometry/GeometryFactory.h"
......@@ -140,7 +140,7 @@ void ThreadVisualisation::slotSetFrameRate(float fps)
void ThreadVisualisation::run()
{
// std::cout << "RUN " << _runningTime << "\n";
std::cout << "RUN " << _runningTime << "\n";
//deactivate the output windows
vtkObject::GlobalWarningDisplayOff();
......@@ -180,59 +180,83 @@ void ThreadVisualisation::run()
//renderer->AddActor(axis);
//add big circle at null point
{
vtkSphereSource* org = vtkSphereSource::New();
org->SetRadius(300);
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(org->GetOutputPort());
org->Delete();
// create actor
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
mapper->Delete();
actor->GetProperty()->SetColor(.90,.90,0.0);
actor->Delete();
//renderer->AddActor(actor);
}
//add another big circle at null point
{
vtkSphereSource* org = vtkSphereSource::New();
org->SetRadius(300);
//org->SetCenter(50,80,0);
vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
mapper->SetInputConnection(org->GetOutputPort());
org->Delete();
// create actor
vtkActor* actor = vtkActor::New();
actor->SetMapper(mapper);
mapper->Delete();
actor->GetProperty()->SetColor(.90,.90,0.0);
actor->SetPosition(5000,8000,0);
actor->Delete();
//renderer->AddActor(actor);
}
// Create a real circle, not a sphere
{
VTK_CREATE(vtkRegularPolygonSource, polygonSource);
polygonSource->GeneratePolygonOff();
polygonSource->SetNumberOfSides(50);
polygonSource->SetRadius(1000);
polygonSource->SetCenter(0,0,0);
polygonSource->Update();
VTK_CREATE(vtkPolyDataMapper,mapper);
mapper->SetInputConnection(polygonSource->GetOutputPort());
VTK_CREATE(vtkActor,actor);
actor->GetProperty()->SetColor(180.0/255,180.0/255.0,180.0/255.0);
actor->SetMapper(mapper);
//renderer->AddActor(actor);
}
// {
// vtkSphereSource* org = vtkSphereSource::New();
// org->SetRadius(10);
// vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
// mapper->SetInputConnection(org->GetOutputPort());
// org->Delete();
// //------
// // create actor
// vtkActor* actor = vtkActor::New();
// actor->SetMapper(mapper);
// mapper->Delete();
// actor->GetProperty()->SetColor(.1,.10,0.0);
// _renderer->AddActor(actor);
// actor->Delete();
// mysphere;
// //
// }
// {
// vtkPolyDataMapper* mapper = vtkPolyDataMapper::New();
// mapper->SetInputConnection(extern_mysphere->GetOutputPort());
// //------
// // create actor
// vtkActor* actor = vtkActor::New();
// actor->SetMapper(mapper);
// mapper->Delete();
// actor->GetProperty()->SetColor(.1,.10,0.0);
// _renderer->AddActor(actor);
// actor->Delete();
// //
// }
// {
// // Train
// double p0[3] = {1.0*100, 4.0*100, 0.0};
// double p1[3] = {3.0*100, 4.0*100, 0.0};
// double p2[3] = {3.0*100, 5.0*100, 0.0};
// double p3[3] = {1.0*100, 5.0*100, 0.0};
// double p4[3] = {1.0*100, 4.0*100, 0.0};
// // Create a vtkPoints object and store the points in it
// VTK_CREATE(vtkPoints, points);
// points->InsertNextPoint(p0);
// points->InsertNextPoint(p1);
// points->InsertNextPoint(p2);
// points->InsertNextPoint(p3);
// points->InsertNextPoint(p4);
// VTK_CREATE(vtkPolyLine, polyLine);
// polyLine->GetPointIds()->SetNumberOfIds(5);
// for(unsigned int i = 0; i < 5; i++)
// {
// polyLine->GetPointIds()->SetId(i,i);
// }
// // Create a cell array to store the lines in and add the lines to it
// VTK_CREATE(vtkCellArray, cells);
// cells->InsertNextCell(polyLine);
// // Create a polydata to store everything in
// VTK_CREATE(vtkPolyData, polyData);
// // Add the points to the dataset
// polyData->SetPoints(points);
// // Add the lines to the dataset
// polyData->SetLines(cells);
// VTK_CREATE(vtkPolyDataMapper, mapper);
// mapper->SetInputData(polyData);
// VTK_CREATE(vtkActor, actor);
// actor->SetMapper(mapper);
// actor->GetProperty()->SetColor(.1,.10,0.0);
// _renderer->AddActor(actor);
// }
// Create the render window
_renderWindow = vtkRenderWindow::New();
......@@ -302,6 +326,10 @@ void ThreadVisualisation::run()
renderingTimer->setTextActor(_runningTime);
_renderWinInteractor->AddObserver(vtkCommand::TimerEvent,renderingTimer);
//create the necessary connections
QObject::connect(renderingTimer, SIGNAL(signalRunningTime(unsigned long )),
this->parent(), SLOT(slotRunningTime(unsigned long )));
......@@ -311,8 +339,7 @@ void ThreadVisualisation::run()
QObject::connect(renderingTimer, SIGNAL(signalRenderingTime(int)),
this->parent(), SLOT(slotRenderingTime(int)));
// std::cout << "timer " << timer << "\n";
std::cout << "timer " << timer << "\n";
// Create my interactor style
InteractorStyle* style = InteractorStyle::New();
_renderWinInteractor->SetInteractorStyle( style );
......@@ -586,7 +613,7 @@ void ThreadVisualisation::initGlyphs3D()
//importer->GetRenderWindow()->GetInteractor()->Start();
////collect all the elements from the 3ds
vtkActorCollection* collection=importer->GetRenderer()->GetActors();
vtkActorCollection* collection=importer->GetRenderer()x->GetActors();
vtkActor *actorCharlie= collection->GetLastActor();
actorCharlie->InitPathTraversal();
vtkMapper *mapperCharlie=actorCharlie->GetMapper();
......
......@@ -74,6 +74,8 @@ extern vtkActor* extern_glyphs_pedestrians_actor_2D;
extern vtkActor* extern_glyphs_pedestrians_actor_3D;
extern SyncData extern_trajectories_firstSet;
// extern vtkSmartPointer<vtkSphereSource> extern_mysphere;
class ThreadVisualisation :public QThread {
Q_OBJECT
......
This diff is collapsed.
......@@ -52,6 +52,8 @@ class vtkFFMPEGWriter;
#include <vtkTensorGlyph.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkLineSource.h>
#include "train.h"
class SyncData;
class QObject;
......@@ -89,6 +91,9 @@ extern PointPlotter* extern_trail_plotter;
extern SyncData extern_trajectories_firstSet;
extern SyncData mysphere;
extern std::map<std::string, std::shared_ptr<TrainType> > extern_trainTypes;
extern std::map<int, std::shared_ptr<TrainTimeTable> > extern_trainTimeTables;
//states if the datasets are loaded.
extern bool extern_first_dataset_loaded;
......@@ -126,6 +131,8 @@ public:
void SetRenderTimerId(int tid);
void setTextActor(vtkTextActor* runningTime);
vtkSmartPointer<vtkPolyData> train(double x1, double y1, double x2, double y2);
vtkSmartPointer<vtkLineSource> door(double x1, double y1, double x2, double y2);
private:
///updates system global changes, like fullscreen, ffw and soone
......
......@@ -46,10 +46,9 @@
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include "train.h"
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
//external variables
/// define the speed/rate/pace at which the trajectories are displayed.
......@@ -84,6 +83,9 @@ double extern_scale_pedestrian=0.1;
// At most three pedestrians groups can be loaded
///The first pedestrian group
Pedestrian** extern_pedestrians_firstSet=NULL;
vtkSmartPointer<vtkSphereSource> extern_mysphere=nullptr;
std::map<std::string, std::shared_ptr<TrainType> > extern_trainTypes;
std::map<int, std::shared_ptr<TrainTimeTable> > extern_trainTimeTables;
//vtkSmartPointer<vtkTensorGlyph> extern_glyphs_pedestrians=NULL;
......
......@@ -25,7 +25,7 @@
*
*
**/
#ifndef _MACROS_H
#define _MACROS_H
......@@ -39,9 +39,15 @@
#include <iostream>
enum RoomState {
ROOM_CLEAN=0,
ROOM_SMOKED=1
};
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
#endif
//fix for osx/linux/win
#define _isnan(x) std::isnan(x)
......@@ -89,11 +95,6 @@
#define LIST_EMPTY -1
enum RoomState {
ROOM_CLEAN=0,
ROOM_SMOKED=1
};
enum AgentType {
MALE=0,
FEMALE,
......
......@@ -82,6 +82,35 @@ Building::Building(const std::string& filename, const std::string& rootDir, Rout
}
#endif
// bool Building::AddTrainType(std::shared_ptr<TrainType> TT)
// {
// if (_trainTypes.count(TT->type)!=0) {
// // Log->Write("WARNING: Duplicate type for train found [%s]",TT->type);
// }
// _trainTypes[TT->type] = TT;
// return true;
// }
// bool Building::AddTrainTimeTable(std::shared_ptr<TrainTimeTable> TTT)
// {
// if (_trainTimeTables.count(TTT->id)!=0) {
// Log->Write("WARNING: Duplicate id for train time table found [%d]",TTT->id);
// exit(EXIT_FAILURE);
// }
// _trainTimeTables[TTT->id] = TTT;
// return true;
// }
// const std::map<std::string, std::shared_ptr<TrainType> >& Building::GetTrainTypes() const
// {
// return _trainTypes;
// }
// const std::map<int, std::shared_ptr<TrainTimeTable> >& Building::GetTrainTimeTables() const
// {
// return _trainTimeTables;
// }
Building::~Building()
{
//
......
......@@ -43,6 +43,12 @@
#include "Obstacle.h"
#include "Goal.h"
#include "../tinyxml/tinyxml.h"
// train schedules: Trains get deleted and added.
class RoutingEngine;
class Pedestrian;
class Transition;
......@@ -67,6 +73,8 @@ private:
std::map<int, Hline*> _hLines;
std::map<int, Goal*>_goals;
/// pedestrians pathway
bool _savePathway;
std::ofstream _pathWayStream;
......@@ -101,6 +109,9 @@ public:
Transition* GetTransition(int id) ;
Transition* ParseTransitionNode(TiXmlElement * xTrans);
/**
* Not implemented
*/
......
......@@ -578,7 +578,7 @@ void FacilityGeometry::addObstacles(vtkPolyData* polygonPolyData )
void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, double z, double color1, double color2, string text)
{
//if(z!=1)return;
const double cellSize=40; //cm
const double cellSize=10; //cm
// const int dimX=(x2-x1)/cellSize+1;
// const int dimY=(y2-y1)/cellSize+1;
......
......@@ -23,7 +23,7 @@
*
*
**/
#ifndef _ROOM_H
#define _ROOM_H
......@@ -165,4 +165,3 @@ public:
};
#endif /* _ROOM_H */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment