SaxParser.cpp 64.5 KB
Newer Older
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1 2 3 4 5 6 7 8
/**
 * @file    SaxParser.cpp
 * @author  Ulrich Kemloh <kemlohulrich@gmail.com>
 * @version 0.1
 * Created on: 6 Sep 2010
 * Copyright (C) <2009-2010>
 *
 * @section LICENSE
Mohcine Chraibi's avatar
Mohcine Chraibi committed
9
 * This file is part of JuPedSim.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
10
 *
Mohcine Chraibi's avatar
Mohcine Chraibi committed
11
 * JuPedSim is free software: you can redistribute it and/or modify
Ulrich Kemloh's avatar
Ulrich Kemloh committed
12 13 14 15 16 17 18 19 20 21
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * OpenPedSim is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
Mohcine Chraibi's avatar
Mohcine Chraibi committed
22
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
23 24 25 26 27 28 29 30 31
 *
 * @section DESCRIPTION
 *
 *
 *
 */

#include "SaxParser.h"
#include "TrajectoryPoint.h"
32
#include "FrameElement.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
33 34 35 36
#include "Frame.h"
#include "SyncData.h"
#include "Debug.h"

37
#include "geometry/JPoint.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
38
#include "geometry/FacilityGeometry.h"
39
#include "geometry/Building.h"
40 41
#include "geometry/GeometryFactory.h"

42
#include "geometry/Wall.h"
43 44
#include "geometry/SubRoom.h"

45
#include "SystemSettings.h"
Ulrich Kemloh's avatar
Ulrich Kemloh committed
46 47 48

#include <QMessageBox>
#include <QString>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
49 50
#include <QProgressDialog>
#include <QPushButton>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
51 52
#include <limits>
#include <iostream>
53
#include <cmath>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
54

55 56 57 58 59 60 61 62 63 64 65 66
#include <vtkVersion.h>
#include <vtkSmartPointer.h>
#include <vtkPolygon.h>
#include <vtkCellArray.h>
#include <vtkPolyData.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkAssembly.h>
#include <vtkProperty.h>
67
#include <vtkTriangleFilter.h>
68 69 70 71 72
#include <vtkGenericDataObjectReader.h>
#include <vtkPolyDataReader.h>
#include <vtkStructuredGridReader.h>
#include <vtkStructuredPointsReader.h>
#include <vtkImageDataGeometryFilter.h>
73
#include <vtkStripper.h>
74

75

Mohcine Chraibi's avatar
Mohcine Chraibi committed
76 77
#define VTK_CREATE(type, name)                                  \
     vtkSmartPointer<type> name = vtkSmartPointer<type>::New()
78

79

Ulrich Kemloh's avatar
Ulrich Kemloh committed
80 81 82 83
using namespace std;

/**
 * constructor
84 85 86 87 88 89
 *
 * @param geo
 * @param data
 * @param par 0=fps, 1=agents
 * @param roomCaption
 * @return
Ulrich Kemloh's avatar
Ulrich Kemloh committed
90
 */
91
SaxParser::SaxParser(GeometryFactory& geoFac, SyncData& dataset, double * fps):_geoFactory(geoFac),_dataset(dataset)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
92
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
93 94 95 96 97
     _para=fps;
     _parsingWalls=false;
     _parsingCrossings=false;
     _color=0.0;
     _dataset.clearFrames();
98

Mohcine Chraibi's avatar
Mohcine Chraibi committed
99 100
     _geometry = std::shared_ptr<FacilityGeometry>(new FacilityGeometry("No name", "No name", "No name"));
     _geoFactory.AddElement(-1,-1,_geometry);
101

Mohcine Chraibi's avatar
Mohcine Chraibi committed
102 103
     //default header
     InitHeader(0,0,0);
Ulrich Kemloh's avatar
Ulrich Kemloh committed
104 105
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
106 107
SaxParser::~SaxParser()
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
108 109 110 111

}

bool SaxParser::startElement(const QString & /* namespaceURI */,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
112 113
                             const QString & /* localName */, const QString &qName,
                             const QXmlAttributes &at)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
114
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
     if (qName == "header") {
          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="version") {
                    QStringList query = at.value(i).split(".");
                    int major=0;
                    int minor=0;
                    int patch=0;
                    switch (query.size() ) {
                    case 1:
                         major=query.at(0).toInt();
                         break;
                    case 2:
                         major=query.at(0).toInt();
                         minor=query.at(1).toInt();
                         break;
                    case 3:
                         major=query.at(0).toInt();
                         minor=query.at(1).toInt();
                         patch=query.at(2).toInt();
                         break;
135
                    }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
                    InitHeader(major,minor,patch);
                    //cout<<"version found:"<<at.value(i).toStdString()<<endl;exit(0);
               }
          }
     } else if (qName == "file") {
          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="location") {
                    QString fileName=at.value(i);
                    if(!fileName.isEmpty()) {
                         if(fileName.endsWith(".xml",Qt::CaseInsensitive)) {
                              //SaxParser::parseGeometryJPS(fileName,geometry);
                         } else if (fileName.endsWith(".trav",Qt::CaseInsensitive)) {
                              SaxParser::parseGeometryTRAV(fileName,_geoFactory);
                         }
                    }
               }
          }
     }
     else if (qName == "source")
     {
          double xmin, xmax, ymin, ymax;
          double z=0;// @todo read this some when we go 3D

          int source_id=-1;
          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="id") {
                    source_id=at.value(i).toInt();
               } else if(at.localName(i)=="x_min") {
                    xmin=at.value(i).toDouble()*FAKTOR;
               }
               else if(at.localName(i)=="x_max") {
                    xmax=at.value(i).toDouble()*FAKTOR;
               }
               else if(at.localName(i)=="y_min") {
                    ymin=at.value(i).toDouble()*FAKTOR;
               }
               else if(at.localName(i)=="y_max") {
                    ymax=at.value(i).toDouble()*FAKTOR;
               }
          }
          _geometry->addSource(xmin,ymin,xmax,ymax);

          // double CHT[3]= {_color,_height,_thickness};
          // JPoint* pt1= new JPoint(xmin,ymin,z);
          // JPoint* pt2= new JPoint(xmin,ymax,z);
          // JPoint* pt3= new JPoint(xmax,ymin,z);
          // JPoint* pt4= new JPoint(xmax,ymax,z);
          // pt1->setColorHeightThicknes(CHT);
          // pt2->setColorHeightThicknes(CHT);
          // pt3->setColorHeightThicknes(CHT);
          // pt4->setColorHeightThicknes(CHT);
          // _currentPointsList.push_back(pt1);
          // _currentPointsList.push_back(pt2);
          // _currentPointsList.push_back(pt3);
          // _currentPointsList.push_back(pt4);
     } // source
     else if (qName == "floor") {
          double xMin=0,
               xMax=0,
               yMin=0,
               yMax=0;

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="xMin") {
                    xMin=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="xMax") {
                    xMax=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="yMin") {
                    yMin=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="yMax") {
                    yMax=at.value(i).toDouble()*FAKTOR;
               }

          }
          _geometry->addFloor(xMin,yMin,xMax,yMax);
     } else if (qName == "cuboid") {
          double length=0, height=0,
               width=0, color=0;
          double center[3]= {0,0,0};

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="centerX") {
                    center[0]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerY") {
                    center[1]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerZ") {
                    center[2]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="length") {
                    length=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="height") {
                    height=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="width") {
                    width=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    color=at.value(i).toDouble()*FAKTOR;
               }
          }
          _geometry->addObjectBox(center,height,width,length,color);

     } else if (qName == "sphere") {
          double radius=0, color=0;
          double center[3]= {0,0,0};

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="centerX") {
                    center[0]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerY") {
                    center[1]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerZ") {
                    center[2]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="radius") {
                    radius=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    color=at.value(i).toDouble();
               }
          }
          _geometry->addObjectSphere(center,radius,color);
     } else if (qName == "label") {
          double  color=0;
          double center[3]= {0,0,0};
          QString text;

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="centerX") {
                    center[0]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerY") {
                    center[1]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerZ") {
                    center[2]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="text") {
                    text=at.value(i);
               } else if(at.localName(i)=="color") {
                    color=at.value(i).toDouble();
               }
          }
          _geometry->addObjectLabel(center,center,text.toStdString(),color);
     } else if (qName == "cylinder") {
          double height=0, radius=0, color=0;
          double center[3]= {0,0,0};
          double rotation[3]= {0,0,0};

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="centerX") {
                    center[0]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerY") {
                    center[1]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="centerZ") {
                    center[2]=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="height") {
                    height=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="radius") {
                    radius=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    color=at.value(i).toDouble();
               } else if(at.localName(i)=="angleX") {
                    rotation[0]=at.value(i).toDouble();
               } else if(at.localName(i)=="angleY") {
                    rotation[1]=at.value(i).toDouble();
               } else if(at.localName(i)=="angleZ") {
                    rotation[2]=at.value(i).toDouble();
               }
          }
          _geometry->addObjectCylinder(center,radius,height,rotation,color);
     } else if (qName == "agents") {
     } else if (qName == "roomCaption") {
     } else if (qName == "frameRate") {
     } else if (qName == "geometry")
     {
          //cout<<"geo tag found"<<endl;
          //_geometry = std::shared_ptr<FacilityGeometry>(new FacilityGeometry("No name"));
          //_geoFactory.AddElement(0,0,_geometry);

     }else if (qName == "gradient_field"){
          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="filename") {
                    ParseGradientFieldVTK(at.value(i),_geoFactory);
               }
          }

     }
     else if (qName == "wall") {
          _parsingWalls=true;
          _thickness=15;
          _height=250;
          _color=0;
          _caption="";

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="thickness") {
                    _thickness=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="height") {
                    _height=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    _color=at.value(i).toDouble();
               } else if(at.localName(i)=="caption") {
                    _caption=at.value(i);
               }
          }

     } else if (qName == "door") {
          _parsingWalls=false;
          _thickness=15;
          _height=250;
          _color=255;
          _caption="";

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="thickness") {
                    _thickness=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="height") {
                    _height=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    _color=at.value(i).toDouble();
               } else if(at.localName(i)=="caption") {
                    _caption=at.value(i);
               }
          }

     }
//FIXME
     else if (qName == "crossing") {
          _parsingWalls=false;
          _parsingCrossings=true;
          _thickness=15;
          _height=250;
          _color=255;
          _caption="";

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="thickness") {
                    _thickness=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="height") {
                    _height=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    _color=at.value(i).toDouble();
               } else if(at.localName(i)=="caption") {
                    _caption=at.value(i);
               }
          }

     }else if (qName == "hline") {
          _parsingWalls=false;
          _parsingCrossings=true;
          _thickness=15;
          _height=250;
          _color=255;
          _caption="";
          QString room_id, subroom_id;

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="thickness") {
                    _thickness=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="height") {
                    _height=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="color") {
                    _color=at.value(i).toDouble();
               } else if(at.localName(i)=="caption") {
                    _caption=at.value(i);
               }else if(at.localName(i)=="room_id") {
                    room_id=at.value(i);
               }else if(at.localName(i)=="subroom_id") {
                    subroom_id=at.value(i);
               }
          }
          _caption=room_id+":"+subroom_id+":"+_caption;

     }
     else if (qName == "timeFirstFrame") {
          /*unsigned long timeFirstFrame_us=0;
            unsigned long timeFirstFrame_s=0;

            for(int i=0; i<at.length(); i++) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
408
            if(at.localName(i)=="microsec") {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
409
            timeFirstFrame_us=at.value(i).toULong();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
410
            } else if(at.localName(i)=="sec") {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
411
            timeFirstFrame_s=at.value(i).toULong();
Ulrich Kemloh's avatar
Ulrich Kemloh committed
412
            }
413
            }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502
            dataset->setDelayAbsolute(timeFirstFrame_s,timeFirstFrame_us);
          */
     } else if (qName == "point") {
          double xPos=0;
          double yPos=0;
          double zPos=0;

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="xPos") {
                    xPos=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="yPos") {
                    yPos=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)=="zPos") {
                    zPos=at.value(i).toDouble()*FAKTOR;
               }
          }
          double CHT[3]= {_color,_height,_thickness};
          JPoint* pt= new JPoint(xPos,yPos,zPos);
          pt->setColorHeightThicknes(CHT);
          _currentPointsList.push_back(pt);

     }
     else if (qName == "frame")
     {
          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="ID") {
                    _currentFrameID=at.value(i).toInt();
                    //cout<<"frame: " <<_currentFrameID<<endl;
               }
          }

     }
     else if (qName == "agent") {

          int id=0;
          double xPos=0;
          double yPos=0;
          double zPos=0;
          //double agent_color =std::numeric_limits<double>::quiet_NaN();
          //double xVel=std::numeric_limits<double>::quiet_NaN();
          //double yVel=std::numeric_limits<double>::quiet_NaN();
          //double zVel=std::numeric_limits<double>::quiet_NaN();
          double dia_a=std::numeric_limits<double>::quiet_NaN();
          double dia_b=std::numeric_limits<double>::quiet_NaN();
          double el_angle=std::numeric_limits<double>::quiet_NaN();
          double el_color=std::numeric_limits<double>::quiet_NaN();
          double el_x=std::numeric_limits<double>::quiet_NaN();
          double el_y=std::numeric_limits<double>::quiet_NaN();
          double el_z=std::numeric_limits<double>::quiet_NaN();

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="ID") {
                    id=at.value(i).toInt();
                    //TODO: maybe you should change ur format to take the ID 0 as first valid ID.
                    if (id==0) {
                         //slotErrorOutput("Person with ID=0 detected. ID should start with 1 !");
                         return false;
                    }
               } else if(at.localName(i)==_jps_xPos) {
                    xPos=at.value(i).toDouble()*FAKTOR;
                    //xPos=at.value(i).toDouble();
               } else if(at.localName(i)==_jps_yPos) {
                    //yPos=at.value(i).toDouble();
                    yPos=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)==_jps_zPos) {
                    zPos=at.value(i).toDouble()*FAKTOR;
               }

               else if(at.localName(i)==_jps_radiusA) {
                    dia_a=at.value(i).toDouble()*FAKTOR;
                    //dia_a=at.value(i).toDouble();
               } else if(at.localName(i)==_jps_radiusB) {
                    dia_b=at.value(i).toDouble()*FAKTOR;
                    //dia_b=at.value(i).toDouble();
               } else if(at.localName(i)==_jps_ellipseOrientation) {
                    el_angle=at.value(i).toDouble();
               } else if(at.localName(i)==_jps_ellipseColor) {
                    el_color=at.value(i).toDouble();
               } else if(at.localName(i)=="agentColor") {
                    //agent_color=at.value(i).toDouble();
               } else if(at.localName(i)==_jps_xVel) {
                    //xVel=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)==_jps_yVel) {
                    //yVel=at.value(i).toDouble()*FAKTOR;
               } else if(at.localName(i)==_jps_zVel) {
                    //zVel=at.value(i).toDouble()*FAKTOR;
               }

          }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
