Blender V4.3
bmesh_iterators.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
22#include "BLI_bit_span.hh"
23#include "BLI_compiler_attrs.h"
24#include "BLI_mempool.h"
25
26/* these iterator over all elements of a specific
27 * type in the mesh.
28 *
29 * be sure to keep 'bm_iter_itype_htype_map' in sync with any changes
30 */
31typedef enum BMIterType {
35 /* these are topological iterators. */
39 BM_VERTS_OF_EDGE = 7, /* just v1, v2: added so py can use generalized sequencer wrapper */
44 /* returns elements from all boundaries, and returns
45 * the first element at the end to flag that we're entering
46 * a different face hole boundary. */
47 // BM_ALL_LOOPS_OF_FACE = 12,
48 /* iterate through loops around this loop, which are fetched
49 * from the other faces in the radial cycle surrounding the
50 * input loop's edge. */
54
55#define BM_ITYPE_MAX 14
56
57/* the iterator htype for each iterator */
58extern const char bm_iter_itype_htype_map[BM_ITYPE_MAX];
59
60/* -------------------------------------------------------------------- */
66#define BM_ITER_MESH(ele, iter, bm, itype) \
67 for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); ele; \
68 BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
69
70#define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar) \
71 for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL), indexvar = 0; ele; \
72 BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter), (indexvar)++)
73
74/* a version of BM_ITER_MESH which keeps the next item in storage
75 * so we can delete the current item, see bug #36923. */
76#ifndef NDEBUG
77# define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype) \
78 for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); \
79 ele ? ((void)((iter)->count = BM_iter_mesh_count(itype, bm)), \
80 (void)(BM_CHECK_TYPE_ELEM_ASSIGN(ele_next) = BM_iter_step(iter)), \
81 1) : \
82 0; \
83 BM_CHECK_TYPE_ELEM_ASSIGN(ele) = ele_next)
84#else
85# define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype) \
86 for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); \
87 ele ? ((BM_CHECK_TYPE_ELEM_ASSIGN(ele_next) = BM_iter_step(iter)), 1) : 0; \
88 ele = ele_next)
89#endif
90
91#define BM_ITER_ELEM(ele, iter, data, itype) \
92 for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, NULL, itype, data); ele; \
93 BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
94
95#define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar) \
96 for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, NULL, itype, data), indexvar = 0; ele; \
97 BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter), (indexvar)++)
98
101/* iterator type structs */
146
147typedef void (*BMIter__begin_cb)(void *);
148typedef void *(*BMIter__step_cb)(void *);
149
150/* Iterator Structure */
151/* NOTE: some of these vars are not used,
152 * so they have been commented to save stack space since this struct is used all over */
176
180void *BM_iter_at_index(BMesh *bm, char itype, void *data, int index) ATTR_WARN_UNUSED_RESULT;
187int BM_iter_as_array(BMesh *bm, char itype, void *data, void **array, int len);
199 char itype,
200 void *data,
201 int *r_len,
202 void **stack_array,
203 int stack_array_size) ATTR_WARN_UNUSED_RESULT;
210 const char *slot_name,
211 char restrictmask,
212 void **array,
213 int len);
215 const char *slot_name,
216 char restrictmask,
217 int *r_len,
218 /* optional args to avoid an alloc (normally stack array) */
219 void **stack_array,
220 int stack_array_size);
221
223 BMesh *bm,
225 bool (*test_fn)(BMElem *, void *user_data),
226 void *user_data);
232 bool (*test_fn)(BMFace *, void *user_data),
233 void *user_data);
234
240int BM_iter_elem_count_flag(char itype, void *data, char hflag, bool value);
246int BMO_iter_elem_count_flag(BMesh *bm, char itype, void *data, short oflag, bool value);
250int BM_iter_mesh_count(char itype, BMesh *bm);
256int BM_iter_mesh_count_flag(char itype, BMesh *bm, char hflag, bool value);
257
258/* private for bmesh_iterators_inline.c */
259
260#define BMITER_CB_DEF(name) \
261 struct BMIter__##name; \
262 void bmiter__##name##_begin(struct BMIter__##name *iter); \
263 void *bmiter__##name##_step(struct BMIter__##name *iter)
264
265BMITER_CB_DEF(elem_of_mesh);
266BMITER_CB_DEF(edge_of_vert);
267BMITER_CB_DEF(face_of_vert);
268BMITER_CB_DEF(loop_of_vert);
269BMITER_CB_DEF(loop_of_edge);
270BMITER_CB_DEF(loop_of_loop);
271BMITER_CB_DEF(face_of_edge);
272BMITER_CB_DEF(vert_of_edge);
273BMITER_CB_DEF(vert_of_face);
274BMITER_CB_DEF(edge_of_face);
275BMITER_CB_DEF(loop_of_face);
276
277#undef BMITER_CB_DEF
278
280
281#define BM_ITER_CHECK_TYPE_DATA(data) \
282 CHECK_TYPE_ANY(data, void *, BMFace *, BMEdge *, BMVert *, BMLoop *, BMElem *)
283
284#define BM_iter_new(iter, bm, itype, data) \
285 (BM_ITER_CHECK_TYPE_DATA(data), BM_iter_new(iter, bm, itype, data))
286#define BM_iter_init(iter, bm, itype, data) \
287 (BM_ITER_CHECK_TYPE_DATA(data), BM_iter_init(iter, bm, itype, data))
#define ATTR_WARN_UNUSED_RESULT
int BM_iter_mesh_count_flag(char itype, BMesh *bm, char hflag, bool value)
Mesh Iter Flag Count.
int BMO_iter_as_array(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char restrictmask, void **array, int len)
Operator Iterator as Array.
int BMO_iter_elem_count_flag(BMesh *bm, char itype, void *data, short oflag, bool value)
Elem Iter Tool Flag Count.
const char bm_iter_itype_htype_map[BM_ITYPE_MAX]
int BM_iter_mesh_bitmap_from_filter(char itype, BMesh *bm, blender::MutableBitSpan bitmap, bool(*test_fn)(BMElem *, void *user_data), void *user_data)
int BM_iter_mesh_bitmap_from_filter_tessface(BMesh *bm, blender::MutableBitSpan bitmap, bool(*test_fn)(BMFace *, void *user_data), void *user_data)
BMIterType
BMesh Iterators.
@ BM_LOOPS_OF_LOOP
@ BM_FACES_OF_EDGE
@ BM_FACES_OF_VERT
@ BM_EDGES_OF_MESH
@ BM_VERTS_OF_MESH
@ BM_VERTS_OF_EDGE
@ BM_VERTS_OF_FACE
@ BM_FACES_OF_MESH
@ BM_LOOPS_OF_VERT
@ BM_LOOPS_OF_EDGE
@ BM_EDGES_OF_VERT
@ BM_EDGES_OF_FACE
@ BM_LOOPS_OF_FACE
int BM_iter_mesh_count(char itype, BMesh *bm)
void * BM_iter_as_arrayN(BMesh *bm, char itype, void *data, int *r_len, void **stack_array, int stack_array_size) ATTR_WARN_UNUSED_RESULT
Iterator as Array.
int BM_iter_as_array(BMesh *bm, char itype, void *data, void **array, int len)
Iterator as Array.
void *(* BMIter__step_cb)(void *)
void * BM_iter_at_index(BMesh *bm, char itype, void *data, int index) ATTR_WARN_UNUSED_RESULT
#define BMITER_CB_DEF(name)
void * BMO_iter_as_arrayN(BMOpSlot slot_args[BMO_OP_MAX_SLOTS], const char *slot_name, char restrictmask, int *r_len, void **stack_array, int stack_array_size)
#define BM_ITYPE_MAX
void(* BMIter__begin_cb)(void *)
int BM_iter_elem_count_flag(char itype, void *data, char hflag, bool value)
Elem Iter Flag Count.
ATTR_WARN_UNUSED_RESULT BMesh const char itype
ATTR_WARN_UNUSED_RESULT BMesh * bm
#define BMO_OP_MAX_SLOTS
ATTR_WARN_UNUSED_RESULT const BMFlagLayer const short oflag
int len
BLI_mempool_iter pooliter
BMIter__vert_of_edge vert_of_edge
BMIter__loop_of_vert loop_of_vert
BMIter__edge_of_face edge_of_face
BMIter__loop_of_edge loop_of_edge
union BMIter::@135 data
BMIter__face_of_vert face_of_vert
BMIter__begin_cb begin
BMIter__loop_of_loop loop_of_loop
BMIter__vert_of_face vert_of_face
BMIter__edge_of_vert edge_of_vert
BMIter__step_cb step
BMIter__face_of_edge face_of_edge
BMIter__loop_of_face loop_of_face
BMIter__elem_of_mesh elem_of_mesh