Macros.h 6.95 KB
Newer Older
1
/**
2 3
 * \file        Macros.h
 * \date        Jun 16, 2010
4
 * \version     v0.6
Mohcine Chraibi's avatar
Mohcine Chraibi committed
5
 * \copyright   <2009-2015> Forschungszentrum Jülich GmbH. All rights reserved.
Ulrich Kemloh's avatar
Ulrich Kemloh committed
6
 *
7
 * \section License
8 9 10
 * This file is part of JuPedSim.
 *
 * JuPedSim is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU Lesser General Public License as published by
12 13 14 15 16 17 18 19
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * 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.
 *
20
 * You should have received a copy of the GNU Lesser General Public License
21 22
 * along with JuPedSim. If not, see <http://www.gnu.org/licenses/>.
 *
23
 * \section Description
24
 * useful constants
25 26 27 28
 *
 *
 **/
 
Ulrich Kemloh's avatar
Ulrich Kemloh committed
29 30

#ifndef _MACROS_H
Ulrich Kemloh's avatar
Ulrich Kemloh committed
31
#define _MACROS_H
Ulrich Kemloh's avatar
Ulrich Kemloh committed
32

Ulrich Kemloh's avatar
Ulrich Kemloh committed
33 34
#include <cstdlib>
#include <vector>
35
#include <map>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
36
#include <string.h>
Ulrich Kemloh's avatar
Ulrich Kemloh committed
37
#include <algorithm>
38
#include <sstream>
39
#include <iostream>
40

41

42 43
#define _USE_MATH_DEFINES
#include <math.h>
Mohcine Chraibi's avatar
Mohcine Chraibi committed
44 45 46 47 48

#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif 

49

50
// should be true only when using this file in the simulation core
51
#define _SIMULATOR 1
52
#define _USE_PROTOCOL_BUFFER 1
53

54

Mohcine Chraibi's avatar
Mohcine Chraibi committed
55 56 57 58 59 60

#define JPS_OLD_VERSION "0.5" // this version is still supported
#define JPS_VERSION_MINOR "6"
#define JPS_VERSION_MAJOR "0"

#define JPS_VERSION JPS_VERSION_MAJOR "." JPS_VERSION_MINOR
61 62

// disable openmp in debug mode
63
#ifdef _NDEBUG
Ulrich Kemloh's avatar
Ulrich Kemloh committed
64
//#undef _OPENMP
65
#endif
Ulrich Kemloh's avatar
Ulrich Kemloh committed
66

67
// precision error
68
#define J_EPS 0.001
69
#define J_EPS_EVENT 0.00001 //zum pruefen des aktuellen Zeitschrittes auf events
70
#define J_EPS_DIST 0.05// [m]
71

72 73 74
#define J_EPS_GOAL 0.005 /// [m] Abstand zum Ziel, damit Fußgänger immer zu einem Raum gehört
#define J_TOLERANZ 0.03  /// [m] Toleranz beim erstellen der Linien
#define J_EPS_V 0.1 /// [m/s] wenn  v<EPS_V wird mit 0 gerechnet
75

76 77 78
// routing macros
#define J_QUEUE_VEL_THRESHOLD_NEW_ROOM 0.7 // [m/s] maximum speed to be considered in a queue while looking for a reference in a new room
#define J_QUEUE_VEL_THRESHOLD_JAM 0.2 // [m/s] maximum speed to be considered in a queue while looking for a reference in a jam situation
79 80
#define CBA_THRESHOLD 0.15
#define OBSTRUCTION 4
81

82
// Length of array
Ulrich Kemloh's avatar
Ulrich Kemloh committed
83 84
#define CLENGTH 1000

85
// conversion (cm <-> m)
86
#define FAKTOR 1
Ulrich Kemloh's avatar
Ulrich Kemloh committed
87

88 89
// default final destination for the pedestrians
#define FINAL_DEST_OUT -1
Ulrich Kemloh's avatar
Ulrich Kemloh committed
90 91

// Linked cells
Mohcine Chraibi's avatar
Mohcine Chraibi committed
92
#define LIST_EMPTY      -1
Ulrich Kemloh's avatar
Ulrich Kemloh committed
93

94 95

enum RoomState {
96 97
     ROOM_CLEAN=0,
     ROOM_SMOKED=1
98 99
};

100 101 102 103 104 105 106
enum AgentType {
     MALE=0,
     FEMALE,
     CHILD,
     ELDERLY
};

107
enum FileFormat {
108 109 110 111 112
     FORMAT_XML_PLAIN,
     FORMAT_XML_BIN,
     FORMAT_PLAIN,
     FORMAT_VTK,
     FORMAT_XML_PLAIN_WITH_MESH
113
};
Ulrich Kemloh's avatar
Ulrich Kemloh committed
114

115
enum RoutingStrategy {
116
     ROUTING_LOCAL_SHORTEST=1,
117 118 119 120 121 122 123 124
     ROUTING_GLOBAL_SHORTEST,
     ROUTING_QUICKEST,
     ROUTING_FROM_FILE,
     ROUTING_NAV_MESH,
     ROUTING_DUMMY,
     ROUTING_SAFEST,
     ROUTING_COGNITIVEMAP,
     ROUTING_UNDEFINED =-1
125
};
Ulrich Kemloh's avatar
Ulrich Kemloh committed
126

