Cleanup: commas at the end of enums
[blender.git] / source / blender / bmesh / operators / bmo_hull.c
index fb99c9777d0f294387f081950e0c791994522567..259bb0f5a9c24bdca0553901478a4883a80c3179 100644 (file)
 /* Internal operator flags */
 typedef enum {
        HULL_FLAG_INPUT =           (1 << 0),
-       
+
        HULL_FLAG_INTERIOR_ELE =    (1 << 1),
        HULL_FLAG_OUTPUT_GEOM =     (1 << 2),
-       
+
        HULL_FLAG_DEL =             (1 << 3),
-       HULL_FLAG_HOLE =            (1 << 4)
+       HULL_FLAG_HOLE =            (1 << 4),
 } HullFlags;
 
 /* Store hull triangles separate from BMesh faces until the end; this
@@ -67,8 +67,9 @@ typedef struct HullTriangle {
 
 /*************************** Hull Triangles ***************************/
 
-static void hull_add_triangle(BMesh *bm, GSet *hull_triangles, BLI_mempool *pool,
-                              BMVert *v1, BMVert *v2, BMVert *v3)
+static void hull_add_triangle(
+        BMesh *bm, GSet *hull_triangles, BLI_mempool *pool,
+        BMVert *v1, BMVert *v2, BMVert *v3)
 {
        HullTriangle *t;
        int i;
@@ -80,7 +81,7 @@ static void hull_add_triangle(BMesh *bm, GSet *hull_triangles, BLI_mempool *pool
 
        /* Mark triangles vertices as not interior */
        for (i = 0; i < 3; i++)
-               BMO_elem_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE);
+               BMO_vert_flag_disable(bm, t->v[i], HULL_FLAG_INTERIOR_ELE);
 
        BLI_gset_insert(hull_triangles, t);
        normal_tri_v3(t->no, v1->co, v2->co, v3->co);
@@ -92,8 +93,8 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e)
        BMFace *f;
 
        BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
-               if (BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT) ||
-                   !BMO_elem_flag_test(bm, f, HULL_FLAG_OUTPUT_GEOM))
+               if (BMO_face_flag_test(bm, f, HULL_FLAG_INPUT) ||
+                   BMO_face_flag_test(bm, f, HULL_FLAG_OUTPUT_GEOM) == false)
                {
                        return f;
                }
@@ -105,7 +106,7 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e)
 static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
 {
        GSetIterator iter;
-       
+
        GSET_ITER (iter, hull_triangles) {
                HullTriangle *t = BLI_gsetIterator_getKey(&iter);
                int i;
@@ -118,14 +119,15 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
                        };
                        BMFace *f, *example = NULL;
 
-                       if (BM_face_exists(t->v, 3, &f)) {
+                       f = BM_face_exists(t->v, 3);
+                       if (f != NULL) {
                                /* If the operator is run with "use_existing_faces"
                                 * disabled, but an output face in the hull is the
                                 * same as a face in the existing mesh, it should not
                                 * be marked as unused or interior. */
-                               BMO_elem_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM);
-                               BMO_elem_flag_disable(bm, f, HULL_FLAG_HOLE);
-                               BMO_elem_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE);
+                               BMO_face_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM);
+                               BMO_face_flag_disable(bm, f, HULL_FLAG_HOLE);
+                               BMO_face_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE);
                        }
                        else {
                                /* Look for an adjacent face that existed before the hull */
@@ -139,12 +141,12 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
                                BM_face_copy_shared(bm, f, NULL, NULL);
                        }
                        /* Mark face for 'geom.out' slot and select */
-                       BMO_elem_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM);
+                       BMO_face_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM);
                        BM_face_select_set(bm, f, true);
 
                        /* Mark edges for 'geom.out' slot */
                        for (i = 0; i < 3; i++) {
-                               BMO_elem_flag_enable(bm, edges[i], HULL_FLAG_OUTPUT_GEOM);
+                               BMO_edge_flag_enable(bm, edges[i], HULL_FLAG_OUTPUT_GEOM);
                        }
                }
                else {
@@ -153,17 +155,17 @@ static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
                                const int next = (i == 2 ? 0 : i + 1);
                                BMEdge *e = BM_edge_exists(t->v[i], t->v[next]);
                                if (e &&
-                                   BMO_elem_flag_test(bm, e, HULL_FLAG_INPUT) &&
-                                   !BMO_elem_flag_test(bm, e, HULL_FLAG_HOLE))
+                                   BMO_edge_flag_test(bm, e, HULL_FLAG_INPUT) &&
+                                   !BMO_edge_flag_test(bm, e, HULL_FLAG_HOLE))
                                {
-                                       BMO_elem_flag_enable(bm, e, HULL_FLAG_OUTPUT_GEOM);
+                                       BMO_edge_flag_enable(bm, e, HULL_FLAG_OUTPUT_GEOM);
                                }
                        }
                }
 
                /* Mark verts for 'geom.out' slot */
                for (i = 0; i < 3; i++) {
-                       BMO_elem_flag_enable(bm, t->v[i], HULL_FLAG_OUTPUT_GEOM);
+                       BMO_vert_flag_enable(bm, t->v[i], HULL_FLAG_OUTPUT_GEOM);
                }
        }
 }
@@ -189,8 +191,9 @@ static LinkData *final_edges_find_link(ListBase *adj, BMVert *v)
        return NULL;
 }
 
-static int hull_final_edges_lookup(HullFinalEdges *final_edges,
-                                   BMVert *v1, BMVert *v2)
+static int hull_final_edges_lookup(
+        HullFinalEdges *final_edges,
+        BMVert *v1, BMVert *v2)
 {
        ListBase *adj;
 
@@ -210,7 +213,7 @@ static HullFinalEdges *hull_final_edges(GSet *hull_triangles)
 {
        HullFinalEdges *final_edges;
        GSetIterator iter;
-       
+
        final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges");
        final_edges->edges = BLI_ghash_ptr_new("final edges ghash");
        final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 0, 128, BLI_MEMPOOL_NOP);
@@ -259,8 +262,9 @@ static void hull_final_edges_free(HullFinalEdges *final_edges)
 
 /**************************** Final Output ****************************/
 
-static void hull_remove_overlapping(BMesh *bm, GSet *hull_triangles,
-                                    HullFinalEdges *final_edges)
+static void hull_remove_overlapping(
+        BMesh *bm, GSet *hull_triangles,
+        HullFinalEdges *final_edges)
 {
        GSetIterator hull_iter;
 
@@ -282,22 +286,23 @@ static void hull_remove_overlapping(BMesh *bm, GSet *hull_triangles,
                                        break;
                                }
                        }
-                       
+
                        /* Note: can't change ghash while iterating, so mark
                         * with 'skip' flag rather than deleting triangles */
                        if (BM_vert_in_face(t->v[1], f) &&
                            BM_vert_in_face(t->v[2], f) && f_on_hull)
                        {
                                t->skip = true;
-                               BMO_elem_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE);
-                               BMO_elem_flag_enable(bm, f, HULL_FLAG_HOLE);
+                               BMO_face_flag_disable(bm, f, HULL_FLAG_INTERIOR_ELE);
+                               BMO_face_flag_enable(bm, f, HULL_FLAG_HOLE);
                        }
                }
        }
 }
 
-static void hull_mark_interior_elements(BMesh *bm, BMOperator *op,
-                                        HullFinalEdges *final_edges)
+static void hull_mark_interior_elements(
+        BMesh *bm, BMOperator *op,
+        HullFinalEdges *final_edges)
 {
        BMEdge *e;
        BMFace *f;
@@ -306,13 +311,13 @@ static void hull_mark_interior_elements(BMesh *bm, BMOperator *op,
        /* Check for interior edges too */
        BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) {
                if (!hull_final_edges_lookup(final_edges, e->v1, e->v2))
-                       BMO_elem_flag_enable(bm, e, HULL_FLAG_INTERIOR_ELE);
+                       BMO_edge_flag_enable(bm, e, HULL_FLAG_INTERIOR_ELE);
        }
 
        /* Mark all input faces as interior, some may be unmarked in
         * hull_remove_overlapping() */
        BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) {
-               BMO_elem_flag_enable(bm, f, HULL_FLAG_INTERIOR_ELE);
+               BMO_face_flag_enable(bm, f, HULL_FLAG_INTERIOR_ELE);
        }
 }
 
@@ -329,47 +334,50 @@ static void hull_tag_unused(BMesh *bm, BMOperator *op)
         * the hull), but that aren't also used by elements outside the
         * input set */
        BMO_ITER (v, &oiter, op->slots_in, "input", BM_VERT) {
-               if (BMO_elem_flag_test(bm, v, HULL_FLAG_INTERIOR_ELE)) {
+               if (BMO_vert_flag_test(bm, v, HULL_FLAG_INTERIOR_ELE)) {
                        bool del = true;
-               
+
                        BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) {
-                               if (!BMO_elem_flag_test(bm, e, HULL_FLAG_INPUT)) {
+                               if (!BMO_edge_flag_test(bm, e, HULL_FLAG_INPUT)) {
                                        del = false;
                                        break;
                                }
                        }
 
                        BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) {
-                               if (!BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT)) {
+                               if (!BMO_face_flag_test(bm, f, HULL_FLAG_INPUT)) {
                                        del = false;
                                        break;
                                }
                        }
 
-                       if (del)
-                               BMO_elem_flag_enable(bm, v, HULL_FLAG_DEL);
+                       if (del) {
+                               BMO_vert_flag_enable(bm, v, HULL_FLAG_DEL);
+                       }
                }
        }
 
        BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) {
-               if (BMO_elem_flag_test(bm, e, HULL_FLAG_INTERIOR_ELE)) {
+               if (BMO_edge_flag_test(bm, e, HULL_FLAG_INTERIOR_ELE)) {
                        bool del = true;
 
                        BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
-                               if (!BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT)) {
+                               if (!BMO_face_flag_test(bm, f, HULL_FLAG_INPUT)) {
                                        del = false;
                                        break;
                                }
                        }
 
-                       if (del)
-                               BMO_elem_flag_enable(bm, e, HULL_FLAG_DEL);
+                       if (del) {
+                               BMO_edge_flag_enable(bm, e, HULL_FLAG_DEL);
+                       }
                }
        }
 
        BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) {
-               if (BMO_elem_flag_test(bm, f, HULL_FLAG_INTERIOR_ELE))
-                       BMO_elem_flag_enable(bm, f, HULL_FLAG_DEL);
+               if (BMO_face_flag_test(bm, f, HULL_FLAG_INTERIOR_ELE)) {
+                       BMO_face_flag_enable(bm, f, HULL_FLAG_DEL);
+               }
        }
 }
 
@@ -383,10 +391,10 @@ static void hull_tag_holes(BMesh *bm, BMOperator *op)
        /* Unmark any hole faces if they are isolated or part of a
         * border */
        BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) {
-               if (BMO_elem_flag_test(bm, f, HULL_FLAG_HOLE)) {
+               if (BMO_face_flag_test(bm, f, HULL_FLAG_HOLE)) {
                        BM_ITER_ELEM (e, &iter, f, BM_EDGES_OF_FACE) {
                                if (BM_edge_is_boundary(e)) {
-                                       BMO_elem_flag_disable(bm, f, HULL_FLAG_HOLE);
+                                       BMO_face_flag_disable(bm, f, HULL_FLAG_HOLE);
                                        break;
                                }
                        }
@@ -398,17 +406,17 @@ static void hull_tag_holes(BMesh *bm, BMOperator *op)
        BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) {
                bool hole = true;
                bool any_faces = false;
-               
+
                BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
                        any_faces = true;
-                       if (!BMO_elem_flag_test(bm, f, HULL_FLAG_HOLE)) {
+                       if (!BMO_face_flag_test(bm, f, HULL_FLAG_HOLE)) {
                                hole = false;
                                break;
                        }
                }
 
                if (hole && any_faces)
-                       BMO_elem_flag_enable(bm, e, HULL_FLAG_HOLE);
+                       BMO_edge_flag_enable(bm, e, HULL_FLAG_HOLE);
        }
 }
 
@@ -425,8 +433,9 @@ static int hull_input_vert_count(BMOperator *op)
        return count;
 }
 
-static BMVert **hull_input_verts_copy(BMOperator *op,
-                                      const int num_input_verts)
+static BMVert **hull_input_verts_copy(
+        BMOperator *op,
+        const int num_input_verts)
 {
        BMOIter oiter;
        BMVert *v;
@@ -441,8 +450,9 @@ static BMVert **hull_input_verts_copy(BMOperator *op,
        return input_verts;
 }
 
-static float (*hull_verts_for_bullet(BMVert **input_verts,
-                                     const int num_input_verts))[3]
+static float (*hull_verts_for_bullet(
+        BMVert **input_verts,
+        const int num_input_verts))[3]
 {
        float (*coords)[3] = MEM_callocN(sizeof(*coords) * num_input_verts, __func__);
        int i;
@@ -454,9 +464,10 @@ static float (*hull_verts_for_bullet(BMVert **input_verts,
        return coords;
 }
 
-static BMVert **hull_verts_from_bullet(plConvexHull hull,
-                                       BMVert **input_verts,
-                                       const int num_input_verts)
+static BMVert **hull_verts_from_bullet(
+        plConvexHull hull,
+        BMVert **input_verts,
+        const int num_input_verts)
 {
        const int num_verts = plConvexHullNumVertices(hull);
        BMVert **hull_verts = MEM_mallocN(sizeof(*hull_verts) *
@@ -478,9 +489,10 @@ static BMVert **hull_verts_from_bullet(plConvexHull hull,
        return hull_verts;
 }
 
-static void hull_from_bullet(BMesh *bm, BMOperator *op,
-                             GSet *hull_triangles,
-                             BLI_mempool *pool)
+static void hull_from_bullet(
+        BMesh *bm, BMOperator *op,
+        GSet *hull_triangles,
+        BLI_mempool *pool)
 {
        int *fvi = NULL;
        BLI_array_declare(fvi);
@@ -499,7 +511,7 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op,
 
        hull = plConvexHullCompute(coords, num_input_verts);
        hull_verts = hull_verts_from_bullet(hull, input_verts, num_input_verts);
-       
+
        count = plConvexHullNumFaces(hull);
        for (i = 0; i < count; i++) {
                const int len = plConvexHullGetFaceSize(hull, i);
@@ -509,7 +521,7 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op,
                        int j;
 
                        /* Get face vertex indices */
-                       BLI_array_empty(fvi);
+                       BLI_array_clear(fvi);
                        BLI_array_grow_items(fvi, len);
                        plConvexHullGetFaceVertices(hull, i, fvi);
 
@@ -529,6 +541,9 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op,
        }
 
        BLI_array_free(fvi);
+
+       plConvexHullDelete(hull);
+
        MEM_freeN(hull_verts);
        MEM_freeN(coords);
        MEM_freeN(input_verts);
@@ -567,11 +582,17 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
 
        /* Tag input elements */
        BMO_ITER (ele, &oiter, op->slots_in, "input", BM_ALL) {
-               BMO_elem_flag_enable(bm, ele, HULL_FLAG_INPUT);
-               
+
                /* Mark all vertices as interior to begin with */
-               if (ele->head.htype == BM_VERT)
-                       BMO_elem_flag_enable(bm, ele, HULL_FLAG_INTERIOR_ELE);
+               if (ele->head.htype == BM_VERT) {
+                       BMO_vert_flag_enable(bm, (BMVert *)ele, HULL_FLAG_INPUT | HULL_FLAG_INTERIOR_ELE);
+               }
+               else if (ele->head.htype == BM_EDGE) {
+                       BMO_edge_flag_enable(bm, (BMEdge *)ele, HULL_FLAG_INPUT);
+               }
+               else {
+                       BMO_face_flag_enable(bm, (BMFace *)ele, HULL_FLAG_INPUT);
+               }
        }
 
        hull_pool = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_NOP);
@@ -580,7 +601,7 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
        hull_from_bullet(bm, op, hull_triangles, hull_pool);
 
        final_edges = hull_final_edges(hull_triangles);
-       
+
        hull_mark_interior_elements(bm, op, final_edges);
 
        /* Remove hull triangles covered by an existing face */