503 504
//        xml2txt
//        cout << _currentFrameID << " " << id << " " << xPos << " " << yPos << " " << zPos << "\n";
505

Mohcine Chraibi's avatar
Mohcine Chraibi committed
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
          //coordinates of the ellipse, default to the head of the agent
          //if(std::isnan(el_x)) el_x=xPos;
          //if(std::isnan(el_y)) el_y=yPos;
          //if(std::isnan(el_z)) el_z=zPos;

          //double pos[3]={xPos,yPos,zPos};
          //double vel[3]={xVel,yPos,zPos};
          //double ellipse[7]={el_x,el_y,el_z,dia_a,dia_b,el_angle,el_color};
          //double para[2]={agent_color,el_angle};

          double pos[3]= {xPos,yPos,zPos};
          double angle[3]= {0,0,el_angle};
          double radius[3]= {dia_a,dia_b,30.0};

          FrameElement *element = new FrameElement(id-1);
          element->SetPos(pos);
          element->SetOrientation(angle);
          element->SetRadius(radius);
          element->SetColor(el_color);
          _currentFrame.push_back(element);

     } else if (qName == "agentInfo") {
          double height=std::numeric_limits<double>::quiet_NaN();
          double color=std::numeric_limits<double>::quiet_NaN();
          double id=std::numeric_limits<double>::quiet_NaN();

          for(int i=0; i<at.length(); i++) {
               if(at.localName(i)=="ID") {
                    id=at.value(i).toDouble();
               }
               if(at.localName(i)=="height") {
                    height=at.value(i).toDouble()*FAKTOR;
               }
               if(at.localName(i)=="color") {
                    color=at.value(i).toDouble();
               }
          }
          if(std::isnan(id)) return true;

          if(!std::isnan(height)) {
               _initialPedestriansHeights.append(QString::number(int(id)));
               _initialPedestriansHeights.append(QString::number(height));
          }
          if(!std::isnan(color)) {
               _initialPedestriansColors.append(QString::number(int(id)));
               _initialPedestriansColors.append(QString::number(int(color)));
          }
     }
     return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
555 556
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
557 558
bool SaxParser::characters(const QString &str)
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
559 560
     _currentText.append(str);
     return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
561 562 563
}

bool SaxParser::endElement(const QString & /* namespaceURI */,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
564
                           const QString & /* localName */, const QString &qName)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
565
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585
     if (qName == "header") {

     } else if (qName == "agents") {
          _dataset.setNumberOfAgents(_currentText.toInt());
     } else if (qName == "frameRate") {
          _para[0]=_currentText.toFloat();
     } else if (qName == "wall") {
          if(_currentPointsList.size()>1)
               for(unsigned int i=0; i<_currentPointsList.size()-1; i++) {
                    _geometry->addWall(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString());
               }
          clearPoints();
     } else if (qName == "door") {
          for(unsigned int i=0; i<_currentPointsList.size()-1; i++) {
               _geometry->addDoor(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString());
          }
          clearPoints();
     } else if (qName == "crossing") {
          if(_currentPointsList.size()>1) //hack
               for(unsigned int i=0; i<_currentPointsList.size()-1; i++) {
586
                    _geometry->addNavLine(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643
               }
          clearPoints();
     } else if (qName == "hline") {
          if(_currentPointsList.size()>1)
          {
               for(unsigned int i=0; i<_currentPointsList.size()-1; i++)
               {
                    int room_id=-1;
                    int subroom_id=-1;
                    QStringList lst = _caption.split(":");
                    if(lst.length()>2)
                    {
                         room_id=lst[0].toInt();
                         subroom_id=lst[1].toInt();
                         _caption=lst[2];
                    }
                    auto&& geo=_geoFactory.GetElement(room_id,subroom_id);
                    if(geo!=nullptr)
                    {
                         geo->addNavLine(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString());
                    }
                    else
                    {
                         _geometry->addNavLine(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString());
                    }
               }
          }
          clearPoints();
     } else if (qName == "step") {//FIXME
          for(unsigned int i=0; i<_currentPointsList.size()-1; i++) {
               _geometry->addDoor(_currentPointsList[i],_currentPointsList[i+1],_caption.toStdString());
          }
          clearPoints();
     } else if (qName == "frame") {
          Frame* frame = new Frame(_currentFrameID);
          while(!_currentFrame.empty()) {
               frame->addElement(_currentFrame.back());
               _currentFrame.pop_back();
          }

          //compute the polydata, might increase the runtime
          frame->ComputePolyData();

          _dataset.addFrame(frame);
          //to be on the safe side
          _currentFrame.clear();

     } else if (qName == "agent") {
     } else if (qName == "geometry") {
     } else if (qName == "point") {
     } else if (qName == "shape") {
          _dataset.setInitialHeights(_initialPedestriansHeights);
          _dataset.setInitialColors(_initialPedestriansColors);
     } else if (qName == "gradient_field") {
     }
     _currentText.clear();
     return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
644 645
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
646 647
bool SaxParser::fatalError(const QXmlParseException &exception)
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
648 649 650 651 652
     QMessageBox::warning(0, QObject::tr("SAX Handler"), QObject::tr(
                               "Parse error at line %1, column "
                               "%2:\n%3.") .arg(exception.lineNumber()) .arg(
                                    exception.columnNumber()) .arg(exception.message()));
     return false;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
653 654 655
}

bool SaxParser::attributeDecl(const QString& eName, const QString& aName,
Ulrich Kemloh's avatar
Ulrich Kemloh committed
656 657
                              const QString& type, const QString& valueDefault, const QString& value)
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
658
     //cout<<aName.toStdString()<<endl;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
659

Mohcine Chraibi's avatar
Mohcine Chraibi committed
660 661 662
     QString dummy=eName+aName+type+valueDefault+value;
     return (dummy==dummy);
     //return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
