Skip to content

Commit

Permalink
Added an option to turn off the restricted navigation that only allow…
Browse files Browse the repository at this point in the history
…s the agent to move to another viewpoint if it's in the field of view
  • Loading branch information
peteanderson80 committed Dec 5, 2019
1 parent 25c25d3 commit 5331d70
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ sim.newEpisode(['2t7WUuJeko7'], ['1e6b606b44df4a6086c0f97e826d4d15'], [0], [0])

Heading is defined from the y-axis with the z-axis up (turning right is positive). Camera elevation is measured from the horizon defined by the x-y plane (up is positive). There is also a `newRandomEpisode` function which only requires a list of scanIds, and randomly determines a viewpoint and heading (with zero camera elevation).

Interaction with the simulator is through the `makeAction` function, which takes as arguments a list of navigable location indices, a list of heading changes (in radians) and a list of elevation changes (in radians). The navigable location indices select which nearby camera viewpoint the agent should move to. *Only camera viewpoints that are within the agent's current field of view are considered navigable* (i.e., the agent can't move backwards, for example). For agent `n`, navigable locations are given by `getState()[n].navigableLocations`. Index 0 always contains the current viewpoint (i.e., the agent always has the option to stay in the same place). As the navigation graph is irregular, the remaining viewpoints are sorted by their angular distance from the centre of the image, so index 1 (if available) will approximate moving directly forward. For example, to turn 30 degrees left without moving (keeping camera elevation unchanged):
Interaction with the simulator is through the `makeAction` function, which takes as arguments a list of navigable location indices, a list of heading changes (in radians) and a list of elevation changes (in radians). The navigable location indices select which nearby camera viewpoint the agent should move to. *By default, only camera viewpoints that are within the agent's current field of view are considered navigable, unless restricted navigation is turned off* (i.e., the agent can't move backwards, for example). For agent `n`, navigable locations are given by `getState()[n].navigableLocations`. Index 0 always contains the current viewpoint (i.e., the agent always has the option to stay in the same place). As the navigation graph is irregular, the remaining viewpoints are sorted by their angular distance from the centre of the image, so index 1 (if available) will approximate moving directly forward. For example, to turn 30 degrees left without moving (keeping camera elevation unchanged):
```
sim.makeAction([0], [-0.523599], [0])
```
Expand Down
10 changes: 10 additions & 0 deletions include/MatterSim.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ namespace mattersim {
*/
void setDiscretizedViewingAngles(bool value);

/**
* Enable or disable restricted navigation. When enabled, the navigable locations
* that the agent can move to are restricted to nearby viewpoints that are in
* the camera field of view given the current heading. When disabled, the agent
* can always move to any adjacent viewpoint in the navigation graph.
* Default is true (enabled).
*/
void setRestrictedNavigation(bool value);

/**
* Enable or disable preloading of images from disk to CPU memory. Default is false (disabled).
* Enabled is better for training models, but will cause a delay when starting the simulator.
Expand Down Expand Up @@ -247,6 +256,7 @@ namespace mattersim {
bool initialized;
bool renderingEnabled;
bool discretizeViews;
bool restrictedNavigation;
bool preloadImages;
bool renderDepth;
int width;
Expand Down
9 changes: 8 additions & 1 deletion src/lib/MatterSim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Simulator::Simulator() :width(320),
initialized(false),
renderingEnabled(true),
discretizeViews(false),
restrictedNavigation(true),
preloadImages(false),
renderDepth(false),
batchSize(1),
Expand Down Expand Up @@ -120,6 +121,12 @@ void Simulator::setDiscretizedViewingAngles(bool value) {
}
}

void Simulator::setRestrictedNavigation(bool value) {
if (!initialized) {
restrictedNavigation = value;
}
}

void Simulator::setPreloadingEnabled(bool value) {
if (!initialized) {
preloadImages = value;
Expand Down Expand Up @@ -342,7 +349,7 @@ void Simulator::populateNavigable() {
double rel_elevation = atan2(tar_z, glm::length(target_dir)) - state->elevation;
glm::vec3 normed_target_dir = glm::normalize(target_dir);
double cos_angle = glm::dot(normed_target_dir, camera_horizon_dir);
if (cos_angle >= cos_half_hfov) {
if (!restrictedNavigation || (cos_angle >= cos_half_hfov)) {
glm::vec3 pos = navGraph.cameraPosition(state->scanId,i);
double rel_heading = atan2( target_dir.x*camera_horizon_dir.y - target_dir.y*camera_horizon_dir.x,
target_dir.x*camera_horizon_dir.x + target_dir.y*camera_horizon_dir.y );
Expand Down
1 change: 1 addition & 0 deletions src/lib_python/MatterSimPython.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ PYBIND11_MODULE(MatterSim, m) {
.def("setCameraVFOV", &Simulator::setCameraVFOV)
.def("setElevationLimits", &Simulator::setElevationLimits)
.def("setDiscretizedViewingAngles", &Simulator::setDiscretizedViewingAngles)
.def("setRestrictedNavigation", &Simulator::setRestrictedNavigation)
.def("setPreloadingEnabled", &Simulator::setPreloadingEnabled)
.def("setDepthEnabled", &Simulator::setDepthEnabled)
.def("setBatchSize", &Simulator::setBatchSize)
Expand Down

0 comments on commit 5331d70

Please sign in to comment.