@@ -142,12 +142,72 @@ Lists of vertices, edges, and faces have to be constructed explicitly.
142142[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, ..., 80]
143143
144144
145+ Vertex, Edge, Face Attributes
146+ =============================
147+
148+ Arbitrary data can be assigned to vertices, edges, and faces, as vertex/edge/face attributes, and to the overall mesh itself.
149+ To allow for serialisatin of the mesh and all the data associated with it, the data should be JSON serialisable.
150+ See :ref: `Mesh Serialisation ` for more information.
151+
152+ The functionality is demonstrated here using vertex attributes.
153+ The mechanism is exactly the same for edges and faces.
154+
155+ It is good practice to declare default values for the added data attributes.
156+
157+ >>> mesh = Mesh.from_meshgrid(dx = 10 , dy = 10 , nx = 10 , ny = 10 )
158+ >>> mesh.update_default_vertex_attributes(a = None , b = 0.0 , c = False )
159+
160+ Get the value of one attribute of one vertex.
161+
162+ >>> mesh.vertex_attribute(0 , ' a' )
163+ None
164+
165+ Get the value of multiple attributes of one vertex.
166+
167+ >>> mesh.vertex_attributes(0 , [' a' , ' b' ])
168+ (None, 0.0)
169+
170+ Get the value of one attribute of all vertices.
171+
172+ >>> mesh.vertices_attribute(' a' )
173+ [None, None, None, ... None]
174+
175+ Get the value of multiple attributes of all vertices.
176+
177+ >>> mesh.vertices_attributes([' b' , ' c' ])
178+ [(0.0, False), (0.0, False), (0.0, False), ..., (0.0, False)]
179+
180+ Similarly, for a selection of vertices.
181+
182+ >>> mesh.vertices_attribute(' b' , vertices = [0 , 1 , 2 , 3 ])
183+ [0.0, 0.0, 0.0, 0.0]
184+
185+ >>> mesh.vertices_attributes([' a' , ' c' ], vertices = [0 , 1 , 2 , 3 ])
186+ [(None, False), (None, False), (None, False), (None, False)]
187+
188+ Updating attributes is currently only possible one vertex at a time.
189+
190+ >>> mesh.vertex_attribute(0 , ' a' , (1.0 , 0.0 , 0.0 ))
191+
192+ >>> for vertex in mesh.vertices():
193+ ... if mesh.vertex_degree(vertex) == 2 :
194+ ... mesh.vertex_attribute(vertex, ' a' , (1.0 , 0.0 , 0.0 ))
195+ ...
196+
197+ Finally, note that the xyz coordinates of vertices can be accessed and modified using the same functions.
198+
199+ >>> mesh.vertex_attributes(0 , ' xyz' )
200+ (0.0, 0.0, 0.0)
201+ >>> mesh.vertices_attribute(' x' )
202+ [0.0, 1.0, 2.0, ..., 9.0]
203+
204+
145205Halfedge Data Structure
146206=======================
147207
148208The topology of a mesh is stored in a halfedge data structure.
149- In this data structure, vertices are connected to other vertices, and faces to other faces via edges.
150- An edge has at most two connected faces.
209+ In this data structure, vertices are connected to other vertices, and faces to other faces, via edges.
210+ An edge has two connected vertices, and at most two connected faces.
151211Each each is split into two halfedges, one for each of the connected faces.
152212If an edge has only one connected face, the edge is on the boundary.
153213
@@ -189,6 +249,39 @@ True
189249
190250.. figure :: /_images/userguide/basics.datastructures.meshes.meshgrid-column3.png
191251
252+
253+ Halfedge Cycles
254+ ---------------
255+
256+ The vertices of a face of the mesh are ordered in a continuous cycle.
257+ Every two consecutive vertices are connected by a halfedge of the face.
258+ Like the vertices, the halfedges of a face form a continuous cycle.
259+ In a valid halfedge mesh, all the cycle directions are consisten.
260+ By cycling the faces, each edge is traversed exactly twice,
261+ in opposite direction, except fo the edges on the boundary.
262+
263+ >>> for face in mesh.faces():
264+ ... for edge in mesh.face_halfedges(face):
265+ ... print (mesh.halfedge_face(edge) == face)
266+ ...
267+ True
268+ True
269+ ...
270+ True
271+
272+ .. figure :: /_images/userguide/basics.datastructures.meshes.cycles.png
273+
274+ Using a combination of the halfedge functions, it is possible to traverse the mesh in a number of ways.
275+
276+ * :meth: `compas.datastructures.Mesh.face_halfedges `
277+ * :meth: `compas.datastructures.Mesh.halfedge_face `
278+ * :meth: `compas.datastructures.Mesh.halfedge_before `
279+ * :meth: `compas.datastructures.Mesh.halfedge_after `
280+
281+
282+ Neighbours
283+ ----------
284+
192285>>> for i, nbr in enumerate (mesh.vertex_neighbors(23 , ordered = True )):
193286... print (i, nbr)
194287...
@@ -219,11 +312,13 @@ True
219312
220313.. figure :: /_images/userguide/basics.datastructures.meshes.face-neighbours.png
221314
222- >>> for edge in mesh.edge_loop((30 , 31 )):
315+
316+ Loops and Strips
317+ ----------------
318+
319+ >>> for edge in mesh.halfedge_loop((32 , 33 )):
223320... print (edge)
224321...
225- (30, 31)
226- (31, 32)
227322(32, 33)
228323(33, 34)
229324(34, 35)
@@ -232,6 +327,19 @@ True
232327(37, 38)
233328(38, 39)
234329
330+ >>> for edge in mesh.edge_loop((62 , 63 )):
331+ ... print (edge)
332+ ...
333+ (60, 61)
334+ (61, 62)
335+ (62, 63)
336+ (63, 64)
337+ (64, 65)
338+ (65, 66)
339+ (66, 67)
340+ (67, 68)
341+ (68, 69)
342+
235343.. figure :: /_images/userguide/basics.datastructures.meshes.edge-loop.png
236344
237345>>> for edge in mesh.edge_strip((20 , 30 )):
@@ -273,28 +381,6 @@ Mesh Geometry
273381* edge_direction
274382
275383
276- Data Attributes
277- ===============
278-
279- Additional data can be assigned to vertices, edges, and faces, as vertex/edge/face attributes, and to the overall mesh itself.
280-
281- * vertex_attribute
282- * edge_attribute
283- * face_attribute
284-
285- * vertex_attributes
286- * edge_attributes
287- * face_attributes
288-
289- * vertices_attribute
290- * edges_attribute
291- * faces_attribute
292-
293- * vertices_attributes
294- * edges_attributes
295- * faces_attributes
296-
297-
298384Filtering
299385=========
300386
0 commit comments