663 664
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
665 666
void SaxParser::clearPoints()
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
667 668 669 670 671 672
     while (!_currentPointsList.empty()) {
          delete _currentPointsList.back();
          _currentPointsList.pop_back();
     }
     _currentPointsList.clear();
     return;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
673 674 675
}

/// provided for convenience and will be removed in the next version
676
bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac)
Mohcine Chraibi's avatar
Mohcine Chraibi committed
677 678 679
{
     Debug::Messages( "Enter SaxParser::parseGeometryJPS with filename <%s>",fileName.toStdString().c_str());

Mohcine Chraibi's avatar
Mohcine Chraibi committed
680 681 682
     double captionsColor=0;//red
     if(!fileName.endsWith(".xml",Qt::CaseInsensitive)) return false;
     QString wd;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
683
     QDir dir(wd);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
684
     SystemSettings::getWorkingDirectory(wd);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
685 686
     QString s = dir.relativeFilePath(fileName);
     fileName=wd + QDir::separator() + s;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
687 688 689
     // QString = QDir::cleanPath(wd + QDir::separator() + fileName);
     Debug::Messages("filename: <%s)", fileName.toStdString().c_str());
     Debug::Messages("wd: <%s>",wd.toStdString().c_str());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
690

Mohcine Chraibi's avatar
Mohcine Chraibi committed
691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709
     Building* building = new Building();
     string geometrypath = fileName.toStdString();
     // read the geometry
     if(!building->LoadGeometry(geometrypath))
          return false;
     if(!building->InitGeometry())
          return false; // create the polygons

     int room_id = -1;
     int subroom_id = -1;
     for(auto&& itr_room: building->GetAllRooms())
     {
          room_id++;
          for(auto&& itr_subroom: itr_room.second->GetAllSubRooms())
          {
               subroom_id++;
               string room_caption = itr_room.second->GetCaption() + "_RId_" + QString::number(itr_room.first).toStdString();
               string subroom_caption = itr_subroom.second->GetCaption()+ "_RId_" + QString::number(itr_room.first).toStdString();
               auto geometry= shared_ptr<FacilityGeometry>(
710
                    new FacilityGeometry(itr_subroom.second->GetType(), room_caption, subroom_caption
Mohcine Chraibi's avatar
Mohcine Chraibi committed
711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
                         )
                    );
               int currentFloorPolyID=0;
               int currentObstPolyID=0;

               // Setup the points
               VTK_CREATE(vtkPoints,floor_points);
               VTK_CREATE(vtkPoints,obstacles_points);
               // Add the polygon to a list of polygons
               VTK_CREATE(vtkCellArray,floor_polygons);
               VTK_CREATE(vtkCellArray,obstacles_polygons);

               //string caption = r->GetCaption();
               SubRoom* sub = itr_subroom.second.get();

               vector<Point> poly = sub->GetPolygon();
               if(sub->IsClockwise()==true) {
                    std::reverse(poly.begin(),poly.end());
               }

               // Create the polygon
               VTK_CREATE(vtkPolygon,polygon);
               polygon->GetPointIds()->SetNumberOfIds(poly.size());

               for (unsigned int s=0; s<poly.size(); s++) {
                    floor_points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR);
                    polygon->GetPointIds()->SetId(s, currentFloorPolyID++);
               }
               floor_polygons->InsertNextCell(polygon);

               //plot the walls only for not stairs
               const vector<Wall>& walls= sub->GetAllWalls();
               for(unsigned int w=0; w<walls.size(); w++) {
                    Point p1 = walls[w].GetPoint1();
                    Point p2 = walls[w].GetPoint2();
746 747 748
                    double z1= sub->GetElevation(p1);
                    double z2= sub->GetElevation(p2);

Mohcine Chraibi's avatar
Mohcine Chraibi committed
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
                    if(sub->GetType()=="stair") {
                         geometry->addStair(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR);
                    } else {
                         geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR);
                    }
               }

               //insert the subroom caption
               string caption=itr_room.second->GetCaption()+" ( " + QString::number(sub->GetSubRoomID()).toStdString() + " ) ";
               const Point& p=sub->GetCentroid();
               double z= sub->GetElevation(p);
               double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR};
               geometry->addObjectLabel(pos,pos,caption,captionsColor);

               //plot the obstacles
               for(auto obst:sub->GetAllObstacles())
               {
                    for(auto wall: obst->GetAllWalls())
                    {
                         Point p1 = wall.GetPoint1();
                         Point p2 = wall.GetPoint2();
                         double z1= sub->GetElevation(p1);
                         double z2= sub->GetElevation(p2);
                         geometry->addWall(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR);
                    }
                    //add the obstacle caption
                    const Point& p=obst->GetCentroid();
                    double z= sub->GetElevation(p);
                    double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR};
                    geometry->addObjectLabel(pos,pos,obst->GetCaption(),captionsColor);

                    //add a special texture to the obstacles
                    auto poly = obst->GetPolygon();
                    //if(obst->IsClockwise()==true) {
                    //  std::reverse(poly.begin(),poly.end());
                    //}

                    // Create the polygon
                    VTK_CREATE(vtkPolygon,polygon);
                    polygon->GetPointIds()->SetNumberOfIds(poly.size());

                    for (unsigned int s=0; s<poly.size(); s++) {
                         obstacles_points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR);
                         polygon->GetPointIds()->SetId(s, currentObstPolyID++);
                    }
                    obstacles_polygons->InsertNextCell(polygon);
               }

               // Create a PolyData to represent the floor
               VTK_CREATE(vtkPolyData, floorPolygonPolyData);
               floorPolygonPolyData->SetPoints(floor_points);
               floorPolygonPolyData->SetPolys(floor_polygons);
               geometry->addFloor(floorPolygonPolyData);

               // Create a PolyData to represen the obstacles
               VTK_CREATE(vtkPolyData, obstPolygonPolyData);
               obstPolygonPolyData->SetPoints(obstacles_points);
               obstPolygonPolyData->SetPolys(obstacles_polygons);
               geometry->addObstacles(obstPolygonPolyData);

               // add the crossings
               for(auto&& cr: itr_subroom.second->GetAllCrossings())
               {
                    Point p1 = cr->GetPoint1();
                    Point p2 = cr->GetPoint2();
                    double z1= cr->GetSubRoom1()->GetElevation(p1);
                    double z2= cr->GetSubRoom1()->GetElevation(p2);
                    geometry->addNavLine(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR);

                    const Point& p =cr->GetCentre();
                    double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR};
                    geometry->addObjectLabel(pos,pos,"nav_"+QString::number(cr->GetID()).toStdString()+"_"+
                                             QString::number(cr->GetUniqueID()).toStdString()
                                             ,captionsColor);
               }

               // add the exits
               for(auto&& tr: itr_subroom.second->GetAllTransitions())
               {
                    Point p1 = tr->GetPoint1();
                    Point p2 = tr->GetPoint2();
                    double z1 = 0;
                    double z2 = 0;

                    if(tr->GetSubRoom1()) // get elevation for both points
                    {
                         z2 = tr->GetSubRoom1()->GetElevation(p2);
                         z1 = tr->GetSubRoom1()->GetElevation(p1);
                    }
                    else if(! tr->GetSubRoom2())
                    {
                         z2 = tr->GetSubRoom2()->GetElevation(p2);
                         z1 = tr->GetSubRoom2()->GetElevation(p1);
                    }
                    else
                         std::cout << "ERROR: Can not calculate elevations for transition " << tr->GetID() << ", " << tr->GetCaption() << ". Both subrooms are not defined \n";
845

Mohcine Chraibi's avatar
Mohcine Chraibi committed
846
                    geometry->addDoor(p1._x*FAKTOR, p1._y*FAKTOR, z1*FAKTOR, p2._x*FAKTOR, p2._y*FAKTOR,z2*FAKTOR);
847

Mohcine Chraibi's avatar
Mohcine Chraibi committed
848 849 850 851 852
                    const Point& p =tr->GetCentre();
                    double pos[3]= {p._x*FAKTOR,p._y*FAKTOR,z1*FAKTOR};
                    geometry->addObjectLabel(pos,pos,"door_"+QString::number(tr->GetID()).toStdString()+
                                             +"_"+ QString::number(tr->GetUniqueID()).toStdString(),captionsColor);
               }
