local.md 3.88 KB
Newer Older
Hui Wang's avatar
Hui Wang committed
1
2
[[Home]](../index) [[Mesh Edit]](../meshedit/overview) [[Path Tracer]](../pathtracer/overview) [[Animation]](../animation/overview)

TheNumbat's avatar
TheNumbat committed
3
---
Hui Wang's avatar
Hui Wang committed
4

TheNumbat's avatar
TheNumbat committed
5
6
7
8
9
10
11
12
13
14
15
16
17
18

# Local Mesh Operations

Many of the actions that need to be implemented in the MeshEdit mode are local mesh operations (like edge collapse, face bevel, etc.).

A good recipe for ensuring that all pointers are still valid after a local remeshing operation is:

1.  Draw a picture of all the elements (vertices, edges, faces, halfedges) that will be needed from the original mesh, and all the elements that should appear in the modified mesh.
2.  Allocate any new elements that are needed in the modified mesh, but do not appear in the original mesh.
3.  For every element in the "modified" picture, set **all** of its pointers -- even if they didn't change. For instance, for each halfedge, make sure to set `next`, `twin`, `vertex`, `edge`, and `face` to the correct values in the new (modified) picture. For each vertex, make sure to set its `halfedge` pointer. Etc. A convenience method `Halfedge::set_neighbors()` has been created for this purpose.
4.  Deallocate any elements that are no longer used in the modified mesh, which can be done by calling `Halfedge_Mesh::erase()`.

The reason for setting all the pointers (and not just the ones that changed) is that it is very easy to miss a pointer, causing your code to crash.

allai5's avatar
allai5 committed
19
### Interface with global mesh operations
TheNumbat's avatar
TheNumbat committed
20

allai5's avatar
allai5 committed
21
To facilitate user interaction, as well as global mesh processing operations (described below), local mesh operations should return the following values when possible. However, should it happen that the specified values are not available, or that the operation should not work on the given input, we need a way to signify the failure case. To do so, each local operation actually returns a ``std::optional`` value parameterized on the type of element it returns. For example, ``Halfedge_Mesh::erase_vertex`` returns a ``std::optional<Halfedge_Mesh::Face>``.  An ``optional`` can hold a value of the specified type, or, similarly to a pointer, a null value (``std::nullopt``). See ``student/meshedit.cpp`` for specific examples.
TheNumbat's avatar
TheNumbat committed
22

allai5's avatar
allai5 committed
23
Also, remember that in any case, _the program should not crash!_ So for instance, you should never return a pointer to an element that was deleted.
TheNumbat's avatar
TheNumbat committed
24

Hui Wang's avatar
Hui Wang committed
25
See the [User Guide](../guide/model) for demonstrations of each local operation.
TheNumbat's avatar
TheNumbat committed
26

TheNumbat's avatar
TheNumbat committed
27
28
*   `Halfedge_Mesh::flip_edge` - should return the edge that was flipped

Hui Wang's avatar
Hui Wang committed
29
![](./local/flip_edge.svg)
TheNumbat's avatar
TheNumbat committed
30
31
32

*   `Halfedge_Mesh::split_edge` - should return the inserted vertex

Hui Wang's avatar
Hui Wang committed
33
![](./local/split_edge.svg)
TheNumbat's avatar
TheNumbat committed
34

Sanjay Salem's avatar
Sanjay Salem committed
35
36
*   `Halfedge_Mesh::bisect_edge` - should bisect the edge and return the inserted vertex

Hui Wang's avatar
Hui Wang committed
37
![](./local/bisect_edge.svg)
Sanjay Salem's avatar
Sanjay Salem committed
38

TheNumbat's avatar
TheNumbat committed
39
40
*   `Halfedge_Mesh::collapse_edge` - should return the new vertex, corresponding to the collapsed edge

Hui Wang's avatar
Hui Wang committed
41
![](./local/collapse_edge.svg)
TheNumbat's avatar
TheNumbat committed
42
43
44

*   `Halfedge_Mesh::collapse_face` - should return the new vertex, corresponding to the collapsed face

Hui Wang's avatar
Hui Wang committed
45
![](./local/collapse_face.svg)
TheNumbat's avatar
TheNumbat committed
46

Sanjay Salem's avatar
Sanjay Salem committed
47
48
*   `Halfedge_Mesh::inset_vertex` - should return the newly inserted vertex

Hui Wang's avatar
Hui Wang committed
49
![](./local/inset_vertex.svg)
Sanjay Salem's avatar
Sanjay Salem committed
50

TheNumbat's avatar
TheNumbat committed
51
52
*   `Halfedge_Mesh::erase_vertex` - should return the new face, corresponding to the faces originally containing the vertex

Hui Wang's avatar
Hui Wang committed
53
![](./local/erase_vertex.svg)
TheNumbat's avatar
TheNumbat committed
54
55
56

*   `Halfedge_Mesh::erase_edge` - should return the new face, corresponding to the faces originally containing the edge

Hui Wang's avatar
Hui Wang committed
57
![](./local/erase_edge.svg)
TheNumbat's avatar
TheNumbat committed
58
59
60

*   `Halfedge_Mesh::bevel_vertex` - should return the new face, corresponding to the beveled vertex

Hui Wang's avatar
Hui Wang committed
61
![](./local/bevel_vertex.svg)
TheNumbat's avatar
TheNumbat committed
62
63
64

*   `Halfedge_Mesh::bevel_edge` - should return the new face, corresponding to the beveled edge

Hui Wang's avatar
Hui Wang committed
65
![](./local/bevel_edge.svg)
TheNumbat's avatar
TheNumbat committed
66

Sanjay Salem's avatar
Sanjay Salem committed
67
*   `Halfedge_Mesh::bevel_face` / `Halfedge_Mesh::extrude_face` / `Halfedge_Mesh::inset_face` - should return the new, inset face
TheNumbat's avatar
TheNumbat committed
68

Hui Wang's avatar
Hui Wang committed
69
![](./local/bevel_face.svg)
TheNumbat's avatar
TheNumbat committed
70

Sanjay Salem's avatar
Sanjay Salem committed
71
72
*   `Halfedge_Mesh::extrude_vertex` - should return the new vertex

Hui Wang's avatar
Hui Wang committed
73
![](./local/extrude_vertex.svg)