Commit cedfd5a7 authored by Ulrich Kemloh's avatar Ulrich Kemloh

Merging v0.5 into master to create tag v0.5-alhpa1

parents 4109b576 f799698e
This diff is collapsed.
......@@ -32,7 +32,7 @@ PROJECT_NAME = jpscore
# This could be handy for archiving the generated documentation or
# if some version control system is used.
PROJECT_NUMBER = 0.4
PROJECT_NUMBER = v.0.5
# Using the PROJECT_BRIEF tag one can provide an optional one line description
# for a project that appears at the top of each page and should give viewer
......@@ -203,7 +203,7 @@ TAB_SIZE = 4
# will result in a user-defined paragraph with heading "Side Effects:".
# You can put \n's in the value part of an alias to insert newlines.
ALIASES =
#ALIASES += version="\par v.0.5"
# This tag can be used to specify a number of word-keyword mappings (TCL only).
# A mapping has the form "name=value". For example adding
......
This diff is collapsed.
/**
* File: IODispatcher.h
* \file IODispatcher.h
* \date Nov 20, 2010
* \version v0.5
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
*
* Created on 20. November 2010, 15:20
*
*
* @section LICENSE
* \section License
* This file is part of JuPedSim.
*
* JuPedSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
......@@ -17,17 +17,16 @@
* 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
* You should have received a copy of the GNU Lesser General Public License
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
* \section Description
*
*
*
*/
**/
#ifndef _IODISPATCHER_H
#define _IODISPATCHER_H
#define _IODISPATCHER_H
#include "OutputHandler.h"
#include "../geometry/Building.h"
......@@ -37,91 +36,157 @@
extern OutputHandler* Log;
class IODispatcher {
class Trajectories;
class IODispatcher
{
private:
std::vector<OutputHandler* > pHandlers;
std::string WritePed(Pedestrian* ped);
std::vector<Trajectories*> _outputHandlers;
public:
IODispatcher();
IODispatcher(const IODispatcher& orig);
virtual ~IODispatcher();
void AddIO(OutputHandler* ioh);
const std::vector<OutputHandler*>& GetIOHandlers();
void Write(const std::string& str);
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
int AreaLevel(std::string caption);
template<typename A>
bool IsElementInVector(const std::vector<A> &vec, A& el) {
typename std::vector<A>::const_iterator it;
it = std::find (vec.begin(), vec.end(), el);
if(it==vec.end()){
return false;
}else{
return true;
}
}
IODispatcher();
virtual ~IODispatcher();
void AddIO(Trajectories* ioh);
const std::vector<Trajectories*>& GetIOHandlers();
void WriteHeader(int nPeds, double fps, Building* building, int seed);
void WriteGeometry(Building* building);
void WriteFrame(int frameNr, Building* building);
void WriteFooter();
};
class Trajectories
{
public:
Trajectories()
{
_outputHandler = NULL;
};
virtual ~Trajectories(){};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed)=0;
virtual void WriteGeometry(Building* building)=0;
virtual void WriteFrame(int frameNr, Building* building)=0;
virtual void WriteFooter()=0;
void Write(const std::string& str)
{
_outputHandler->Write(str);
}
void SetOutputHandler(OutputHandler* outputHandler)
{
_outputHandler=outputHandler;
}
template<typename A>
bool IsElementInVector(const std::vector<A> &vec, A& el)
{
typename std::vector<A>::const_iterator it;
it = std::find(vec.begin(), vec.end(), el);
if (it == vec.end())
{
return false;
}
else
{
return true;
}
}
protected:
OutputHandler* _outputHandler;
};
class TrajectoriesFLAT:public IODispatcher {
class TrajectoriesJPSV04: public Trajectories {
public:
TrajectoriesFLAT();
virtual ~TrajectoriesFLAT(){};
TrajectoriesJPSV04(){};
virtual ~TrajectoriesJPSV04(){};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
std::string WritePed(Pedestrian* ped);
};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
class TrajectoriesJPSV05: public Trajectories {
public:
TrajectoriesJPSV05(){};
virtual ~TrajectoriesJPSV05(){};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
class TrajectoriesVTK:public IODispatcher {
class TrajectoriesFLAT: public Trajectories
{
public:
TrajectoriesVTK();
virtual ~TrajectoriesVTK(){};
TrajectoriesFLAT();
virtual ~TrajectoriesFLAT()
{
}
;
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
class TrajectoriesXML_MESH:public IODispatcher {
class TrajectoriesVTK: public Trajectories
{
public:
TrajectoriesXML_MESH(){};
virtual ~TrajectoriesXML_MESH(){};
TrajectoriesVTK();
virtual ~TrajectoriesVTK()
{
}
;
//virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
//virtual void WriteFrame(int frameNr, Building* building);
//virtual void WriteFooter();
virtual void WriteGeometry(Building* building);
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
class TrajectoriesJPSV06: public IODispatcher {
class TrajectoriesXML_MESH: public Trajectories
{
public:
TrajectoriesJPSV06(){};
virtual ~TrajectoriesJPSV06(){};
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
TrajectoriesXML_MESH()
{
}
;
virtual ~TrajectoriesXML_MESH()
{
}
;
//virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
//virtual void WriteFrame(int frameNr, Building* building);
//virtual void WriteFooter();
virtual void WriteGeometry(Building* building);
};
#endif /* _IODISPATCHER_H */
class TrajectoriesJPSV06: public Trajectories
{
public:
TrajectoriesJPSV06(){};
virtual ~TrajectoriesJPSV06(){ };
virtual void WriteHeader(int nPeds, double fps, Building* building, int seed);
virtual void WriteGeometry(Building* building);
virtual void WriteFrame(int frameNr, Building* building);
virtual void WriteFooter();
};
#endif /* _IODISPATCHER_H */
/**
* File: OutputHandler.cpp
* \file OutputHandler.cpp
* \date Nov 20, 2010
* \version v0.5
* \copyright <2009-2014> Forschungszentrum Jülich GmbH. All rights reserved.
*
* Created on 20. November 2010, 15:20
*
* @section LICENSE
* \section License
* This file is part of JuPedSim.
*
* JuPedSim is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
......@@ -16,14 +17,14 @@
* 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
* You should have received a copy of the GNU Lesser General Public License
* along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
*
* @section DESCRIPTION
*
* \section Description
*
*
*/
**/
#include "OutputHandler.h"
......@@ -33,96 +34,187 @@
using namespace std;
void OutputHandler::incrementWarnings()
{
_nWarnings += 1;
}
void OutputHandler::Write(string str) {
if (this != NULL)
cout << str << endl;
int OutputHandler::GetWarnings()
{
return _nWarnings;
}
void OutputHandler::Write(const char* message,...) {
char msg[CLENGTH];
va_list ap;
va_start (ap, message);
vsprintf (msg,message ,ap);
va_end (ap);
string str(msg);
if(str.find("ERROR")==string::npos) {
cout<<msg<<endl;
cout.flush();
}
else {
cerr<<msg<<endl;
cerr.flush();
}
//cout << "\033[1;30mbold red text\033[0m\n";
//cout << "\033[1;31"<<msg<<"\033[0m\n";
//cout << "\033[1;31 bla bla \033[0m\n";
void OutputHandler::incrementErrors()
{
_nErrors += 1;
}
void STDIOHandler::Write(string str) {
if (this != NULL)
cout << str << endl;
int OutputHandler::GetErrors()
{
return _nErrors;
}
FileHandler::FileHandler(const char *fn) {
pfp.open(fn);
if (!fn) {
char tmp[CLENGTH];
sprintf(tmp, "Error!!! File [%s] could not be opened!", fn);
cerr << tmp << endl;
exit(0);
}
void OutputHandler::Write(string str)
{
if (this != NULL)
cout << str << endl;
}
FileHandler::~FileHandler() {
pfp.close();
void OutputHandler::ProgressBar(double TotalPeds, double NowPeds)
{
// based on this answer:
// https://stackoverflow.com/questions/1637587/c-libcurl-console-progress-bar
// how wide you want the progress meter to be
int totaldotz=40;
double fraction = NowPeds / TotalPeds;
// part of the progressmeter that's already "full"
int dotz = round(fraction * totaldotz);
// create the "meter"
int ii=0;
printf("Evacuation: %3.0f%% [",fraction*100);
// part that's full already
for ( ; ii < dotz; ii++) {
printf("=");
}
printf(">");
// remaining part (spaces)
for ( ; ii < totaldotz;ii++) {
printf(" ");
}
// and back to line begin - do not forget the fflush to avoid output buffering problems!
printf("]\r");
fflush(stdout);
}
void FileHandler::Write(string str) {
if (this != NULL) {
pfp << str << endl;
pfp.flush();
void OutputHandler::Write(const char* message,...)
{
char msg[CLENGTH];
va_list ap;
va_start(ap, message);
vsprintf(msg, message, ap);
va_end(ap);
string str(msg);
if (str.find("ERROR") != string::npos)
{
cerr << msg << endl;
cerr.flush();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
cerr << msg << endl;
cerr.flush();
incrementWarnings();
}
else
{ // infos
cout << msg << endl;
cout.flush();
}
}
void FileHandler::Write(const char* string,...) {
char msg[CLENGTH];
va_list ap;
va_start (ap, string);
vsprintf (msg,string ,ap);
va_end (ap);
pfp<<msg<<endl;
pfp.flush();
void STDIOHandler::Write(string str)
{
if (str.find("ERROR") != string::npos)
{
cerr << str << endl;
cerr.flush();
incrementErrors();
}
else if (str.find("WARNING") != string::npos)
{
cerr << str << endl;
cerr.flush();
incrementWarnings();
}
else
{ // infos
cout << str << endl;
cout.flush();
}
}
TraVisToHandler::TraVisToHandler(string host, int port) {
client = new TraVisToClient(host, port);
brokentags.push_back("<trajectories>");
brokentags.push_back("</trajectories>");
brokentags.push_back("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
FileHandler::FileHandler(const char *fn)
{
_pfp.open(fn);
if (!fn) {
char tmp[CLENGTH];
sprintf(tmp, "Error!!! File [%s] could not be opened!", fn);
cerr << tmp << endl;
exit(0);
}
}
TraVisToHandler::~TraVisToHandler(){
delete client;
FileHandler::~FileHandler()
{
_pfp.close();
}
void TraVisToHandler::Write(string str) {
vector<string>::iterator str_it;
void FileHandler::Write(string str)
{
if (this != NULL) {
_pfp << str << endl;
_pfp.flush();
}
//There are a few broken tags which need to be checked for and removed.
for (str_it = brokentags.begin(); str_it != brokentags.end(); ++str_it) {
int tagstart = str.find(*str_it);