853

Mohcine Chraibi's avatar
Mohcine Chraibi committed
854 855 856
               geoFac.AddElement(room_id,subroom_id,geometry);
          }
     }
857

Mohcine Chraibi's avatar
Mohcine Chraibi committed
858 859 860 861

     // free memory
     delete building;
     return true;
862 863
}

Ulrich Kemloh's avatar
Ulrich Kemloh committed
864
/// provided for convenience and will be removed in the next version
865

866
void SaxParser::parseGeometryTRAV(QString content, GeometryFactory& geoFac,QDomNode geo)
867
{
Ulrich Kemloh's avatar
Ulrich Kemloh committed
868

Mohcine Chraibi's avatar
Mohcine Chraibi committed
869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942
     cout<<"external geometry found"<<endl;
     //creating am empty document
     // to be filled
     QDomDocument doc("");
     QDomNode geoNode;
     auto geometry= shared_ptr<FacilityGeometry>(new FacilityGeometry("no name", "no name", "no name"));

     //first try to open the file
     if(content.endsWith(".trav",Qt::CaseInsensitive) ) {
          QFile file(content);
          if (!file.open(QIODevice::ReadOnly)) {
               //slotErrorOutput("could not open the File" );
               cout<<"could not open the File"<<endl;
               return ;
          }
          QString *errorCode = new QString();
          if (!doc.setContent(&file, errorCode)) {
               file.close();
               //slotErrorOutput(*errorCode);
               cout<<errorCode->toStdString()<<endl;
               return ;
          }
          file.close();
          geoNode =doc.documentElement().namedItem("geometry");

          if (geoNode.isNull()) {
               cout<<"No geometry information found. <geometry> <geometry/> tag is missing."<<endl;
          }
     } else {
          if(content.isEmpty()) {
               geoNode=geo;
               cout <<"parsing the old fashion way"<<endl;
          } else {
               content = "<travisto>\n" +content+ "\n</travisto>\n";
               QString errorMsg="";
               doc.setContent(content,&errorMsg);

               if(!errorMsg.isEmpty()) {
                    Debug::Error("%s", (const char *)errorMsg.toStdString().c_str());
                    return;
               }
               geoNode =doc.elementsByTagName("geometry").item(0);
          }
     }

     // for the case there is more than just one geometry Node
     while (!geoNode.isNull()) {
          QDomElement e = geoNode.toElement();
          QDomNodeList walls = e.elementsByTagName("wall");
          QDomNodeList doors = e.elementsByTagName("door");

          //objects which can be positioned everywhere in the facility
          QDomNodeList spheres = e.elementsByTagName("sphere");
          QDomNodeList cuboids = e.elementsByTagName("cuboid");
          QDomNodeList floors = e.elementsByTagName("floor");
          QDomNodeList cylinders = e.elementsByTagName("cylinder");
          QDomNodeList labels = e.elementsByTagName("label");


          //parsing the walls
          for (  int i = 0; i < walls.length(); i++) {
               QDomElement el = walls.item(i).toElement();

               //wall thickness, default to 30 cm
               double thickness = el.attribute("thickness","15").toDouble()*FAKTOR;
               //wall height default to 250 cm
               double height = el.attribute("height","250").toDouble()*FAKTOR;
               //wall color default to blue
               double color = el.attribute("color","0").toDouble();

               //get the points defining each wall
               //not that a wall is not necessarily defined by two points, could be more...
               QDomNodeList points = el.elementsByTagName("point");
               for (  int i = 0; i < points.length() - 1; i++) {
Ulrich Kemloh's avatar
Ulrich Kemloh committed
943

944 945 946
                    double x1=points.item(i).toElement().attribute("xPos", "0").toDouble()*FAKTOR;
                    double y1=points.item(i).toElement().attribute("yPos", "0").toDouble()*FAKTOR;
                    double z1=points.item(i).toElement().attribute("zPos", "0").toDouble()*FAKTOR;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
947

948 949 950
                    double x2=points.item(i+1).toElement().attribute("xPos", "0").toDouble()*FAKTOR;
                    double y2=points.item(i+1).toElement().attribute("yPos", "0").toDouble()*FAKTOR;
                    double z2=points.item(i+1).toElement().attribute("zPos", "0").toDouble()*FAKTOR;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
                    geometry->addWall(x1, y1,z1 ,x2, y2,z2,thickness,height,color);
               }
          }

          //parsing the doors
          if(doors.length()>0)
               for (  int i = 0; i < doors.length(); i++) {
                    QDomElement el = doors.item(i).toElement();

                    //door thickness, default to 15 cm
                    double thickness = el.attribute("thickness","15").toDouble()*FAKTOR;
                    //door height default to 250 cm
                    double height = el.attribute("height","250").toDouble()*FAKTOR;
                    //door color default to blue
                    double color = el.attribute("color","255").toDouble();

                    //get the points defining each wall
                    //not that a wall is not necesarily defined by two points, could be more...
                    QDomNodeList points = el.elementsByTagName("point");
                    //Debug::Messages("found:  " << points.length() <<" for this wall" <<endl;
                    for (  int i = 0; i < points.length() - 1; i++) {

                         double x1=points.item(i).toElement().attribute("xPos", "0").toDouble()*FAKTOR;
                         double y1=points.item(i).toElement().attribute("yPos", "0").toDouble()*FAKTOR;
                         double z1=points.item(i).toElement().attribute("zPos", "0").toDouble()*FAKTOR;

                         double x2=points.item(i+1).toElement().attribute("xPos", "0").toDouble()*FAKTOR;
                         double y2=points.item(i+1).toElement().attribute("yPos", "0").toDouble()*FAKTOR;
                         double z2=points.item(i+1).toElement().attribute("zPos", "0").toDouble()*FAKTOR;
                         geometry->addDoor(x1, y1, z1, x2, y2,z2,thickness,height,color);
                    }
               }

          // parsing the objets
          for (  int i = 0; i < spheres.length(); i++) {

               double center[3];
               center[0] = spheres.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR;
               center[1]= spheres.item(i).toElement().attribute("centerY", "0").toDouble()*FAKTOR;
               center[2]= spheres.item(i).toElement().attribute("centerZ", "0").toDouble()*FAKTOR;
               double color= spheres.item(i).toElement().attribute("color", "0").toDouble()*FAKTOR;
               double radius= spheres.item(i).toElement().attribute("radius", "0").toDouble()*FAKTOR;
               //double width = spheres.item(i).toElement().attribute("width", "0").toDouble();
               //double height= spheres.item(i).toElement().attribute("height", "0").toDouble();

               geometry->addObjectSphere(center,radius,color);
          }
          // cubic shapes
          for (  int i = 0; i < cuboids.length(); i++) {

               double center[3];
               center[0] = cuboids.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR;
               center[1]= cuboids.item(i).toElement().attribute("centerY", "0").toDouble()*FAKTOR;
               center[2]= cuboids.item(i).toElement().attribute("centerZ", "0").toDouble()*FAKTOR;
               double color= cuboids.item(i).toElement().attribute("color", "0").toDouble();
               double length= cuboids.item(i).toElement().attribute("length", "0").toDouble()*FAKTOR;
               double width = cuboids.item(i).toElement().attribute("width", "0").toDouble()*FAKTOR;
               double height= cuboids.item(i).toElement().attribute("height", "0").toDouble()*FAKTOR;
               geometry->addObjectBox(center,height,width,length,color);
               //		Debug::Error("cuboids: "<<length<<" || " <<width << " || "<<height<<" || "<<color<<endl;
          }
          // floors
          for (  int i = 0; i < floors.length(); i++) {

               double left =floors.item(i).toElement().attribute("xMin","0").toDouble()*FAKTOR;
               double right =floors.item(i).toElement().attribute("xMax","0").toDouble()*FAKTOR;
               double up =floors.item(i).toElement().attribute("yMax","0").toDouble()*FAKTOR;
               double down =floors.item(i).toElement().attribute("yMin","0").toDouble()*FAKTOR;
               double z =floors.item(i).toElement().attribute("z","0").toDouble()*FAKTOR;
               geometry->addFloor(left,down,right,up,z);
          }
          // cylinders
          for (  int i = 0; i < cylinders.length(); i++) {

               double center[3], rotation[3];
               center[0] = cylinders.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR;
               center[1]= cylinders.item(i).toElement().attribute("centerY", "0").toDouble()*FAKTOR;
               center[2]= cylinders.item(i).toElement().attribute("centerZ", "0").toDouble()*FAKTOR;
               double color= cylinders.item(i).toElement().attribute("color", "0").toDouble();
               double radius= cylinders.item(i).toElement().attribute("radius", "0").toDouble()*FAKTOR;
               double height= cylinders.item(i).toElement().attribute("height", "0").toDouble()*FAKTOR;
               rotation[0] = cylinders.item(i).toElement().attribute("angleX", "90").toDouble();
               rotation[1] = cylinders.item(i).toElement().attribute("angleY", "0").toDouble();
               rotation[2] = cylinders.item(i).toElement().attribute("angleZ", "0").toDouble();
               geometry->addObjectCylinder(center,radius,height,rotation,color);
          }

          //Labels
          for (  int i = 0; i < labels.length(); i++) {

               double center[3];
               center[0] = labels.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR;
               center[1]= labels.item(i).toElement().attribute("centerY", "0").toDouble()*FAKTOR;
               center[2]= labels.item(i).toElement().attribute("centerZ", "0").toDouble()*FAKTOR;
               double color= labels.item(i).toElement().attribute("color", "0").toDouble();
               string caption= labels.item(i).toElement().attribute("text", "").toStdString();
               geometry->addObjectLabel(center,center,caption,color);
          }
          // you should normally have only one geometry node, but one never knows...
          geoNode = geoNode.nextSiblingElement("geometry");
     }

     geoFac.AddElement(0,0,geometry);
1054 1055 1056 1057
}

