Cleanup: commas at the end of enums
[blender.git] / source / blender / bmesh / operators / bmo_hull.c
index 80bdf9de7ed26696f56e720462aef3acfff7f8b9..259bb0f5a9c24bdca0553901478a4883a80c3179 100644 (file)
@@ -22,6 +22,8 @@
 
 /** \file blender/bmesh/operators/bmo_hull.c
  *  \ingroup bmesh
 
 /** \file blender/bmesh/operators/bmo_hull.c
  *  \ingroup bmesh
+ *
+ * Create a convex hull using bullet physics library.
  */
 
 #ifdef WITH_BULLET
  */
 
 #ifdef WITH_BULLET
 #include "MEM_guardedalloc.h"
 
 #include "BLI_array.h"
 #include "MEM_guardedalloc.h"
 
 #include "BLI_array.h"
-#include "BLI_ghash.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
 #include "BLI_listbase.h"
 #include "BLI_math.h"
-#include "BLI_utildefines.h"
 
 #include "Bullet-C-Api.h"
 
 /* XXX: using 128 for totelem and pchunk of mempool, no idea what good
  * values would be though */
 
 #include "Bullet-C-Api.h"
 
 /* XXX: using 128 for totelem and pchunk of mempool, no idea what good
  * values would be though */
-#include "BLI_mempool.h"
 
 #include "bmesh.h"
 
 
 #include "bmesh.h"
 
 /* Internal operator flags */
 typedef enum {
        HULL_FLAG_INPUT =           (1 << 0),
 /* Internal operator flags */
 typedef enum {
        HULL_FLAG_INPUT =           (1 << 0),
-       
+
        HULL_FLAG_INTERIOR_ELE =    (1 << 1),
        HULL_FLAG_OUTPUT_GEOM =     (1 << 2),
        HULL_FLAG_INTERIOR_ELE =    (1 << 1),
        HULL_FLAG_OUTPUT_GEOM =     (1 << 2),
-       
+
        HULL_FLAG_DEL =             (1 << 3),
        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
 } HullFlags;
 
 /* Store hull triangles separate from BMesh faces until the end; this
@@ -68,8 +67,9 @@ typedef struct HullTriangle {
 
 /*************************** Hull Triangles ***************************/
 
 
 /*************************** Hull Triangles ***************************/
 
-static void hull_add_triangle(BMesh *bm, GHash *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;
 {
        HullTriangle *t;
        int i;
@@ -81,9 +81,9 @@ static void hull_add_triangle(BMesh *bm, GHash *hull_triangles, BLI_mempool *poo
 
        /* Mark triangles vertices as not interior */
        for (i = 0; i < 3; i++)
 
        /* 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_ghash_insert(hull_triangles, t, NULL);
+       BLI_gset_insert(hull_triangles, t);
        normal_tri_v3(t->no, v1->co, v2->co, v3->co);
 }
 
        normal_tri_v3(t->no, v1->co, v2->co, v3->co);
 }
 
@@ -93,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) {
        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;
                }
                {
                        return f;
                }
@@ -103,30 +103,31 @@ static BMFace *hull_find_example_face(BMesh *bm, BMEdge *e)
        return NULL;
 }
 
        return NULL;
 }
 
-static void hull_output_triangles(BMesh *bm, GHash *hull_triangles)
+static void hull_output_triangles(BMesh *bm, GSet *hull_triangles)
 {
 {
-       GHashIterator iter;
-       
-       GHASH_ITER (iter, hull_triangles) {
-               HullTriangle *t = BLI_ghashIterator_getKey(&iter);
+       GSetIterator iter;
+
+       GSET_ITER (iter, hull_triangles) {
+               HullTriangle *t = BLI_gsetIterator_getKey(&iter);
                int i;
 
                if (!t->skip) {
                        BMEdge *edges[3] = {
                int i;
 
                if (!t->skip) {
                        BMEdge *edges[3] = {
-                               BM_edge_create(bm, t->v[0], t->v[1], NULL, TRUE),
-                               BM_edge_create(bm, t->v[1], t->v[2], NULL, TRUE),
-                               BM_edge_create(bm, t->v[2], t->v[0], NULL, TRUE)
+                               BM_edge_create(bm, t->v[0], t->v[1], NULL, BM_CREATE_NO_DOUBLE),
+                               BM_edge_create(bm, t->v[1], t->v[2], NULL, BM_CREATE_NO_DOUBLE),
+                               BM_edge_create(bm, t->v[2], t->v[0], NULL, BM_CREATE_NO_DOUBLE)
                        };
                        BMFace *f, *example = NULL;
 
                        };
                        BMFace *f, *example = NULL;
 
-                       if (BM_face_exists(bm, 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. */
                                /* 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 */
                        }
                        else {
                                /* Look for an adjacent face that existed before the hull */
@@ -136,34 +137,35 @@ static void hull_output_triangles(BMesh *bm, GHash *hull_triangles)
                                }
 
                                /* Create new hull face */
                                }
 
                                /* Create new hull face */
-                               f = BM_face_create_quad_tri_v(bm, t->v, 3, example, TRUE);
-                               BM_face_copy_shared(bm, f);
+                               f = BM_face_create_verts(bm, t->v, 3, example, BM_CREATE_NO_DOUBLE, true);
+                               BM_face_copy_shared(bm, f, NULL, NULL);
                        }
                        }
-                       /* Mark face for 'geomout' slot and select */
-                       BMO_elem_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM);
-                       BM_face_select_set(bm, f, TRUE);
+                       /* Mark face for 'geom.out' slot and select */
+                       BMO_face_flag_enable(bm, f, HULL_FLAG_OUTPUT_GEOM);
+                       BM_face_select_set(bm, f, true);
 
 
-                       /* Mark edges for 'geomout' slot */
+                       /* Mark edges for 'geom.out' slot */
                        for (i = 0; i < 3; i++) {
                        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 {
                        }
                }
                else {
-                       /* Mark input edges for 'geomout' slot */
+                       /* Mark input edges for 'geom.out' slot */
                        for (i = 0; i < 3; i++) {
                                const int next = (i == 2 ? 0 : i + 1);
                                BMEdge *e = BM_edge_exists(t->v[i], t->v[next]);
                                if (e &&
                        for (i = 0; i < 3; i++) {
                                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_elem_flag_enable(bm, e, HULL_FLAG_OUTPUT_GEOM);
+                                   BMO_edge_flag_test(bm, e, HULL_FLAG_INPUT) &&
+                                   !BMO_edge_flag_test(bm, e, HULL_FLAG_HOLE))
+                               {
+                                       BMO_edge_flag_enable(bm, e, HULL_FLAG_OUTPUT_GEOM);
                                }
                        }
                }
 
                                }
                        }
                }
 
-               /* Mark verts for 'geomout' slot */
+               /* Mark verts for 'geom.out' slot */
                for (i = 0; i < 3; i++) {
                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;
 }
 
        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;
 
 {
        ListBase *adj;
 
@@ -200,28 +203,28 @@ static int hull_final_edges_lookup(HullFinalEdges *final_edges,
 
        adj = BLI_ghash_lookup(final_edges->edges, v1);
        if (!adj)
 
        adj = BLI_ghash_lookup(final_edges->edges, v1);
        if (!adj)
-               return FALSE;
+               return false;
 
        return !!final_edges_find_link(adj, v2);
 }
 
 /* Used for checking whether a pre-existing edge lies on the hull */
 
        return !!final_edges_find_link(adj, v2);
 }
 
 /* Used for checking whether a pre-existing edge lies on the hull */
-static HullFinalEdges *hull_final_edges(GHash *hull_triangles)
+static HullFinalEdges *hull_final_edges(GSet *hull_triangles)
 {
        HullFinalEdges *final_edges;
 {
        HullFinalEdges *final_edges;
-       GHashIterator iter;
-       
+       GSetIterator iter;
+
        final_edges = MEM_callocN(sizeof(HullFinalEdges), "HullFinalEdges");
        final_edges->edges = BLI_ghash_ptr_new("final edges ghash");
        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), 128, 128, 0);
