From e8332bb3232800b50c367ce095234372a2ac5c74 Mon Sep 17 00:00:00 2001 From: Fabien Grzeskowiak Date: Fri, 10 Apr 2020 15:19:38 +0200 Subject: [PATCH] fix UMANS for linux --- APIFunctions.cpp | 16 ++++++++++++---- APIFunctions.h | 25 +++++++++++-------------- CMakeLists.txt | 4 ++-- include/core/crowdSimulator.h | 4 ++-- include/tools/vector2D.h | 6 +++--- src/CostFunctions/FOEAvoidance.cpp | 8 ++++---- src/CostFunctions/TtcaDca.cpp | 4 ++-- src/core/policy.cpp | 6 +++--- 8 files changed, 39 insertions(+), 34 deletions(-) diff --git a/APIFunctions.cpp b/APIFunctions.cpp index c58a5c2..5fc5f43 100644 --- a/APIFunctions.cpp +++ b/APIFunctions.cpp @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -26,21 +26,29 @@ #include #include #include +#include +#include +#include -extern "C" { - +extern "C" +{ CrowdSimulator* cs; AgentData* agentData; size_t agentDataSize; API_FUNCTION bool StartSimulation(const char* configFileName, int numberOfThreads) { + std::setlocale(LC_NUMERIC, "en_US.UTF-8"); + omp_set_num_threads(numberOfThreads); // initialize a new crowd simulation; we'll fill it with the contents of the given config file cs = CrowdSimulator::FromConfigFile(configFileName, false); if (cs == nullptr) + { return false; + } + cs->GetWorld()->SetNumberOfThreads(numberOfThreads); @@ -196,4 +204,4 @@ extern "C" { return true; } -} \ No newline at end of file +} diff --git a/APIFunctions.h b/APIFunctions.h index 756364d..1d732db 100644 --- a/APIFunctions.h +++ b/APIFunctions.h @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -23,12 +23,10 @@ #ifdef WIN32 #define API_FUNCTION __declspec(dllexport) #else -#define API_FUNCTION __attribute__((visibility("default"))) +#define API_FUNCTION #endif #endif -extern "C" -{ /// A struct that describes the status of a single agent in the simulation. /// This struct is used for communication between the UMANS library and external applications. struct AgentData @@ -48,18 +46,18 @@ extern "C" /// Sets up a simulation based on a configuration file. /// After this function call, the simulation will be ready for its first time step. /// true if the operation was successful; false otherwise, e.g. if the configuration file is invalid. - API_FUNCTION bool StartSimulation(const char* configFileName, int nrThreads); + API_FUNCTION extern "C" bool StartSimulation(const char* configFileName, int nrThreads); /// Gets the step size of the simulation, in seconds. /// [out] Will store the step size of the simulation. /// true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet. - API_FUNCTION bool GetSimulationTimeStep(float& result_dt); + API_FUNCTION extern "C" bool GetSimulationTimeStep(float& result_dt); /// Performs the given number of simulation steps. /// To obtain the resulting status of the simulation, use the GetAgentPositions() function. /// The number of steps to perform. /// true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet. - API_FUNCTION bool DoSimulationSteps(int nrSteps); + API_FUNCTION extern "C" bool DoSimulationSteps(int nrSteps); /// Gets the current status of all agents in the simulation. /// [out] Will store a reference to an array of AgentData objects, @@ -67,13 +65,13 @@ extern "C" /// [out] Will store the number of agents in the simulation, /// i.e. the number of useful entries in the AgentData array. /// true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet. - API_FUNCTION bool GetAgentPositions(AgentData*& result_agentData, int& result_nrAgents); + API_FUNCTION extern "C" bool GetAgentPositions(AgentData*& result_agentData, int& result_nrAgents); /// Overrides the position of some or all agents in the simulation. You can decide for yourself which agents are affected. /// A reference to an array of AgentData objects, where each object describes the position of a single agent that you want to set. /// The number of entries in the AgentData array. /// true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet. - API_FUNCTION bool SetAgentPositions(AgentData* agentData, int nrAgents); + API_FUNCTION extern "C" bool SetAgentPositions(AgentData* agentData, int nrAgents); /// Tries to add a new agent to the simulation. /// The x-coordinate of the agent's starting position. @@ -88,13 +86,13 @@ extern "C" /// otherwise, the simulation will assign a different ID. /// true if the operation was successful; false otherwise, /// i.e. if the simulation has not been initialized (correctly) yet, or if the agent with the given ID does not exist. - API_FUNCTION bool AddAgent(float x, float y, float radius, float prefSpeed, float maxSpeed, float maxAcceleration, int policyID, int& result_id, int desiredID = -1); + API_FUNCTION extern "C" bool AddAgent(float x, float y, float radius, float prefSpeed, float maxSpeed, float maxAcceleration, int policyID, int& result_id, int desiredID = -1); /// Tries to remove a specific agent from the simulation. /// The ID of the agent to remove. /// true if the operation was successful; false otherwise, /// i.e. if the simulation has not been initialized (correctly) yet, or if the agent with the given ID does not exist. - API_FUNCTION bool RemoveAgent(int id); + API_FUNCTION extern "C" bool RemoveAgent(int id); /// Changes the goal of a single agent in the simulation. /// The ID of the agent to change. @@ -102,9 +100,8 @@ extern "C" /// The y-coordinate of the agent's new goal. /// true if the operation was successful; false otherwise, /// i.e. if the simulation has not been initialized (correctly) yet, or if the agent with the given ID does not exist. - API_FUNCTION bool SetAgentGoal(int id, float x, float y); + API_FUNCTION extern "C" bool SetAgentGoal(int id, float x, float y); /// Cleans up some objects related to the simulation. Call this method just before you finish using the UMANS library. /// true if the operation was successful; false otherwise, i.e. if the simulation has not been initialized (correctly) yet. - API_FUNCTION bool CleanUp(); -} \ No newline at end of file + API_FUNCTION extern "C" bool CleanUp(); diff --git a/CMakeLists.txt b/CMakeLists.txt index 718ee6d..cca56c6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ cmake_minimum_required( VERSION 2.8 ) project( UMANS ) -set (CMAKE_CXX_STANDARD 14) +set (CMAKE_CXX_STANDARD 17) #set(EXECUTABLE_OUTPUT_PATH bin/${CMAKE_BUILD_TYPE}) @@ -48,7 +48,7 @@ endif (UMANS_USE_MULTITHREADING) # === Linux compatibility compiler option if (NOT MSVC) - add_definitions(-fPIC) + add_definitions(-O3 -lstdc++fs -fPIC -shared) endif() # === Engine project: a static library that performs the simulation diff --git a/include/core/crowdSimulator.h b/include/core/crowdSimulator.h index 882039a..225f4e3 100644 --- a/include/core/crowdSimulator.h +++ b/include/core/crowdSimulator.h @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -60,7 +60,7 @@ public: /// This affects whether or not the program will try to print progress information to the console. /// A pointer to new CrowdSimulator object, or nullptr if the loading failed for any reason. static CrowdSimulator* FromConfigFile(const std::string& filename, bool isConsoleApplication); - + /// Destroys this CrowdSimulator object. ~CrowdSimulator(); diff --git a/include/tools/vector2D.h b/include/tools/vector2D.h index 3e50f38..6079447 100644 --- a/include/tools/vector2D.h +++ b/include/tools/vector2D.h @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -219,7 +219,7 @@ inline float counterClockwiseAngle(const Vector2D& va, const Vector2D& vb) #pragma endregion -template T clamp(T v, T min, T max) +template T v2D_clamp(T v, T min, T max) { if (v < min) return min; @@ -228,7 +228,7 @@ template T clamp(T v, T min, T max) return v; } -inline Vector2D clamp(const Vector2D& v, float maxLength) +inline Vector2D v2D_clamp(const Vector2D& v, float maxLength) { float mag = v.magnitude(); if (mag <= maxLength) diff --git a/src/CostFunctions/FOEAvoidance.cpp b/src/CostFunctions/FOEAvoidance.cpp index 909aa8a..db4e9d8 100644 --- a/src/CostFunctions/FOEAvoidance.cpp +++ b/src/CostFunctions/FOEAvoidance.cpp @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -42,7 +42,7 @@ float Importance(float ttc) float t0 = 5, I0 = 10, a = -I0 / t0; float I = a * ttc + I0; - return clamp(I, 0.1f, 10.f); + return v2D_clamp(I, 0.1f, 10.f); //return 1; } @@ -125,9 +125,9 @@ Vector2D FOEAvoidance::GetGradient(const Vector2D& velocity, Agent* agent, const // TODO: check neighboring obstacles // ... - gradtheta = clamp(gradtheta, -0.1f, 0.1f); + gradtheta = v2D_clamp(gradtheta, -0.1f, 0.1f); //gradtheta = -gradtheta; - //gradv = clamp(gradv, -1.f, 1.f); + //gradv = v2D_clamp(gradv, -1.f, 1.f); //gradv = 0; return -1 * R*(velocity.magnitude()*Vector2D(sin(gradtheta), 1 - cos(gradtheta)) + Vector2D(0, gradv)); diff --git a/src/CostFunctions/TtcaDca.cpp b/src/CostFunctions/TtcaDca.cpp index 68b79a3..b32e958 100644 --- a/src/CostFunctions/TtcaDca.cpp +++ b/src/CostFunctions/TtcaDca.cpp @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -229,7 +229,7 @@ Vector2D TtcaDca::GetGradient(const Vector2D& velocity, Agent* agent, const Worl GradS += GradThS_movement.second; // clamp the change in angle - //GradTh = clamp(GradTh, -1.f, 1.f); + //GradTh = v2D_clamp(GradTh, -1.f, 1.f); Vector2D Gradient; diff --git a/src/core/policy.cpp b/src/core/policy.cpp index d4c6d37..dd0df91 100644 --- a/src/core/policy.cpp +++ b/src/core/policy.cpp @@ -1,5 +1,5 @@ /* UMANS: Unified Microscopic Agent Navigation Simulator -** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettré +** Copyright (C) 2018-2020 Inria Rennes Bretagne Atlantique - Rainbow - Julien Pettr� ** ** This program is free software: you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by @@ -61,10 +61,10 @@ Vector2D Policy::ComputeNewVelocity(Agent* agent, WorldBase * world) } // clamp to a maximum acceleration - acceleration = clamp(acceleration, agent->getMaximumAcceleration()); + acceleration = v2D_clamp(acceleration, agent->getMaximumAcceleration()); // use this to compute a new velocity, clamped to a maximum speed - return clamp(currentVelocity + acceleration * dt, agent->getMaximumSpeed()); + return v2D_clamp(currentVelocity + acceleration * dt, agent->getMaximumSpeed()); } Vector2D Policy::getAccelerationFromGradient(Agent* agent, WorldBase * world) -- GitLab