QString SaxParser::extractGeometryFilename(QString &filename)
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
     QString extracted_geo_name="";
     //first try to look at a string <file location="filename.xml"/>
     QFile file(filename);
     QString line;
     if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
          QTextStream in(&file);
          while (!in.atEnd()) {
               //look for a line with
               line = in.readLine();
               //cout<<"checking: "<<line.toStdString()<<endl;
               if(line.contains("location" ,Qt::CaseInsensitive))
                    if(line.contains("<file" ,Qt::CaseInsensitive)) {
                         //try to extract what ever is inside the quotes

                         QString begin="\"";
                         QString end="\"";
                         int startIndex = line.indexOf(begin)+begin.length();
                         if(startIndex <= 0)continue; //false alarm
                         int endIndex = line.indexOf(end,startIndex);
                         if(endIndex <= 0)continue; // false alarm
                         extracted_geo_name= line.mid(startIndex,endIndex - startIndex);
                         return extracted_geo_name;
                         //break;// we are done
                    }
               if(line.contains("<geometry" ,Qt::CaseInsensitive))
                    if(line.contains("version" ,Qt::CaseInsensitive)) {
                         //real geometry file
                         QFileInfo fileInfoGeometry(filename);
                         extracted_geo_name=fileInfoGeometry.fileName();
                         return extracted_geo_name;
                    }
          }
     }

     //maybe this is already the geometry file itself ?
     //do a rapid test
     //    FacilityGeometry* geo = new FacilityGeometry();
     //    QFileInfo fileInfoGeometry(filename);
     //    extracted_geo_name=fileInfoGeometry.fileName();

     //    //just check if it starts with geometry
     //    //if(parseGeometryJPS(extracted_geo_name,geo)==true)
     //    //{
     //        return extracted_geo_name;
     //    //}
     //    delete geo;

     return "";
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1106 1107
}

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117
QString SaxParser::extractGeometryFilenameTXT(QString &filename)
{
     QString extracted_geo_name="";
     QFile file(filename);
     QString line;
     if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
          QTextStream in(&file);
          while (!in.atEnd()) {
               //look for a line with
               line = in.readLine();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1118
               // std::cout << " >> " <<  line.toStdString().c_str() << endl;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1119 1120
               if(line.split(":").size()==2)
               {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1121
                    if(line.split(":")[0].contains("geometry",Qt::CaseInsensitive))
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1122
                    {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1123 1124
                         extracted_geo_name = line.split(":")[1].simplified().remove(' ');
                         break;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1125 1126 1127 1128
                    }
               }
          }// while
     } // if open
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1129
     if(extracted_geo_name=="")
1130 1131 1132 1133 1134
     {
          Debug::Warning("Could not extract geometry file!");
//          extracted_geo_name = "geo.xml";
     }

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1135 1136 1137
     else
          Debug::Messages("Extracted geometry from TXT file <%s>", extracted_geo_name.toStdString().c_str());
     return extracted_geo_name;
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1138 1139 1140
}


