Blender  V3.3
bmesh_iterators.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
20 #include "BLI_compiler_attrs.h"
21 #include "BLI_mempool.h"
22 
23 /* these iterator over all elements of a specific
24  * type in the mesh.
25  *
26  * be sure to keep 'bm_iter_itype_htype_map' in sync with any changes
27  */
28 typedef enum BMIterType {
32  /* these are topological iterators. */
36  BM_VERTS_OF_EDGE = 7, /* just v1, v2: added so py can use generalized sequencer wrapper */
41  /* returns elements from all boundaries, and returns
42  * the first element at the end to flag that we're entering
43  * a different face hole boundary. */
44  // BM_ALL_LOOPS_OF_FACE = 12,
45  /* iterate through loops around this loop, which are fetched
46  * from the other faces in the radial cycle surrounding the
47  * input loop's edge. */
51 
52 #define BM_ITYPE_MAX 14
53 
54 /* the iterator htype for each iterator */
55 extern const char bm_iter_itype_htype_map[BM_ITYPE_MAX];
56 
57 /* -------------------------------------------------------------------- */
63 #define BM_ITER_MESH(ele, iter, bm, itype) \
64  for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); ele; \
65  BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
66 
67 #define BM_ITER_MESH_INDEX(ele, iter, bm, itype, indexvar) \
68  for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL), indexvar = 0; ele; \
69  BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter), (indexvar)++)
70 
71 /* a version of BM_ITER_MESH which keeps the next item in storage
72  * so we can delete the current item, see bug T36923. */
73 #ifdef DEBUG
74 # define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype) \
75  for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); \
76  ele ? ((void)((iter)->count = BM_iter_mesh_count(itype, bm)), \
77  (void)(BM_CHECK_TYPE_ELEM_ASSIGN(ele_next) = BM_iter_step(iter)), \
78  1) : \
79  0; \
80  BM_CHECK_TYPE_ELEM_ASSIGN(ele) = ele_next)
81 #else
82 # define BM_ITER_MESH_MUTABLE(ele, ele_next, iter, bm, itype) \
83  for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, bm, itype, NULL); \
84  ele ? ((BM_CHECK_TYPE_ELEM_ASSIGN(ele_next) = BM_iter_step(iter)), 1) : 0; \
85  ele = ele_next)
86 #endif
87 
88 #define BM_ITER_ELEM(ele, iter, data, itype) \
89  for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, NULL, itype, data); ele; \
90  BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter))
91 
92 #define BM_ITER_ELEM_INDEX(ele, iter, data, itype, indexvar) \
93  for (BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_new(iter, NULL, itype, data), indexvar = 0; ele; \
94  BM_CHECK_TYPE_ELEM_ASSIGN(ele) = BM_iter_step(iter), (indexvar)++)
95 
98 /* iterator type structs */
101 };
105 };
110 };
115 };
119 };
123 };
127 };
130 };
134 };
138 };
142 };
143 
144 typedef void (*BMIter__begin_cb)(void *);
145 typedef void *(*BMIter__step_cb)(void *);
146 
147 /* Iterator Structure */
148 /* NOTE: some of these vars are not used,
149  * so they have been commented to save stack space since this struct is used all over */
150 typedef struct BMIter {
151  /* keep union first */
152  union {
154 
165  } data;
166 
169 
170  int count; /* NOTE: only some iterators set this, don't rely on it. */
171  char itype;
173 
177 void *BM_iter_at_index(BMesh *bm, char itype, void *data, int index) ATTR_WARN_UNUSED_RESULT;
184 int BM_iter_as_array(BMesh *bm, char itype, void *data, void **array, int len);
195 void *BM_iter_as_arrayN(BMesh *bm,
196  char itype,
197  void *data,
198  int *r_len,
199  void **stack_array,
200  int stack_array_size) ATTR_WARN_UNUSED_RESULT;
207  const char *slot_name,
208  char restrictmask,
209  void **array,
210  int len);
212  const char *slot_name,
213  char restrictmask,
214  int *r_len,
215  /* optional args to avoid an alloc (normally stack array) */
216  void **stack_array,
217  int stack_array_size);
218 
220  BMesh *bm,
221  uint *bitmap,
222  bool (*test_fn)(BMElem *, void *user_data),
223  void *user_data);
228  uint *bitmap,
229  bool (*test_fn)(BMFace *, void *user_data),
230  void *user_data);
231 
237 int BM_iter_elem_count_flag(char itype, void *data, char hflag, bool value);
243 int BMO_iter_elem_count_flag(BMesh *bm, char itype, void *data, short oflag, bool value);
247 int BM_iter_mesh_count(char itype, BMesh *bm);
253 int BM_iter_mesh_count_flag(char itype, BMesh *bm, char hflag, bool value);
254 
255 /* private for bmesh_iterators_inline.c */
256 
257 #define BMITER_CB_DEF(name) \
258  struct BMIter__##name; \
259  void bmiter__##name##_begin(struct BMIter__##name *iter); \
260  void *bmiter__##name##_step(struct BMIter__##name *iter)
261 
262 BMITER_CB_DEF(elem_of_mesh);
263 BMITER_CB_DEF(edge_of_vert);
264 BMITER_CB_DEF(face_of_vert);
265 BMITER_CB_DEF(loop_of_vert);
266 BMITER_CB_DEF(loop_of_edge);
267 BMITER_CB_DEF(loop_of_loop);
268 BMITER_CB_DEF(face_of_edge);
269 BMITER_CB_DEF(vert_of_edge);
270 BMITER_CB_DEF(vert_of_face);
271 BMITER_CB_DEF(edge_of_face);
272 BMITER_CB_DEF(loop_of_face);
273 
274 #undef BMITER_CB_DEF
275 
277 
278 #define BM_ITER_CHECK_TYPE_DATA(data) \
279  CHECK_TYPE_ANY(data, void *, BMFace *, BMEdge *, BMVert *, BMLoop *, BMElem *)
280 
281 #define BM_iter_new(iter, bm, itype, data) \
282  (BM_ITER_CHECK_TYPE_DATA(data), BM_iter_new(iter, bm, itype, data))
283 #define BM_iter_init(iter, bm, itype, data) \
284  (BM_ITER_CHECK_TYPE_DATA(data), BM_iter_init(iter, bm, itype, data))
#define ATTR_WARN_UNUSED_RESULT
unsigned int uint
Definition: BLI_sys_types.h:67
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.
int BM_iter_mesh_bitmap_from_filter(char itype, BMesh *bm, uint *bitmap, bool(*test_fn)(BMElem *, void *user_data), void *user_data)
const char bm_iter_itype_htype_map[BM_ITYPE_MAX]
int BM_iter_mesh_bitmap_from_filter_tessface(BMesh *bm, uint *bitmap, bool(*test_fn)(BMFace *, void *user_data), void *user_data)
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)
void *(* BMIter__step_cb)(void *)
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
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_mesh_count(char itype, BMesh *bm)
struct BMIter BMIter
int BM_iter_as_array(BMesh *bm, char itype, void *data, void **array, int len)
Iterator as Array.
#define BMITER_CB_DEF(name)
void * BM_iter_at_index(BMesh *bm, char itype, void *data, int index) ATTR_WARN_UNUSED_RESULT
#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
void * user_data
SyclQueue void void size_t num_bytes void
int len
Definition: draw_manager.c:108
BLI_mempool_iter pooliter
struct BMIter__edge_of_vert edge_of_vert
struct BMIter__face_of_edge face_of_edge
struct BMIter__vert_of_face vert_of_face
struct BMIter__loop_of_face loop_of_face
struct BMIter__loop_of_edge loop_of_edge
struct BMIter__vert_of_edge vert_of_edge
union BMIter::@141 data
struct BMIter__edge_of_face edge_of_face
struct BMIter__face_of_vert face_of_vert
BMIter__begin_cb begin
struct BMIter__loop_of_vert loop_of_vert
struct BMIter__elem_of_mesh elem_of_mesh
BMIter__step_cb step
struct BMIter__loop_of_loop loop_of_loop