From 52a3614e9b3a976c0adf2140c61fe6dfab32c5b2 Mon Sep 17 00:00:00 2001
From: Ulrich Kemloh <u.kemloh@fz-juelich.de>
Date: Thu, 9 Aug 2012 13:41:49 +0000
Subject: [PATCH] TraVisTo can now natively display the new goemetry format.
 version has to be "0.4" as in <geometry version ="0.4" caption="second life"
 gridSizeX="20" gridSizeY="20" unit="m"> and extension .xml

---
 src/InteractorStyle.cpp         |   1 -
 src/SaxParser.cpp               | 123 +++++++++++++++++++++++++++++++-
 src/SaxParser.h                 |   3 +
 src/geometry/FacilityGeometry.h |   2 +-
 src/travisto.cpp                |  18 ++---
 5 files changed, 134 insertions(+), 13 deletions(-)

diff --git a/src/InteractorStyle.cpp b/src/InteractorStyle.cpp
index 73407d1..6be369c 100644
--- a/src/InteractorStyle.cpp
+++ b/src/InteractorStyle.cpp
@@ -107,7 +107,6 @@ void InteractorStyle::OnChar() {
 	case 27:
 		extern_fullscreen_enable = false;
 		extern_force_system_update = true;
-		std::cout << "esc pressed" << std::endl;
 		break;
 
 	case 'a': {
diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp
index 6279414..c421ec2 100644
--- a/src/SaxParser.cpp
+++ b/src/SaxParser.cpp
@@ -59,10 +59,9 @@ SaxParser::SaxParser(FacilityGeometry* geo, SyncData* data, double* fps){
 	geometry=geo;
 	dataset=data;
 	para=fps;
+	parsingWalls=false;
 
 	dataset->clearFrames();
-
-	parsingWalls=false;
 }
 
 SaxParser::~SaxParser() {
@@ -869,4 +868,124 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD
 	}
 }
 
+void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){
+	QDomDocument doc("");
+
+	QFile file(filename);
+	if (!file.open(QIODevice::ReadOnly)) {
+		qDebug()<<"could not open the file: "<<filename<<endl;
+		return ;
+	}
+	QString *errorCode = new QString();
+	if (!doc.setContent(&file, errorCode)) {
+		file.close();
+		qDebug()<<errorCode<<endl;
+		return ;
+	}
+	QDomElement root= doc.documentElement();
+
+	//only parsing the geometry node
+	if(root.tagName()!="geometry") return;
+
+
+	double version =root.attribute("version","-1").toDouble();
+
+	if(version<0.4){
+		QMessageBox::warning(0, QObject::tr("Parsing Error"),
+				QObject::tr("Only geometry version >= 0.4 supported"));
+	}
+
+	//parsing the subrooms
+	QDomNodeList xSubRoomsNodeList=doc.elementsByTagName("subroom");
+	//parsing the walls
+	for (unsigned int i = 0; i < xSubRoomsNodeList.length(); i++) {
+		QDomElement xPoly = xSubRoomsNodeList.item(i).firstChildElement("polygon");
+		while(!xPoly.isNull()) {
+			//wall thickness, default to 30 cm
+			double thickness = xPoly.attribute("thickness","15").toDouble();
+			//wall height default to 250 cm
+			double height = xPoly.attribute("height","250").toDouble();
+			//wall color default to blue
+			double color = xPoly.attribute("color","0").toDouble();
+
+			QDomNodeList xVertices=xPoly.elementsByTagName("vertex");
+			for( int i=0;i<xVertices.count()-1;i++){
+				double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble();
+				double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble();
+				double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble();
 
+				double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble();
+				double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble();
+				geo->addWall(x1, y1, x2, y2,z1,thickness,height,color);
+			}
+			xPoly = xPoly.nextSiblingElement("polygon");
+		}
+	}
+
+	QDomNodeList xObstaclesList=doc.elementsByTagName("obstacle");
+	for (unsigned int i = 0; i < xObstaclesList.length(); i++) {
+		QDomElement xPoly = xObstaclesList.item(i).firstChildElement("polygon");
+		while(!xPoly.isNull()) {
+			//wall thickness, default to 30 cm
+			double thickness = xPoly.attribute("thickness","15").toDouble();
+			//wall height default to 250 cm
+			double height = xPoly.attribute("height","250").toDouble();
+			//wall color default to blue
+			double color = xPoly.attribute("color","0").toDouble();
+
+			QDomNodeList xVertices=xPoly.elementsByTagName("vertex");
+			for( int i=0;i<xVertices.count()-1;i++){
+				double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble();
+				double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble();
+				double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble();
+
+				double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble();
+				double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble();
+				geo->addWall(x1, y1, x2, y2,z1,thickness,height,color);
+			}
+			xPoly = xPoly.nextSiblingElement("polygon");
+		}
+	}
+
+	QDomNodeList xCrossingsList=doc.elementsByTagName("crossing");
+	for (unsigned int i = 0; i < xCrossingsList.length(); i++) {
+		QDomElement xCrossing = xCrossingsList.item(i).toElement();
+		QDomNodeList xVertices=xCrossing.elementsByTagName("vertex");
+
+		///door thickness, default to 15 cm
+		double thickness = xCrossing.attribute("thickness","15").toDouble();
+		//door height default to 250 cm
+		double height = xCrossing.attribute("height","250").toDouble();
+		//door color default to blue
+		double color = xCrossing.attribute("color","255").toDouble();
+
+		double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble();
+		double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble();
+		double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble();
+
+		double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble();
+		double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble();
+		geo->addDoor(x1, y1, x2, y2,z1,thickness,height,color);
+	}
+
+	QDomNodeList xTransitionsList=doc.elementsByTagName("transition");
+	for (unsigned int i = 0; i < xTransitionsList.length(); i++) {
+		QDomElement xTransition = xTransitionsList.item(i).toElement();
+		QDomNodeList xVertices=xTransition.elementsByTagName("vertex");
+
+		///door thickness, default to 15 cm
+		double thickness = xTransition.attribute("thickness","15").toDouble();
+		//door height default to 250 cm
+		double height = xTransition.attribute("height","250").toDouble();
+		//door color default to blue
+		double color = xTransition.attribute("color","255").toDouble();
+
+		double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble();
+		double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble();
+		double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble();
+
+		double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble();
+		double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble();
+		geo->addDoor(x1, y1, x2, y2,z1,thickness,height,color);
+	}
+}
diff --git a/src/SaxParser.h b/src/SaxParser.h
index 83752e6..be322fe 100644
--- a/src/SaxParser.h
+++ b/src/SaxParser.h
@@ -68,6 +68,9 @@ public:
 	/// provided for convenience and will be removed in the next version
 	static void parseGeometryPG3(QString content, FacilityGeometry *geo);
 
