From 07a5caad5fad742196aa4df0e251aaf4f0568563 Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Fri, 27 Jun 2014 20:03:50 +1000 Subject: [PATCH] BMesh: use slightly faster method of stepping over edge-disks --- source/blender/bmesh/bmesh_class.h | 9 ++++++ .../bmesh/intern/bmesh_queries_inline.h | 3 +- source/blender/bmesh/intern/bmesh_structure.c | 28 ++----------------- source/blender/bmesh/intern/bmesh_structure.h | 2 ++ .../bmesh/intern/bmesh_structure_inline.h | 20 +++++++++++-- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h index 83b02764046..01745396cd1 100644 --- a/source/blender/bmesh/bmesh_class.h +++ b/source/blender/bmesh/bmesh_class.h @@ -311,6 +311,15 @@ typedef bool (*BMElemFilterFunc)(BMElem *, void *user_data); # define BM_FACE_FIRST_LOOP(p) ((p)->l_first) #endif +#define BM_DISK_EDGE_NEXT(e, v) ( \ + CHECK_TYPE_INLINE(e, BMEdge *), CHECK_TYPE_INLINE(v, BMVert *), \ + BLI_assert(BM_vert_in_edge(e, v)), \ + (((&e->v1_disk_link)[v == e->v2]).next)) +#define BM_DISK_EDGE_PREV(e, v) ( \ + CHECK_TYPE_INLINE(e, BMEdge *), CHECK_TYPE_INLINE(v, BMVert *), \ + BLI_assert(BM_vert_in_edge(e, v)), \ + (((&e->v1_disk_link)[v == e->v2]).prev)) + /** * size to use for stack arrays when dealing with NGons, * alloc after this limit is reached. diff --git a/source/blender/bmesh/intern/bmesh_queries_inline.h b/source/blender/bmesh/intern/bmesh_queries_inline.h index 0856b9846c1..6162af46837 100644 --- a/source/blender/bmesh/intern/bmesh_queries_inline.h +++ b/source/blender/bmesh/intern/bmesh_queries_inline.h @@ -144,8 +144,7 @@ BLI_INLINE bool BM_vert_is_wire_endpoint(const BMVert *v) { const BMEdge *e = v->e; if (e && e->l == NULL) { - const BMDiskLink *dl = (e->v1 == v) ? &e->v1_disk_link : &e->v2_disk_link; - return (dl->next == e); + return (BM_DISK_EDGE_NEXT(e, v) == e); } return false; } diff --git a/source/blender/bmesh/intern/bmesh_structure.c b/source/blender/bmesh/intern/bmesh_structure.c index afcafc8640d..d8313dab36f 100644 --- a/source/blender/bmesh/intern/bmesh_structure.c +++ b/source/blender/bmesh/intern/bmesh_structure.c @@ -130,17 +130,6 @@ bool bmesh_edge_swapverts(BMEdge *e, BMVert *v_orig, BMVert *v_new) * cycle order and all non-manifold conditions are represented trivially. */ -BLI_INLINE BMDiskLink *bmesh_disk_edge_link_from_vert(BMEdge *e, BMVert *v) -{ - if (v == e->v1) { - return &e->v1_disk_link; - } - else { - BLI_assert(v == e->v2); - return &e->v2_disk_link; - } -} - void bmesh_disk_edge_append(BMEdge *e, BMVert *v) { if (!v->e) { @@ -205,28 +194,15 @@ BMEdge *bmesh_disk_edge_exists(const BMVert *v1, const BMVert *v2) int bmesh_disk_count(const BMVert *v) { + int count = 0; if (v->e) { BMEdge *e_first, *e_iter; - int count = 0; - e_iter = e_first = v->e; - do { - if (!e_iter) { - return 0; - } - - if (count >= (1 << 20)) { - printf("bmesh error: infinite loop in disk cycle!\n"); - return 0; - } count++; } while ((e_iter = bmesh_disk_edge_next(e_iter, v)) != e_first); - return count; - } - else { - return 0; } + return count; } bool bmesh_disk_validate(int len, BMEdge *e, BMVert *v) diff --git a/source/blender/bmesh/intern/bmesh_structure.h b/source/blender/bmesh/intern/bmesh_structure.h index 5c87b5eb9b5..8e721ddd229 100644 --- a/source/blender/bmesh/intern/bmesh_structure.h +++ b/source/blender/bmesh/intern/bmesh_structure.h @@ -47,6 +47,8 @@ bool bmesh_loop_validate(BMFace *f); /* DISK CYCLE MANAGMENT */ void bmesh_disk_edge_append(BMEdge *e, BMVert *v); void bmesh_disk_edge_remove(BMEdge *e, BMVert *v); +BLI_INLINE BMEdge *bmesh_disk_edge_next_safe(const BMEdge *e, const BMVert *v); +BLI_INLINE BMEdge *bmesh_disk_edge_prev_safe(const BMEdge *e, const BMVert *v); BLI_INLINE BMEdge *bmesh_disk_edge_next(const BMEdge *e, const BMVert *v); BLI_INLINE BMEdge *bmesh_disk_edge_prev(const BMEdge *e, const BMVert *v); int bmesh_disk_facevert_count(const BMVert *v); diff --git a/source/blender/bmesh/intern/bmesh_structure_inline.h b/source/blender/bmesh/intern/bmesh_structure_inline.h index c29acaa724c..5b7e890f5ea 100644 --- a/source/blender/bmesh/intern/bmesh_structure_inline.h +++ b/source/blender/bmesh/intern/bmesh_structure_inline.h @@ -27,6 +27,12 @@ #ifndef __BMESH_STRUCTURE_INLINE_H__ #define __BMESH_STRUCTURE_INLINE_H__ +BLI_INLINE BMDiskLink *bmesh_disk_edge_link_from_vert(const BMEdge *e, const BMVert *v) +{ + BLI_assert(BM_vert_in_edge(e, v)); + return (BMDiskLink *)&(&e->v1_disk_link)[v == e->v2]; +} + /** * \brief Next Disk Edge * @@ -34,7 +40,7 @@ * * \return Pointer to the next edge in the disk cycle for the vertex v. */ -BLI_INLINE BMEdge *bmesh_disk_edge_next(const BMEdge *e, const BMVert *v) +BLI_INLINE BMEdge *bmesh_disk_edge_next_safe(const BMEdge *e, const BMVert *v) { if (v == e->v1) return e->v1_disk_link.next; @@ -43,7 +49,7 @@ BLI_INLINE BMEdge *bmesh_disk_edge_next(const BMEdge *e, const BMVert *v) return NULL; } -BLI_INLINE BMEdge *bmesh_disk_edge_prev(const BMEdge *e, const BMVert *v) +BLI_INLINE BMEdge *bmesh_disk_edge_prev_safe(const BMEdge *e, const BMVert *v) { if (v == e->v1) return e->v1_disk_link.prev; @@ -52,4 +58,14 @@ BLI_INLINE BMEdge *bmesh_disk_edge_prev(const BMEdge *e, const BMVert *v) return NULL; } +BLI_INLINE BMEdge *bmesh_disk_edge_next(const BMEdge *e, const BMVert *v) +{ + return BM_DISK_EDGE_NEXT(e, v); +} + +BLI_INLINE BMEdge *bmesh_disk_edge_prev(const BMEdge *e, const BMVert *v) +{ + return BM_DISK_EDGE_PREV(e, v); +} + #endif /* __BMESH_STRUCTURE_INLINE_H__ */