forked from DLR-RM/BlenderProc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPath.py
43 lines (29 loc) · 1018 Bytes
/
Path.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from glob import glob
from random import choice
from src.main.Provider import Provider
from src.utility.Utility import Utility
class Path(Provider):
""" Samples a path to one of the files in folder defined by a path.
Example 1: return a path to a random .obj file in the defined folder.
{
"provider": "sampler.Path",
"path": "/home/path/to/folder/*.obj"
}
**Configuration**:
.. csv-table::
:header: "Parameter", "Description"
"path", "A path to a folder containing files. Type: string."
"""
def __init__(self, config):
Provider.__init__(self, config)
def run(self):
""" Samples a path to an object.
:return: A path to object. Type: string.
"""
# get path to folder
path = Utility.resolve_path(self.config.get_string("path"))
# get list of paths
paths = glob(path)
# chose a random one
chosen_path = choice(paths)
return chosen_path