[Bf-blender-cvs] [07a5caa] master: BMesh: use slightly faster method of stepping over edge-disks

Campbell Barton noreply at git.blender.org
Fri Jun 27 12:39:17 CEST 2014


Commit: 07a5caad5fad742196aa4df0e251aaf4f0568563
Author: Campbell Barton
Date:   Fri Jun 27 20:03:50 2014 +1000
https://developer.blender.org/rB07a5caad5fad742196aa4df0e251aaf4f0568563

BMesh: use slightly faster method of stepping over edge-disks

===================================================================

M	source/blender/bmesh/bmesh_class.h
M	source/blender/bmesh/intern/bmesh_queries_inline.h
M	source/blender/bmesh/intern/bmesh_structure.c
M	source/blender/bmesh/intern/bmesh_structure.h
M	source/blender/bmesh/intern/bmesh_structure_inline.h

===================================================================

diff --git a/source/blender/bmesh/bmesh_class.h b/source/blender/bmesh/bmesh_class.h
index 83b0276..0174539 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 0856b98..6162af4 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 afcafc8..d8313da 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 5c87b5eb..8e721dd 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 c29acaa..5b7e890 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__ */




More information about the Bf-blender-cvs mailing list