forked from DLR-RM/BlenderProc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathColor.py
57 lines (43 loc) · 1.69 KB
/
Color.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import random
import mathutils
from src.main.Provider import Provider
class Color(Provider):
""" Uniformly samples a 4-dimensional RGBA vector.
Example 1: Sample a RGBA grey color value using [min, max] range.
{
"provider": "sampler.Color",
"min": [0, 0, 0, 1],
"max": [1, 1, 1, 1],
"grey": True,
}
**Configuration**:
.. csv-table::
:header: "Parameter", "Description"
"min", "A list of four values, describing the minimum values of R, G, B and A components. "
"Type: list. Range: [0; 1]."
"max", "A list of four values, describing the maximum values of R, G, B and A components. "
"Type: list. Range: [0; 1]."
"grey", "Sample grey values only. Type: bool. Default: False."
"""
def __init__(self, config):
Provider.__init__(self, config)
def run(self):
""" Samples a RGBA vector uniformly for each component.
:return: RGBA vector. Type: mathutils.Vector
"""
# minimum values vector
min = self.config.get_vector4d("min")
# maximum values vector
max = self.config.get_vector4d("max")
# sample only grey values
grey = self.config.get_bool("grey", False)
color = mathutils.Vector([0, 0, 0, 0])
for i in range(4):
if 0 <= min[i] <= 1 and 0 <= max[i] <= 1:
if grey and 0 < i < 3:
color[i] = color[i-1]
else:
color[i] = random.uniform(min[i], max[i])
else:
raise RuntimeError("min and max vectors must be composed of values in [0, 1] range!")
return color