O --- O
libPEDSIM Documentation
[HOME] [EXAMPLES] [ECOSYSTEM] [DOCUMENTATION] [DOWNLOAD]
O --- O
ped_outputwriter.h
1 //
2 // pedsim - A microscopic pedestrian simulation system.
3 // Copyright (c) by Christian Gloor
4 //
5 
6 #ifndef _ped_outputwriter_h_
7 #define _ped_outputwriter_h_ 1
8 
9 //disable warnings on 255 char debug symbols
10 #pragma warning (disable : 4786)
11 //disable warnings on extern before template instantiation
12 #pragma warning (disable : 4231)
13 
14 #ifdef _WIN32
15 #ifdef _DLL
16 # define LIBEXPORT __declspec(dllexport)
17 # define EXPIMP_TEMPLATE
18 #else
19 # define LIBEXPORT __declspec(dllimport)
20 # define EXPIMP_TEMPLATE extern
21 #endif
22 #else
23 # define LIBEXPORT
24 # define EXPIMP_TEMPLATE
25 #endif
26 
27 #ifdef _WIN32
28 #ifndef _WINSOCKAPI_
29 #include <WinSock2.h>
30 #endif
31 #else
32 #define SOCKET int
33 #endif
34 
35 #include <iostream>
36 #include <fstream>
37 #include <unordered_map>
38 
39 #include "ped_agent.h"
40 #include "ped_obstacle.h"
41 #include "ped_waypoint.h"
42 #include "ped_scene.h"
43 #include "ped_outputwriter.h"
44 
45 
46 namespace Ped {
47 
51  class LIBEXPORT OutputWriter {
52  public:
53  virtual ~OutputWriter() {};
54 
55  // pure virtual functions providing the framework.
56 
57  // general
58  virtual void writeTimeStep(long int timestep) = 0;
59  virtual void setScenarioName(string name) = 0;
60  virtual void drawLine(const Tvector &s, const Tvector &e, int duration = 1, double red = 1.0, double green = 1.0, double blue = 1.0) = 0;
61  virtual void writeMetrics(std::unordered_map<std::string,std::string> hash) = 0;
62  virtual void setCamera (Ped::Tvector pos, Ped::Tvector direction, string id = "") = 0;
63 
64  // szene
65  virtual void defineScene(Tscene &s) = 0;
66  virtual void addObstacle(Tobstacle &o) = 0;
67  virtual void addAgent(Tagent &a) = 0;
68  virtual void removeAgent(Tagent &a) = 0;
69  virtual void addWaypoint(Twaypoint &w) = 0;
70 
71  // agent
72  virtual void drawAgent(Tagent &a) = 0;
73  // obstacle
74  virtual void drawObstacle(Tobstacle &o) = 0;
75  // waypoint
76  virtual void drawWaypoint(Twaypoint &w) = 0;
77 
78  protected:
79  };
80 
81 
85  class LIBEXPORT CSV_OutputWriter : public OutputWriter {
86  public:
87  virtual ~CSV_OutputWriter() {};
88 
89  // general
90  virtual void writeTimeStep(long int timestep) {};
91 
92  // szene
93  virtual void defineScene(Tscene &s) {};
94  virtual void addObstacle(Tobstacle &o) {};
95  virtual void addAgent(Tagent &a) {};
96  virtual void removeAgent(Tagent &a) {};
97  virtual void addWaypoint(Twaypoint &w) {};
98 
99  // agent
100  virtual void drawAgent(Tagent &a) { cout << a.getid() << ", " << a.getPosition().x << ", " << a.getPosition().y << endl; };
101 
102  protected:
103  };
104 
105 
110  class LIBEXPORT XMLOutputWriter : public OutputWriter {
111  public:
112  XMLOutputWriter();
113  XMLOutputWriter(string scenarioname);
114  virtual ~XMLOutputWriter();
115 
116  // general
117  virtual void writeTimeStep(long int timestep);
118  virtual void setScenarioName(string name);
119  virtual void drawLine(const Tvector &s, const Tvector &e, int duration = 1, double red = 1.0, double green = 0.0, double blue = 0.0);
120  virtual void writeMetrics(std::unordered_map<std::string,std::string> hash);
121 
122  // szene
123  virtual void defineScene(Tscene &s) {};
124  virtual void addObstacle(Tobstacle &o) {};
125  virtual void addAgent(Tagent &a) {};
126  virtual void removeAgent(Tagent &a);
127  virtual void addWaypoint(Twaypoint &w) {};
128  virtual void setCamera (Ped::Tvector pos, Ped::Tvector direction, string id = "");
129 
130  // agent
131  virtual void drawAgent(Tagent &a);
132 
133  // obstacle
134  virtual void drawObstacle(Tobstacle &o);
135 
136  // waypoint
137  virtual void drawWaypoint(Twaypoint &w);
138 
139  protected:
140  virtual void write(string message) {};
141  };
142 
147  class LIBEXPORT FileOutputWriter : public XMLOutputWriter {
148  public:
150  virtual ~FileOutputWriter();
151 
152  protected:
153  virtual void write(string message);
154  ofstream outfile_;
155  };
156 
161  class LIBEXPORT UDPOutputWriter : public XMLOutputWriter {
162  public:
163  UDPOutputWriter();
164  virtual ~UDPOutputWriter();
165 
166  protected:
167  virtual void write(string message);
168  SOCKET socket_;
169  };
170 
171 
172 }
173 
174 #endif
O --- O

⁠(c) Christian Gloor [ c|h|g|l|o|o|r|@|s|i|l|m|a|r|i|l|.|o|r|g| ]