+	/// provided for convenience and will be removed in the next version
+	static void parseGeometryXMLV04(QString content, FacilityGeometry *geo);
+
 	/// provided for convenience and will be removed in the next version
 	static void parseGeometryTRAV(QString content, FacilityGeometry *geo,QDomNode geoNode=NULL);
 
diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h
index 58abeda..adf7b5f 100644
--- a/src/geometry/FacilityGeometry.h
+++ b/src/geometry/FacilityGeometry.h
@@ -33,7 +33,7 @@
 #ifndef FACILITYGEOMETRY_H_
 #define FACILITYGEOMETRY_H_
 
-#include<string>
+#include <string>
 
 //forwarded classes
 class vtkPolyData;
diff --git a/src/travisto.cpp b/src/travisto.cpp
index 57edee9..3cf0668 100644
--- a/src/travisto.cpp
+++ b/src/travisto.cpp
@@ -266,10 +266,10 @@ void TraVisTo::slotHelpAbout() {
 	QMessageBox::about(
 			this,
 			"About TraVisTo",
-			"Version 0.2 build with  QT 4.6 and VTK 5.4\n\n"
+			"Version 0.4 build with  QT 4.6 and VTK 5.4\n\n"
 			"TraVisTo stands for Trajectories Visualisation Tool. It is a tool for visualizing pedestrians motion\n"
-			"developped at the Forschungszentrum Juelich, Germany\n\n"
-			"Copyright 2009-2011.\n"
+			"developped at the Forschungszentrum Juelich GmbH, Germany\n\n"
+			"Copyright 2009-2012.\n"
 			"Authors: Ulrich Kemloh\n\n"
 			"For questions, contact +49-40-246161-4193 \nor mail at \n"
 			"u.kemloh@fz-juelich.de\n");
@@ -579,14 +579,14 @@ bool TraVisTo::addPedestrianGroup(int groupID,QString fileName){
 	{
 		//geometry=parseGeometryPG3(fileName);
 		SaxParser::parseGeometryPG3(fileName,geometry);
-
 	}
 
-	//	// if jul is detected, just load and show the geometry then exit
-	//	if(fileName.endsWith(".jul",Qt::CaseInsensitive)){
-	//		slotLoadParseShowGeometry(fileName);
-	//		return false;
-	//	}
+	// if xml is detected, just load and show the geometry then exit
+	else if(fileName.endsWith(".xml",Qt::CaseInsensitive)){
+		SaxParser::parseGeometryXMLV04(fileName,geometry);
+		//slotLoadParseShowGeometry(fileName);
+		//return false;
+	}
 
 	QFile file(fileName);
 	if (!file.open(QIODevice::ReadOnly)) {
-- 
GitLab