MengeCrowdSim / Menge

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

how to define obstacle set #117

Open xiangyuanhang opened 5 years ago

xiangyuanhang commented 5 years ago

I'm trying to change the obstacle set. I notice from the code that there are at least two means of defining obstacle set: a) using several vertex b) using a .nav file

And I have some questions. a) is there a convenient way to generate the coordinates of vertex instead of typing it one by one ? b) how to generate a .nav file? c) is there any other ways of defining obstacle set as I didn't find the documentation for that.

Thanks in advance!

curds01 commented 5 years ago

I agree; editing XML files is a nuisance. I almost never do that. I use a number of informal utilities to do the job. You can get access to them here (https://github.com/curds01/MengeUtils). These are currently all python 2 utilities (I need to upgrade them to python 3).

You have several options:

  1. If you have access to a 3D modeling package, you can model your world as objects. Then you can automatically slice that scene with a plane and that will generate the definition of an ObstacleSet.
  2. I have a utility for drawing obstacles by hand and then saving the obstacles out as an ObstacleSet.

Let me know which one you prefer and I can elaborate on that mechanism.

xiangyuanhang commented 5 years ago

Thanks for your answer. For the first option, which 3D modeling package should I install? I'm more interested in the first one. But the second one sounds easier to use(I don't know if it's true or not)

curds01 commented 5 years ago

For option 1, if you don't already have a modeling package that you are familiar with, it's probably not going to be a very good option. Essentially, you'd have to learn how to model. I find it useful because I'm familiar with the tools. And I generally model a visualization and simulation version of the environments I'm interested in. If you're interested in this route, you can download blender -- an open-source 3D package.

Option 2 is more accessible. The problem is that the tool is quite crude. You can't do precision (for example, putting a vertex at an exact location). And you'll have to do some tricks to make sure you're creating obstacles at an appropriate scale. But it should get you up and running -- it depends on how complex your simulation environment is and how precise it needs to be.

xiangyuanhang commented 5 years ago

In this case, I think I might start with the second one. So it is included in the utilities you provided above right? Could you please show me how to use it. Thank you very much!

curds01 commented 5 years ago

So, checkout the repo of utilities outlined above.

  1. Go to the directory you've checked it out into.
  2. Execute python roadmapBuilder.py (assuming you've got python 2.7 in your path and all the dependencies installed). You should get a window like this: image
  3. If you hold the 'h' key down, it will display context-sensitive information. image

You will want to go into the "ObstacleContext" to create/edit obstacles. But first, we're going to go into the AgentContext to create an agent to help define scale.

  1. Hit the 'a' key to enter the AgentContext.
  2. In the middle of the window, click the mouse. A very, very small agent will be created. Zoom in on the agent (using the mouse wheel).
  3. Hit escape to leave the agent context.
  4. Hit 'o' to enter the obstacle context.
  5. Hit the 'h' key to display the help for obstacles: image It should say "New Polygon" at the bottom and "ObstacleContext" at the top. Plan on using the 'h' key a lot. It'll explain the details.

Obstacle editing has two modes:

  1. Drawing obstacles (reach this by hitting the '1' key.)
  2. Edit existing obstacles (hit the '2' key). At the bottom of the screen it will tell you what mode you're in.

Drawing obstacles

  1. Every time you click a vertex will be placed and a polygon will be gradually constructed. A vertex will be yellow. Once you have two, an obstacle will be shown (as a red line). Once you have three or more you can see the whole polygon.
  2. A polygon will be colored red or blue, depending on whether agents should stay outside or inside the obstacle, respectively.
  3. To finish one obstacle and start another, right click.
  4. At any time hit "Ctrl+s" to save your obstacles to the disk. They will be written into the same directory as roadmapBuilder.py into a file called obstacles.xml. You can copy and paste the object definition into you scenario description.

This should get you started, I strongly suggest you experiment with the documented features (as shown when you hit the 'h' key).

xiangyuanhang commented 5 years ago

Thanks for your thorough answer which helps a lot. And the tool works really well! And I'm learning how to model 3D world using blender right now. If I'm not wrong, the utility you provided can slice the 3D world with a plane and generate a ObstacleSet, right? So what I have to do is to model a 3D world using blender and then use the utility you provided to slice it into a ObstacleSet, right?

curds01 commented 5 years ago

I'm glad it's working for you.

In Blender, after you've modeled your scene, export it as an .obj file (wavefront obj). Then you can pass it as input to the program ObjSlice.py. It has instructions for how to use it (python ObjSlice.py --help). It's pretty straightforward.

AdriannaGmz commented 5 years ago

hi! I'm also facing a similar situation in which I'm creating my own scenario with obstacles. so I have three questions:

  1. you mentioned that in the roadmapBuilder.py, the red and blue polygons indicate whether agent should be inside or outside... how to change it? i drew 5 polygons and they turned in each color respectively (first polygon -blue, second polygon - red, third polygon - blue, ..etc) how to turn them all into red so the agent doesn't enter anywhere to the obstacles?

2 - Before reading this post, I changed manually the vertices in the xml so I could have an octagon in the center. When menge_sim got executed, the agent could enter the octagon but then it couldn't leave! How should I understand this? or how to modify it so the agent can not access to the obstacles?

3- besides this Scene xml file, is there any other consideration to take into account as for the obstacles placement? what about the nav file?

Thank you very much for your kind attention in advanced!

curds01 commented 5 years ago
  1. Reversing the direction of obstacles:

    • Hit 'o' to enter obstacle mode.
    • Hit '2' to enter obstacle edit mode.
    • Hit 'p' to enter polygon edit mode.
    • Move the mouse over the obstacle (it highlights yellow)
    • Hit the 'r' key to reverse the winding.
    • Move the mouse -- color has reversed.
  2. Manually editing an xml file has to be done in conjunction with all the various components (are agent positions still valid? Is the roadmap still valid? etc.)

  3. You only have to worry about a .nav file if you're using the navigation map in a velocity component. Authoring a velocity component is quite complex.