/
face.py
330 lines (257 loc) · 8.39 KB
/
face.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
from compas.data import Data
from compas.geometry import Polygon
class SurfaceType(object):
"""Enumaration of surface types."""
PLANE = 0
CYLINDER = 1
CONE = 2
SPHERE = 3
TORUS = 4
BEZIER_SURFACE = 5
BSPLINE_SURFACE = 6
SURFACE_OF_REVOLUTION = 7
SURFACE_OF_EXTRUSTION = 8
OFFSET_SURFACE = 9
OTHER_SURFACE = 10
class BrepFace(Data):
"""An interface for a Brep Face.
Attributes
----------
area : float, read-only
Returns the area of this face's geometry.
centroid : :class:`compas.geometry.Point`, read-only
Returns the centroid of this face's geometry.
edges : list[:class:`compas.geometry.BrepEdge`], read-only
Returns a list of the edges comprising this face.
is_bspline : bool, read-only
Returns True if this face is a bspline, False otherwise.
is_cone : bool, read-only
Returns True if this face is a cone, False otherwise.
is_cylinder : bool, read-only
Returns True if this face is a cylinder, False otherwise.
is_plane : bool, read-only
Returns True if this face is a plane, False otherwise.
is_sphere : bool, read-only
Returns True if this face is a sphere, False otherwise.
is_torus : bool, read-only
Returns True if this face is a torus, False otherwise.
is_valid : bool, read-only
Return True if this face is valid, False otherwise.
loops : list[:class:`compas.geometry.BrepLoop`], read-only
Returns a list of the loops comprising this face.
native_face : Any
The underlying face object. Type is backend-dependent.
nurbssurface : :class:`compas.geometry.NurbsSurface`, read-only
Returns the geometry of this face as a NURBS surface.
surface : :class:`compas.geometry.Surface`, read-only
Returns the geometry of this face as a surface.
type : literal(SurfaceType), read-only
Returns the surface type of this face. One of: PLANE, CYLINDER, CONE, SPHERE, TORUS, BEZIER_SURFACE,
BSPLINE_SURFACE, SURFACE_OF_REVOLUTION, SURFACE_OF_EXTRUSTION, OFFSET_SURFACE, OTHER_SURFACE.
vertices : list[:class:`compas.geometry.BrepVertex`], read-only
Returns a list of the vertices comprising this face.
"""
# ==============================================================================
# Properties
# ==============================================================================
@property
def is_plane(self):
raise NotImplementedError
@property
def is_cylinder(self):
raise NotImplementedError
@property
def is_sphere(self):
raise NotImplementedError
@property
def is_torus(self):
raise NotImplementedError
@property
def is_cone(self):
raise NotImplementedError
@property
def is_bspline(self):
raise NotImplementedError
@property
def vertices(self):
raise NotImplementedError
@property
def edges(self):
raise NotImplementedError
@property
def loops(self):
raise NotImplementedError
@property
def surface(self):
raise NotImplementedError
@property
def native_face(self):
raise NotImplementedError
@property
def nurbssurface(self):
raise NotImplementedError
@property
def area(self):
raise NotImplementedError
@property
def centroid(self):
raise NotImplementedError
@property
def is_valid(self):
raise NotImplementedError
@property
def type(self):
raise NotImplementedError
# ==============================================================================
# Constructors
# ==============================================================================
@classmethod
def from_plane(cls, plane):
"""Construct a face from a plane geometry.
Parameters
----------
plane : :class:`compas.geometry.Plane`
Returns
-------
:class:`compas.geometry.BrepFace`
"""
raise NotImplementedError
@classmethod
def from_cylinder(cls):
"""Construct a face from a cylinder geometry.
Parameters
----------
cylinder : :class:`compas.geometry.Cylinder`
Returns
-------
:class:`compas.geometry.BrepFace`
"""
raise NotImplementedError
@classmethod
def from_cone(cls, cone):
"""Construct a face from a cone geometry.
Parameters
----------
cone : :class:`compas.geometry.Cone`
Returns
-------
:class:`compas.geometry.BrepFace`
"""
raise NotImplementedError
@classmethod
def from_sphere(cls, sphere):
"""Construct a face from a sphere geometry.
Parameters
----------
sphere : :class:`compas.geometry.Sphere`
Returns
-------
:class:`compas.geometry.BrepFace`
"""
raise NotImplementedError
@classmethod
def from_torus(cls, torus):
"""Construct a face from a torus geometry.
Parameters
----------
torus : :class:`compas.geometry.Torus`
Returns
-------
:class:`compas.geometry.BrepFace`
"""
raise NotImplementedError
@classmethod
def from_surface(cls, surface):
"""Construct a face from a surfaces geometry.
Parameters
----------
surface : :class:`compas.geometry.Surface`
Returns
-------
:class:`compas.geometry.BrepFace`
"""
raise NotImplementedError
# ==============================================================================
# Conversions
# ==============================================================================
def to_polygon(self):
"""Convert the face to a polygon without underlying geometry.
Returns
-------
:class:`~compas.geometry.Polygon`
"""
points = []
for vertex in self.loops[0].vertices:
points.append(vertex.point)
return Polygon(points)
# ==============================================================================
# Methods
# ==============================================================================
def adjacent_faces(self):
"""Returns a list of the faces adjacent to this face.
Returns
-------
list[:class:`compas.geometry.BrepFace`]
"""
raise NotImplementedError
def as_brep(self):
"""Returns a Brep representation of this face.
Returns
-------
:class:`compas.geometry.Brep`
"""
raise NotImplementedError
def add_loop(self, loop, *args, **kwargs):
"""Adds an inner loop to this face.
Parameters
----------
loop : :class:`compas.geometry.BrepLoop`
The loop to add
Notes
-----
Any additional arguments may be backend specific.
"""
raise NotImplementedError
def add_loops(self, loops, *args, **kwargs):
"""Adds several inner loops to this face.
Parameters
----------
loops : list[:class:`compas.geometry.BrepLoop`]
The loops to add.
Notes
-----
Any additional arguments may be backend specific.
"""
raise NotImplementedError
def try_get_nurbssurface(
self,
precision,
continuity_u,
continuity_v,
maxdegree_u,
maxdegree_v,
maxsegments_u,
maxsegments_v,
):
"""Returns the NURBS surface representation of this face. Or None if this cannot be done.
Parameters
----------
precision : float
The precision of the conversion.
continuity_u : int
The continuity of the surface in the u direction.
continuity_v : int
The continuity of the surface in the v direction.
maxdegree_u : int
The maximum degree of the surface in the u direction.
maxdegree_v : int
The maximum degree of the surface in the v direction.
maxsegments_u : int
The maximum number of segments in the u direction.
maxsegments_v : int
The maximum number of segments in the v direction.
Returns
-------
:class:`~compas.geometry.NurbsSurface` or None
"""
raise NotImplementedError