-       final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 128, 128, 0);
+       final_edges->base_pool = BLI_mempool_create(sizeof(ListBase), 0, 128, BLI_MEMPOOL_NOP);
+       final_edges->link_pool = BLI_mempool_create(sizeof(LinkData), 0, 128, BLI_MEMPOOL_NOP);
 
 
-       GHASH_ITER (iter, hull_triangles) {
+       GSET_ITER (iter, hull_triangles) {
+               HullTriangle *t = BLI_gsetIterator_getKey(&iter);
                LinkData *link;
                int i;
                LinkData *link;
                int i;
-               
+
                for (i = 0; i < 3; i++) {
                for (i = 0; i < 3; i++) {
-                       HullTriangle *t = BLI_ghashIterator_getKey(&iter);
                        BMVert *v1 = t->v[i];
                        BMVert *v2 = t->v[(i + 1) % 3];
                        ListBase *adj;
                        BMVert *v1 = t->v[i];
                        BMVert *v2 = t->v[(i + 1) % 3];
                        ListBase *adj;
@@ -259,60 +262,62 @@ static void hull_final_edges_free(HullFinalEdges *final_edges)
 
 /**************************** Final Output ****************************/
 
 
 /**************************** Final Output ****************************/
 
-static void hull_remove_overlapping(BMesh *bm, GHash *hull_triangles,
-                                    HullFinalEdges *final_edges)
+static void hull_remove_overlapping(
+        BMesh *bm, GSet *hull_triangles,
+        HullFinalEdges *final_edges)
 {
 {
-       GHashIterator hull_iter;
+       GSetIterator hull_iter;
 
 
-       GHASH_ITER (hull_iter, hull_triangles) {
-               HullTriangle *t = BLI_ghashIterator_getKey(&hull_iter);
+       GSET_ITER (hull_iter, hull_triangles) {
+               HullTriangle *t = BLI_gsetIterator_getKey(&hull_iter);
                BMIter bm_iter1, bm_iter2;
                BMFace *f;
                BMIter bm_iter1, bm_iter2;
                BMFace *f;
-               int f_on_hull;
+               bool f_on_hull;
 
                BM_ITER_ELEM (f, &bm_iter1, t->v[0], BM_FACES_OF_VERT) {
                        BMEdge *e;
 
                        /* Check that all the face's edges are on the hull,
                         * otherwise can't reuse it */
 
                BM_ITER_ELEM (f, &bm_iter1, t->v[0], BM_FACES_OF_VERT) {
                        BMEdge *e;
 
                        /* Check that all the face's edges are on the hull,
                         * otherwise can't reuse it */
-                       f_on_hull = TRUE;
+                       f_on_hull = true;
                        BM_ITER_ELEM (e, &bm_iter2, f, BM_EDGES_OF_FACE) {
                                if (!hull_final_edges_lookup(final_edges, e->v1, e->v2)) {
                        BM_ITER_ELEM (e, &bm_iter2, f, BM_EDGES_OF_FACE) {
                                if (!hull_final_edges_lookup(final_edges, e->v1, e->v2)) {
-                                       f_on_hull = FALSE;
+                                       f_on_hull = false;
                                        break;
                                }
                        }
                                        break;
                                }
                        }
-                       
+
                        /* Note: can't change ghash while iterating, so mark
                         * with 'skip' flag rather than deleting triangles */
                        /* Note: can't change ghash while iterating, so mark
                         * with 'skip' flag rather than deleting triangles */
-                       if (BM_vert_in_face(f, t->v[1]) &&
-                           BM_vert_in_face(f, t->v[2]) && f_on_hull)
+                       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);
+                               t->skip = true;
+                               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;
        BMOIter oiter;
 
        /* Check for interior edges too */
 {
        BMEdge *e;
        BMFace *f;
        BMOIter oiter;
 
        /* Check for interior edges too */
-       BMO_ITER (e, &oiter, bm, op, "input", BM_EDGE) {
+       BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) {
                if (!hull_final_edges_lookup(final_edges, e->v1, e->v2))
                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() */
        }
 
        /* Mark all input faces as interior, some may be unmarked in
         * hull_remove_overlapping() */
-       BMO_ITER (f, &oiter, bm, op, "input", BM_FACE) {
-               BMO_elem_flag_enable(bm, f, HULL_FLAG_INTERIOR_ELE);
+       BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) {
+               BMO_face_flag_enable(bm, f, HULL_FLAG_INTERIOR_ELE);
        }
 }
 
        }
 }
 
@@ -328,48 +333,51 @@ static void hull_tag_unused(BMesh *bm, BMOperator *op)
         * interior (i.e. were already part of the input, but not part of
         * the hull), but that aren't also used by elements outside the
         * input set */
         * interior (i.e. were already part of the input, but not part of
         * the hull), but that aren't also used by elements outside the
         * input set */
-       BMO_ITER (v, &oiter, bm, op, "input", BM_VERT) {
-               if (BMO_elem_flag_test(bm, v, HULL_FLAG_INTERIOR_ELE)) {
-                       int del = TRUE;
-               
+       BMO_ITER (v, &oiter, op->slots_in, "input", BM_VERT) {
+               if (BMO_vert_flag_test(bm, v, HULL_FLAG_INTERIOR_ELE)) {
+                       bool del = true;
+
                        BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) {
                        BM_ITER_ELEM (e, &iter, v, BM_EDGES_OF_VERT) {
-                               if (!BMO_elem_flag_test(bm, e, HULL_FLAG_INPUT)) {
-                                       del = FALSE;
+                               if (!BMO_edge_flag_test(bm, e, HULL_FLAG_INPUT)) {
+                                       del = false;
                                        break;
                                }
                        }
 
                        BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) {
                                        break;
                                }
                        }
 
                        BM_ITER_ELEM (f, &iter, v, BM_FACES_OF_VERT) {
-                               if (!BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT)) {
-                                       del = FALSE;
+                               if (!BMO_face_flag_test(bm, f, HULL_FLAG_INPUT)) {
+                                       del = false;
                                        break;
                                }
                        }
 
                                        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, bm, op, "input", BM_EDGE) {
-               if (BMO_elem_flag_test(bm, e, HULL_FLAG_INTERIOR_ELE)) {
-                       int del = TRUE;
+       BMO_ITER (e, &oiter, op->slots_in, "input", BM_EDGE) {
+               if (BMO_edge_flag_test(bm, e, HULL_FLAG_INTERIOR_ELE)) {
+                       bool del = true;
 
                        BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
 
                        BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
-                               if (!BMO_elem_flag_test(bm, f, HULL_FLAG_INPUT)) {
-                                       del = FALSE;
+                               if (!BMO_face_flag_test(bm, f, HULL_FLAG_INPUT)) {
+                                       del = false;
                                        break;
                                }
                        }
 
                                        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, bm, op, "input", BM_FACE) {
-               if (BMO_elem_flag_test(bm, f, HULL_FLAG_INTERIOR_ELE))
-                       BMO_elem_flag_enable(bm, f, HULL_FLAG_DEL);
+       BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) {
+               if (BMO_face_flag_test(bm, f, HULL_FLAG_INTERIOR_ELE)) {
+                       BMO_face_flag_enable(bm, f, HULL_FLAG_DEL);
+               }
        }
 }
 
        }
 }
 
@@ -382,11 +390,11 @@ static void hull_tag_holes(BMesh *bm, BMOperator *op)
 
        /* Unmark any hole faces if they are isolated or part of a
         * border */
 
        /* Unmark any hole faces if they are isolated or part of a
         * border */
-       BMO_ITER (f, &oiter, bm, op, "input", BM_FACE) {
-               if (BMO_elem_flag_test(bm, f, HULL_FLAG_HOLE)) {
+       BMO_ITER (f, &oiter, op->slots_in, "input", BM_FACE) {
+               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)) {
                        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;
                                }
                        }
                                        break;
                                }
                        }
@@ -395,38 +403,39 @@ static void hull_tag_holes(BMesh *bm, BMOperator *op)
 
        /* Mark edges too if all adjacent faces are holes and the edge is
         * not already isolated */
 
        /* Mark edges too if all adjacent faces are holes and the edge is
         * not already isolated */
-       BMO_ITER (e, &oiter, bm, op, "input", BM_EDGE) {
-               int hole = TRUE;
-               int any_faces = FALSE;
-               
+       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) {
                BM_ITER_ELEM (f, &iter, e, BM_FACES_OF_EDGE) {
-                       any_faces = TRUE;
-                       if (!BMO_elem_flag_test(bm, f, HULL_FLAG_HOLE)) {
-                               hole = FALSE;
+                       any_faces = true;
+                       if (!BMO_face_flag_test(bm, f, HULL_FLAG_HOLE)) {
+                               hole = false;
                                break;
                        }
                }
 
                if (hole && any_faces)
                                break;
                        }
                }
 
                if (hole && any_faces)
-                       BMO_elem_flag_enable(bm, e, HULL_FLAG_HOLE);
+                       BMO_edge_flag_enable(bm, e, HULL_FLAG_HOLE);
        }
 }
 
        }
 }
 
-static int hull_input_vert_count(BMesh *bm, BMOperator *op)
+static int hull_input_vert_count(BMOperator *op)
 {
        BMOIter oiter;
        BMVert *v;
        int count = 0;
 
 {
        BMOIter oiter;
        BMVert *v;
        int count = 0;
 
-       BMO_ITER (v, &oiter, bm, op, "input", BM_VERT) {
+       BMO_ITER (v, &oiter, op->slots_in, "input", BM_VERT) {
                count++;
        }
 
        return count;
 }
 
                count++;
        }
 
        return count;
 }
 
-static BMVert **hull_input_verts_copy(BMesh *bm, BMOperator *op,
-                                      const int num_input_verts)
+static BMVert **hull_input_verts_copy(
+        BMOperator *op,
+        const int num_input_verts)
 {
        BMOIter oiter;
        BMVert *v;
 {
        BMOIter oiter;
        BMVert *v;
@@ -434,17 +443,18 @@ static BMVert **hull_input_verts_copy(BMesh *bm, BMOperator *op,
                                           num_input_verts, AT);
        int i = 0;
 
                                           num_input_verts, AT);
        int i = 0;
 
-       BMO_ITER (v, &oiter, bm, op, "input", BM_VERT) {
+       BMO_ITER (v, &oiter, op->slots_in, "input", BM_VERT) {
                input_verts[i++] = v;
        }
 
        return input_verts;
 }
 
                input_verts[i++] = v;
        }
 
        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, AT);
+       float (*coords)[3] = MEM_callocN(sizeof(*coords) * num_input_verts, __func__);
        int i;
 
        for (i = 0; i < num_input_verts; i++) {
        int i;
 
        for (i = 0; i < num_input_verts; i++) {
@@ -454,9 +464,10 @@ static float (*hull_verts_for_bullet(BMVert **input_verts,
        return coords;
 }
 
        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) *
 {
        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;
 }
 
        return hull_verts;
 }
 
-static void hull_from_bullet(BMesh *bm, BMOperator *op,
-                             GHash *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);
 {
        int *fvi = NULL;
        BLI_array_declare(fvi);
@@ -492,14 +504,14 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op,
        plConvexHull hull;
        int i, count = 0;
 
        plConvexHull hull;
        int i, count = 0;
 
-       const int num_input_verts = hull_input_vert_count(bm, op);
+       const int num_input_verts = hull_input_vert_count(op);
 
 
-       input_verts = hull_input_verts_copy(bm, op, num_input_verts);
+       input_verts = hull_input_verts_copy(op, num_input_verts);
        coords = hull_verts_for_bullet(input_verts, num_input_verts);
 
        hull = plConvexHullCompute(coords, num_input_verts);
        hull_verts = hull_verts_from_bullet(hull, input_verts, num_input_verts);
        coords = hull_verts_for_bullet(input_verts, num_input_verts);
 
        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);
        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 */
                        int j;
 
                        /* Get face vertex indices */
-                       BLI_array_empty(fvi);
+                       BLI_array_clear(fvi);
                        BLI_array_grow_items(fvi, len);
                        plConvexHullGetFaceVertices(hull, i, fvi);
 
                        BLI_array_grow_items(fvi, len);
                        plConvexHullGetFaceVertices(hull, i, fvi);
 
@@ -529,19 +541,22 @@ static void hull_from_bullet(BMesh *bm, BMOperator *op,
        }
 
        BLI_array_free(fvi);
        }
 
        BLI_array_free(fvi);
+
+       plConvexHullDelete(hull);
+
        MEM_freeN(hull_verts);
        MEM_freeN(coords);
        MEM_freeN(input_verts);
 }
 
 /* Check that there are at least three vertices in the input */
        MEM_freeN(hull_verts);
        MEM_freeN(coords);
        MEM_freeN(input_verts);
 }
 
 /* Check that there are at least three vertices in the input */
