Visualise sources from TXT trajectories #73

parent 9b496d47
......@@ -18,7 +18,7 @@
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>.
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
......@@ -708,6 +708,7 @@ 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))
......@@ -721,7 +722,6 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
geometry_file=SaxParser::extractGeometryFilenameTXT(fileName);
}
Debug::Messages("MainWindow::addPedestrianGroup: geometry name: <%s>", geometry_file.toStdString().c_str());
if(geometry_file.isEmpty())
{
......@@ -745,7 +745,9 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
if( !(check_file.exists() && check_file.isFile()) )
{
Debug::Error("Geomery file does not exist.");
exit(EXIT_FAILURE);
//exit(EXIT_FAILURE);
return(false);
}
//geometry_file = check_file.fileName();
}
......@@ -831,6 +833,7 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
statusBar()->showMessage(tr("parsing the file"));
//parsing the xml file
if(fileName.endsWith(".xml",Qt::CaseInsensitive))
{
......@@ -852,8 +855,27 @@ bool MainWindow::addPedestrianGroup(int groupID,QString fileName)
// try to parse the txt file
else if(fileName.endsWith(".txt",Qt::CaseInsensitive))
{
QString source_file=SaxParser::extractSourceFileTXT(fileName);
QFileInfo check_file(source_file);
if( !(check_file.exists() && check_file.isFile()) )
{
Debug::Messages("WARNING: MainWindow::addPedestrianGroup: source name: <%s> not found!", source_file.toStdString().c_str());
}
else
Debug::Messages("INFO: MainWindow::addPedestrianGroup: source name: <%s>", source_file.toStdString().c_str());
QFile file(source_file);
QXmlInputSource source(&file);
QXmlSimpleReader reader;
SaxParser handler(geometry,*dataset,&frameRate);
reader.setContentHandler(&handler);
reader.parse(source);
file.close();
if(false==SaxParser::ParseTxtFormat(fileName, dataset,&frameRate))
return false;
}
......
......@@ -5,20 +5,20 @@
* Copyright (C) <2009-2010>
*
* @section LICENSE
* This file is part of OpenPedSim.
* This file is part of JuPedSim.
*
* OpenPedSim is free software: you can redistribute it and/or modify
* JuPedSim is free software: you can redistribute it and/or modify
* 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,
* JuPedSim 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
* along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>.
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
......
......@@ -13,7 +13,7 @@
* 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,
* JuPedSim 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.
......@@ -672,7 +672,7 @@ void SaxParser::clearPoints()
return;
}
/// provided for convenience and will be removed in the next version
bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac)
{
Debug::Messages( "Enter SaxParser::parseGeometryJPS with filename <%s>",fileName.toStdString().c_str());
......@@ -712,9 +712,8 @@ bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac)
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>(
new FacilityGeometry(itr_subroom.second->GetType(), room_caption, subroom_caption
)
);
new FacilityGeometry(itr_subroom.second->GetType(), room_caption, subroom_caption));
int currentFloorPolyID=0;
int currentObstPolyID=0;
......@@ -859,8 +858,6 @@ bool SaxParser::parseGeometryJPS(QString fileName, GeometryFactory& geoFac)
geoFac.AddElement(room_id,subroom_id,geometry);
}
}
// free memory
delete building;
return true;
......@@ -1109,6 +1106,83 @@ QString SaxParser::extractGeometryFilename(QString &filename)
return "";
}
// not used yet!!
bool SaxParser::getSourcesTXT(QString &filename)
{
std::cout << "Enter getSourcesTXT with " << filename.toStdString().c_str() << "\n";
std::string sfilename = filename.toStdString();
TiXmlDocument docSource(sfilename);
if (!docSource.LoadFile()) {
Debug::Error("ERROR: \t%s", docSource.ErrorDesc());
Debug::Error("ERROR: \t could not parse the sources file.");
return false;
}
TiXmlElement* xRootNodeSource = docSource.RootElement();
if (!xRootNodeSource) {
Debug::Messages("ERROR:\tRoot element does not exist in source file.");
return false;
}
if (xRootNodeSource->ValueStr() != "JPScore") {
Debug::Messages("ERROR:\tRoot element value in source file is not 'JPScore'.");
return false;
}
TiXmlNode* xSourceF = xRootNodeSource->FirstChild("agents_sources");
if (!xSourceF) {
Debug::Messages("ERROR:\tNo agents_sources tag in file not found.");
return false;
}
Debug::Messages("INFO:\t Loading sources from file");
TiXmlNode* xSourceNodeF = xSourceF->FirstChild("source");
if(xSourceNodeF)
{
for (TiXmlElement* e = xSourceF->FirstChildElement("source"); e;
e = e->NextSiblingElement("source"))
{
float xmin = xmltof(e->Attribute("x_min"), 0);
float xmax = xmltof(e->Attribute("x_max"), 0);
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);
}//for
}
return true;
}
QString SaxParser::extractSourceFileTXT(QString &filename)
{
QString extracted_source_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("sources",Qt::CaseInsensitive))
{
extracted_source_name = line.split(":")[1].simplified().remove(' ');
break;
}
}
}// while
} // if open
if(extracted_source_name=="")
{
Debug::Warning("Could not extract source file!");
}
else
Debug::Messages("Extracted source from TXT file <%s>", extracted_source_name.toStdString().c_str());
return extracted_source_name;
}
QString SaxParser::extractGeometryFilenameTXT(QString &filename)
{
......@@ -1468,7 +1542,6 @@ bool SaxParser::ParseTxtFormat(const QString &fileName, SyncData* dataset, doubl
Debug::Error("could not open the file <%s>", fileName.toStdString().c_str());
return false;
}
return true;
}
......
......@@ -6,20 +6,20 @@
* Copyright (C) <2009-2010>
*
* @section LICENSE
* This file is part of OpenPedSim.
* This file is part of JuPedSim.
*
* OpenPedSim is free software: you can redistribute it and/or modify
* JuPedSim is free software: you can redistribute it and/or modify
* 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,
* JuPedSim 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
* along with OpenPedSim. If not, see <http://www.gnu.org/licenses/>.
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
......@@ -65,7 +65,12 @@ public:
const QString& type,
const QString& valueDefault,
const QString& value);
std::shared_ptr<FacilityGeometry> GetGeometryFactory()
{
return _geometry;
}
bool getSourcesTXT(QString &filename);
/// provided for convenience and will be removed in the next version
static bool parseGeometryJPS(QString content, GeometryFactory& geo);
......@@ -76,8 +81,9 @@ public:
static void parseGeometryTRAV(QString fileName, GeometryFactory& geoFac, QDomNode geoNode=QDomNode());
/// take a large file and find the geometry file location.
static QString extractGeometryFilename(QString& filename);
static QString extractGeometryFilename(QString& filename);
static QString extractGeometryFilenameTXT(QString &filename);
static QString extractSourceFileTXT(QString &filename);
/// parse the txt file format
static bool ParseTxtFormat(const QString& fileName, SyncData* dataset, double * fps);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment