E2. Data Structures
Task: extend edge_strip
method
edge_strip
methodIn this exercise, we will look into Mesh.edge_strip(edge)
. The current method only works for quad meshes, where all the mesh faces have four vertices. This exercise aims at extending this algorithm for general n-polygon meshes, where faces have an even number of vertices, e.g. Rectangle, hexagon, octagon, etc.
edge_strip
and halfedge_strip
source code
edge_strip
and halfedge_strip
source codeFirstly let's read the source code of edge_strip
and halfedge_strip
. There are a few ways to navigate to the source code.
Search
edge_strip
in theApi Reference,
then click[source]
Open the COMPAS folder in VS code. Go to
Edit > Find in Files
, or use shortcutctrl+shift+F
(Windows) orCmd+shift+F
(Mac). Searchedge_strip
.
In your VS code, hover your mouse over
edge_strip
, a preview of the declaration will appear. Right-click onedge_strip
and clickgo to Definition
orCtrl+Click
.
Now let's read the source code of edge_strip
.
What the algorithm does is that:
Given a start edge
(u, v)
;Find the face that
(u, v)
belongs to;
3. Find the half edges on the face; find the half-edge that's on the same strip of the start edge;
4. Find the half-edge pointing in opposite direction; This edge is the new start edge (u, v)
;
5. Repeat step 1 to step 4 until the half-edge is on the boundary, where the face that the half-edge belongs to doesn't exist;
6. Flip the edge directions of all the half-edges that have been found so far. Flipping the directions make sure that all the edges found on the strip will point in the same direction; find the pair half-edge of the initial start edge (u, v)
; repeat step 1 to step 4 until the half-edge is on the boundary.
halfedge_strip
finds half-edges that are in the same orientation as the start half-edge (u, v)
, which corresponds to step 1 to step 5 of edge_strip
.
Quad Topology
ex2_quad.py provides you the script to find edge strips in a quad mesh using the current Mesh.mesh_strip
method. A random edge "start"
is chosen from the quad mesh, which is shown in red. All the edges on the strip are shown in green. Mesh.edge_strip(start)
finds edges that are in the orientation as the "start"
edge. Thus, looping through all the edges, we can find the faces where the edges belong, except when the edge is on the boundary. The edge strip is colored red.
Extend the edge_strip
method
edge_strip
methodNow you can extend the algorithm so that it works for polygon faces with even numbers of vertices. You can write your own edge_strip
function in your script and test it on the hexagon mesh.
Bonus Task: Checkered pattern
In this bonus task, you need to develop the checkered pattern on a quad mesh starting from a random face. Checkered pattern contains two colors where a single checker is surrounded on all four sides by a checker of a different color. You can set different attributes to the mesh faces to differ the checkers.
The following pictures are the random face where you can start from, and the checked pattern that you are expected to achieve.
Hint
The information of the faces can be saved as a face_attribute
. For example, is_colored: True / False
for faces on the checked pattern.
We should also try to find a way to check every face only one using the mesh data-structure. Here is one possible solution:
Start from a random face 5, set face_attribute:
is_colored: True
. Create an empty listto_check
, and add face 5 into it.Check the neighbouring faces of face 5. If the face_attribute of face 5:
is_colored
isTrue
, set the face_attribute of all the neighbouring facesis_colored: False
. Vice versa. Now face 5 is checked and should be deleted fromto_check
list. The neighbouring faces are added to theto_check
list.
3. Pick the last element in the to_check
list, face 6 in this case.
4. Check the neighbouring faces of face 6. Set face_attribute based on the attribute of face 6. Delete face 6 from the to_check
list, and added the faces that have not been checked (face 10, 7, 2) in to the to_check
list. Face 6 has been checked, which you can tell by the fact that it already has a face_attribute. Thus, face 6 doesn't need to be added to the to_check
list again.
5. Repeat step 1-4 until the to_check
list is empty, which means all faces on the mesh are checked.
You can look up depth_first_search
as a reference.
Code
Last updated