-static int hull_num_input_verts_is_ok(BMesh *bm, BMOperator *op)
+static bool hull_num_input_verts_is_ok(BMOperator *op)
 {
        BMOIter oiter;
        BMVert *v;
        int partial_num_verts = 0;
 
 {
        BMOIter oiter;
        BMVert *v;
        int partial_num_verts = 0;
 
-       BMO_ITER (v, &oiter, bm, op, "input", BM_VERT) {
+       BMO_ITER (v, &oiter, op->slots_in, "input", BM_VERT) {
                partial_num_verts++;
                if (partial_num_verts >= 3)
                        break;
                partial_num_verts++;
                if (partial_num_verts >= 3)
                        break;
@@ -556,35 +571,41 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
        BLI_mempool *hull_pool;
        BMElemF *ele;
        BMOIter oiter;
        BLI_mempool *hull_pool;
        BMElemF *ele;
        BMOIter oiter;
-       GHash *hull_triangles;
+       GSet *hull_triangles;
 
        /* Verify that at least three verts in the input */
 
        /* Verify that at least three verts in the input */
-       if (!hull_num_input_verts_is_ok(bm, op)) {
+       if (!hull_num_input_verts_is_ok(op)) {
                BMO_error_raise(bm, op, BMERR_CONVEX_HULL_FAILED,
                                "Requires at least three vertices");
                return;
        }
 
        /* Tag input elements */
                BMO_error_raise(bm, op, BMERR_CONVEX_HULL_FAILED,
                                "Requires at least three vertices");
                return;
        }
 
        /* Tag input elements */
-       BMO_ITER (ele, &oiter, bm, op, "input", BM_ALL) {
-               BMO_elem_flag_enable(bm, ele, HULL_FLAG_INPUT);
-               
+       BMO_ITER (ele, &oiter, op->slots_in, "input", BM_ALL) {
+
                /* Mark all vertices as interior to begin with */
                /* 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), 128, 128, 0);
-       hull_triangles = BLI_ghash_ptr_new("hull_triangles");
+       hull_pool = BLI_mempool_create(sizeof(HullTriangle), 0, 128, BLI_MEMPOOL_NOP);
+       hull_triangles = BLI_gset_ptr_new("hull_triangles");
 
        hull_from_bullet(bm, op, hull_triangles, hull_pool);
 
        final_edges = hull_final_edges(hull_triangles);
 
        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 */
        hull_mark_interior_elements(bm, op, final_edges);
 
        /* Remove hull triangles covered by an existing face */
-       if (BMO_slot_bool_get(op, "use_existing_faces")) {
+       if (BMO_slot_bool_get(op->slots_in, "use_existing_faces")) {
                hull_remove_overlapping(bm, hull_triangles, final_edges);
 
                hull_tag_holes(bm, op);
                hull_remove_overlapping(bm, hull_triangles, final_edges);
 
                hull_tag_holes(bm, op);
@@ -597,29 +618,29 @@ void bmo_convex_hull_exec(BMesh *bm, BMOperator *op)
        hull_output_triangles(bm, hull_triangles);
        BLI_mempool_destroy(hull_pool);
 
        hull_output_triangles(bm, hull_triangles);
        BLI_mempool_destroy(hull_pool);
 
-       BLI_ghash_free(hull_triangles, NULL, NULL);
+       BLI_gset_free(hull_triangles, NULL);
 
        hull_tag_unused(bm, op);
 
        /* Output slot of input elements that ended up inside the hull
         * rather than part of it */
 
        hull_tag_unused(bm, op);
 
        /* Output slot of input elements that ended up inside the hull
         * rather than part of it */
-       BMO_slot_buffer_from_enabled_flag(bm, op, "interior_geom", BM_ALL,
-                                         HULL_FLAG_INTERIOR_ELE);
+       BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom_interior.out",
+                                         BM_ALL_NOLOOP, HULL_FLAG_INTERIOR_ELE);
 
        /* Output slot of input elements that ended up inside the hull and
         * are are unused by other geometry. */
 
        /* Output slot of input elements that ended up inside the hull and
         * are are unused by other geometry. */
-       BMO_slot_buffer_from_enabled_flag(bm, op, "unused_geom", BM_ALL,
-                                         HULL_FLAG_DEL);
+       BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom_unused.out",
+                                         BM_ALL_NOLOOP, HULL_FLAG_DEL);
 
        /* Output slot of faces and edges that were in the input and on
         * the hull (useful for cases like bridging where you want to
         * delete some input geometry) */
 
        /* Output slot of faces and edges that were in the input and on
         * the hull (useful for cases like bridging where you want to
         * delete some input geometry) */
-       BMO_slot_buffer_from_enabled_flag(bm, op, "holes_geom", BM_ALL,
-                                         HULL_FLAG_HOLE);
+       BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom_holes.out",
+                                         BM_ALL_NOLOOP, HULL_FLAG_HOLE);
 
        /* Output slot of all hull vertices, faces, and edges */
 
        /* Output slot of all hull vertices, faces, and edges */
-       BMO_slot_buffer_from_enabled_flag(bm, op, "geomout", BM_ALL,
-                                         HULL_FLAG_OUTPUT_GEOM);
+       BMO_slot_buffer_from_enabled_flag(bm, op, op->slots_out, "geom.out",
+                                         BM_ALL_NOLOOP, HULL_FLAG_OUTPUT_GEOM);
 }
 
 #endif  /* WITH_BULLET */
 }
 
 #endif  /* WITH_BULLET */