127 128
enum OperativModels {
    MODEL_GFCM=1,
129 130 131 132 133
    MODEL_GOMPERTZ,
//    MODEL_ORCA,
//    MODEL_CFM,
//    MODEL_VELO
//    MODEL_GNM
134
};
Ulrich Kemloh's avatar
Ulrich Kemloh committed
135

136 137 138 139
enum AgentColorMode {
     BY_VELOCITY=1,
     BY_KNOWLEDGE,
     BY_ROUTE,
140 141
     BY_SPOTLIGHT,
     //BY_GROUP
142
};
Ulrich Kemloh's avatar
Ulrich Kemloh committed
143 144
//global functions for convenience

145
inline char xmltob(const char * t, char v = 0)
146
{
147
     if (t && (*t)) return (char) atoi(t);
148 149
     return v;
}
150
inline int xmltoi(const char * t, int v = 0)
151
{
152
     if (t && (*t)) return atoi(t);
153 154
     return v;
}
155
inline long xmltol(const char * t, long v = 0)
156
{
157
     if (t && (*t)) return atol(t);
158 159
     return v;
}
160
inline double xmltof(const char * t, double v = 0.0)
161
{
162
     if (t && (*t)) return atof(t);
163 164
     return v;
}
165
inline const char * xmltoa(const char * t, const char * v = "")
166
{
167
     if (t) return t;
168 169
     return v;
}
170
inline char xmltoc(const char * t, const char v = '\0')
171
{
172
     if (t && (*t)) return *t;
173 174
     return v;
}
Ulrich Kemloh's avatar
Ulrich Kemloh committed
175

176 177 178
/**
 * @return true if the element is present in the vector
 */
Ulrich Kemloh's avatar
Ulrich Kemloh committed
179
template<typename A>
180 181 182 183 184 185 186
inline 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;
Ulrich Kemloh's avatar
Ulrich Kemloh committed
187
     }
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
}

/**
 * Implementation of a map with a default value.
 * @return the default value if the element was not found in the map
 */
template <typename K, typename V>
inline V GetWithDef(const  std::map <K,V> & m, const K & key, const V & defval ) {
     typename std::map<K,V>::const_iterator it = m.find( key );
     if ( it == m.end() ) {
          return defval;
     } else {
          return it->second;
     }
}

inline std::string concatenate(std::string const& name, int i) {
     std::stringstream s;
     s << name << i;
     return s.str();
}
209

210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
//**************************************************************
//useful colors attributes for debugging
//**************************************************************

//Text attributes
#define OFF       0     //All attributes off
#define BRIGHT      1    //Bold on
//       4    Underscore (on monochrome display adapter only)
#define BLINK       5    //Blink on
//       7    Reverse video on
//      8    Concealed on

//   Foreground colors
#define BLACK     30
#define CYAN      36
#define WHITE     37
#define RED       31
#define GREEN     32
#define YELLOW    33
#define BLUE      34
#define MAGENTA   35

//    Background colors
#define BG_BLACK  40
#define BG_RED    41
#define BG_GREEN  42
#define BG_YELLOW 43
#define BG_BLUE   44
#define BG_CYAN   47
#define BG_WHITE  47

// Special caracters
#define HOME  printf("\033[1;1H");  // cursor up left
#define CLEAR   printf(" \033[2J"); //clear screen
#define RED_LINE  printf("%c[%d;%d;%dm\n",0x1B, BRIGHT,RED,BG_BLACK);
#define GREEN_LINE  printf("\t%c[%d;%d;%dm",0x1B, BRIGHT,GREEN,BG_BLACK);
#define BLUE_LINE  printf("\t%c[%d;%d;%dm",0x1B, BRIGHT,BLUE,BG_BLACK);
#define MAGENTA_LINE  printf("\t%c[%d;%d;%dm",0x1B, BRIGHT,MAGENTA,BG_BLACK);
#define YELLOW_LINE  printf("\t%c[%d;%d;%dm",0x1B, BRIGHT,YELLOW,BG_BLACK);
#define OFF_LINE printf("%c[%dm\n", 0x1B, OFF);


//**************************************************************
//useful macros  for debugging
//**************************************************************
#ifdef TRACE_LOGGING

inline void _printDebugLine(const std::string& fileName, int lineNumber)
{
unsigned found = fileName.find_last_of("/\\");
std::cerr  << "["<< lineNumber  << "]: ---"<< fileName.substr(found+1)<< " ---"<<std::endl;
}

#define dtrace(...)                         \
    (_printDebugLine(__FILE__, __LINE__),   \
    fprintf(stderr, __VA_ARGS__),           \
    (void) fprintf(stderr, "\n"))

#define derror(...)                         \
    (_printDebugLine(__FILE__, __LINE__),   \
    fprintf(stderr, "ERROR: "),             \
    fprintf(stderr, __VA_ARGS__)            \
    )
#else

#define dtrace(...)    ((void) 0)
#define derror(...)                         \
    (fprintf(stderr, __VA_ARGS__)           \
    )
#endif /* TRACE_LOGGING */

Mohcine Chraibi's avatar
Mohcine Chraibi committed
281
#endif  /* _MACROS_H */