From b916ef6bdf26eff37ff81b5e38b854537f690367 Mon Sep 17 00:00:00 2001
From: Ulrich Kemloh <kemlohulrich@gmail.com>
Date: Mon, 21 Jul 2014 17:11:34 +0200
Subject: [PATCH] fixed error in reading the embedded geometry file

---
 src/MainWindow.cpp                | 13 ++++++++++---
 src/SaxParser.cpp                 | 14 ++++++++------
 src/SystemSettings.cpp            | 21 ++++++++++++++++-----
 src/SystemSettings.h              | 11 +++++++----
 src/ThreadVisualisation.cpp       | 24 ++++++++++++------------
 src/TimerCallback.cpp             |  6 +++++-
 src/geometry/Building.cpp         |  2 +-
 src/geometry/FacilityGeometry.cpp |  9 +++++++--
 src/geometry/FacilityGeometry.h   |  2 ++
 9 files changed, 68 insertions(+), 34 deletions(-)

diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index a505983..f48b930 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -547,13 +547,19 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){
 
     if(fileName.isEmpty())
         fileName = QFileDialog::getOpenFileName(this,
-                                                "Select the file containing data to visualize",
+                                                "Select the file containing the data to visualize",
                                                 "F:\\workspace\\JPSvis\\data",
-                                                "Visualisation Files (*.dat *.trav *.xml *.pg3 *.jul);;All Files (*.*)");
+                                                "Visualisation Files (*.dat *.trav *.xml);;All Files (*.*)");
 
     if (fileName.isNull()) {
         return false;
     }
+
+    //get and set the working dir
+    QFileInfo fileInfo(fileName);
+    QString wd=fileInfo.absoluteDir().absolutePath();
+    SystemSettings::setWorkingDirectory(wd);
+
     //the geometry actor
     //FacilityGeometry* geometry=NULL;
     FacilityGeometry* geometry = visualisationThread->getGeometry();
