From ed3c4eff15356eb253a01e6324d199346375401f Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi <m.chraibi@fz-juelich.de> Date: Fri, 12 Apr 2019 23:07:27 +0200 Subject: [PATCH] Parse goals from file (TXT traj) --- src/MainWindow.cpp | 21 +++++++++++++-- src/SaxParser.cpp | 45 ++++++++++++++++++------------- src/geometry/FacilityGeometry.cpp | 14 ++++++---- src/geometry/FacilityGeometry.h | 2 +- 4 files changed, 56 insertions(+), 26 deletions(-) diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp index 6d16b86..b07999f 100755 --- a/src/MainWindow.cpp +++ b/src/MainWindow.cpp @@ -708,7 +708,6 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) //the geometry actor auto&& geometry = _visualisationThread->getGeometry(); -// geometry.addSource(1,4,2,5); QString geometry_file; //try to get a geometry filename if(fileName.endsWith(".xml",Qt::CaseInsensitive)) @@ -856,6 +855,7 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) else if(fileName.endsWith(".txt",Qt::CaseInsensitive)) { QString source_file=SaxParser::extractSourceFileTXT(fileName); + QString goal_file=SaxParser::extractGoalFileTXT(fileName); QFileInfo check_file(source_file); if( !(check_file.exists() && check_file.isFile()) ) { @@ -864,14 +864,31 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName) else Debug::Messages("INFO: MainWindow::addPedestrianGroup: source name: <%s>", source_file.toStdString().c_str()); + check_file = source_file; + if( !(check_file.exists() && check_file.isFile()) ) + { + Debug::Messages("WARNING: MainWindow::addPedestrianGroup: goal name: <%s> not found!", goal_file.toStdString().c_str()); + } + else + Debug::Messages("INFO: MainWindow::addPedestrianGroup: goal name: <%s>", goal_file.toStdString().c_str()); + + + // ------ parsing sources QFile file(source_file); QXmlInputSource source(&file); QXmlSimpleReader reader; - SaxParser handler(geometry,*dataset,&frameRate); reader.setContentHandler(&handler); reader.parse(source); file.close(); + QFile file2(goal_file); + QXmlInputSource source2(&file2); + reader.parse(source2); + file2.close(); + // ----- + // // ---- parsing goals + // ----- + if(false==SaxParser::ParseTxtFormat(fileName, dataset,&frameRate)) return false; diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index e184eeb..0b75fa5 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -156,10 +156,10 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, double xmin, xmax, ymin, ymax; double z=0;// @todo read this some when we go 3D - int source_id=-1; + string source_id=""; for(int i=0; i<at.length(); i++) { if(at.localName(i)=="id") { - source_id=at.value(i).toInt(); + source_id=at.value(i).toStdString(); } else if(at.localName(i)=="x_min") { xmin=at.value(i).toDouble()*FAKTOR; } @@ -173,24 +173,33 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, ymax=at.value(i).toDouble()*FAKTOR; } } - _geometry->addRectangle(xmin,ymin,xmax,ymax, 0, 120.0, 150.0); + _geometry->addRectangle(xmin,ymin,xmax,ymax, 0, 120.0, 150.0, source_id); //@todo: here z=0. What about sources in the 2 floor? + } - - // 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 == "goal") + { + double xmin, xmax, ymin, ymax; + double z=0;// @todo read this some when we go 3D + QString caption = ""; + for(int i=0; i<at.length(); i++) { + if(at.localName(i)=="caption") { + caption=at.value(i); + } 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->addRectangle(xmin,ymin,xmax,ymax, z, 90.0, 90.0, caption.toStdString()); + } // goal else if (qName == "floor") { double xMin=0, xMax=0, diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 6ea908d..3fbfd5b 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -575,12 +575,13 @@ void FacilityGeometry::addObstacles(vtkPolyData* polygonPolyData ) -void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, double z, double color1, double color2) +void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, double z, double color1, double color2, string text) { //if(z!=1)return; - const double cellSize=40; //cm + const double cellSize=40; //cm // const int dimX=(x2-x1)/cellSize+1; // const int dimY=(y2-y1)/cellSize+1; + const int dimX= (int)ceil((x2-x1)/cellSize) +1; const int dimY= (int)ceil((y2-y1)/cellSize) +1; @@ -589,8 +590,6 @@ void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, //vtkDoubleArray *scalars = vtkDoubleArray::New(); vtkDataArray* pData = vtkUnsignedCharArray::New(); pData->SetNumberOfComponents(3); - std::cout << "---- " << color1 << " " << color2 << "\n" ; - double color[2][3]= {{color1, color1, color1},{color2,color2,color2}}; bool idx=0; bool lastColorUsed=0; @@ -627,12 +626,17 @@ void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, //map->SetLookupTable(lookupTable); imageActor->SetMapper(map); - imageActor->GetProperty()->SetAmbient(0.2); + if(color2==90) // quick and dirty --> goal + imageActor->GetProperty()->SetAmbient(1.5); + else + imageActor->GetProperty()->SetAmbient(0.6); //imageActor->GetProperty()->SetDiffuse(0.8); // move the actor in x-direction imageActor->SetPosition(x1, y1, z); assembly2D->AddPart(imageActor); + double center[3]={x1/2+x2/2, y1/2+y2/2, 0}; + addNewElementText(center, 0, text, 0); } diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index 6cdd937..2507ceb 100644 --- a/src/geometry/FacilityGeometry.h +++ b/src/geometry/FacilityGeometry.h @@ -104,7 +104,7 @@ public: /// draw a floor, divided in cells, void addFloor(double x1, double y1, double x2, double y2, double z=0); - void addRectangle(double x1, double y1, double x2, double y2, double z=0, double c1=120, double c2=150); + void addRectangle(double x1, double y1, double x2, double y2, double z=0, double c1=120, double c2=150, std::string text=""); void addFloor(vtkPolyData* polygonPolyData); ///draw obstacles -- GitLab