From e2fb2e4fe68853e97c12094c9570acd6359c2db7 Mon Sep 17 00:00:00 2001 From: Mohcine Chraibi <m.chraibi@fz-juelich.de> Date: Fri, 12 Apr 2019 20:09:22 +0200 Subject: [PATCH] refactor addSource and prepare for goals --- src/SaxParser.cpp | 41 ++++++++++++++++++++++++++++--- src/SaxParser.h | 1 + src/geometry/FacilityGeometry.cpp | 5 ++-- src/geometry/FacilityGeometry.h | 2 +- 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/SaxParser.cpp b/src/SaxParser.cpp index 1fdb043..e184eeb 100644 --- a/src/SaxParser.cpp +++ b/src/SaxParser.cpp @@ -173,7 +173,9 @@ bool SaxParser::startElement(const QString & /* namespaceURI */, ymax=at.value(i).toDouble()*FAKTOR; } } - _geometry->addSource(xmin,ymin,xmax,ymax); + _geometry->addRectangle(xmin,ymin,xmax,ymax, 0, 120.0, 150.0); + //@todo: here z=0. What about sources in the 2 floor? + // double CHT[3]= {_color,_height,_thickness}; // JPoint* pt1= new JPoint(xmin,ymin,z); @@ -1145,8 +1147,8 @@ bool SaxParser::getSourcesTXT(QString &filename) float ymin = xmltof(e->Attribute("y_min"), 0); float ymax = xmltof(e->Attribute("y_max"), 0); bool dont_add = (xmin==0) && (xmax==0) && (ymin==0) && (ymax==0); - if(! dont_add) - _geometry->addSource(xmin,ymin,xmax,ymax); + // if(! dont_add) + // _geometry->addSource(xmin,ymin,xmax,ymax); }//for } return true; @@ -1184,6 +1186,39 @@ QString SaxParser::extractSourceFileTXT(QString &filename) return extracted_source_name; } +QString SaxParser::extractGoalFileTXT(QString &filename) +{ + QString extracted_goal_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(); + // std::cout << " >> " << line.toStdString().c_str() << endl; + if(line.split(":").size()==2) + { + if(line.split(":")[0].contains("goals",Qt::CaseInsensitive)) + { + extracted_goal_name = line.split(":")[1].simplified().remove(' '); + break; + } + } + }// while + } // if open + if(extracted_goal_name=="") + { + Debug::Warning("Could not extract goal file!"); + } + + else + Debug::Messages("Extracted goal from TXT file <%s>", extracted_goal_name.toStdString().c_str()); + return extracted_goal_name; +} + + + QString SaxParser::extractGeometryFilenameTXT(QString &filename) { QString extracted_geo_name=""; diff --git a/src/SaxParser.h b/src/SaxParser.h index bca8d25..7e104cb 100644 --- a/src/SaxParser.h +++ b/src/SaxParser.h @@ -84,6 +84,7 @@ public: static QString extractGeometryFilename(QString& filename); static QString extractGeometryFilenameTXT(QString &filename); static QString extractSourceFileTXT(QString &filename); + static QString extractGoalFileTXT(QString &filename); /// parse the txt file format static bool ParseTxtFormat(const QString& fileName, SyncData* dataset, double * fps); diff --git a/src/geometry/FacilityGeometry.cpp b/src/geometry/FacilityGeometry.cpp index 09bee37..6ea908d 100644 --- a/src/geometry/FacilityGeometry.cpp +++ b/src/geometry/FacilityGeometry.cpp @@ -575,7 +575,7 @@ void FacilityGeometry::addObstacles(vtkPolyData* polygonPolyData ) -void FacilityGeometry::addSource(double x1, double y1, double x2, double y2, double z) +void FacilityGeometry::addRectangle(double x1, double y1, double x2, double y2, double z, double color1, double color2) { //if(z!=1)return; const double cellSize=40; //cm @@ -589,8 +589,9 @@ void FacilityGeometry::addSource(double x1, double y1, double x2, double y2, dou //vtkDoubleArray *scalars = vtkDoubleArray::New(); vtkDataArray* pData = vtkUnsignedCharArray::New(); pData->SetNumberOfComponents(3); + std::cout << "---- " << color1 << " " << color2 << "\n" ; - double color[2][3]= {{120, 120, 120},{150,150,150}}; + double color[2][3]= {{color1, color1, color1},{color2,color2,color2}}; bool idx=0; bool lastColorUsed=0; for(int i=0; i<dimY-1; i++) { diff --git a/src/geometry/FacilityGeometry.h b/src/geometry/FacilityGeometry.h index 9a10019..6cdd937 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 addSource(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 addFloor(vtkPolyData* polygonPolyData); ///draw obstacles -- GitLab