-
Notifications
You must be signed in to change notification settings - Fork 9
/
asset.py
194 lines (161 loc) · 6.78 KB
/
asset.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
"""SensorGrid and Sensor Schema"""
from pydantic import Field, constr, validator
from typing import List
from enum import Enum
from ..geometry import Mesh3D
from .._base import NoExtraBaseModel
from ._base import IDdRadianceBaseModel
import re
class _RadianceAsset(IDdRadianceBaseModel):
"""Hidden base class for all Radiance Assets."""
display_name: str = Field(
default=None,
description='Text string for a unique display name, used to set the default '
'file name that the radiance asset is written to within a radiance folder. '
'Must not contain spaces or special characters.'
)
@validator('display_name')
def valid_rad_string_display_name(cls, value):
"""Check that a string is valid for Radiance.
This method is modified from the honeybee-core.typing.valid_rad_string method.
"""
if value is not None:
try:
illegal_match = re.search(r'[^.A-Za-z0-9_-]', value)
except TypeError:
raise TypeError('display_name must be a text string. Got {}: {}.'.format(
type(value), value))
assert illegal_match is None, \
'Illegal character "{}" found in display_name'.format(illegal_match.group(0))
assert len(value) > 0, \
'Input display_name "{}" contains no characters.'.format(value)
return value
room_identifier: str = Field(
None,
regex=r'[A-Za-z0-9_-]',
min_length=1,
max_length=100,
description='Optional text string for the Room identifier to which this '
'object belongs. This will be used to narrow down the number of '
'aperture groups that have to be run with this sensor grid. If None, '
'the grid will be run with all aperture groups in the model.'
)
light_path: List[List[str]] = Field(
None,
description='Get or set a list of lists for the light path from the object to '
'the sky. Each sub-list contains identifiers of aperture groups through which '
'light passes. (eg. [["SouthWindow1"], ["static_apertures", "NorthWindow2"]]).'
'Setting this property will override any auto-calculation of the light '
'path from the model and room_identifier upon export to the simulation.'
)
class Sensor(NoExtraBaseModel):
"""A single Radiance of sensors."""
type: constr(regex='^Sensor$') = 'Sensor'
pos: List[float] = Field(
...,
description="Position of sensor in space as an array of (x, y, z) values.",
min_items=3,
max_items=3
)
dir: List[float] = Field(
...,
description="Direction of sensor as an array of (x, y, z) values.",
min_items=3,
max_items=3
)
class SensorGrid(_RadianceAsset):
"""A grid of sensors."""
type: constr(regex='^SensorGrid$') = 'SensorGrid'
sensors: List[Sensor] = Field(
...,
description='A list of sensors that belong to the grid.'
)
mesh: Mesh3D = Field(
None,
description='An optional Mesh3D that aligns with the sensors and can be '
'used for visualization of the grid. Note that the number of sensors in '
'the grid must match the number of faces or the number vertices within '
'the Mesh3D.'
)
class ViewType(str, Enum):
"""A single character for the view type (-vt)."""
perspective = 'v'
hemispherical_fisheye = 'h'
parallel = 'l'
cylindrical_panorama = 'c'
angular_fisheye = 'a'
planisphere = 's'
class View(_RadianceAsset):
"""A single Radiance of sensors."""
type: constr(regex='^View$') = 'View'
position: List[float] = Field(
...,
description='The view position (-vp) as an array of (x, y, z) values.'
'This is the focal point of a perspective view or the center of a '
'parallel projection.',
min_items=3,
max_items=3
)
direction: List[float] = Field(
...,
description='The view direction (-vd) as an array of (x, y, z) values.'
'The length of this vector indicates the focal distance as needed by '
'the pixel depth of field (-pd) in rpict.',
min_items=3,
max_items=3
)
up_vector: List[float] = Field(
...,
description='The view up (-vu) vector as an array of (x, y, z) values.',
min_items=3,
max_items=3
)
view_type: ViewType = ViewType.perspective
h_size: float = Field(
60,
description='A number for the horizontal field of view in degrees (for '
'all perspective projections including fisheye). For a parallel '
'projection, this is the view width in world coordinates.'
)
v_size: float = Field(
60,
description='A number for the vertical field of view in degrees (for '
'all perspective projections including fisheye). For a parallel '
'projection, this is the view width in world coordinates.'
)
shift: float = Field(
None,
description='The view shift (-vs). This is the amount the actual '
'image will be shifted to the right of the specified view. This '
'option is useful for generating skewed perspectives or rendering '
'an image a piece at a time. A value of 1 means that the rendered '
'image starts just to the right of the normal view. A value of -1 '
'would be to the left. Larger or fractional values are permitted '
'as well.'
)
lift: float = Field(
None,
description='The view lift (-vl). This is the amount the actual '
'image will be lifted up from the specified view. This '
'option is useful for generating skewed perspectives or rendering '
'an image a piece at a time. A value of 1 means that the rendered '
'image starts just to the right of the normal view. A value of -1 '
'would be to the left. Larger or fractional values are permitted '
'as well.'
)
fore_clip: float = Field(
None,
description='View fore clip (-vo) at a distance from the view point.'
'The plane will be perpendicular to the view direction for perspective '
'and parallel view types. For fisheye view types, the clipping plane is '
'actually a clipping sphere, centered on the view point with fore_clip radius. '
'Objects in front of this imaginary surface will not be visible.'
)
aft_clip: float = Field(
None,
description='View aft clip (-va) at a distance from the view point.'
'Like the view fore plane, it will be perpendicular to the view '
'direction for perspective and parallel view types. For fisheye '
'view types, the clipping plane is actually a clipping sphere, '
'centered on the view point with radius val.'
)