Commit fe6b9e4d authored by Mohcine Chraibi's avatar Mohcine Chraibi

Merge branch 'trains' into 'master'

Trains

See merge request !2
parents b130f1be 711fa9e7
Pipeline #21352 passed with stages
in 16 seconds
......@@ -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,6 @@ void ThreadVisualisation::slotSetFrameRate(float fps)
void ThreadVisualisation::run()
{
// std::cout << "RUN " << _runningTime << "\n";
//deactivate the output windows
vtkObject::GlobalWarningDisplayOff();
......@@ -180,59 +179,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 +325,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,7 +338,6 @@ void ThreadVisualisation::run()
QObject::connect(renderingTimer, SIGNAL(signalRenderingTime(int)),
this->parent(), SLOT(slotRenderingTime(int)));
// std::cout << "timer " << timer << "\n";
// Create my interactor style
InteractorStyle* style = InteractorStyle::New();
......@@ -586,7 +612,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
......
......@@ -37,7 +37,7 @@
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#ifdef TRAVISTO_FFMPEG
#ifdef _WIN32
......@@ -77,8 +77,14 @@
#include <vtkLabeledDataMapper.h>
#include <vtkMath.h>
#include <vtkPolyLine.h>
#include <vtkTextProperty.h>
#include <vtkProperty.h>
#include <vtkLineSource.h>
#include <vtkVectorText.h>
#include <vtkFollower.h>
#include <vtkLine.h>
#include <vtkTubeFilter.h>
#include "geometry/FacilityGeometry.h"
#include "geometry/Point.h"
......@@ -92,12 +98,17 @@
#include "TrailPlotter.h"
#include "geometry/PointPlotter.h"
#include "TimerCallback.h"
#include <vtkTextActor3D.h>
#define VTK_CREATE(type, name) \
vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
using namespace std;
static int once=1;
TimerCallback* TimerCallback::New()
{
TimerCallback *cb = new TimerCallback;
......@@ -126,6 +137,10 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
vtkRenderWindow *renderWindow = iren->GetRenderWindow();
vtkRenderer *renderer =renderWindow->GetRenderers()->GetFirstRenderer();
if (iren && renderWindow && renderer) {
//first pedestrian group
......@@ -145,9 +160,98 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
frame = extern_trajectories_firstSet.getNextFrame();
}
frameNumber=extern_trajectories_firstSet.getFrameCursor();
if(frame==NULL)
frameNumber=extern_trajectories_firstSet.getFrameCursor();
double now = frameNumber*iren->GetTimerDuration(tid)/1000;
// {
// for (auto tab: extern_trainTimeTables)
// {
// VTK_CREATE(vtkPolyDataMapper, mapper);
// VTK_CREATE(vtkActor, actor);
// }
// }
int countTrains = 0;
char label[100];
for (auto tab: extern_trainTimeTables)
{
// VTK_CREATE(vtkTextActor, textActor);
VTK_CREATE(vtkTextActor3D, textActor);
auto trainType = tab.second->type;
sprintf(label, "%s_%d", trainType.c_str(), tab.second->id);
auto trainId = tab.second->id;
auto trackStart = tab.second->pstart;
auto trackEnd = tab.second->pend;
auto trainStart = tab.second->tstart;
auto trainEnd = tab.second->tend;
auto train = extern_trainTypes[trainType];
auto doors = train->doors;
std::vector<Point> doorPoints;
auto mapper = tab.second->mapper;
auto actor = tab.second->actor;
auto txtActor = tab.second->textActor;
for(auto door: doors)
{
doorPoints.push_back(door.GetPoint1());
doorPoints.push_back(door.GetPoint2());
}//doors
if(once)
{
auto data = getTrainData(trainStart, trainEnd, doorPoints);
mapper->SetInputData(data);
actor->SetMapper(mapper);
actor->GetProperty()->SetLineWidth(10);
actor->GetProperty()->SetOpacity(0.1);//feels cool!
actor->GetProperty()->SetColor(
std::abs(0.9-renderer->GetBackground()[0]),
std::abs(0.9-renderer->GetBackground()[1]),
std::abs(1.0-renderer->GetBackground()[2])
);
// text
txtActor->GetTextProperty()->SetOpacity(0.7);
double pos_x = 50*(trainStart._x + trainEnd._x+0.5);
double pos_y = 50*(trainStart._y + trainEnd._y+0.5);
txtActor->SetPosition (pos_x, pos_y+2, 20);
txtActor->SetInput (label);
txtActor->GetTextProperty()->SetFontSize (30);
txtActor->GetTextProperty()->SetBold (true);
txtActor->GetTextProperty()->SetColor (
std::abs(0.9-renderer->GetBackground()[0]),
std::abs(0.9-renderer->GetBackground()[1]),
std::abs(0.5-renderer->GetBackground()[2])
);
txtActor->SetVisibility(false);
}
if((now >= tab.second->tin) && (now <= tab.second->tout))
{
actor->SetVisibility(true);
txtActor->SetVisibility(true);
}
else
{
actor->SetVisibility(false);
txtActor->SetVisibility(false);
}
if(once)
{
renderer->AddActor(actor);
renderer->AddActor(txtActor);
if(countTrains == extern_trainTimeTables.size())
once = 0;
}
countTrains++;
}// time table
if(frame==NULL)
{
} else {
......@@ -205,7 +309,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
int* winSize=renderWindow->GetSize();
static int lastWinX=winSize[0]+1; // +1 to trigger a first change
static int lastWinY=winSize[1];
// HHHHHH
sprintf(runningTimeText,"Pedestrians: %d Time: %ld Sec",nPeds,frameNumber*iren->GetTimerDuration(tid)/1000);
runningTime->SetInput(runningTimeText);
runningTime->Modified();
......@@ -252,6 +356,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
emit signalFrameNumber(frameNumber, minFrame);
emit signalRunningTime(frameNumber*iren->GetTimerDuration(tid));
emit signalRenderingTime(effectivefps);
}
#ifdef TRAVISTO_FFMPEG
......@@ -542,3 +647,60 @@ void TimerCallback::setTextActor(vtkTextActor* ra)
{
runningTime=ra;
}
// https://vtk.org/Wiki/VTK/Examples/Cxx/GeometricObjects/ColoredLines
vtkSmartPointer<vtkPolyData> TimerCallback::getTrainData(
Point trainStart, Point trainEnd, std::vector<Point> doorPoints)
{
float factor = 100.0;
double pt[3] = { 1.0, 0.0, 0.0 }; // to convert from Point
// Create the polydata where we will store all the geometric data
vtkSmartPointer<vtkPolyData> linesPolyData =
vtkSmartPointer<vtkPolyData>::New();
// Create a vtkPoints container and store the points in it
vtkSmartPointer<vtkPoints> pts =
vtkSmartPointer<vtkPoints>::New();
pt[0] = factor*trainStart._x; pt[1] = factor*trainStart._y;
pts->InsertNextPoint(pt);
for(auto p: doorPoints)
{
pt[0] = factor*p._x; pt[1] = factor*p._y;
pts->InsertNextPoint(pt);
}
pt[0] = factor*trainEnd._x; pt[1] = factor*trainEnd._y;
pts->InsertNextPoint(pt);
// Add the points to the polydata container
linesPolyData->SetPoints(pts);
vtkSmartPointer<vtkCellArray> lines =
vtkSmartPointer<vtkCellArray>::New();
// Create the first line (between Origin and P0)
for(int i = 0; i<= doorPoints.size(); i+=2 )
{
vtkSmartPointer<vtkLine> line =
vtkSmartPointer<vtkLine>::New();
line->GetPointIds()->SetId(0, i);
line->GetPointIds()->SetId(1, i+1);
lines->InsertNextCell(line);
lines->InsertNextCell(line);
line = nullptr;
}
// Add the lines to the polydata container
linesPolyData->SetLines(lines);
return linesPolyData;
}
......@@ -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,12 @@ public:
void SetRenderTimerId(int tid);