MengeCrowdSim / Menge

The source code for the Menge crowd simulation framework
Apache License 2.0
139 stars 64 forks source link

Access to visualization-relevant quantities #108

Open MZofka opened 5 years ago

MZofka commented 5 years ago

Hi,

since the documentation is not very helpful, i would like to address my issue here:

i am working on a external viewer for some of the agent's internal quantities based on the Robot Operating System (ROS). Therefore, i am trying to access some of the relevant quantities (the agent's environment, velocity, roadgraph,...) to visualize them in RVIZ.

I tried to access the static environment via the SpatialQuery data structure using the getObstacles() function, but the received list size always seems to be zero. So i am missing the obstacles, which has been defined in the xml scene configuration, such as

`

` which is read from the scenario xml configuration by starting up. So at least i would have expected size 1 for the obstacle list from the SpatialQuery data structure.

Additionally, can you tell me how to access

I understood that there are behavior-specific quantities, which i also would like to access. I am interfacing MENGE via an own agent model, inheriting from Menge::Agents::SimulatorBase< MyModel >.

Any help is highly appreciated.

MengeCrowdSim commented 5 years ago

Your primary guidance will be found in the MengeVis library. Menge's default visualizer visualizes quantities such as the environment (obstacles) and global roadmap. I assume the "agent's individual trip" means a particular agent's path through the environment (assuming its velocity component defines a path).

Obstacles

SimSystem::addObstacleToScene shows how to extract the obstacles from the simulator.

Roadmap

One of the keys to this is to remember that the roadmap belongs to one or more VelocityComponents. Admittedly, if all of your agents only belong to states that use a road_map velocity component, then you should have access to it. So, we'll separate this into two concepts: getting access to the roadmap and visualizing it.

Accessing the roadmap

Option 1: Grab a pointer to the graph independent of any agent or state:

#include "MengeCore/resources/Graph.h"

GraphPtr my_graph = loadGraph("/Path/To/Graph.txt");
draw_graph(my_graph);

In this option, the call to loadGraph() will parse the graph text (if it hasn't already been loaded), and return you an antiquated smart pointer to that graph. Note: This is the same graph that is used by any velocity component that referenced the same path. So, don't modify it unless you plan on messing things up. :)

Option 2: Grab the graph from the velocity component contained in a particular state.

State* state = ...;
VelComponent* vc = state->getVelComponent();
RoadMapVelComponent* rvc = dynamic_cast<const RoadMapVelComponent *>( vc );
assert(rvc != nullptr);
const GraphPtr my_graph = rvc->getRoadMap();

Drawing the roadmap

RoadMapVCContext::draw3DGL() shows how to extract the roadmap vertices and edges. In this function they are drawn directly to the OpenGL context.

Drawing the path on the roadmap

Drawing an agent's path requires the agent and the roadmap. For that, you'll actually need the full velocity component and not just the graph. The full example of how this is done is also in: RoadMapVCContext::draw3DGL()

Because a particular agent's path on a road map is stored in the VelocityComponent that belongs to the state that the agent is currently in, I'd recommend Option 2 above for accessing the roadmap.

MengeCrowdSim commented 5 years ago

Did that meet your needs? If I don't hear from you in the next little bit, I'll assumed you're content and close the issue.