-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Python example on generating random obstacle maps
- Loading branch information
1 parent
345f198
commit 8f1f01b
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import numpy as np | ||
import pywavemap as wave | ||
|
||
# Create an empty map | ||
user_home = os.path.expanduser('~') | ||
your_map = wave.Map.create({ | ||
"type": "hashed_chunked_wavelet_octree", | ||
"min_cell_width": { | ||
"meters": 0.1 | ||
} | ||
}) | ||
|
||
# Create a large box of free space | ||
map_aabb = wave.AABB(min=np.array([-50.0, -50.0, -10.0]), | ||
max=np.array([50.0, 50.0, 10.0])) | ||
wave.edit.sum(your_map, map_aabb, -0.05) | ||
|
||
# Add random obstacles and cutouts | ||
num_obstacles = 1000 | ||
for idx in range(num_obstacles): | ||
random_center = np.random.rand(3) | ||
random_center -= 0.5 | ||
random_center *= 2.0 | ||
random_center *= np.array([44.0, 44.0, 4.0]) | ||
update = float(np.random.rand(1)[0] * 0.2) | ||
if np.random.rand(1)[0] < 0.7: | ||
random_radius = float(5.0 * np.random.rand(1)[0]) | ||
sphere = wave.Sphere(center=random_center, radius=random_radius) | ||
wave.edit.sum(your_map, sphere, update) | ||
else: | ||
random_width = 5.0 * np.random.rand(3) | ||
box = wave.AABB(min=random_center - random_width, | ||
max=random_center + random_width) | ||
wave.edit.sum(your_map, box, update) | ||
if idx % 20: | ||
your_map.threshold() | ||
|
||
# Trim off any excess parts | ||
wave.edit.crop(your_map, map_aabb) | ||
your_map.prune() | ||
|
||
# Save the map | ||
output_map_path = os.path.join(user_home, "random_map.wvmp") | ||
your_map.store(output_map_path) |