bmmesh api - use struct rather than int[4] to initialize mesh sizes.

also correct bad assert() in previous commit.
This commit is contained in:
Campbell Barton 2012-03-01 20:09:17 +00:00
parent d534f0e16d
commit 9aafe32147
19 changed files with 105 additions and 106 deletions

View File

@ -51,6 +51,7 @@
#include "BLI_mempool.h"
#include "BLI_utildefines.h"
#include "BKE_utildefines.h"
#include "BKE_customdata.h"
#include "BKE_customdata_file.h"
#include "BKE_global.h"

View File

@ -526,7 +526,7 @@ BMesh *BKE_mesh_to_bmesh(Mesh *me, Object *ob)
{
BMesh *bm;
bm = BM_mesh_create(ob, bm_mesh_allocsize_default);
bm = BM_mesh_create(ob, &bm_mesh_allocsize_default);
BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%b", me, ob, TRUE);

View File

@ -143,8 +143,12 @@ BMEditMesh *DM_to_editbmesh(Object *ob, DerivedMesh *dm, BMEditMesh *existing, i
BMEditMesh *em = existing;
BMesh *bm;
if (em) bm = em->bm;
else bm = BM_mesh_create(ob, bm_mesh_allocsize_default);
if (em) {
bm = em->bm;
}
else {
bm = BM_mesh_create(ob, &bm_mesh_allocsize_default);
}
DM_to_bmesh_ex(dm, bm);
@ -164,7 +168,7 @@ BMesh *DM_to_bmesh(Object *ob, DerivedMesh *dm)
{
BMesh *bm;
bm = BM_mesh_create(ob, bm_mesh_allocsize_default);
bm = BM_mesh_create(ob, &bm_mesh_allocsize_default);
DM_to_bmesh_ex(dm, bm);

View File

@ -201,63 +201,13 @@ extern "C" {
#include "DNA_listBase.h"
#include "DNA_customdata_types.h"
#include <stdlib.h>
#include "BLI_utildefines.h"
#include "bmesh_class.h"
/*forward declarations*/
/*
* BMHeader
*
* All mesh elements begin with a BMHeader. This structure
* hold several types of data
*
* 1: The type of the element (vert, edge, loop or face)
* 2: Persistant "header" flags/markings (sharp, seam, select, hidden, ect)
note that this is different from the "tool" flags.
* 3: Unique ID in the bmesh.
* 4: some elements for internal record keeping.
*
*/
/* BMHeader->htype (char) */
enum {
BM_VERT = 1,
BM_EDGE = 2,
BM_LOOP = 4,
BM_FACE = 8
};
#define BM_ALL (BM_VERT | BM_EDGE | BM_LOOP | BM_FACE)
/* BMHeader->hflag (char) */
enum {
BM_ELEM_SELECT = (1 << 0),
BM_ELEM_HIDDEN = (1 << 1),
BM_ELEM_SEAM = (1 << 2),
BM_ELEM_SMOOTH = (1 << 3), /* used for faces and edges, note from the user POV,
* this is a sharp edge when disabled */
BM_ELEM_TAG = (1 << 4), /* internal flag, used for ensuring correct normals
* during multires interpolation, and any other time
* when temp tagging is handy.
* always assume dirty & clear before use. */
/* we have 2 spare flags which is awesome but since we're limited to 8
* only add new flags with care! - campbell */
/* BM_ELEM_SPARE = (1 << 5), */
/* BM_ELEM_SPARE = (1 << 6), */
BM_ELEM_INTERNAL_TAG = (1 << 7) /* for low level internal API tagging,
* since tools may want to tag verts and
* not have functions clobber them */
};
/* Mesh Level Ops */
extern int bm_mesh_allocsize_default[4];
/* ------------------------------------------------------------------------- */
/* bmesh_inline.c */

View File

@ -47,6 +47,19 @@ struct Object;
*
* hrm. it doesnt but stull works ok, remove the comment above? - campbell.
*/
/**
* BMHeader
*
* All mesh elements begin with a BMHeader. This structure
* hold several types of data
*
* 1: The type of the element (vert, edge, loop or face)
* 2: Persistant "header" flags/markings (smooth, seam, select, hidden, ect)
* note that this is different from the "tool" flags.
* 3: Unique ID in the bmesh.
* 4: some elements for internal record keeping.
*/
typedef struct BMHeader {
void *data; /* customdata layers */
int index; /* notes:
@ -188,4 +201,37 @@ typedef struct BMesh {
int opflag; /* current operator flag */
} BMesh;
/* BMHeader->htype (char) */
enum {
BM_VERT = 1,
BM_EDGE = 2,
BM_LOOP = 4,
BM_FACE = 8
};
#define BM_ALL (BM_VERT | BM_EDGE | BM_LOOP | BM_FACE)
/* BMHeader->hflag (char) */
enum {
BM_ELEM_SELECT = (1 << 0),
BM_ELEM_HIDDEN = (1 << 1),
BM_ELEM_SEAM = (1 << 2),
BM_ELEM_SMOOTH = (1 << 3), /* used for faces and edges, note from the user POV,
* this is a sharp edge when disabled */
BM_ELEM_TAG = (1 << 4), /* internal flag, used for ensuring correct normals
* during multires interpolation, and any other time
* when temp tagging is handy.
* always assume dirty & clear before use. */
/* we have 2 spare flags which is awesome but since we're limited to 8
* only add new flags with care! - campbell */
/* BM_ELEM_SPARE = (1 << 5), */
/* BM_ELEM_SPARE = (1 << 6), */
BM_ELEM_INTERNAL_TAG = (1 << 7) /* for low level internal API tagging,
* since tools may want to tag verts and
* not have functions clobber them */
};
#endif /* __BMESH_CLASS_H__ */

View File

@ -31,13 +31,9 @@
extern "C" {
#endif
#include "BLI_memarena.h"
#include "BLI_ghash.h"
#include "BKE_utildefines.h"
#include <stdarg.h>
#include <string.h> /* for memcpy */
/*
* operators represent logical, executable mesh modules. all topological
@ -140,7 +136,7 @@ typedef struct BMOperator {
int needflag;
int flag;
struct BMOpSlot slots[BMO_OP_MAX_SLOTS]; void (*exec)(BMesh *bm, struct BMOperator *op);
MemArena *arena;
struct MemArena *arena;
} BMOperator;
#define MAX_SLOTNAME 32

View File

@ -589,17 +589,17 @@ BMesh *BM_mesh_copy(BMesh *bmold)
int i, j;
/* allocate a bmesh */
bm = BM_mesh_create(bmold->ob, bm_mesh_allocsize_default);
bm = BM_mesh_create(bmold->ob, &bm_mesh_allocsize_default);
CustomData_copy(&bmold->vdata, &bm->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&bmold->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&bmold->ldata, &bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&bmold->pdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_bmesh_init_pool(&bm->vdata, bm_mesh_allocsize_default[0]);
CustomData_bmesh_init_pool(&bm->edata, bm_mesh_allocsize_default[1]);
CustomData_bmesh_init_pool(&bm->ldata, bm_mesh_allocsize_default[2]);
CustomData_bmesh_init_pool(&bm->pdata, bm_mesh_allocsize_default[3]);
CustomData_bmesh_init_pool(&bm->vdata, bm_mesh_allocsize_default.totvert);
CustomData_bmesh_init_pool(&bm->edata, bm_mesh_allocsize_default.totedge);
CustomData_bmesh_init_pool(&bm->ldata, bm_mesh_allocsize_default.totloop);
CustomData_bmesh_init_pool(&bm->pdata, bm_mesh_allocsize_default.totface);
vtable = MEM_mallocN(sizeof(BMVert *) * bmold->totvert, "BM_mesh_copy vtable");
etable = MEM_mallocN(sizeof(BMEdge *) * bmold->totedge, "BM_mesh_copy etable");

View File

@ -44,14 +44,14 @@
#include "bmesh_private.h"
/* used as an extern, defined in bmesh.h */
int bm_mesh_allocsize_default[4] = {512, 512, 2048, 512};
BMAllocTemplate bm_mesh_allocsize_default = {512, 512, 2048, 512};
static void bm_mempool_init(BMesh *bm, const int allocsize[4])
static void bm_mempool_init(BMesh *bm, const BMAllocTemplate *allocsize)
{
bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize[0], allocsize[0], FALSE, TRUE);
bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize[1], allocsize[1], FALSE, TRUE);
bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize[2], allocsize[2], FALSE, FALSE);
bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize[3], allocsize[3], FALSE, TRUE);
bm->vpool = BLI_mempool_create(sizeof(BMVert), allocsize->totvert, allocsize->totvert, FALSE, TRUE);
bm->epool = BLI_mempool_create(sizeof(BMEdge), allocsize->totedge, allocsize->totedge, FALSE, TRUE);
bm->lpool = BLI_mempool_create(sizeof(BMLoop), allocsize->totloop, allocsize->totloop, FALSE, FALSE);
bm->fpool = BLI_mempool_create(sizeof(BMFace), allocsize->totface, allocsize->totface, FALSE, TRUE);
#ifdef USE_BMESH_HOLES
bm->looplistpool = BLI_mempool_create(sizeof(BMLoopList), allocsize[3], allocsize[3], FALSE, FALSE);
@ -70,7 +70,7 @@ static void bm_mempool_init(BMesh *bm, const int allocsize[4])
*
* \note ob is needed by multires
*/
BMesh *BM_mesh_create(struct Object *ob, const int allocsize[4])
BMesh *BM_mesh_create(struct Object *ob, BMAllocTemplate *allocsize)
{
/* allocate the structure */
BMesh *bm = MEM_callocN(sizeof(BMesh), __func__);
@ -173,7 +173,7 @@ void BM_mesh_clear(BMesh *bm)
bm->ob = ob;
/* allocate the memory pools for the mesh elements */
bm_mempool_init(bm, bm_mesh_allocsize_default);
bm_mempool_init(bm, &bm_mesh_allocsize_default);
bm->stackdepth = 1;
bm->totflags = 1;

View File

@ -27,7 +27,9 @@
* \ingroup bmesh
*/
BMesh *BM_mesh_create(struct Object *ob, const int allocsize[4]);
struct BMAllocTemplate;
BMesh *BM_mesh_create(struct Object *ob, struct BMAllocTemplate *allocsize);
void BM_mesh_free(BMesh *bm);
void BM_mesh_data_free(BMesh *bm);
@ -46,4 +48,10 @@ BMVert *BM_vert_at_index(BMesh *bm, const int index);
BMEdge *BM_edge_at_index(BMesh *bm, const int index);
BMFace *BM_face_at_index(BMesh *bm, const int index);
typedef struct BMAllocTemplate {
int totvert, totedge, totloop, totface;
} BMAllocTemplate;
extern BMAllocTemplate bm_mesh_allocsize_default;
#endif /* __BMESH_MESH_H__ */

View File

@ -94,14 +94,9 @@ BM_INLINE void BMO_slot_map_ptr_insert(BMesh *bm, BMOperator *op, const char *sl
BM_INLINE int BMO_slot_map_contains(BMesh *UNUSED(bm), BMOperator *op, const char *slotname, void *element)
{
BMOpSlot *slot = BMO_slot_get(op, slotname);
BLI_assert(slot->slottype == BMO_OP_SLOT_MAPPING);
/*sanity check*/
if (slot->slottype != BMO_OP_SLOT_MAPPING) {
#ifdef DEBUG
printf("%s: invalid type %d\n", __func__, slot->slottype);
#endif
return 0;
}
/* sanity check */
if (!slot->data.ghash) return 0;
return BLI_ghash_haskey(slot->data.ghash, element);
@ -112,14 +107,9 @@ BM_INLINE void *BMO_slot_map_data_get(BMesh *UNUSED(bm), BMOperator *op, const c
{
BMOElemMapping *mapping;
BMOpSlot *slot = BMO_slot_get(op, slotname);
BLI_assert(slot->slottype == BMO_OP_SLOT_MAPPING);
/*sanity check*/
if (slot->slottype != BMO_OP_SLOT_MAPPING) {
#ifdef DEBUG
printf("%s: invalid type %d\n", __func__, slot->slottype);
#endif
return NULL;
}
/* sanity check */
if (!slot->data.ghash) return NULL;
mapping = (BMOElemMapping *)BLI_ghash_lookup(slot->data.ghash, element);
@ -132,7 +122,7 @@ BM_INLINE void *BMO_slot_map_data_get(BMesh *UNUSED(bm), BMOperator *op, const c
BM_INLINE float BMO_slot_map_float_get(BMesh *bm, BMOperator *op, const char *slotname,
void *element)
{
float *val = (float*) BMO_slot_map_data_get(bm, op, slotname, element);
float *val = (float *) BMO_slot_map_data_get(bm, op, slotname, element);
if (val) return *val;
return 0.0f;
@ -141,7 +131,7 @@ BM_INLINE float BMO_slot_map_float_get(BMesh *bm, BMOperator *op, const char *sl
BM_INLINE int BMO_slot_map_int_get(BMesh *bm, BMOperator *op, const char *slotname,
void *element)
{
int *val = (int*) BMO_slot_map_data_get(bm, op, slotname, element);
int *val = (int *) BMO_slot_map_data_get(bm, op, slotname, element);
if (val) return *val;
return 0;

View File

@ -27,8 +27,7 @@
*/
#include <stdlib.h>
#include <string.h> /* for memcpy */
#include "BLI_listbase.h"

View File

@ -174,12 +174,14 @@ void bmo_dissolve_faces_exec(BMesh *bm, BMOperator *op)
}
}
if (BMO_error_occurred(bm)) goto cleanup;
if (BMO_error_occurred(bm)) {
goto cleanup;
}
BMO_slot_buffer_from_flag(bm, op, "regionout", FACE_NEW, BM_FACE);
cleanup:
/* free/cleanu */
/* free/cleanup */
for (i = 0; i < BLI_array_count(regions); i++) {
if (regions[i]) MEM_freeN(regions[i]);
}

View File

@ -440,7 +440,7 @@ void bmo_split_exec(BMesh *bm, BMOperator *op)
BMO_slot_copy(&dupeop, splitop, "isovertmap",
"isovertmap");
/* cleanu */
/* cleanup */
BMO_op_finish(bm, &delop);
BMO_op_finish(bm, &dupeop);
}

View File

@ -20,6 +20,8 @@
* ***** END GPL LICENSE BLOCK *****
*/
#include <string.h> /* for memcpy */
#include "MEM_guardedalloc.h"
#include "BLI_array.h"

View File

@ -137,10 +137,10 @@ void bmo_mesh_to_bmesh_exec(BMesh *bm, BMOperator *op)
printf("shapekey <-> mesh mismatch!\n");
}
CustomData_bmesh_init_pool(&bm->vdata, bm_mesh_allocsize_default[0]);
CustomData_bmesh_init_pool(&bm->edata, bm_mesh_allocsize_default[1]);
CustomData_bmesh_init_pool(&bm->ldata, bm_mesh_allocsize_default[2]);
CustomData_bmesh_init_pool(&bm->pdata, bm_mesh_allocsize_default[3]);
CustomData_bmesh_init_pool(&bm->vdata, bm_mesh_allocsize_default.totvert);
CustomData_bmesh_init_pool(&bm->edata, bm_mesh_allocsize_default.totedge);
CustomData_bmesh_init_pool(&bm->ldata, bm_mesh_allocsize_default.totloop);
CustomData_bmesh_init_pool(&bm->pdata, bm_mesh_allocsize_default.totface);
for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) {
v = BM_vert_create(bm, keyco && set_key ? keyco[i] : mvert->co, NULL);

View File

@ -39,6 +39,7 @@
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_memarena.h"
#include "bmesh.h"
#include "bmesh_private.h"

View File

@ -3206,16 +3206,16 @@ static int mesh_separate_selected(Main *bmain, Scene *scene, Base *editbase, wmO
if (!em)
return OPERATOR_CANCELLED;
bmnew = BM_mesh_create(obedit, bm_mesh_allocsize_default);
bmnew = BM_mesh_create(obedit, &bm_mesh_allocsize_default);
CustomData_copy(&em->bm->vdata, &bmnew->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&em->bm->edata, &bmnew->edata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&em->bm->ldata, &bmnew->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&em->bm->pdata, &bmnew->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_bmesh_init_pool(&bmnew->vdata, bm_mesh_allocsize_default[0]);
CustomData_bmesh_init_pool(&bmnew->edata, bm_mesh_allocsize_default[1]);
CustomData_bmesh_init_pool(&bmnew->ldata, bm_mesh_allocsize_default[2]);
CustomData_bmesh_init_pool(&bmnew->pdata, bm_mesh_allocsize_default[3]);
CustomData_bmesh_init_pool(&bmnew->vdata, bm_mesh_allocsize_default.totvert);
CustomData_bmesh_init_pool(&bmnew->edata, bm_mesh_allocsize_default.totedge);
CustomData_bmesh_init_pool(&bmnew->ldata, bm_mesh_allocsize_default.totloop);
CustomData_bmesh_init_pool(&bmnew->pdata, bm_mesh_allocsize_default.totface);
basenew = ED_object_add_duplicate(bmain, scene, editbase, USER_DUP_MESH); /* 0 = fully linked */
assign_matarar(basenew->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */

View File

@ -546,7 +546,7 @@ static void undoMesh_to_editbtMesh(void *umv, void *emv, void *UNUSED(obdata))
BMEdit_Free(em);
bm = BM_mesh_create(ob, bm_mesh_allocsize_default);
bm = BM_mesh_create(ob, &bm_mesh_allocsize_default);
BMO_op_callf(bm, "mesh_to_bmesh mesh=%p object=%p set_shapekey=%b", &um->me, ob, FALSE);
em2 = BMEdit_Create(bm, TRUE);

View File

@ -29,13 +29,13 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
#include "BLI_array.h"
#include "BLI_math.h"
#include "BLI_rand.h"
#include "BLI_smallhash.h"
#include "BLI_scanfill.h"
#include "BLI_memarena.h"
#include "BKE_DerivedMesh.h"
#include "BKE_context.h"