@@ -1354,7 +1360,7 @@ void MainWindow::slotPreviousFrame(){
 
 void MainWindow::slotShowPedestrianCaption(){
 
-    SystemSettings::setShowCaptions(ui.actionShow_Captions->isChecked());
+    SystemSettings::setShowAgentsCaptions(ui.actionShow_Captions->isChecked());
     extern_force_system_update=true;
 }
 
@@ -1575,5 +1581,6 @@ void MainWindow::slotShowHideGeometryCaptions(){
 
     bool value=ui.actionShow_Geometry_Captions->isChecked();
     visualisationThread->setGeometryLabelsVisibility(value);
+    //SystemSettings::setShowCaptions(value);
     //SystemSettings::setOnScreenInfos(value);
 }
diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp
index e74dc1f..2d21f30 100644
--- a/src/SaxParser.cpp
+++ b/src/SaxParser.cpp
@@ -37,6 +37,7 @@
 #include "geometry/JPoint.h"
 #include "geometry/FacilityGeometry.h"
 #include "geometry/Building.h"
+#include "SystemSettings.h"
 
 #include <QMessageBox>
 #include <QString>
@@ -617,8 +618,12 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){
 
 	if(!fileName.endsWith(".xml",Qt::CaseInsensitive)) return ;
 
+    QString wd;
+    SystemSettings::getWorkingDirectory(wd);
+    fileName=wd+"/"+fileName;
+
 	Building* building = new Building();
-	string geometrypath = fileName.toStdString();
+    string geometrypath = fileName.toStdString();
 
 	// read the geometry
 	building->LoadBuildingFromFile(geometrypath);
@@ -890,12 +895,9 @@ void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
 	QDomDocument doc("");
 
 	QFile file(filename);
-    //int size =file.size()/(1024*1024);
 
-    //if(size>100){
-    //	cout<<"The file is too large: "<<filename.toStdString()<<endl;
-    //	return;
-    //}
+    //TODO: check if you can parse this with the building classes.
+    // This should be a fall back option
 
 	if (!file.open(QIODevice::ReadOnly)) {
 		qDebug()<<"could not open the file: "<<filename<<endl;
diff --git a/src/SystemSettings.cpp b/src/SystemSettings.cpp
index f25d4c0..43be1c2 100644
--- a/src/SystemSettings.cpp
+++ b/src/SystemSettings.cpp
@@ -40,7 +40,7 @@
 
 bool SystemSettings::showLegend=false;
 bool SystemSettings::pedColorProfileReadFromFile=true;
-bool SystemSettings::showCaption=false;
+bool SystemSettings::showAgentsCaptions=false;
 bool SystemSettings::is2D=false;
 bool SystemSettings::showAgents=true;
 bool SystemSettings::showGeometry=true;
@@ -63,6 +63,7 @@ bool SystemSettings::onScreenInfos=true;
 bool SystemSettings::recordPNGsequence=false;
 //QString SystemSettings::outputDir =QDir::currentPath()+"/";
 QString SystemSettings::outputDir  = QDir::homePath() +"/Desktop/TraVisTo_Files/";
+QString SystemSettings::workingDir  = QDir::currentPath();
 QString SystemSettings::filesPrefix="";
 
 
@@ -90,12 +91,12 @@ unsigned short   SystemSettings::getListeningPort(){
 }
 
 
-void  SystemSettings::setShowCaptions(bool caption){
-	showCaption=caption;
+void  SystemSettings::setShowAgentsCaptions(bool caption){
+    showAgentsCaptions=caption;
 }
 
-bool  SystemSettings::getShowCaption(){
-	return showCaption;
+bool  SystemSettings::getShowAgentsCaptions(){
+    return showAgentsCaptions;
 }
 
 void SystemSettings::set2D(bool lis2D){
@@ -126,6 +127,16 @@ bool SystemSettings::getShowGeometry()
     return showGeometry;
 }
 
+void   SystemSettings::setWorkingDirectory(QString dir)
+{
+    workingDir=dir;
+}
+
+void   SystemSettings::getWorkingDirectory(QString& dir)
+{
+    dir=workingDir;
+}
+
 void  SystemSettings::getBackgroundColor(double* col){
 	col[0]=bgColor[0];
 	col[1]=bgColor[1];
diff --git a/src/SystemSettings.h b/src/SystemSettings.h
index 8e6455b..58a12ae 100644
--- a/src/SystemSettings.h
+++ b/src/SystemSettings.h
@@ -48,8 +48,8 @@ public:
 	bool static getShowLegend();
 
 	//set/get the caption status
-	void static setShowCaptions(bool caption);
-	bool static getShowCaption();
+    void static setShowAgentsCaptions(bool caption);
+    bool static getShowAgentsCaptions();
 
 	// set/get the listening port
 	void static setListningPort(unsigned short port);
@@ -67,6 +67,9 @@ public:
     void static setShowGeometry(bool status);
     bool static getShowGeometry();
 
+    void static setWorkingDirectory(QString dir);
+    void static getWorkingDirectory(QString& dir);
+
 	// set/get the bk color
 	// todo done directly in the travisto.cpp
 	void static getBackgroundColor(double* col);
@@ -151,13 +154,12 @@ private:
 	static bool recordPNGsequence;
 	static bool pedColorProfileReadFromFile;
 	static bool showLegend;
-	static bool showCaption;
+    static bool showAgentsCaptions;
 	static bool is2D; //   Toggle 2D/3D mode
     static bool showAgents;
     static bool showGeometry;
 	static unsigned short port;
 	static double bgColor[3];
-	//static double ellipseShape[2];
 	static int ellipseResolution;
 	static int pedestriansColor[3][3]; // 3 groups, and 3 color per groups
 	static int pedesShape;
@@ -166,6 +168,7 @@ private:
 	static int trailingType;
 	static int trailingGeometry;
 	static QString outputDir;
+    static QString workingDir;
 	static int captionSize;
 	static QColor captionColor;
 	static int captionOrientaton;
diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp
index f8c757d..534cade 100644
--- a/src/ThreadVisualisation.cpp
+++ b/src/ThreadVisualisation.cpp
@@ -73,6 +73,7 @@
 #include <vtkCylinderSource.h>
 #include <vtkWindowToImageFilter.h>
 #include <vtkActor.h>
+#include <vtkLightKit.h>
 
 
 #include "geometry/FacilityGeometry.h"
@@ -279,9 +280,19 @@ void ThreadVisualisation::run(){
 	renderWinInteractor->Initialize();
 
     //add a light kit
+    {
+        VTK_CREATE(vtkLightKit, lightKit);
+        //lightKit->SetKeyLightIntensity(1);
+
+        //lightKit->SetKeyLightWarmth(5);
+        //lightKit->SetBackLightAngle(30,40);
+        //lightKit->SetKeyLightWarmth(2.0);
+        //lightKit->SetMaintainLuminance(true);
+        //lightKit->AddLightsToRenderer(renderer);
+    }
 
 
-    if(SystemSettings::get2D()){
+    if(true || SystemSettings::get2D()){
         renderer->GetActiveCamera()->OrthogonalizeViewUp();
         renderer->GetActiveCamera()->ParallelProjectionOn();
         renderer->ResetCamera();
@@ -1061,14 +1072,3 @@ void ThreadVisualisation::setOnscreenInformationVisibility(bool show){
 	runningTime->SetVisibility(show);
 }
 
-//void ThreadVisualisation::WindowModifiedCallback( vtkObject*
-//		caller, unsigned long eventId,void* clientData ,void* callData )
-//{
-//	vtkRenderWindow* window = static_cast<vtkRenderWindow*>(caller);
-//	int* windowSize = window->GetSize();
-//
-//
-//	int *pos=renderWindow->GetSize();
-//	runningTime->SetPosition(pos[1]/2,pos[0]);
-//
-//}
diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp
index c79bcf1..ed8336f 100644
--- a/src/TimerCallback.cpp
+++ b/src/TimerCallback.cpp
@@ -183,7 +183,7 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId,
                         {
                             const std::vector<FrameElement *> &elements=frame->GetFrameElements();
 
-                            for(int i=0;i<elements.size();i++)
+                            for(unsigned int i=0;i<elements.size();i++)
                             {
                                 FrameElement* el = elements[i];
                                 double pos[3];
@@ -333,6 +333,10 @@ void TimerCallback::updateSettings(vtkRenderWindow* renderWindow) {
     extern_glyphs_pedestrians_actor_3D->SetVisibility(SystemSettings::getShowAgents()&& !SystemSettings::get2D());
     extern_trail_plotter->SetVisibility(extern_tracking_enable);
 
+    //agents captions
+    extern_pedestrians_labels->SetVisibility(SystemSettings::getShowAgentsCaptions());
+
+    //geometry captions
 
     //enable / disable full screen
     if(fullscreen!=extern_fullscreen_enable){
diff --git a/src/geometry/Building.cpp b/src/geometry/Building.cpp
index 5fcc440..54bf5a3 100644
--- a/src/geometry/Building.cpp
+++ b/src/geometry/Building.cpp
@@ -322,7 +322,7 @@ void Building::LoadBuildingFromFile(const std::string &filename) {
 	TiXmlDocument docGeo(geoFilename);
 	if (!docGeo.LoadFile()){
 		Log->Write("ERROR: \t%s", docGeo.ErrorDesc());
-		Log->Write("ERROR: \t could not parse the geometry file");
+        Log->Write("ERROR: \t could not parse the geometry file [%s]",geoFilename.c_str());
 		exit(EXIT_FAILURE);
 	}
 
diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp
index 5f39a9b..f0001c7 100644
--- a/src/geometry/FacilityGeometry.cpp
+++ b/src/geometry/FacilityGeometry.cpp
@@ -123,12 +123,16 @@ vtkAssembly* FacilityGeometry::getActor2D(){
 	return assembly2D;
 }
 
+ vtkAssembly* FacilityGeometry::getCaptionsActor()
+ {
+     return assemblyCaptions;
+ }
+
  vtkAssembly* FacilityGeometry::getActor3D()
  {
      assembly3D->AddPart(assemblyDoors3D);
      assembly3D->AddPart(assemblyWalls3D);
-//    assembly3D->AddPart(assemblyObjects);
-//     assembly3D->AddPart(assemblyCaptions);
+     assembly3D->AddPart(assemblyCaptions);
      return assembly3D;
  }
 
@@ -667,6 +671,7 @@ void FacilityGeometry::addObjectLabel(double center[3], double orientation[3], s
 vtkActor2DCollection* FacilityGeometry::getCaptions(){
 	return captions;
 }
+
 // orientation and color ignored
 void FacilityGeometry::addNewElementText(double center[3], double orientation[3],
 string text, double color) {
diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h
index 1bf9d75..49aae3e 100644
--- a/src/geometry/FacilityGeometry.h
+++ b/src/geometry/FacilityGeometry.h
@@ -70,6 +70,8 @@ public:
 
     vtkAssembly* getActor3D();
 
+    vtkAssembly* getCaptionsActor();
+
 	vtkActor2DCollection* getCaptions();
 
 	///draw a wall
-- 
GitLab