diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 7022cd85579103938949bb534767067056d30124..f417d596eb8cefd7a9e2aa591278c126b774291d 100644 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -425,8 +425,6 @@ FacilityGeometry* MainWindow::parseGeometry(QDomNode geoNode){ if (fileName.endsWith(".xml",Qt::CaseInsensitive)) { //cout<<"good bye"<<endl; exit(0); - //should be a file name - //return parseGeometryPG3(fileName); //SaxParser::parseGeometryPG3(fileName,geometry); } else if (fileName.endsWith(".trav",Qt::CaseInsensitive)) @@ -502,33 +500,37 @@ bool MainWindow::parsePedestrianShapes(QDomNode shapeNode, int groupID){ /// add a new dataset bool MainWindow::slotAddDataSet(){ - if (numberOfDatasetLoaded>=3){ - QMessageBox::information(this,"notice","You can load at most 3 datasets.\n In" - " Order to load other data, please first clear previously loaded data."); - return false; - } - // if at least one data set was loaded - if (numberOfDatasetLoaded>=1){ - int res = QMessageBox::question(this, "action", - "adding a new dataset will reset the visualisation process. Continue?", QMessageBox::Discard - | QMessageBox::Yes, QMessageBox::Yes); +// if (numberOfDatasetLoaded>=3){ +// QMessageBox::information(this,"notice","You can load at most 3 datasets.\n In" +// " Order to load other data, please first clear previously loaded data."); +// return false; +// } - if (res == QMessageBox::Discard) return false; +// // if at least one data set was loaded +// if (numberOfDatasetLoaded>=1){ +// int res = QMessageBox::question(this, "action", +// "adding a new dataset will reset the visualisation process. Continue?", QMessageBox::Discard +// | QMessageBox::Yes, QMessageBox::Yes); - } +// if (res == QMessageBox::Discard) return false; +// } // just continue - numberOfDatasetLoaded++; + numberOfDatasetLoaded=1; if(addPedestrianGroup(numberOfDatasetLoaded)==false){ numberOfDatasetLoaded--; return false; } + slotStartPlaying(); + QString stre(numberOfDatasetLoaded); stre.setNum(numberOfDatasetLoaded); stre.append(" dataset loaded"); statusBar()->showMessage(stre); + slotStartPlaying(); + return true; } @@ -542,9 +544,9 @@ void MainWindow::slotClearAllDataset(){ } -bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ +bool MainWindow::addPedestrianGroup(int groupID,QString fileName) +{ statusBar()->showMessage(tr("Select a file")); - if(fileName.isEmpty()) fileName = QFileDialog::getOpenFileName(this, "Select the file containing the data to visualize", @@ -555,6 +557,8 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ return false; } + + //get and set the working dir QFileInfo fileInfo(fileName); QString wd=fileInfo.absoluteDir().absolutePath(); @@ -566,9 +570,17 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ // if xml is detected, just load and show the geometry then exit if(fileName.endsWith(".xml",Qt::CaseInsensitive)){ + + //try to parse the correct way + // fall back to this if it fails + //SaxParser::parseGeometryJPS(fileInfo.baseName(),geometry); + SaxParser::parseGeometryXMLV04(fileName,geometry); //slotLoadParseShowGeometry(fileName); //return false; + //cout<<"here:"<<endl; + //cout<<"group:"<<groupID<<endl; + //exit(0); } QFile file(fileName); @@ -577,6 +589,7 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ return false; } + SyncData* dataset=NULL; @@ -614,10 +627,12 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ default: Debug::Error("invalid pedestrian group: %d " ,groupID); Debug::Error("should be 1, 2 or 3"); - return false; + //return false; break; } + + double frameRate=15; //default frame rate statusBar()->showMessage(tr("parsing the file")); QXmlInputSource source(&file); @@ -631,10 +646,10 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName){ reader.parse(source); file.close(); - QString frameRateStr=QString::number(frameRate); SystemSettings::setFilenamePrefix(QFileInfo ( fileName ).baseName()+"_"); + // set the visualisation window title visualisationThread->setWindowTitle(fileName); visualisationThread->slotSetFrameRate(frameRate); @@ -1028,6 +1043,7 @@ void MainWindow::slotShowGeometry(){ ui.actionShow_Walls->setEnabled(true); ui.actionShow_Geometry_Captions->setEnabled(true); ui.actionShow_Navigation_Lines->setEnabled(true); + ui.actionShow_Floor->setEnabled(true); SystemSettings::setShowGeometry(true); } else{ @@ -1036,6 +1052,7 @@ void MainWindow::slotShowGeometry(){ ui.actionShow_Walls->setEnabled(false); ui.actionShow_Geometry_Captions->setEnabled(false); ui.actionShow_Navigation_Lines->setEnabled(false); + ui.actionShow_Floor->setEnabled(false); SystemSettings::setShowGeometry(false); } extern_force_system_update=true; @@ -1075,7 +1092,7 @@ void MainWindow::slotShowHideNavLines() void MainWindow::slotShowHideFloor() { bool status = ui.actionShow_Floor->isChecked(); - visualisationThread->getGeometry()->showFloor(status); + visualisationThread->showFloor(status); SystemSettings::setShowFloor(status); } @@ -1489,7 +1506,7 @@ void MainWindow::slotChangeFloorColor() double color[3]={(double)col.red()/255.0 ,(double)col.green()/255.0 ,(double)col.blue()/255.0}; - visualisationThread->getGeometry()->changeFloorColor(color); + visualisationThread->setFloorColor(color); delete colorDialog; } @@ -1614,7 +1631,6 @@ void MainWindow::dropEvent(QDropEvent *event) { mayPlay = true; } } - if (mayPlay) { slotStartPlaying(); } diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index b9901dd9c2a880c90fa5ad6927e4b770c65fe8eb..adc694c8d1b1359c84e992ff5c8a258bc1dd1288 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -46,7 +46,6 @@ #include <iostream> #include <cmath> - #include <vtkVersion.h> #include <vtkSmartPointer.h> #include <vtkPolygon.h> @@ -78,13 +77,12 @@ using namespace std; */ SaxParser::SaxParser(FacilityGeometry* geo, SyncData* data, double* fps){ geometry=geo; - dataset=data; + dataset=data; para=fps; parsingWalls=false; parsingCrossings=false; color=0.0; - - dataset->clearFrames(); + dataset->clearFrames(); } SaxParser::~SaxParser() { @@ -101,6 +99,7 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, { double version=at.value(i).toDouble(); InitHeader(version); + //cout<<"version found:"<<version<<endl;exit(0); } } }else if (qName == "file") { @@ -576,6 +575,7 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, } 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()); } @@ -586,11 +586,18 @@ bool SaxParser::endElement(const QString & /* namespaceURI */, } clearPoints(); } else if (qName == "crossing") { + if(currentPointsList.size()>1) //hack + for(unsigned int i=0;i<currentPointsList.size()-1;i++){ + geometry->addNavLine(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); + } + clearPoints(); + } else if (qName == "hline") { + if(currentPointsList.size()>1) //hack for(unsigned int i=0;i<currentPointsList.size()-1;i++){ geometry->addNavLine(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); } clearPoints(); - } else if (qName == "step") {//FIXME + } else if (qName == "step") {//FIXME for(unsigned int i=0;i<currentPointsList.size()-1;i++){ geometry->addDoor(currentPointsList[i],currentPointsList[i+1],caption.toStdString()); } @@ -681,7 +688,7 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ for (int k = 0; k < r->GetNumberOfSubRooms(); k++) { - SubRoom* sub = r->GetSubRoom(k); + SubRoom* sub = r->GetSubRoom(k); vector<Point> poly = sub->GetPolygon(); @@ -689,24 +696,31 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ std::reverse(poly.begin(),poly.end()); } - // Create the polygon + // Create the polygon VTK_CREATE(vtkPolygon,polygon); - polygon->GetPointIds()->SetNumberOfIds(poly.size()); + polygon->GetPointIds()->SetNumberOfIds(poly.size()); - for (unsigned int s=0;s<poly.size();s++){ - points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); - polygon->GetPointIds()->SetId(s, currentID++); - } - polygons->InsertNextCell(polygon); + for (unsigned int s=0;s<poly.size();s++){ + points->InsertNextPoint(poly[s]._x*FAKTOR,poly[s]._y*FAKTOR,sub->GetElevation(poly[s])*FAKTOR); + polygon->GetPointIds()->SetId(s, currentID++); + } + polygons->InsertNextCell(polygon); //plot the walls only for not stairs - if(sub->GetType()!="stair"){ - 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(); - double z1= sub->GetElevation(p1); - double z2= sub->GetElevation(p2); + + 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(); + double z1= sub->GetElevation(p1); + double z2= sub->GetElevation(p2); + + 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); } } @@ -736,7 +750,7 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ double pos[3]={p._x*FAKTOR,p._y*FAKTOR,z*FAKTOR}; geometry->addObjectLabel(pos,pos,obst->GetCaption(),captionsColor); } - } + } } // Create a PolyData to represent the floor @@ -778,13 +792,17 @@ void SaxParser::parseGeometryJPS(QString fileName, FacilityGeometry *geometry){ geometry->addObjectLabel(pos,pos,"door_"+QString::number(tr->GetID()).toStdString(),captionsColor); } + //TODO:dirty hack for parsing the Hlines + // free memory delete building; } /// provided for convenience and will be removed in the next version -void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QDomNode geo){ + +void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QDomNode geo) +{ cout<<"external geometry found"<<endl; //creating am empty document @@ -848,7 +866,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //parsing the walls - for (unsigned int i = 0; i < walls.length(); i++) { + for ( int i = 0; i < walls.length(); i++) { QDomElement el = walls.item(i).toElement(); //wall thickness, default to 30 cm @@ -861,7 +879,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //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 (unsigned int i = 0; i < points.length() - 1; i++) { + 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; @@ -876,7 +894,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //parsing the doors if(doors.length()>0) - for (unsigned int i = 0; i < doors.length(); i++) { + for ( int i = 0; i < doors.length(); i++) { QDomElement el = doors.item(i).toElement(); //door thickness, default to 15 cm @@ -890,7 +908,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD //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 (unsigned int i = 0; i < points.length() - 1; i++) { + 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; @@ -904,7 +922,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD } // parsing the objets - for (unsigned int i = 0; i < spheres.length(); i++) { + for ( int i = 0; i < spheres.length(); i++) { double center[3]; center[0] = spheres.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR; @@ -918,7 +936,7 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD geometry->addObjectSphere(center,radius,color); } // cubic shapes - for (unsigned int i = 0; i < cuboids.length(); i++) { + for ( int i = 0; i < cuboids.length(); i++) { double center[3]; center[0] = cuboids.item(i).toElement().attribute("centerX", "0").toDouble()*FAKTOR; @@ -973,11 +991,22 @@ void SaxParser::parseGeometryTRAV(QString content, FacilityGeometry *geometry,QD } } -void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo){ + +void SaxParser::parseGeometryXMLV04(QString filename, FacilityGeometry *geo) +{ QDomDocument doc(""); QFile file(filename); + int size =file.size()/(1024*1024); + + //avoid dom parsing a very large dataset + 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 diff --git a/src/ThreadDataTransfert.cpp b/src/ThreadDataTransfert.cpp index 8b34b435d59f2815fd615076a1fe59c7cc1315dc..a7356c79640cf30a92acebada4c8c8d0064d1115 100644 --- a/src/ThreadDataTransfert.cpp +++ b/src/ThreadDataTransfert.cpp @@ -279,7 +279,6 @@ void ThreadDataTransfer::parseDataNode(QDomNodeList frames){ double xPos=agents.item(i).toElement().attribute("xPos","0").toDouble()*FAKTOR; double yPos=agents.item(i).toElement().attribute("yPos","0").toDouble()*FAKTOR; double zPos=agents.item(i).toElement().attribute("zPos","0").toDouble()*FAKTOR; - double agent_color =std::numeric_limits<double>::quiet_NaN(); double xVel=agents.item(i).toElement().attribute("xVel").toDouble(&ok)*FAKTOR; @@ -322,6 +321,7 @@ void ThreadDataTransfer::parseDataNode(QDomNodeList frames){ } //adding the new frame to the right dataset + newFrame->ComputePolyData(); extern_trajectories_firstSet.addFrame(newFrame); // frameNumbers++; } diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 3a51d82366171625e53b9a1c45e9ad99dc128d9a..de8e8d0aec16c3b39d844694741735c83c370eba 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -414,6 +414,11 @@ void ThreadVisualisation::showNavLines(bool status) } } +void ThreadVisualisation::showFloor(bool status) +{ + geometry->showFloor(status); +} + void ThreadVisualisation::initGlyphs2D() { @@ -1046,14 +1051,19 @@ void ThreadVisualisation::setGeometry(FacilityGeometry* geometry){ } FacilityGeometry* ThreadVisualisation::getGeometry() { - if(geometry==NULL){ + //if(geometry==NULL){ geometry=new FacilityGeometry(); - } + //} return geometry; } void ThreadVisualisation::setWallsColor(double* color){ - geometry->changeWallsColor(color); + geometry->changeWallsColor(color); +} + +void ThreadVisualisation::setFloorColor(double *color) +{ + geometry->changeFloorColor(color); } void ThreadVisualisation::setGeometryLabelsVisibility(int v){ diff --git a/src/ThreadVisualisation.h b/src/ThreadVisualisation.h index ad56e15ec40cb47f767761ff018d80130ec3f590..56159ca758d2387b9decbe61e4dc08c4066beacb 100644 --- a/src/ThreadVisualisation.h +++ b/src/ThreadVisualisation.h @@ -122,6 +122,9 @@ public: /// change the walls color void setWallsColor(double* color); + /// change the floor color + void setFloorColor(double* color); + /// change the exits color. void setExitsColor(double* color); @@ -137,6 +140,9 @@ public: /// show/ hide the exits void showNavLines(bool status); + /// show/ hide the floor + void showFloor(bool status); + /// show / hide stairs ///not implemented void showStairs(bool status); @@ -156,7 +162,6 @@ Q_SIGNALS: private: - /// initialize the legend void initLegend(/*std::vector scalars*/); diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 150fa885b80da34be9f13cffbe35e85a256f5102..c4a2a995609066d9a4f79e125e9775cb4ed4ba8e 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -296,6 +296,30 @@ void FacilityGeometry::addWall(double x1, double y1, double z1, double x2, doubl delete center; } +void FacilityGeometry::addStair(double x1, double y1, double z1, double x2, double y2, double z2,double thickness,double height,double color){ + + // all walls will have this parameters until changed + wallColor=color; + + // if(SystemSettings::get2D()){ + double m[]={x1,y1,z1}; + double n[]={x2,y2,z2}; + linesPlotter2D->PlotWall(m,n,wallColor/255.0); + + +// JPoint *p1 = new JPoint(x1,y1,z1); +// JPoint *p2 = new JPoint(x2,y2,z2); +// double *center = p1->centreCoordinatesWith(*p2); +// double angle =p1->angleMadeWith(*p2); +// double length =p1->distanceTo(*p2)+wallThickness; + +// addNewElement(center, length, angle, WALL); + +// delete p1; +// delete p2; +// delete center; +} + void FacilityGeometry::addDoor(double x1, double y1, double z1, double x2, double y2, double z2,double thickness ,double height, double color){ // all doors will take this color upon changed @@ -414,6 +438,35 @@ void FacilityGeometry::addWall(JPoint* p1, JPoint* p2, string caption){ addNewElement( center, length, angle, WALL); } +void FacilityGeometry::addStair(JPoint* p1, JPoint* p2, string caption){ + double m[3]; + double n[3]; + double CHT[3]; + p1->getXYZ(m); + p2->getXYZ(n); + p1->getColorHeightThicknes(CHT); + + wallThickness = CHT[2]; + wallHeight=CHT[1]; + wallColor = CHT[0]; + linesPlotter2D->PlotWall(m,n,wallColor/255.0); + + if (caption.compare("") != 0){ + + double center[3]; + center[0]=0.5*(m[0]+n[0]); + center[1]=0.5*(m[1]+n[1]); + center[2]=0.5*(m[2]+n[2]); + double orientation[3]={0,0,0}; + addNewElementText(center,orientation,caption.c_str(),50); + } + +// double *center = p1->centreCoordinatesWith(*p2); +// double angle =p1->angleMadeWith(*p2); +// double length =p1->distanceTo(*p2)+wallThickness; +// addNewElement( center, length, angle, WALL); +} + void FacilityGeometry::addDoor(JPoint* p1, JPoint* p2, string caption){ double m[3]; diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index 3f885a84817d34216095b19abcd0880fd16d8938..37d5db7048084ed8de8951bd9f322630c2b64d56 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -81,6 +81,12 @@ public: //void addWall(double center[3], double width, double orientation); void addWall(JPoint* p1, JPoint* p2, std::string caption=""); + ///draw a stair + void addStair(double x1, double y1, double z1, double x2, double y2, double z2, double thickness=15, double height=250,double col=255); + //void addWall(double center[3], double width, double orientation); + void addStair(JPoint* p1, JPoint* p2, std::string caption=""); + + ///draw a door void addDoor(double x1, double y1, double z1 ,double x2, double y2, double z2, double thickness=17, double height=250,double col=30); //void addDoor(double center[3], double width, double orientation);