1141
void SaxParser::parseGeometryXMLV04(QString filename, GeometryFactory& geoFac)
1142
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321
     cout << "parsing 04\n" ;
     QDomDocument doc("");
     QFile file(filename);

     int size =file.size()/(1024*1024);

     //avoid dom parsing a very large dataset
     if(size>500) {
          //cout<<"The file is too large: "<<filename.toStdString()<<endl;
          return;
     }

     auto geo= shared_ptr<FacilityGeometry>(new FacilityGeometry("no name", "no name", "no name"));
     //cout<<"filename: "<<filename.toStdString()<<endl;

     //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;
          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();

     string unit=root.attribute("unit","cm").toStdString();
     double xToCmfactor=100;
     if (unit=="cm") xToCmfactor=1;
     if (unit=="m") xToCmfactor=100;

     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 (  int i = 0; i < xSubRoomsNodeList.length(); i++) {
          QDomElement xPoly = xSubRoomsNodeList.item(i).firstChildElement("polygon");
          double position[3]= {0,0,0};
          double pos_count=1;
          double color=0;

          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
               color = xPoly.attribute("color","0").toDouble();

               QDomNodeList xVertices=xPoly.elementsByTagName("vertex");
               pos_count+=xVertices.count()-1;

               for( int i=0; i<xVertices.count()-1; i++) {
                    //all unit are converted in cm
                    double x1=xVertices.item(i).toElement().attribute("px", "0").toDouble()*xToCmfactor;
                    double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble()*xToCmfactor;
                    double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
                    double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
                    double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
                    double z2=xVertices.item(i+1).toElement().attribute("pz", "0").toDouble()*xToCmfactor;

                    position[0]+= x1;
                    position[1]+= y1;
                    position[2]+= z1;

                    geo->addWall(x1, y1, z1, x2, y2,z2,thickness,height,color);
               }
               xPoly = xPoly.nextSiblingElement("polygon");
          }

          //add the caption
          string roomCaption = xSubRoomsNodeList.item(i).parentNode().toElement().attribute("caption").toStdString();
          string subroomCaption=xSubRoomsNodeList.item(i).toElement().attribute("id").toStdString();
          string caption=roomCaption+" ( " + subroomCaption + " ) ";
          position[0]/=pos_count;
          position[1]/=pos_count;
          position[2]/=pos_count;
          geo->addObjectLabel(position,position,caption,color);
          geo->SetRoomCaption(roomCaption);
          geo->SetSubRoomCaption(subroomCaption);
          cout<<"position: [" <<position[0]<<", "<<position[1]<<", "<<position[2]<<" ]"<<endl;;
          cout << roomCaption<< "  " << subroomCaption << "\n" ;
     }

     QDomNodeList xObstaclesList=doc.elementsByTagName("obstacle");
     for (  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()*xToCmfactor;
                    double y1=xVertices.item(i).toElement().attribute("py", "0").toDouble()*xToCmfactor;
                    double z1=xVertices.item(i).toElement().attribute("pz", "0").toDouble()*xToCmfactor;

                    double x2=xVertices.item(i+1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
                    double y2=xVertices.item(i+1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
                    double z2=xVertices.item(i+1).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
                    geo->addWall(x1, y1, z1, x2, y2,z2,thickness,height,color);
               }
               xPoly = xPoly.nextSiblingElement("polygon");
          }
     }

     QDomNodeList xCrossingsList=doc.elementsByTagName("crossing");

     for (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","120").toDouble();
          QString id= xCrossing.attribute("id","-1");

          double x1=xVertices.item(0).toElement().attribute("px", "0").toDouble()*xToCmfactor;
          double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble()*xToCmfactor;
          double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble()*xToCmfactor;

          double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
          double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
          double z2=xVertices.item(1).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
          geo->addNavLine(x1, y1, z1, x2, y2,z2,thickness,height,color);

          double center[3]= {(x1+x2)/2.0, (y1+y2)/2.0, (z2+z1)/2.0};
          geo->addObjectLabel(center,center,id.toStdString(),21);
     }

     QDomNodeList xTransitionsList=doc.elementsByTagName("transition");
     for (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()*xToCmfactor;
          double y1=xVertices.item(0).toElement().attribute("py", "0").toDouble()*xToCmfactor;
          double z1=xVertices.item(0).toElement().attribute("pz", "0").toDouble()*xToCmfactor;

          double x2=xVertices.item(1).toElement().attribute("px", "0").toDouble()*xToCmfactor;
          double y2=xVertices.item(1).toElement().attribute("py", "0").toDouble()*xToCmfactor;
          double z2=xVertices.item(1).toElement().attribute("pz", "0").toDouble()*xToCmfactor;
          geo->addDoor(x1, y1, z1, x2, y2,z2,thickness,height,color);

          string id= xTransition.attribute("id","-1").toStdString();
          double center[3]= {(x1+x2)/2.0, (y1+y2)/2.0, (z2+z1)/2.0};
          geo->addObjectLabel(center,center,id,21);
     }

     //room 0, subroom 0
     geoFac.AddElement(0,0,geo);
1322
}
1323

