Commit d9a7b185 authored by Mohcine Chraibi's avatar Mohcine Chraibi

Formatting Code

The goal of this commit is always to make  diffs unambiguous by
2. Untabifying all files
1. Indent all files by using 4 spaces

Please adapt you editor so that it uses NO tabs  and only 4 spaces for indenting
parent 7c16ba28
......@@ -2,6 +2,7 @@
# -DCMAKE_CXX_COMPILER:STRING=clang++ -DCMAKE_C_COMPILER:STRING=clang .
# -DCMAKE_BUILD_TYPE:STRING=Debug (default Release)
# -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON (default OFF)
# -DBUILD_TESTING=ON (default OFF)
#--------------------------------------------------------------------------
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
......@@ -16,12 +17,11 @@ set(JPSCORE_VERSION
${JPSCORE_MAJOR_VERSION}.${JPSCORE_MINOR_VERSION}.${JPSCORE_PATCH_VERSION})
message( STATUS "JPSCORE_VERSION: " ${JPSCORE_VERSION} )
# # configure_file (
# # "${CMAKE_SOURCE_DIR}/Config.h.in"
# # "${CMAKE_BINARY_DIR}/Config.h"
# # )
# #include_directories ("${CMAKE_BINARY_DIR}")
if(NOT BUILD_TESTING)
set(BUILD_TESTING OFF)
endif(NOT BUILD_TESTING)
message( STATUS "BUILD_TESTING: " ${BUILD_TESTING} )
if(NOT DEFINED PROCESSOR_COUNT)
# Unknown:
set(PROCESSOR_COUNT 0)
......@@ -33,15 +33,6 @@ if(NOT DEFINED PROCESSOR_COUNT)
list(LENGTH procs PROCESSOR_COUNT)
endif(EXISTS "${cpuinfo_file}")
# Mac:
# if(APPLE)
# find_program(cmd_sys_pro "system_profiler")
# if(cmd_sys_pro)
# execute_process(COMMAND ${cmd_sys_pro} OUTPUT_VARIABLE info)
# string(REGEX REPLACE "^.*Total Number Of Cores: ([0-9]+).*$" "\\1"
# PROCESSOR_COUNT "${info}")
# endif(cmd_sys_pro)
# endif(APPLE)
# Windows:
if(WIN32)
......@@ -50,8 +41,6 @@ if(NOT DEFINED PROCESSOR_COUNT)
endif(NOT DEFINED PROCESSOR_COUNT)
if(PROCESSOR_COUNT)
# add 1 should be magic! http://www.kitware.com/blog/home/post/63
#math(EXPR PROCESSOR_COUNT "${PROCESSOR_COUNT} + 1")
message( STATUS "PROCESSOR_COUNT: " ${PROCESSOR_COUNT})
set(CTEST_BUILD_FLAGS "-j${PROCESSOR_COUNT}")
endif(PROCESSOR_COUNT)
......@@ -104,8 +93,7 @@ FIND_PACKAGE(CGAL QUIET)
if(CGAL_FOUND)
include (${CGAL_USE_FILE})
INCLUDE_DIRECTORIES(${CGAL_CORE_INCLUDE_DIR})
add_definitions(-D_CGAL=1)
target_link_libraries (jpscore ${CGAL_CORE_LIBRARY})
add_definitions(-D_CGAL=1)
message (SEND_ERROR "${CGAL_FOUND}")
message (FATAL_ERROR "${CGAL_CORE_INCLUDE_DIR}")
message (SEND_ERROR " Erreur: ${CGAL_FOUND}")
......@@ -115,7 +103,10 @@ else(CGAL_FOUND)
endif(CGAL_FOUND)
# test files: all cpp-files in Utest
file(GLOB test_files "${CMAKE_TEST_DIR}/*.cpp")
if(BUILD_TESTING)
file(GLOB test_files "${CMAKE_TEST_DIR}/*.cpp")
endif(BUILD_TESTING)
set ( source_files
main.cpp
Simulation.cpp
......@@ -269,7 +260,7 @@ set ( header_files
add_library ( core SHARED ${source_files} )
#add_library(core OBJECT ${source_files} ${header_files})
#Target
add_executable(
jpscore main.cpp
......@@ -303,33 +294,33 @@ else(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE MATCHES Debug)
endif(CMAKE_COMPILER_IS_GNUCXX AND CMAKE_BUILD_TYPE MATCHES Debug)
# ----------------------------- cTest ------------------------------------------
enable_testing() #adds another build target, which is test for Makefile generators
include(CTest) #adding Dart support
#test if code compiles and runs default setting. Takes about 30 seconds
add_test (jpscore_compile ${CMAKE_CTEST_COMMAND}
--build-and-test "${CMAKE_SOURCE_DIR}" "${EXECUTABLE_OUTPUT_PATH}" #"${CMAKE_BINARY_DIR}"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} -j${PROCESSOR_COUNT}
--build-two-config
--build-exe-dir ${EXECUTABLE_OUTPUT_PATH} # todo wo soll der exe hin?: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
--build-project JPScore
--test-command jpscore --ini=${CMAKE_SOURCE_DIR}/inputfiles/Default/ini.xml
)
if(BUILD_TESTING)
enable_testing() #adds another build target, which is test for Makefile generators
include(CTest) #adding Dart support
#test if code compiles and runs default setting. Takes about 30 seconds
add_test (jpscore_compile ${CMAKE_CTEST_COMMAND}
--build-and-test "${CMAKE_SOURCE_DIR}" "${EXECUTABLE_OUTPUT_PATH}" #"${CMAKE_BINARY_DIR}"
--build-generator ${CMAKE_GENERATOR}
--build-makeprogram ${CMAKE_MAKE_PROGRAM} -j${PROCESSOR_COUNT}
--build-two-config
--build-exe-dir ${EXECUTABLE_OUTPUT_PATH} # todo wo soll der exe hin?: ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}
--build-project JPScore
--test-command jpscore --ini=${CMAKE_SOURCE_DIR}/inputfiles/Default/ini.xml
)
foreach (test_src ${test_files})
GET_FILENAME_COMPONENT(test ${test_src} NAME_WE)
add_executable( ${test} ${test_src})
target_link_libraries (${test} core)
add_test(NAME ${test} COMMAND ${test})
endforeach(test_src ${test_files})
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
message(STATUS "Found Python: " ${PYTHON_EXECUTABLE})
message(STATUS "run: " ${CMAKE_SOURCE_DIR}/Utest/testflow.py)
set (test_parameters "${CMAKE_SOURCE_DIR}")
add_test(NAME flow COMMAND "${CMAKE_TEST_DIR}/testflow.py" "${test_parameters}")
#add_test(testtime "${CMAKE_SOURCE_DIR}/Utest/run.py")
endif(PYTHONINTERP_FOUND)
foreach (test_src ${test_files})
GET_FILENAME_COMPONENT(test ${test_src} NAME_WE)
add_executable( ${test} ${test_src})
target_link_libraries (${test} core)
add_test(NAME ${test} COMMAND ${test})
endforeach(test_src ${test_files})
find_package(PythonInterp)
if(PYTHONINTERP_FOUND)
message(STATUS "Found Python: " ${PYTHON_EXECUTABLE})
message(STATUS "run: " ${CMAKE_SOURCE_DIR}/Utest/testflow.py)
set (test_parameters "${CMAKE_SOURCE_DIR}")
add_test(NAME flow COMMAND "${CMAKE_TEST_DIR}/testflow.py" "${test_parameters}")
endif(PYTHONINTERP_FOUND)
endif(BUILD_TESTING)
......@@ -37,263 +37,263 @@ using namespace std;
IODispatcher::IODispatcher() {
pHandlers = vector<OutputHandler*>();
pHandlers = vector<OutputHandler*>();
}
IODispatcher::~IODispatcher() {
for (int i = 0; i < (int) pHandlers.size(); i++)
delete pHandlers[i];
pHandlers.clear();
for (int i = 0; i < (int) pHandlers.size(); i++)
delete pHandlers[i];
pHandlers.clear();
}
void IODispatcher::AddIO(OutputHandler* ioh) {
pHandlers.push_back(ioh);
pHandlers.push_back(ioh);
}
const vector<OutputHandler*>& IODispatcher::GetIOHandlers() {
return pHandlers;
return pHandlers;
}
void IODispatcher::Write(const std::string& str) {
for (vector<OutputHandler*>::iterator it = pHandlers.begin();
it != pHandlers.end(); ++it) {
(*it)->Write(str);
}
for (vector<OutputHandler*>::iterator it = pHandlers.begin();
it != pHandlers.end(); ++it) {
(*it)->Write(str);
}
}
string IODispatcher::WritePed(Pedestrian* ped) {
double RAD2DEG = 180.0 / M_PI;
char tmp[CLENGTH] = "";
double v0 = ped->GetV0Norm();
if (v0 == 0.0) {
Log->Write("ERROR: IODispatcher::WritePed()\t v0=0");
exit(0);
}
double v = ped->GetV().Norm();
int color = (int) (v / v0 * 255);
if(ped->GetSpotlight()==false) color=-1;
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
sprintf(tmp, "<agent ID=\"%d\"\t"
"xPos=\"%.2f\"\tyPos=\"%.2f\"\t"
"zPos=\"%.2f\"\t"
"radiusA=\"%.2f\"\tradiusB=\"%.2f\"\t"
"ellipseOrientation=\"%.2f\" ellipseColor=\"%d\"/>\n",
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
return tmp;
double RAD2DEG = 180.0 / M_PI;
char tmp[CLENGTH] = "";
double v0 = ped->GetV0Norm();
if (v0 == 0.0) {
Log->Write("ERROR: IODispatcher::WritePed()\t v0=0");
exit(0);
}
double v = ped->GetV().Norm();
int color = (int) (v / v0 * 255);
if(ped->GetSpotlight()==false) color=-1;
double a = ped->GetLargerAxis();
double b = ped->GetSmallerAxis();
double phi = atan2(ped->GetEllipse().GetSinPhi(), ped->GetEllipse().GetCosPhi());
sprintf(tmp, "<agent ID=\"%d\"\t"
"xPos=\"%.2f\"\tyPos=\"%.2f\"\t"
"zPos=\"%.2f\"\t"
"radiusA=\"%.2f\"\tradiusB=\"%.2f\"\t"
"ellipseOrientation=\"%.2f\" ellipseColor=\"%d\"/>\n",
ped->GetID(), (ped->GetPos().GetX()) * FAKTOR,
(ped->GetPos().GetY()) * FAKTOR,(ped->GetElevation()+0.3) * FAKTOR ,a * FAKTOR, b * FAKTOR,
phi * RAD2DEG, color);
return tmp;
}
void IODispatcher::WriteHeader(int nPeds, double fps, Building* building, int seed ) {
nPeds = building->GetNumberOfPedestrians();
string tmp;
tmp =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<trajectories>\n";
char agents[CLENGTH] = "";
sprintf(agents, "\t<header version = \"%s\">\n", JPS_VERSION);
tmp.append(agents);
sprintf(agents, "\t\t<agents>%d</agents>\n", nPeds);
tmp.append(agents);
sprintf(agents, "\t\t<seed>%d</seed>\n", seed);
tmp.append(agents);
sprintf(agents, "\t\t<frameRate>%f</frameRate>\n", fps);
tmp.append(agents);
tmp.append("\t</header>\n");
Write(tmp);
void IODispatcher::WriteHeader(int nPeds, double fps, Building* building, int seed ) {
nPeds = building->GetNumberOfPedestrians();
string tmp;
tmp =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n" "<trajectories>\n";
char agents[CLENGTH] = "";
sprintf(agents, "\t<header version = \"%s\">\n", JPS_VERSION);
tmp.append(agents);
sprintf(agents, "\t\t<agents>%d</agents>\n", nPeds);
tmp.append(agents);
sprintf(agents, "\t\t<seed>%d</seed>\n", seed);
tmp.append(agents);
sprintf(agents, "\t\t<frameRate>%f</frameRate>\n", fps);
tmp.append(agents);
tmp.append("\t</header>\n");
Write(tmp);
}
void IODispatcher::WriteGeometry(Building* building) {
// just put a link to the geometry file
string embed_geometry;
embed_geometry.append("\t<geometry>\n");
char file_location[CLENGTH] = "";
sprintf(file_location, "\t<file location= \"%s\"/>\n", building->GetGeometryFilename().c_str());
embed_geometry.append(file_location);
embed_geometry.append("\t</geometry>\n");
//Write(embed_geometry);
//return;
//
string geometry;
geometry.append("\t<geometry>\n");
bool plotHlines = true;
bool plotCrossings = true;
bool plotTransitions = true;
bool plotPlayingField=false;
vector<string> rooms_to_plot;
//Promenade
//rooms_to_plot.push_back("outside");
//rooms_to_plot.push_back("010");
// first the rooms
//to avoid writing navigation line twice
vector<int> navLineWritten;
for (int i = 0; i < building->GetNumberOfRooms(); i++) {
Room* r = building->GetRoom(i);
string caption = r->GetCaption(); //if(r->GetID()!=1) continue;
if (rooms_to_plot.empty() == false)
if (IsElementInVector(rooms_to_plot, caption) == false)
continue;
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k); //if(s->GetSubRoomID()!=0) continue;
geometry.append(s->WriteSubRoom());
// the hlines
if (plotHlines) {
const vector<Hline*>& hlines = s->GetAllHlines();
for (unsigned int i = 0; i < hlines.size(); i++) {
Hline* hline = hlines[i];
int uid1 = hline->GetUniqueID();
if (!IsElementInVector(navLineWritten, uid1)) {
navLineWritten.push_back(uid1);
if (rooms_to_plot.empty()
|| IsElementInVector(rooms_to_plot, caption)) {
geometry.append(hline->WriteElement());
}
}
}
// the crossings
if (plotCrossings) {
const vector<Crossing*>& crossings = s->GetAllCrossings();
for (unsigned int i = 0; i < crossings.size(); i++) {
Crossing* crossing = crossings[i];
int uid1 = crossing->GetUniqueID();
if (!IsElementInVector(navLineWritten, uid1)) {
navLineWritten.push_back(uid1);
if (rooms_to_plot.empty()
|| IsElementInVector(rooms_to_plot,
caption)) {
geometry.append(crossing->WriteElement());
}
}
}
}
// the transitions
if (plotTransitions) {
const vector<Transition*>& transitions =
s->GetAllTransitions();
for (unsigned int i = 0; i < transitions.size(); i++) {
Transition* transition = transitions[i];
int uid1 = transition->GetUniqueID();
if (!IsElementInVector(navLineWritten, uid1)) {
navLineWritten.push_back(uid1);
if (rooms_to_plot.empty()) {
geometry.append(transition->WriteElement());
} else {
Room* room1 = transition->GetRoom1();
Room* room2 = transition->GetRoom2();
string caption1 = room1->GetCaption();
if (room2) {
string caption2 = room2->GetCaption();
if (IsElementInVector(rooms_to_plot,
caption1)
|| IsElementInVector(rooms_to_plot,
caption2)) {
geometry.append(transition->WriteElement());
}
} else {
if (IsElementInVector(rooms_to_plot,
caption1)) {
geometry.append(transition->WriteElement());
}
}
}
}
}
}
}
}
}
//eventually write any goal
for (map<int, Goal*>::const_iterator itr = building->GetAllGoals().begin();
itr != building->GetAllGoals().end(); ++itr) {
geometry.append(itr->second->Write());
}
if(plotPlayingField){
//add the playing area
double width=3282;
double length=5668;
char tmp[100];
geometry.append("\t\t<wall>\n");
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,-width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,-width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
geometry.append(tmp);
geometry.append("\t\t</wall>\n");
geometry.append("\t\t<wall>\n");
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,-width);
geometry.append(tmp);
geometry.append("\t\t</wall>\n");
}
geometry.append("\t</geometry>\n");
Write(geometry);
// just put a link to the geometry file
string embed_geometry;
embed_geometry.append("\t<geometry>\n");
char file_location[CLENGTH] = "";
sprintf(file_location, "\t<file location= \"%s\"/>\n", building->GetGeometryFilename().c_str());
embed_geometry.append(file_location);
embed_geometry.append("\t</geometry>\n");
//Write(embed_geometry);
//return;
//
string geometry;
geometry.append("\t<geometry>\n");
bool plotHlines = true;
bool plotCrossings = true;
bool plotTransitions = true;
bool plotPlayingField=false;
vector<string> rooms_to_plot;
//Promenade
//rooms_to_plot.push_back("outside");
//rooms_to_plot.push_back("010");
// first the rooms
//to avoid writing navigation line twice
vector<int> navLineWritten;
for (int i = 0; i < building->GetNumberOfRooms(); i++) {
Room* r = building->GetRoom(i);
string caption = r->GetCaption(); //if(r->GetID()!=1) continue;
if (rooms_to_plot.empty() == false)
if (IsElementInVector(rooms_to_plot, caption) == false)
continue;
for (int k = 0; k < r->GetNumberOfSubRooms(); k++) {
SubRoom* s = r->GetSubRoom(k); //if(s->GetSubRoomID()!=0) continue;
geometry.append(s->WriteSubRoom());
// the hlines
if (plotHlines) {
const vector<Hline*>& hlines = s->GetAllHlines();
for (unsigned int i = 0; i < hlines.size(); i++) {
Hline* hline = hlines[i];
int uid1 = hline->GetUniqueID();
if (!IsElementInVector(navLineWritten, uid1)) {
navLineWritten.push_back(uid1);
if (rooms_to_plot.empty()
|| IsElementInVector(rooms_to_plot, caption)) {
geometry.append(hline->WriteElement());
}
}
}
// the crossings
if (plotCrossings) {
const vector<Crossing*>& crossings = s->GetAllCrossings();
for (unsigned int i = 0; i < crossings.size(); i++) {
Crossing* crossing = crossings[i];
int uid1 = crossing->GetUniqueID();
if (!IsElementInVector(navLineWritten, uid1)) {
navLineWritten.push_back(uid1);
if (rooms_to_plot.empty()
|| IsElementInVector(rooms_to_plot,
caption)) {
geometry.append(crossing->WriteElement());
}
}
}
}
// the transitions
if (plotTransitions) {
const vector<Transition*>& transitions =
s->GetAllTransitions();
for (unsigned int i = 0; i < transitions.size(); i++) {
Transition* transition = transitions[i];
int uid1 = transition->GetUniqueID();
if (!IsElementInVector(navLineWritten, uid1)) {
navLineWritten.push_back(uid1);
if (rooms_to_plot.empty()) {
geometry.append(transition->WriteElement());
} else {
Room* room1 = transition->GetRoom1();
Room* room2 = transition->GetRoom2();
string caption1 = room1->GetCaption();
if (room2) {
string caption2 = room2->GetCaption();
if (IsElementInVector(rooms_to_plot,
caption1)
|| IsElementInVector(rooms_to_plot,
caption2)) {
geometry.append(transition->WriteElement());
}
} else {
if (IsElementInVector(rooms_to_plot,
caption1)) {
geometry.append(transition->WriteElement());
}
}
}
}
}
}
}
}
}
//eventually write any goal
for (map<int, Goal*>::const_iterator itr = building->GetAllGoals().begin();
itr != building->GetAllGoals().end(); ++itr) {
geometry.append(itr->second->Write());
}
if(plotPlayingField){
//add the playing area
double width=3282;
double length=5668;
char tmp[100];
geometry.append("\t\t<wall>\n");
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,-width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,-width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",length,width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",-length,width);
geometry.append(tmp);
geometry.append("\t\t</wall>\n");
geometry.append("\t\t<wall>\n");
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,width);
geometry.append(tmp);
sprintf(tmp, "\t\t\t<point xPos=\"%.2f\" yPos=\"%.2f\"/>\n",0.0,-width);
geometry.append(tmp);
geometry.append("\t\t</wall>\n");
}
geometry.append("\t</geometry>\n");
Write(geometry);
}
void IODispatcher::WriteFrame(int frameNr, Building* building) {
string data;
char tmp[CLENGTH] = "";
vector<string> rooms_to_plot;
//promenade
//rooms_to_plot.push_back("010");
sprintf(tmp, "<frame ID=\"%d\">\n", frameNr);
data.append(tmp);
for (int roomindex = 0; roomindex < building->GetNumberOfRooms(); roomindex++) {
Room* r = building->GetRoom(roomindex);
string caption = r->GetCaption();
if ((rooms_to_plot.empty() == false)
&& (IsElementInVector(rooms_to_plot, caption) == false)) {