1324
bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, double * fps)
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1325
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1326 1327
     //fileName="data/trajectories/1000_1_0_0_1_1.txt";
     //fileName="data/trajectories/50_3_0_1_1_2.txt";
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1328 1329
     Debug::Messages("parsing txt trajectory <%s> ", fileName.toStdString().c_str());
     *fps=16;//default value
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1330 1331 1332 1333 1334 1335 1336
     QFile inputFile(fileName);
     if (inputFile.open(QIODevice::ReadOnly))
     {
          QTextStream in(&inputFile);
          int lastFrameID=-1;
          int maxFrame=1000;
          //initialize the process dialog
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1337
          QProgressDialog progressDialog ("Simulation","Cancel",1, maxFrame,NULL);
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348
          progressDialog.setModal(true);
          //_progressDialog->setStyleSheet(stylesheet);
          progressDialog.setWindowFlags(Qt::FramelessWindowHint|Qt::WindowStaysOnTopHint);
          //_progressDialog->setWindowFlags(Qt::Dialog | Qt::FramelessWindowHint | Qt::WindowTitleHint|Qt::WindowStaysOnTopHint);
          progressDialog.setFixedSize(400,100);
          progressDialog.setLabelText("<h3>Loading...</h3>");
          QList<QPushButton *> buttons=progressDialog.findChildren<QPushButton *>();
          buttons.at(0)->hide(); // that is the cancel button
          progressDialog.setValue(1);
          progressDialog.show();

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1349
          double unitFactor=FAKTOR;// @todo: use correct unit
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1350 1351 1352 1353

          while ( !in.atEnd() )
          {
               QString line = in.readLine();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365
               if(line[0] == "#")  // looking for framerate
               {
                    if(line.split(":").size()==2)
                    {
                         if(line.split(":")[0].contains("framerate",Qt::CaseInsensitive))
                         {
                              *fps = line.split(":")[1].toDouble();
                              Debug::Messages("Frame rate  <%.0f>", *fps);
                         }
                    }
                    continue;
               }
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1366 1367
               line = line.trimmed(); // remove whitespaces from
                                      // beginning and end
1368
               QStringList pieces = line.split(QRegExp("\\s+"));
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1369 1370 1371

               double pos[3];
               double angle[3]={0,0,30};
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1372
               double radius[3]={0.3*FAKTOR,0.3*FAKTOR,0.3*FAKTOR};
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402

               int agentID=-1 ;
               int frameID=-1;
               double color=155 ;
               switch(pieces.size())
               {
               case 5:
                    agentID=pieces[0].toInt();
                    frameID=pieces[1].toInt();
                    pos[0]=pieces[2].toDouble()*unitFactor;
                    pos[1]=pieces[3].toDouble()*unitFactor;
                    pos[2]=pieces[4].toDouble()*unitFactor;
                    break;

               case 9:
                    agentID=pieces[0].toInt();
                    frameID=pieces[1].toInt();
                    color=pieces[8].toDouble();
                    pos[0]=pieces[2].toDouble()*unitFactor;
                    pos[1]=pieces[3].toDouble()*unitFactor;
                    pos[2]=pieces[4].toDouble()*unitFactor;
                    radius[0]=pieces[5].toDouble()*unitFactor;
                    radius[1]=pieces[6].toDouble()*unitFactor;
                    angle[2]=pieces[7].toDouble();
                    break;

               default:
                    //try to scan the line for the unit
                    if(line.contains("centimeter", Qt::CaseInsensitive)||
                       line.contains("centimetre", Qt::CaseInsensitive))
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1403
                    {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1404 1405
                         unitFactor=0.01;
                         qDebug()<<"unit centimetre detected";
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1406 1407
                    }
                    else
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1408 1409 1410 1411 1412 1413 1414 1415
                         if(line.contains("meter", Qt::CaseInsensitive)||
                            line.contains("metre", Qt::CaseInsensitive))
                         {
                              unitFactor=1;
                              qDebug()<<"unit metre detected";
                         }
                         else
                         {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1416
                              Debug::Warning("Ignoring line: <%s>",line.toStdString().c_str());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450
                         }
                    continue;//next line
                    break;
               }

               FrameElement *element = new FrameElement(agentID-1);
               element->SetPos(pos);
               element->SetOrientation(angle);
               element->SetRadius(radius);
               element->SetColor(color);

               if(dataset->GetFrames().count(frameID)<1)
               {
                    Frame* frame = new Frame(frameID);
                    frame->addElement(element);
                    dataset->addFrame(frame);
                    //cout<<"adding frame: "<<frameID<<endl;
               }
               else
               {
                    dataset->GetFrames()[frameID]->addElement(element);
               }

               //a new frame is starting.
               // not longer necessary if you are using maps and frameid
               if(frameID!=lastFrameID)
               {
                    progressDialog.setValue(dataset->getSize());
                    lastFrameID=frameID;
                    QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
               }
          }

          inputFile.close();
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1451
          Debug::Messages("%d frames added!", dataset->GetFrames().size());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462
          //construct the polydata
          for( const auto & frame:dataset->GetFrames())
          {
               frame.second->ComputePolyData();
               //cout<<"computing polydata"<<endl;
          }
          //dataset->setNumberOfAgents(50);

     }
     else
     {
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1463
          Debug::Error("could not open the file  <%s>", fileName.toStdString().c_str());
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1464 1465 1466 1467
          return false;
     }

     return true;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
1468 1469
}

1470
bool SaxParser::ParseGradientFieldVTK(QString fileName, GeometryFactory& geoFac)
1471
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490
     if(QFileInfo(fileName).isRelative())
     {
          QString wd;
          SystemSettings::getWorkingDirectory(wd);
          fileName=wd+"/"+fileName;
     }

     qDebug()<<"Opening the gradient field:"<<fileName<<endl;
     // Read the file
     VTK_CREATE(vtkStructuredPointsReader, reader);
     reader->SetFileName(fileName.toStdString().c_str());
     reader->Update();
     reader->SetLookupTableName("LOOKUP_TABLE default");

     VTK_CREATE(vtkImageDataGeometryFilter,geometryFilter );
     geometryFilter->SetInputConnection(reader->GetOutputPort());
     geometryFilter->Update();

     //try a triangle strip
1491 1492 1493 1494 1495 1496
//    VTK_CREATE(vtkStripper,stripper);
//    stripper->SetInputConnection(geometryFilter->GetOutputPort());
//    VTK_CREATE(vtkTriangleFilter,trianglefilter);
//    trianglefilter->SetInputConnection(stripper->GetOutputPort());


Mohcine Chraibi's avatar
Mohcine Chraibi committed
1497 1498
     VTK_CREATE(vtkPolyDataMapper,mapper);
     mapper->SetInputConnection(geometryFilter->GetOutputPort());
1499

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1500 1501 1502 1503
     VTK_CREATE(vtkActor, actor);
     actor->SetMapper(mapper);
     //conversion from m to cm
     actor->SetScale(100);
1504

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1505 1506
     auto gradient_field= shared_ptr<FacilityGeometry>(new FacilityGeometry("Gradient Field", "no name", "no name"));
     gradient_field->addGradientField(actor);
1507

Mohcine Chraibi's avatar
Mohcine Chraibi committed
1508 1509 1510
     geoFac.AddElement(-1,-1,gradient_field);
     geoFac.AddElement(-2,-2,gradient_field);
     return true;
1511 1512
}

1513
void SaxParser::InitHeader(int major, int minor, int patch)
1514
{
Mohcine Chraibi's avatar
Mohcine Chraibi committed
1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542
     if ( (minor==6) || (minor==5 && patch==1) ) {
          _jps_xPos=QString("x");
          _jps_yPos=QString("y");
          _jps_zPos=QString("z");
          _jps_xVel=QString("xV");
          _jps_yVel=QString("yV");
          _jps_zVel=QString("zV");
          _jps_radiusA=QString("rA");
          _jps_radiusB=QString("rB");
          _jps_ellipseOrientation=QString("eO");
          _jps_ellipseColor=QString("eC");
     } else {
          _jps_xPos=QString("xPos");
          _jps_yPos=QString("yPos");
          _jps_zPos=QString("zPos");
          _jps_xVel=QString("xVel");
          _jps_yVel=QString("yVel");
          _jps_zVel=QString("zVel");
          _jps_radiusA=QString("radiusA");
          _jps_radiusB=QString("radiusB");
          _jps_ellipseOrientation=QString("ellipseOrientation");
          _jps_ellipseColor=QString("ellipseColor");
     }
     if(major!=0) {
          cout<<"unsupported header version: "<<major<<"."<<minor<<"."<<patch<<endl;
          cout<<"Please use 0.5 0.5.1 or 0.6 "<<endl;
          exit(0);
     }
1543
}